qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
161,485
|
<p>How should I configure the class to bind three dropdowns (date, month, year) to a single Date property so that it works the way it works for 'single request parameter per property' scenario ?
I guess a should add some custom PropertyEditors by overriding initBinder method. What else ?</p>
|
[
{
"answer_id": 173783,
"author": "miceuz",
"author_id": 24443,
"author_profile": "https://Stackoverflow.com/users/24443",
"pm_score": 3,
"selected": true,
"text": "dateField = new SimpleFormat(\"YYYY-mm-dd\").parse(this.year + \"-\" + this.month + \"-\" this.day);\n Calendar c = Calendar.getInstance();\nc.set(year, month, day);\ndateField = calendar.getTime();\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/578/"
] |
161,486
|
<p>I developing ASP.NET application using a Swedish version of Windows XP and Visual studio Professional. When ever i get an error aka. "yellow screen of death" the error message is in swedish, making it a bit hard to search for info about it.</p>
<p>How can i change what language the error messages in ASP.NET uses?</p>
<p>I have no language pack installed for the .net framework. I am however running an english windows xp with a swedish language interface pack on it.</p>
<p>I also have this in my web.config:</p>
<pre><code><system.web>
<globalization uiCulture="en-US" />
</system.web>
</code></pre>
|
[
{
"answer_id": 161503,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 6,
"selected": false,
"text": "<system.web>\n <globalization uiCulture=\"en-US\" />\n</system.web>\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20368/"
] |
161,490
|
<p>I am currently porting a lot of code from an MFC-based application to a DLL for client branding purposes.</p>
<p>I've come across an unusual problem. This bit of code is the same in both systems:</p>
<pre><code>// ...
CCommsProperties props;
pController->GetProperties( props );
if (props.handshake != HANDSHAKE_RTS_CTS)
{
props.handshake = HANDSHAKE_RTS_CTS;
pController->RefreshCommProperties( props );
}
// ... in another file:
void CControllerSI::RefreshCommProperties ( const CCommsProperties& props )
{
// ... code ...
}
</code></pre>
<p>CommProperties is a wrapper for the comm settings, serialization of etc. and pController is of type ControllerSI which itself is a layer between the actual Comms and the Application.</p>
<p>On the original MFC version the setting of handshake to RTS-CTS sticks but when running as the DLL version it resets itself to 0 as soon as the function is entered. The code is contained entirely in the DLL section of the code, so there are no boundaries.</p>
<p>The main differences between the original and the new modules is the variables that call the various dialogs have been removed and the removed #includes</p>
<p>I've lost an afternoon to this and I don't really want to lose any more...</p>
|
[
{
"answer_id": 161564,
"author": "user22044",
"author_id": 22044,
"author_profile": "https://Stackoverflow.com/users/22044",
"pm_score": 1,
"selected": false,
"text": "RefreshCommProperties()"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/342/"
] |
161,497
|
<p>In Windows XP what is the best way to execute a particular application when a particular type of USB device is attached (it currently attaches as a storage device - i.e. it appears as a drive).</p>
<p>The solution I am looking for must execute the application from the very first time the device is attached or offer the application as a selection, whichever is easier to achieve, the device must remain attached as a storage device.</p>
<p><strong>EDIT:</strong> Polling all attached devices is not adequate - windows will already have done its pop-ups at that stage. The issue is with starting the application without additional pop-ups, the application will then need to use the device as a normal storage drive.</p>
|
[
{
"answer_id": 161728,
"author": "Treb",
"author_id": 22114,
"author_profile": "https://Stackoverflow.com/users/22114",
"pm_score": 2,
"selected": false,
"text": "ManagementEventWatcher Watcher;\nWqlEventQuery Query = new WqlEventQuery();\nQuery.EventClassName = \"__InstanceCreationEvent\";\nQuery.Condition = \"TargetInstance ISA 'Win32_USBControllerDevice'\";\nQuery.WithinInterval = new TimeSpan(0, 0, 2);\n\nWatcher = new ManagementEventWatcher(Query);\nWatcher.EventArrived += new EventArrivedEventHandler(OnUsbConnected);\n"
},
{
"answer_id": 162514,
"author": "Tim Farley",
"author_id": 4425,
"author_profile": "https://Stackoverflow.com/users/4425",
"pm_score": 1,
"selected": false,
"text": "[autorun]\nopen=c:\\progra~1\\itunes\\itunes.exe\nlabel=Open iTunes\nicon=c:\\progra~1\\itunes\\itunes.exe,0\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22100/"
] |
161,510
|
<p>In Ruby, is it possible to pass by reference a parameter with value-type semantics (e.g. a Fixnum)?
I'm looking for something similar to C#'s '<strong>ref</strong>' keyword.</p>
<p>Example:</p>
<pre><code>def func(x)
x += 1
end
a = 5
func(a) #this should be something like func(ref a)
puts a #should read '6'
</code></pre>
<p>Btw. I know I could just use:</p>
<pre><code>a = func(a)
</code></pre>
|
[
{
"answer_id": 161589,
"author": "Christoph Schiessl",
"author_id": 20467,
"author_profile": "https://Stackoverflow.com/users/20467",
"pm_score": 4,
"selected": false,
"text": "Fixnum x += 1 Fixnum Fixnum"
},
{
"answer_id": 161607,
"author": "jmah",
"author_id": 3948,
"author_profile": "https://Stackoverflow.com/users/3948",
"pm_score": 6,
"selected": true,
"text": "def func(x, bdg)\n eval \"#{x} += 1\", bdg\nend\n\na = 5\nfunc(:a, binding)\nputs a # => 6\n"
},
{
"answer_id": 161634,
"author": "muesan",
"author_id": 22154,
"author_profile": "https://Stackoverflow.com/users/22154",
"pm_score": 4,
"selected": false,
"text": "class Container\nattr_accessor :value\n def initialize value\n @value = value\n end\nend\n\ndef func(x)\n x.value += 1\nend\n\na = Container.new(5)\nfunc(a)\nputs a.value\n"
},
{
"answer_id": 28804261,
"author": "Ivan Gusev",
"author_id": 1147597,
"author_profile": "https://Stackoverflow.com/users/1147597",
"pm_score": 3,
"selected": false,
"text": "def func(x) \n x[0] += 1\nend\n\na = [5]\nfunc(a) #this should be something like func(ref a)\nputs a[0] #should read '6'\n"
},
{
"answer_id": 56168196,
"author": "Ivan Cenov",
"author_id": 2635665,
"author_profile": "https://Stackoverflow.com/users/2635665",
"pm_score": -1,
"selected": false,
"text": "fp = {}\ndef changeit(par)\n par[:abc] = 'cde'\nend\n\nchangeit(fp)\n\np fp\n {:abc=>\"cde\"}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11545/"
] |
161,518
|
<p>How do I link an external .jar into my Xcode java project? That is, have it in the classpath during compilation and execution. I'm using Xcode 3.0 and this seems to have changed since 2.4.</p>
|
[
{
"answer_id": 162574,
"author": "jmah",
"author_id": 3948,
"author_profile": "https://Stackoverflow.com/users/3948",
"pm_score": 0,
"selected": false,
"text": "-classpath path/to/lib"
},
{
"answer_id": 540112,
"author": "Paxic",
"author_id": 64457,
"author_profile": "https://Stackoverflow.com/users/64457",
"pm_score": 2,
"selected": false,
"text": "<!-- lib directory should contain any pre-built jar files needed to build the project\n AppleJavaExtensions.jar is included to allow the built jars to run cross-platform if you depend on Apple eAWT or eIO classes.\n See http://developer.apple.com/samplecode/AppleJavaExtensions/index.html for more information -->\n <fileset id=\"lib.jars\" dir=\"${lib}\">\n <include name=\"**/*.jar\"/>\n </fileset>"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161518",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4127/"
] |
161,519
|
<p>I use Visual Basic and an automation interface to retrieve strings from an external application. These strings contain simple html formatting codes (<b>, <i>, etc.).
Is there any easy function in Visual Basic for Word to insert these strings into a word document and convert the html formatting codes to word formatting?</p>
|
[
{
"answer_id": 161699,
"author": "Treb",
"author_id": 22114,
"author_profile": "https://Stackoverflow.com/users/22114",
"pm_score": 0,
"selected": false,
"text": "<b>, <i>, <a> and <p>,"
},
{
"answer_id": 163511,
"author": "Jonathan Yee",
"author_id": 16320,
"author_profile": "https://Stackoverflow.com/users/16320",
"pm_score": 4,
"selected": false,
"text": "ActiveDocument.Range.PasteSpecial ,,,,WdPasteDataType.wdPasteHTML\n"
},
{
"answer_id": 30892682,
"author": "Adz",
"author_id": 4238727,
"author_profile": "https://Stackoverflow.com/users/4238727",
"pm_score": 2,
"selected": false,
"text": "Set objdoc = objInsp.WordEditor\nSet objword = objdoc.Application\nSet objsel = objword.Selection\nobjsel.WholeStory\nvs_html = \"<html><body>\" + vs_body + \"</body></html>\"\nvs_file = \"C:\\temp\\1.html\"\nCall DumptoFile(vs_file, \"\", vs_html, False)\nRetVal = objsel.InsertFile(vs_file, , , False, False)\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
161,524
|
<p>I'm writing a query for an application that needs to list all the products with the number of times they have been purchased.</p>
<p>I came up with this and it works, but I am not too sure how optimized it is. My SQL is really rusty due to my heavy usage of ORM's, But in this case a query is a much more elegant solution.</p>
<p>Can you spot anything wrong (approach wise) with the query?</p>
<hr>
<pre><code>SELECT products.id,
products.long_name AS name,
count(oi.order_id) AS sold
FROM products
LEFT OUTER JOIN
( SELECT * FROM orderitems
INNER JOIN orders ON orderitems.order_id = orders.id
AND orders.paid = 1 ) AS oi
ON oi.product_id = products.id
GROUP BY products.id
</code></pre>
<hr>
<p>The schema (with relevant fields) looks like this:</p>
<pre><code>*orders* id, paid
*orderitems* order_id, product_id
*products* id
</code></pre>
<h2>UPDATE</h2>
<p>This is for MySQL</p>
|
[
{
"answer_id": 161555,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 0,
"selected": false,
"text": "SELECT products.id,\n MIN(products.long_name) AS name, \n count(oi.order_id) AS sold\nFROM (products\nLEFT OUTER JOIN orderitemss AS oi ON oi.product_id = products.id)\nINNER JOIN orders AS o ON oi.order_id = o.id \nWHERE orders.paid = 1\nGROUP BY products.id\n"
},
{
"answer_id": 161569,
"author": "Mike Woodhouse",
"author_id": 1060,
"author_profile": "https://Stackoverflow.com/users/1060",
"pm_score": 3,
"selected": true,
"text": "SELECT products.id, \n products.long_name AS name, \n count(oi.order_id) AS sold\nFROM products\nLEFT OUTER JOIN\n orderitems AS oi\n INNER JOIN \n orders \n ON oi.order_id = orders.id AND orders.paid = 1\n ON oi.product_id = products.id\nGROUP BY products.id\n"
},
{
"answer_id": 162165,
"author": "Darrel Miller",
"author_id": 6819,
"author_profile": "https://Stackoverflow.com/users/6819",
"pm_score": 2,
"selected": false,
"text": "SELECT products.id, \n products.long_name AS name, \n count(oi.order_id) AS sold\nFROM orders \n INNER JOIN orderitems AS oi ON oi.order_id = orders.id AND orders.paid = 1\n RIGHT JOIN products ON oi.product_id = products.id\nGROUP BY products.id\n"
},
{
"answer_id": 168024,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 0,
"selected": false,
"text": "SELECT\n p.id,\n p.long_name AS name,\n (SELECT COUNT(*) FROM OrderItems oi WHERE oi.order_id in\n (SELECT o.id FROM Orders o WHERE o.Paid = 1 AND o.Product_id = p.id)\n ) as sold\nFROM Products p\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1877/"
] |
161,531
|
<p>This seems to be a common problem but I cannot find a solution.</p>
<p>I type in my username and password which are in a login control I have created.
I then press enter once I've typed in my password and the page just refreshes. It triggers the page load event but not the button on click event.</p>
<p>If I press the submit button then everything works fine.</p>
|
[
{
"answer_id": 161560,
"author": "Jon Limjap",
"author_id": 372,
"author_profile": "https://Stackoverflow.com/users/372",
"pm_score": 1,
"selected": false,
"text": "<form runat=\"server\" DefaultButton=\"SubmitButton\">\n"
},
{
"answer_id": 161768,
"author": "WebDude",
"author_id": 15360,
"author_profile": "https://Stackoverflow.com/users/15360",
"pm_score": 3,
"selected": true,
"text": "<form runat=\"server\" DefaultButton=\"SubmitButton\">\n <form runat=\"server\" id=\"form1\">\n protected void Page_Load(object sender, EventArgs e)\n{\n form1.DefaultButton = ucLogin.btnSubmit.ClientID;\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1469/"
] |
161,539
|
<p>Imagine the following Ruby Module:</p>
<pre><code>module Foo
def inst_method
puts "Called Foo.inst_method"
end
def self.class_method
puts "Called Foo.class_method"
end
end
</code></pre>
<p>Obviously <code>Foo.class_method</code> can be called without any class instances. However, what's happening to <code>Foo.inst_method</code>? Is it possible to call <code>Foo.inst_method</code> without previously including/extending a class?</p>
<p>Disclaimer: The question isn't focused on solving a real problem. I'm just trying to improve my understanding of the Ruby object system.</p>
|
[
{
"answer_id": 161618,
"author": "Jean",
"author_id": 7898,
"author_profile": "https://Stackoverflow.com/users/7898",
"pm_score": 2,
"selected": false,
"text": "module Tester\n def inst_meth\n puts \"test inst meth\\n\"\n end\n\n def self.meth\n puts \"test self meth\\n\"\n end\nend\n\nbegin\n Tester.meth\nrescue;\n puts $!\nend\nbegin\n Tester.inst_meth\nrescue\n puts $!\nend\nbegin\n Tester.new.inst_meth\nrescue\n puts $!\nend\nbegin\n extend Tester\n inst_meth\nrescue\n puts $!\nend\nbegin\n include Tester\n inst_meth\nrescue\n puts $!\nend\n >ruby test.rb\ntest self meth\nundefined method `inst_meth' for Tester:Module\nundefined method `new' for Tester:Module\n test inst meth\n test inst meth\n"
},
{
"answer_id": 162639,
"author": "Ian Terrell",
"author_id": 9269,
"author_profile": "https://Stackoverflow.com/users/9269",
"pm_score": 5,
"selected": true,
"text": "Array Hash Enumerable each_with_index select reject sort"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20467/"
] |
161,541
|
<p>I am starting a new distributed project. Should I use SVN or Git, and why?</p>
|
[
{
"answer_id": 161562,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 3,
"selected": false,
"text": "svn git"
},
{
"answer_id": 161602,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 4,
"selected": false,
"text": "git-svn git-svn"
},
{
"answer_id": 162141,
"author": "Andre Bossard",
"author_id": 21027,
"author_profile": "https://Stackoverflow.com/users/21027",
"pm_score": 4,
"selected": false,
"text": "backup/public"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5147/"
] |
161,549
|
<p>I recently had to rename a table (and a column and FK/PK contraints) in SQL Server 2000 without losing an data. There did not seem to be an obvious DDL T-SQL statements for performing this action, so I used sp_rename to directly fiddle with object names.</p>
<p>Was this the only solution to the problem? (other, than give the table the correct name in the first place - doh!)</p>
|
[
{
"answer_id": 161557,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 4,
"selected": false,
"text": "EXEC sp_rename 'Old_TableName', 'New_TableName'\n"
},
{
"answer_id": 161628,
"author": "Philippe Grondier",
"author_id": 11436,
"author_profile": "https://Stackoverflow.com/users/11436",
"pm_score": 0,
"selected": false,
"text": "ALTER TABLE SELECT oldTable.oldField1 as newField1, ..."
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23497/"
] |
161,556
|
<p>I've got a Method that gets a IDictionary as a parameter.
Now I want to provide a method that retrieves the value from this dictionary, but it should be case-invariant.</p>
<p>So my solution to this right now was to have a static function that loops through the keys and converts them toLower() like this:</p>
<pre><code>private static IDictionary<ILanguage, IDictionary<string, string>> ConvertKeysToLowerCase(
IDictionary<ILanguage, IDictionary<string, string>> dictionaries)
{
IDictionary<ILanguage, IDictionary<string, string>> resultingConvertedDictionaries
= new Dictionary<ILanguage, IDictionary<string, string>>();
foreach(ILanguage keyLanguage in dictionaries.Keys)
{
IDictionary<string, string> convertedDictionatry = new Dictionary<string, string>();
foreach(string key in dictionaries[keyLanguage].Keys)
{
convertedDictionatry.Add(key.ToLower(), dictionaries[keyLanguage][key]);
}
resultingConvertedDictionaries.Add(keyLanguage, convertedDictionatry);
}
return resultingConvertedDictionaries;
}
</code></pre>
<p>Now, this is ok, but still it's a pretty huge chunk of code that contradicts my idea of "clean and efficient". Do you know any alternatives to this so that the .ContainsKey() method of the dictionary doesn't differentiate between casing?</p>
|
[
{
"answer_id": 161565,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": true,
"text": "StringComparer.OrdinalIgnoreCase"
},
{
"answer_id": 161608,
"author": "VVS",
"author_id": 21038,
"author_profile": "https://Stackoverflow.com/users/21038",
"pm_score": 1,
"selected": false,
"text": "private static IDictionary<string, string> ConvertKeysToLowerCase(\n IDictionary<string, string> dictionaries)\n{\n var convertedDictionatry = new Dictionary<string, string>();\n foreach(string key in dictionaries.Keys)\n {\n convertedDictionatry.Add(key.ToLower(), dictionaries[key]);\n }\n return convertedDictionatry;\n}\n // myLanguageDictionaries is of type IDictionary<ILanguage, IDictionary<string, string>>\nforeach (var dictionary in myLanguageDictionaries.Keys)\n{\n myLanguageDictionaries[dictionary].Value = \n ConvertKeysToLowerCase(myLanguageDictionaries[dictionary].Value);\n}\n"
},
{
"answer_id": 161877,
"author": "Jonathan C Dickinson",
"author_id": 24064,
"author_profile": "https://Stackoverflow.com/users/24064",
"pm_score": 1,
"selected": false,
"text": "Add(string key, string value) { dictionary.Add(key.ToLowerInvariant(), value) ; }\npublic string this[string key]\n{\n get { return dictionary[key.ToLowerInvariant()]; }\n set { dictionary[key.ToLowerInvariant()] = value; }\n}\n// And so forth.\n"
},
{
"answer_id": 161920,
"author": "mancaus",
"author_id": 13797,
"author_profile": "https://Stackoverflow.com/users/13797",
"pm_score": -1,
"selected": false,
"text": "IEnumerable<T> \n private static IDictionary<ILanguage, IDictionary<string, string>> ConvertKeysToLowerCase(\n IDictionary<ILanguage, IDictionary<string, string>> dictionaries)\n {\n return dictionaries.ToDictionary(\n x => x.Key, v => CloneWithComparer(v.Value, StringComparer.OrdinalIgnoreCase));\n }\n\n static IDictionary<K, V> CloneWithComparer<K,V>(IDictionary<K, V> original, IEqualityComparer<K> comparer)\n {\n return original.ToDictionary(x => x.Key, x => x.Value, comparer);\n }\n"
},
{
"answer_id": 60415940,
"author": "ANJYR",
"author_id": 2126088,
"author_profile": "https://Stackoverflow.com/users/2126088",
"pm_score": 0,
"selected": false,
"text": "convertedDictionatry = convertedDictionatry .ToDictionary(k => k.Key.ToLower(), k => k.Value.ToLower());\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161556",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21699/"
] |
161,614
|
<p>I need to get the Class of an object at runtime.</p>
<p>For an non-abstract class I could do something like:</p>
<pre><code>public class MyNoneAbstract{
public static Class MYNONEABSTRACT_CLASS = new MyNoneAbstract().getClass();
</code></pre>
<p>But for an abstract class this does NOT work (always gives me <code>Object</code>)</p>
<pre><code>public abstract class MyAbstract{
public static Class MYABSTRACT_CLASS = MyAbstract.class.getClass();
</code></pre>
<p>This code will be running in JavaME environments.</p>
|
[
{
"answer_id": 161625,
"author": "skaffman",
"author_id": 21234,
"author_profile": "https://Stackoverflow.com/users/21234",
"pm_score": 3,
"selected": true,
"text": "MyAbstract.class\n"
},
{
"answer_id": 162340,
"author": "DJClayworth",
"author_id": 19276,
"author_profile": "https://Stackoverflow.com/users/19276",
"pm_score": 0,
"selected": false,
"text": "public abstract class MyAbstract{\n public static Class MYABSTRACT_CLASS = MyAbstract.class;\n}\n"
},
{
"answer_id": 166954,
"author": "michael aubert",
"author_id": 17867,
"author_profile": "https://Stackoverflow.com/users/17867",
"pm_score": 0,
"selected": false,
"text": "Object.getClass() public String getClassHierarchy() {\n return super.getClassHierarchy() + \".MyAbstract\";\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/180142/"
] |
161,633
|
<p>Should methods in a Java interface be declared with or without the <code>public</code> access modifier?</p>
<p>Technically it doesn't matter, of course. A class method that implements an <code>interface</code> is always <code>public</code>. But what is a better convention?</p>
<p>Java itself is not consistent in this. See for instance <code>Collection</code> vs. <code>Comparable</code>, or <code>Future</code> vs. <code>ScriptEngine</code>.</p>
|
[
{
"answer_id": 161649,
"author": "JeeBee",
"author_id": 17832,
"author_profile": "https://Stackoverflow.com/users/17832",
"pm_score": 3,
"selected": false,
"text": "public"
},
{
"answer_id": 161659,
"author": "Rasmus Faber",
"author_id": 5542,
"author_profile": "https://Stackoverflow.com/users/5542",
"pm_score": 6,
"selected": false,
"text": "public interface Foo{\n public void MakeFoo();\n void PerformBar();\n}\n"
},
{
"answer_id": 161682,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 3,
"selected": false,
"text": "abstract"
},
{
"answer_id": 161692,
"author": "serg10",
"author_id": 1853,
"author_profile": "https://Stackoverflow.com/users/1853",
"pm_score": 1,
"selected": false,
"text": "public"
},
{
"answer_id": 161693,
"author": "cretzel",
"author_id": 18722,
"author_profile": "https://Stackoverflow.com/users/18722",
"pm_score": 3,
"selected": false,
"text": "public public public abstract"
},
{
"answer_id": 161787,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 9,
"selected": true,
"text": "public abstract"
},
{
"answer_id": 3447430,
"author": "Pradeep Sharma",
"author_id": 129230,
"author_profile": "https://Stackoverflow.com/users/129230",
"pm_score": 2,
"selected": false,
"text": "public abstract public"
},
{
"answer_id": 44868858,
"author": "Werner Thumann",
"author_id": 3146077,
"author_profile": "https://Stackoverflow.com/users/3146077",
"pm_score": 3,
"selected": false,
"text": "private static default public interface MyInterface {\n\n //minimal\n int CONST00 = 0;\n void method00();\n static void method01() {}\n default void method02() {}\n private static void method03() {}\n private void method04() {}\n\n //full\n public static final int CONST10 = 0;\n public abstract void method10();\n public static void method11() {}\n public default void method12() {}\n private static void method13() {}\n private void method14() {}\n\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3565/"
] |
161,637
|
<p>My team developed a GUI application on Visual Studio 2005, managed C++. Since some deliveries it is not possible to open the form in the designer, even if the source code and the project settings have not been changed. The designer reports this error: </p>
<p><strong>Exception of type 'System.OutOfMemoryException' was thrown.</strong> </p>
<p><em>at Microsoft.VisualStudio.Design.VSDynamicTypeService.ShadowCopyAssembly(String fileName)
at Microsoft.VisualStudio.Design.VSDynamicTypeService.CreateDynamicAssembly(String codeBase)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.Search(String fullName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, String description)
...</em></p>
<p>We successfully recompiled the project but we still encounter this problem.
Any idea?</p>
|
[
{
"answer_id": 235919,
"author": "msulis",
"author_id": 9317,
"author_profile": "https://Stackoverflow.com/users/9317",
"pm_score": 0,
"selected": false,
"text": "multi(0)disk(0)rdisk(0)partition(2)\\WINDOWS=\"Microsoft Windows XP Professional\" /noexecute=optin /fastdetect /3GB\n cd %ProgramFiles%\\Microsoft Visual Studio 8\\Common7\\IDE\n editbin /LARGEADDRESSAWARE devenv.exe\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17934/"
] |
161,639
|
<p>I have two overloads of a c++ function and I would like to set a breakpoint on one of them:</p>
<pre><code>0:000> bu myexe!displayerror
Matched: 00000000`ff3c6100 myexe!displayError (int, HRESULT, wchar_t *)
Matched: 00000000`ff3c60d0 myexe!displayError (int, HRESULT)
Ambiguous symbol error at 'myexe!displayerror'
</code></pre>
<p>Heck I would be fine with setting breakpoints on all overloads, but can't seem to figure out how:</p>
<pre><code>0:000> bu myexe!displayerror*
Matched: 00000000`ff3c6100 myexe!displayError (int, HRESULT, wchar_t *)
Matched: 00000000`ff3c60d0 myexe!displayError (int, HRESULT)
Ambiguous symbol error at 'myexe!displayerror*'
</code></pre>
|
[
{
"answer_id": 161658,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": false,
"text": "bu 0xff3c6100\n"
},
{
"answer_id": 4176483,
"author": "kizzx2",
"author_id": 111021,
"author_profile": "https://Stackoverflow.com/users/111021",
"pm_score": 2,
"selected": false,
"text": "bm myexe!displayerror\n bc bc 1-3\n bd 1-3\n bm"
},
{
"answer_id": 9646178,
"author": "EdChum",
"author_id": 704848,
"author_profile": "https://Stackoverflow.com/users/704848",
"pm_score": 1,
"selected": false,
"text": "x myexe!displayerror\n bp ff3c6100 // for myexe!displayError (int, HRESULT, wchar_t *)\n bp /1 ff3c6100\n bp ff3c6100 \"kb;dv;g\"\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15071/"
] |
161,654
|
<p>This is a subjective question as I want to gauge if it's worth me moaning at my co-workers for doing something which I find utterly detestable.</p>
<p>The issue is that a bunch of my co-workers will truncate method calls to fit a width. We all use widescreen laptops that can handle large resolutions (mine is 1920x1200) and when it comes to debugging and reading code I find it much easier to read one line method calls as opposed to multiple line calls.</p>
<p>Here's an example of a method (how I would like it):</p>
<pre><code>IReallyLongInterfaceName instanceOfInterfaceName = OurContainer.retrieveClass(IReallyLongInterfaceName.class, param1, param2, param3);
</code></pre>
<p>(I do hate really long interface/class names as well :)</p>
<p>It seems that this doesn't render well on StackOverflow, but I think most of you know what I mean. Anyway, some of the other devs do the following.</p>
<pre><code>IReallyLongInterfaceName instanceOfInterfaceName = OurContainer.retrieveClass(IReallyLongInterfaceName.class,
param1,
param2,
param3);
</code></pre>
<p>Which is the easier to read at the end of the day for you and would I be unreasonable in asking them to use the first of the two (as it is part of our standard)?</p>
|
[
{
"answer_id": 161723,
"author": "Avi",
"author_id": 1605,
"author_profile": "https://Stackoverflow.com/users/1605",
"pm_score": 2,
"selected": false,
"text": "IReallyLongInterfaceName instanceOfInterfaceName =\n OurContainer.retrieveClass(IReallyLongInterfaceName.class,\n param1, param2, param3);\n"
},
{
"answer_id": 165609,
"author": "Kevin Day",
"author_id": 10973,
"author_profile": "https://Stackoverflow.com/users/10973",
"pm_score": 0,
"selected": false,
"text": "applyEncryptionParameters(key,\n certificate,\n 0, // strength - set to 0 to accept default for platform\n algorithm);\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161654",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6414/"
] |
161,655
|
<p>Consider the following subversion directory structure</p>
<p>/dir1/file.txt</p>
<p>/dir2/file.txt</p>
<p>I want to move the file.txt in dir1 to replace the same file in dir2 and ensure that the history for the dir1 file is maintained. I don't care about the history of original dir2 file.</p>
<p>Is this possible using subversion commands and not hacking the backend?</p>
|
[
{
"answer_id": 161668,
"author": "Richard Harrison",
"author_id": 19624,
"author_profile": "https://Stackoverflow.com/users/19624",
"pm_score": 4,
"selected": true,
"text": "svn rm /dir2/file.txt\nsvn mv /dir1/file.txt /dir2/file.txt\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/445016/"
] |
161,666
|
<p>I'm trying to learn scheme via SICP. Exercise 1.3 reads as follow: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. Please comment on how I can improve my solution.</p>
<pre><code>(define (big x y)
(if (> x y) x y))
(define (p a b c)
(cond ((> a b) (+ (square a) (square (big b c))))
(else (+ (square b) (square (big a c))))))
</code></pre>
|
[
{
"answer_id": 161674,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 3,
"selected": true,
"text": "(define (max2 . l)\n (lambda ()\n (let ((a (apply max l)))\n (values a (apply max (remv a l))))))\n\n(define (q a b c)\n (call-with-values (max2 a b c)\n (lambda (a b)\n (+ (* a a) (* b b)))))\n\n(define (skip-min . l)\n (lambda ()\n (apply values (remv (apply min l) l))))\n\n(define (p a b c)\n (call-with-values (skip-min a b c)\n (lambda (a b)\n (+ (* a a) (* b b)))))\n"
},
{
"answer_id": 161675,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 4,
"selected": false,
"text": "big max (define (exercise1.3 a b c)\n (let ((smallest (min a b c))\n (square (lambda (x) (* x x))))\n (+ (square a) (square b) (square c) (- (square smallest)))))\n if (define (exercise1.3 . args)\n (let ((sorted (sort! args >))\n (square (lambda (x) (* x x))))\n (+ (square (car sorted)) (square (cadr sorted)))))\n (define (exercise1.3 . args)\n (apply + (map! (cut expt <> 2) (take! (sort! args >) 2))))\n"
},
{
"answer_id": 161720,
"author": "Sébastien RoccaSerra",
"author_id": 2797,
"author_profile": "https://Stackoverflow.com/users/2797",
"pm_score": 2,
"selected": false,
"text": "(require (lib \"list.ss\")) ;; I use PLT Scheme\n\n(define (exercise-1-3 a b c)\n (let* [(sorted-list (sort (list a b c) >))\n (x (first sorted-list))\n (y (second sorted-list))]\n (+ (* x x) (* y y))))\n"
},
{
"answer_id": 610719,
"author": "Scott Hoffman",
"author_id": 50640,
"author_profile": "https://Stackoverflow.com/users/50640",
"pm_score": 4,
"selected": false,
"text": "(define (p a b c)\n (if (> a b)\n (if (> b c)\n (+ (square a) (square b))\n (+ (square a) (square c)))\n (if (> a c)\n (+ (square a) (square b))\n (+ (square b) (square c)))))\n"
},
{
"answer_id": 1084304,
"author": "Shawn J. Goff",
"author_id": 251561,
"author_profile": "https://Stackoverflow.com/users/251561",
"pm_score": 3,
"selected": false,
"text": "(define (smallest-of-three a b c)\n (if (< a b)\n (if (< a c) a c)\n (if (< b c) b c)))\n\n(define (square a)\n (* a a))\n\n(define (sum-of-squares-largest a b c) \n (+ (square a)\n (square b)\n (square c)\n (- (square (smallest-of-three a b c)))))\n"
},
{
"answer_id": 1161816,
"author": "Carlos Santos",
"author_id": 119399,
"author_profile": "https://Stackoverflow.com/users/119399",
"pm_score": 5,
"selected": false,
"text": "(define (square x) (* x x))\n\n(define (sum-of-squares x y) (+ (square x) (square y)))\n\n(define (min x y) (if (< x y) x y))\n\n(define (max x y) (if (> x y) x y))\n\n(define (sum-squares-2-biggest x y z)\n (sum-of-squares (max x y) (max z (min x y))))\n"
},
{
"answer_id": 1518167,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 4,
"selected": false,
"text": "min max square (define (sum-of-highest-squares x y z)\n (+ (square (max x y))\n (square (max (min x y) z))))\n"
},
{
"answer_id": 1881239,
"author": "Christy John",
"author_id": 147671,
"author_profile": "https://Stackoverflow.com/users/147671",
"pm_score": 2,
"selected": false,
"text": "(define (p a b c)\n (cond ((> a b)\n (cond ((> b c)\n (+ (square a) (square b)))\n (else (+ (square a) (square c)))))\n (else\n (cond ((> a c)\n (+ (square b) (square a))))\n (+ (square b) (square c)))))\n"
},
{
"answer_id": 1997522,
"author": "Eric",
"author_id": 242969,
"author_profile": "https://Stackoverflow.com/users/242969",
"pm_score": 0,
"selected": false,
"text": "(define (procedure a b c)\n (let ((y (sort (list a b c) >)) (square (lambda (x) (* x x))))\n (+ (square (first y)) (square(second y)))))\n"
},
{
"answer_id": 4664891,
"author": "andres.santana",
"author_id": 439847,
"author_profile": "https://Stackoverflow.com/users/439847",
"pm_score": 0,
"selected": false,
"text": ";exercise 1.3\n(define (sum-square-of-max a b c)\n (+ (if (> a b) (* a a) (* b b))\n (if (> b c) (* b b) (* c c))))\n"
},
{
"answer_id": 9061733,
"author": "Scott Miao",
"author_id": 1177608,
"author_profile": "https://Stackoverflow.com/users/1177608",
"pm_score": 3,
"selected": false,
"text": "(define (sum-sqr x y)\n(+ (square x) (square y)))\n\n(define (sum-squares-2-of-3 x y z)\n (cond ((and (<= x y) (<= x z)) (sum-sqr y z))\n ((and (<= y x) (<= y z)) (sum-sqr x z))\n ((and (<= z x) (<= z y)) (sum-sqr x y))))\n"
},
{
"answer_id": 9065099,
"author": "user448810",
"author_id": 448810,
"author_profile": "https://Stackoverflow.com/users/448810",
"pm_score": 3,
"selected": false,
"text": "(define (f a b c) \n (if (= a (min a b c)) \n (+ (* b b) (* c c)) \n (f b c a)))\n"
},
{
"answer_id": 22533758,
"author": "riddhi_agrawal",
"author_id": 826050,
"author_profile": "https://Stackoverflow.com/users/826050",
"pm_score": 1,
"selected": false,
"text": "(define (sum a b) (+ a b))\n(define (square a) (* a a))\n(define (greater a b ) \n ( if (< a b) b a))\n(define (smaller a b ) \n ( if (< a b) a b))\n(define (sumOfSquare a b)\n (sum (square a) (square b)))\n(define (sumOfSquareOfGreaterNumbers a b c)\n (sumOfSquare (greater a b) (greater (smaller a b) c)))\n"
},
{
"answer_id": 28664937,
"author": "Elliot Gorokhovsky",
"author_id": 3154996,
"author_profile": "https://Stackoverflow.com/users/3154996",
"pm_score": 0,
"selected": false,
"text": "(define (square-sum-larger a b c)\n (+ \n (square (max a b))\n (square (max (min a b) c))))\n"
},
{
"answer_id": 45962062,
"author": "Ethan Barrett",
"author_id": 5670477,
"author_profile": "https://Stackoverflow.com/users/5670477",
"pm_score": 0,
"selected": false,
"text": " ; Exercise 1.3\n(define (sum-square-largest a b c)\n (+ (square (greatest a b))\n (square (greatest (least a b) c))))\n\n(define (greatest a b)\n (cond (( > a b) a)\n (( < a b) b)))\n\n(define (least a b)\n (cond ((> a b) b)\n ((< a b) a)))\n\n(define (square a)\n (* a a))\n"
},
{
"answer_id": 51550302,
"author": "Joseph Glass",
"author_id": 10142260,
"author_profile": "https://Stackoverflow.com/users/10142260",
"pm_score": 2,
"selected": false,
"text": "(define (isGreater? x y z)\n(if (and (> x z) (> y z))\n(+ (square x) (square y))\n0))\n\n(define (sumLarger x y z)\n(if (= (isGreater? x y z) 0) \n(sumLarger y z x)\n(isGreater? x y z)))\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161666",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24457/"
] |
161,672
|
<p>I noticed some code of a colleague today that initialized class variables in the initialization. However it was causing a warning, he says because of the order they are in. My question is why is it better to do variable initialization where it currently is and not within the curly brackets?</p>
<pre><code>DiagramScene::DiagramScene( int slideNo, QRectF screenRect, MainWindow* parent )
: QGraphicsScene( screenRect, parent ),
myParent( parent ),
slideUndoImageCurrentIndex(-1),
nextGroupID(0),
m_undoInProgress(false),
m_deleteItemOnNextUndo(0)
line(0),
path(0)
{
/* Setup default brush for background */
scDetail->bgBrush.setStyle(Qt::SolidPattern);
scDetail->bgBrush.setColor(Qt::white);
setBackgroundBrush(scDetail->bgBrush);
}
</code></pre>
|
[
{
"answer_id": 161684,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 6,
"selected": true,
"text": "const const"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24459/"
] |
161,676
|
<p>I'm running zsh as the default shell on a Ubuntu box, and everything works fine using gnome-terminal (which as far as I know emulates xterm). When I login from a windows box via ssh and putty (which also emulates xterm) suddendly the home/end keys no longer work. </p>
<p>I've been able to solve that adding these lines to my zshrc file...</p>
<pre><code>bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
</code></pre>
<p>...but I'm still wondering what's wrong here. Any idea?</p>
|
[
{
"answer_id": 162125,
"author": "agnul",
"author_id": 6069,
"author_profile": "https://Stackoverflow.com/users/6069",
"pm_score": 2,
"selected": false,
"text": "^[OH ^[OF ^[[1~ ^[[4~ ^[Ow"
},
{
"answer_id": 686458,
"author": "hopla",
"author_id": 82011,
"author_profile": "https://Stackoverflow.com/users/82011",
"pm_score": 7,
"selected": true,
"text": "/etc/zsh/zshrc if [[ \"$TERM\" != emacs ]]; then\n[[ -z \"$terminfo[kdch1]\" ]] || bindkey -M emacs \"$terminfo[kdch1]\" delete-char\n[[ -z \"$terminfo[khome]\" ]] || bindkey -M emacs \"$terminfo[khome]\" beginning-of-line\n[[ -z \"$terminfo[kend]\" ]] || bindkey -M emacs \"$terminfo[kend]\" end-of-line\n[[ -z \"$terminfo[kich1]\" ]] || bindkey -M emacs \"$terminfo[kich1]\" overwrite-mode\n[[ -z \"$terminfo[kdch1]\" ]] || bindkey -M vicmd \"$terminfo[kdch1]\" vi-delete-char\n[[ -z \"$terminfo[khome]\" ]] || bindkey -M vicmd \"$terminfo[khome]\" vi-beginning-of-line\n[[ -z \"$terminfo[kend]\" ]] || bindkey -M vicmd \"$terminfo[kend]\" vi-end-of-line\n[[ -z \"$terminfo[kich1]\" ]] || bindkey -M vicmd \"$terminfo[kich1]\" overwrite-mode\n\n[[ -z \"$terminfo[cuu1]\" ]] || bindkey -M viins \"$terminfo[cuu1]\" vi-up-line-or-history\n[[ -z \"$terminfo[cuf1]\" ]] || bindkey -M viins \"$terminfo[cuf1]\" vi-forward-char\n[[ -z \"$terminfo[kcuu1]\" ]] || bindkey -M viins \"$terminfo[kcuu1]\" vi-up-line-or-history\n[[ -z \"$terminfo[kcud1]\" ]] || bindkey -M viins \"$terminfo[kcud1]\" vi-down-line-or-history\n[[ -z \"$terminfo[kcuf1]\" ]] || bindkey -M viins \"$terminfo[kcuf1]\" vi-forward-char\n[[ -z \"$terminfo[kcub1]\" ]] || bindkey -M viins \"$terminfo[kcub1]\" vi-backward-char\n\n# ncurses fogyatekos\n[[ \"$terminfo[kcuu1]\" == \"^[O\"* ]] && bindkey -M viins \"${terminfo[kcuu1]/O/[}\" vi-up-line-or-history\n[[ \"$terminfo[kcud1]\" == \"^[O\"* ]] && bindkey -M viins \"${terminfo[kcud1]/O/[}\" vi-down-line-or-history\n[[ \"$terminfo[kcuf1]\" == \"^[O\"* ]] && bindkey -M viins \"${terminfo[kcuf1]/O/[}\" vi-forward-char\n[[ \"$terminfo[kcub1]\" == \"^[O\"* ]] && bindkey -M viins \"${terminfo[kcub1]/O/[}\" vi-backward-char\n[[ \"$terminfo[khome]\" == \"^[O\"* ]] && bindkey -M viins \"${terminfo[khome]/O/[}\" beginning-of-line\n[[ \"$terminfo[kend]\" == \"^[O\"* ]] && bindkey -M viins \"${terminfo[kend]/O/[}\" end-of-line\n[[ \"$terminfo[khome]\" == \"^[O\"* ]] && bindkey -M emacs \"${terminfo[khome]/O/[}\" beginning-of-line\n[[ \"$terminfo[kend]\" == \"^[O\"* ]] && bindkey -M emacs \"${terminfo[kend]/O/[}\" end-of-line\nfi\n zshrc zshrc .zshrc xterm xterm xterm xterm xterm xterm-color linux xterm-color linux .zshrc export TERM=linux linux"
},
{
"answer_id": 10377906,
"author": "Josh McGee",
"author_id": 1271512,
"author_profile": "https://Stackoverflow.com/users/1271512",
"pm_score": 3,
"selected": false,
"text": "zsh -f ~/zsh-4.3.17/Functions/Misc/zkbd\n source . source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE\n [[ -n ${key[Left]} ]] && bindkey \"${key[Left]}\" backward-char\n [[ -n ${key[Right]} ]] && bindkey \"${key[Right]}\" forward-char\n # etc.\n autoload zkbd zkbd man -P \"less -p 'keyboard definition'\" zshcontrib zshall"
},
{
"answer_id": 26861174,
"author": "Rene",
"author_id": 3124469,
"author_profile": "https://Stackoverflow.com/users/3124469",
"pm_score": 3,
"selected": false,
"text": "bindkey -v\n\nbindkey '\\eOH' beginning-of-line\nbindkey '\\eOF' end-of-line\n"
},
{
"answer_id": 59054483,
"author": "Zenexer",
"author_id": 1188377,
"author_profile": "https://Stackoverflow.com/users/1188377",
"pm_score": 3,
"selected": false,
"text": "putty TERM xterm putty-256color putty-256color toe -a | grep -F putty putty-256color COLORTERM truecolor /etc/ssh/sshd_config COLORTERM AcceptEnv exec zsh TERM TERM TERM echo $TERM screen tmux TERM=tmux-256color TERM=screen-256color"
},
{
"answer_id": 70126402,
"author": "jordiburgos",
"author_id": 1108098,
"author_profile": "https://Stackoverflow.com/users/1108098",
"pm_score": 0,
"selected": false,
"text": "bindkey \"\\e[1;5D\" backward-word\nbindkey \"\\e[1;5C\" forward-word\n\n# ctrl-bs and ctrl-del\nbindkey \"\\e[3;5~\" kill-word\nbindkey \"\\C-_\" backward-kill-word\n\n# del, home and end\nbindkey \"\\e[3~\" delete-char\nbindkey \"\\e[H\" beginning-of-line\nbindkey \"\\e[F\" end-of-line\n\n# alt-bs\nbindkey \"\\e\\d\" undo\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6069/"
] |
161,687
|
<p>You sometimes hear it said about Perl that there might be 6 different ways to approach the same problem. Good Perl developers usually have well-reasoned insights for making choices between the various possible methods of implementation.</p>
<p>So an example Perl problem:</p>
<p>A simple script which recursively iterates through a directory structure, looking for files which were modified recently (after a certain date, which would be variable). Save the results to a file.</p>
<p>The question, for Perl developers: What is your best way to accomplish this?</p>
|
[
{
"answer_id": 161740,
"author": "antik",
"author_id": 1625,
"author_profile": "https://Stackoverflow.com/users/1625",
"pm_score": -1,
"selected": false,
"text": "readdir utime stat"
},
{
"answer_id": 161762,
"author": "workmad3",
"author_id": 16035,
"author_profile": "https://Stackoverflow.com/users/16035",
"pm_score": 2,
"selected": false,
"text": "use File::Find;\nfind (\\&checkFile, $directory_to_check_recursively);\n\nsub checkFile()\n{\n #examine each file in here. Filename is in $_ and you are chdired into it's directory\n #directory is also available in $File::Find::dir\n}\n"
},
{
"answer_id": 161766,
"author": "Philip Reynolds",
"author_id": 1087,
"author_profile": "https://Stackoverflow.com/users/1087",
"pm_score": 4,
"selected": false,
"text": "#!/usr/bin/perl\n\nuse strict;\nuse File::Find();\n\nFile::Find::find( {wanted => \\&wanted}, \".\");\n\nsub wanted {\n my (@stat);\n my ($time) = time();\n my ($days) = 5 * 60 * 60 * 24;\n\n @stat = stat($_);\n if (($time - $stat[9]) >= $days) {\n print \"$_ \\n\";\n }\n}\n"
},
{
"answer_id": 162436,
"author": "pjf",
"author_id": 19422,
"author_profile": "https://Stackoverflow.com/users/19422",
"pm_score": 5,
"selected": true,
"text": "#!/usr/bin/perl\nuse strict;\nuse warnings;\nuse autodie; # Causes built-ins like open to succeed or die.\n # You can 'use Fatal qw(open)' if autodie is not installed.\n\nuse File::Find::Rule;\nuse Getopt::Std;\n\nuse constant SECONDS_IN_DAY => 24 * 60 * 60;\n\nour %option = (\n m => 1, # -m switch: days ago modified, defaults to 1\n o => undef, # -o switch: output file, defaults to STDOUT\n);\n\ngetopts('m:o:', \\%option);\n\n# If we haven't been given directories to search, default to the\n# current working directory.\n\nif (not @ARGV) {\n @ARGV = ( '.' );\n}\n\nprint STDERR \"Finding files changed in the last $option{m} day(s)\\n\";\n\n\n# Convert our time in days into a timestamp in seconds from the epoch.\nmy $last_modified_timestamp = time() - SECONDS_IN_DAY * $option{m};\n\n# Now find all the regular files, which have been modified in the last\n# $option{m} days, looking in all the locations specified in\n# @ARGV (our remaining command line arguments).\n\nmy @files = File::Find::Rule->file()\n ->mtime(\">= $last_modified_timestamp\")\n ->in(@ARGV);\n\n# $out_fh will store the filehandle where we send the file list.\n# It defaults to STDOUT.\n\nmy $out_fh = \\*STDOUT;\n\nif ($option{o}) {\n open($out_fh, '>', $option{o});\n}\n\n# Print our results.\n\nprint {$out_fh} join(\"\\n\", @files), \"\\n\";\n"
},
{
"answer_id": 162502,
"author": "dland",
"author_id": 18625,
"author_profile": "https://Stackoverflow.com/users/18625",
"pm_score": 3,
"selected": false,
"text": "#! /usr/bin/perl -w\n\n# delete temp files on agr1\n\nuse strict;\nuse File::Find::Rule;\nuse File::Path 'rmtree';\n\nfor my $file (\n\n File::Find::Rule->new\n ->mtime( '<' . days_ago(2) )\n ->name( qr/^CGItemp\\d+$/ )\n ->file()\n ->in('/tmp'),\n\n File::Find::Rule->new\n ->mtime( '<' . days_ago(20) )\n ->name( qr/^listener-\\d{4}-\\d{2}-\\d{2}-\\d{4}.log$/ )\n ->file()\n ->maxdepth(1)\n ->in('/usr/oracle/ora81/network/log'),\n\n File::Find::Rule->new\n ->mtime( '<' . days_ago(10) )\n ->name( qr/^batch[_-]\\d{8}-\\d{4}\\.run\\.txt$/ )\n ->file()\n ->maxdepth(1)\n ->in('/var/log/req'),\n\n File::Find::Rule->new\n ->mtime( '<' . days_ago(20) )\n ->or(\n File::Find::Rule->name( qr/^remove-\\d{8}-\\d{6}\\.txt$/ ),\n File::Find::Rule->name( qr/^insert-tp-\\d{8}-\\d{4}\\.log$/ ),\n )\n ->file()\n ->maxdepth(1)\n ->in('/home/agdata/import/logs'),\n\n File::Find::Rule->new\n ->mtime( '<' . days_ago(90) )\n ->or(\n File::Find::Rule->name( qr/^\\d{8}-\\d{6}\\.txt$/ ),\n File::Find::Rule->name( qr/^\\d{8}-\\d{4}\\.report\\.txt$/ ),\n )\n ->file()\n ->maxdepth(1)\n ->in('/home/agdata/redo/log'),\n\n) {\n if (unlink $file) {\n print \"ok $file\\n\";\n }\n else {\n print \"fail $file: $!\\n\";\n }\n}\n\n{\n my $now;\n sub days_ago {\n # days as number of seconds\n $now ||= time;\n return $now - (86400 * shift);\n }\n}\n"
},
{
"answer_id": 4621689,
"author": "Hien",
"author_id": 566287,
"author_profile": "https://Stackoverflow.com/users/566287",
"pm_score": 0,
"selected": false,
"text": "sub mfind {\n my %done;\n\n sub find {\n my $last_mod = shift;\n my $path = shift;\n\n #determine physical link if symlink\n $path = readlink($path) || $path; \n\n #return if already processed\n return if $done{$path} > 1;\n\n #mark path as processed\n $done{$path}++;\n\n #DFS recursion \n return grep{$_} @_\n ? ( find($last_mod, $path), find($last_mod, @_) ) \n : -d $path\n ? find($last_mod, glob(\"$path/*\") )\n : -f $path && (stat($path))[9] >= $last_mod \n ? $path : undef;\n }\n\n return find(@_);\n}\n\nprint join \"\\n\", mfind(time - 1 * 86400, \"some path\");\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19468/"
] |
161,698
|
<p>I'm using a local artifactory to proxy the request, but the build and test phases are still a bit slow. It's not the actual compile and tests that are slow, it's the "warmup" of the maven2 framework. Any ideas?</p>
|
[
{
"answer_id": 161710,
"author": "Henry B",
"author_id": 6414,
"author_profile": "https://Stackoverflow.com/users/6414",
"pm_score": 3,
"selected": false,
"text": "-Dmaven.junit.fork=true\n-Dmaven.junit.jvmargs=-Xmx512m\n -Dmaven.compile.fork=true\n"
},
{
"answer_id": 8661057,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "-DskipTests=true"
},
{
"answer_id": 31427187,
"author": "facundofarias",
"author_id": 3009370,
"author_profile": "https://Stackoverflow.com/users/3009370",
"pm_score": 3,
"selected": false,
"text": "$ mvn -version $ mvn clean install \n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 03:05 min\n[INFO] Finished at: 2015-07-15T11:47:02+02:00\n[INFO] Final Memory: 88M/384M\n $ mvn -T 4 clean install\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 02:22 min (Wall Clock)\n[INFO] Finished at: 2015-07-15T11:50:57+02:00\n[INFO] Final Memory: 80M/533M\n $ mvn -T 2C clean install\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 02:12 min (Wall Clock)\n[INFO] Finished at: 2015-07-15T12:00:29+02:00\n[INFO] Final Memory: 87M/519M\n[INFO] ------------------------------------------------------------------------\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161698",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17554/"
] |
161,717
|
<p>If I create a function with jQuery that adds an empty div, performs some animation inside the blank space created by the div, then removes the div, the browser never makes room for the empty div (height and width are set).</p>
<p>If I don't remove the empty div in my function, then the browser will create the needed space and everything works correctly. However, I really need the blank space created by the div to be removed when the animation is complete.</p>
<p>Is there a way to queue up the div removall so that the browser will show the desired behavior?</p>
|
[
{
"answer_id": 263947,
"author": "SeanDowney",
"author_id": 5261,
"author_profile": "https://Stackoverflow.com/users/5261",
"pm_score": 2,
"selected": false,
"text": "$('#someDiv').slideDown(100, function() { \n $(this).remove(); \n});\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4820/"
] |
161,738
|
<p>How can I check if a given string is a valid URL address?</p>
<p>My knowledge of regular expressions is basic and doesn't allow me to choose from the hundreds of regular expressions I've already seen on the web.</p>
|
[
{
"answer_id": 161756,
"author": "Duncan Smart",
"author_id": 1278,
"author_profile": "https://Stackoverflow.com/users/1278",
"pm_score": 6,
"selected": false,
"text": "System.Uri.TryCreate static bool IsValidUrl(string urlString)\n{\n Uri uri;\n return Uri.TryCreate(urlString, UriKind.Absolute, out uri)\n && (uri.Scheme == Uri.UriSchemeHttp\n || uri.Scheme == Uri.UriSchemeHttps\n || uri.Scheme == Uri.UriSchemeFtp\n || uri.Scheme == Uri.UriSchemeMailto\n /*...*/);\n}\n\n// In test fixture...\n\n[Test]\nvoid IsValidUrl_Test()\n{\n Assert.True(IsValidUrl(\"http://www.example.com\"));\n Assert.False(IsValidUrl(\"javascript:alert('xss')\"));\n Assert.False(IsValidUrl(\"\"));\n Assert.False(IsValidUrl(null));\n}\n javascript:"
},
{
"answer_id": 161779,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 4,
"selected": false,
"text": " ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?\n"
},
{
"answer_id": 163684,
"author": "Keng",
"author_id": 730,
"author_profile": "https://Stackoverflow.com/users/730",
"pm_score": 6,
"selected": false,
"text": "(\\b(https?|ftp|file)://)?[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]\n ** ** **http://www.regexbuddy.com** \n**http://www.regexbuddy.com/** \n**http://www.regexbuddy.com/index.html** \n**http://www.regexbuddy.com/index.html?source=library** \n**http://www.regexbuddy.com/index.html?source=library#copyright** \n"
},
{
"answer_id": 190405,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 9,
"selected": false,
"text": "/^[a-z](?:[-a-z0-9\\+\\.])*:(?:\\/\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:])*@)?(?:\\[(?:(?:(?:[0-9a-f]{1,4}:){6}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|::(?:[0-9a-f]{1,4}:){5}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+\\.[-a-z0-9\\._~!\\$&'\\(\\)\\*\\+,;=:]+)\\]|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}|(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=])*)(?::[0-9]*)?(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*|\\/(?:(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*)?|(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*|(?!(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])))(?:\\?(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])|[\\x{E000}-\\x{F8FF}\\x{F0000}-\\x{FFFFD}\\x{100000}-\\x{10FFFD}\\/\\?])*)?(?:\\#(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])|[\\/\\?])*)?$/i\n /^(?:[a-z](?:[-a-z0-9\\+\\.])*:(?:\\/\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:])*@)?(?:\\[(?:(?:(?:[0-9a-f]{1,4}:){6}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|::(?:[0-9a-f]{1,4}:){5}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+\\.[-a-z0-9\\._~!\\$&'\\(\\)\\*\\+,;=:]+)\\]|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}|(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=])*)(?::[0-9]*)?(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*|\\/(?:(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*)?|(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*|(?!(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])))(?:\\?(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])|[\\x{E000}-\\x{F8FF}\\x{F0000}-\\x{FFFFD}\\x{100000}-\\x{10FFFD}\\/\\?])*)?(?:\\#(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])|[\\/\\?])*)?|(?:\\/\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:])*@)?(?:\\[(?:(?:(?:[0-9a-f]{1,4}:){6}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|::(?:[0-9a-f]{1,4}:){5}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+\\.[-a-z0-9\\._~!\\$&'\\(\\)\\*\\+,;=:]+)\\]|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}|(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=])*)(?::[0-9]*)?(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*|\\/(?:(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*)?|(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=@])+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@]))*)*|(?!(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])))(?:\\?(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])|[\\x{E000}-\\x{F8FF}\\x{F0000}-\\x{FFFFD}\\x{100000}-\\x{10FFFD}\\/\\?])*)?(?:\\#(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}!\\$&'\\(\\)\\*\\+,;=:@])|[\\/\\?])*)?)$/i\n <?php\n\n/* Regex convenience functions (character class, non-capturing group) */\nfunction cc($str, $suffix = '', $negate = false) {\n return '[' . ($negate ? '^' : '') . $str . ']' . $suffix;\n}\nfunction ncg($str, $suffix = '') {\n return '(?:' . $str . ')' . $suffix;\n}\n\n/* Preserved from RFC3986 */\n\n$ALPHA = 'a-z';\n$DIGIT = '0-9';\n$HEXDIG = $DIGIT . 'a-f';\n\n$sub_delims = '!\\\\$&\\'\\\\(\\\\)\\\\*\\\\+,;=';\n$gen_delims = ':\\\\/\\\\?\\\\#\\\\[\\\\]@';\n$reserved = $gen_delims . $sub_delims;\n$unreserved = '-' . $ALPHA . $DIGIT . '\\\\._~';\n\n$pct_encoded = '%' . cc($HEXDIG) . cc($HEXDIG);\n\n$dec_octet = ncg(implode('|', array(\n cc($DIGIT),\n cc('1-9') . cc($DIGIT),\n '1' . cc($DIGIT) . cc($DIGIT),\n '2' . cc('0-4') . cc($DIGIT),\n '25' . cc('0-5')\n)));\n\n$IPv4address = $dec_octet . ncg('\\\\.' . $dec_octet, '{3}');\n\n$h16 = cc($HEXDIG, '{1,4}');\n$ls32 = ncg($h16 . ':' . $h16 . '|' . $IPv4address);\n\n$IPv6address = ncg(implode('|', array(\n ncg($h16 . ':', '{6}') . $ls32,\n '::' . ncg($h16 . ':', '{5}') . $ls32,\n ncg($h16, '?') . '::' . ncg($h16 . ':', '{4}') . $ls32,\n ncg($h16 . ':' . $h16, '?') . '::' . ncg($h16 . ':', '{3}') . $ls32,\n ncg(ncg($h16 . ':', '{0,2}') . $h16, '?') . '::' . ncg($h16 . ':', '{2}') . $ls32,\n ncg(ncg($h16 . ':', '{0,3}') . $h16, '?') . '::' . $h16 . ':' . $ls32,\n ncg(ncg($h16 . ':', '{0,4}') . $h16, '?') . '::' . $ls32,\n ncg(ncg($h16 . ':', '{0,5}') . $h16, '?') . '::' . $h16,\n ncg(ncg($h16 . ':', '{0,6}') . $h16, '?') . '::',\n)));\n\n$IPvFuture = 'v' . cc($HEXDIG, '+') . cc($unreserved . $sub_delims . ':', '+');\n\n$IP_literal = '\\\\[' . ncg(implode('|', array($IPv6address, $IPvFuture))) . '\\\\]';\n\n$port = cc($DIGIT, '*');\n\n$scheme = cc($ALPHA) . ncg(cc('-' . $ALPHA . $DIGIT . '\\\\+\\\\.'), '*');\n\n/* New or changed in RFC3987 */\n\n$iprivate = '\\x{E000}-\\x{F8FF}\\x{F0000}-\\x{FFFFD}\\x{100000}-\\x{10FFFD}';\n\n$ucschar = '\\x{A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}' .\n '\\x{10000}-\\x{1FFFD}\\x{20000}-\\x{2FFFD}\\x{30000}-\\x{3FFFD}' .\n '\\x{40000}-\\x{4FFFD}\\x{50000}-\\x{5FFFD}\\x{60000}-\\x{6FFFD}' .\n '\\x{70000}-\\x{7FFFD}\\x{80000}-\\x{8FFFD}\\x{90000}-\\x{9FFFD}' .\n '\\x{A0000}-\\x{AFFFD}\\x{B0000}-\\x{BFFFD}\\x{C0000}-\\x{CFFFD}' .\n '\\x{D0000}-\\x{DFFFD}\\x{E1000}-\\x{EFFFD}';\n\n$iunreserved = '-' . $ALPHA . $DIGIT . '\\\\._~' . $ucschar;\n\n$ipchar = ncg($pct_encoded . '|' . cc($iunreserved . $sub_delims . ':@'));\n\n$ifragment = ncg($ipchar . '|' . cc('\\\\/\\\\?'), '*');\n\n$iquery = ncg($ipchar . '|' . cc($iprivate . '\\\\/\\\\?'), '*');\n\n$isegment_nz_nc = ncg($pct_encoded . '|' . cc($iunreserved . $sub_delims . '@'), '+');\n$isegment_nz = ncg($ipchar, '+');\n$isegment = ncg($ipchar, '*');\n\n$ipath_empty = '(?!' . $ipchar . ')';\n$ipath_rootless = ncg($isegment_nz) . ncg('\\\\/' . $isegment, '*');\n$ipath_noscheme = ncg($isegment_nz_nc) . ncg('\\\\/' . $isegment, '*');\n$ipath_absolute = '\\\\/' . ncg($ipath_rootless, '?'); // Spec says isegment-nz *( \"/\" isegment )\n$ipath_abempty = ncg('\\\\/' . $isegment, '*');\n\n$ipath = ncg(implode('|', array(\n $ipath_abempty,\n $ipath_absolute,\n $ipath_noscheme,\n $ipath_rootless,\n $ipath_empty\n))) . ')';\n\n$ireg_name = ncg($pct_encoded . '|' . cc($iunreserved . $sub_delims . '@'), '*');\n\n$ihost = ncg(implode('|', array($IP_literal, $IPv4address, $ireg_name)));\n$iuserinfo = ncg($pct_encoded . '|' . cc($iunreserved . $sub_delims . ':'), '*');\n$iauthority = ncg($iuserinfo . '@', '?') . $ihost . ncg(':' . $port, '?');\n\n$irelative_part = ncg(implode('|', array(\n '\\\\/\\\\/' . $iauthority . $ipath_abempty . '',\n '' . $ipath_absolute . '',\n '' . $ipath_noscheme . '',\n '' . $ipath_empty . ''\n)));\n\n$irelative_ref = $irelative_part . ncg('\\\\?' . $iquery, '?') . ncg('\\\\#' . $ifragment, '?');\n\n$ihier_part = ncg(implode('|', array(\n '\\\\/\\\\/' . $iauthority . $ipath_abempty . '',\n '' . $ipath_absolute . '',\n '' . $ipath_rootless . '',\n '' . $ipath_empty . ''\n)));\n\n$absolute_IRI = $scheme . ':' . $ihier_part . ncg('\\\\?' . $iquery, '?');\n\n$IRI = $scheme . ':' . $ihier_part . ncg('\\\\?' . $iquery, '?') . ncg('\\\\#' . $ifragment, '?');\n\n$IRI_reference = ncg($IRI . '|' . $irelative_ref);\n $escape_backslash = '/(?<!\\\\)\\\\(?![\\[\\]\\\\\\^\\$\\.\\|\\*\\+\\(\\)QEnrtaefvdwsDWSbAZzB1-9GX]|x\\{[0-9a-f]{1,4}\\}|\\c[A-Z]|)/';\n$absolute_IRI = preg_replace($escape_backslash, '\\\\\\\\', $absolute_IRI);\n$IRI = preg_replace($escape_backslash, '\\\\\\\\', $IRI);\n$IRI_reference = preg_replace($escape_backslash, '\\\\\\\\', $IRI_reference);\n"
},
{
"answer_id": 2015516,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": false,
"text": ")|((\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])\\.){3}(?#\n /^(https?|ftp):\\/\\/(?# protocol\n)(([a-z0-9$_\\.\\+!\\*\\'\\(\\),;\\?&=-]|%[0-9a-f]{2})+(?# username\n)(:([a-z0-9$_\\.\\+!\\*\\'\\(\\),;\\?&=-]|%[0-9a-f]{2})+)?(?# password\n)@)?(?# auth requires @\n)((([a-z0-9]\\.|[a-z0-9][a-z0-9-]*[a-z0-9]\\.)*(?# domain segments AND\n)[a-z][a-z0-9-]*[a-z0-9](?# top level domain OR\n)|((\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])\\.){3}(?#\n )(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])(?# IP address\n))(:\\d+)?(?# port\n))(((\\/+([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)*(?# path\n)(\\?([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)(?# query string\n)?)?)?(?# path and query string optional\n)(#([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)?(?# fragment\n)$/i\n define('URL_FORMAT', \n'/^(https?):\\/\\/'. // protocol\n'(([a-z0-9$_\\.\\+!\\*\\'\\(\\),;\\?&=-]|%[0-9a-f]{2})+'. // username\n'(:([a-z0-9$_\\.\\+!\\*\\'\\(\\),;\\?&=-]|%[0-9a-f]{2})+)?'. // password\n'@)?(?#'. // auth requires @\n')((([a-z0-9]\\.|[a-z0-9][a-z0-9-]*[a-z0-9]\\.)*'. // domain segments AND\n'[a-z][a-z0-9-]*[a-z0-9]'. // top level domain OR\n'|((\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])\\.){3}'.\n'(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])'. // IP address\n')(:\\d+)?'. // port\n')(((\\/+([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)*'. // path\n'(\\?([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)'. // query string\n'?)?)?'. // path and query string optional\n'(#([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)?'. // fragment\n'$/i');\n <?php\n\ndefine('URL_FORMAT',\n'/^(https?):\\/\\/'. // protocol\n'(([a-z0-9$_\\.\\+!\\*\\'\\(\\),;\\?&=-]|%[0-9a-f]{2})+'. // username\n'(:([a-z0-9$_\\.\\+!\\*\\'\\(\\),;\\?&=-]|%[0-9a-f]{2})+)?'. // password\n'@)?(?#'. // auth requires @\n')((([a-z0-9]\\.|[a-z0-9][a-z0-9-]*[a-z0-9]\\.)*'. // domain segments AND\n'[a-z][a-z0-9-]*[a-z0-9]'. // top level domain OR\n'|((\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])\\.){3}'.\n'(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])'. // IP address\n')(:\\d+)?'. // port\n')(((\\/+([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)*'. // path\n'(\\?([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)'. // query string\n'?)?)?'. // path and query string optional\n'(#([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)?'. // fragment\n'$/i');\n\n/**\n * Verify the syntax of the given URL. \n * \n * @access public\n * @param $url The URL to verify.\n * @return boolean\n */\nfunction is_valid_url($url) {\n if (str_starts_with(strtolower($url), 'http://localhost')) {\n return true;\n }\n return preg_match(URL_FORMAT, $url);\n}\n\n\n/**\n * String starts with something\n * \n * This function will return true only if input string starts with\n * niddle\n * \n * @param string $string Input string\n * @param string $niddle Needle string\n * @return boolean\n */\nfunction str_starts_with($string, $niddle) {\n return substr($string, 0, strlen($niddle)) == $niddle;\n}\n\n\n/**\n * Test a URL for validity and count results.\n * @param url url\n * @param expected expected result (true or false)\n */\n\n$numtests = 0;\n$passed = 0;\n\nfunction test_url($url, $expected) {\n global $numtests, $passed;\n $numtests++;\n $valid = is_valid_url($url);\n echo \"URL Valid?: \" . ($valid?\"yes\":\"no\") . \" for URL: $url. Expected: \".($expected?\"yes\":\"no\").\". \";\n if($valid == $expected) {\n echo \"PASS\\n\"; $passed++;\n } else {\n echo \"FAIL\\n\";\n }\n}\n\necho \"URL Tests:\\n\\n\";\n\ntest_url(\"http://localserver/projects/public/assets/javascript/widgets/UserBoxMenu/widget.css\", true);\ntest_url(\"http://www.google.com\", true);\ntest_url(\"http://www.google.co.uk/projects/my%20folder/test.php\", true);\ntest_url(\"https://myserver.localdomain\", true);\ntest_url(\"http://192.168.1.120/projects/index.php\", true);\ntest_url(\"http://192.168.1.1/projects/index.php\", true);\ntest_url(\"http://projectpier-server.localdomain/projects/public/assets/javascript/widgets/UserBoxMenu/widget.css\", true);\ntest_url(\"https://2.4.168.19/project-pier?c=test&a=b\", true);\ntest_url(\"https://localhost/a/b/c/test.php?c=controller&arg1=20&arg2=20\", true);\ntest_url(\"http://user:password@localhost/a/b/c/test.php?c=controller&arg1=20&arg2=20\", true);\n\necho \"\\n$passed out of $numtests tests passed.\\n\\n\";\n\n?>\n"
},
{
"answer_id": 5268056,
"author": "ridgerunner",
"author_id": 433790,
"author_profile": "https://Stackoverflow.com/users/433790",
"pm_score": 3,
"selected": false,
"text": "// function url_valid($url) { Rev:20110423_2000\n//\n// Return associative array of valid URI components, or FALSE if $url is not\n// RFC-3986 compliant. If the passed URL begins with: \"www.\" or \"ftp.\", then\n// \"http://\" or \"ftp://\" is prepended and the corrected full-url is stored in\n// the return array with a key name \"url\". This value should be used by the caller.\n//\n// Return value: FALSE if $url is not valid, otherwise array of URI components:\n// e.g.\n// Given: \"http://www.jmrware.com:80/articles?height=10&width=75#fragone\"\n// Array(\n// [scheme] => http\n// [authority] => www.jmrware.com:80\n// [userinfo] =>\n// [host] => www.jmrware.com\n// [IP_literal] =>\n// [IPV6address] =>\n// [ls32] =>\n// [IPvFuture] =>\n// [IPv4address] =>\n// [regname] => www.jmrware.com\n// [port] => 80\n// [path_abempty] => /articles\n// [query] => height=10&width=75\n// [fragment] => fragone\n// [url] => http://www.jmrware.com:80/articles?height=10&width=75#fragone\n// )\nfunction url_valid($url) {\n if (strpos($url, 'www.') === 0) $url = 'http://'. $url;\n if (strpos($url, 'ftp.') === 0) $url = 'ftp://'. $url;\n if (!preg_match('/# Valid absolute URI having a non-empty, valid DNS host.\n ^\n (?P<scheme>[A-Za-z][A-Za-z0-9+\\-.]*):\\/\\/\n (?P<authority>\n (?:(?P<userinfo>(?:[A-Za-z0-9\\-._~!$&\\'()*+,;=:]|%[0-9A-Fa-f]{2})*)@)?\n (?P<host>\n (?P<IP_literal>\n \\[\n (?:\n (?P<IPV6address>\n (?: (?:[0-9A-Fa-f]{1,4}:){6}\n | ::(?:[0-9A-Fa-f]{1,4}:){5}\n | (?: [0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}\n | (?:(?:[0-9A-Fa-f]{1,4}:){0,1}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}\n | (?:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}\n | (?:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})?:: [0-9A-Fa-f]{1,4}:\n | (?:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})?::\n )\n (?P<ls32>[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}\n | (?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}\n (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\n )\n | (?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?:: [0-9A-Fa-f]{1,4}\n | (?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::\n )\n | (?P<IPvFuture>[Vv][0-9A-Fa-f]+\\.[A-Za-z0-9\\-._~!$&\\'()*+,;=:]+)\n )\n \\]\n )\n | (?P<IPv4address>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}\n (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\n | (?P<regname>(?:[A-Za-z0-9\\-._~!$&\\'()*+,;=]|%[0-9A-Fa-f]{2})+)\n )\n (?::(?P<port>[0-9]*))?\n )\n (?P<path_abempty>(?:\\/(?:[A-Za-z0-9\\-._~!$&\\'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*)\n (?:\\?(?P<query> (?:[A-Za-z0-9\\-._~!$&\\'()*+,;=:@\\\\/?]|%[0-9A-Fa-f]{2})*))?\n (?:\\#(?P<fragment> (?:[A-Za-z0-9\\-._~!$&\\'()*+,;=:@\\\\/?]|%[0-9A-Fa-f]{2})*))?\n $\n /mx', $url, $m)) return FALSE;\n switch ($m['scheme']) {\n case 'https':\n case 'http':\n if ($m['userinfo']) return FALSE; // HTTP scheme does not allow userinfo.\n break;\n case 'ftps':\n case 'ftp':\n break;\n default:\n return FALSE; // Unrecognized URI scheme. Default to FALSE.\n }\n // Validate host name conforms to DNS \"dot-separated-parts\".\n if ($m['regname']) { // If host regname specified, check for DNS conformance.\n if (!preg_match('/# HTTP DNS host name.\n ^ # Anchor to beginning of string.\n (?!.{256}) # Overall host length is less than 256 chars.\n (?: # Group dot separated host part alternatives.\n [A-Za-z0-9]\\. # Either a single alphanum followed by dot\n | # or... part has more than one char (63 chars max).\n [A-Za-z0-9] # Part first char is alphanum (no dash).\n [A-Za-z0-9\\-]{0,61} # Internal chars are alphanum plus dash.\n [A-Za-z0-9] # Part last char is alphanum (no dash).\n \\. # Each part followed by literal dot.\n )* # Zero or more parts before top level domain.\n (?: # Explicitly specify top level domains.\n com|edu|gov|int|mil|net|org|biz|\n info|name|pro|aero|coop|museum|\n asia|cat|jobs|mobi|tel|travel|\n [A-Za-z]{2}) # Country codes are exactly two alpha chars.\n \\.? # Top level domain can end in a dot.\n $ # Anchor to end of string.\n /ix', $m['host'])) return FALSE;\n }\n $m['url'] = $url;\n for ($i = 0; isset($m[$i]); ++$i) unset($m[$i]);\n return $m; // return TRUE == array of useful named $matches plus the valid $url.\n}\n"
},
{
"answer_id": 6789329,
"author": "vortex",
"author_id": 757375,
"author_profile": "https://Stackoverflow.com/users/757375",
"pm_score": 2,
"selected": false,
"text": "if(\n preg_match(\n \"/^{$IRI_reference}$/iu\",\n 'http://www.url.com'\n )\n){\n echo 'true';\n}\n Warning: preg_match() [function.preg-match]: Compilation failed: character value in \\x{...} sequence is too large at offset XX\n"
},
{
"answer_id": 8234912,
"author": "Matthew O'Riordan",
"author_id": 139607,
"author_profile": "https://Stackoverflow.com/users/139607",
"pm_score": 8,
"selected": false,
"text": "www.google.com http://www.google.com mailto:somebody@google.com somebody@google.com www.url-with-querystring.com/?url=has-querystring /((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)/\n"
},
{
"answer_id": 9284473,
"author": "Kiril",
"author_id": 28760,
"author_profile": "https://Stackoverflow.com/users/28760",
"pm_score": 6,
"selected": false,
"text": "/^(?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)+(?:[a-z\\u00a1-\\uffff]{2,}\\.?))(?::\\d{2,5})?(?:[/?#]\\S*)?$/i\n % %^(?:(?:(?:https?|ftp):)?\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\x{00a1}-\\x{ffff}][a-z0-9\\x{00a1}-\\x{ffff}_-]{0,62})?[a-z0-9\\x{00a1}-\\x{ffff}]\\.)+(?:[a-z\\x{00a1}-\\x{ffff}]{2,}\\.?))(?::\\d{2,5})?(?:[/?#]\\S*)?$%iuS\n"
},
{
"answer_id": 13069066,
"author": "LifeInstructor",
"author_id": 1524615,
"author_profile": "https://Stackoverflow.com/users/1524615",
"pm_score": 3,
"selected": false,
"text": "function validateURL(textval) {\n var urlregex = new RegExp(\n \"^(http|https|ftp)\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\\'/\\\\\\+&%\\$#\\=~])*$\");\n return urlregex.test(textval);\n }\n"
},
{
"answer_id": 13069128,
"author": "LifeInstructor",
"author_id": 1524615,
"author_profile": "https://Stackoverflow.com/users/1524615",
"pm_score": 3,
"selected": false,
"text": " function validateURL(textval) {\n var urlregex = new RegExp(\n \"^(http|https|ftp)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\?\\'\\\\\\+&%\\$#\\=~_\\-]+))*$\");\n return urlregex.test(textval);\n }\n"
},
{
"answer_id": 13713556,
"author": "Christopher Rivera",
"author_id": 1259947,
"author_profile": "https://Stackoverflow.com/users/1259947",
"pm_score": 3,
"selected": false,
"text": "public static void main(args) {\n String url = \"go to http://www.m.abut.ly/abc its awesome\"\n url = url.replaceAll(/https?:\\/\\/w{0,3}\\w*?\\.(\\w*?\\.)?\\w{2,3}\\S*|www\\.(\\w*?\\.)?\\w*?\\.\\w{2,3}\\S*|(\\w*?\\.)?\\w*?\\.\\w{2,3}[\\/\\?]\\S*/ , { it ->\n \"woof${it}woof\"\n })\n println url \n}\n http://google.com\nhttp://google.com/help.php\nhttp://google.com/help.php?a=5\n\nhttp://www.google.com\nhttp://www.google.com/help.php\nhttp://www.google.com?a=5\n\ngoogle.com?a=5\ngoogle.com/help.php\ngoogle.com/help.php?a=5\n\nhttp://www.m.google.com/help.php?a=5 (and all its permutations)\nwww.m.google.com/help.php?a=5 (and all its permutations)\nm.google.com/help.php?a=5 (and all its permutations)\n http www / ? http https?:\\/\\/w{0,3}\\w*?\\.\\w{2,3}\\S*\n www www\\.\\w*?\\.\\w{2,3}\\S*\n ? / \\w*?\\.\\w{2,3}[\\/\\?]\\S*\n"
},
{
"answer_id": 13739087,
"author": "Ashish",
"author_id": 1680395,
"author_profile": "https://Stackoverflow.com/users/1680395",
"pm_score": 2,
"selected": false,
"text": "String regularExpression = \"((((ht{2}ps?://)?)((w{3}\\\\.)?))?)[^.&&[a-zA-Z0-9]][a-zA-Z0-9.-]+[^.&&[a-zA-Z0-9]](\\\\.[a-zA-Z]{2,3})\";\n\nassertTrue(\"www.google.com\".matches(regularExpression));\nassertTrue(\"www.google.co.uk\".matches(regularExpression));\nassertTrue(\"http://www.google.com\".matches(regularExpression));\nassertTrue(\"http://www.google.co.uk\".matches(regularExpression));\nassertTrue(\"https://www.google.com\".matches(regularExpression));\nassertTrue(\"https://www.google.co.uk\".matches(regularExpression));\nassertTrue(\"google.com\".matches(regularExpression));\nassertTrue(\"google.co.uk\".matches(regularExpression));\nassertTrue(\"google.mu\".matches(regularExpression));\nassertTrue(\"mes.intnet.mu\".matches(regularExpression));\nassertTrue(\"cse.uom.ac.mu\".matches(regularExpression));\n\n//cannot contain 2 '.' after www\nassertFalse(\"www..dr.google\".matches(regularExpression));\n\n//cannot contain 2 '.' just before com\nassertFalse(\"www.dr.google..com\".matches(regularExpression));\n\n// to test case where url www must be followed with a '.'\nassertFalse(\"www:google.com\".matches(regularExpression));\n\n// to test case where url www must be followed with a '.'\n//assertFalse(\"http://wwwe.google.com\".matches(regularExpression));\n\n// to test case where www must be preceded with a '.'\nassertFalse(\"https://www@.google.com\".matches(regularExpression));\n"
},
{
"answer_id": 16425824,
"author": "Ewan",
"author_id": 1401034,
"author_profile": "https://Stackoverflow.com/users/1401034",
"pm_score": 2,
"selected": false,
"text": "import re\nregex = re.compile(\n r'^(?:http|ftp)s?://' # http:// or https://\n r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\\.)+(?:[A-Z]{2,6}\\.?|[A-Z0-9-]{2,}\\.?)|' # domain...\n r'localhost|' # localhost...\n r'\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|' # ...or ipv4\n r'\\[?[A-F0-9]*:[A-F0-9:]+\\]?)' # ...or ipv6\n r'(?::\\d+)?' # optional port\n r'(?:/?|[/?]\\S+)$', re.IGNORECASE)\n"
},
{
"answer_id": 17181268,
"author": "jojojohn",
"author_id": 971563,
"author_profile": "https://Stackoverflow.com/users/971563",
"pm_score": 2,
"selected": false,
"text": " $url = \"http://www.example.com\";\n\nif(!filter_var($url, FILTER_VALIDATE_URL))\n {\n echo \"URL is not valid\";\n }\nelse\n {\n echo \"URL is valid\";\n }\n"
},
{
"answer_id": 17185781,
"author": "thermz",
"author_id": 954680,
"author_profile": "https://Stackoverflow.com/users/954680",
"pm_score": 3,
"selected": false,
"text": "@Test\n public void testWebsiteUrl(){\n String regularExpression = \"((http|ftp|https):\\\\/\\\\/)?[\\\\w\\\\-_]+(\\\\.[\\\\w\\\\-_]+)+([\\\\w\\\\-\\\\.,@?^=%&:/~\\\\+#]*[\\\\w\\\\-\\\\@?^=%&/~\\\\+#])?\";\n\n assertTrue(\"www.google.com\".matches(regularExpression));\n assertTrue(\"www.google.co.uk\".matches(regularExpression));\n assertTrue(\"http://www.google.com\".matches(regularExpression));\n assertTrue(\"http://www.google.co.uk\".matches(regularExpression));\n assertTrue(\"https://www.google.com\".matches(regularExpression));\n assertTrue(\"https://www.google.co.uk\".matches(regularExpression));\n assertTrue(\"google.com\".matches(regularExpression));\n assertTrue(\"google.co.uk\".matches(regularExpression));\n assertTrue(\"google.mu\".matches(regularExpression));\n assertTrue(\"mes.intnet.mu\".matches(regularExpression));\n assertTrue(\"cse.uom.ac.mu\".matches(regularExpression));\n\n assertTrue(\"http://www.google.com/path\".matches(regularExpression));\n assertTrue(\"http://subdomain.web-site.com/cgi-bin/perl.cgi?key1=value1&key2=value2e\".matches(regularExpression));\n assertTrue(\"http://www.google.com/?queryparam=123\".matches(regularExpression));\n assertTrue(\"http://www.google.com/path?queryparam=123\".matches(regularExpression));\n\n assertFalse(\"www..dr.google\".matches(regularExpression));\n\n assertFalse(\"www:google.com\".matches(regularExpression));\n\n assertFalse(\"https://www@.google.com\".matches(regularExpression));\n\n assertFalse(\"https://www.google.com\\\"\".matches(regularExpression));\n assertFalse(\"https://www.google.com'\".matches(regularExpression));\n\n assertFalse(\"http://www.google.com/path'\".matches(regularExpression));\n assertFalse(\"http://subdomain.web-site.com/cgi-bin/perl.cgi?key1=value1&key2=value2e'\".matches(regularExpression));\n assertFalse(\"http://www.google.com/?queryparam=123'\".matches(regularExpression));\n assertFalse(\"http://www.google.com/path?queryparam=12'3\".matches(regularExpression));\n\n }\n"
},
{
"answer_id": 17511761,
"author": "Shantonu",
"author_id": 1564801,
"author_profile": "https://Stackoverflow.com/users/1564801",
"pm_score": 2,
"selected": false,
"text": "(https?|ftp)://(www\\d?|[a-zA-Z0-9]+)?\\.[a-zA-Z0-9-]+(\\:|\\.)([a-zA-Z0-9.]+|(\\d+)?)([/?:].*)?"
},
{
"answer_id": 17714711,
"author": "S.p",
"author_id": 1503110,
"author_profile": "https://Stackoverflow.com/users/1503110",
"pm_score": 4,
"selected": false,
"text": "\"(([\\w]+:)?//)?(([\\d\\w]|%[a-fA-F\\d]{2,2})+(:([\\d\\w]|%[a-fA-f\\d]{2,2})+)?@)?([\\d\\w][-\\d\\w]{0,253}[\\d\\w]\\.)+[\\w]{2,4}(:[\\d]+)?(/([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)*(\\?(&?([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})=?)*)?(#([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)?\"\n"
},
{
"answer_id": 18724720,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 5,
"selected": false,
"text": "parse_url URI URI"
},
{
"answer_id": 19280767,
"author": "Mohammad Anini",
"author_id": 1711813,
"author_profile": "https://Stackoverflow.com/users/1711813",
"pm_score": 2,
"selected": false,
"text": "\"@((((ht)|(f))tp[s]?://)|(www\\.))([a-z][-a-z0-9]+\\.)?([a-z][-a-z0-9]+\\.)?[a-z][-a-z0-9]+\\.[a-z]+[/]?[a-z0-9._\\/~#&=;%+?-]*@si\"\n"
},
{
"answer_id": 20542241,
"author": "Reetika",
"author_id": 2667029,
"author_profile": "https://Stackoverflow.com/users/2667029",
"pm_score": 1,
"selected": false,
"text": "^http(s{0,1})://[a-zA-Z0-9_/\\\\-\\\\.]+\\\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\\\&\\\\?\\\\=\\\\-\\\\.\\\\~\\\\%]*\n"
},
{
"answer_id": 23909979,
"author": "Vinoth K S",
"author_id": 3409006,
"author_profile": "https://Stackoverflow.com/users/3409006",
"pm_score": 2,
"selected": false,
"text": "function validUrl(Url) {\n var myRegExp =/^(?:(?:https?|ftp):\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/i;\n\n if (!RegExp.test(Url.value)) {\n $(\"#urlErrorLbl\").removeClass('highlightNew');\n return false;\n } \n\n $(\"#urlErrorLbl\").addClass('highlightNew'); \n return true; \n}\n"
},
{
"answer_id": 24058129,
"author": "Besnik Kastrati",
"author_id": 2311058,
"author_profile": "https://Stackoverflow.com/users/2311058",
"pm_score": 5,
"selected": false,
"text": "(([\\w]+:)?//)?(([\\d\\w]|%[a-fA-f\\d]{2,2})+(:([\\d\\w]|%[a-fA-f\\d]{2,2})+)?@)?([\\d\\w][-\\d\\w]{0,253}[\\d\\w]\\.)+[\\w]{2,63}(:[\\d]+)?(/([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)*(\\?(&?([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})=?)*)?(#([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)?\n var urlreg=/(([\\w]+:)?\\/\\/)?(([\\d\\w]|%[a-fA-f\\d]{2,2})+(:([\\d\\w]|%[a-fA-f\\d]{2,2})+)?@)?([\\d\\w][-\\d\\w]{0,253}[\\d\\w]\\.)+[\\w]{2,63}(:[\\d]+)?(\\/([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)*(\\?(&?([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})=?)*)?(#([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)?/;\n\n$('textarea').on('input',function(){\n var url = $(this).val();\n $(this).toggleClass('invalid', urlreg.test(url) == false)\n});\n\n$('textarea').trigger('input'); textarea{color:green;}\n.invalid{color:red;} <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\n<textarea>http://www.google.com</textarea>\n<textarea>http//www.google.com</textarea>\n<textarea>googlecom</textarea>\n<textarea>https://www.google.com</textarea>"
},
{
"answer_id": 25538699,
"author": "Mikael Engver",
"author_id": 579697,
"author_profile": "https://Stackoverflow.com/users/579697",
"pm_score": 3,
"selected": false,
"text": "((https?:)?//)?(([\\d\\w]|%[a-fA-f\\d]{2,2})+(:([\\d\\w]|%[a-fA-f\\d]{2,2})+)?@)?([\\d\\w][-\\d\\w]{0,253}[\\d\\w]\\.)+[\\w]{2,63}(:[\\d]+)?(/([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)*(\\?(&?([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})=?)*)?(#([-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)?\n http://stackoverflow.com\nhttps://stackoverflow.com\n //stackoverflow.com\n"
},
{
"answer_id": 25831196,
"author": "M.R.Safari",
"author_id": 1761442,
"author_profile": "https://Stackoverflow.com/users/1761442",
"pm_score": 0,
"selected": false,
"text": "^(?:http(?:s)?:\\/\\/)?(?:www\\.)?(?:[\\w-]*)\\.\\w{2,}$\n"
},
{
"answer_id": 27379352,
"author": "miphe",
"author_id": 563915,
"author_profile": "https://Stackoverflow.com/users/563915",
"pm_score": 2,
"selected": false,
"text": ".com (http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}(\\.[a-z]{2,6}|:[0-9]{3,4})\\b([-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]*)\n"
},
{
"answer_id": 27945109,
"author": "runlevel0",
"author_id": 2850382,
"author_profile": "https://Stackoverflow.com/users/2850382",
"pm_score": 0,
"selected": false,
"text": "(^(\\bhttp)(|s):\\/{2})(?=[a-z0-9-_]{1,255})\\.\\1\\.([a-z]{3,7}$)\n (^(\\bhttp)(|s):\\/{2})(?=[a-z0-9-_.]{1,255})\\.([a-z]{3,7})\n"
},
{
"answer_id": 28527268,
"author": "kash",
"author_id": 1126904,
"author_profile": "https://Stackoverflow.com/users/1126904",
"pm_score": 3,
"selected": false,
"text": "public static final Matcher WEB = Pattern.compile(new StringBuilder() \n.append(\"((?:(http|https|Http|Https|rtsp|Rtsp):\") \n.append(\"\\\\/\\\\/(?:(?:[a-zA-Z0-9\\\\$\\\\-\\\\_\\\\.\\\\+\\\\!\\\\*\\\\'\\\\(\\\\)\") \n.append(\"\\\\,\\\\;\\\\?\\\\&\\\\=]|(?:\\\\%[a-fA-F0-9]{2})){1,64}(?:\\\\:(?:[a-zA-Z0-9\\\\$\\\\-\\\\_\") \n.append(\"\\\\.\\\\+\\\\!\\\\*\\\\'\\\\(\\\\)\\\\,\\\\;\\\\?\\\\&\\\\=]|(?:\\\\%[a-fA-F0-9]{2})){1,25})?\\\\@)?)?\") \n.append(\"((?:(?:[a-zA-Z0-9][a-zA-Z0-9\\\\-]{0,64}\\\\.)+\") // named host \n.append(\"(?:\") // plus top level domain \n.append(\"(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])\") \n.append(\"|(?:biz|b[abdefghijmnorstvwyz])\") \n.append(\"|(?:cat|com|coop|c[acdfghiklmnoruvxyz])\") \n.append(\"|d[ejkmoz]\") \n.append(\"|(?:edu|e[cegrstu])\") \n.append(\"|f[ijkmor]\") \n.append(\"|(?:gov|g[abdefghilmnpqrstuwy])\") \n.append(\"|h[kmnrtu]\") \n.append(\"|(?:info|int|i[delmnoqrst])\") \n.append(\"|(?:jobs|j[emop])\") \n.append(\"|k[eghimnrwyz]\") \n.append(\"|l[abcikrstuvy]\") \n.append(\"|(?:mil|mobi|museum|m[acdghklmnopqrstuvwxyz])\") \n.append(\"|(?:name|net|n[acefgilopruz])\") \n.append(\"|(?:org|om)\") \n.append(\"|(?:pro|p[aefghklmnrstwy])\") \n.append(\"|qa\") \n.append(\"|r[eouw]\") \n.append(\"|s[abcdeghijklmnortuvyz]\") \n.append(\"|(?:tel|travel|t[cdfghjklmnoprtvwz])\") \n.append(\"|u[agkmsyz]\") \n.append(\"|v[aceginu]\") \n.append(\"|w[fs]\") \n.append(\"|y[etu]\") \n.append(\"|z[amw]))\") \n.append(\"|(?:(?:25[0-5]|2[0-4]\") // or ip address \n.append(\"[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\\\.(?:25[0-5]|2[0-4][0-9]\") \n.append(\"|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\\\.(?:25[0-5]|2[0-4][0-9]|[0-1]\") \n.append(\"[0-9]{2}|[1-9][0-9]|[1-9]|0)\\\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}\") \n.append(\"|[1-9][0-9]|[0-9])))\") \n.append(\"(?:\\\\:\\\\d{1,5})?)\") // plus option port number \n.append(\"(\\\\/(?:(?:[a-zA-Z0-9\\\\;\\\\/\\\\?\\\\:\\\\@\\\\&\\\\=\\\\#\\\\~\") // plus option query params \n.append(\"\\\\-\\\\.\\\\+\\\\!\\\\*\\\\'\\\\(\\\\)\\\\,\\\\_])|(?:\\\\%[a-fA-F0-9]{2}))*)?\") \n.append(\"(?:\\\\b|$)\").toString() \n).matcher(\"\");\n"
},
{
"answer_id": 29472385,
"author": "Daniel Mihai",
"author_id": 2123170,
"author_profile": "https://Stackoverflow.com/users/2123170",
"pm_score": 0,
"selected": false,
"text": "function validateUrl(value){\n return /^(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)$/gi.test(value);\n}\n\nconsole.log(validateUrl('google.com')); // true\nconsole.log(validateUrl('www.google.com')); // true\nconsole.log(validateUrl('http://www.google.com')); // true\nconsole.log(validateUrl('http:/www.google.com')); // false\nconsole.log(validateUrl('www.google.com/test')); // true"
},
{
"answer_id": 30238449,
"author": "Fredmat",
"author_id": 1466704,
"author_profile": "https://Stackoverflow.com/users/1466704",
"pm_score": 2,
"selected": false,
"text": "$url = 'http://www.yoururl.co.uk/sub1/sub2/?param=1¶m2/';\n\nif ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {\n // Wrong\n}\nelse {\n // Valid\n}\n"
},
{
"answer_id": 33028229,
"author": "Rahul Desai",
"author_id": 586051,
"author_profile": "https://Stackoverflow.com/users/586051",
"pm_score": 2,
"selected": false,
"text": "/\\b(?:(?:https?|ftp):\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\x{00a1}-\\x{ffff}0-9]+-?)*[a-z\\x{00a1}-\\x{ffff}0-9]+)(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}0-9]+-?)*[a-z\\x{00a1}-\\x{ffff}0-9]+)*(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?\\b/gi"
},
{
"answer_id": 39198430,
"author": "MithPaul",
"author_id": 3183039,
"author_profile": "https://Stackoverflow.com/users/3183039",
"pm_score": 0,
"selected": false,
"text": "(https?:\\/\\/)?(www\\.)[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)|(https?:\\/\\/)?(www\\.)?(?!ww)[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)\n"
},
{
"answer_id": 39478555,
"author": "ctwheels",
"author_id": 3600709,
"author_profile": "https://Stackoverflow.com/users/3600709",
"pm_score": 0,
"selected": false,
"text": "gmx $regex = <<<'EOD'\n// Put the regex here\nEOD;\n john.doe@gmail.com www.google.com/pathtofile.php?query (?:\n (?<scheme>\n (?<urn>urn)|\n (?&d_scheme)\n )\n :\n )?\n (?:\n (?<scheme>\n (?<urn>urn)|\n (?&d_scheme)\n )\n :\n )?\n gmx (?(DEFINE)\n # Definitions\n (?<ALPHA>[\\p{L}])\n (?<DIGIT>[0-9])\n (?<HEX>[0-9a-fA-F])\n (?<NCCHAR>\n (?&UNRESERVED)|\n (?&PCT_ENCODED)|\n (?&SUB_DELIMS)|\n @\n )\n (?<PCHAR>\n (?&UNRESERVED)|\n (?&PCT_ENCODED)|\n (?&SUB_DELIMS)|\n :|\n @|\n \\/\n )\n (?<UCHAR>\n (?&UNRESERVED)|\n (?&PCT_ENCODED)|\n (?&SUB_DELIMS)|\n :\n )\n (?<RCHAR>\n (?&UNRESERVED)|\n (?&PCT_ENCODED)|\n (?&SUB_DELIMS)\n )\n (?<PCT_ENCODED>%(?&HEX){2})\n (?<UNRESERVED>\n ((?&ALPHA)|(?&DIGIT)|[-._~])\n )\n (?<RESERVED>(?&GEN_DELIMS)|(?&SUB_DELIMS))\n (?<GEN_DELIMS>[:\\/?#\\[\\]@])\n (?<SUB_DELIMS>[!$&'()*+,;=])\n # URI Parts\n (?<d_scheme>\n (?!urn)\n (?:\n (?&ALPHA)\n ((?&ALPHA)|(?&DIGIT)|[+-.])*\n (?=:)\n )\n )\n (?<d_hier_part_slashes>\n (\\/{2})?\n )\n (?<d_authority>(?&d_userinfo)?)\n (?<d_userinfo>(?&UCHAR)*)\n (?<d_ipv6>\n (?![^:]*::[^:]*::[^:]*)\n (\n (\n ((?&HEX){0,4})\n :\n ){1,7}\n ((?&d_ipv4)|:|(?&HEX){1,4})\n )\n )\n (?<d_ipv4>\n ((?&octet)\\.){3}\n (?&octet)\n )\n (?<octet>\n (\n 25[]0-5]|\n 2[0-4](?&DIGIT)|\n 1(?&DIGIT){2}|\n [1-9](?&DIGIT)|\n (?&DIGIT)\n )\n )\n (?<d_reg_name>(?&RCHAR)*)\n (?<d_urn_name>(?&UCHAR)*)\n (?<d_port>(?&DIGIT)*)\n (?<d_path>\n (\n \\/\n ((?&PCHAR)*)*\n (?=\\?|\\#|$)\n )\n )\n (?<d_query>\n (\n ((?&PCHAR)|\\/|\\?)*\n )?\n )\n (?<d_fragment>\n (\n ((?&PCHAR)|\\/|\\?)*\n )?\n )\n)\n^\n(?<link>\n (?:\n (?<scheme>\n (?<urn>urn)|\n (?&d_scheme)\n )\n :\n )\n (?(urn)\n (?:\n (?<namespace_identifier>[0-9a-zA-Z\\-]+)\n :\n (?<namespace_specific_string>(?&d_urn_name)+)\n )\n |\n (?<hier_part>\n (?<slashes>(?&d_hier_part_slashes))\n (?<authority>\n (?:\n (?<userinfo>(?&d_authority))\n @\n )?\n (?<host>\n (?<ipv4>\\[?(?&d_ipv4)\\]?)|\n (?<ipv6>\\[(?&d_ipv6)\\])|\n (?<domain>(?&d_reg_name))\n )\n (?:\n :\n (?<port>(?&d_port))\n )?\n )\n (?<path>(?&d_path))?\n )\n (?:\n \\?\n (?<query>(?&d_query))\n )?\n (?:\n \\#\n (?<fragment>(?&d_fragment))\n )?\n )\n)\n$\n # Valid URIs\nftp://cnn.example.com&story=breaking_news@10.0.0.1/top_story.htm\nftp://ftp.is.co.za/rfc/rfc1808.txt\nhttp://www.ietf.org/rfc/rfc2396.txt\nldap://[2001:db8::7]/c=GB?objectClass?one\nmailto:John.Doe@example.com\nnews:comp.infosystems.www.servers.unix\ntel:+1-816-555-1212\ntelnet://192.0.2.16:80/\nurn:isbn:0451450523\nurn:oid:2.16.840\nurn:isan:0000-0000-9E59-0000-O-0000-0000-2\nurn:oasis:names:specification:docbook:dtd:xml:4.1.2\nhttp://localhost/test/somefile.php?query=someval&variable=value#fragment\nhttp://[2001:db8:a0b:12f0::1]/test\nftp://username:password@domain.com/path/to/file/somefile.html?queryVariable=value#fragment\nhttps://subdomain.domain.com/path/to/file.php?query=value#fragment\nhttps://subdomain.example.com/path/to/file.php?query=value#fragment\nmailto:john.smith(comment)@example.com\nmailto:user@[2001:DB8::1]\nmailto:user@[255:192:168:1]\nmailto:M.Handley@cs.ucl.ac.uk\nhttp://localhost:4433/path/to/file?query#fragment\n# Note that the example below IS a valid as it does follow RFC standards\nlocalhost:4433/path/to/file\n\n# These work with the optional scheme group although I'd suggest making the scheme mandatory as misinterpretations can occur\njohn.doe@gmail.com\nwww.google.com/pathtofile.php?query\n[192a:123::192.168.1.1]:80/path/to/file.html?query#fragment\n"
},
{
"answer_id": 39908190,
"author": "maxspan",
"author_id": 2209468,
"author_profile": "https://Stackoverflow.com/users/2209468",
"pm_score": 2,
"selected": false,
"text": "_(^|[\\s.:;?\\-\\]<\\(])(https?://[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?)(?=$|[\\s',\\|\\(\\).:;?\\-\\[\\]>\\)])_i\n\n#\\b(([\\w-]+://?|www[.])[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/)))#iS\n"
},
{
"answer_id": 45728224,
"author": "Johann",
"author_id": 753632,
"author_profile": "https://Stackoverflow.com/users/753632",
"pm_score": 1,
"selected": false,
"text": "function isAValidUrl(url) {\n try {\n new URL(url);\n return true;\n } catch(e) {\n return false;\n }\n}\n"
},
{
"answer_id": 45966320,
"author": "Divya-Systematix",
"author_id": 5711511,
"author_profile": "https://Stackoverflow.com/users/5711511",
"pm_score": 3,
"selected": false,
"text": "^(http|https):\\/\\/+[\\www\\d]+\\.[\\w]+(\\/[\\w\\d]+)?\n"
},
{
"answer_id": 46088854,
"author": "tk_",
"author_id": 3168721,
"author_profile": "https://Stackoverflow.com/users/3168721",
"pm_score": 1,
"selected": false,
"text": "^(https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]\\.[^\\s]{2,})$\n"
},
{
"answer_id": 48048416,
"author": "IT Eng - BU",
"author_id": 8743681,
"author_profile": "https://Stackoverflow.com/users/8743681",
"pm_score": 0,
"selected": false,
"text": "(https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]\\.[^\\s]{2,})\n function RegExForUrlMatch()\n{\n var expression = /(https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]\\.[^\\s]{2,})/g;\n\n var regex = new RegExp(expression);\n var t = document.getElementById(\"url\").value;\n\n if (t.match(regex)) {\n document.getElementById(\"demo\").innerHTML = \"Successful match\";\n } else {\n document.getElementById(\"demo\").innerHTML = \"No match\";\n }\n} <input type=\"text\" id=\"url\" placeholder=\"url\" onkeyup=\"RegExForUrlMatch()\">\n\n<p id=\"demo\">Please enter a URL to test</p>"
},
{
"answer_id": 48408597,
"author": "Ravi Matani",
"author_id": 4017996,
"author_profile": "https://Stackoverflow.com/users/4017996",
"pm_score": 0,
"selected": false,
"text": "please visit yourwebsite.com yourwebsite.com if (new RegExp(\"([-a-z0-9]{1,63}\\\\.)*?[a-z0-9][-a-z0-9]{0,61}[a-z0-9]\\\\.(com|com/|org|gov|cm|net|online|live|biz|us|uk|co.us|co.uk|in|co.in|int|info|edu|mil|ca|co|co.au|org/|gov/|cm/|net/|online/|live/|biz/|us/|uk/|co.us/|co.uk/|in/|co.in/|int/|info/|edu/|mil/|ca/|co/|co.au/)(/[-\\\\w@\\\\+\\\\.~#\\\\?*&/=% ]*)?$\").test(strMessage) || (new RegExp(\"^[a-z ]+[\\.]?[a-z ]+?[\\.]+[a-z ]+?[\\.]+[a-z ]+?[-\\\\w@\\\\+\\\\.~#\\\\?*&/=% ]*\").test(strMessage) && new RegExp(\"([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?\").test(strMessage)) || (new RegExp(\"^[a-z ]+[\\.]?[a-z ]+?[-\\\\w@\\\\+\\\\.~#\\\\?*&/=% ]*\").test(strMessage) && new RegExp(\"([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?\").test(strMessage))) {\n if (new RegExp(\"^[a-z ]+[\\.]?[a-z ]+?[\\.]+[a-z ]+?[\\.]+[a-z ]+?$\").test(strMessage) && new RegExp(\"([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?\").test(strMessage)) {\n var url1 = /(^|<|\\s)([\\w\\.]+\\.(?:com|org|gov|cm|net|online|live|biz|us|uk|co.us|co.uk|in|co.in|int|info|edu|mil|ca|co|co.au))(\\s|>|$)/g;\n var html = $.trim(strMessage);\n if (html) {\n html = html.replace(url1, '$1<a style=\"color:blue; text-decoration:underline;\" target=\"_blank\" href=\"http://$2\">$2</a>$3');\n }\n returnString = html;\n return returnString;\n } else {\n var url1 = /(^|<|\\s)(www\\..+?\\.(?:com|org|gov|cm|net|online|live|biz|us|uk|co.us|co.uk|in|co.in|int|info|edu|mil|ca|co|co.au)[^,\\s]*)(\\s|>|$)/g,\n url2 = /(^|<|\\s)(((https?|ftp):\\/\\/|mailto:).+?\\.(?:com|org|gov|cm|net|online|live|biz|us|uk|co.us|co.uk|in|co.in|int|info|edu|mil|ca|co|co.au)[^,\\s]*)(\\s|>|$)/g,\n url3 = /(^|<|\\s)([\\w\\.]+\\.(?:com|org|gov|cm|net|online|live|biz|us|uk|co.us|co.uk|in|co.in|int|info|edu|mil|ca|co|co.au)[^,\\s]*)(\\s|>|$)/g;\n\n var html = $.trim(strMessage);\n if (html) {\n html = html.replace(url1, '$1<a style=\"color:blue; text-decoration:underline;\" target=\"_blank\" href=\"http://$2\">$2</a>$3').replace(url2, '$1<a style=\"color:blue; text-decoration:underline;\" target=\"_blank\" href=\"$2\">$2</a>$5').replace(url3, '$1<a style=\"color:blue; text-decoration:underline;\" target=\"_blank\" href=\"http://$2\">$2</a>$3');\n }\n returnString = html;\n\n return returnString;\n }\n}\n"
},
{
"answer_id": 49154622,
"author": "dev_khan",
"author_id": 1722028,
"author_profile": "https://Stackoverflow.com/users/1722028",
"pm_score": 0,
"selected": false,
"text": "^[a-zA-Z0-9]+\\:\\/\\/[a-zA-Z0-9]+\\.[-a-zA-Z0-9]+\\.?[a-zA-Z0-9]+$|^[a-zA-Z0-9]+\\.[-a-zA-Z0-9]+\\.[a-zA-Z0-9]+$\n"
},
{
"answer_id": 51560709,
"author": "Nike Kov",
"author_id": 5790492,
"author_profile": "https://Stackoverflow.com/users/5790492",
"pm_score": 0,
"selected": false,
"text": "/(^|\\s)((https?:\\/\\/)?[\\w-]+(\\.[\\w-]+)+\\.?(:\\d+)?(\\/\\S*)?)/gi (^|\\\\s)((https?:\\\\/\\\\/)?[\\\\w-]+(\\\\.[\\\\w-]+)+\\\\.?(:\\\\d+)?(\\\\/\\\\S*)?)"
},
{
"answer_id": 52508260,
"author": "Erick Maynard",
"author_id": 4469176,
"author_profile": "https://Stackoverflow.com/users/4469176",
"pm_score": 0,
"selected": false,
"text": "http(s)://www.google.com http://google.com www.google.com google.com [Google](http://www.google.com) /^(\\[[A-z0-9 _]*\\]\\()?((?:(http|https):\\/\\/)?(?:[\\w-]+\\.)+[a-z]{2,6})(\\))?$\n /^(\\[[A-z0-9 _]*\\]\\()?((?:(http|https|ftp|file):\\/\\/)?(?:[\\w-]+\\.)+[a-z]{2,6})(\\))?$\n"
},
{
"answer_id": 53480857,
"author": "Mahfuzur Rahman",
"author_id": 6570691,
"author_profile": "https://Stackoverflow.com/users/6570691",
"pm_score": 0,
"selected": false,
"text": "var hasURL = (str) =>{\n var url_pattern = new RegExp(\"(www.|http://|https://|ftp://)\\w*\");\n if(!url_pattern.test(str)){\n document.getElementById(\"demo\").innerHTML = 'No URL';\n }\n else\n document.getElementById(\"demo\").innerHTML = 'String has a URL';\n}; <p>Please enter a string and test it has any url or not</p>\n<input type=\"text\" id=\"url\" placeholder=\"url\" onkeyup=\"hasURL(document.getElementById('url').value)\">\n<p id=\"demo\"></p>"
},
{
"answer_id": 53711623,
"author": "Elie G.",
"author_id": 5647659,
"author_profile": "https://Stackoverflow.com/users/5647659",
"pm_score": 3,
"selected": false,
"text": "^((?:(?:http|ftp|ws)s?|sftp):\\/\\/?)?([^:/\\s.#?]+\\.[^:/\\s#?]+|localhost)(:\\d+)?((?:\\/\\w+)*\\/)?([\\w\\-.]+[^#?\\s]+)?([^#]+)?(#[\\w-]*)?$ ((?:(?:http|ftp|ws)s?|sftp):\\/\\/?)? ([^:/\\s.#?]+\\.[^:/\\s#?]+|localhost) (:\\d+)? ((?:\\/\\w+)*\\/)?([\\w\\-.]+[^#?\\s]+)? ([^#]+)? (#[\\w-]*)? ? ^ $"
},
{
"answer_id": 54690403,
"author": "Sajeeb Chandan Saha",
"author_id": 9518407,
"author_profile": "https://Stackoverflow.com/users/9518407",
"pm_score": 2,
"selected": false,
"text": "https?:\\/{2}(?:[\\/-\\w.]|(?:%[\\da-fA-F]{2}))+\n"
},
{
"answer_id": 55468411,
"author": "Nodarii",
"author_id": 2460760,
"author_profile": "https://Stackoverflow.com/users/2460760",
"pm_score": 4,
"selected": false,
"text": "^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$\n"
},
{
"answer_id": 55952338,
"author": "Dragana Le Mitova",
"author_id": 4317831,
"author_profile": "https://Stackoverflow.com/users/4317831",
"pm_score": 1,
"selected": false,
"text": "/^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$/gm\n"
},
{
"answer_id": 56037210,
"author": "Kerem",
"author_id": 1139130,
"author_profile": "https://Stackoverflow.com/users/1139130",
"pm_score": 0,
"selected": false,
"text": "isValidUrl(input) {\n var regex = /^(((H|h)(T|t)(T|t)(P|p)(S|s)?):\\/\\/)?[-a-zA-Z0-9@:%._\\+~#=]{2,100}\\.[a-zA-Z]{2,10}(\\/([-a-zA-Z0-9@:%_\\+.~#?&//=]*))?/\n return regex.test(input)\n}\n"
},
{
"answer_id": 56056825,
"author": "Dmytro Huz",
"author_id": 5907412,
"author_profile": "https://Stackoverflow.com/users/5907412",
"pm_score": 4,
"selected": false,
"text": "/(https?:\\/\\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])(:?\\d*)\\/?([a-z_\\/0-9\\-#.]*)\\??([a-z_\\/0-9\\-#=&]*)/g\n"
},
{
"answer_id": 63103782,
"author": "medBouzid",
"author_id": 2392106,
"author_profile": "https://Stackoverflow.com/users/2392106",
"pm_score": 0,
"selected": false,
"text": "domain.extension www blog.domain.extension /^(www\\.|[a-zA-Z0-9](.*[a-zA-Z0-9])?\\.)?((?!www)[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9])\\.[a-z]{2,5}(:[0-9]{1,5})?$/i\n (www\\.|[a-zA-Z0-9](.*[a-zA-Z0-9])?\\.)? www. [a-zA-Z0-9](.*[a-zA-Z0-9])? (.*[a-zA-Z0-9])?\\.)? ? ((?!www)[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9])\\. [a-z]{2,}"
},
{
"answer_id": 63991456,
"author": "manmeet",
"author_id": 1161987,
"author_profile": "https://Stackoverflow.com/users/1161987",
"pm_score": -1,
"selected": false,
"text": "/^(http|HTTP)+(s|S)?:\\/\\/[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._\\$\\(\\)/]+$/g\n"
},
{
"answer_id": 64206393,
"author": "Qasim Rizvi",
"author_id": 3616731,
"author_profile": "https://Stackoverflow.com/users/3616731",
"pm_score": 0,
"selected": false,
"text": "^(ftp|http|https):\\/\\/[^ \"]+$\n"
},
{
"answer_id": 66998354,
"author": "Nabijon Azamov",
"author_id": 6244001,
"author_profile": "https://Stackoverflow.com/users/6244001",
"pm_score": 0,
"selected": false,
"text": "(http(s)?:\\/\\/.)?(ftp(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{0,256}\\.[a-z] \n{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)\n https://google.com t.me https://t.me ftp://google.com http://sm.tj http://bro.tj t.me/rshss https:google.com www.cool.com.au http://www.cool.com.au http://www.cool.com.au/ersdfs http://www.cool.com.au/ersdfs?dfd=dfgd@s=1 http://www.cool.com:81/index.html\n"
},
{
"answer_id": 70034706,
"author": "Hans",
"author_id": 15096247,
"author_profile": "https://Stackoverflow.com/users/15096247",
"pm_score": -1,
"selected": false,
"text": "((?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@|\\d{1,3}(?:\\.\\d{1,3}){3}|(?:(?:[a-z\\d\\x{00a1}-\\x{ffff}]+-?)*[a-z\\d\\x{00a1}-\\x{ffff}]+)(?:\\.(?:[a-z\\d\\x{00a1}-\\x{ffff}]+-?)*[a-z\\d\\x{00a1}-\\x{ffff}]+)*(?:\\.[a-z\\x{00a1}-\\x{ffff}]{2,6}))(?::\\d+)?(?:[^\\s]*)|(?:(?:(?:[A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+(?::[0-9]+)?|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)(?:(?:\\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)|(?:(?:(?:(?:[A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)(?:(?:\\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?))|(?:(?:(?:[\\\\w]+:)?//)?(?:(?:[\\\\d\\\\w]|%[a-fA-f\\\\d]{2,2})+(?::(?:[\\\\d\\\\w]|%[a-fA-f\\\\d]{2,2})+)?@)?(?:[\\\\d\\\\w][-\\\\d\\\\w]{0,253}[\\\\d\\\\w]\\\\.)+[\\\\w]{2,4}(?::[\\\\d]+)?(?:/(?:[-+_~.\\\\d\\\\w]|%[a-fA-f\\\\d]{2,2})*)*(?:\\\\?(?:&?(?:[-+_~.\\\\d\\\\w]|%[a-fA-f\\\\d]{2,2})=?)*)?(?:#(?:[-+_~.\\\\d\\\\w]|%[a-fA-f\\\\d]{2,2})*)?)|(?:https?:\\/\\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])(?::?\\d*)\\/?(?:[a-z_\\/0-9\\-#.]*)\\??(?:[a-z_\\/0-9\\-#=&]*)|(?:(?:(?:https?:)?(?:\\/?\\/))(?:(?:[\\d\\w]|%[a-fA-f\\d]{2,2})+(?::(?:[\\d\\w]|%[a-fA-f\\d]{2,2})+)?@)?(?:[\\d\\w][-\\d\\w]{0,253}[\\d\\w]\\.)+[\\w]{2,63}(?::[\\d]+)?(?:/(?:[-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)*(?:\\?(?:&?(?:[-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})=?)*)?(?:#(?:[-+_~.\\d\\w]|%[a-fA-f\\d]{2,2})*)?)|(?:(?:https?|ftp)://(?:www\\d?|[a-zA-Z0-9]+)?\\.[a-zA-Z0-9-]+(?:\\:|\\.)(?:[a-zA-Z0-9.]+|(?:\\d+)?)(?:[/?:].*)?)|(?:\\b(?:(?:https?|ftp):\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\x{00a1}-\\x{ffff}0-9]+-?)*[a-z\\x{00a1}-\\x{ffff}0-9]+)(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}0-9]+-?)*[a-z\\x{00a1}-\\x{ffff}0-9]+)*(?:\\.(?:[a-z\\x{00a1}-\\x{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?\\b))\n"
},
{
"answer_id": 70067237,
"author": "suchislife",
"author_id": 687137,
"author_profile": "https://Stackoverflow.com/users/687137",
"pm_score": 0,
"selected": false,
"text": "new URL() /**\n * \n * The URL() constructor returns a newly created URL object representing \n * the URL defined by the parameters. \n * \n * https://developer.mozilla.org/en-US/docs/Web/API/URL/URL\n * \n */\nlet requestUrl = new URL('https://username:password@developer.mozilla.org:8080/en-US/docs/search.html?par1=abc&par2=123&par3=true#Recent');\n\nlet urlParts = {\n origin: requestUrl.origin,\n href: requestUrl.href,\n protocol: requestUrl.protocol,\n username: requestUrl.username,\n password: requestUrl.password,\n host: requestUrl.host,\n hostname: requestUrl.hostname,\n port: requestUrl.port,\n pathname: requestUrl.pathname,\n search: requestUrl.search,\n searchParams: {\n par1: String(requestUrl.searchParams.get('par1')),\n par2: Number(requestUrl.searchParams.get('par2')),\n par3: Boolean(requestUrl.searchParams.get('par3')),\n },\n hash: requestUrl.hash \n};\n\nconsole.log(urlParts);"
},
{
"answer_id": 71875638,
"author": "Trashman",
"author_id": 3608565,
"author_profile": "https://Stackoverflow.com/users/3608565",
"pm_score": 0,
"selected": false,
"text": "regEx_valid_URL = /^[a-z](?:[-a-z0-9\\+\\.])*:(?:\\/\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:])*@)?(?:\\[(?:(?:(?:[0-9a-f]{1,4}:){6}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|::(?:[0-9a-f]{1,4}:){5}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3})|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+\\.[-a-z0-9\\._~!\\$&'\\(\\)\\*\\+,;=:]+)\\]|(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?:\\.(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}|(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=])*)(?::[0-9]*)?(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:@]))*)*|\\/(?:(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:@]))*)*)?|(?:(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:@]))+)(?:\\/(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:@]))*)*|(?!(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:@])))(?:\\?(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:@])|[\\uE000-\\uF8FF}\\uF0000-\\uFFFFD\\u100000-\\u10FFFD\\/\\?])*)?(?:\\#(?:(?:%[0-9a-f][0-9a-f]|[-a-z0-9\\._~\\uA0}-\\uD7FF}\\uF900-\\uFDCF}\\uFDF0}-\\uFFEF}\\u10000-\\u1FFFD\\u20000-\\u2FFFD\\u30000-\\u3FFFD\\u40000-\\u4FFFD\\u50000-\\u5FFFD\\u60000-\\u6FFFD\\u70000-\\u7FFFD\\u80000-\\u8FFFD\\u90000-\\u9FFFD\\uA0000-\\uAFFFD\\uB0000-\\uBFFFD\\uC0000-\\uCFFFD\\uD0000-\\uDFFFD\\uE1000-\\uEFFFD!\\$&'\\(\\)\\*\\+,;=:@])|[\\/\\?])*)?$/i;\n\ncheckedURL = RegExp(regEx_valid_URL).exec('gopher://example.somewhere.university/');\n\nif (checkedURL != null) {\n console.log('The URL ' + checkedURL + ' is valid');\n}"
},
{
"answer_id": 73117746,
"author": "Mikey J Lee",
"author_id": 2063880,
"author_profile": "https://Stackoverflow.com/users/2063880",
"pm_score": 0,
"selected": false,
"text": "/((https?:\\/\\/|ftp:\\/\\/|www\\.)\\S+\\.[^()\\n ]+((?:\\([^)]*\\))|[^.,;:?!\"'\\n\\)\\]<* ])+)/"
},
{
"answer_id": 73745423,
"author": "Luca Migliori",
"author_id": 6360503,
"author_profile": "https://Stackoverflow.com/users/6360503",
"pm_score": 0,
"selected": false,
"text": "[(http(s)?):\\/\\/(www\\.)?a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1842864/"
] |
161,747
|
<p>I would like to allow the logged user to edit MediaWiki/Common.css without adding them to the sysop group.</p>
<p>I understand that this will allow user to change it to harful ways but it is a closed wiki so that is not a problem.</p>
<p>Any solution is acceptable even changing php code :)</p>
|
[
{
"answer_id": 295808,
"author": "che",
"author_id": 7806,
"author_profile": "https://Stackoverflow.com/users/7806",
"pm_score": 5,
"selected": true,
"text": "$wgGroupPermissions['mynewgroup']['editinterface'] = true;\n $wgGroupPermissions['user']['editinterface'] = true;\n// user is the default group for all logged-in users\n"
},
{
"answer_id": 25591535,
"author": "Lee Miller",
"author_id": 1905376,
"author_profile": "https://Stackoverflow.com/users/1905376",
"pm_score": 0,
"selected": false,
"text": "$wgAllowUserCss = true;\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4508/"
] |
161,755
|
<p>Ant has a nice way to select groups of files, most handily using ** to indicate a directory tree. E.g.</p>
<pre><code>**/CVS/* # All files immediately under a CVS directory.
mydir/mysubdir/** # All files recursively under mysubdir
</code></pre>
<p>More examples can be seen here:</p>
<p><a href="http://ant.apache.org/manual/dirtasks.html" rel="nofollow noreferrer">http://ant.apache.org/manual/dirtasks.html</a></p>
<p>How would you implement this in python, so that you could do something like:</p>
<pre><code>files = get_files("**/CVS/*")
for file in files:
print file
=>
CVS/Repository
mydir/mysubdir/CVS/Entries
mydir/mysubdir/foo/bar/CVS/Entries
</code></pre>
|
[
{
"answer_id": 161858,
"author": "dkagedal",
"author_id": 24458,
"author_profile": "https://Stackoverflow.com/users/24458",
"pm_score": 2,
"selected": false,
"text": "os.walk **/CVS/* def match(pattern, filename):\n if pattern.startswith(\"**\"):\n return fnmatch.fnmatch(file, pattern[1:])\n else:\n return fnmatch.fnmatch(file, pattern)\n fnmatch.fnmatch"
},
{
"answer_id": 162716,
"author": "Jack M.",
"author_id": 3421,
"author_profile": "https://Stackoverflow.com/users/3421",
"pm_score": 0,
"selected": false,
"text": "import re\n\nfor (dirpath, dirnames, filenames) in os.walk(\".\"):\n if re.search(r'\\.svn$', dirpath):\n for file in filenames:\n print file\n"
},
{
"answer_id": 163212,
"author": "Brian",
"author_id": 9493,
"author_profile": "https://Stackoverflow.com/users/9493",
"pm_score": 3,
"selected": true,
"text": "** def glob_to_regex(pat, dirsep=os.sep):\n dirsep = re.escape(dirsep)\n print re.escape(pat)\n regex = (re.escape(pat).replace(\"\\\\*\\\\*\"+dirsep,\".*\")\n .replace(\"\\\\*\\\\*\",\".*\")\n .replace(\"\\\\*\",\"[^%s]*\" % dirsep)\n .replace(\"\\\\?\",\"[^%s]\" % dirsep))\n return re.compile(regex+\"$\")\n [a-z] \\*\\*/ \\*\\*/CVS ./CVS \\*\\* ** pat.split('/') -> ['**','CVS','*'] n levels deep -> look at pat[n] pat[n] == '**' dirsep.join(pat[n:]) glob\\_to\\_regex() os.walk \"**\" glob.glob(os.path.join(curpath,pat[n])) \"**\" pat[n] pat[n+1]"
},
{
"answer_id": 10597029,
"author": "Andrew Alcock",
"author_id": 1395668,
"author_profile": "https://Stackoverflow.com/users/1395668",
"pm_score": 3,
"selected": false,
"text": "import formic\nfileset = formic.FileSet(include=\"**/CVS/*\", default_excludes=False)\nfor file_name in fileset.qualified_files():\n print file_name\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161755",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/974/"
] |
161,775
|
<p>I am working on a script that downloads emails and stores them in a db, I usually receive thousands of emails on this account, once downloaded the mails are deleted.</p>
<p>Being paranoic, I want to have at least one month backup of my emails, but I cannot clutter my main mailbox address leaving them in there.</p>
<p>So i need to move the mails (via php code) from one mailbox to another. I came up with this solution that uses imap_append(). This solution, however recreates the email, and does not really move it.</p>
<p>Do you have any suggestions or alternative ways of doing this?</p>
<p>Remember: it must be done in php, because I need to integrate it in my readmail script.</p>
<p>I have already seen this thread <a href="https://stackoverflow.com/questions/57547/imap-forwarder">where a fetchmail solution was proposed</a></p>
<p>Here follows the code I wrote for this task</p>
<pre><code><?php
/**
* Conn params
*/
$fromMboxServerPath = "{imap.from.server/notls/imap:143}";
$fromMboxMailboxPath = "INBOX";
$fromMboxMailAddress = "login";
$fromMboxMailPass = "pass";
$toMboxServerPath = "{imap.to.server/notls/imap:143}";
$toMboxMailboxPath = "INBOX";
$toMboxMailAddress = "login";
$toMboxMailPass = "pass";
$fromMboxConnStr = $fromMboxServerPath.$fromMboxMailboxPath;
$toMboxConnStr = $toMboxServerPath.$toMboxMailboxPath;
$fetchStartSeq = 1;
$fetchEndSeq = 10;
function myLog($str)
{
echo "Log [".date('Y-m-d H:i:s')."]: $str\n";
}
myLog("Connecting to mailbox");
function mboxConn($connstr,$addr,$pass)
{
if(!($mbox = @imap_open($connstr, $addr, $pass)))
{
myLog("Error: ".imap_last_error());
die;
}
else
{
myLog("Connected to: $addr $connstr");
return $mbox;
}
}
function mboxCheck($mbox)
{
if(!($mbox_data = imap_check($mbox)))
{
myLog("Error: ".imap_last_error());
die;
}
else
{
myLog("Mailbox check ".$mbox_data->Mailbox." OK");
myLog($mbox_data->Nmsgs." messages present");
return $mbox_data->Nmsgs;
}
}
$fromMbox = mboxConn($fromMboxConnStr, $fromMboxMailAddress, $fromMboxMailPass);
$toMbox = mboxConn($toMboxConnStr, $toMboxMailAddress, $toMboxMailPass);
$fromMboxCount = mboxCheck($fromMbox);
$toMboxCount = mboxCheck($toMbox);
/**
* Loop on mails
*/
$fetchStartUID = imap_uid($fromMbox,$fetchStartSeq);
if ($fromMboxCount < $fetchEndSeq)
{
$fetchEndSeq = $fromMboxCount;
}
$fetchEndUID = imap_uid($fromMbox,$fetchEndSeq);
/**
* Loop on mails
*/
myLog("Do stuff and backup from UID [$fetchStartUID] to UID [$fetchEndUID]");
for ($i=$fetchStartSeq;$i<=$fetchEndSeq;$i++)
{
$pfx = "Msg #$i : ";
$h = imap_header($fromMbox, $i);
$fh = imap_fetchheader($fromMbox, $i);
$fb = imap_body($fromMbox, $i);
$message = $fh.$fb;
$msgUID = imap_uid($fromMbox,$i);
$struct = imap_fetchstructure ($fromMbox, $i);
/**
* We do some logging
*/
myLog($pfx."UID [".$msgUID."] SEQ [".imap_msgno($fromMbox,$msgUID)."] Flags: [". $h->Unseen . $h->Recent . $h->Deleted . $h->Answered . $h->Draft . $h->Flagged."]");
myLog($pfx."From: [". htmlspecialchars($h->fromaddress) . "] To: [".htmlspecialchars($h->toaddress)."]");
myLog($pfx."Subject: [$h->subject]");
/**
* Here you do whaterver you need with your email
*/
/**
* Backup email
*/
if (!($ret = imap_append($toMbox,$toMboxServerPath.$toMboxMailboxPath,$message)))
{
myLog("Error: ".imap_last_error());
die;
}
else
{
myLog("everything ok, mail [$fetchStartUID:$fetchEndUID] downloaded and moved in $newMailboxNameMOVE");
}
}
/**
* End
*/
imap_close($fromMbox);
imap_close($toMbox);
myLog("Connection closed");
?>
</code></pre>
|
[
{
"answer_id": 5835167,
"author": "Manuel Richarz",
"author_id": 719628,
"author_profile": "https://Stackoverflow.com/users/719628",
"pm_score": 1,
"selected": false,
"text": "$fromMboxServerPath = \"{imap.from.server/notls/imap/readonly:143}\"; //ReadOnly\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161775",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15780/"
] |
161,783
|
<p>I have a web page with <code>DIV</code>s with a <code>mouseover</code> handler that is intended to show a pop-up information bubble. I don't want more than one info bubble to be visible at a time. But when the user moves the mouse rapidly over two items, I sometimes get two bubbles. This should not happen, because the code for showing a pop-up cancels the previous pop-up. </p>
<p>If this were a multi-threaded system then the problem would be obvious: there are two threads trying to show a pop-up, and they both cancel existing pop-ups then pop up their own pop-ups. But I assumed JavaScript is always run single-threaded, which would prevent this. Am I wrong? Are event handlers running asynchronously, in which case I need synchronized access to shared data, or should I instead be looking for bugs in the library code for cancelling pop-ups?</p>
<p>Edited to add:</p>
<ul>
<li>The library in question is <a href="http://code.google.com/p/simile-widgets/" rel="nofollow noreferrer">SIMILE Timeline</a> and its Ajax library;</li>
<li>The event handler does call <code>SimileAjax.DOM.cancelEvent(domEvt)</code>, which I assume based on the name cancels the bubbling of events;</li>
<li>Just to make thing s more complicated, what I am actually doing is starting a timeout that if not cancelled by a <code>moustout</code> shows the pop-up, this being intended to prevent pop-ups flickering annoyingly but annoyingly having the reverse effect.</li>
</ul>
<p>I'll have another poke at it and see if I can work out where I am going wrong. :-)</p>
|
[
{
"answer_id": 161824,
"author": "Tom",
"author_id": 20,
"author_profile": "https://Stackoverflow.com/users/20",
"pm_score": 1,
"selected": false,
"text": "// maintain a reference to the active div bubble\nthis.oActiveDivBubble = null;\n\n// event handler for the first div\n$('exampleDiv1').observe('mouseover', function(evt) {\n evt.stop();\n if(this.oActiveDivBubble ) {\n this.oActiveDivBubble .hide();\n }\n this.oActiveDivBubble = $('exampleDiv1Bubble');\n this.oActiveDivBubble .show();\n\n}.bind(this));\n\n// event handler for the second div\n$('exampleDiv2').observe('mouseover'), function(evt) {\n evt.stop();\n if(this.oActiveDivBubble) {\n this.oActiveDivBubble.hide();\n }\n this.oActiveDivBubble = $('exampleDiv2Bubble');\n this.oActiveDivBubble .show();\n}.bind(this));\n"
},
{
"answer_id": 162244,
"author": "pdc",
"author_id": 8925,
"author_profile": "https://Stackoverflow.com/users/8925",
"pm_score": 0,
"selected": false,
"text": "mouseover var self = this;\nSimileAjax.DOM.registerEvent(labelElmtData.elmt, \"mouseover\", function (elt, domEvt, target) {\n return self._onHover(labelElmtData.elmt, domEvt, evt);\n});\n MyPlan.EventPainter.prototype._onHover = function(target, domEvt, evt) { \n ... calculate x and y ...\n domEvt.cancelBubble = true;\n SimileAjax.DOM.cancelEvent(domEvt);\n this._futureShowBubble(x, y, evt);\n\n return false;\n}\nMyPlan.EventPainter.prototype._futureShowBubble = function (x, y, evt) {\n if (this._futurePopup) {\n if (evt.getID() == this._futurePopup.evt.getID()) {\n return;\n } else {\n /* We had queued a different event's pop-up; this must now be cancelled. */\n window.clearTimeout(this._futurePopup.timeoutID);\n } \n }\n this._futurePopup = {\n x: x,\n y: y,\n evt: evt\n }; \n var self = this;\n this._futurePopup.timeoutID = window.setTimeout(function () {\n self._onTimeout();\n }, this._popupTimeout);\n}\n MyPlan.EventPainter.prototype._onTimeout = function () {\n this._showBubble(this._futurePopup.x, this._futurePopup.y, this._futurePopup.evt);\n\n};\n\nMyPlan.EventPainter.prototype._showBubble = function(x, y, evt) {\n if (this._futurePopup) {\n window.clearTimeout(this._futurePopup.timeoutID);\n this._futurePopup = null;\n } \n ...\n\n SimileAjax.WindowManager.cancelPopups();\n SimileAjax.Graphics.createBubbleForContentAndPoint(...);\n};\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8925/"
] |
161,788
|
<p>Are there any downsides to passing structs by value in C, rather than passing a pointer?</p>
<p>If the struct is large, there is obviously the performance aspect of copying lots of data, but for a smaller struct, it should basically be the same as passing several values to a function.</p>
<p>It is maybe even more interesting when used as return values. C only has single return values from functions, but you often need several. So a simple solution is to put them in a struct and return that.</p>
<p>Are there any reasons for or against this?</p>
<p>Since it might not be obvious to everyone what I'm talking about here, I'll give a simple example.</p>
<p>If you're programming in C, you'll sooner or later start writing functions that look like this:</p>
<pre><code>void examine_data(const char *ptr, size_t len)
{
...
}
char *p = ...;
size_t l = ...;
examine_data(p, l);
</code></pre>
<p>This isn't a problem. The only issue is that you have to agree with your coworker in which the order the parameters should be so you use the same convention in all functions.</p>
<p>But what happens when you want to return the same kind of information? You typically get something like this:</p>
<pre><code>char *get_data(size_t *len);
{
...
*len = ...datalen...;
return ...data...;
}
size_t len;
char *p = get_data(&len);
</code></pre>
<p>This works fine, but is much more problematic. A return value is a return value, except that in this implementation it isn't. There is no way to tell from the above that the function <code>get_data</code> isn't allowed to look at what <code>len</code> points to. And there is nothing that makes the compiler check that a value is actually returned through that pointer. So next month, when someone else modifies the code without understanding it properly (because he didn't read the documentation?) it gets broken without anyone noticing, or it starts crashing randomly.</p>
<p>So, the solution I propose is the simple struct</p>
<pre><code>struct blob { char *ptr; size_t len; }
</code></pre>
<p>The examples can be rewritten like this:</p>
<pre><code>void examine_data(const struct blob data)
{
... use data.tr and data.len ...
}
struct blob = { .ptr = ..., .len = ... };
examine_data(blob);
struct blob get_data(void);
{
...
return (struct blob){ .ptr = ...data..., .len = ...len... };
}
struct blob data = get_data();
</code></pre>
<p>For some reason, I think that most people would instinctively make <code>examine_data</code> take a pointer to a struct blob, but I don't see why. It still gets a pointer and an integer, it's just much clearer that they go together. And in the <code>get_data</code> case it is impossible to mess up in the way I described before, since there is no input value for the length, and there must be a returned length.</p>
|
[
{
"answer_id": 162140,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 4,
"selected": false,
"text": "struct {\n short a;\n char b;\n short c;\n char d;\n}\n"
},
{
"answer_id": 3355560,
"author": "kizzx2",
"author_id": 111021,
"author_profile": "https://Stackoverflow.com/users/111021",
"pm_score": 5,
"selected": false,
"text": "// foo.c\n\ntypedef struct\n{\n double x, y;\n} point;\n\nvoid give_two_doubles(double * x, double * y)\n{\n *x = 1.0;\n *y = 2.0;\n}\n\npoint give_point()\n{\n point a = {1.0, 2.0};\n return a;\n}\n\nint main()\n{\n return 0;\n}\n gcc -Wall -O3 foo.c -o foo\n objdump -d foo | vim -\n 0000000000400480 <give_two_doubles>:\n 400480: 48 ba 00 00 00 00 00 mov $0x3ff0000000000000,%rdx\n 400487: 00 f0 3f \n 40048a: 48 b8 00 00 00 00 00 mov $0x4000000000000000,%rax\n 400491: 00 00 40 \n 400494: 48 89 17 mov %rdx,(%rdi)\n 400497: 48 89 06 mov %rax,(%rsi)\n 40049a: c3 retq \n 40049b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)\n\n00000000004004a0 <give_point>:\n 4004a0: 66 0f 28 05 28 01 00 movapd 0x128(%rip),%xmm0\n 4004a7: 00 \n 4004a8: 66 0f 29 44 24 e8 movapd %xmm0,-0x18(%rsp)\n 4004ae: f2 0f 10 05 12 01 00 movsd 0x112(%rip),%xmm0\n 4004b5: 00 \n 4004b6: f2 0f 10 4c 24 f0 movsd -0x10(%rsp),%xmm1\n 4004bc: c3 retq \n 4004bd: 0f 1f 00 nopl (%rax)\n nopl give_two_doubles() give_point() give_point() give_two_doubles() mov movapd movsd give_two_doubles()"
},
{
"answer_id": 5746156,
"author": "Jingguo Yao",
"author_id": 431698,
"author_profile": "https://Stackoverflow.com/users/431698",
"pm_score": 3,
"selected": false,
"text": "struct person {\n int no;\n int age;\n};\n\nstruct person create() {\n struct person jingguo = { .no = 1, .age = 2};\n return jingguo;\n}\n\nint main(int argc, const char *argv[]) {\n struct person result;\n result = create();\n return 0;\n}\n .file \"foo.c\"\n .text\n.globl create\n .type create, @function\ncreate:\n pushl %ebp\n movl %esp, %ebp\n subl $16, %esp\n movl 8(%ebp), %ecx\n movl $1, -8(%ebp)\n movl $2, -4(%ebp)\n movl -8(%ebp), %eax\n movl -4(%ebp), %edx\n movl %eax, (%ecx)\n movl %edx, 4(%ecx)\n movl %ecx, %eax\n leave\n ret $4\n .size create, .-create\n.globl main\n .type main, @function\nmain:\n pushl %ebp\n movl %esp, %ebp\n subl $20, %esp\n leal -8(%ebp), %eax\n movl %eax, (%esp)\n call create\n subl $4, %esp\n movl $0, %eax\n leave\n ret\n .size main, .-main\n .ident \"GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3\"\n .section .note.GNU-stack,\"\",@progbits\n +---------------------------+\nebp | saved ebp |\n +---------------------------+\nebp-4 | age part of struct person | \n +---------------------------+\nebp-8 | no part of struct person |\n +---------------------------+ \nebp-12 | |\n +---------------------------+\nebp-16 | |\n +---------------------------+\nebp-20 | ebp-8 (address) |\n +---------------------------+\n +---------------------------+\n | ebp-8 (address) |\n +---------------------------+\n | return address |\n +---------------------------+\nebp,esp | saved ebp |\n +---------------------------+\n"
},
{
"answer_id": 7550748,
"author": "Chris Lutz",
"author_id": 60777,
"author_profile": "https://Stackoverflow.com/users/60777",
"pm_score": 3,
"selected": false,
"text": "void examine_data(const char *c, size_t l)\n{\n c[0] = 'l'; // compiler error\n}\n\nvoid examine_data(const struct blob blob)\n{\n blob.ptr[0] = 'l'; // perfectly legal, quite likely to blow up at runtime\n}\n const struct const char * char *const const char * const struct const_blob { const char *c; size_t l } typedef"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24458/"
] |
161,790
|
<p>I have the following class in C++:</p>
<pre><code>class a {
const int b[2];
// other stuff follows
// and here's the constructor
a(void);
}
</code></pre>
<p>The question is, how do I initialize b in the initialization list, given that I can't initialize it inside the body of the function of the constructor, because b is <code>const</code>?</p>
<p>This doesn't work:</p>
<pre><code>a::a(void) :
b([2,3])
{
// other initialization stuff
}
</code></pre>
<p>Edit: The case in point is when I can have different values for <code>b</code> for different instances, but the values are known to be constant for the lifetime of the instance.</p>
|
[
{
"answer_id": 161829,
"author": "Daniel Bungert",
"author_id": 21093,
"author_profile": "https://Stackoverflow.com/users/21093",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n\nclass a {\n static const int b[2];\npublic:\n a(void) {\n for(int i = 0; i < 2; i++) {\n printf(\"b[%d] = [%d]\\n\", i, b[i]);\n }\n }\n};\n\nconst int a::b[2] = { 4, 2 };\n\nint main(int argc, char **argv)\n{\n a foo;\n return 0;\n}\n"
},
{
"answer_id": 161875,
"author": "orj",
"author_id": 20480,
"author_profile": "https://Stackoverflow.com/users/20480",
"pm_score": 3,
"selected": false,
"text": "a::a(void) :\nb({2,3})\n{\n // other initialization stuff\n}\n #include <iostream>\n\nclass A \n{\npublic:\n A();\n static const int a[2];\n};\n\nconst int A::a[2] = {0, 1};\n\nA::A()\n{\n}\n\nint main (int argc, char * const argv[]) \n{\n std::cout << \"A::a => \" << A::a[0] << \", \" << A::a[1] << \"\\n\";\n return 0;\n}\n A::a => 0, 1\n #include <iostream>\n\nclass A \n{\npublic:\n A();\n int a[2];\n};\n\nA::A()\n{\n a[0] = 9; // or some calculation\n a[1] = 10; // or some calculation\n}\n\nint main (int argc, char * const argv[]) \n{\n A v;\n std::cout << \"v.a => \" << v.a[0] << \", \" << v.a[1] << \"\\n\";\n return 0;\n}\n"
},
{
"answer_id": 162372,
"author": "Weipeng",
"author_id": 192280,
"author_profile": "https://Stackoverflow.com/users/192280",
"pm_score": 6,
"selected": true,
"text": "int* a = new int[N];\n// fill a\n\nclass C {\n const std::vector<int> v;\npublic:\n C():v(a, a+N) {}\n};\n"
},
{
"answer_id": 922255,
"author": "Nefzen",
"author_id": 112830,
"author_profile": "https://Stackoverflow.com/users/112830",
"pm_score": 2,
"selected": false,
"text": "readonly DateTime a = DateTime.Now;\n //in header file\nclass a{\n static const int SIZE;\n static const char array[][10];\n};\n//in cpp file:\nconst int a::SIZE = 5;\nconst char array[SIZE][10] = {\"hello\", \"cruel\",\"world\",\"goodbye\", \"!\"};\n"
},
{
"answer_id": 2642704,
"author": "Matthew",
"author_id": 317152,
"author_profile": "https://Stackoverflow.com/users/317152",
"pm_score": 4,
"selected": false,
"text": "std::vector const std::vector #include <stdio.h>\n\n\ntemplate <class Type, size_t MaxLength>\nclass ConstFixedSizeArrayFiller {\nprivate:\n size_t length;\n\npublic:\n ConstFixedSizeArrayFiller() : length(0) {\n }\n\n virtual ~ConstFixedSizeArrayFiller() {\n }\n\n virtual void Fill(Type *array) = 0;\n\nprotected:\n void add_element(Type *array, const Type & element)\n {\n if(length >= MaxLength) {\n // todo: throw more appropriate out-of-bounds exception\n throw 0;\n }\n array[length] = element;\n length++;\n }\n};\n\n\ntemplate <class Type, size_t Length>\nclass ConstFixedSizeArray {\nprivate:\n Type array[Length];\n\npublic:\n explicit ConstFixedSizeArray(\n ConstFixedSizeArrayFiller<Type, Length> & filler\n ) {\n filler.Fill(array);\n }\n\n const Type *Array() const {\n return array;\n }\n\n size_t ArrayLength() const {\n return Length;\n }\n};\n\n\nclass a {\nprivate:\n class b_filler : public ConstFixedSizeArrayFiller<int, 2> {\n public:\n virtual ~b_filler() {\n }\n\n virtual void Fill(int *array) {\n add_element(array, 87);\n add_element(array, 96);\n }\n };\n\n const ConstFixedSizeArray<int, 2> b;\n\npublic:\n a(void) : b(b_filler()) {\n }\n\n void print_items() {\n size_t i;\n for(i = 0; i < b.ArrayLength(); i++)\n {\n printf(\"%d\\n\", b.Array()[i]);\n }\n }\n};\n\n\nint main()\n{\n a x;\n x.print_items();\n return 0;\n}\n ConstFixedSizeArrayFiller ConstFixedSizeArray const b_filler"
},
{
"answer_id": 2861574,
"author": "CharlesB",
"author_id": 11343,
"author_profile": "https://Stackoverflow.com/users/11343",
"pm_score": 2,
"selected": false,
"text": "std::vector boost::array #include <boost/array.hpp>\n\nconst boost::array<int, 2> aa={ { 2, 3} };\n\nclass A {\n const boost::array<int, 2> b;\n A():b(aa){};\n};\n"
},
{
"answer_id": 6308072,
"author": "Pete",
"author_id": 782738,
"author_profile": "https://Stackoverflow.com/users/782738",
"pm_score": 2,
"selected": false,
"text": "class a {\n int privateB[2];\npublic:\n a(int b0,b1) { privateB[0]=b0; privateB[1]=b1; }\n int b(const int idx) { return privateB[idx]; }\n}\n a aobj(2,3); // initialize \"constant array\" b[]\nn = aobj.b(1); // read b[1] (write impossible from here)\n"
},
{
"answer_id": 7806293,
"author": "Flexo",
"author_id": 168175,
"author_profile": "https://Stackoverflow.com/users/168175",
"pm_score": 6,
"selected": false,
"text": "struct a {\n const int b[2];\n // other bits follow\n\n // and here's the constructor\n a();\n};\n\na::a() :\n b{2,3}\n{\n // other constructor work\n}\n\nint main() {\n a a;\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1084/"
] |
161,794
|
<p>I am not sure if I formulated the question right, but still ...</p>
<p>I have a view that shows a flash embed and this flash take as parameter a <code>/controller/action</code> URL that generates a XML. I nee to send, from this view, an array to the XML generator action. How is the best way ? Is there some <code>helper->set()</code> method like or I have to create an specific URL to send this array to that action ?</p>
<p>Here goes my structure:</p>
<p><strong><code>my_controller.php</code></strong></p>
<pre><code>function player() {}
</code></pre>
<p><strong><code>player.ctp</code></strong></p>
<pre><code><div id="myDiv">Here it Goes</div>
<script type="text/javascript">
var so = new SWFObject('player.swf','test','50','50','8');
so.addVariable('file','/xml/generate'); // need to pass an array here
so.write('myDiv');
</script>
</code></pre>
<p><strong><code>xml_controller.php</code></strong></p>
<pre><code>public function generate() {
// I need to read an array here
}
</code></pre>
<p><strong><code>generate.ctp</code></strong></p>
<pre><code>echo "<xml><data>" . $array['contents'] . "</data>";
</code></pre>
|
[
{
"answer_id": 163979,
"author": "neilcrookes",
"author_id": 9968,
"author_profile": "https://Stackoverflow.com/users/9968",
"pm_score": 1,
"selected": false,
"text": "function player() {\n $this->Session->write('key', $array);\n}\n public function generate() {\n $array = $this->Session->read('key');\n}\n so.addVariable('file','/xml/generate/<?php echo $session->id(); ?>');\n public function generate($sessionId) {\n CakeSession::id($sessionId);\n $array = $this->Session->read('key');\n}\n"
},
{
"answer_id": 164000,
"author": "neilcrookes",
"author_id": 9968,
"author_profile": "https://Stackoverflow.com/users/9968",
"pm_score": 2,
"selected": false,
"text": "so.addVariable('file','/xml/generate/<?php echo urlencode(serialize($array)); ?>');\n public function generate($array) {\n $array = unserialize($array);\n}\n"
},
{
"answer_id": 9646309,
"author": "Vincent",
"author_id": 1260980,
"author_profile": "https://Stackoverflow.com/users/1260980",
"pm_score": 0,
"selected": false,
"text": "www.site.com/model/action/param1:foo/param2:test\n $yourarray = $this->params['named'];\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161794",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2274/"
] |
161,797
|
<p><a href="https://stackoverflow.com/questions/160930">Another question</a> asked about determining odd/evenness in C, and the idiomatic (x & 1) approach was correctly flagged as broken for <a href="http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement" rel="noreferrer">one's complement-based</a> systems, which the C standard allows for.</p>
<p>Do systems really exist in the 'real world' outside of computer museums? I've been coding since the 1970's and I'm pretty sure I've never met such a beast. </p>
<p>Is anyone actually developing or testing code for such a system? And, if not, should we worry about such things or should we put them into <a href="http://en.wikipedia.org/wiki/Room_101" rel="noreferrer">Room 101</a> along with paper tape and punch cards...?</p>
|
[
{
"answer_id": 46440337,
"author": "Antti Haapala -- Слава Україні",
"author_id": 918959,
"author_profile": "https://Stackoverflow.com/users/918959",
"pm_score": 3,
"selected": false,
"text": "Type | Bits | Range\n---------------------+------+-----------------\nsigned char | 9 | -2⁸+1 ... 2⁸-1\nsigned short | 18 | -2¹⁷+1 ... 2¹⁷-1\nsigned int | 36 | -2³⁵+1 ... 2³⁵-1\nsigned long int | 36 | -2³⁵+1 ... 2³⁵-1\nsigned long long int | 72 | -2⁷¹+1 ... 2⁷¹-1\n unsigned int unsigned long 0 ... 2³⁶ - 2 0 ... 2³⁶ - 1"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161797",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737/"
] |
161,813
|
<p>How do I resolve merge conflicts in my Git repository?</p>
|
[
{
"answer_id": 162056,
"author": "davetron5000",
"author_id": 3029,
"author_profile": "https://Stackoverflow.com/users/3029",
"pm_score": 9,
"selected": false,
"text": "git add the_file git rebase --continue"
},
{
"answer_id": 163234,
"author": "Paul",
"author_id": 23356,
"author_profile": "https://Stackoverflow.com/users/23356",
"pm_score": 6,
"selected": false,
"text": "git log --merge git diff git config merge.tool \"your.tool\" git mergetool git add filename git add git commit"
},
{
"answer_id": 163659,
"author": "Peter Burns",
"author_id": 101,
"author_profile": "https://Stackoverflow.com/users/101",
"pm_score": 13,
"selected": true,
"text": "git mergetool\n git mergetool vimdiff meld opendiff kdiff3 tkdiff xxdiff tortoisemerge gvimdiff diffuse ecmerge p4merge araxis vimdiff emerge vimdiff git config merge.tool vimdiff\ngit config merge.conflictstyle diff3\ngit config mergetool.prompt false\n vimdiff git mergetool\n vimdiff ╔═══════╦══════╦════════╗\n ║ ║ ║ ║\n ║ LOCAL ║ BASE ║ REMOTE ║\n ║ ║ ║ ║\n ╠═══════╩══════╩════════╣\n ║ ║\n ║ MERGED ║\n ║ ║\n ╚═══════════════════════╝\n vimdiff :diffg RE\n :diffg BA\n :diffg LO\n :wqa git commit -m \"message\" git clean *.orig"
},
{
"answer_id": 167365,
"author": "Pat Notz",
"author_id": 825,
"author_profile": "https://Stackoverflow.com/users/825",
"pm_score": 7,
"selected": false,
"text": "# Common base version of the file.\ngit show :1:some_file.cpp\n\n# 'Ours' version of the file.\ngit show :2:some_file.cpp\n\n# 'Theirs' version of the file.\ngit show :3:some_file.cpp\n"
},
{
"answer_id": 3407920,
"author": "coolaj86",
"author_id": 151312,
"author_profile": "https://Stackoverflow.com/users/151312",
"pm_score": 11,
"selected": false,
"text": "git fetch origin\ngit pull origin master\n\nFrom ssh://gitosis@example.com:22/projectname\n * branch master -> FETCH_HEAD\nUpdating a030c3a..ee25213\nerror: Entry 'filename.c' not uptodate. Cannot merge.\n git add filename.c\ngit commit -m \"made some wild and crazy changes\"\ngit pull origin master\n\nFrom ssh://gitosis@example.com:22/projectname\n * branch master -> FETCH_HEAD\nAuto-merging filename.c\nCONFLICT (content): Merge conflict in filename.c\nAutomatic merge failed; fix conflicts and then commit the result.\n git mergetool\n git checkout --ours filename.c\ngit checkout --theirs filename.c\ngit add filename.c\ngit commit -m \"using theirs\"\n git pull origin master\n\nFrom ssh://gitosis@example.com:22/projectname\n * branch master -> FETCH_HEAD\nAlready up-to-date.\n"
},
{
"answer_id": 7589612,
"author": "Mark E. Haase",
"author_id": 122763,
"author_profile": "https://Stackoverflow.com/users/122763",
"pm_score": 10,
"selected": false,
"text": "git config merge.conflictstyle diff3 <<<<<<<\nChanges made on the branch that is being merged into. In most cases,\nthis is the branch that I have currently checked out (i.e. HEAD).\n|||||||\nThe common ancestor version.\n=======\nChanges made on the branch that is being merged in. This is often a \nfeature/topic branch.\n>>>>>>>\n diff common mine\ndiff common theirs\n git log --merge -p <name of file>\n"
},
{
"answer_id": 15034682,
"author": "eci",
"author_id": 535192,
"author_profile": "https://Stackoverflow.com/users/535192",
"pm_score": 5,
"selected": false,
"text": "git diff --name-status --diff-filter=U\n emacs $(git diff --name-only --diff-filter=U)\n ALT+x vc-resolve-conflicts\n git add FILENAME\n git commit\n"
},
{
"answer_id": 16095649,
"author": "Michael Durrant",
"author_id": 631619,
"author_profile": "https://Stackoverflow.com/users/631619",
"pm_score": 5,
"selected": false,
"text": "git add .\ngit commit -m\"some msg\"\n git add file,file2,file3...\ngit commit # Then type the files in the editor and save-quit.\n -m git status # Make sure I know whats going on\ngit add .\ngit commit # Then use the editor\n git pull\n git pull origin master.\n git checkout master\ngit fetch \ngit rebase --hard origin/master # or whatever branch I want.\n"
},
{
"answer_id": 17642404,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": false,
"text": "git merge HEAD git merge --abort git add git commit git mergetool git diff HEAD MERGE_HEAD git log --merge -p <path> HEAD MERGE_HEAD git show :1:filename git show :2:filename HEAD git show :3:filename MERGE_HEAD"
},
{
"answer_id": 21352966,
"author": "iankit",
"author_id": 1620792,
"author_profile": "https://Stackoverflow.com/users/1620792",
"pm_score": 5,
"selected": false,
"text": "(Code not in Conflict)\n>>>>>>>>>>>\n(first alternative for conflict starts here)\nMultiple code lines here\n===========\n(second alternative for conflict starts here)\nMultiple code lines here too \n<<<<<<<<<<<\n(Code not in conflict here)\n git commit -a -m \"commit message\"\ngit push origin master\n"
},
{
"answer_id": 24135969,
"author": "trai bui",
"author_id": 2285933,
"author_profile": "https://Stackoverflow.com/users/2285933",
"pm_score": -1,
"selected": false,
"text": "- `checkout master`\n- `git pull` / get new commit\n- `git checkout` to your branch\n- `git rebase master`\n"
},
{
"answer_id": 25370867,
"author": "Haimei",
"author_id": 2730862,
"author_profile": "https://Stackoverflow.com/users/2730862",
"pm_score": 5,
"selected": false,
"text": "test master git checkout test\n git pull --rebase origin master\n git add #your_changes_files\n git rebase --continue\n git push origin +test\n"
},
{
"answer_id": 27426207,
"author": "Brian Di Palma",
"author_id": 1927079,
"author_profile": "https://Stackoverflow.com/users/1927079",
"pm_score": 4,
"selected": false,
"text": "git log --merge -p [[--] path]\n -- git log ..$MERGED_IN_BRANCH --pretty=full -p [path]\n git log $MERGED_IN_BRANCH.. --pretty=full -p [path]\n $MERGED_IN_BRANCH [path] .. HEAD"
},
{
"answer_id": 28469286,
"author": "Chetan",
"author_id": 2486083,
"author_profile": "https://Stackoverflow.com/users/2486083",
"pm_score": 4,
"selected": false,
"text": "git checkout master git pull git checkout -b mybranch git add . git commit git checkout master git checkout"
},
{
"answer_id": 31835412,
"author": "kenorb",
"author_id": 55075,
"author_profile": "https://Stackoverflow.com/users/55075",
"pm_score": 7,
"selected": false,
"text": "git git status Unmerged paths git mergetool git checkout --theirs path/file git checkout --ours path/file <<<<< >>>>> ===== git add git rm git status Unmerged paths git add path/file git commit -a git mergetool -t diffmerge .\n brew install caskroom/cask/brew-cask\nbrew cask install diffmerge\n /usr/bin #!/bin/sh\nDIFFMERGE_PATH=/Applications/DiffMerge.app\nDIFFMERGE_EXE=${DIFFMERGE_PATH}/Contents/MacOS/DiffMerge\nexec ${DIFFMERGE_EXE} --nosplash \"$@\"\n"
},
{
"answer_id": 34464046,
"author": "Sazzad Hissain Khan",
"author_id": 1084174,
"author_profile": "https://Stackoverflow.com/users/1084174",
"pm_score": 5,
"selected": false,
"text": "git pull --rebase git pull --rebase git pull merge git mergetool\ngit add conflict_file\ngit rebase --continue\n"
},
{
"answer_id": 35020326,
"author": "Mohamed Ali",
"author_id": 4356754,
"author_profile": "https://Stackoverflow.com/users/4356754",
"pm_score": 5,
"selected": false,
"text": "git checkout . --ours\n git checkout . --theirs\n p4merge git mergetool -t p4merge\n"
},
{
"answer_id": 37893577,
"author": "akardon",
"author_id": 3795379,
"author_profile": "https://Stackoverflow.com/users/3795379",
"pm_score": 4,
"selected": false,
"text": "git fetch git merge git fetch git rebase git pull git stash pop $ git config --global --add merge.tool kdiff3\n$ git config --global --add mergetool.kdiff3.path \"C:/Program Files/KDiff3/kdiff3.exe\"\n$ git config --global --add mergetool.kdiff3.trustExitCode false\n\n$ git config --global --add diff.guitool kdiff3\n$ git config --global --add difftool.kdiff3.path \"C:/Program Files/KDiff3/kdiff3.exe\"\n$ git config --global --add difftool.kdiff3.trustExitCode false\n $ git mergetool\n $ git mergetool\nNo files need merging\n"
},
{
"answer_id": 39771096,
"author": "Noidea",
"author_id": 6822575,
"author_profile": "https://Stackoverflow.com/users/6822575",
"pm_score": 6,
"selected": false,
"text": "git checkout --ours -- <filename>\ngit add <filename> # Marks conflict as resolved\ngit commit -m \"merged bla bla\" # An \"empty\" commit\n git checkout --theirs -- <filename>\ngit add <filename>\ngit commit -m \"merged bla bla\"\n git merge --strategy-option ours\n git merge --strategy-option theirs\n git mergetool git add <filename> git commit -m \"merged bla bla\" mergetool meld git mergetool -t meld\n git mergetool -t meld"
},
{
"answer_id": 40896972,
"author": "Conchylicultor",
"author_id": 4172685,
"author_profile": "https://Stackoverflow.com/users/4172685",
"pm_score": 4,
"selected": false,
"text": "patience patience { patience git merge -s recursive -X patience other-branch\n With this option, merge-recursive spends a little extra time to avoid \nmismerges that sometimes occur due to unimportant matching lines \n(e.g., braces from distinct functions). Use this when the branches to \nbe merged have diverged wildly.\n merge-base git diff $(git merge-base <our-branch> <their-branch>) <their-branch>\n git diff $(git merge-base <our-branch> <their-branch>) <their-branch> <file>\n"
},
{
"answer_id": 44724095,
"author": "Qijun Liu",
"author_id": 5771924,
"author_profile": "https://Stackoverflow.com/users/5771924",
"pm_score": 5,
"selected": false,
"text": " git status\n <<<<<<<<head\n blablabla\n git add solved_conflicts_files\n git commit -m 'merge msg'\n"
},
{
"answer_id": 44927577,
"author": "Baini.Marouane",
"author_id": 6204104,
"author_profile": "https://Stackoverflow.com/users/6204104",
"pm_score": 3,
"selected": false,
"text": "git fetch <br>\ngit checkout **your branch**<br>\ngit rebase master<br>\n git add<br>\ngit rebase --continue<br>\ngit commit --amend<br>\ngit push origin HEAD:refs/drafts/master (push like a drafts)<br>\n"
},
{
"answer_id": 45039920,
"author": "AJC",
"author_id": 6292652,
"author_profile": "https://Stackoverflow.com/users/6292652",
"pm_score": 2,
"selected": false,
"text": "git checkout <localbranch>\ngit merge origin/<remotebranch>\n git status Unmerged paths:\n(use \"git add <file>...\" to mark resolution)\nboth modified: src/test/java/com/.../TestClass.java\n <<<<<<< HEAD\n public void testMethod() {\n }\n =======\n public void testMethod() { ...\n }\n >>>>>>> origin/<remotebranch>\n git add TestClass.java\n git commit -m \"commit message\"\n git push\n"
},
{
"answer_id": 46738478,
"author": "Aniruddha Das",
"author_id": 537647,
"author_profile": "https://Stackoverflow.com/users/537647",
"pm_score": 1,
"selected": false,
"text": "git pull origin develop git add commit push git add git commit git push origin HEAD"
},
{
"answer_id": 46763813,
"author": "Vicente Bolea",
"author_id": 2420872,
"author_profile": "https://Stackoverflow.com/users/2420872",
"pm_score": 3,
"selected": false,
"text": ":Gstatus :Gdiff :diffget //2 :diffget //3 :Gwrite"
},
{
"answer_id": 49314436,
"author": "Kailash Bhalaki",
"author_id": 8253389,
"author_profile": "https://Stackoverflow.com/users/8253389",
"pm_score": 2,
"selected": false,
"text": "incoming current change"
},
{
"answer_id": 62220397,
"author": "Friedrich",
"author_id": 11769765,
"author_profile": "https://Stackoverflow.com/users/11769765",
"pm_score": -1,
"selected": false,
"text": "git reset --hard origin/master\n"
},
{
"answer_id": 66118061,
"author": "stevec",
"author_id": 5783745,
"author_profile": "https://Stackoverflow.com/users/5783745",
"pm_score": 4,
"selected": false,
"text": "git diff git diff\n++<<<<<<< HEAD\n + display full last name boolean in star table\n++=======\n+ users viewer.id/star.id, and conversation uses user.id\n+\n++>>>>>>> feat/rspec-tests-for-cancancan\n <<<<<<< ======= ======= >>>>>>> merge"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161813",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] |
161,819
|
<p>What are the main/best Maven repositories to use that will include the majority of your open source Java package dependencies.</p>
<p>Also in what order should these be included? Does it matter?</p>
|
[
{
"answer_id": 161846,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 5,
"selected": false,
"text": "<repository>\n <id>MavenCentral</id>\n <name>Maven repository</name>\n <url>http://repo1.maven.org/maven2</url>\n <releases>\n <enabled>true</enabled>\n </releases>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n</repository>\n<repository>\n <id>objectweb</id>\n <name>Objectweb repository</name>\n <url>http://maven.objectweb.org/maven2</url>\n <releases>\n <enabled>true</enabled>\n </releases>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n</repository>\n<repository>\n <id>jboss</id>\n <name>JBoss Maven2 repository</name>\n <url>http://repository.jboss.com/maven2/</url>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n <releases>\n <enabled>true</enabled>\n </releases>\n</repository>\n<repository>\n <id>glassfish</id>\n <name>Glassfish repository</name>\n <url>http://download.java.net/maven/1</url>\n <layout>legacy</layout>\n <releases>\n <enabled>true</enabled>\n </releases>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n</repository>\n<repository>\n <id>apache.snapshots</id>\n <name>Apache Snapshot Repository</name>\n <url>\n http://people.apache.org/repo/m2-snapshot-repository\n </url>\n <releases>\n <enabled>false</enabled>\n </releases>\n <snapshots>\n <enabled>true</enabled>\n </snapshots>\n</repository>\n<repository>\n <id>ops4j.repository</id>\n <name>OPS4J Repository</name>\n <url>http://repository.ops4j.org/maven2</url>\n <releases>\n <enabled>true</enabled>\n </releases>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n</repository>\n<repository>\n <id>Codehaus Snapshots</id>\n <url>http://snapshots.repository.codehaus.org/</url>\n <snapshots>\n <enabled>true</enabled>\n </snapshots>\n <releases>\n <enabled>false</enabled>\n </releases>\n</repository>\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17719/"
] |
161,822
|
<p>I have several similar methods, say eg. CalculatePoint(...) and CalculateListOfPoints(...). Occasionally, they may not succeed, and need to indicate this to the caller. For CalculateListOfPoints, which returns a generic List, I could return an empty list and require the caller to check this; however Point is a value type and so I can't return null there.</p>
<p>Ideally I would like the methods to 'look' similar; one solution could be to define them as </p>
<pre><code>public Point CalculatePoint(... out Boolean boSuccess);
public List<Point> CalculateListOfPoints(... out Boolean boSuccess);
</code></pre>
<p>or alternatively to return a Point? for CalculatePoint, and return null to indicate failure. That would mean having to cast back to the non-nullable type though, which seems excessive.</p>
<p>Another route would be to return the Boolean boSuccess, have the result (Point or List) as an 'out' parameter, and call them TryToCalculatePoint or something...</p>
<p>What is best practice? </p>
<p>Edit: I do not want to use Exceptions for flow control! Failure is sometimes expected.</p>
|
[
{
"answer_id": 161834,
"author": "Luk",
"author_id": 5789,
"author_profile": "https://Stackoverflow.com/users/5789",
"pm_score": 6,
"selected": true,
"text": "public bool CalculatePoint(... out Point result);"
},
{
"answer_id": 161840,
"author": "Jonathan C Dickinson",
"author_id": 24064,
"author_profile": "https://Stackoverflow.com/users/24064",
"pm_score": 0,
"selected": false,
"text": "// NB: A bool is the return value. \n// This makes it possible to put this beast in if statements.\npublic bool TryCalculatePoint(... out Point result) { }\n\npublic Point CalculatePoint(...)\n{\n Point result;\n if(!TryCalculatePoint(... out result))\n throw new BogusPointException();\n return result;\n}\n"
},
{
"answer_id": 162151,
"author": "artur02",
"author_id": 13937,
"author_profile": "https://Stackoverflow.com/users/13937",
"pm_score": 1,
"selected": false,
"text": "public static readonly Point Empty\n"
},
{
"answer_id": 162237,
"author": "Samuel Jack",
"author_id": 1727,
"author_profile": "https://Stackoverflow.com/users/1727",
"pm_score": 1,
"selected": false,
"text": "/// <summary>\n/// Represents the return value from an operation that might fail\n/// </summary>\n/// <typeparam name=\"T\"></typeparam>\npublic struct Maybe<T>\n{\n T _value;\n bool _hasValue;\n\n\n public Maybe(T value)\n {\n _value = value;\n _hasValue = true;\n }\n\n public Maybe()\n {\n _hasValue = false;\n _value = default(T);\n }\n\n\n public bool Success\n {\n get { return _hasValue; }\n }\n\n\n public T Value\n {\n get \n { // could throw an exception if _hasValue is false\n return _value; \n }\n }\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6091/"
] |
161,828
|
<p>I need to control the data type when reading XML data in SAS. The XML data are written and accessed using the XML libname engine in SAS.</p>
<p>SAS seems to guess the data type based on the contents of a column: If I write "20081002" to my XML data in a character column, it will be read back in as a numerical variable.</p>
<p>An example:</p>
<pre><code>filename my_xml '/tmp/my.xml'; * Yes, I use SAS on Unix *;
libname my_xml XML;
data my_xml.data_type_test;
text_char="This is obviously text";
date_char="20081002";
num_char="42";
genuine_num=42;
run;
proc copy inlib=my_xml outlib=WORK;
run;
libname my_xml;
filename my_xml CLEAR;
</code></pre>
<p>Only the last column is defined as numerical data type in the XML data, but when I copy it into my WORK library, only the column <em>text_char</em> is character. The other 3 are now numeric.</p>
<p>How can I control the data type when reading XML data in SAS?</p>
|
[
{
"answer_id": 162067,
"author": "jilles de wit",
"author_id": 7531,
"author_profile": "https://Stackoverflow.com/users/7531",
"pm_score": 1,
"selected": false,
"text": "libname my_xml_out XML XMLMETA=SCHEMADATA;\n libname my_xml_in XML XMLSCHEMA='external-file'\n XMLMETA=SCHEMA"
},
{
"answer_id": 536786,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "<!-- ############################################################ -->\n<TABLE name=\"DATA_TYPE_TEST\">\n <TABLE-PATH syntax=\"XPath\">/TABLE/DATA_TYPE_TEST</TABLE-PATH>\n\n <COLUMN name=\"text_char\">\n <PATH syntax=\"XPath\">/TABLE/DATA_TYPE_TEST/text_char</PATH>\n <TYPE>character</TYPE>\n <DATATYPE>string</DATATYPE>\n <LENGTH>22</LENGTH>\n </COLUMN>\n\n <COLUMN name=\"date_char\">\n <PATH syntax=\"XPath\">/TABLE/DATA_TYPE_TEST/date_char</PATH>\n <TYPE>numeric</TYPE>\n <DATATYPE>integer</DATATYPE>\n <FORMAT width=\"9\">DATE</FORMAT>\n <INFORMAT width=\"8\">ND8601DA</INFORMAT>\n </COLUMN>\n\n <COLUMN name=\"num_char\">\n <PATH syntax=\"XPath\">/TABLE/DATA_TYPE_TEST/num_char</PATH>\n <TYPE>character</TYPE>\n <DATATYPE>string</DATATYPE>\n <LENGTH>2</LENGTH>\n </COLUMN>\n\n <COLUMN name=\"genuine_num\">\n <PATH syntax=\"XPath\">/TABLE/DATA_TYPE_TEST/genuine_num</PATH>\n <TYPE>numeric</TYPE>\n <DATATYPE>integer</DATATYPE>\n </COLUMN>\n\n</TABLE>\n filename my 'C:\\temp\\my.xml';\nfilename SXLEMAP 'C:\\temp\\MyMap.map';\nlibname my xml xmlmap=SXLEMAP access=READONLY;\n\ntitle 'Table DATA_TYPE_TEST';\nproc contents data=my.DATA_TYPE_TEST varnum; \nrun;\nproc print data=my.DATA_TYPE_TEST(obs=10); \nrun;\n Table DATA_TYPE_TEST\n\nThe CONTENTS Procedure\n\nData Set Name MY.DATA_TYPE_TEST Observations \nMember Type DATA Variables 4 \nEngine XML Indexes 0 \nCreated . Observation Length 0 \nLast Modified . Deleted Observations 0 \nProtection Compressed NO\nData Set Type Sorted NO\nLabel \nData Representation Default \nEncoding Default \n\n\nVariables in Creation Order\n\n# Variable Type Len Format Informat Label\n\n1 text_char Char 22 $22. $22. text_char \n2 date_char Num 8 DATE9. ND8601DA8. date_char \n3 num_char Char 2 $2. $2. num_char \n4 genuine_num Num 8 F8. F8. genuine_num\n\nTable DATA_TYPE_TEST\n\n genuine_\n Obs text_char date_char num_char num\n\n 1 This is obviously text 02OCT2008 42 42\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18968/"
] |
161,838
|
<p>Is it possible to unlisten on a socket after you have called listen(fd, backlog)? </p>
<p>Edit: My mistake for not making myself clear. I'd like to be able to temporarily unlisten on the socket. Calling close() will leave the socket in the M2LS state and prevent me from reopening it (or worse, some nefarious program could bind to that socket)</p>
<p>Temporarily unlistening would be a way (maybe not the best way) to signal to an upstream load balancer that this app couldn't accept any more requests for the moment</p>
|
[
{
"answer_id": 161841,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 2,
"selected": false,
"text": "close(fd);\n"
},
{
"answer_id": 161896,
"author": "prakash",
"author_id": 123,
"author_profile": "https://Stackoverflow.com/users/123",
"pm_score": 1,
"selected": false,
"text": "close(fd) shutdown(fd, how) fd is the socket file descriptor you want to shutdown, and how is one of the following:\n\n0 Further receives are disallowed\n\n1 Further sends are disallowed\n\n2 Further sends and receives are disallowed (like close())\n"
},
{
"answer_id": 169005,
"author": "Andrew Johnson",
"author_id": 5109,
"author_profile": "https://Stackoverflow.com/users/5109",
"pm_score": 4,
"selected": true,
"text": "while (running) {\n\n int i32ConnectFD = accept(i32SocketFD, NULL, NULL);\n while (noConnectionsPlease) {\n shutdown(i32ConnectFD, 2);\n close(i32ConnectFD);\n break;\n }\n\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6449/"
] |
161,852
|
<p>I have a slight problem reading data from file. I want to be able to read wstring's, aswell as a chunk of raw data of arbitrary size (size is in bytes). </p>
<pre><code>std::wfstream stream(file.c_str());
std::wstring comType;
stream >> comType;
int comSize;
stream >> comSize;
char *comData = new char[comSize];
memset(comData, 0, comSize);
stream.read(comData, comSize);
//error C2664 : 'std::basic_istream<_Elem,_Traits>::read'
// : cannot convert parameter 1 from 'char *' to 'wchar_t *'
</code></pre>
<p>Perhaps I am using wrong streams, or something along those lines. Basically, I want to read a wstring, size of the data followed (which could be any number of bytes), followed by that many bytes of component data. Obviously, I can't read char's because the template assumes wchar_t's.</p>
<p>I can read wchar_t's but then I have to make sure the data is stored as aligned by sizeof(wchar_t). Otherwise, I could end up corrupting the stream. A scenario would be when the data is 15 bytes. I would have to read 16 bytes, then mask the unwanted byte, seek the stream to 15 bytes offset (if possible with wchar_t templated?) to be able to read the next data chunk.</p>
<p>Clearly, there <em>should</em> be a nicer way of achieving what I am trying to do.</p>
|
[
{
"answer_id": 161878,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 1,
"selected": false,
"text": "#include \"stdafx.h\"\n#include <fstream>\n#include <iostream>\n\nint _tmain(int argc, _TCHAR* argv[])\n{\n std::wstring str(L\"hello\");\n size_t size1 = str.length();\n char data[] = { 0x10, 0x20, 0x30 };\n size_t size2 = 3;\n\n FILE* output = NULL;\n if (_wfopen_s(&output, L\"c:\\\\test.bin\", L\"wb\") == 0) {\n fwrite(&size1, sizeof(size_t), 1, output);\n fwrite(str.c_str(), size1 * sizeof(wchar_t), 1, output);\n fwrite(&size2, sizeof(size_t), 1, output);\n fwrite(data, size2, 1, output);\n\n fclose(output);\n }\n\n FILE* input = NULL;\n if (_wfopen_s(&input, L\"c:\\\\test.bin\", L\"rb\") == 0) {\n fread(&size1, sizeof(size_t), 1, input);\n wchar_t* wstr = new wchar_t[size1 + 1];\n fread(wstr, size1 * sizeof(wchar_t), 1, input);\n std::wstring str(wstr, size1);\n delete[] wstr;\n fread(&size2, sizeof(size_t), 1, input);\n char* data1 = new char[size2];\n fread(data1, size2, 1, input);\n\n std::wcout << str.c_str() << std::endl;\n for (size_t i = 0; i < size2; ++i) {\n std::wcout << std::hex << \"0x\" << int(data1[i]) << std::endl;\n }\n\n delete[] data1;\n\n fclose(input);\n }\n\n return 0;\n}\n hello\n0x10\n0x20\n0x30\n"
},
{
"answer_id": 162108,
"author": "Fionn",
"author_id": 21566,
"author_profile": "https://Stackoverflow.com/users/21566",
"pm_score": 2,
"selected": false,
"text": "wchar_t *comData = new wchar_t[comSize];\nstream.read(comData, comSize);\n"
},
{
"answer_id": 21128284,
"author": "Jac08in",
"author_id": 887061,
"author_profile": "https://Stackoverflow.com/users/887061",
"pm_score": 0,
"selected": false,
"text": "# ifdef UNICODE\n# define tfstream wfstream\n# else\n# define tfstream fstream\n# endif\n\ntfstream fs( _T(\"filename.bin\"), tfstream::binary );\nbyte buffer[1023];\nfs.read( buffer, sizeof(buffer) )\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2166173/"
] |
161,859
|
<p>I'd like to invoke bash using a string as input. Something like:</p>
<pre><code>sh -l -c "./foo"
</code></pre>
<p>I'd like to do this from Java. Unfortunately, when I try to invoke the command using <code>getRuntime().exec</code>, I get the following error: </p>
<pre><code> foo": -c: line 0: unexpected EOF while looking for matching `"'
foo": -c: line 1: syntax error: unexpected end of file
</code></pre>
<p>It seems to be related to my string not being terminated with an EOF. </p>
<p>Is there a way to insert a platform specific EOF into a Java string? Or should I be looking for another approach, like writing to a temp script before invoking "sh" ?</p>
|
[
{
"answer_id": 161888,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 7,
"selected": true,
"text": "Runtime.getRuntime().exec(new String[] {\"sh\", \"-l\", \"-c\", \"./foo\"});\n echo \"Hello, world!\" Runtime.getRuntime().exec(new String[] {\"echo\", \"Hello, world!\"});\n echo /bin/echo"
},
{
"answer_id": 162577,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 4,
"selected": false,
"text": "main String Process exec(String[] cmdarray) \nProcess exec(String[] cmdarray, String[] envp) \nProcess exec(String[] cmdarray, String[] envp, File dir)\n java.lang.ProcessBuilder Runtime.getRuntime().exec(new String[] {\n \"sh\", \"-c\", \"sh -l -c \\\"echo foo; echo bar;\\\"\"\n});\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20426/"
] |
161,872
|
<p>What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?</p>
<p>Guidelines:</p>
<ul>
<li>Try to limit answers to the Perl core and not CPAN</li>
<li>Please give an example and a short description</li>
</ul>
<hr>
<h2>Hidden Features also found in other languages' Hidden Features:</h2>
<p>(These are all from <a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162257">Corion's answer</a>)</p>
<ul>
<li><a href="https://stackoverflow.com/questions/132241/hidden-features-of-c#">C</a>
<ul>
<li>Duff's Device</li>
<li>Portability and Standardness</li>
</ul></li>
<li><a href="https://stackoverflow.com/questions/9033/hidden-features-of-c">C#</a>
<ul>
<li>Quotes for whitespace delimited lists and strings</li>
<li>Aliasable namespaces</li>
</ul></li>
<li><a href="https://stackoverflow.com/questions/15496/hidden-features-of-java">Java</a>
<ul>
<li>Static Initalizers</li>
</ul></li>
<li><a href="https://stackoverflow.com/questions/61088/hidden-features-of-javascript">JavaScript</a>
<ul>
<li>Functions are First Class citizens</li>
<li>Block scope and closure</li>
<li>Calling methods and accessors indirectly through a variable</li>
</ul></li>
<li><a href="https://stackoverflow.com/questions/63998/hidden-features-of-ruby">Ruby</a>
<ul>
<li>Defining methods through code</li>
</ul></li>
<li><a href="https://stackoverflow.com/questions/61401/hidden-features-of-php">PHP</a>
<ul>
<li>Pervasive online documentation</li>
<li>Magic methods</li>
<li>Symbolic references</li>
</ul></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python">Python</a>
<ul>
<li>One line value swapping</li>
<li>Ability to replace even core functions with your own functionality</li>
</ul></li>
</ul>
<h2>Other Hidden Features:</h2>
<p>Operators:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162094">The bool quasi-operator</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162058">The flip-flop operator</a>
<ul>
<li>Also used for <a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#205627">list construction</a></li>
</ul></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162004">The <code>++</code> and unary <code>-</code> operators work on strings</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162075">The repetition operator</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#161943">The spaceship operator</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162239">The || operator (and // operator) to select from a set of choices</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162152">The diamond operator</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162249">Special cases of the <code>m//</code> operator</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162060">The tilde-tilde "operator"</a></li>
</ul>
<p>Quoting constructs:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163416">The qw operator</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162094">Letters can be used as quote delimiters in q{}-like constructs</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163374">Quoting mechanisms</a></li>
</ul>
<p>Syntax and Names:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162094">There can be a space after a sigil</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162094">You can give subs numeric names with symbolic references</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163416">Legal trailing commas</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162601">Grouped Integer Literals</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#168925">hash slices</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#195254">Populating keys of a hash from an array</a></li>
</ul>
<p>Modules, Pragmas, and command-line options:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163440">use strict and use warnings</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163440">Taint checking</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162085">Esoteric use of -n and -p</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163541">CPAN</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162601"><code>overload::constant</code></a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#164255">IO::Handle module</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163725">Safe compartments</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#310083">Attributes</a></li>
</ul>
<p>Variables:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162357">Autovivification</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#161985">The <code>$[</code> variable</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#168947">tie</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#172118">Dynamic Scoping</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#205627">Variable swapping with a single statement</a></li>
</ul>
<p>Loops and flow control:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163440">Magic goto</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163481"><code>for</code> on a single variable</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#169592">continue clause</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#205104">Desperation mode</a></li>
</ul>
<p>Regular expressions:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162565">The <code>\G</code> anchor</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#161976"><code>(?{})</code> and '(??{})` in regexes</a></li>
</ul>
<p>Other features:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163440">The debugger</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162206">Special code blocks such as BEGIN, CHECK, and END</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163700">The <code>DATA</code> block</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162601">New Block Operations</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162601">Source Filters</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162601">Signal Hooks</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#167309">map</a> (<a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#167809">twice</a>)</li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162842">Wrapping built-in functions</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl/189883#189883">The <code>eof</code> function</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#194796">The <code>dbmopen</code> function</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#205104">Turning warnings into errors</a></li>
</ul>
<p>Other tricks, and meta-answers:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#163532">cat files, decompressing gzips if needed</a></li>
<li><a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl#162271">Perl Tips</a></li>
</ul>
<hr>
<p><strong>See Also:</strong></p>
<ul>
<li><a href="https://stackoverflow.com/questions/132241/hidden-features-of-c">Hidden features of C</a></li>
<li><a href="https://stackoverflow.com/questions/9033/hidden-features-of-c">Hidden features of C#</a></li>
<li><a href="https://stackoverflow.com/questions/75538/hidden-features-of-c">Hidden features of C++</a></li>
<li><a href="https://stackoverflow.com/questions/15496/hidden-features-of-java">Hidden features of Java</a></li>
<li><a href="https://stackoverflow.com/questions/61088/hidden-features-of-javascript">Hidden features of JavaScript</a></li>
<li><a href="https://stackoverflow.com/questions/63998/hidden-features-of-ruby">Hidden features of Ruby</a></li>
<li><a href="https://stackoverflow.com/questions/61401/hidden-features-of-php">Hidden features of PHP</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python">Hidden features of Python</a></li>
<li><a href="https://stackoverflow.com/questions/2493996/hidden-features-of-clojure">Hidden features of Clojure</a></li>
</ul>
|
[
{
"answer_id": 161943,
"author": "Sec",
"author_id": 20555,
"author_profile": "https://Stackoverflow.com/users/20555",
"pm_score": 4,
"selected": false,
"text": "$a = 5 <=> 7; # $a is set to -1\n$a = 7 <=> 5; # $a is set to 1\n$a = 6 <=> 6; # $a is set to 0\n"
},
{
"answer_id": 161985,
"author": "Sec",
"author_id": 20555,
"author_profile": "https://Stackoverflow.com/users/20555",
"pm_score": 3,
"selected": false,
"text": "$[=1;\n"
},
{
"answer_id": 162004,
"author": "Leon Timmermans",
"author_id": 4727,
"author_profile": "https://Stackoverflow.com/users/4727",
"pm_score": 5,
"selected": false,
"text": "my $_ = \"a\"\nprint -$_\n print ++$_\n $_ = 'z'\nprint ++$_\n"
},
{
"answer_id": 162058,
"author": "John Siracusa",
"author_id": 164,
"author_profile": "https://Stackoverflow.com/users/164",
"pm_score": 6,
"selected": false,
"text": "while(<$fh>)\n{\n next if 1..1; # skip first record\n ...\n}\n perldoc perlop"
},
{
"answer_id": 162060,
"author": "Sec",
"author_id": 20555,
"author_profile": "https://Stackoverflow.com/users/20555",
"pm_score": 3,
"selected": false,
"text": "print ~~ localtime;\n print scalar localtime;\n print localtime;\n"
},
{
"answer_id": 162075,
"author": "Bruno De Fraine",
"author_id": 6918,
"author_profile": "https://Stackoverflow.com/users/6918",
"pm_score": 5,
"selected": false,
"text": "print '-' x 80; # print row of dashes\n print for (1, 4, 9) x 3; # print 149149149\n"
},
{
"answer_id": 162085,
"author": "Sec",
"author_id": 20555,
"author_profile": "https://Stackoverflow.com/users/20555",
"pm_score": 5,
"selected": false,
"text": "\"-n\" \"-p\" }{ ls |perl -lne 'print $_; }{ print \"$. Files\"'\n LINE: while (defined($_ = <ARGV>)) {\n print $_; }{ print \"$. Files\";\n}\n"
},
{
"answer_id": 162094,
"author": "moritz",
"author_id": 14132,
"author_profile": "https://Stackoverflow.com/users/14132",
"pm_score": 6,
"selected": false,
"text": " $ perl -wle 'my $x = 3; print $ x'\n 3\n $ perl -lwe '*4 = sub { print \"yes\" }; 4->()' \nyes\n $ perl -wle 'print !!4'\n1\n$ perl -wle 'print !!\"0 but true\"'\n1\n$ perl -wle 'print !!0'\n(empty line)\n use overload q{...} $ perl -Mstrict -wle 'print q bJet another perl hacker.b'\nJet another perl hacker.\n m xabcx\n# same as m/abc/\n"
},
{
"answer_id": 162152,
"author": "spoulson",
"author_id": 3347,
"author_profile": "https://Stackoverflow.com/users/3347",
"pm_score": 4,
"selected": false,
"text": "<> <FH> while (<>) {\n... # code for each line\n}\n"
},
{
"answer_id": 162206,
"author": "Bruno De Fraine",
"author_id": 6918,
"author_profile": "https://Stackoverflow.com/users/6918",
"pm_score": 4,
"selected": false,
"text": "BEGIN CHECK END BEGIN perl -c BEGIN {\n eval {\n require 'config.local.pl';\n };\n if ($@) {\n require 'config.default.pl';\n }\n}\n"
},
{
"answer_id": 162239,
"author": "pjf",
"author_id": 19422,
"author_profile": "https://Stackoverflow.com/users/19422",
"pm_score": 5,
"selected": false,
"text": "|| $x = $a || $b;\n\n # $x = $a, if $a is true.\n # $x = $b, otherwise\n $x = $a || $b || $c || 0;\n $a $b $c 0 // $a $b $c 0"
},
{
"answer_id": 162249,
"author": "Michael Carman",
"author_id": 8233,
"author_profile": "https://Stackoverflow.com/users/8233",
"pm_score": 4,
"selected": false,
"text": "m// ? reset '"
},
{
"answer_id": 162257,
"author": "Corion",
"author_id": 11253,
"author_profile": "https://Stackoverflow.com/users/11253",
"pm_score": 5,
"selected": false,
"text": "// *My::Namespace:: = \\%Your::Namespace\n BEGIN CHECK import new DESTROY END my $method = 'foo';\nmy $obj = My::Class->new();\n$obj->$method( 'baz' ); # calls $obj->foo( 'baz' )\n *foo = sub { print \"Hello world\" };\n use subs 'unlink'; \nsub unlink { print 'No.' }\n BEGIN{\n *CORE::GLOBAL::unlink = sub {print 'no'}\n};\n\nunlink($_) for @ARGV\n"
},
{
"answer_id": 162565,
"author": "J.J.",
"author_id": 21204,
"author_profile": "https://Stackoverflow.com/users/21204",
"pm_score": 4,
"selected": false,
"text": "while(/\\G(\\b\\w*\\b)/g) {\n print \"$1\\n\";\n}\n"
},
{
"answer_id": 162601,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 5,
"selected": false,
"text": "sub do_stuff_with_a_hash (&\\%) {\n my ( $block_of_code, $hash_ref ) = @_;\n while ( my ( $k, $v ) = each %$hash_ref ) { \n $block_of_code->( $k, $v );\n }\n}\n use Data::Dumper;\n\ndo_stuff_with_a_hash {\n local $Data::Dumper::Terse = 1;\n my ( $k, $v ) = @_;\n say qq(Hey, the key is \"$k\"!);\n say sprintf qq(Hey, the value is \"%v\"!), Dumper( $v );\n\n} %stuff_for\n;\n Data::Dumper::Dumper sub map { } @list perl -MLib::DB -MLib::TL -e 'run_expensive_database_delete() if $hour_of_day < AM_7';\n Lib::TL my $old_die_handler = $SIG{__DIE__};\n$SIG{__DIE__} \n = sub { say q(Hey! I'm DYIN' over here!); goto &$old_die_handler; }\n ;\n $SIG{__DIE__} END { } overload::constant import overload::constant \n integer => sub { \n my $lit = shift;\n return $lit > 2_000_000_000 ? Math::BigInt->new( $lit ) : $lit \n };\n Math::BigInt 2_000_000_000"
},
{
"answer_id": 162842,
"author": "J.J.",
"author_id": 21204,
"author_profile": "https://Stackoverflow.com/users/21204",
"pm_score": 2,
"selected": false,
"text": "sub print {\n print @_, \"\\n\";\n}\n sub print {\n exists $ENV{DEVELOPER} ?\n print Dumper(@_) :\n print @_;\n}\n"
},
{
"answer_id": 163374,
"author": "Robert P",
"author_id": 18097,
"author_profile": "https://Stackoverflow.com/users/18097",
"pm_score": 5,
"selected": false,
"text": "my $url = q{http://my.url.com/any/arbitrary/path/in/the/url.html};\n my $var = q#some string where the pound is the final escape.#;\nmy $var2 = q{A more pleasant way of escaping.};\nmy $var3 = q(Others prefer parens as the quote mechanism.);\n my $var4 = qq{This \"$mechanism\" is broken. Please inform \"$user\" at \"$email\" about it.};\n my $output = qx{type \"$path\"}; # get just the output\nmy $moreout = qx{type \"$path\" 2>&1}; # get stuff on stderr too\n sub MyRegexCheck {\n my ($string, $regex) = @_;\n if ($string)\n {\n return ($string =~ $regex);\n }\n return; # returns 'null' or 'empty' in every context\n}\n\nmy $regex = qr{http://[\\w]\\.com/([\\w]+/)+};\n@results = MyRegexCheck(q{http://myurl.com/subpath1/subpath2/}, $regex);\n \n my @allowed = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z { });\n my @badwords = qw(WORD1 word2 word3 word4);\n my @numbers = qw(one two three four 5 six seven); # works with numbers too\n my @list = ('string with space', qw(eight nine), \"a $var\"); # works in other lists\n my $arrayref = [ qw(and it works in arrays too) ]; \n"
},
{
"answer_id": 163416,
"author": "dland",
"author_id": 18625,
"author_profile": "https://Stackoverflow.com/users/18625",
"pm_score": 5,
"selected": false,
"text": "my @list = ('abc', 'def', 'ghi', 'jkl');\n my @list = qw(abc def ghi jkl);\n print 1, 2, 3, ;\n print\n results_of_foo(),\n results_of_xyzzy(),\n results_of_quux(),\n ;\n"
},
{
"answer_id": 163440,
"author": "Andru Luvisi",
"author_id": 5922,
"author_profile": "https://Stackoverflow.com/users/5922",
"pm_score": 5,
"selected": false,
"text": "-t goto &sub use strict use warnings"
},
{
"answer_id": 163481,
"author": "timkay",
"author_id": 24558,
"author_profile": "https://Stackoverflow.com/users/24558",
"pm_score": 5,
"selected": false,
"text": "for ($item)\n{\n s/ / /g;\n s/<.*?>/ /g;\n $_ = join(\" \", split(\" \", $_));\n}\n"
},
{
"answer_id": 163488,
"author": "timkay",
"author_id": 24558,
"author_profile": "https://Stackoverflow.com/users/24558",
"pm_score": 4,
"selected": false,
"text": "rename(\"$_.part\", $_) for \"data.txt\";\n"
},
{
"answer_id": 163498,
"author": "timkay",
"author_id": 24558,
"author_profile": "https://Stackoverflow.com/users/24558",
"pm_score": 3,
"selected": false,
"text": "sub load_file\n{\n local(@ARGV, $/) = shift;\n <>;\n}\n sub load_file\n{\n local @ARGV = shift;\n local $/ = wantarray? $/: undef;\n <>;\n}\n"
},
{
"answer_id": 163532,
"author": "timkay",
"author_id": 24558,
"author_profile": "https://Stackoverflow.com/users/24558",
"pm_score": 6,
"selected": false,
"text": "s{ \n ^ # make sure to get whole filename\n ( \n [^'] + # at least one non-quote\n \\. # extension dot\n (?: # now either suffix\n gz\n | Z \n )\n )\n \\z # through the end\n}{gzcat '$1' |}xs for @ARGV;\n <> @ARGV while (<>) {\n print;\n}\n"
},
{
"answer_id": 163700,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "my @lines = <DATA>;\nfor (@lines) {\n print if /bad/;\n}\n\n__DATA__\nsome good data\nsome bad data\nmore good data \nmore good data \n"
},
{
"answer_id": 164255,
"author": "Alexandr Ciornii",
"author_id": 13467,
"author_profile": "https://Stackoverflow.com/users/13467",
"pm_score": 2,
"selected": false,
"text": "IO::Handle use IO::Handle; \n$log->autoflush(1);\n"
},
{
"answer_id": 166230,
"author": "Tomasz",
"author_id": 10523,
"author_profile": "https://Stackoverflow.com/users/10523",
"pm_score": 0,
"selected": false,
"text": "$| = 1; # flush the buffer on the next output \n\nfor $i(1..100) {\n print \"Progress $i %\\r\"\n}\n"
},
{
"answer_id": 167809,
"author": "talexb",
"author_id": 5649,
"author_profile": "https://Stackoverflow.com/users/5649",
"pm_score": 2,
"selected": false,
"text": "my @symbols = map { +{ 'key' => $_ } } @things;"
},
{
"answer_id": 169592,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "while( <> ){\n print \"top of loop\\n\";\n chomp;\n\n next if /next/i;\n last if /last/i;\n\n print \"bottom of loop\\n\";\n}continue{\n print \"continue\\n\";\n}\n"
},
{
"answer_id": 189883,
"author": "Telemachus",
"author_id": 26702,
"author_profile": "https://Stackoverflow.com/users/26702",
"pm_score": 2,
"selected": false,
"text": "eof perldoc -f eof $. while (<>) {\n print \"$ARGV:$.\\t$_\";\n} \ncontinue {\n close ARGV if eof\n}\n"
},
{
"answer_id": 194796,
"author": "AmbroseChapel",
"author_id": 242241,
"author_profile": "https://Stackoverflow.com/users/242241",
"pm_score": 1,
"selected": false,
"text": "dbmopen()"
},
{
"answer_id": 205104,
"author": "Schwern",
"author_id": 14660,
"author_profile": "https://Stackoverflow.com/users/14660",
"pm_score": 3,
"selected": false,
"text": "SKIP: {\n skip() if $something;\n\n print \"Never printed\";\n}\n\nsub skip {\n no warnings \"exiting\";\n last SKIP;\n}\n local $SIG{__WARN__} = sub { die @_ };\n$num = \"two\";\n$sum = 1 + $num;\nprint \"Never reached\";\n"
},
{
"answer_id": 243146,
"author": "Guillaume Gervais",
"author_id": 10687,
"author_profile": "https://Stackoverflow.com/users/10687",
"pm_score": 2,
"selected": false,
"text": "$url =~ /http:\\/\\/www\\.stackoverflow\\.com\\//;\n /bar/ m/bar/ m!bar! $url =~ m!http://www\\.stackoverflow\\.com/!;\n q{foo} 'foo' $code = q{\n if( this is awesome ) {\n print \"Look ma, no escaping!\";\n }\n};\n $string = qq'You owe me $1,000 dollars!';\n"
},
{
"answer_id": 302384,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "my $foo = undef ;\nsub bar:lvalue{ return $foo ;}\n\n# Then later\n\nbar = 5 ;\nprint bar ;\n"
},
{
"answer_id": 479046,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "my $processed_input = $records || process_inputs($records_file);\n"
},
{
"answer_id": 530460,
"author": "Schwern",
"author_id": 14660,
"author_profile": "https://Stackoverflow.com/users/14660",
"pm_score": 3,
"selected": false,
"text": "#!/usr/bin/perl\n'di';\n'ig00';\n\n...Perl code goes here, ignored by nroff...\n\n.00; # finish .ig\n\n'di \\\" finish the diversion\n.nr nl 0-1 \\\" fake up transition to first page\n.nr % 0 \\\" start at page 1\n'; __END__\n\n...man page goes here, ignored by Perl...\n op.c /* perl4's way of mixing documentation and code\n (before the invention of POD) was based on a\n trick to mix nroff and perl code. The trick was\n built upon these three nroff macros being used in\n void context. The pink camel has the details in\n the script wrapman near page 319. */\n const char * const maybe_macro = SvPVX_const(sv);\n if (strnEQ(maybe_macro, \"di\", 2) ||\n strnEQ(maybe_macro, \"ds\", 2) ||\n strnEQ(maybe_macro, \"ig\", 2))\n useless = NULL;\n 'di'; 'die'; 'did you get that thing I sentcha?'; 'ignore this line'; 0 1 .00; /* the constants 0 and 1 are permitted as they are\n conventionally used as dummies in constructs like\n 1 while some_condition_with_side_effects; */\n else if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))\n useless = NULL;\n 2 while condition"
},
{
"answer_id": 530538,
"author": "Chris Lutz",
"author_id": 60777,
"author_profile": "https://Stackoverflow.com/users/60777",
"pm_score": 2,
"selected": false,
"text": "while(<>) {\n s/(\\w{0,4})/reverse($1);/e; # reverses all words between 0 and 4 letters\n print;\n}\n This is a test of regular expressions\n^D\n sihT si a tset fo regular expressions\n"
},
{
"answer_id": 547210,
"author": "timkay",
"author_id": 24558,
"author_profile": "https://Stackoverflow.com/users/24558",
"pm_score": 1,
"selected": false,
"text": "@is_month{qw(jan feb mar apr may jun jul aug sep oct nov dec)} = undef;\n\nprint \"It's a month\" if exists $is_month{lc $mon};\n PVHV Elt SV Dump \\%is_month, 12;\n\nSV = RV(0x81c1bc) at 0x81c1b0\n REFCNT = 1\n FLAGS = (TEMP,ROK)\n RV = 0x812480\n SV = PVHV(0x80917c) at 0x812480\n REFCNT = 2\n FLAGS = (SHAREKEYS)\n ARRAY = 0x206f20 (0:8, 1:4, 2:4)\n hash quality = 101.2%\n KEYS = 12\n FILL = 8\n MAX = 15\n RITER = -1\n EITER = 0x0\n Elt \"feb\" HASH = 0xeb0d8580\n SV = NULL(0x0) at 0x804b40\n REFCNT = 1\n FLAGS = ()\n Elt \"may\" HASH = 0xf2290c53\n SV = NULL(0x0) at 0x812420\n REFCNT = 1\n FLAGS = ()\n exists my %is_month = map { $_ => 1 } qw(jan feb mar apr may jun jul aug sep oct nov dec);\n\nprint \"It's a month\" if $is_month{lc $mon});\n"
},
{
"answer_id": 686725,
"author": "Robert P",
"author_id": 18097,
"author_profile": "https://Stackoverflow.com/users/18097",
"pm_score": 3,
"selected": false,
"text": "use diagnostics;\n use strict;\nuse diagnostics;\n\n$var = \"foo\";\n use diagnostics;\nuse strict;\n\nsub myname {\n print { \" Some Error \" };\n};\n"
},
{
"answer_id": 931133,
"author": "user105090",
"author_id": 105090,
"author_profile": "https://Stackoverflow.com/users/105090",
"pm_score": 3,
"selected": false,
"text": "$a = 3;\n$b = 4;\n\nprint \"$a * $b = @{[$a * $b]}\";\n 3 * 4 = 12"
},
{
"answer_id": 931169,
"author": "Chas. Owens",
"author_id": 78259,
"author_profile": "https://Stackoverflow.com/users/78259",
"pm_score": 3,
"selected": false,
"text": "* $_ = \"foo bar\";\nmy $count =()= /[aeiou]/g; #3\n sub foo {\n return @_;\n}\n\n$count =()= foo(qw/a b c d/); #4\n *"
},
{
"answer_id": 1026982,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "$/ = \\3; print $_,\"\\n\" while <>; # output three chars on each line\n"
},
{
"answer_id": 1059420,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "print \"\".localtime; # Request a string\n\nprint 0+@array; # Request a number\n"
},
{
"answer_id": 1105711,
"author": "Dario",
"author_id": 105459,
"author_profile": "https://Stackoverflow.com/users/105459",
"pm_score": 2,
"selected": false,
"text": "Quantum::Superpositions use Quantum::Superpositions;\n\nif ($x == any($a, $b, $c)) { ... }\n"
},
{
"answer_id": 1270366,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "my @strings = ('one', 'two', 'three', 'four');\n\nmy $md5sorted_strings = \n map { $_->[0] } # 4) map back to the original value\n sort { $a->[1] cmp $b->[1] } # 3) sort by the correct element of the list\n map { [$_, md5sum_func($_)] } # 2) create a list of anonymous lists\n @strings # 1) take strings\n"
},
{
"answer_id": 1380565,
"author": "mob",
"author_id": 168657,
"author_profile": "https://Stackoverflow.com/users/168657",
"pm_score": 0,
"selected": false,
"text": "# MyUsefulRoutines.pl\n\nsub doSomethingUseful {\n my @args = @_;\n # ...\n}\n\nif ($0 =~ /MyUsefulRoutines.pl/) {\n # someone is running perl MyUsefulRoutines.pl [args] from the command line\n &doSomethingUseful (@ARGV);\n} else {\n # someone is calling require \"MyUsefulRoutines.pl\" from another script\n 1;\n}\n object.__name__ == \"__main__\""
},
{
"answer_id": 1548716,
"author": "Kiffin",
"author_id": 178045,
"author_profile": "https://Stackoverflow.com/users/178045",
"pm_score": 1,
"selected": false,
"text": "defined &DB::DB"
},
{
"answer_id": 1653812,
"author": "Eric Strom",
"author_id": 189416,
"author_profile": "https://Stackoverflow.com/users/189416",
"pm_score": 2,
"selected": false,
"text": "x!! print 'the meaning of ', join ' ' => \n 'life,' x!! $self->alive,\n 'the universe,' x!! ($location ~~ Universe),\n ('and', 'everything.') x!! 42; # this is added as a list\n do_something() if test();\n"
},
{
"answer_id": 1681732,
"author": "Erick",
"author_id": 12251,
"author_profile": "https://Stackoverflow.com/users/12251",
"pm_score": 1,
"selected": false,
"text": "#detecting blacklist words in the current line\n/foo|bar|baz/;\n @blacklistWords = (\"foo\", \"bar\", \"baz\");\n$anyOfBlacklist = join \"|\", (@blacklistWords);\n/$anyOfBlacklist/;\n"
},
{
"answer_id": 1762916,
"author": "Nick Dixon",
"author_id": 52958,
"author_profile": "https://Stackoverflow.com/users/52958",
"pm_score": 1,
"selected": false,
"text": "my %unique = map { $_ => 1 } @list;\nmy @unique = keys %unique;\n"
},
{
"answer_id": 2062632,
"author": "Eric Strom",
"author_id": 189416,
"author_profile": "https://Stackoverflow.com/users/189416",
"pm_score": 0,
"selected": false,
"text": "redo ->can('print') sub get_printer {\n my $self = shift;\n {$self->can('print') or $self = $self->next and redo}\n}\n"
},
{
"answer_id": 2628795,
"author": "Alexey",
"author_id": 281140,
"author_profile": "https://Stackoverflow.com/users/281140",
"pm_score": 2,
"selected": false,
"text": "perl -w -MO=Lint,no-context myscript.pl\n"
},
{
"answer_id": 2655810,
"author": "dawg",
"author_id": 298607,
"author_profile": "https://Stackoverflow.com/users/298607",
"pm_score": 2,
"selected": false,
"text": "use re debug perl -MO=Concise[,OPTIONS] use re debug /^(^(?:(.*?),){$i}/ /^(?:(.*?),|$){$i}/ (.*?) use re debug ,|$ ((.*?),) | ($) /^(?:(.*?)(?:,|$)){$i}/ .*? /^(?:(?:^|,)([^,]*)){$i}/ perl -MO=Concise[,OPTIONS] -MO=Concise"
},
{
"answer_id": 2911357,
"author": "Danny Woods",
"author_id": 350695,
"author_profile": "https://Stackoverflow.com/users/350695",
"pm_score": 2,
"selected": false,
"text": "sub with_output_to_string(&) { # allows compiler to accept \"yoursub {}\" syntax.\n my $function = shift;\n my $string = '';\n my $handle = IO::Handle->new();\n open($handle, '>', \\$string) || die $!; # IO handle on a plain scalar string ref\n my $old_handle = select $handle;\n eval { $function->() };\n select $old_handle;\n die $@ if $@;\n return $string;\n}\n\nmy $greeting = with_output_to_string {\n print \"Hello, world!\";\n};\n\nprint $greeting, \"\\n\";\n"
},
{
"answer_id": 2911832,
"author": "Terry",
"author_id": 68338,
"author_profile": "https://Stackoverflow.com/users/68338",
"pm_score": 0,
"selected": false,
"text": "ls | xargs stat $ ls | perl -pe 'print \"stat \"' | sh \n |$\\ -ne \\x27 '\\'' $ ls | perl -nle 'chomp; print \"stat '\\''$_'\\''\"' | sh\n $ ls | perl -pe 's/(.*)/stat \\x27$1\\x27/' | sh\n $ ls | perl -pe 's/\\n/\\0/' | xargs -0 stat\n"
},
{
"answer_id": 2912104,
"author": "Jauder Ho",
"author_id": 26366,
"author_profile": "https://Stackoverflow.com/users/26366",
"pm_score": 2,
"selected": false,
"text": "my %seen;\n\nfor (<LINE>) {\n print $_ unless $seen{$_}++;\n}\n"
},
{
"answer_id": 2912459,
"author": "knb",
"author_id": 202553,
"author_profile": "https://Stackoverflow.com/users/202553",
"pm_score": 2,
"selected": false,
"text": "> perl -e \"say 'hello\"\" # does not work \n\nString found where operator expected at -e line 1, near \"say 'hello'\"\n (Do you need to predeclare say?)\nsyntax error at -e line 1, near \"say 'hello'\"\nExecution of -e aborted due to compilation errors.\n\n> perl -E \"say 'hello'\" \nhello\n"
},
{
"answer_id": 2913535,
"author": "trapd00r",
"author_id": 227697,
"author_profile": "https://Stackoverflow.com/users/227697",
"pm_score": 2,
"selected": false,
"text": "print my $foo = \"foo @{[scalar(localtime)]} bar\";\n"
},
{
"answer_id": 2913693,
"author": "Justin",
"author_id": 201853,
"author_profile": "https://Stackoverflow.com/users/201853",
"pm_score": 2,
"selected": false,
"text": "my $interpolation = \"We will interpolated variables\";\nprint <<\"END\";\nWith double quotes, $interpolation, just like normal HEREDOCS.\nEND\n\nprint <<'END';\nWith single quotes, the variable $foo will *not* be interpolated.\n(You have probably seen this in other languages.)\nEND\n\n## this is the fun and \"hidden\" one\nmy $shell_output = <<`END`;\necho With backticks, these commands will be executed in shell.\necho The output is returned.\nls | wc -l\nEND\n\nprint \"shell output: $shell_output\\n\";\n"
},
{
"answer_id": 3526979,
"author": "wolverian",
"author_id": 245704,
"author_profile": "https://Stackoverflow.com/users/245704",
"pm_score": 3,
"selected": false,
"text": "$SIG{__WARN__} use warnings FATAL => \"all\"; perldoc lexwarn perldoc foo perldoc perlfoo"
},
{
"answer_id": 3653228,
"author": "Jet",
"author_id": 348008,
"author_profile": "https://Stackoverflow.com/users/348008",
"pm_score": 0,
"selected": false,
"text": "sub _now { \n my ($now) = localtime() =~ /([:\\d]{8})/;\n return $now;\n}\n\nprint _now(), \"\\n\"; # 15:10:33\n"
},
{
"answer_id": 5630109,
"author": "gdey",
"author_id": 73494,
"author_profile": "https://Stackoverflow.com/users/73494",
"pm_score": 2,
"selected": false,
"text": "say 'This will output' if 1;\nsay 'This will not output' unless 1;\nsay 'Will say this 3 times. The first Time: '.$_ for 1..3;\n sub something_really_important_to_implement_later {\n ...\n} \n"
},
{
"answer_id": 6244313,
"author": "maasha",
"author_id": 764601,
"author_profile": "https://Stackoverflow.com/users/764601",
"pm_score": 2,
"selected": false,
"text": "perl -MData::Dumper -e '@CONV = glob( \"{A,T,C,G}\" x 4 ); print Dumper( \\@CONV )'\n"
},
{
"answer_id": 6631997,
"author": "Balbir Singh",
"author_id": 812536,
"author_profile": "https://Stackoverflow.com/users/812536",
"pm_score": -1,
"selected": false,
"text": "@a = ( 11, 22, 33, 44, 55, 66, 77 );\n$x = 10;\n$i = 3;\n\n@a = ( @a[0..$i-1], $x, @a[$i..$#a] );\n"
},
{
"answer_id": 8842278,
"author": "Prakash K",
"author_id": 159470,
"author_profile": "https://Stackoverflow.com/users/159470",
"pm_score": 0,
"selected": false,
"text": "Deparse $ perl -e '$\"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};$\\=$/;q<Just another Perl Hacker>->();'\nJust another Perl Hacker\n\n$ perl -MO=Deparse -e '$\"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};$\\=$/;q<Just another Perl Hacker>->();'\n$\" = $,;\n*{\"@{[('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')['0020191411140003' =~ /../g]];}\";} = *_ = sub {\n print /::(.*)/;\n}\n;\n$\\ = $/;\n'Just another Perl Hacker'->();\n-e syntax OK\n use B::Deparse;\nmy $deparse = B::Deparse->new;\n$code = $deparse->coderef2text($coderef);\nprint $code;\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] |
161,873
|
<p>I'm working on the K&R book. I've read farther ahead than I've done exercises, mostly for lack of time. I'm catching up, and have done almost all the exercises from chapter 1, which is the tutorial.</p>
<p>My issue was exercise 1-18. The exercise is to:</p>
<blockquote>
<p>Write a program to remove trailing blanks and
tabs from line of input, and to delete entirely blank lines</p>
</blockquote>
<p>My code (below) does that, and works. My problem with it is the trim method I implemented. It feels ... wrong ... somehow. Like if I saw similar code in C# in a code review, I'd probably go nuts. (C# being one of my specialties.)</p>
<p>Can anyone offer some advice on cleaning this up -- with the catch that said advice has to only use knowledge from Chapter 1 of K & R. (I know there are a zillion ways to clean this up using the full C library; we're just talking Chapter 1 and basic stdio.h here.) Also, when giving the advice, can you explain why it will help? (I am, after all, trying to learn! And who better to learn from than the experts here?)</p>
<pre><code>#include <stdio.h>
#define MAXLINE 1000
int getline(char line[], int max);
void trim(char line[], char ret[]);
int main()
{
char line[MAXLINE];
char out[MAXLINE];
int length;
while ((length = getline(line, MAXLINE)) > 0)
{
trim(line, out);
printf("%s", out);
}
return 0;
}
int getline(char line[], int max)
{
int c, i;
for (i = 0; i < max - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
line[i] = c;
if (c == '\n')
{
line[i] = c;
++i;
}
line[i] = '\0';
return i;
}
void trim(char line[], char ret[])
{
int i = 0;
while ((ret[i] = line[i]) != '\0')
++i;
if (i == 1)
{
// Special case to remove entirely blank line
ret[0] = '\0';
return;
}
for ( ; i >= 0; --i)
{
if (ret[i] == ' ' || ret[i] == '\t')
ret[i] = '\0';
else if (ret[i] != '\0' && ret[i] != '\r' && ret[i] != '\n')
break;
}
for (i = 0; i < MAXLINE; ++i)
{
if (ret[i] == '\n')
{
break;
}
else if (ret[i] == '\0')
{
ret[i] = '\n';
ret[i + 1] = '\0';
break;
}
}
}
</code></pre>
<p>EDIT: I appreciate all the helpful tips I'm seeing here. I would like to remind folks that I'm still a n00b with C, and specifically haven't gotten up to pointers yet. (Remember the bit about Ch.1 of K&R -- Ch.1 doesn't do pointers.) I "kinda" get some of those solutions, but they're still a touch advanced for where I'm at ... </p>
<p>And most of what I'm looking for is the trim method itself -- specifically the fact that I'm looping through <strong>3</strong> times (which feels so dirty). I feel like if I were just a touch more clever (even without the advanced knowledge of C), this could have been cleaner.</p>
|
[
{
"answer_id": 161895,
"author": "Eric Z Beard",
"author_id": 1219,
"author_profile": "https://Stackoverflow.com/users/1219",
"pm_score": 3,
"selected": false,
"text": "if (1 == myvar)\n if (myvar = 1)\n"
},
{
"answer_id": 161935,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 4,
"selected": true,
"text": "int trim(char line[])\n{\n int len = 0;\n for (len = 0; line[len] != 0; ++len)\n ;\n\n while (len > 0 &&\n line[len-1] == ' ' && line[len-1] == '\\t' && line[len-1] == '\\n')\n line[--len] = 0;\n\n return len;\n}\n if (trim(line) != 0)\n printf(\"%s\\n\", line);\n while (len > 0 && line[len-1] <= ' ')\n line[--len] = 0;\n"
},
{
"answer_id": 161974,
"author": "TK.",
"author_id": 1816,
"author_profile": "https://Stackoverflow.com/users/1816",
"pm_score": 1,
"selected": false,
"text": "while( (ret[i] = line[i]) )\n i++;\n while ((ret[i] = line[i]) != '\\0')\n ++i;\n for ( ; i >= 0; --i)\n while (i)\n{\n if (ret[i] == ' ' || ret[i] == '\\t')\n {\n ret[i--] = '\\0';\n }\n else if (ret[i] != '\\0' && ret[i] != '\\r' && ret[i] != '\\n')\n {\n break;\n }\n}\n"
},
{
"answer_id": 162002,
"author": "aib",
"author_id": 1088,
"author_profile": "https://Stackoverflow.com/users/1088",
"pm_score": 0,
"selected": false,
"text": "void trim(char line[], char ret[])\n{\n int i = 0;\n\n while ((ret[i] = line[i]) != '\\0')\n ++i;\n\n if (i == 1) { // Special case to remove entirely blank line\n ret[0] = '\\0';\n return;\n }\n\n for (; i>=0; --i) { //continue backwards from the end of the line\n if ((ret[i] == ' ') || (ret[i] == '\\t')) //remove trailing whitespace\n ret[i] = '\\0';\n\n else if ((ret[i] != '\\0') && (ret[i] != '\\r') && (ret[i] != '\\n')) //...until we hit a word character\n break;\n }\n\n for (i=0; i<MAXLINE-1; ++i) { //-1 because we might need to add a character to the line\n if (ret[i] == '\\n') //break on newline\n break;\n\n if (ret[i] == '\\0') { //line doesn't have a \\n -- add it\n ret[i] = '\\n';\n ret[i+1] = '\\0';\n break;\n }\n }\n}\n"
},
{
"answer_id": 162226,
"author": "orj",
"author_id": 20480,
"author_profile": "https://Stackoverflow.com/users/20480",
"pm_score": 0,
"selected": false,
"text": "#include \"stdio.h\"\n\nsize_t StrLen(const char* s)\n{\n // this will crash if you pass NULL\n size_t l = 0;\n const char* p = s;\n while(*p)\n {\n l++;\n ++p;\n }\n return l;\n}\n\nconst char* Trim(char* s)\n{\n size_t l = StrLen(s);\n if(l < 1)\n return 0;\n\n char* end = s + l -1;\n while(s < end && (*end == ' ' || *end == '\\t'))\n {\n *end = 0;\n --end;\n }\n\n return s;\n}\n\nint Getline(char* out, size_t max)\n{\n size_t l = 0;\n char c;\n while(c = getchar())\n {\n ++l;\n\n if(c == EOF) return 0;\n if(c == '\\n') break;\n\n if(l < max-1)\n {\n out[l-1] = c;\n out[l] = 0;\n }\n }\n\n return l;\n}\n\n#define MAXLINE 1024\n\nint main (int argc, char * const argv[]) \n{\n char line[MAXLINE];\n while (Getline(line, MAXLINE) > 0)\n {\n const char* trimmed = Trim(line);\n if(trimmed)\n printf(\"|%s|\\n\", trimmed);\n\n line[0] = 0;\n }\n\n return 0;\n}\n"
},
{
"answer_id": 162266,
"author": "ilitirit",
"author_id": 9825,
"author_profile": "https://Stackoverflow.com/users/9825",
"pm_score": 0,
"selected": false,
"text": "ret[i] != '\\0' && ret[i] != '\\r' && ret[i] != '\\n'\n"
},
{
"answer_id": 162329,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "char *findEndOfString(char *string) {\n while (*string) ++string;\n return string; // string is now pointing to the terminating 0\n}\n\nvoid trim(char *line) {\n char *end = findEndOfString(line);\n // note that we start at the first real character, not at terminating 0\n for (end = end-1; end >= line; end--) {\n if (isWhitespace(*end)) *end = 0;\n else return;\n }\n}\n"
},
{
"answer_id": 164006,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "#include <stdbool.h> /* needed when using bool, false and true. C99 specific. */\n#include <assert.h> /* needed for calling assert() */\n\ntypedef enum {\n TAB = '\\t',\n BLANK = ' '\n} WhiteSpace_e;\n\ntypedef enum {\n ENDOFLINE = '\\n',\n ENDOFSTRING = '\\0'\n} EndofLine_e;\n\nbool isWhiteSpace(\n char character\n) {\n if ( (BLANK == character) || (TAB == character ) ) {\n return true;\n } else {\n return false;\n }\n}\n\nbool isEndOfLine( \n char character\n) {\n if ( (ENDOFLINE == character) || (ENDOFSTRING == character ) ) {\n return true;\n } else {\n return false;\n }\n} \n\n/* remove blanks and tabs (i.e. whitespace) from line-string */\nvoid removeWhiteSpace(\n char string[]\n) {\n int i;\n int indexOutput;\n\n /* copy all non-whitespace character in sequential order from the first to the last.\n whitespace characters are not copied */\n i = 0;\n indexOutput = 0;\n while ( false == isEndOfLine( string[i] ) ) {\n if ( false == isWhiteSpace( string[i] ) ) {\n assert ( indexOutput <= i );\n string[ indexOutput ] = string[ i ];\n indexOutput++;\n }\n i++; /* proceed to next character in the input string */\n }\n\n assert( isEndOfLine( string[ i ] ) );\n string[ indexOutput ] = ENDOFSTRING;\n\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161873",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14048/"
] |
161,879
|
<p>Quite often in ANSI C code I can see parenthesis sorrounding a single return value. </p>
<p>Like this:-</p>
<pre><code>int foo(int x) {
if (x)
return (-1);
else
return (0);
}
</code></pre>
<p>Why use () around the return value in those cases? Any ideas? I can see no reason for that.</p>
|
[
{
"answer_id": 161899,
"author": "Adam Haile",
"author_id": 194,
"author_profile": "https://Stackoverflow.com/users/194",
"pm_score": 7,
"selected": true,
"text": "return (x+i*2);\n int y = x+i*2;\nreturn y;\n"
},
{
"answer_id": 161992,
"author": "Kristopher Johnson",
"author_id": 1175,
"author_profile": "https://Stackoverflow.com/users/1175",
"pm_score": 5,
"selected": false,
"text": "return (a + b);\n return a;\n return(a); // ugh\n"
},
{
"answer_id": 182760,
"author": "Stein G. Strindhaug",
"author_id": 26115,
"author_profile": "https://Stackoverflow.com/users/26115",
"pm_score": 3,
"selected": false,
"text": "return 1\n return -1\n return (-1)\n"
},
{
"answer_id": 4762785,
"author": "TonyK",
"author_id": 428857,
"author_profile": "https://Stackoverflow.com/users/428857",
"pm_score": -1,
"selected": false,
"text": "C/C++ int foo(int x) {\n if (x) {\n return (-1);\n }\n else {\n return (0);\n }\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161879",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23864/"
] |
161,884
|
<p>For those of you that like puzzles: I had this problem recently and am sure there must be a nicer solution.</p>
<p>Consider :</p>
<ul>
<li>an ObservableCollection of <strong>Foo</strong> objects called <em>foos</em>.</li>
<li><strong>Foo</strong> contains a string ID field</li>
<li>I have no control over <em>foos</em></li>
<li><em>foos</em> will be changing</li>
</ul>
<p>Then:</p>
<ul>
<li>I have another collection called <em>sortLikeThis</em></li>
<li><em>sortListThis</em> contains strings</li>
<li>The strings are the IDs in the order in which the <em>foos</em> are to be shown</li>
</ul>
<p>Plus:</p>
<ul>
<li>There may be objects in <em>foos</em> with an ID that is not in <em>sortLikeThis</em>. These need to go at the end.</li>
<li>Likewise, there may be strings in <em>sortLikeThis</em> that do not appear in <em>foos</em>.</li>
</ul>
<p>Is there a nice way to bind to and show in wpf the <strong>Foo</strong> objects in <em>foos</em> in the order defined by IDs in <em>sortLikeThis</em> ?</p>
|
[
{
"answer_id": 161899,
"author": "Adam Haile",
"author_id": 194,
"author_profile": "https://Stackoverflow.com/users/194",
"pm_score": 7,
"selected": true,
"text": "return (x+i*2);\n int y = x+i*2;\nreturn y;\n"
},
{
"answer_id": 161992,
"author": "Kristopher Johnson",
"author_id": 1175,
"author_profile": "https://Stackoverflow.com/users/1175",
"pm_score": 5,
"selected": false,
"text": "return (a + b);\n return a;\n return(a); // ugh\n"
},
{
"answer_id": 182760,
"author": "Stein G. Strindhaug",
"author_id": 26115,
"author_profile": "https://Stackoverflow.com/users/26115",
"pm_score": 3,
"selected": false,
"text": "return 1\n return -1\n return (-1)\n"
},
{
"answer_id": 4762785,
"author": "TonyK",
"author_id": 428857,
"author_profile": "https://Stackoverflow.com/users/428857",
"pm_score": -1,
"selected": false,
"text": "C/C++ int foo(int x) {\n if (x) {\n return (-1);\n }\n else {\n return (0);\n }\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20508/"
] |
161,885
|
<p>When running performance tests file system cache hit or miss can significantly influence test results. Therefore generally before running such tests used files are evicted from system cache. How to do that on Linux?</p>
<p><strong>Clarification:</strong> If possible, the solution should not require root privileges.</p>
|
[
{
"answer_id": 162041,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 4,
"selected": false,
"text": "sync; echo 3 > /proc/sys/vm/drop_caches\n"
},
{
"answer_id": 162792,
"author": "Paweł Hajdan",
"author_id": 9403,
"author_profile": "https://Stackoverflow.com/users/9403",
"pm_score": 4,
"selected": true,
"text": "#include <unistd.h>\n#include <fcntl.h>\nint main(int argc, char *argv[]) {\n int fd;\n fd = open(argv[1], O_RDONLY);\n fdatasync(fd);\n posix_fadvise(fd, 0,0,POSIX_FADV_DONTNEED);\n close(fd);\n return 0;\n}\n"
},
{
"answer_id": 1167957,
"author": "user143174",
"author_id": 143174,
"author_profile": "https://Stackoverflow.com/users/143174",
"pm_score": 3,
"selected": false,
"text": "$ pcu-fadvise -a dontneed filename-to-evict\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9403/"
] |
161,913
|
<p>I would like to draw a diagram in HTML. The positioning structure looks like this:</p>
<pre class="lang-html prettyprint-override"><code><div id='hostDiv'>
<div id='backgroundDiv'>
... drawing the background ...
</div>
<div id='foregroundDiv' style='position: absolute;'>
... drawing the foreground ...
</div>
</div>
</code></pre>
<p>The foreground contains a Table element that is dynamically populated with text, hence the row heights might alter depending on the amount of text going into a cell.
How can I predict the final height of the Table element in the foregroun? I need this information to set the correct height of the background. Is there a way to pre-render the Table from Javascript and read out its height? Or some other trick?</p>
<p>PS. The size of the hostDiv may vary as the browser resizes.</p>
|
[
{
"answer_id": 161923,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 3,
"selected": false,
"text": "var height = $('#myTable').height();\n"
},
{
"answer_id": 161934,
"author": "gx.",
"author_id": 21580,
"author_profile": "https://Stackoverflow.com/users/21580",
"pm_score": 2,
"selected": false,
"text": "$(document).ready(function () { var height = $('#myTable').height(); });\n"
},
{
"answer_id": 161947,
"author": "japollock",
"author_id": 1210318,
"author_profile": "https://Stackoverflow.com/users/1210318",
"pm_score": 1,
"selected": false,
"text": "$('navlist-main').offsetHeight\n"
},
{
"answer_id": 5100073,
"author": "Alvin T",
"author_id": 472482,
"author_profile": "https://Stackoverflow.com/users/472482",
"pm_score": 0,
"selected": false,
"text": "document.getElementById(\"#Table\").clientHeight;\ndocument.getElementById(\"#Table\").clientWidth;\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24451/"
] |
161,915
|
<p>I'm trying to have two inputs (one textbox, one drop down) to have the same width.
You can set the width through css, but for some reason, the select box is always a few pixels smaller.
It seems this only happens with the xhtml 1.0 strict doctype
Any suggestions/ideas about the reason/work around?</p>
<p>Having the following HTML</p>
<pre><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style>
.searchInput{
width: 1000px;
overflow: hidden;
}
</style>
</head>
<body>
<form action="theAction" method="post" class="searchForm" >
<fieldset>
<legend>Search</legend>
<p>
<!--<label for="name">Product name</label>-->
<input class="searchInput" type="text" name="name" id="name" value="" />
</p>
<p>
<!--<label for="ml2">Product Group</label>-->
<select class="searchInput" name="ml2" id="ml2">
<option value="158">INDUSTRIAL PRIMERS/FILLERS</option>
<option value="168">CV CLEAR COATS</option>
<option value="171">CV PRIMERS/FILLERS</option>
<option value="" selected="selected">All</option>
</select>
</p>
<input type="submit" class="search" value="Show" name="Show" id="Show" />
<input type="reset" value="Reset" name="reset" id="reset" class="reset"/>
</fieldset>
</form>
</body
</html>
</code></pre>
|
[
{
"answer_id": 161940,
"author": "Vincent McNabb",
"author_id": 16299,
"author_profile": "https://Stackoverflow.com/users/16299",
"pm_score": 0,
"selected": false,
"text": "input select <style type=\"text/css\">\n .searchInput {\n overflow: hidden;\n }\n select.searchInput {\n width: 101px;\n }\n input.searchInput {\n width: 97px;\n }\n</style>\n"
},
{
"answer_id": 161946,
"author": "Ross",
"author_id": 2025,
"author_profile": "https://Stackoverflow.com/users/2025",
"pm_score": 0,
"selected": false,
"text": "select"
},
{
"answer_id": 167288,
"author": "Ian Oxley",
"author_id": 1904,
"author_profile": "https://Stackoverflow.com/users/1904",
"pm_score": 3,
"selected": false,
"text": ".searchInput {\n margin:0;\n padding:0;\n border-width:1px;\n width:1000px;\n}\n"
},
{
"answer_id": 169007,
"author": "enobrev",
"author_id": 14651,
"author_profile": "https://Stackoverflow.com/users/14651",
"pm_score": 2,
"selected": false,
"text": " .searchInput{\n width: 1000px;\n border: 0;\n background-color: #CCC;\n overflow: hidden;\n }\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
161,928
|
<p>I am trying to figure out what is the 'grafts' in the Git.</p>
<p>For example, in one of the latest comments <a href="http://web.archive.org/web/20080930112610/http://log.emmanuelebassi.net/archives/2007/09/when-the-levee-breaks/" rel="noreferrer">here</a>, Tobu suppose to use <b>git-filter-branch</b> and <b>.git/info/grafts</b> to join two repositories.</p>
<p>But I don't understand why I need these <em>grafts</em>? It seems, that all work without last two commands.</p>
|
[
{
"answer_id": 50517809,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 4,
"selected": false,
"text": "$GIT_DIR/info/grafts refs/replace/ dscho gitster echo \"$commit-id $graft-id\" >> .git/info/grafts\n git replace --graft $commit-id $graft-id\ngit filter-branch $graft-id..HEAD\n .git/info/grafts linux.git git replace git replace --graft replace --graft git replace [-f] --graft <commit> [<parent>...]\n <commit> [<parents>...] derrickstolee stefanbeller gitster upload-pack git fetch peff gitster upload-pack commit-graph repo->objects->commit_graph struct commit->object.parsed commit->graph_pos commit->maybe_tree NULL repo_get_commit_tree()"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/70293/"
] |
161,937
|
<p>I understand there is a HTTP response header directive to disable page caching:</p>
<pre><code>Cache-Control:no-cache
</code></pre>
<p>I can modify the header by "hand":</p>
<pre><code> <%response.addHeader("Cache-Control","no-cache");%>
</code></pre>
<p>But is there a "nice" way to make the JSP interpreter return this header line in the server response?</p>
<p>(I checked the <%@page ...%> directive. It seems there is nothing like that.)</p>
|
[
{
"answer_id": 162096,
"author": "Swati",
"author_id": 12682,
"author_profile": "https://Stackoverflow.com/users/12682",
"pm_score": 0,
"selected": false,
"text": "<?xml version=\"1.0\"?>\n<jsp:root xmlns:jsp=\"http://java.sun.com/JSP/Page\" version=\"2.0\"> \n <jsp:scriptlet><![CDATA[\n response.setHeader(\"Cache-Control\", \"no-cache\");\n ]]></jsp:scriptlet>\n</jsp:root>\n <jsp:root />"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17428/"
] |
161,942
|
<p>I don't want a discussion about when to and not to throw exceptions. I wish to resolve a simple issue. 99% of the time the argument for not throwing exceptions revolves around them being slow while the other side claims (with benchmark test) that the speed is not the issue. I've read numerous blogs, articles, and posts pertaining one side or the other. So which is it?</p>
<p>Some links from the answers: <a href="http://yoda.arachsys.com/csharp/exceptions2.html" rel="noreferrer">Skeet</a>, <a href="http://blogs.msdn.com/ricom/archive/2006/09/25/771142.aspx" rel="noreferrer">Mariani</a>, <a href="http://blogs.msdn.com/cbrumme/archive/2003/10/01/51524.aspx" rel="noreferrer">Brumme</a>.</p>
|
[
{
"answer_id": 161965,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 9,
"selected": true,
"text": "int.TryParse"
},
{
"answer_id": 162001,
"author": "Sklivvz",
"author_id": 7028,
"author_profile": "https://Stackoverflow.com/users/7028",
"pm_score": 2,
"selected": false,
"text": "marco@sklivvz:~/develop/test$ mono Exceptions.exe | grep PM\n10/2/2008 2:53:32 PM\n10/2/2008 2:53:42 PM\n10/2/2008 2:53:52 PM\n"
},
{
"answer_id": 9425957,
"author": "linquize",
"author_id": 1031218,
"author_profile": "https://Stackoverflow.com/users/1031218",
"pm_score": 2,
"selected": false,
"text": "int c = 1000000;\nint s = Environment.TickCount;\nfor (int i = 0; i < c; i++)\n{\n try { throw new Exception(); }\n catch { }\n}\nint d = Environment.TickCount - s;\n\nConsole.WriteLine(d + \"ms / \" + c + \" exceptions\");\n"
},
{
"answer_id": 9798675,
"author": "David Jeske",
"author_id": 519568,
"author_profile": "https://Stackoverflow.com/users/519568",
"pm_score": 2,
"selected": false,
"text": "baseline: recurse_depth 8, error_freqeuncy 0 (0), time elapsed 13.0007 ms\nbaseline: recurse_depth 8, error_freqeuncy 0.25 (0), time elapsed 13.0007 ms\nbaseline: recurse_depth 8, error_freqeuncy 0.5 (0), time elapsed 13.0008 ms\nbaseline: recurse_depth 8, error_freqeuncy 0.75 (0), time elapsed 13.0008 ms\nbaseline: recurse_depth 8, error_freqeuncy 1 (0), time elapsed 14.0008 ms\nretval_error: recurse_depth 5, error_freqeuncy 0 (0), time elapsed 13.0008 ms\nretval_error: recurse_depth 5, error_freqeuncy 0.25 (249999), time elapsed 14.0008 ms\nretval_error: recurse_depth 5, error_freqeuncy 0.5 (499999), time elapsed 16.0009 ms\nretval_error: recurse_depth 5, error_freqeuncy 0.75 (999999), time elapsed 16.001 ms\nretval_error: recurse_depth 5, error_freqeuncy 1 (999999), time elapsed 16.0009 ms\nretval_error: recurse_depth 8, error_freqeuncy 0 (0), time elapsed 20.0011 ms\nretval_error: recurse_depth 8, error_freqeuncy 0.25 (249999), time elapsed 21.0012 ms\nretval_error: recurse_depth 8, error_freqeuncy 0.5 (499999), time elapsed 24.0014 ms\nretval_error: recurse_depth 8, error_freqeuncy 0.75 (999999), time elapsed 24.0014 ms\nretval_error: recurse_depth 8, error_freqeuncy 1 (999999), time elapsed 24.0013 ms\nexception_error: recurse_depth 8, error_freqeuncy 0 (0), time elapsed 31.0017 ms\nexception_error: recurse_depth 8, error_freqeuncy 0.25 (249999), time elapsed 5607.3208 ms\nexception_error: recurse_depth 8, error_freqeuncy 0.5 (499999), time elapsed 11172.639 ms\nexception_error: recurse_depth 8, error_freqeuncy 0.75 (999999), time elapsed 22297.2753 ms\nexception_error: recurse_depth 8, error_freqeuncy 1 (999999), time elapsed 22102.2641 ms\n using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace ConsoleApplication1 {\n\npublic class TestIt {\n int value;\n\n public class TestException : Exception { } \n\n public int getValue() {\n return value;\n }\n\n public void reset() {\n value = 0;\n }\n\n public bool baseline_null(bool shouldfail, int recurse_depth) {\n if (recurse_depth <= 0) {\n return shouldfail;\n } else {\n return baseline_null(shouldfail,recurse_depth-1);\n }\n }\n\n public bool retval_error(bool shouldfail, int recurse_depth) {\n if (recurse_depth <= 0) {\n if (shouldfail) {\n return false;\n } else {\n return true;\n }\n } else {\n bool nested_error = retval_error(shouldfail,recurse_depth-1);\n if (nested_error) {\n return true;\n } else {\n return false;\n }\n }\n }\n\n public void exception_error(bool shouldfail, int recurse_depth) {\n if (recurse_depth <= 0) {\n if (shouldfail) {\n throw new TestException();\n }\n } else {\n exception_error(shouldfail,recurse_depth-1);\n }\n\n }\n\n public static void Main(String[] args) {\n int i;\n long l;\n TestIt t = new TestIt();\n int failures;\n\n int ITERATION_COUNT = 1000000;\n\n\n // (0) baseline null workload\n for (int recurse_depth = 2; recurse_depth <= 10; recurse_depth+=3) {\n for (float exception_freq = 0.0f; exception_freq <= 1.0f; exception_freq += 0.25f) { \n int EXCEPTION_MOD = (exception_freq == 0.0f) ? ITERATION_COUNT+1 : (int)(1.0f / exception_freq); \n\n failures = 0;\n DateTime start_time = DateTime.Now;\n t.reset(); \n for (i = 1; i < ITERATION_COUNT; i++) {\n bool shoulderror = (i % EXCEPTION_MOD) == 0;\n t.baseline_null(shoulderror,recurse_depth);\n }\n double elapsed_time = (DateTime.Now - start_time).TotalMilliseconds;\n Console.WriteLine(\n String.Format(\n \"baseline: recurse_depth {0}, error_freqeuncy {1} ({2}), time elapsed {3} ms\",\n recurse_depth, exception_freq, failures,elapsed_time));\n }\n }\n\n\n // (1) retval_error\n for (int recurse_depth = 2; recurse_depth <= 10; recurse_depth+=3) {\n for (float exception_freq = 0.0f; exception_freq <= 1.0f; exception_freq += 0.25f) { \n int EXCEPTION_MOD = (exception_freq == 0.0f) ? ITERATION_COUNT+1 : (int)(1.0f / exception_freq); \n\n failures = 0;\n DateTime start_time = DateTime.Now;\n t.reset(); \n for (i = 1; i < ITERATION_COUNT; i++) {\n bool shoulderror = (i % EXCEPTION_MOD) == 0;\n if (!t.retval_error(shoulderror,recurse_depth)) {\n failures++;\n }\n }\n double elapsed_time = (DateTime.Now - start_time).TotalMilliseconds;\n Console.WriteLine(\n String.Format(\n \"retval_error: recurse_depth {0}, error_freqeuncy {1} ({2}), time elapsed {3} ms\",\n recurse_depth, exception_freq, failures,elapsed_time));\n }\n }\n\n // (2) exception_error\n for (int recurse_depth = 2; recurse_depth <= 10; recurse_depth+=3) {\n for (float exception_freq = 0.0f; exception_freq <= 1.0f; exception_freq += 0.25f) { \n int EXCEPTION_MOD = (exception_freq == 0.0f) ? ITERATION_COUNT+1 : (int)(1.0f / exception_freq); \n\n failures = 0;\n DateTime start_time = DateTime.Now;\n t.reset(); \n for (i = 1; i < ITERATION_COUNT; i++) {\n bool shoulderror = (i % EXCEPTION_MOD) == 0;\n try {\n t.exception_error(shoulderror,recurse_depth);\n } catch (TestException e) {\n failures++;\n }\n }\n double elapsed_time = (DateTime.Now - start_time).TotalMilliseconds;\n Console.WriteLine(\n String.Format(\n \"exception_error: recurse_depth {0}, error_freqeuncy {1} ({2}), time elapsed {3} ms\",\n recurse_depth, exception_freq, failures,elapsed_time)); }\n }\n }\n}\n\n\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161942",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23164/"
] |
161,960
|
<p>A query that is used to loop through <b>17 millions records to remove duplicates</b> has been running now for about <b>16 hours</b> and I wanted to know if the query is stopped right now if it will finalize the delete statements or if it has been deleting while running this query? Indeed, if I do stop it, does it finalize the deletes or rolls back?</p>
<p>I have found that when I do a </p>
<pre><code> select count(*) from myTable
</code></pre>
<p>That the rows that it returns (while doing this query) is about 5 less than what the starting row count was. Obviously the server resources are extremely poor, so does that mean that this process has taken 16 hours to find 5 duplicates (when there are actually thousands), and this could be running for days?</p>
<p>This query took 6 seconds on 2000 rows of test data, and it works great on that set of data, so I figured it would take 15 hours for the complete set.</p>
<p>Any ideas?</p>
<p>Below is the query:</p>
<pre><code>--Declare the looping variable
DECLARE @LoopVar char(10)
DECLARE
--Set private variables that will be used throughout
@long DECIMAL,
@lat DECIMAL,
@phoneNumber char(10),
@businessname varchar(64),
@winner char(10)
SET @LoopVar = (SELECT MIN(RecordID) FROM MyTable)
WHILE @LoopVar is not null
BEGIN
--initialize the private variables (essentially this is a .ctor)
SELECT
@long = null,
@lat = null,
@businessname = null,
@phoneNumber = null,
@winner = null
-- load data from the row declared when setting @LoopVar
SELECT
@long = longitude,
@lat = latitude,
@businessname = BusinessName,
@phoneNumber = Phone
FROM MyTable
WHERE RecordID = @LoopVar
--find the winning row with that data. The winning row means
SELECT top 1 @Winner = RecordID
FROM MyTable
WHERE @long = longitude
AND @lat = latitude
AND @businessname = BusinessName
AND @phoneNumber = Phone
ORDER BY
CASE WHEN webAddress is not null THEN 1 ELSE 2 END,
CASE WHEN caption1 is not null THEN 1 ELSE 2 END,
CASE WHEN caption2 is not null THEN 1 ELSE 2 END,
RecordID
--delete any losers.
DELETE FROM MyTable
WHERE @long = longitude
AND @lat = latitude
AND @businessname = BusinessName
AND @phoneNumber = Phone
AND @winner != RecordID
-- prep the next loop value to go ahead and perform the next duplicate query.
SET @LoopVar = (SELECT MIN(RecordID)
FROM MyTable
WHERE @LoopVar < RecordID)
END
</code></pre>
|
[
{
"answer_id": 162021,
"author": "jwanagel",
"author_id": 15118,
"author_profile": "https://Stackoverflow.com/users/15118",
"pm_score": 3,
"selected": false,
"text": "declare @count int\nselect @count = 5\nWHILE @count > 0\nBEGIN\n print @count\n delete from applicationlog;\n waitfor time '20:00';\n select @count = @count -1\nEND\n"
},
{
"answer_id": 162277,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 1,
"selected": false,
"text": "SELECT *\nFROM MyTable\nWHERE @long = longitude\n AND @lat = latitude\n AND @businessname = BusinessName\n AND @phoneNumber = Phone\n"
},
{
"answer_id": 165659,
"author": "Ricardo C",
"author_id": 232589,
"author_profile": "https://Stackoverflow.com/users/232589",
"pm_score": 2,
"selected": false,
"text": "SET IMPLICIT_TRANSACTIONS ON;\n"
},
{
"answer_id": 1177803,
"author": "HLGEM",
"author_id": 9034,
"author_profile": "https://Stackoverflow.com/users/9034",
"pm_score": 0,
"selected": false,
"text": "SELECT min(m.RecordID), m.longitude, m.latitude, m.businessname, m.phone \n into #RecordsToKeep \nFROM MyTable m\njoin \n(select longitude, latitude, businessname, phone\nfrom MyTable\ngroup by longitude, latitude, businessname, phone\nhaving count(*) >1) a \non a.longitude = m.longitude and a.latitude = m.latitude and\na.businessname = b.businessname and a.phone = b.phone \ngroup by m.longitude, m.latitude, m.businessname, m.phone \nORDER BY CASE WHEN m.webAddress is not null THEN 1 ELSE 2 END, \n CASE WHEN m.caption1 is not null THEN 1 ELSE 2 END, \n CASE WHEN m.caption2 is not null THEN 1 ELSE 2 END\n\n\n\nwhile (select count(*) from #RecordsToKeep) > 0\nbegin\nselect top 1000 * \ninto #Batch\nfrom #RecordsToKeep\n\nDelete m\nfrom mytable m\njoin #Batch b \n on b.longitude = m.longitude and b.latitude = m.latitude and\n b.businessname = b.businessname and b.phone = b.phone \nwhere r.recordid <> b.recordID\n\nDelete r\nfrom #RecordsToKeep r\njoin #Batch b on r.recordid = b.recordid\n\nend\n\nDelete m\nfrom mytable m\njoin #RecordsToKeep r \n on r.longitude = m.longitude and r.latitude = m.latitude and\n r.businessname = b.businessname and r.phone = b.phone \nwhere r.recordid <> m.recordID\n"
},
{
"answer_id": 4646461,
"author": "endo64",
"author_id": 333153,
"author_profile": "https://Stackoverflow.com/users/333153",
"pm_score": 0,
"selected": false,
"text": "delete t1 from table1 as t1 where exists (\n select * from table1 as t2 where\n t1.column1=t2.column1 and\n t1.column2=t2.column2 and\n t1.column3=t2.column3 and\n --add other colums if any\n t1.id>t2.id\n)\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7952/"
] |
161,975
|
<p>Ever since I started using .NET, I've just been creating Helper classes or Partial classes to keep code located and contained in their own little containers, etc. </p>
<p>What I'm looking to know is the best practices for making ones code as clean and polished as it possibly could be.</p>
<p>Obviously clean code is subjective, but I'm talking about when to use things (not how to use them) such as polymorphism, inheritance, interfaces, classes and how to design classes more appropriately (to make them more useful, not just say 'DatabaseHelper', as some considered this bad practice in the <a href="https://stackoverflow.com/questions/114342/what-are-code-smells-what-is-the-best-way-to-correct-them">code smells wiki</a>).</p>
<p>Are there any resources out there that could possibly help with this kind of decision making? </p>
<p>Bare in mind that I haven't even started a CS or software engineering course, and that a teaching resource is fairly limited in real-life.</p>
|
[
{
"answer_id": 162003,
"author": "Andre Bossard",
"author_id": 21027,
"author_profile": "https://Stackoverflow.com/users/21027",
"pm_score": 6,
"selected": true,
"text": "holy code"
},
{
"answer_id": 1164985,
"author": "peterchen",
"author_id": 31317,
"author_profile": "https://Stackoverflow.com/users/31317",
"pm_score": 1,
"selected": false,
"text": "m_Pi m_PI"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161975",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20900/"
] |
161,984
|
<p>Is it possible to create Selenium tests using the Firefox plugin that use randomly generated values to help do regression tests?</p>
<p><strong>The full story:</strong>
I would like to help my clients do acceptance testing by providing them with a suite of tests that use some smarts to create random (or at least pseudo-random) values for the database. One of the issues with my Selenium IDE tests at the moment is that they have predefined values - which makes some types of testing problematic. </p>
|
[
{
"answer_id": 162107,
"author": "Thilo",
"author_id": 14955,
"author_profile": "https://Stackoverflow.com/users/14955",
"pm_score": 7,
"selected": true,
"text": "type fieldName javascript{Math.floor(Math.random()*11)}\n"
},
{
"answer_id": 2709476,
"author": "RajendraChary",
"author_id": 325509,
"author_profile": "https://Stackoverflow.com/users/325509",
"pm_score": 5,
"selected": false,
"text": "Selenium.prototype.doRandomString = function( options, varName ) {\n\n var length = 8;\n var type = 'alphanumeric';\n var o = options.split( '|' );\n for ( var i = 0 ; i < 2 ; i ++ ) {\n if ( o[i] && o[i].match( /^\\d+$/ ) )\n length = o[i];\n\n if ( o[i] && o[i].match( /^(?:alpha)?(?:numeric)?$/ ) )\n type = o[i];\n }\n\n switch( type ) {\n case 'alpha' : storedVars[ varName ] = randomAlpha( length ); break;\n case 'numeric' : storedVars[ varName ] = randomNumeric( length ); break;\n case 'alphanumeric' : storedVars[ varName ] = randomAlphaNumeric( length ); break;\n default : storedVars[ varName ] = randomAlphaNumeric( length );\n };\n};\n\nfunction randomNumeric ( length ) {\n return generateRandomString( length, '0123456789'.split( '' ) );\n}\n\nfunction randomAlpha ( length ) {\n var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );\n return generateRandomString( length, alpha );\n}\n\nfunction randomAlphaNumeric ( length ) {\n var alphanumeric = '01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split( '' );\n return generateRandomString( length, alphanumeric );\n}\n\nfunction generateRandomString( length, chars ) {\n var string = '';\n for ( var i = 0 ; i < length ; i++ )\n string += chars[ Math.floor( Math.random() * chars.length ) ];\n return string;\n}\n Command Target Value\n----------- --------- ----------\nrandomString 6 x\ntype username ${x}\n <tr>\n <td>randomString</td>\n <td>6</td>\n <td>x</td>\n</tr>\n<tr>\n <td>type</td>\n <td>username</td>\n <td>${x}</td>\n</tr>\n"
},
{
"answer_id": 3616176,
"author": "corbacho",
"author_id": 436732,
"author_profile": "https://Stackoverflow.com/users/436732",
"pm_score": 5,
"selected": false,
"text": "javascript{\"joe+\" + Math.floor(Math.random()*11111) + \"@gmail.com\";}\n joe+testing@gmail.com joe@gmail.com"
},
{
"answer_id": 4959178,
"author": "afternoon",
"author_id": 26201,
"author_profile": "https://Stackoverflow.com/users/26201",
"pm_score": 3,
"selected": false,
"text": "\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\".split(\"\").filter(function(e, i, a) { return Math.random() > 0.8 }).join(\"\")\n"
},
{
"answer_id": 5500921,
"author": "TomG",
"author_id": 6315,
"author_profile": "https://Stackoverflow.com/users/6315",
"pm_score": 2,
"selected": false,
"text": "javascript{['brie','cheddar','swiss'][Math.floor(Math.random()*3)]}\n"
},
{
"answer_id": 5619276,
"author": "bast",
"author_id": 701873,
"author_profile": "https://Stackoverflow.com/users/701873",
"pm_score": 1,
"selected": false,
"text": "function generateRandomString( length, chars ) {\nvar string=prompt(\"Please today's random string\",'');\nif (string == '')\n {for ( var i = 0 ; i < length ; i++ )\n string += chars[ Math.floor( Math.random() * chars.length ) ];\n return string;}\n else\n {\n return string;}\n}\n"
},
{
"answer_id": 9708548,
"author": "lhoess",
"author_id": 398403,
"author_profile": "https://Stackoverflow.com/users/398403",
"pm_score": 0,
"selected": false,
"text": "<tr>\n <td>runScript</td>\n <td>emailRandom=document.getElementById('email');console.log(emailRandom.value);emailRandom.value="myEmail+" + Math.floor(Math.random()*11111)+ "@gmail.com";</td>\n <td></td>\n</tr>\n"
},
{
"answer_id": 29807393,
"author": "Jonathan Conibeer",
"author_id": 4821205,
"author_profile": "https://Stackoverflow.com/users/4821205",
"pm_score": 2,
"selected": false,
"text": "<tr>\n<td>store</td>\n <td>javascript{Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 8)}</td>\n<td>myRandomString</td>\n</tr>\n"
},
{
"answer_id": 41010108,
"author": "andrew lorien",
"author_id": 4920725,
"author_profile": "https://Stackoverflow.com/users/4920725",
"pm_score": 0,
"selected": false,
"text": "<tr>\n <td>store</td>\n <td>javascript{var myDate = new Date(); myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate()+"-"+myDate.getHours()+myDate.getMinutes()+myDate.getSeconds()+myDate.getMilliseconds();}</td>\n <td>S_Unique</td>\n</tr>\n<tr>\n <td>store</td>\n <td>Selenium Test InternalRefID-${S_Unique}</td>\n <td>UniqueInternalRefID</td>\n</tr>\n<tr>\n <td>store</td>\n <td>Selenium Test Title-${S_Unique}</td>\n <td>UniqueTitle</td>\n</tr>\n<tr>\n <td>store</td>\n <td>SeleniumEmail-${G_Unique}@myURL.com</td>\n <td>UniqueEmailAddress</td>\n</tr>\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14971/"
] |
161,988
|
<p>I'm reading data from a table( from a MySQL Database) with Hibernate SQL Query.
The thing is, the table contains a colum that is mapped to a char in Hibernate Model, and sometimes this column is empty.
And I suppose this is where my exception comes from.
How can I map a colum of char to my hibernate model without getting this error ?
Thanks for your answers !</p>
<hr>
<p>Thank you for your answer !
My column is not nullable (I 'm using MySQL and this column is NOT NULL)
Then, I don't think that </p>
<pre><code>if (str == null) {
</code></pre>
<p>is appropriate.</p>
<p>the error is : </p>
<pre><code>15:30:35,289 INFO CharacterType:178 - could not read column value from result set: LSFUS11_20_; String index out of range: 0
</code></pre>
<p>which results in the following exception :</p>
<pre><code>java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:558)
</code></pre>
<p>I think I may try your solution, but with : </p>
<pre><code>if (str == "") {
</code></pre>
<p>since it can't be null, it's just an empty String.</p>
<p>Thanks for your piece code, I'm going to try that !</p>
|
[
{
"answer_id": 162145,
"author": "MetroidFan2002",
"author_id": 8026,
"author_profile": "https://Stackoverflow.com/users/8026",
"pm_score": 3,
"selected": true,
"text": "import java.sql.ResultSet;\nimport java.sql.SQLException;\n\nimport org.hibernate.type.CharacterType;\n\npublic class NullCharacterType extends CharacterType {\n\n /**\n * Serializable ID generated by Eclipse\n */\n private static final long serialVersionUID = 1L;\n\n public NullCharacterType() {\n super();\n }\n\n public Object get(final ResultSet rs, final String name)\n throws SQLException {\n final String str = rs.getString(name);\n if (str == null || str.length() == 0) {\n return new Character((char) 0);\n } else {\n return new Character(str.charAt(0));\n }\n }\n}\n <property name=\"theChar\" type=\"character\">\n <property name=\"theChar\" type=\"yourpackage.NullCharacterType\">\n"
},
{
"answer_id": 3280869,
"author": "srinivas",
"author_id": 395796,
"author_profile": "https://Stackoverflow.com/users/395796",
"pm_score": 0,
"selected": false,
"text": "mysql.jar mysql.jar"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161988",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24069/"
] |
161,994
|
<p>Assuming I have an open source web server or proxy I can enhance, let's say apache or squid. </p>
<p>Is there a way to determine the time each client spends on a web page?</p>
<p>HTTP is of course stateless, so it's not trivial, but maybe someone has an idea on how to approach this problem?</p>
|
[
{
"answer_id": 162136,
"author": "joelhardi",
"author_id": 11438,
"author_profile": "https://Stackoverflow.com/users/11438",
"pm_score": 0,
"selected": false,
"text": "<a href>"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/161994",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13523/"
] |
162,007
|
<p>I have an object of the type System.Drawing.Image and want to make every pixel which has some specific color, for example black, transparent (that is, set alpha to 0 for this pixel).</p>
<p>What is the best way to do this?</p>
|
[
{
"answer_id": 162063,
"author": "Phil Wright",
"author_id": 6276,
"author_profile": "https://Stackoverflow.com/users/6276",
"pm_score": 4,
"selected": true,
"text": "ImageAttributes attribs = new ImageAttributes();\nList<ColorMap> colorMaps = new List<ColorMap>();\n//\n// Remap black top be transparent\nColorMap remap = new ColorMap();\nremap.OldColor = Color.Black;\nremap.NewColor = Color.Transparent;\ncolorMaps.Add(remap);\n//\n// ...add additional remapping entries here...\n//\nattribs.SetRemapTable(colorMaps.ToArray(), ColorAdjustType.Bitmap);\ncontext.Graphics.DrawImage(image, imageRect, 0, 0, \n imageRect.Width, imageRect.Height, \n GraphicsUnit.Pixel, attribs);\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7559/"
] |
162,011
|
<p>I have a Nant build file which executes NUnit after compiling the dll's. I am executing the NAnt build file with a task in CruiseControl. So NAnt is running the tests not CruiseControl.</p>
<p>How do I configure it so that the CruiseControl web dashboard can be used to view the NUnit output ?</p>
<hr>
<p>This fixed it:</p>
<pre><code><publishers>
<merge>
<files>
<file>build\*.test-result.xml</file>
</files>
</merge>
<xmllogger />
</publishers>
</code></pre>
|
[
{
"answer_id": 162055,
"author": "ckramer",
"author_id": 20504,
"author_profile": "https://Stackoverflow.com/users/20504",
"pm_score": 4,
"selected": true,
"text": " <merge>\n <files>\n <file><path to XML output>\\*.xml</file>\n </files>\n </merge>\n"
},
{
"answer_id": 2237994,
"author": "ScottD",
"author_id": 111506,
"author_profile": "https://Stackoverflow.com/users/111506",
"pm_score": 2,
"selected": false,
"text": "<merge> <publisher> <xmllogger> <workingDirectory> <project>"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2083160/"
] |
162,020
|
<p>I am using ASP.NET 2.0 with AJAX Extensions (1.0?) and am wondering if it is possible to call a method asynchronously and have the results populate on the page after it has been loaded.</p>
<p>I have a gridview that is populated by a fairly long-running SQL query. I would prefer to have the page come up and the results trickle back in as they are returned from the server instead of forcing the user to stare at a blank page until everything is processed.</p>
|
[
{
"answer_id": 866098,
"author": "nicoruy",
"author_id": 60315,
"author_profile": "https://Stackoverflow.com/users/60315",
"pm_score": 0,
"selected": false,
"text": "<div style=\"visibility:hidden\">\n <asp:Button ID=\"btnLoad\" OnClick=\"btnLoad_Click\" runat=\"server\"/>\n</div>\n protected void Page_Load(object sender, EventArgs e)\n{ \n if (!Page.IsPostBack)\n {\n ScriptManager.RegisterStartupScript(this, this.GetType(), \"InitialLoad\" + this.ClientID, Page.ClientScript.GetPostBackEventReference(btnLoad, \"\")+\";\", true);\n }\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
162,028
|
<p>We have a large C# (.net 2.0) app which uses our own C++ COM component and a 3rd party fingerprint scanner library also accessed via COM. We ran into an issue where in production some events from the fingerprint library do not get fired into the C# app, although events from our own C++ COM component fired and were received just fine.</p>
<p>Using MSINFO32 to compare the loaded modules on a working system to those on a failing system we determined that this was caused by STDOLE.DLL not being in the GAC and hence not loaded into the faulty process.</p>
<p>Dragging this file into the GAC caused events to come back fine from the fingerprint COM library.</p>
<p>So what does stdole.dll do? It's 16k in size so it can't be much... is it some sort of link to another library like STDOLE32? How come its absence causes such odd behavior?</p>
<p>How do we distribute stdole.dll? This is an XCOPY deploy app and we don't use the GAC. Should we package it as a resource and use the System.EnterpriseServices.Internal.Publish.GacInstall to ensure it's in the GAC?</p>
|
[
{
"answer_id": 39623446,
"author": "Tony L.",
"author_id": 3347858,
"author_profile": "https://Stackoverflow.com/users/3347858",
"pm_score": 2,
"selected": false,
"text": "Embed Interop Types=true Embed Interop Types=false"
},
{
"answer_id": 49375166,
"author": "Ruskin",
"author_id": 581414,
"author_profile": "https://Stackoverflow.com/users/581414",
"pm_score": 1,
"selected": false,
"text": "<File Include=\"bin/stdole.dll\"> ...\n"
},
{
"answer_id": 68167786,
"author": "StayOnTarget",
"author_id": 3195477,
"author_profile": "https://Stackoverflow.com/users/3195477",
"pm_score": 2,
"selected": false,
"text": "stdole.dll .NET app -->\n stdole.dll -->\n stdole2.tlb -->\n oleaut32.dll\n stdole.dll stdole.dll StdPicture using System.Runtime.InteropServices;\n\nnamespace stdole\n{\n [CoClass(typeof (StdPictureClass))]\n [Guid(\"7BF80981-BF32-101A-8BBB-00AA00300CAB\")]\n [ComImport]\n public interface StdPicture : Picture\n {\n }\n}\n tlbimp.exe Guid 7BF80981-BF32-101A-8BBB-00AA00300CAB stole.StdPicture Computer\\HKEY_CLASSES_ROOT\\Interface\\{7BF80981-BF32-101A-8BBB-00AA00300CAB}\\TypeLib\n 00020430-0000-0000-C000-000000000046 Computer\\HKEY_CLASSES_ROOT\\TypeLib\\{00020430-0000-0000-C000-000000000046}\n 2.0\\0\\win32 C:\\WINDOWS\\SysWow64\\stdole2.tlb\n StdPicture stdole2.tlb // typelib filename: stdole2.tlb\n\n[\n uuid(00020430-0000-0000-C000-000000000046),\n version(2.0),\n helpstring(\"OLE Automation\")\n]\nlibrary stdole\n{\n ...\n}\n uuid StdPicture [\n uuid(0BE35204-8F91-11CE-9DE3-00AA004BB851)\n]\ncoclass StdPicture {\n ...\n};\n uuid Computer\\HKEY_CLASSES_ROOT\\CLSID\\{0BE35204-8F91-11CE-9DE3-00AA004BB851}\\InprocServer32\n C:\\Windows\\System32\\oleaut32.dll StdPicture stdole SysWow64"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
162,032
|
<p>I've got two arrays of the same size. I'd like to merge the two so the values of one are the key indexes of the new array, and the values of the new array are the values of the other.</p>
<p>Right now I'm just looping through the arrays and creating the new array manually, but I have a feeling there is a much more elegant way to go about this. I don't see any array functions for this purpose, but maybe I missed something? Is there a simple way to this along these lines?</p>
<pre><code>$mapped_array = mapkeys($array_with_keys, $array_with_values);
</code></pre>
|
[
{
"answer_id": 162040,
"author": "aib",
"author_id": 1088,
"author_profile": "https://Stackoverflow.com/users/1088",
"pm_score": 7,
"selected": true,
"text": "array_combine()"
},
{
"answer_id": 163069,
"author": "Christopher Lightfoot",
"author_id": 24525,
"author_profile": "https://Stackoverflow.com/users/24525",
"pm_score": 4,
"selected": false,
"text": "array array_combine ( array $keys , array $values ) <?php\n$a = array('green', 'red', 'yellow');\n$b = array('avocado', 'apple', 'banana');\n$c = array_combine($a, $b);\n\nprint_r($c);\n?>\n Array\n(\n [green] => avocado\n [red] => apple\n [yellow] => banana\n)\n"
},
{
"answer_id": 1923763,
"author": "Mathias",
"author_id": 234034,
"author_profile": "https://Stackoverflow.com/users/234034",
"pm_score": 3,
"selected": false,
"text": "function array_merge_keys($ray1, $ray2) {\n $keys = array_merge(array_keys($ray1), array_keys($ray2));\n $vals = array_merge($ray1, $ray2);\n return array_combine($keys, $vals);\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
162,037
|
<p>My Outlook add-in handles NewInspector event of the Inspector object, in order to display a custom form for the mail item.</p>
<p>I can get EntryID of the CurrentItem of the Inspector object which is passed as a parameter of the event. But, the problem is that the EntryID of the current mail item is shorter than it should be, and is unknown. I know every EntryID of every mail item that was created, and I can see that specific mail item has a wrong EntryID.</p>
<p>What is wrong?</p>
|
[
{
"answer_id": 162585,
"author": "Nenad Dobrilovic",
"author_id": 22062,
"author_profile": "https://Stackoverflow.com/users/22062",
"pm_score": 3,
"selected": true,
"text": "item.Save();\nitem.Move(some_folder);\nitems_list.Add(item.EntryID);\n item.Save();\nitem = (Outlook.MailItem)item.Move(some_folder);\nitems_list.Add(item.EntryID);\n"
},
{
"answer_id": 58498283,
"author": "dotNET",
"author_id": 1137199,
"author_profile": "https://Stackoverflow.com/users/1137199",
"pm_score": 0,
"selected": false,
"text": "MailItem.Save() EntryID MailItem EntryID Drafts"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162037",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22062/"
] |
162,042
|
<p>Let's face it. The Singleton Pattern is <a href="https://stackoverflow.com/questions/11831/singletons-good-design-or-a-crutch#11839">highly controversial</a> topic with hordes programmers on <em>both</em> sides of the fence. There are those who feel like the Singleton is nothing more then a glorified global variable, and others who swear by pattern and use it incessantly. I don't want the <a href="http://code.google.com/p/google-singleton-detector/wiki/WhySingletonsAreControversial" rel="noreferrer">Singleton Controversy</a> to lie at the heart of my question, however. <strong>Everyone can have a tug-of-war and battle it out and see who wins for all I care</strong>. What I'm trying to say is, I don't believe there is a single correct answer and I'm not intentionally trying inflame partisan bickering. I am simply interested in <em>singleton-alternatives</em> when I ask the question:</p>
<p><strong>Are their any specific alternatives to the GOF Singleton Pattern?</strong></p>
<p>For example, many times when I have used the singleton pattern in the past, I am simply interested in preserving the state/values of one or several variables. The state/values of variables, however, can be preserved between each instantiation of the class using <strong>static variables</strong> instead of using the singleton pattern.</p>
<p>What other idea's do you have?</p>
<p><strong>EDIT:</strong> I don't really want this to be another post about "how to use the singleton correctly." Again, I'm looking for ways to avoid it. For fun, ok? I guess I'm asking a purely academic question in your best movie trailer voice, "In a parallel universe where there is no singleton, what could we do?"</p>
|
[
{
"answer_id": 162167,
"author": "Pop Catalin",
"author_id": 4685,
"author_profile": "https://Stackoverflow.com/users/4685",
"pm_score": 2,
"selected": false,
"text": "*pseudocode* currentContainer.GetServiceByObjectType(singletonType)\n//Under the covers the object might be a singleton, but this is hidden to the consumer.\n *pseudocode* singletonType.Instance\n"
},
{
"answer_id": 162311,
"author": "seuvitor",
"author_id": 23477,
"author_profile": "https://Stackoverflow.com/users/23477",
"pm_score": 4,
"selected": false,
"text": "class NeedyClass {\n\n private ExSingletonClass exSingleton;\n\n public NeedyClass(ExSingletonClass exSingleton){\n this.exSingleton = exSingleton;\n }\n\n // Here goes some code that uses the exSingleton object\n}\n class FactoryOfNeedy {\n\n private ExSingletonClass exSingleton;\n\n public FactoryOfNeedy() {\n this.exSingleton = new ExSingletonClass();\n }\n\n public NeedyClass buildNeedy() {\n return new NeedyClass(this.exSingleton);\n }\n}\n"
},
{
"answer_id": 162441,
"author": "Rasmus Faber",
"author_id": 5542,
"author_profile": "https://Stackoverflow.com/users/5542",
"pm_score": 7,
"selected": false,
"text": "void purchaseLaptop(String creditCardNumber, int price){\n CreditCardProcessor.getInstance().debit(creditCardNumber, amount);\n Cart.getInstance().addLaptop();\n}\n void purchaseLaptop(CreditCardProcessor creditCardProcessor, Cart cart, \n String creditCardNumber, int price){\n creditCardProcessor.debit(creditCardNumber, amount);\n cart.addLaptop();\n}\n"
},
{
"answer_id": 2464541,
"author": "Mark M",
"author_id": 195539,
"author_profile": "https://Stackoverflow.com/users/195539",
"pm_score": 3,
"selected": false,
"text": "public class MonoStateExample\n{\n private static int x;\n\n public int getX()\n {\n return x;\n }\n\n public void setX(int xVal)\n {\n x = xVal;\n }\n}\n\npublic class MonoDriver\n{\n public static void main(String args[])\n {\n MonoStateExample m1 = new MonoStateExample();\n m1.setX(10);\n\n MonoStateExample m2 = new MonoStateExample();\n if(m1.getX() == m2.getX())\n {\n //singleton behavior\n }\n }\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162042",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25/"
] |
162,057
|
<p>I'm building a Thunderbird extension and would like to add my own header to all outgoing email (e.g. <myext-version: 1.0> ). Any idea how to do this? I know it's possible since this is done in the OpenPGP Enigmail extension. Thanks!</p>
|
[
{
"answer_id": 686118,
"author": "gerhard",
"author_id": 83151,
"author_profile": "https://Stackoverflow.com/users/83151",
"pm_score": 2,
"selected": false,
"text": "function SendObserver() {\n this.register();\n}\n\nSendObserver.prototype = {\n observe: function(subject, topic, data) {\n\n /* thunderbird sends a notification even when it's only saving the message as a draft.\n * We examine the caller chain to check for valid send notifications \n */\n var f = this.observe;\n while (f) {\n if(/Save/.test(f.name)) {\n print(\"Ignoring send notification because we're probably autosaving or saving as a draft/template\");\n return;\n }\n f = f.caller;\n }\n\n // add your headers here, separated by \\r\\n\n subject.gMsgCompose.compFields.otherRandomHeaders += \"x-test: test\\r\\n\"; \n }\n\n },\n register: function() {\n var observerService = Components.classes[\"@mozilla.org/observer-service;1\"]\n .getService(Components.interfaces.nsIObserverService);\n observerService.addObserver(this, \"mail:composeOnSend\", false);\n },\n unregister: function() {\n var observerService = Components.classes[\"@mozilla.org/observer-service;1\"]\n .getService(Components.interfaces.nsIObserverService);\n observerService.removeObserver(this, \"mail:composeOnSend\");\n }\n};\n\n\n/*\n * Register observer for send events. Check for event target to ensure that the \n * compose window is loaded/unloaded (and not the content of the editor).\n * \n * Unregister to prevent memory leaks (as per MDC documentation).\n */\nvar sendObserver;\nwindow.addEventListener('load', function (e) {if (e.target == document) sendObserver = new SendObserver(); }, true);\nwindow.addEventListener('unload', function (e) { if (e.target == document) sendObserver.unregister();}, true);\n chrome://messenger/content/messengercompose/messengercompose.xul)"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24473/"
] |
162,064
|
<p>I am using a textbox in a .NET 2 winforms app that is setup with a custom AutoCompleteSource. Is there anyway through code that I can increase the width of the list that appears containing the auto complete suggestions? </p>
<p>Ideally I would like to do this without increasing the width of the textbox as I am short for space in the UI.</p>
|
[
{
"answer_id": 162547,
"author": "Nikki9696",
"author_id": 456669,
"author_profile": "https://Stackoverflow.com/users/456669",
"pm_score": 1,
"selected": false,
"text": "Public Class Form1\nPrivate WithEvents T As TextBox\nPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load\n T = New TextBox\n T.SetBounds(20, 20, 100, 30)\n T.Font = New Font(\"Arial\", 12, FontStyle.Regular)\n T.Multiline = True\n T.Text = \"Type Here\"\n T.SelectAll()\n Controls.Add(T)\nEnd Sub\nPrivate Sub T_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles T.TextChanged\n Dim Width As Integer = TextRenderer.MeasureText(T.Text, T.Font).Width + 10\n Dim Height As Integer = TextRenderer.MeasureText(T.Text, T.Font).Height + 10\n T.Width = Width\n T.Height = Height\nEnd Sub\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6165/"
] |
162,079
|
<p>We have the usual <strong>web.xml</strong> for our web application which includes some jsp and jsp tag files. I want to switch to using pre-compiled jsp's. I have the pre-compilation happening in the build ok, and it generates the web.xml fragment and now I want to merge the fragment into the main web.xml.</p>
<p>Is there an <strong>include</strong> type directive for <strong>web.xml</strong> that will let me include the fragment. </p>
<p>Ideally I will leave things as is for DEV- as its useful to change jsp's on the fly and see the changes immediately but then for UAT/PROD, the jsp's will be pre-compiled and thus work faster.</p>
|
[
{
"answer_id": 162186,
"author": "Chris Kimpton",
"author_id": 48310,
"author_profile": "https://Stackoverflow.com/users/48310",
"pm_score": 2,
"selected": false,
"text": " <jasper2\n validateXml=\"false\"\n uriroot=\"${web.dir}\"\n addWebXmlMappings=\"true\"\n webXmlFragment=\"${web.dir}/WEB-INF/classes/jasper_generated_web.xml\"\n outputDir=\"${web.dir}/WEB-INF/jsp-src\" />\n"
},
{
"answer_id": 171192,
"author": "Mads Hansen",
"author_id": 14419,
"author_profile": "https://Stackoverflow.com/users/14419",
"pm_score": 3,
"selected": true,
"text": " <?xml version=\"1.0\"?>\n<project name=\"jspc\" basedir=\".\" default=\"all\">\n <import file=\"${build.appserver.home}/bin/catalina-tasks.xml\"/>\n\n <target name=\"all\" depends=\"jspc,compile\"></target>\n\n <target name=\"jspc\">\n <jasper\n validateXml=\"false\"\n uriroot=\"${build.war.dir}\"\n webXmlFragment=\"${build.war.dir}/WEB-INF/generated_web.xml\"\n addWebXmlMappings=\"true\"\n outputDir=\"${build.src.dir}\" />\n </target>\n\n <target name=\"compile\">\n <javac destdir=\"${build.dir}/classes\"\n srcdir=\"${build.src.dir}\"\n optimize=\"on\"\n debug=\"off\"\n failonerror=\"true\"\n source=\"1.5\"\n target=\"1.5\"\n excludes=\"**/*.smap\">\n <classpath>\n <fileset dir=\"${build.war.dir}/WEB-INF/classes\">\n <include name=\"*.class\" />\n </fileset>\n <fileset dir=\"${build.war.lib.dir}\">\n <include name=\"*.jar\" />\n </fileset>\n <fileset dir=\"${build.appserver.home}/lib\">\n <include name=\"*.jar\" />\n </fileset> \n <fileset dir=\"${build.appserver.home}/bin\">\n <include name=\"*.jar\"/>\n </fileset>\n </classpath>\n <include name=\"**\" />\n <exclude name=\"tags/**\"/>\n </javac>\n </target>\n\n <target name=\"clean\">\n <delete>\n <fileset dir=\"${build.src.dir}\"/>\n <fileset dir=\"${build.dir}/classes/org/apache/jsp\"/>\n </delete>\n </target>\n</project>\n"
},
{
"answer_id": 1532580,
"author": "Alexander Pogrebnyak",
"author_id": 185722,
"author_profile": "https://Stackoverflow.com/users/185722",
"pm_score": 2,
"selected": false,
"text": "<!-- @JSPS_MAP@ --> <servlet> <servlet-mapping> <servlet>\n <servlet-name>MyServlet</servlet-name>\n <servlet-class>my.servlets.MyServlet</servlet-class>\n <servlet>\n\n <!-- @JSPS_MAP@ -->\n\n <servlet-mapping>\n <servlet-name>MyServlet</servlet-name>\n <url-pattern>/my-servlet</url-pattern>\n </servlet-mapping>\n @JSPS_MAP@ <loadfile\n property=\"generated.web.xml.fragment\"\n srcFile=\"${generated.fragment.file}\"\n/>\n\n<copy file=\"${orig-web-content.dir}/WEB-INF/web.xml\"\n toFile=\"${generated-web-content.dir}/WEB-INF/web.xml\"\n>\n <filterset>\n <filter token=\"JSPS_MAP\"\n value=\" --> ${generated.web.xml.fragment} <!-- \"\n />\n </filterset>\n</copy>\n ${orig-web-content.dir}/WEB-INF/web.xml ${generated-web-content.dir}/WEB-INF/web.xml"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48310/"
] |
162,086
|
<p>in web.xml i set my welcome file to a jsp within web.xml</p>
<pre><code><welcome-file>WEB-INF/index.jsp</welcome-file>
</code></pre>
<p>inside index.jsp i then forward on to a servlet </p>
<pre><code><% response.sendRedirect(response.encodeRedirectURL("myServlet/")); %>
</code></pre>
<p>however the application tries to find the servlet at the following path </p>
<pre><code>applicationName/WEB-INF/myServlet
</code></pre>
<p>the problem is that web-inf should not be in the path. If i move index.jsp out of web-inf then the problem goes but is there another way i can get around this?</p>
|
[
{
"answer_id": 162186,
"author": "Chris Kimpton",
"author_id": 48310,
"author_profile": "https://Stackoverflow.com/users/48310",
"pm_score": 2,
"selected": false,
"text": " <jasper2\n validateXml=\"false\"\n uriroot=\"${web.dir}\"\n addWebXmlMappings=\"true\"\n webXmlFragment=\"${web.dir}/WEB-INF/classes/jasper_generated_web.xml\"\n outputDir=\"${web.dir}/WEB-INF/jsp-src\" />\n"
},
{
"answer_id": 171192,
"author": "Mads Hansen",
"author_id": 14419,
"author_profile": "https://Stackoverflow.com/users/14419",
"pm_score": 3,
"selected": true,
"text": " <?xml version=\"1.0\"?>\n<project name=\"jspc\" basedir=\".\" default=\"all\">\n <import file=\"${build.appserver.home}/bin/catalina-tasks.xml\"/>\n\n <target name=\"all\" depends=\"jspc,compile\"></target>\n\n <target name=\"jspc\">\n <jasper\n validateXml=\"false\"\n uriroot=\"${build.war.dir}\"\n webXmlFragment=\"${build.war.dir}/WEB-INF/generated_web.xml\"\n addWebXmlMappings=\"true\"\n outputDir=\"${build.src.dir}\" />\n </target>\n\n <target name=\"compile\">\n <javac destdir=\"${build.dir}/classes\"\n srcdir=\"${build.src.dir}\"\n optimize=\"on\"\n debug=\"off\"\n failonerror=\"true\"\n source=\"1.5\"\n target=\"1.5\"\n excludes=\"**/*.smap\">\n <classpath>\n <fileset dir=\"${build.war.dir}/WEB-INF/classes\">\n <include name=\"*.class\" />\n </fileset>\n <fileset dir=\"${build.war.lib.dir}\">\n <include name=\"*.jar\" />\n </fileset>\n <fileset dir=\"${build.appserver.home}/lib\">\n <include name=\"*.jar\" />\n </fileset> \n <fileset dir=\"${build.appserver.home}/bin\">\n <include name=\"*.jar\"/>\n </fileset>\n </classpath>\n <include name=\"**\" />\n <exclude name=\"tags/**\"/>\n </javac>\n </target>\n\n <target name=\"clean\">\n <delete>\n <fileset dir=\"${build.src.dir}\"/>\n <fileset dir=\"${build.dir}/classes/org/apache/jsp\"/>\n </delete>\n </target>\n</project>\n"
},
{
"answer_id": 1532580,
"author": "Alexander Pogrebnyak",
"author_id": 185722,
"author_profile": "https://Stackoverflow.com/users/185722",
"pm_score": 2,
"selected": false,
"text": "<!-- @JSPS_MAP@ --> <servlet> <servlet-mapping> <servlet>\n <servlet-name>MyServlet</servlet-name>\n <servlet-class>my.servlets.MyServlet</servlet-class>\n <servlet>\n\n <!-- @JSPS_MAP@ -->\n\n <servlet-mapping>\n <servlet-name>MyServlet</servlet-name>\n <url-pattern>/my-servlet</url-pattern>\n </servlet-mapping>\n @JSPS_MAP@ <loadfile\n property=\"generated.web.xml.fragment\"\n srcFile=\"${generated.fragment.file}\"\n/>\n\n<copy file=\"${orig-web-content.dir}/WEB-INF/web.xml\"\n toFile=\"${generated-web-content.dir}/WEB-INF/web.xml\"\n>\n <filterset>\n <filter token=\"JSPS_MAP\"\n value=\" --> ${generated.web.xml.fragment} <!-- \"\n />\n </filterset>\n</copy>\n ${orig-web-content.dir}/WEB-INF/web.xml ${generated-web-content.dir}/WEB-INF/web.xml"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24481/"
] |
162,088
|
<p>I use <code>serialize</code> in one <code>ActiveRecord</code> model to serialize an <code>Array</code> of simple Hashes into a text database field. I even use the second parameter to coerce deserialization into <code>Array</code>s.</p>
<pre><code>class Shop < ActiveRecord::Base
serialize : recipients, Array
end
</code></pre>
<p>It seems to work fine but, after a few requests, the content of <code>recipients</code> turns to <code>HashOfIndifferentAccess</code> hashes instead of arrays. This only happens after a few reloads of the models and I haven't been able to reproduce it in tests or the console, only in production environment.</p>
|
[
{
"answer_id": 12501093,
"author": "Jordan Sitkin",
"author_id": 273987,
"author_profile": "https://Stackoverflow.com/users/273987",
"pm_score": 2,
"selected": false,
"text": "some_field.force_encoding(Encoding::UTF_8)"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21702/"
] |
162,105
|
<p>What's a good method of programatically generating etag for web pages, and is this practice recommended? Some sites recommend turning etags off, others recommend producing them manually, and some recommend leaving the default settings active - what's the best way here?</p>
|
[
{
"answer_id": 163102,
"author": "blueyed",
"author_id": 15690,
"author_profile": "https://Stackoverflow.com/users/15690",
"pm_score": 3,
"selected": false,
"text": "md5($content)"
},
{
"answer_id": 826923,
"author": "easel",
"author_id": 16706,
"author_profile": "https://Stackoverflow.com/users/16706",
"pm_score": 2,
"selected": false,
"text": "FileETag none"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16511/"
] |
162,113
|
<p>I'm looking for an elegant, high performance solution to the following problem. </p>
<p>There are 256 linked lists. </p>
<ul>
<li>Each list contains the same types of object that among other things holds a whole number that is used to define a sort order.</li>
<li>All numbers across all lists are unique</li>
<li>Each individual list is sorted in ascending order by these numbers</li>
</ul>
<p>How would you create a single ascending ordered list from all the objects from the 256 original linked lists? I'd prefer not to brute force it, and have a few other ideas, but this seems like one of those problems that there's a standard, optimal solution for.</p>
|
[
{
"answer_id": 162131,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 3,
"selected": true,
"text": "# Preprocessing:\nresult = list.new()\nqueue = priority_queue.new()\n\nforeach (list in lists):\n queue.push(list.first())\n\n# Main loop:\nwhile (not queue.empty()):\n node = queue.pop()\n result.insert(node)\n if (node.next() != null):\n queue.push(node.next())\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162113",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7855/"
] |
162,142
|
<p>Perforce allows people to check in unchanged files. Why any version control system would allow this is beyond me, but that's a topic for another question. I want to create a trigger that will deny the submission of unchanged files. However, I have no experience with Perforce triggers. From what I've read, I'm guessing this would be a "Change-content" trigger since the files being submitted would have to be diffed against the respective head revisions they are about to replace. I would need to iterate over the incoming files and make sure they had all indeed changed. The problem is, I have no idea how to go about it.</p>
<p>Can anyone with Perforce trigger experience offer an example or at least point me in the right direction?</p>
|
[
{
"answer_id": 162570,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 3,
"selected": false,
"text": " SubmitOptions: Flags to change submit behaviour.\n\n submitunchanged All open files are submitted\n submitunchanged+reopen (default).\n\n revertunchanged Files that have content or type\n revertunchanged+reopen changes are submitted. Unchanged\n files are reverted.\n\n leaveunchanged Files that have content or type\n leaveunchanged+reopen changes are submitted. Unchanged\n files are moved to the default\n changelist.\n\n +reopen appended to the submit option flag\n will cause submitted files to be\n reopened on the default changelist.\n"
},
{
"answer_id": 164925,
"author": "Mark",
"author_id": 4405,
"author_profile": "https://Stackoverflow.com/users/4405",
"pm_score": 1,
"selected": false,
"text": "p4 diff //depot/path/...@=<change>\n p4 diff -sr //...@=<change>\n"
},
{
"answer_id": 8567383,
"author": "Chance",
"author_id": 382186,
"author_profile": "https://Stackoverflow.com/users/382186",
"pm_score": 0,
"selected": false,
"text": "p4 triggers Triggers: Trigger_name change-content //... \"/<path_to_trigger_script>/<script_name> %changelist% %serverhost% %serverport% %user%\" Trigger_name //... % <> #!/usr/bin/perl\n\n# ----- CHECK 1 : Make sure files NOT identical\n\n# get variables passed in through triggers call 'p4 triggers'\n$ChangeNum = $ARGV[0]; #change number\n$Server = $ARGV[1];\n$Port = $ARGV[2];\n$User = $ARGV[3];\n$p4 = \"<path_to_p4_exec>/p4 -p $Port \";\n# get list of files opened under the submitted changelist\n@files = `$p4 opened -a -c $ChangeNum | cut -f1 -d\"#\"`;\n\n# go through each file and compare to predecessor\n# although workspace should be configured to not submit unchanged files\n# this is an additional check\nforeach $file (@files)\n{\n chomp($file);\n # get sum of depot file, the #head version\n $depotSum = `$p4 print -q $file\\#head | sum`;\n # get sum of the recently submitted file, use @=$ChangeNum to do this\n $clientSum = `$p4 print -q $file\\@=$ChangeNum | sum`;\n\n chomp $depotSum;\n chomp $clientSum;\n # if 2 sums are same, issue error\n if ( $depotSum eq $clientSum )\n {\n # make sure this file is opened for edit and not for add/delete\n if ( `$p4 describe $ChangeNum | grep \"edit\"` )\n {\n printf \"\\nFile $file identical to predecessor!\";\n exit( 1 );\n }\n }\n\n}\n"
},
{
"answer_id": 43927870,
"author": "Samwise",
"author_id": 3799759,
"author_profile": "https://Stackoverflow.com/users/3799759",
"pm_score": 0,
"selected": false,
"text": "triggers Triggers:\n myTrigger form-in client \"sed -i -e s/submitunchanged/leaveunchanged/ %formfile%\"\n submitunchanged"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162142",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4228/"
] |
162,149
|
<p>Our company is sending out a lot of emails per day and planning to send even more in future. (thousands) Also there are mass mailouts as well in the ten thousands every now and then.</p>
<p>Anybody has experience with hotmail, yahoo (web.de, gmx.net) and similar webmail companies blocking your emails because "too many from the same source in a period of time" have been sent to them?</p>
<p>What can be done about it? Spreading email mailouts over a whole day/night? At what rate?</p>
<p>(we are talking about legal emailing just to make sure...)</p>
|
[
{
"answer_id": 162320,
"author": "Till",
"author_id": 2859,
"author_profile": "https://Stackoverflow.com/users/2859",
"pm_score": 6,
"selected": true,
"text": "Precedence: bulk"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/925/"
] |
162,159
|
<p>Which is better to do client side or server side validation?</p>
<p>In our situation we are using </p>
<ul>
<li>jQuery and MVC. </li>
<li>JSON data to pass between our View and Controller. </li>
</ul>
<p>A lot of the validation I do is validating data as users enter it.
For example I use the the <code>keypress</code> event to prevent letters in a text box, set a max number of characters and that a number is with in a range. </p>
<p>I guess the better question would be, Are there any benefits to doing server side validation over client side?</p>
<hr>
<p>Awesome answers everyone. The website that we have is password protected and for a small user base(<50). If they are not running JavaScript we will send ninjas. But if we were designing a site for everyone one I'd agree to do validation on both sides.</p>
|
[
{
"answer_id": 162579,
"author": "Nathan Long",
"author_id": 4376,
"author_profile": "https://Stackoverflow.com/users/4376",
"pm_score": 10,
"selected": true,
"text": "curl POST"
},
{
"answer_id": 19169307,
"author": "TaylorMac",
"author_id": 720785,
"author_profile": "https://Stackoverflow.com/users/720785",
"pm_score": 2,
"selected": false,
"text": "\"required\" inputs field.length > 0"
},
{
"answer_id": 33827418,
"author": "roland",
"author_id": 313353,
"author_profile": "https://Stackoverflow.com/users/313353",
"pm_score": 2,
"selected": false,
"text": "Client-Side validation n Server-side validation"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7617/"
] |
162,163
|
<p>I have been trying to determine a best case solution for registering a COM server using WiX to create a Windows Installer package and am struggling.</p>
<p>In this post <a href="http://blog.deploymentengineering.com/2008/09/howto-use-regsvr32exe-with-wix.html" rel="nofollow noreferrer">Deployment Engineering Archive: HOWTO: Use Regsvr32.exe with WIX</a>, there is an open request for the "Setup police" to crack down on using regsvr32 through an exe custom action. I know the evils of using <code>regsvr32</code> as it registers to the system rather than the user, but I also recall that <code>OleSelfRegister</code> can have issues from a microsoft support bulletin (sorry, can't find the link) - and I believe they recommended using <code>regsvr32</code>.</p>
<p>Any advice?</p>
|
[
{
"answer_id": 162330,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "COM extraction DllRegisterServer()"
},
{
"answer_id": 26304137,
"author": "perlyking",
"author_id": 1073262,
"author_profile": "https://Stackoverflow.com/users/1073262",
"pm_score": 1,
"selected": false,
"text": "heat reg <some.reg> -gg -o <some.wxs> <Fragment>\n <DirectoryRef Id=\"TARGETDIR\">\n <Component Id=\"blah\" Guid=\"{xxxxxxxxxxxxxxxxxxxxxxxxx}\" KeyPath=\"yes\">\n <RegistryKey Key=\"TypeLib\\{xxxxxxxxxxxxxxxxxxxxxx}\\4.1\\0\\win32\" Root=\"HKCR\">\n <RegistryValue Value=\"C:\\Users\\you\\projects\\MyProject\\dependencies\\installation\\COMFOO.exe\" Type=\"string\" />\n </RegistryKey>\n </Component>\n </DirectoryRef>\n</Fragment>\n <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">\n <Directory Id=\"ProgramFilesFolder\" Name=\"PFiles\">\n <Directory Id=\"COMPANY\" Name=\"My Company\">\n <!--This is the actual installation folder-->\n <Directory Name=\"MyProduct\" Id=\"MYPRODUCT\">\n [MYPRODUCT]\\COMFOO.exe"
},
{
"answer_id": 54947377,
"author": "Brian THOMAS",
"author_id": 1589759,
"author_profile": "https://Stackoverflow.com/users/1589759",
"pm_score": 0,
"selected": false,
"text": "Interop.candidate.dll obj\\debug"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162163",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1145/"
] |
162,172
|
<p>I am trying to install xampp 1.6.7 in a Red Hat Enterprise Edition. I followed the installation instructions and after that I started the stack with the command </p>
<pre><code>sudo /opt/lampp/lampp start
</code></pre>
<p>And I get te usual response</p>
<pre><code>XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.
</code></pre>
<p>But when I check the status of the components of the stack MySQL is not running, and I get:</p>
<pre><code>Version: XAMPP for Linux 1.5.5
Apache is running.
MySQL is not running.
ProFTPD is running.
</code></pre>
<p>This not always happens immediatly. Some times MySQL runs for a little while before crashing. I checked the logs and found nothing. </p>
<p>Edit:</p>
<p>the mysql log says</p>
<pre><code>081002 10:41:22 mysqld started
libgcc_s.so.1 must be installed for pthread_cancel to work
081002 10:41:24 mysqld ended
</code></pre>
<p>mysql status says:</p>
<pre><code>[root@localhost lampp]# bin/mysql status
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/lampp/var/mysql/mysql.sock' (2)
</code></pre>
<p>and ps -ef | grep mysql yields nothing</p>
|
[
{
"answer_id": 162230,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 0,
"selected": false,
"text": "mysql status\n ps aux | grep mysql\n"
},
{
"answer_id": 162275,
"author": "Till",
"author_id": 2859,
"author_profile": "https://Stackoverflow.com/users/2859",
"pm_score": 1,
"selected": false,
"text": "log-error my.cnf find / -name \"my.cnf\""
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162172",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9132/"
] |
162,176
|
<p><code>fopen</code> is failing when I try to read in a very moderately sized file in <code>PHP</code>. <code>A 6 meg file</code> makes it choke, though smaller files around <code>100k</code> are just fine. i've read that it is sometimes necessary to recompile <code>PHP</code> with the <code>-D_FILE_OFFSET_BITS=64</code> flag in order to read files over 20 gigs or something ridiculous, but shouldn't I have no problems with a 6 meg file? Eventually we'll want to read in files that are around 100 megs, and it would be nice be able to open them and then read through them line by line with fgets as I'm able to do with smaller files.</p>
<p>What are your tricks/solutions for reading and doing operations on very large files in <code>PHP</code>?</p>
<p>Update: Here's an example of a simple codeblock that fails on my 6 meg file - PHP doesn't seem to throw an error, it just returns false. Maybe I'm doing something extremely dumb?</p>
<pre><code>$rawfile = "mediumfile.csv";
if($file = fopen($rawfile, "r")){
fclose($file);
} else {
echo "fail!";
}
</code></pre>
<p>Another update: Thanks all for your help, it did turn out to be something incredibly dumb - a permissions issue. My small file inexplicably had read permissions when the larger file didn't. Doh!</p>
|
[
{
"answer_id": 162263,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 7,
"selected": true,
"text": "fopen fgets $handle = fopen(\"/tmp/uploadfile.txt\", \"r\") or die(\"Couldn't get handle\");\nif ($handle) {\n while (!feof($handle)) {\n $buffer = fgets($handle, 4096);\n // Process buffer here..\n }\n fclose($handle);\n}\n $rawfile"
},
{
"answer_id": 162495,
"author": "Juan Pablo Califano",
"author_id": 24170,
"author_profile": "https://Stackoverflow.com/users/24170",
"pm_score": -1,
"selected": false,
"text": "ini\\_set(\"memory_limit\",\"12M\");\n"
},
{
"answer_id": 25123395,
"author": "RightClick",
"author_id": 3621140,
"author_profile": "https://Stackoverflow.com/users/3621140",
"pm_score": 0,
"selected": false,
"text": "fopen() file() fopen() file() string->array file()"
},
{
"answer_id": 33001695,
"author": "Al-Punk",
"author_id": 277861,
"author_profile": "https://Stackoverflow.com/users/277861",
"pm_score": 4,
"selected": false,
"text": "fopen() file() fopen() file() file()"
},
{
"answer_id": 54704668,
"author": "Tinel Barb",
"author_id": 7725536,
"author_profile": "https://Stackoverflow.com/users/7725536",
"pm_score": 3,
"selected": false,
"text": "fgets() file_ get_contents() file_get_contents() file() memory_limit $filesize = get_file_size($file);\n$fp = @fopen($file, \"r\");\n$chunk_size = (1<<24); // 16MB arbitrary\n$position = 0;\n\n// if handle $fp to file was created, go ahead\nif ($fp) {\n while(!feof($fp)){\n // move pointer to $position in file\n fseek($fp, $position);\n\n // take a slice of $chunk_size bytes\n $chunk = fread($fp,$chunk_size);\n\n // searching the end of last full text line (or get remaining chunk)\n if ( !($last_lf_pos = strrpos($chunk, \"\\n\")) ) $last_lf_pos = mb_strlen($chunk);\n\n // $buffer will contain full lines of text\n // starting from $position to $last_lf_pos\n $buffer = mb_substr($chunk,0,$last_lf_pos);\n \n ////////////////////////////////////////////////////\n //// ... DO SOMETHING WITH THIS BUFFER HERE ... ////\n ////////////////////////////////////////////////////\n\n // Move $position\n $position += $last_lf_pos;\n\n // if remaining is less than $chunk_size, make $chunk_size equal remaining\n if(($position+$chunk_size) > $filesize) $chunk_size = $filesize-$position;\n $buffer = NULL;\n }\n fclose($fp);\n}\n $chunk_size file_ get_contents() get_file_size()"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162176",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
162,177
|
<p>I have an application A with a domain-model which is mapped to a database using Hibernate. I have another application B that uses exactly the same domain-model-classes as A and adds some additional classes. </p>
<p>My goal is to read data from database A in application B and transfer that data into the database of B (to make a copy of it). In addition, some the domain-classes of B have associations (OneToOne) to domain-classes of A (but in the database of B, of course).</p>
<p>What's the best strategy to accomplish this? I thought of two session factories and using <code>Session.replicate()</code> (how does that work?). Or should I better introduce an additional mapping layer between these two domain-models for loose coupling?</p>
|
[
{
"answer_id": 12634553,
"author": "Kevin Wong",
"author_id": 4792,
"author_profile": "https://Stackoverflow.com/users/4792",
"pm_score": 2,
"selected": false,
"text": "import java.io.Serializable;\nimport java.util.List;\nimport java.util.logging.Logger;\n\nimport lombok.Getter;\nimport lombok.RequiredArgsConstructor;\nimport lombok.Setter;\n\nimport org.hibernate.Session;\nimport org.hibernate.Transaction;\n\nimport ca.digitalrapids.lang.GeneralException;\nimport ca.digitalrapids.mediamanager.server.dao.hibernate.GenericDAOHibernate;\nimport ca.digitalrapids.mediamanager.server.dao.hibernate.GenericDAOHibernate.GenericDAOHibernateFactory;\nimport ca.digitalrapids.persist.dao.DAOOptions;\nimport ca.digitalrapids.persist.hibernate.HibernateUtil2;\n\nimport com.google.common.collect.ImmutableMultimap;\nimport com.google.common.collect.ImmutableSet;\nimport com.google.common.collect.Sets;\n\n@RequiredArgsConstructor\npublic class DataMigrator\n{\n private static final Logger logger = Logger\n .getLogger(DataMigrator.class.getName());\n private final HibernateUtil2 sourceHibernateUtil2;\n private final HibernateUtil2 destHibernateUtil2;\n private final ImmutableSet<Class<?>> beanClassesToMigrate;\n @Setter @Getter\n private Integer copyBatchSize = 10;\n @Setter\n private GenericDAOHibernateFactory sourceDaoFactory = \n new GenericDAOHibernate.GenericDAOHibernateFactoryImpl();\n @Setter\n private GenericDAOHibernateFactory destDaoFactory = \n new GenericDAOHibernate.GenericDAOHibernateFactoryImpl();\n private final ImmutableMultimap<Class<?>, Class<?>> entityDependencies;\n\n public void run() throws GeneralException\n {\n migrateData(sourceHibernateUtil2.getSession(), \n destHibernateUtil2.getSession());\n }\n\n private void migrateData(Session sourceSession, Session destSession) \n throws GeneralException\n {\n logger.info(\"\\nMigrating data from old HSQLDB database.\\n\");\n\n Transaction destTransaction = null;\n try\n {\n destTransaction = destSession.beginTransaction();\n migrateBeans(sourceSession, destSession, beanClassesToMigrate,\n entityDependencies);\n destTransaction.commit();\n } catch (Throwable e) {\n if ( destTransaction != null )\n destTransaction.rollback();\n throw e;\n }\n\n logger.info(\"\\nData migration complete!\\n\");\n }\n\n\n\n private void migrateBeans(Session sourceSession, Session destSession,\n ImmutableSet<Class<?>> beanClasses, ImmutableMultimap<Class<?>, Class<?>> deps)\n {\n if ( beanClasses.isEmpty() ) return;\n Class<?> head = beanClasses.iterator().next();\n ImmutableSet<Class<?>> tail = \n Sets.difference(beanClasses, ImmutableSet.of(head)).immutableCopy();\n ImmutableSet<Class<?>> childrenOfHead = getChildren(head, tail, deps);\n migrateBeans(sourceSession, destSession, childrenOfHead, deps);\n migrateBean(sourceSession, destSession, head);\n migrateBeans(sourceSession, destSession, \n Sets.difference(tail, childrenOfHead).immutableCopy(), deps);\n }\n\n private ImmutableSet<Class<?>> getChildren(Class<?> parent,\n ImmutableSet<Class<?>> possibleChildren, \n ImmutableMultimap<Class<?>, Class<?>> deps)\n {\n ImmutableSet<Class<?>> parentDeps = ImmutableSet.copyOf(deps.get(parent));\n return Sets.intersection(possibleChildren, parentDeps).immutableCopy();\n }\n\n private void migrateBean(Session sourceSession, Session destSession,\n Class<?> beanClass)\n {\n GenericDAOHibernate<?, Serializable> sourceDao = \n sourceDaoFactory.get(beanClass, sourceSession);\n logger.info(\"Migrating \"+sourceDao.countAll()+\" of \"+beanClass);\n\n DAOOptions options = new DAOOptions();\n options.setMaxResults(copyBatchSize);\n List<?> sourceBeans;\n int firstResult = 0;\n int sourceBeansSize;\n do { \n options.setFirstResult(firstResult);\n sourceBeans = sourceDao.findAll(options);\n sourceBeansSize = sourceBeans.size();\n @SuppressWarnings(\"unchecked\")\n GenericDAOHibernate<Object, Serializable> destDao = \n (GenericDAOHibernate<Object, Serializable>) \n destDaoFactory.get(beanClass, destSession);\n for (Object sourceBean : sourceBeans)\n {\n destDao.save(sourceBean);\n }\n firstResult += copyBatchSize;\n sourceSession.clear();/* prevent memory problems */\n } while ( sourceBeansSize >= copyBatchSize );\n }\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162177",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18722/"
] |
162,187
|
<p>When used like this:</p>
<pre><code>import static com.showboy.Myclass;
public class Anotherclass{}
</code></pre>
<p>what's the difference between <code>import static com.showboy.Myclass</code> and <code>import com.showboy.Myclass</code>?</p>
|
[
{
"answer_id": 162215,
"author": "Nicolas",
"author_id": 1730,
"author_profile": "https://Stackoverflow.com/users/1730",
"pm_score": 6,
"selected": false,
"text": "package test;\n\nimport org.example.Foo;\n\nclass A {\n\n B b = Foo.B_INSTANCE;\n\n}\n package test;\n\nimport static org.example.Foo.B_INSTANCE;\n\nclass A {\n\n B b = B_INSTANCE;\n\n}\n"
},
{
"answer_id": 162328,
"author": "Victor",
"author_id": 3419,
"author_profile": "https://Stackoverflow.com/users/3419",
"pm_score": 8,
"selected": false,
"text": "import org.apache.commons.lang.StringUtils;\n .\n .\n .\nif (StringUtils.isBlank(aString)) {\n .\n .\n .\n import static org.apache.commons.lang.StringUtils.isBlank;\n .\n .\n .\nif (isBlank(aString)) {\n .\n .\n .\n"
},
{
"answer_id": 1565597,
"author": "user85421",
"author_id": 85421,
"author_profile": "https://Stackoverflow.com/users/85421",
"pm_score": 5,
"selected": false,
"text": "import static com.showboy.MyClass.*;\n"
},
{
"answer_id": 12494839,
"author": "Rahul Saxena",
"author_id": 1682964,
"author_profile": "https://Stackoverflow.com/users/1682964",
"pm_score": 5,
"selected": false,
"text": "import java.lang.Math;\n\nclass WithoutStaticImports {\n\n public static void main(String [] args) {\n System.out.println(\"round \" + Math.round(1032.897));\n System.out.println(\"min \" + Math.min(60,102));\n }\n}\n import static java.lang.System.out;\nimport static java.lang.Math.*;\n\nclass WithStaticImports {\n public static void main(String [] args) {\n out.println(\"round \" + round(1032.897));\n out.println(\"min \" + min(60,102));\n }\n}\n"
},
{
"answer_id": 34414886,
"author": "Java Main",
"author_id": 4537618,
"author_profile": "https://Stackoverflow.com/users/4537618",
"pm_score": 2,
"selected": false,
"text": "MyClass myPackage myStaticField myStaticMethod MyClass.myStaticField MyClass.myStaticMethod import myPackage.MyClass myPackage.*"
},
{
"answer_id": 35114747,
"author": "roottraveller",
"author_id": 5167682,
"author_profile": "https://Stackoverflow.com/users/5167682",
"pm_score": 4,
"selected": false,
"text": "import static import import static import import java.lang.System.*; \nclass StaticImportExample{ \n public static void main(String args[]){ \n\n System.out.println(\"Hello\");\n System.out.println(\"Java\"); \n\n } \n} \n import static java.lang.System.*; \nclass StaticImportExample{ \n public static void main(String args[]){ \n\n out.println(\"Hello\");//Now no need of System.out \n out.println(\"Java\"); \n\n } \n} \n"
},
{
"answer_id": 37723728,
"author": "Rajeev",
"author_id": 3821301,
"author_profile": "https://Stackoverflow.com/users/3821301",
"pm_score": 1,
"selected": false,
"text": "static import import static import static import static static import static import import static"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10927/"
] |
162,192
|
<p>When adding a DLL as a reference to an ASP.Net project, VS2008 adds several files to the bin directory. If the DLL is called foo.dll, VS2008 adds foo.dll.refresh, foo.pdb and foo.xml. I know what foo.dll is :-), why does VS2008 add the other three files? What do those three files do? Can I delete them? Do they need to be added in source control?</p>
|
[
{
"answer_id": 162223,
"author": "xsl",
"author_id": 11387,
"author_profile": "https://Stackoverflow.com/users/11387",
"pm_score": 5,
"selected": true,
"text": ".dll.refresh .xml .pdb .dll .refresh"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24482/"
] |
162,225
|
<p>I've got an XML document containing news stories, and the body element of a news story contains p tags amongst the plain text. When I use XSL to retrieve the body, e.g.</p>
<pre><code><xsl:value-of select="body" />
</code></pre>
<p>the p tags seem to get stripped out. I'm using Visual Studio 2005's implementation of XSL.</p>
<p>Does anyone have any ideas how to avoid this? Thanks.</p>
|
[
{
"answer_id": 162250,
"author": "Enrico Murru",
"author_id": 68336,
"author_profile": "https://Stackoverflow.com/users/68336",
"pm_score": -1,
"selected": false,
"text": "<xsl:value-of select=\"body\" disable-output-escaping=\"yes\"/>\n"
},
{
"answer_id": 162259,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 6,
"selected": true,
"text": "<xsl:copy-of select=\"body\"/>\n <xsl:copy-of>"
},
{
"answer_id": 162274,
"author": "Eugene Katz",
"author_id": 1533,
"author_profile": "https://Stackoverflow.com/users/1533",
"pm_score": 3,
"selected": false,
"text": "<xsl:template match=\"title\">\n <xsl:copy-of select=\"*\"/>\n</xsl:template>\n"
},
{
"answer_id": 164160,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 1,
"selected": false,
"text": "value-of copy-of"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12277/"
] |
162,255
|
<p>What's the best way, using SQL, to check the maximum number of connections that is allowed for an Oracle database? In the end, I would like to show the current number of sessions and the total number allowed, e.g. "Currently, 23 out of 80 connections are used".</p>
|
[
{
"answer_id": 162374,
"author": "JosephStyons",
"author_id": 672,
"author_profile": "https://Stackoverflow.com/users/672",
"pm_score": 5,
"selected": false,
"text": "SELECT\n 'Currently, ' \n || (SELECT COUNT(*) FROM V$SESSION)\n || ' out of ' \n || DECODE(VL.SESSIONS_MAX,0,'unlimited',VL.SESSIONS_MAX) \n || ' connections are used.' AS USAGE_MESSAGE\nFROM \n V$LICENSE VL\n SELECT\n 'Currently, ' \n || (SELECT COUNT(*) FROM V$SESSION)\n || ' out of ' \n || VP.VALUE \n || ' connections are used.' AS USAGE_MESSAGE\nFROM \n V$PARAMETER VP\nWHERE VP.NAME = 'sessions'\n"
},
{
"answer_id": 162381,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 8,
"selected": true,
"text": "SELECT name, value \n FROM v$parameter\n WHERE name = 'sessions'\n SELECT COUNT(*)\n FROM v$session\n"
},
{
"answer_id": 2977596,
"author": "saris mohammad",
"author_id": 358837,
"author_profile": "https://Stackoverflow.com/users/358837",
"pm_score": 1,
"selected": false,
"text": "select count(*),sum(decode(status, 'ACTIVE',1,0)) from v$session where type= 'USER'\n"
},
{
"answer_id": 24239149,
"author": "botkop",
"author_id": 478746,
"author_profile": "https://Stackoverflow.com/users/478746",
"pm_score": 3,
"selected": false,
"text": "SQL> show parameter sessions\n NAME TYPE VALUE\n------------------------------------ ----------- ------------------------------\njava_max_sessionspace_size integer 0\njava_soft_sessionspace_limit integer 0\nlicense_max_sessions integer 0\nlicense_sessions_warning integer 0\nsessions integer 248\nshared_server_sessions integer\n"
},
{
"answer_id": 26061422,
"author": "FuePi",
"author_id": 139378,
"author_profile": "https://Stackoverflow.com/users/139378",
"pm_score": 5,
"selected": false,
"text": " select current_utilization, limit_value \n from v$resource_limit \n where resource_name='sessions';\n select resource_name, current_utilization, max_utilization, limit_value \n from v$resource_limit \n where resource_name in ('sessions', 'processes');\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24495/"
] |
162,276
|
<p>I am wanting to use the Facebox plugin for JQuery but am having a few issues getting it running how I want. The div that houses the facebox content is created outside of the tag so even though I am loading up some web controls none of them are firing back to the server.</p>
<p>Has anyone dealt with this that can give me some pointers?</p>
|
[
{
"answer_id": 162317,
"author": "Kevin Sheffield",
"author_id": 590,
"author_profile": "https://Stackoverflow.com/users/590",
"pm_score": 3,
"selected": true,
"text": "$('body').append($.facebox.settings.faceboxHtml)\n $('#aspnetForm').append($.facebox.settings.faceboxHtml)\n"
},
{
"answer_id": 395627,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "btn.OnClientClick = string.Format(\"{0}; $.facebox.close();\",ClientScript.GetPostBackEventReference(btn, null));\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/590/"
] |
162,291
|
<p>How can I check if an application is running from a batch (well cmd) file?</p>
<p>I need to not launch another instance if a program is already running. (I can't change the app to make it single instance only.)</p>
<p>Also the application could be running as any user.</p>
|
[
{
"answer_id": 162302,
"author": "prakash",
"author_id": 123,
"author_profile": "https://Stackoverflow.com/users/123",
"pm_score": -1,
"selected": false,
"text": "c:\\windows\\notepad.exe"
},
{
"answer_id": 162361,
"author": "Matt Lacey",
"author_id": 1755,
"author_profile": "https://Stackoverflow.com/users/1755",
"pm_score": 6,
"selected": false,
"text": "tasklist /FI \"IMAGENAME eq notepad.exe\" /FO CSV > search.log\n\nFOR /F %%A IN (search.log) DO IF %%~zA EQU 0 GOTO end\n\nstart notepad.exe\n\n:end\n\ndel search.log\n"
},
{
"answer_id": 162364,
"author": "Motti",
"author_id": 3848,
"author_profile": "https://Stackoverflow.com/users/3848",
"pm_score": 2,
"selected": false,
"text": "tasklist /FI \"IMAGENAME eq myApp.exe\" | grep myApp.exe\nif ERRORLEVEL 1 echo \"myApp is not running\"\n"
},
{
"answer_id": 334954,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "@echo off\nPATH=%PATH%;%PROGRAMFILES%\\PV;%PROGRAMFILES%\\YourProgram\nPV.EXE YourProgram.exe >nul\nif ERRORLEVEL 1 goto Process_NotFound\n:Process_Found\necho YourProgram is running\ngoto END\n:Process_NotFound\necho YourProgram is not running\nYourProgram.exe\ngoto END\n:END\n"
},
{
"answer_id": 1329790,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 9,
"selected": false,
"text": "tasklist /fi \"ImageName eq MyApp.exe\" /fo csv 2>NUL | find /I \"myapp.exe\">NUL\nif \"%ERRORLEVEL%\"==\"0\" echo Program is running\n /fi \"\" /fo csv find find /I"
},
{
"answer_id": 3103301,
"author": "Nin",
"author_id": 374408,
"author_profile": "https://Stackoverflow.com/users/374408",
"pm_score": 0,
"selected": false,
"text": "search.log cd cd search.log search.log del search.log\n\ntasklist /FI \"IMAGENAME eq myprog.exe\" /FO CSV > search.log\n\nFOR /F %%A IN (search.log) DO IF %%-zA EQU 0 GOTO end\n\ncd \"C:\\Program Files\\MyLoc\\bin\"\n\nmyprog.exe myuser mypwd\n\n:end\n"
},
{
"answer_id": 4783062,
"author": "vtrz",
"author_id": 477371,
"author_profile": "https://Stackoverflow.com/users/477371",
"pm_score": 4,
"selected": false,
"text": "wmic process where (name=\"nmake.exe\") get commandline | findstr /i /c:\"/f load.mak\" /c:\"/f build.mak\" > NUL && (echo THE BUILD HAS BEEN STARTED ALREADY! > %ALREADY_STARTED% & exit /b 1)"
},
{
"answer_id": 7007630,
"author": "benmod",
"author_id": 531709,
"author_profile": "https://Stackoverflow.com/users/531709",
"pm_score": 3,
"selected": false,
"text": " tasklist /FI \"IMAGENAME eq notepad.exe\" /FO CSV > search.log\n search.log tasklist /FI \"IMAGENAME eq notepad.exe\" /FO CSV > search.log\n\nFINDSTR notepad.exe search.log > found.log\n\nFOR /F %%A IN (found.log) DO IF %%~zA EQU 0 GOTO end\n\nstart notepad.exe\n\n:end\n\ndel search.log\ndel found.log\n"
},
{
"answer_id": 18873920,
"author": "Calimo",
"author_id": 333599,
"author_profile": "https://Stackoverflow.com/users/333599",
"pm_score": 0,
"selected": false,
"text": "%EXEC_CMD% @echo off\nset EXEC_CMD=\"rsync.exe\"\nwmic process where (name=%EXEC_CMD%) get commandline | findstr /i %EXEC_CMD%> NUL\nif errorlevel 1 (\n %EXEC_CMD% ...\n) else (\n @echo not starting %EXEC_CMD%: already running.\n)\n"
},
{
"answer_id": 25041951,
"author": "npocmaka",
"author_id": 388389,
"author_profile": "https://Stackoverflow.com/users/388389",
"pm_score": 3,
"selected": false,
"text": "WMIC TASKLIST QPROCESS @echo off\n:check_process\nsetlocal\nif \"%~1\" equ \"\" echo pass the process name as forst argument && exit /b 1\n:: first argument is the process you want to check if running\nset process_to_check=%~1\n:: QPROCESS can display only the first 12 symbols of the running process\n:: If other tool is used the line bellow could be deleted\nset process_to_check=%process_to_check:~0,12%\n\nQPROCESS * | find /i \"%process_to_check%\" >nul 2>&1 && (\n echo process %process_to_check% is running\n) || (\n echo process %process_to_check% is not running\n)\nendlocal\n QPROCESS TASKLIST TASKLIST .exe @echo off\n:check_process\nsetlocal\nif \"%~1\" equ \"\" echo pass the process name as forst argument && exit /b 1\n:: first argument is the process you want to check if running\n:: .exe suffix is mandatory\nset \"process_to_check=%~1\"\n\n\nQPROCESS \"%process_to_check%\" >nul 2>&1 && (\n echo process %process_to_check% is running\n) || (\n echo process %process_to_check% is not running\n)\nendlocal\n QPROCESS QPROCESS * QPROCESS some.exe WMI WMIC QPROCESS .bat @if (@X)==(@Y) @end /* JSCRIPT COMMENT **\n\n\n@echo off\ncscript //E:JScript //nologo \"%~f0\"\nexit /b\n\n************** end of JSCRIPT COMMENT **/\n\n\nvar winmgmts = GetObject(\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\");\nvar colProcess = winmgmts.ExecQuery(\"Select * from Win32_Process\");\nvar processes = new Enumerator(colProcess);\nfor (;!processes.atEnd();processes.moveNext()) {\n var process=processes.item();\n WScript.Echo( process.processID + \" \" + process.Name );\n}\n @if (@X)==(@Y) @end /* JSCRIPT COMMENT **\n\n\n@echo off\nif \"%~1\" equ \"\" echo pass the process name as forst argument && exit /b 1\n:: first argument is the process you want to check if running\nset process_to_check=%~1\n\ncscript //E:JScript //nologo \"%~f0\" | find /i \"%process_to_check%\" >nul 2>&1 && (\n echo process %process_to_check% is running\n) || (\n echo process %process_to_check% is not running\n)\n\nexit /b\n\n************** end of JSCRIPT COMMENT **/\n\n\nvar winmgmts = GetObject(\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\");\nvar colProcess = winmgmts.ExecQuery(\"Select * from Win32_Process\");\nvar processes = new Enumerator(colProcess);\nfor (;!processes.atEnd();processes.moveNext()) {\n var process=processes.item();\n WScript.Echo( process.processID + \" \" + process.Name );\n}\n TASKLIST MSHTA MSHTA @if (@X)==(@Y) @end /* JSCRIPT COMMENT **\n@echo off\n\nsetlocal\nif \"%~1\" equ \"\" echo pass the process name as forst argument && exit /b 1\n:: first argument is the process you want to check if running\n\nset process_to_check=%~1\n\n\nmshta \"about:<script language='javascript' src='file://%~dpnxf0'></script>\" | find /i \"%process_to_check%\" >nul 2>&1 && (\n echo process %process_to_check% is running\n) || (\n echo process %process_to_check% is not running\n)\nendlocal\nexit /b\n************** end of JSCRIPT COMMENT **/\n\n\n var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);\n\n\n var winmgmts = GetObject(\"winmgmts:\\\\\\\\.\\\\root\\\\cimv2\");\n var colProcess = winmgmts.ExecQuery(\"Select * from Win32_Process\");\n var processes = new Enumerator(colProcess);\n for (;!processes.atEnd();processes.moveNext()) {\n var process=processes.item();\n fso.Write( process.processID + \" \" + process.Name + \"\\n\");\n }\n close();\n"
},
{
"answer_id": 25423791,
"author": "TrueY",
"author_id": 2156952,
"author_profile": "https://Stackoverflow.com/users/2156952",
"pm_score": 6,
"selected": false,
"text": "SETLOCAL EnableExtensions\nset EXE=MyProg.exe\nFOR /F %%x IN ('tasklist /NH /FI \"IMAGENAME eq %EXE%\"') DO IF NOT %%x == %EXE% (\n echo %EXE% is Not Running\n)\n SETLOCAL EnableExtensions\nset EXE=My Prog.exe\nFOR /F %%x IN (\"%EXE%\") do set EXE_=%%x\nFOR /F %%x IN ('tasklist /NH /FI \"IMAGENAME eq %EXE%\"') DO IF NOT %%x == %EXE_% (\n echo %EXE% is Not Running\n)\n SETLOCAL EnableExtensions\nSET EXE=MyProg.exe\nREM for testing\nREM SET EXE=svchost.exe\nFOR /F %%x IN ('tasklist /NH /FI \"IMAGENAME eq %EXE%\"') DO IF NOT %%x == %EXE% (\n ECHO %EXE% is Not Running\n REM This GOTO may be not necessary\n GOTO notRunning\n) ELSE (\n ECHO %EXE is running\n GOTO Running\n)\n...\n:Running\nREM If Running label not exists, it will loop over all found tasks\n"
},
{
"answer_id": 26024028,
"author": "kayleeFrye_onDeck",
"author_id": 3543437,
"author_profile": "https://Stackoverflow.com/users/3543437",
"pm_score": 3,
"selected": false,
"text": "::Change the name of notepad.exe to the process .exe that you're trying to track\n::Process names are CASE SENSITIVE, so notepad.exe works but Notepad.exe does NOT\n::Do not change IMAGENAME\n::You can Copy and Paste this into an empty batch file and change the name of\n::notepad.exe to the process you'd like to track\n::Also, some large programs take a while to no longer show as not running, so\n::give this batch a few seconds timer to avoid a false result!!\n\n@echo off\nSETLOCAL EnableExtensions\n\nset EXE=notepad.exe\n\nFOR /F %%x IN ('tasklist /NH /FI \"IMAGENAME eq %EXE%\"') DO IF %%x == %EXE% goto ProcessFound\n\ngoto ProcessNotFound\n\n:ProcessFound\n\necho %EXE% is running\ngoto END\n:ProcessNotFound\necho %EXE% is not running\ngoto END\n:END\necho Finished!\n"
},
{
"answer_id": 41684126,
"author": "Riccardo La Marca",
"author_id": 7028122,
"author_profile": "https://Stackoverflow.com/users/7028122",
"pm_score": 5,
"selected": false,
"text": "TASKLIST | FINDSTR ProgramName || START \"\" \"Path\\ProgramName.exe\"\n"
},
{
"answer_id": 42947089,
"author": "Rajeev Jayaswal",
"author_id": 2155858,
"author_profile": "https://Stackoverflow.com/users/2155858",
"pm_score": -1,
"selected": false,
"text": "tasklist | grep program\n"
},
{
"answer_id": 43922550,
"author": "aldemarcalazans",
"author_id": 4941815,
"author_profile": "https://Stackoverflow.com/users/4941815",
"pm_score": 5,
"selected": false,
"text": "QPROCESS \"myprocess.exe\">NUL\nIF %ERRORLEVEL% EQU 0 ECHO \"Process running\"\n"
},
{
"answer_id": 50299150,
"author": "drzaus",
"author_id": 1037948,
"author_profile": "https://Stackoverflow.com/users/1037948",
"pm_score": 2,
"selected": false,
"text": "tasklist :: in case your task name is really long, check for the 'opposite' and find the message when it's not there\ntasklist /fi \"imagename eq yourreallylongtasknamethatwontfitinthelist.exe\" 2>NUL | find /I /N \"no tasks are running\">NUL\nif \"%errorlevel%\"==\"0\" (\n echo Task Found\n) else (\n echo Not Found Task\n)\n"
},
{
"answer_id": 61414882,
"author": "Patrick",
"author_id": 10582249,
"author_profile": "https://Stackoverflow.com/users/10582249",
"pm_score": 1,
"selected": false,
"text": " :: Set programm you want to kill\n :: Fileextension is mandatory\n SET KillProg=explorer.exe\n\n :: Set waiting time between 2 requests in seconds\n SET /A \"_wait=3\"\n\n :ProcessNotFound\n tasklist /NH /FI \"IMAGENAME eq %KillProg%\" | FIND /I \"%KillProg%\"\n IF \"%ERRORLEVEL%\"==\"0\" (\n TASKKILL.EXE /F /T /IM %KillProg%\n ) ELSE (\n timeout /t %_wait%\n GOTO :ProcessNotFound\n )\n taskkill.bat :: Get program name from argumentlist\n IF NOT \"%~1\"==\"\" (\n SET \"KillProg=%~1\"\n ) ELSE (\n ECHO Usage: \"%~nx0\" ProgramToKill.exe & EXIT /B\n )\n\n :: Set waiting time between 2 requests in seconds\n SET /A \"_wait=3\"\n\n :ProcessNotFound\n tasklist /NH /FI \"IMAGENAME eq %KillProg%\" | FIND /I \"%KillProg%\"\n IF \"%ERRORLEVEL%\"==\"0\" (\n TASKKILL.EXE /F /T /IM %KillProg%\n ) ELSE (\n timeout /t %_wait%\n GOTO :ProcessNotFound\n )\n .\\taskkill.bat ProgramToKill.exe"
},
{
"answer_id": 67500084,
"author": "arnold_w",
"author_id": 2075678,
"author_profile": "https://Stackoverflow.com/users/2075678",
"pm_score": 2,
"selected": false,
"text": "@echo off\n\nset \"workdir=C:\\MyProject\\bin\\release\"\nset \"workdir=%workdir:\\=\\\\%\"\n\nsetlocal enableDelayedExpansion\nfor /f \"usebackq tokens=* delims=\" %%a in (`\n wmic process where 'CommandLine like \"%%!workdir!%%\" and not CommandLine like \"%%RuntimeBroker%%\"' get CommandLine^,ProcessId /format:value\n`) do (\n for /f \"tokens=* delims=\" %%G in (\"%%a\") do (\n if \"%%G\" neq \"\" (\nrem echo %%G\n set \"%%G\"\nrem echo !ProcessId!\n goto :TheApplicationIsRunning\n )\n )\n) \n\necho The application is not running\nexit /B\n\n:TheApplicationIsRunning\necho The application is running\nexit /B\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162291",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1755/"
] |
162,298
|
<p>I have a basic ActiveRecord model in which i have two fields that i would like to validate. The requirement is that at least one of the fields must have a value. Both can have values, but at least one needs a value.</p>
<p>How do i express this with </p>
<pre><code>validates_presence_of
</code></pre>
<p>statements? For example:</p>
<pre><code>validates_presence_of :main_file
validates_presence_of :alt_file
</code></pre>
<p>i don't want an error to be generated if only one of them is empty, only if both are empty. </p>
|
[
{
"answer_id": 162334,
"author": "Bartosz Blimke",
"author_id": 18715,
"author_profile": "https://Stackoverflow.com/users/18715",
"pm_score": 4,
"selected": true,
"text": "validates_presence_of :main_file, :if => Proc.new { |p| p.alt_file.blank? }\nvalidates_presence_of :alt_file, :if => Proc.new { |p| p.main_file.blank? }\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18811/"
] |
162,303
|
<p>How can I convert a Char[] (of any length) to a List ?</p>
|
[
{
"answer_id": 162556,
"author": "TK.",
"author_id": 1816,
"author_profile": "https://Stackoverflow.com/users/1816",
"pm_score": 3,
"selected": false,
"text": "byte[] arr = new System.Text.UTF8Encoding( true ).GetBytes( str );\nList<byte> byteList = new List<byte>( arr );\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1816/"
] |
162,304
|
<p>I've been using <a href="https://en.wikipedia.org/wiki/Remote_Desktop_Services#Remote_Desktop_Connection" rel="noreferrer">Remote Desktop Connection</a> to get into a workstation. But in this environment, I cannot use the power options in Start Menu. I need an alternative way to shutdown or restart.</p>
<p>How do I control my computer's power state through the command line?</p>
|
[
{
"answer_id": 162305,
"author": "Keng",
"author_id": 730,
"author_profile": "https://Stackoverflow.com/users/730",
"pm_score": 11,
"selected": true,
"text": "shutdown shutdown -s shutdown -r shutdown -l shutdown -h -h shutdown.exe shutdown -h shutdown -i shutdown -a -f -t <seconds> -t 0 -c <message> -y -f rundll32"
},
{
"answer_id": 162342,
"author": "JosephStyons",
"author_id": 672,
"author_profile": "https://Stackoverflow.com/users/672",
"pm_score": 9,
"selected": false,
"text": "shutdown -t 0 -r -f\n shutdown -t 30 -r\n"
},
{
"answer_id": 162398,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 5,
"selected": false,
"text": "rundll32.exe shell32.dll rundll32.exe user.exe,**ExitWindows** rundll32.exe user.exe,**ExitWindowsExec** rundll32.exe shell32.dll,SHExitWindowsEx n\n n LOGOFF SHUTDOWN REBOOT FORCE POWEROFF FORCE REBOOT rundll32.exe ExitWindows rundll32.exe void CALLBACK ExitWindowsEx(HWND hwnd, HINSTANCE hinst,\n LPSTR pszCmdLine, int nCmdShow);\n rundll32 rundll32 user32 LockWorkStation user32 ExitWindowsEx BOOL WINAPI ExitWindowsEx(UINT uFlags, DWORD dwReserved);\n Rundll32"
},
{
"answer_id": 162428,
"author": "Dean Rather",
"author_id": 14966,
"author_profile": "https://Stackoverflow.com/users/14966",
"pm_score": 3,
"selected": false,
"text": "shutdown -r"
},
{
"answer_id": 416830,
"author": "Kip",
"author_id": 18511,
"author_profile": "https://Stackoverflow.com/users/18511",
"pm_score": 6,
"selected": false,
"text": "-m shutdown -r -f -m \\\\machinename\n -r -f"
},
{
"answer_id": 2426896,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "@echo off\nshutdown -l\n"
},
{
"answer_id": 6301608,
"author": "Gavin",
"author_id": 78216,
"author_profile": "https://Stackoverflow.com/users/78216",
"pm_score": 4,
"selected": false,
"text": "@echo off\necho Shutting down in 10 seconds. Please type \"shutdown /a\" to abort.\ncmd.exe /K shutdown /f /t 10 /r\n"
},
{
"answer_id": 64703616,
"author": "npocmaka",
"author_id": 388389,
"author_profile": "https://Stackoverflow.com/users/388389",
"pm_score": 2,
"selected": false,
"text": "rundll32.exe shell32.dll,SHExitWindowsEx n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/730/"
] |
162,309
|
<p>To pop up the UAC dialog in Vista when writing to the HKLM registry hive, we opt to not use the Win32 Registry API, as when Vista permissions are lacking, we'd need to relaunch our entire application with administrator rights. Instead, we do this trick:</p>
<pre><code>ShellExecute(hWnd, "runas" /* display UAC prompt on Vista */, windir + "\\Reg", "add HKLM\\Software\\Company\\KeyName /v valueName /t REG_MULTI_TZ /d ValueData", NULL, SW_HIDE);
</code></pre>
<p>This solution works fine, besides that our application is a 32-bit one, and it runs the REG.EXE command as it would be a 32-bit app using the WOW compatibility layer! :( If REG.EXE is ran from the command line, it's properly ran in 64-bit mode. This matters, because if it's ran as a 32-bit app, the registry keys will end up in the wrong place due to <a href="http://msdn.microsoft.com/en-us/library/aa384235(VS.85).aspx" rel="noreferrer">registry reflection</a>.</p>
<p>So is there any way to launch a 64-bit app programmatically from a 32-bit app and not have it run using the WOW64 subsystem like its parent 32-bit process (i.e. a "*" suffix in the Task Manager)?</p>
|
[
{
"answer_id": 162360,
"author": "Mike Dimmick",
"author_id": 6970,
"author_profile": "https://Stackoverflow.com/users/6970",
"pm_score": 3,
"selected": false,
"text": "reg.exe PATH"
},
{
"answer_id": 2801958,
"author": "akira",
"author_id": 98653,
"author_profile": "https://Stackoverflow.com/users/98653",
"pm_score": 5,
"selected": true,
"text": "> %WINDIR%\\sysnative\\reg.exe query ...\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162309",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9744/"
] |
162,325
|
<p>This has been an adventure. I started with the looping duplicate query located in <a href="https://stackoverflow.com/questions/161960">my previous question</a>, but each loop would go over all <strong>17 million records</strong>, <strong>meaning it would take weeks</strong> (just running <code>*select count * from MyTable*</code> takes my server 4:30 minutes using MSSQL 2005). I gleamed information from this site and at this <a href="http://weblogs.sqlteam.com/jeffs/archive/2007/03/28/60146.aspx" rel="nofollow noreferrer">post</a>.</p>
<p>And have arrived at the query below. The question is, is this the correct type of query to run on 17 million records for any type of performance? If it isn't, what is?</p>
<p>SQL QUERY:</p>
<pre><code>DELETE tl_acxiomimport.dbo.tblacxiomlistings
WHERE RecordID in
(SELECT RecordID
FROM tl_acxiomimport.dbo.tblacxiomlistings
EXCEPT
SELECT RecordID
FROM (
SELECT RecordID, Rank() over (Partition BY BusinessName, latitude, longitude, Phone ORDER BY webaddress DESC, caption1 DESC, caption2 DESC ) AS Rank
FROM tl_acxiomimport.dbo.tblacxiomlistings
) al WHERE Rank = 1)
</code></pre>
|
[
{
"answer_id": 162378,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 1,
"selected": false,
"text": "SET SHOWPLAN_TEXT ON\n"
},
{
"answer_id": 162479,
"author": "TrevorD",
"author_id": 12492,
"author_profile": "https://Stackoverflow.com/users/12492",
"pm_score": 1,
"selected": false,
"text": "set rowcount 1000\n"
},
{
"answer_id": 162660,
"author": "Bob Probst",
"author_id": 12424,
"author_profile": "https://Stackoverflow.com/users/12424",
"pm_score": 4,
"selected": true,
"text": "SELECT m.*\ninto #temp\nFROM tl_acxiomimport.dbo.tblacxiomlistings m \ninner join (SELECT RecordID, \n Rank() over (Partition BY BusinessName, \n latitude, \n longitude, \n Phone \n ORDER BY webaddress DESC, \n caption1 DESC, \n caption2 DESC ) AS Rank\n FROM tl_acxiomimport.dbo.tblacxiomlistings\n ) al on (al.RecordID = m.RecordID and al.Rank = 1)\n\ntruncate table tl_acxiomimport.dbo.tblacxiomlistings\n\ninsert into tl_acxiomimport.dbo.tblacxiomlistings\n select * from #temp\n"
},
{
"answer_id": 162857,
"author": "kristof",
"author_id": 3241,
"author_profile": "https://Stackoverflow.com/users/3241",
"pm_score": 1,
"selected": false,
"text": "DELETE tl_acxiomimport.dbo.tblacxiomlistings\nFROM\n tl_acxiomimport.dbo.tblacxiomlistings allRecords\n LEFT JOIN ( \n SELECT RecordID, Rank() over (Partition BY BusinessName, latitude, longitude, Phone ORDER BY webaddress DESC, caption1 DESC, caption2 DESC ) AS Rank\n FROM tl_acxiomimport.dbo.tblacxiomlistings\n WHERE Rank = 1) myExceptions\n ON allRecords.RecordID = myExceptions.RecordID\nWHERE\n myExceptions.RecordID IS NULL\n SELECT * SELECT COUNT(*) SELECT *\nFROM\n tl_acxiomimport.dbo.tblacxiomlistings allRecords\n LEFT JOIN ( \n SELECT RecordID, Rank() over (Partition BY BusinessName, latitude, longitude, Phone ORDER BY webaddress DESC, caption1 DESC, caption2 DESC ) AS Rank\n FROM tl_acxiomimport.dbo.tblacxiomlistings\n WHERE Rank = 1) myExceptions\n ON allRecords.RecordID = myExceptions.RecordID\nWHERE\n myExceptions.RecordID IS NULL\n"
},
{
"answer_id": 163274,
"author": "David Aldridge",
"author_id": 6742,
"author_profile": "https://Stackoverflow.com/users/6742",
"pm_score": 2,
"selected": false,
"text": "DELETE tl_acxiomimport.dbo.tblacxiomlistings\nWHERE RecordID in \n(SELECT RecordID\n FROM (\n SELECT RecordID,\n Rank() over (Partition BY BusinessName,\n latitude,\n longitude,\n Phone\n ORDER BY webaddress DESC,\n caption1 DESC,\n caption2 DESC) AS Rank\n FROM tl_acxiomimport.dbo.tblacxiomlistings\n )\n WHERE Rank > 1\n )\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162325",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7952/"
] |
162,326
|
<p>How to get the checked option in a group of radio inputs with JavaScript?</p>
|
[
{
"answer_id": 162408,
"author": "leoinfo",
"author_id": 6948,
"author_profile": "https://Stackoverflow.com/users/6948",
"pm_score": 4,
"selected": true,
"text": "<html>\n <head>\n <script type=\"text/javascript\">\n function testR(){\n var x = document.getElementsByName('r')\n for(var k=0;k<x.length;k++)\n if(x[k].checked){\n alert('Option selected: ' + x[k].value)\n }\n\n }\n </script>\n </head>\n <body>\n <form>\n <input type=\"radio\" id=\"r1\" name=\"r\" value=\"1\">Yes</input>\n <input type=\"radio\" id=\"r2\" name=\"r\" value=\"2\">No</input>\n <input type=\"radio\" id=\"r3\" name=\"r\" value=\"3\">Don't Know</input>\n <br/>\n <input type=\"button\" name=\"check\" value=\"Test\" onclick=\"testR()\"/>\n </form>\n </body>\n</html>\n"
},
{
"answer_id": 162429,
"author": "Wayne",
"author_id": 8236,
"author_profile": "https://Stackoverflow.com/users/8236",
"pm_score": 2,
"selected": false,
"text": "function findSelected(){\n for (i=0;i<document.formname.radioname.length;i++){\n if (document.formname.radioname[i].checked){\n return document.formname.radioname[i];\n }\n }\n}\n"
},
{
"answer_id": 591978,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "function getRadioGroupSelectedElement(radioGroupName) {\n\n var radioGroup = document.getElementsByName(radioGroupName);\n var radioElement = radioGroup.length - 1;\n for(radioElement; radioElement >= 0; radioElement--) {\n if(radioGroup[radioElement].checked){\n return radioGroup[radioElement];\n }\n }\n return false;\n}\n\n\n\nfunction getRadioGroupSelectedValue(radioGroupName) {\n\n var selectedRadio = getRadioGroupSelectedElement(radioGroupName);\n if (selectedRadio !== false) {\n return selectedRadio.value;\n }\n return false;\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1100/"
] |
162,331
|
<p>I'm developing an application targeting .NET Framework 2.0 using C# for which I need to be able to find the default application that is used for opening a particular file type.</p>
<p>I know that, for example, if you just want to open a file using that application you can use something like:</p>
<pre><code>System.Diagnostics.Process.Start( "C:\...\...\myfile.html" );
</code></pre>
<p>to open an HTML document in the default browser, or</p>
<pre><code>System.Diagnostics.Process.Start( "C:\...\...\myfile.txt" );
</code></pre>
<p>to open a text file in the default text editor.</p>
<p>However, what I want to be able to do is to open files that don't necessarily have a <em>.txt</em> extension (for example), in the default text editor, so I need to be able to find out the default application for opening <em>.txt</em> files, which will allow me to invoke it directly.</p>
<p>I'm guessing there's some Win32 API that I'll need to P/Invoke in order to do this, however a quick look with both Google and MSDN didn't reveal anything of much interest; I did find a very large number of completely irrelevant pages, but nothing like I'm looking for. </p>
|
[
{
"answer_id": 162351,
"author": "curtisk",
"author_id": 17651,
"author_profile": "https://Stackoverflow.com/users/17651",
"pm_score": 5,
"selected": true,
"text": "HKEY_CLASSES_ROOT"
},
{
"answer_id": 162371,
"author": "Bart Read",
"author_id": 17786,
"author_profile": "https://Stackoverflow.com/users/17786",
"pm_score": 3,
"selected": false,
"text": "HKEY_CLASSES_ROOT\\.txt\n HKEY_CLASSES_ROOT\\txtfile\n HKEY_CLASSES_ROOT\\txtfile\\shell\\open\\command\n"
},
{
"answer_id": 17773402,
"author": "Ohad Schneider",
"author_id": 67824,
"author_profile": "https://Stackoverflow.com/users/67824",
"pm_score": 6,
"selected": false,
"text": "using System.Runtime.InteropServices;\n\n[DllImport(\"Shlwapi.dll\", CharSet = CharSet.Unicode)]\npublic static extern uint AssocQueryString(\n AssocF flags, \n AssocStr str, \n string pszAssoc, \n string pszExtra, \n [Out] StringBuilder pszOut, \n ref uint pcchOut\n); \n\n[Flags]\npublic enum AssocF\n{\n None = 0,\n Init_NoRemapCLSID = 0x1,\n Init_ByExeName = 0x2,\n Open_ByExeName = 0x2,\n Init_DefaultToStar = 0x4,\n Init_DefaultToFolder = 0x8,\n NoUserSettings = 0x10,\n NoTruncate = 0x20,\n Verify = 0x40,\n RemapRunDll = 0x80,\n NoFixUps = 0x100,\n IgnoreBaseClass = 0x200,\n Init_IgnoreUnknown = 0x400,\n Init_Fixed_ProgId = 0x800,\n Is_Protocol = 0x1000,\n Init_For_File = 0x2000\n}\n\npublic enum AssocStr\n{\n Command = 1,\n Executable,\n FriendlyDocName,\n FriendlyAppName,\n NoOpen,\n ShellNewValue,\n DDECommand,\n DDEIfExec,\n DDEApplication,\n DDETopic,\n InfoTip,\n QuickTip,\n TileInfo,\n ContentType,\n DefaultIcon,\n ShellExtension,\n DropTarget,\n DelegateExecute,\n Supported_Uri_Protocols,\n ProgID,\n AppID,\n AppPublisher,\n AppIconReference,\n Max\n}\n static string AssocQueryString(AssocStr association, string extension)\n{\n const int S_OK = 0;\n const int S_FALSE = 1;\n\n uint length = 0;\n uint ret = AssocQueryString(AssocF.None, association, extension, null, null, ref length);\n if (ret != S_FALSE)\n {\n throw new InvalidOperationException(\"Could not determine associated string\");\n }\n\n var sb = new StringBuilder((int)length); // (length-1) will probably work too as the marshaller adds null termination\n ret = AssocQueryString(AssocF.None, association, extension, null, sb, ref length);\n if (ret != S_OK)\n {\n throw new InvalidOperationException(\"Could not determine associated string\"); \n }\n\n return sb.ToString();\n}\n"
},
{
"answer_id": 33167069,
"author": "Harald Coppoolse",
"author_id": 2281790,
"author_profile": "https://Stackoverflow.com/users/2281790",
"pm_score": 2,
"selected": false,
"text": "private void OnMenuSourceFileOpening(object sender, ...)\n{ // open a context menu with the associated files + \".txt\" files\n if (File.Exists(this.SelectedFileName))\n {\n string fileExt = Path.GetExtension(this.SelectedFileNames);\n string[] allowedExtensions = new string[] { fileExt, \".txt\" };\n var fileAssociations = allowedExtensions\n .Select(ext => new FileAssociationInfo(ext));\n var progInfos = fileAssociations\n .Select(fileAssoc => new ProgramAssociationInfo (fileAssoc.ProgID));\n var toolstripItems = myProgInfos\n .Select(proginfo => new ToolStripLabel (proginfo.Description) { Tag = proginfo });\n // add also the prog info as Tag, for easy access\n // when the toolstrip item is selected\n // of course this can also be done in one long linq statement\n\n // fill the context menu:\n this.contextMenu1.Items.Clear();\n this.contextMenuOpenSourceFile.Items.AddRange (toolstripItems.ToArray());\n }\n}\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17786/"
] |
162,335
|
<p>I was browsing Scott Hanselman's <a href="http://www.hanselman.com/blog/WhatGreatNETDevelopersOughtToKnowMoreNETInterviewQuestions.aspx" rel="noreferrer">Developer Interview question list</a>, and ran across this question:</p>
<blockquote>
<p>What is wrong with
DateTime.Parse(myString)?</p>
</blockquote>
<p>While I know there are inherent risks in parsing a string of unknow format or origin, are there other reasons? Is it to use DateTime.ParseExact instead? Should it be myString.ToString() first?</p>
|
[
{
"answer_id": 162348,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 6,
"selected": true,
"text": "DateTime.Parse() DateTime.TryParse() DateTime.TryParseExact()"
},
{
"answer_id": 162363,
"author": "John Rudy",
"author_id": 14048,
"author_profile": "https://Stackoverflow.com/users/14048",
"pm_score": 1,
"selected": false,
"text": "myString"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5619/"
] |
162,338
|
<p>Can I, using an address found in a map file, use windbg to alter a variable in memory while the app is running?</p>
<p>I'm really interested in turning on/off functionality in run-time maybe with a variable.</p>
<p>How would you do this? Does it require breaking the app through the debugger?</p>
|
[
{
"answer_id": 9576175,
"author": "EdChum",
"author_id": 704848,
"author_profile": "https://Stackoverflow.com/users/704848",
"pm_score": 1,
"selected": false,
"text": "bp /1 012ABCDEF \"myVar=42;g\"\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8123/"
] |
162,399
|
<p>Hi why doesn't this work in SQL Server 2005?</p>
<pre><code>select HALID, count(HALID) as CH from Outages.FaultsInOutages
where CH > 3
group by HALID
</code></pre>
<p>I get invalid column name 'CH'</p>
<hr>
<p>i think having was the right way to go but still receive the error:
Invalid column name 'CH'.</p>
<p>When running:</p>
<p>select HALID, count(HALID) as CH from Outages.FaultsInOutages
group by HALID having CH > 3</p>
|
[
{
"answer_id": 162406,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 2,
"selected": false,
"text": "select HALID, count(HALID) from Outages.FaultsInOutages \ngroup by HALID having count(HALID) > 3\n"
},
{
"answer_id": 162420,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 5,
"selected": true,
"text": "SELECT HALID, COUNT(HALID) AS CH\nFROM Outages.FaultsInOutages\nGROUP BY HALID\nHAVING COUNT(HALID) > 3\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21004/"
] |
162,409
|
<p>Can someone explain what are the benefits of using the @import syntax comparing to just including css using the standard link method?</p>
|
[
{
"answer_id": 162437,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 3,
"selected": false,
"text": "<link> @import"
},
{
"answer_id": 162449,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 2,
"selected": false,
"text": "link"
},
{
"answer_id": 163358,
"author": "Keith Williams",
"author_id": 20376,
"author_profile": "https://Stackoverflow.com/users/20376",
"pm_score": 3,
"selected": false,
"text": "@import"
},
{
"answer_id": 167001,
"author": "Paul D. Waite",
"author_id": 20578,
"author_profile": "https://Stackoverflow.com/users/20578",
"pm_score": 2,
"selected": false,
"text": "@import <link> @import @import @import @import"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24200/"
] |
162,421
|
<p>Being lazy (and liking DRY code), I'm the kind of guy who's going to write a few little wrappers for recurring HTML markup. Those provided by Rails are good already, but sometimes I have something a little more specific that I know I'm going to repeat over and over.</p>
<p>In some situations a partial can be the solution, but sometimes I'm just going to call the snippet way too often to justify the overhead of using partials.</p>
<p>Right now I create a helpers/html_helper.rb file and stick them in there. The problem is that helpers are not reloaded dynamically per request during development. So each time I tweak my snippet or the code around it, I have to kill the server and restart it.</p>
<p>Granted, it's just a 5 seconds process, but I love Rails' convenience of just developing and then refreshing the browser. So I'd love to have that for my markup snippets as well.</p>
<p>Note: Just sticking 'unloadable' inside the helper module doesn't work.</p>
|
[
{
"answer_id": 162600,
"author": "Patrick McKenzie",
"author_id": 15046,
"author_profile": "https://Stackoverflow.com/users/15046",
"pm_score": 1,
"selected": false,
"text": " #I go in environment.db (presumably it will work in one of the per-environment files, too.)\n Dependencies.explicitly_unloadable_constants << 'NameOfHelperToReloadHere'\n"
},
{
"answer_id": 164159,
"author": "Daniel Beardsley",
"author_id": 13216,
"author_profile": "https://Stackoverflow.com/users/13216",
"pm_score": 1,
"selected": false,
"text": "#Put this in config/environments/development.rb\nActiveSupport::Dependencies.explicitly_unloadable_constants.concat(Dir.glob(\"#{RAILS_ROOT}/app/helpers/**/*.rb\").map {|file| File.basename(file, '.rb').camelize})\n #Put this in config/environments/development.rb\nDependencies.explicitly_unloadable_constants.concat(Dir.glob(\"#{RAILS_ROOT}/app/helpers/**/*.rb\").map {|file| File.basename(file, '.rb').camelize})\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162421",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6349/"
] |
162,444
|
<p>We're trying to put together kiosk solution where we can charge people by hour for applications they use. As such, we need a way to figure out when an application is started, when it is closed and log this information for billing. I am a reasonably experienced .NET programmer so a managed code solution would be great. I have also dabbled in Windows API a little bit so that might work too. Any ideas out there?</p>
|
[
{
"answer_id": 162477,
"author": "Ian Jacobs",
"author_id": 22818,
"author_profile": "https://Stackoverflow.com/users/22818",
"pm_score": 0,
"selected": false,
"text": "static void Main() \n{ \n DateTime StartTime = DateTime.Now;\n Application.Run(new frmBilling());\n DateTime EndTime = DateTime.Now;\n\n //Log information to DB for billing\n} \n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16671/"
] |
162,445
|
<p>I wan't to know the real size of a web page (HTML + CSS + Javascript + Images + etc.) but from the browser side, maybe with a software, Firefox Add-On or similar?</p>
|
[
{
"answer_id": 48386021,
"author": "Skippy le Grand Gourou",
"author_id": 812102,
"author_profile": "https://Stackoverflow.com/users/812102",
"pm_score": 0,
"selected": false,
"text": "tools"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24506/"
] |
162,459
|
<p>I have 3 tables</p>
<ol>
<li><b>Links</b><br/>
Link ID<br/>
Link Name<br/>
GroupID (FK into Groups)<br/>
SubGroupID (FK into Subgroups)<br/>
<br/></li>
<li><p><b>Groups</b><br/>
GroupID<br/>
GroupName<br/></p></li>
<li><p><b>SubGroup</b><br/>
SubGroupID<br/>
SubGroupName<br/>
GroupID (FK into Groups)<br/></p></li>
</ol>
<p>Every link needs to have a GroupID but teh SubGroupID is optional. How do i write a SQL query to show: <br/></p>
<p><b>Links.LinkName, Groups.GroupName, SubGroup.SubGroupName<br/></b></p>
<p>For the records with no subgroup just put a blank entry in that field. If i have 250 link rows, i should get back 250 reecords from this query.</p>
<p>Is there a way to do this in one query or do i need to do multiple queries?</p>
|
[
{
"answer_id": 162478,
"author": "Danimal",
"author_id": 2757,
"author_profile": "https://Stackoverflow.com/users/2757",
"pm_score": 1,
"selected": false,
"text": "SELECT \n links.linkname\n , groups.groupname\n , subgroup.groupname\nFROM\n links \n JOIN groups ON links.groupid = groups.groupid\n LEFT OUTER JOIN subgroups ON links.subgroupid = subgroup.subgroupid\n SELECT \n links.linkname\n , groups.groupname\n , SUBGROUPS.groupname\nFROM\n links \n JOIN groups ON links.groupid = groups.groupid\n LEFT OUTER JOIN groups SUBGROUPS ON links.subgroupid = subgroup.groupid\n"
},
{
"answer_id": 162483,
"author": "NotMe",
"author_id": 2424,
"author_profile": "https://Stackoverflow.com/users/2424",
"pm_score": 4,
"selected": true,
"text": "select links.linkname, groups.groupname, subgroup.subgroupname\nfrom links\n inner join groups on (links.groupid = groups.groupid)\n left outer join subgroup on (links.subgroupid = subgroup.subgroupid)\n"
},
{
"answer_id": 162487,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 1,
"selected": false,
"text": "SELECT Links.LinkName, Groups.GroupName, SubGroup.SubGroupName -- Will potentially be NULL\nFROM Links\nINNER JOIN Groups\n ON Group.GroupID = Links.GroupID\nLEFT JOIN SubGroup\n ON SubGroup.SubGroupID = Links.SubGroupID\n"
},
{
"answer_id": 162488,
"author": "Carlton Jenke",
"author_id": 1215,
"author_profile": "https://Stackoverflow.com/users/1215",
"pm_score": 1,
"selected": false,
"text": "select Links.LinkName, Groups.GroupName, SubGroup.SubGroupName\nfrom Links \ninner join Groups on Groups.GroupID = Links.GroupID\nleft outer join SubGroup on Links.SubGroupID = SubGroup.SubGroupID\n"
},
{
"answer_id": 162490,
"author": "Ron Savage",
"author_id": 12476,
"author_profile": "https://Stackoverflow.com/users/12476",
"pm_score": 0,
"selected": false,
"text": "select\n l.LinkName,\n g.GroupName,\n s.SubGroupName\nfrom\n Links l\n'\n JOIN Group g\n on ( g.GroupId = l.GroupId)\n'\n LEFT OUTER JOIN SubGroup s\n on ( s.SubGroupId = l.SubGroupId )\n"
},
{
"answer_id": 162491,
"author": "palehorse",
"author_id": 312,
"author_profile": "https://Stackoverflow.com/users/312",
"pm_score": 0,
"selected": false,
"text": "SELECT LinkName, GroupName, SubGroupNamne\nFROM Links INNER JOIN Groups ON LInks.GroupID = Groups.GroupID\n LEFT JOIN SubGroup ON Links.SubGroupID = SubGroup.SubGroupID\n"
},
{
"answer_id": 162506,
"author": "Zsolt Botykai",
"author_id": 11621,
"author_profile": "https://Stackoverflow.com/users/11621",
"pm_score": 0,
"selected": false,
"text": "select L1.LinkName, G1.GroupName, NVL(S1.SubGroupName,' ')\n from Links L1, Groups G1, SubGroup S1 \nwhere L1.GroupID = G1.GroupID and\n L1.GroupID = S1.GroupID\n"
},
{
"answer_id": 162512,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 0,
"selected": false,
"text": "select a.linkname, b.groupname, c.subgroupname\nfrom links a, groups b, subgroup c\nwhere a.groupid = b.groupid\nand a.subgroupid = c.subgroupid\nand a.subgroupid is not null\nunion all\nselect a.linkname, b.groupname, ' '\nfrom links a, groups b\nwhere a.groupid = b.groupid\nand a.subgroupid is null\n"
},
{
"answer_id": 163282,
"author": "Swinders",
"author_id": 186,
"author_profile": "https://Stackoverflow.com/users/186",
"pm_score": 0,
"selected": false,
"text": "SELECT L.LinkName, G.GroupName, S.SubGroupName\n FROM Links As L\n INNER JOIN Groups As G ON L.GroupID=G.GroupID\n LEFT OUTER JOIN SubGroup S ON L.SubGroupID=S.SubGroupID\n SELECT L.LinkName, G.GroupName, S.SubGroupName\n FROM Links As L\n INNER JOIN Groups As G ON L.GroupID=G.GroupID\n LEFT OUTER JOIN SubGroup S ON L.SubGroupID=S.SubGroupID AND L.GroupID=S.GroupID\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
162,480
|
<p>Consider:</p>
<pre><code>int testfunc1 (const int a)
{
return a;
}
int testfunc2 (int const a)
{
return a;
}
</code></pre>
<p>Are these two functions the same in every aspect or is there a difference?</p>
<p>I'm interested in an answer for the C language, but if there is something interesting in the C++ language, I'd like to know as well.</p>
|
[
{
"answer_id": 162499,
"author": "prakash",
"author_id": 123,
"author_profile": "https://Stackoverflow.com/users/123",
"pm_score": 2,
"selected": false,
"text": "int int*"
},
{
"answer_id": 162504,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 9,
"selected": true,
"text": "const T T const const char* char char const* char char* const char const const const"
},
{
"answer_id": 162505,
"author": "user7545",
"author_id": 7545,
"author_profile": "https://Stackoverflow.com/users/7545",
"pm_score": 2,
"selected": false,
"text": "const int* cantChangeTheData;\nint* const cantChangeTheAddress;\n"
},
{
"answer_id": 162588,
"author": "Andru Luvisi",
"author_id": 5922,
"author_profile": "https://Stackoverflow.com/users/5922",
"pm_score": 4,
"selected": false,
"text": "const int *a\nint const *a\n int * const a\n const int * const a\n static int one = 1;\n\nint testfunc3 (const int *a)\n{\n *a = 1; /* Error */\n a = &one;\n return *a;\n}\n\nint testfunc4 (int * const a)\n{\n *a = 1;\n a = &one; /* Error */\n return *a;\n}\n\nint testfunc5 (const int * const a)\n{\n *a = 1; /* Error */\n a = &one; /* Error */\n return *a;\n}\n"
},
{
"answer_id": 162615,
"author": "Ates Goral",
"author_id": 23501,
"author_profile": "https://Stackoverflow.com/users/23501",
"pm_score": 8,
"selected": false,
"text": "const int a = 1; // read as \"a is an integer which is constant\"\nint const a = 1; // read as \"a is a constant integer\"\n a = 2; // Can't do because a is constant\n const char *s; // read as \"s is a pointer to a char that is constant\"\nchar c;\nchar *const t = &c; // read as \"t is a constant pointer to a char\"\n\n*s = 'A'; // Can't do because the char is constant\ns++; // Can do because the pointer isn't constant\n*t = 'A'; // Can do because the char isn't constant\nt++; // Can't do because the pointer is constant\n"
},
{
"answer_id": 162949,
"author": "Pat Notz",
"author_id": 825,
"author_profile": "https://Stackoverflow.com/users/825",
"pm_score": 2,
"selected": false,
"text": "const * \n\nint * const foo = ...; // Pointer cannot change, pointed to value can change\nconst int * bar = ...; // Pointer can change, pointed to value cannot change\nint * baz = ...; // Pointer can change, pointed to value can change\nconst int * const qux = ...; // Pointer cannot change, pointed to value cannot change\n"
},
{
"answer_id": 266096,
"author": "Emerick Rogul",
"author_id": 33837,
"author_profile": "https://Stackoverflow.com/users/33837",
"pm_score": 3,
"selected": false,
"text": "const int int const const"
},
{
"answer_id": 32727873,
"author": "Nick Westgate",
"author_id": 313445,
"author_profile": "https://Stackoverflow.com/users/313445",
"pm_score": 3,
"selected": false,
"text": "int getInt() const;\n this Foo * const Foo const * const"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15955/"
] |
162,497
|
<p>There is a select dropdown and I want to add "No selection" item to the list which should give me 'null' when submitted.
I'm using SimpleFormController derived controller.</p>
<pre><code>protected Map referenceData(HttpServletRequest httpServletRequest, Object o, Errors errors) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("countryList", Arrays.asList(Country.values()));
return map;
}
</code></pre>
<p>And the jspx part is</p>
<pre class="lang-html prettyprint-override"><code><form:select path="country" items="${countryList}" title="country"/>
</code></pre>
<p>One possible solution seems to be in adding a null value to the beginning of the list and then using a custom PropertyEditor to display this 'null' as 'No selection'.
Is there a better solution?</p>
<p>@Edit: I have solved this with a custom validation annotation which checks if the selected value is "No Selection". Is there a more standard and easier solution?</p>
|
[
{
"answer_id": 171260,
"author": "Jacob Mattison",
"author_id": 1237,
"author_profile": "https://Stackoverflow.com/users/1237",
"pm_score": 6,
"selected": true,
"text": "<form:select path=\"country\" title=\"country\" >\n <form:option value=\"\"> </form:option>\n <form:options items=\"${countryList}\" />\n</form:select>\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/162497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/578/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.