qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
30,319
<p>Is there a tag in HTML that will only display its content if JavaScript is enabled? I know <code>&lt;noscript&gt;</code> works the opposite way around, displaying its HTML content when JavaScript is turned off. But I would like to only display a form on a site if JavaScript is available, telling them why they can't use the form if they don't have it.</p> <p>The only way I know how to do this is with the <code>document.write();</code> method in a script tag, and it seems a bit messy for large amounts of HTML.</p>
[ { "answer_id": 35318, "author": "cpm", "author_id": 3674, "author_profile": "https://Stackoverflow.com/users/3674", "pm_score": 0, "selected": false, "text": "document.getElementById(id).innerHTML = \"My Content\"" }, { "answer_id": 37782, "author": "Shadow2531", "author_id": 1697, "author_profile": "https://Stackoverflow.com/users/1697", "pm_score": 1, "selected": false, "text": "<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <title></title>\n <style>\n *[data-when-js-is-on] {\n display: none;\n }\n </style>\n <script>\n document.getElementsByTagName(\"style\")[0].textContent = \"\";\n </script>\n </head>\n <body>\n <div data-when-js-is-on>\n JS is on.\n </div>\n </body>\n</html>\n" }, { "answer_id": 431554, "author": "Will", "author_id": 53744, "author_profile": "https://Stackoverflow.com/users/53744", "pm_score": 8, "selected": false, "text": "<html>\n<head>\n <noscript><style> .jsonly { display: none } </style></noscript>\n</head>\n\n<body>\n <p class=\"jsonly\">You are a JavaScript User!</p>\n</body>\n</html>\n" }, { "answer_id": 1229544, "author": "alexanderpas", "author_id": 136173, "author_profile": "https://Stackoverflow.com/users/136173", "pm_score": 3, "selected": false, "text": "$(document).ready(function() {\n $(\"body\").addClass(\"js\");\n});\n" }, { "answer_id": 3556881, "author": "Chris Bloom", "author_id": 83743, "author_profile": "https://Stackoverflow.com/users/83743", "pm_score": 3, "selected": false, "text": "<html>\n<head>\n <script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"></script>\n <script type=\"text/javascript\" charset=\"utf-8\">\n $(document).ready(function() {\n $.get('_test.html', function(html) {\n $('p:first').after(html);\n });\n });\n </script>\n</head>\n<body>\n <p>This is content at the top of the page.</p>\n <p>This is content at the bottom of the page.</p>\n</body>\n</html>\n" }, { "answer_id": 6226046, "author": "Spycho", "author_id": 660311, "author_profile": "https://Stackoverflow.com/users/660311", "pm_score": 2, "selected": false, "text": "<html>\n <head>\n <!-- put this in a separate stylesheet -->\n <style type=\"text/css\">\n .jsOff .jsOnly{\n display:none;\n }\n </style>\n </head>\n\n <body class=\"jsOff\">\n <script type=\"text/javascript\">\n document.body.className = document.body.className.replace('jsOff','jsOn');\n </script>\n\n <noscript><p>Please enable JavaScript and then refresh the page.</p></noscript>\n\n <p class=\"jsOnly\">I am only shown if JS is enabled</p>\n </body>\n</html>\n" }, { "answer_id": 17724149, "author": "prgDevelop", "author_id": 527962, "author_profile": "https://Stackoverflow.com/users/527962", "pm_score": 1, "selected": false, "text": ".js {\ndisplay: none;\n}\n" }, { "answer_id": 57666343, "author": "Chuck", "author_id": 8661144, "author_profile": "https://Stackoverflow.com/users/8661144", "pm_score": 2, "selected": false, "text": "HIDDEN" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2098/" ]
30,321
<p>I am looking for a method of storing Application Messages, such as</p> <ul> <li>"You have logged in successfully"</li> <li>"An error has occurred, please call the helpdesk on x100"</li> <li>"You do not have the authority to reset all system passwords" etc</li> </ul> <p>So that "when" the users decide they don't like the wording of messages I don't have to change the source code, recompile then redeploy - instead I just change the message store.</p> <p>I really like the way that I can easily access strings in the web.config using keys and values.</p> <pre><code>ConfigurationManager.AppSettings("LOGINSUCCESS"); </code></pre> <p>However as I could have a large number of application messages I didn't want to use the web.config directly. I was going to add a 2nd web config file and use that but of course you can only have one per virtual directory.</p> <p>Does anyone have any suggestions on how to do this without writing much custom code?</p>
[ { "answer_id": 30326, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 4, "selected": true, "text": "<appSettings file=\"StringKeys.config\">\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/982/" ]
30,328
<p>How do you OCR an tiff file using Tesseract's interface in c#?<br> Currently I only know how to do it using the executable.</p>
[ { "answer_id": 17017418, "author": "linquize", "author_id": 1031218, "author_profile": "https://Stackoverflow.com/users/1031218", "pm_score": 3, "selected": false, "text": "Process process = Process.Start(\"tesseract.exe\", \"out\");\nprocess.WaitForExit();\nif (process.ExitCode == 0)\n{\n string content = File.ReadAllText(\"out.txt\");\n}\n" }, { "answer_id": 18070183, "author": "b_levitt", "author_id": 852208, "author_profile": "https://Stackoverflow.com/users/852208", "pm_score": 3, "selected": false, "text": "Tesseract ocr = new Tesseract(Path.Combine(Environment.CurrentDirectory, \"tessdata\"), \"eng\", Tesseract.OcrEngineMode.OEM_TESSERACT_ONLY);\nthis.ocr.Recognize(clip);\noptOCR.Text = this.ocr.GetText();\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3249/" ]
30,337
<p>Is there an online resource somewhere that maintains statistics on the install-base of Java including JRE version information? If not, is there any recent report that has some numbers?</p> <p>I'm particularly interested in Windows users, but all other OS's are welcome too.</p>
[ { "answer_id": 17017418, "author": "linquize", "author_id": 1031218, "author_profile": "https://Stackoverflow.com/users/1031218", "pm_score": 3, "selected": false, "text": "Process process = Process.Start(\"tesseract.exe\", \"out\");\nprocess.WaitForExit();\nif (process.ExitCode == 0)\n{\n string content = File.ReadAllText(\"out.txt\");\n}\n" }, { "answer_id": 18070183, "author": "b_levitt", "author_id": 852208, "author_profile": "https://Stackoverflow.com/users/852208", "pm_score": 3, "selected": false, "text": "Tesseract ocr = new Tesseract(Path.Combine(Environment.CurrentDirectory, \"tessdata\"), \"eng\", Tesseract.OcrEngineMode.OEM_TESSERACT_ONLY);\nthis.ocr.Recognize(clip);\noptOCR.Text = this.ocr.GetText();\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2881/" ]
30,346
<p>Header, footer and sidebars have fixed position. In the center a content area with both scroll bars. No outer scroll bars on the browser. I have a layout that works in IE7 and FF. I need to add IE6 support. How can I make this work?</p> <p>Here is an approximation of my current CSS.</p> <pre class="lang-html prettyprint-override"><code> &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Layout&lt;/title&gt; &lt;style&gt; * { margin: 0px; padding: 0px; border: 0px; } .sample-border { border: 1px solid black; } #header { position: absolute; top: 0px; left: 0px; right: 0px; height: 60px; } #left-sidebar { position: absolute; top: 65px; left: 0px; width: 220px; bottom: 110px; } #right-sidebar { position: absolute; top: 65px; right: 0px; width: 200px; bottom: 110px; } #footer { position: absolute; bottom: 0px; left: 0px; right: 0px; height: 105px; } @media screen { #content { position: absolute; top: 65px; left: 225px; bottom: 110px; right: 205px; overflow: auto; } body #left-sidebar, body #right-sidebar, body #header, body #footer, body #content { position: fixed; } } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&quot;header&quot; class=&quot;sample-border&quot;&gt;&lt;/div&gt; &lt;div id=&quot;left-sidebar&quot; class=&quot;sample-border&quot;&gt;&lt;/div&gt; &lt;div id=&quot;right-sidebar&quot; class=&quot;sample-border&quot;&gt;&lt;/div&gt; &lt;div id=&quot;content&quot; class=&quot;sample-border&quot;&gt;&lt;img src=&quot;/broken.gif&quot; style=&quot;display: block; width: 3000px; height: 3000px;&quot; /&gt;&lt;/div&gt; &lt;div id=&quot;footer&quot; class=&quot;sample-border&quot;&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
[ { "answer_id": 30932, "author": "palotasb", "author_id": 3063, "author_profile": "https://Stackoverflow.com/users/3063", "pm_score": 1, "selected": false, "text": "<head>" }, { "answer_id": 34424, "author": "Mocky", "author_id": 3211, "author_profile": "https://Stackoverflow.com/users/3211", "pm_score": 0, "selected": false, "text": "<!--[if lt IE 7]>\n<style>\nbody>div.ie6-autoheight {\n height: 455px;\n}\nbody>div.ie6-autowidth {\n right: ;\n width: 530px;\n}\n</style>\n<script src=\"http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js\" type=\"text/javascript\"></script>\n<script type=\"text/javascript\">\n\nfunction fixLayout() {\n if (document.documentElement.offsetWidth) {\n var w = document.documentElement.offsetWidth - 450;\n var h = document.documentElement.offsetHeight - 175;\n var l = document.getElementById('left-sidebar');\n var r = document.getElementById('right-sidebar');\n var c = document.getElementById('content');\n\n c.style.width = w;\n c.style.height = h;\n l.style.height = h;\n r.style.height = h;\n }\n}\nwindow.onresize = fixLayout;\nfixLayout();\n</script>\n<![endif]-->\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3211/" ]
30,354
<p>In one of my VB6 forms, I create several other Form objects and store them in member variables.</p> <pre><code>Private m_frm1 as MyForm Private m_frm2 as MyForm // Later... Set m_frm1 = New MyForm Set m_frm2 = New MyForm </code></pre> <p>I notice that I'm leaking memory whenever this (parent) form is created and destroyed. Is it necessary for me to assign these member variables to <code>Nothing</code> in <code>Form_Unload()</code>?</p> <p>In general, when is that required?</p> <p>SOLVED: This particular memory leak was fixed when I did an <code>Unload</code> on the forms in question, not when I set the form to <code>Nothing</code>. I managed to remove a few other memory leaks by explicitly setting some instances of Class Modules to <code>Nothing</code>, as well.</p>
[ { "answer_id": 30383, "author": "Josh Miller", "author_id": 2818, "author_profile": "https://Stackoverflow.com/users/2818", "pm_score": 2, "selected": false, "text": "Dim y As Long\nFor y = 0 To Forms.Count -1\n Unload Forms(x)\nNext\n" }, { "answer_id": 30398, "author": "BZ.", "author_id": 2349, "author_profile": "https://Stackoverflow.com/users/2349", "pm_score": 2, "selected": false, "text": "With aCustomer\n .FirstName = \"John\"\n .LastName = \"Smith\"\nEnd With\n" }, { "answer_id": 30445, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 3, "selected": false, "text": "Nothing" }, { "answer_id": 30679, "author": "Josh Miller", "author_id": 2818, "author_profile": "https://Stackoverflow.com/users/2818", "pm_score": 4, "selected": true, "text": "Private Sub Form_Load()\n Dim frm As Form2\n Set frm = New Form2\n frm.Show\n Set frm = Nothing\nEnd Sub\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30354", "https://Stackoverflow.com", "https://Stackoverflow.com/users/863/" ]
30,373
<p>I remember first learning about vectors in the STL and after some time, I wanted to use a vector of bools for one of my projects. After seeing some strange behavior and doing some research, I learned that <a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;seqNum=98" rel="noreferrer">a vector of bools is not really a vector of bools</a>.</p> <p>Are there any other common pitfalls to avoid in C++?</p>
[ { "answer_id": 48676, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 2, "selected": false, "text": "virtual" }, { "answer_id": 281451, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 3, "selected": false, "text": "// C Code\nvoid myFunc()\n{\n Plop* plop = createMyPlopResource();\n\n // Use the plop\n\n releaseMyPlopResource(plop);\n}\n" }, { "answer_id": 281487, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 0, "selected": false, "text": "class SomeClass\n{\n ...\n void DoSomething()\n {\n ++counter; // crash here!\n }\n int counter;\n};\n\nvoid Foo(SomeClass & ref)\n{\n ...\n ref.DoSomething(); // if DoSomething is virtual, you might crash here\n ...\n}\n\nvoid Bar(SomeClass * ptr)\n{\n Foo(*ptr); // if ptr is NULL, you have created an invalid reference\n // which probably WILL NOT crash here\n}\n" }, { "answer_id": 281562, "author": "blizpasta", "author_id": 20646, "author_profile": "https://Stackoverflow.com/users/20646", "pm_score": 0, "selected": false, "text": "(x == 10)" }, { "answer_id": 282056, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "for" }, { "answer_id": 282070, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 1, "selected": false, "text": "static_cast" }, { "answer_id": 282921, "author": "gsarkis", "author_id": 36786, "author_profile": "https://Stackoverflow.com/users/36786", "pm_score": -1, "selected": false, "text": "#include <boost/shared_ptr.hpp>\nclass A {\npublic:\n void nuke() {\n boost::shared_ptr<A> (this);\n }\n};\n\nint main(int argc, char** argv) {\n A a;\n a.nuke();\n return(0);\n}\n" }, { "answer_id": 285100, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 2, "selected": false, "text": "delete" }, { "answer_id": 293047, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 6, "selected": false, "text": "##c++" }, { "answer_id": 3986213, "author": "starblue", "author_id": 49246, "author_profile": "https://Stackoverflow.com/users/49246", "pm_score": 0, "selected": false, "text": "&" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2328/" ]
30,379
<p>We have a Windows Server Web Edition 2003 Web Farm. </p> <p>What can we use that handles replication across the servers for:</p> <p>Content &amp; IIS Configuration (App Pools, Virtual Directories, etc...)</p> <p>We will be moving to Windows 2008 in the near future, so I guess what options are there on Windows 2008 as well.</p>
[ { "answer_id": 48676, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 2, "selected": false, "text": "virtual" }, { "answer_id": 281451, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 3, "selected": false, "text": "// C Code\nvoid myFunc()\n{\n Plop* plop = createMyPlopResource();\n\n // Use the plop\n\n releaseMyPlopResource(plop);\n}\n" }, { "answer_id": 281487, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 0, "selected": false, "text": "class SomeClass\n{\n ...\n void DoSomething()\n {\n ++counter; // crash here!\n }\n int counter;\n};\n\nvoid Foo(SomeClass & ref)\n{\n ...\n ref.DoSomething(); // if DoSomething is virtual, you might crash here\n ...\n}\n\nvoid Bar(SomeClass * ptr)\n{\n Foo(*ptr); // if ptr is NULL, you have created an invalid reference\n // which probably WILL NOT crash here\n}\n" }, { "answer_id": 281562, "author": "blizpasta", "author_id": 20646, "author_profile": "https://Stackoverflow.com/users/20646", "pm_score": 0, "selected": false, "text": "(x == 10)" }, { "answer_id": 282056, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "for" }, { "answer_id": 282070, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 1, "selected": false, "text": "static_cast" }, { "answer_id": 282921, "author": "gsarkis", "author_id": 36786, "author_profile": "https://Stackoverflow.com/users/36786", "pm_score": -1, "selected": false, "text": "#include <boost/shared_ptr.hpp>\nclass A {\npublic:\n void nuke() {\n boost::shared_ptr<A> (this);\n }\n};\n\nint main(int argc, char** argv) {\n A a;\n a.nuke();\n return(0);\n}\n" }, { "answer_id": 285100, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 2, "selected": false, "text": "delete" }, { "answer_id": 293047, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 6, "selected": false, "text": "##c++" }, { "answer_id": 3986213, "author": "starblue", "author_id": 49246, "author_profile": "https://Stackoverflow.com/users/49246", "pm_score": 0, "selected": false, "text": "&" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2349/" ]
30,397
<p>I am trying to set up dynamic per-item menus (Edit Control Block) in SharePoint 2007. My goal is to have certain features that are available based on the current user's group membership.</p> <p>I know that the CustomAction tag that controls the creation of this menu item has a Rights attribute. The problem that I have with this is that the groups I am using have identical rights in the site (ViewListItems, ManageAlerts, etc). The groups that we have set up deal more with function, such as Manager, Employee, etc. We want to be able to assign a custom feature to a group, and have the menu items associated with that feature visible only to members of that group. Everyone has the same basic site permissions, but will have extra options availble based on their login credentials.</p> <p>I have seen several articles on modifying the Core.js file to hide items in the context menu, but they are an all-or-nothing approach. There is an interesting post at <a href="http://blog.thekid.me.uk/archive/2008/04/29/sharepoint-custom-actions-in-a-list-view-webpart.aspx" rel="noreferrer">http://blog.thekid.me.uk/archive/2008/04/29/sharepoint-custom-actions-in-a-list-view-webpart.aspx</a> that shows how to dynamically modify the Actions menu. It is trivial to modify this example to check the users group and show or hide the menu based on membership. Unfortunately, this example does not seem to apply to context menu items as evidenced here <a href="http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/c2259839-24c4-4a7e-83e5-3925cdd17c44/" rel="noreferrer">http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/c2259839-24c4-4a7e-83e5-3925cdd17c44/</a>.</p> <p>Does anyone know of a way to do this without using javascript? If not, what is the best way to check the user's group from javascript?</p>
[ { "answer_id": 48676, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 2, "selected": false, "text": "virtual" }, { "answer_id": 281451, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 3, "selected": false, "text": "// C Code\nvoid myFunc()\n{\n Plop* plop = createMyPlopResource();\n\n // Use the plop\n\n releaseMyPlopResource(plop);\n}\n" }, { "answer_id": 281487, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 0, "selected": false, "text": "class SomeClass\n{\n ...\n void DoSomething()\n {\n ++counter; // crash here!\n }\n int counter;\n};\n\nvoid Foo(SomeClass & ref)\n{\n ...\n ref.DoSomething(); // if DoSomething is virtual, you might crash here\n ...\n}\n\nvoid Bar(SomeClass * ptr)\n{\n Foo(*ptr); // if ptr is NULL, you have created an invalid reference\n // which probably WILL NOT crash here\n}\n" }, { "answer_id": 281562, "author": "blizpasta", "author_id": 20646, "author_profile": "https://Stackoverflow.com/users/20646", "pm_score": 0, "selected": false, "text": "(x == 10)" }, { "answer_id": 282056, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "for" }, { "answer_id": 282070, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 1, "selected": false, "text": "static_cast" }, { "answer_id": 282921, "author": "gsarkis", "author_id": 36786, "author_profile": "https://Stackoverflow.com/users/36786", "pm_score": -1, "selected": false, "text": "#include <boost/shared_ptr.hpp>\nclass A {\npublic:\n void nuke() {\n boost::shared_ptr<A> (this);\n }\n};\n\nint main(int argc, char** argv) {\n A a;\n a.nuke();\n return(0);\n}\n" }, { "answer_id": 285100, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 2, "selected": false, "text": "delete" }, { "answer_id": 293047, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 6, "selected": false, "text": "##c++" }, { "answer_id": 3986213, "author": "starblue", "author_id": 49246, "author_profile": "https://Stackoverflow.com/users/49246", "pm_score": 0, "selected": false, "text": "&" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2470/" ]
30,494
<p>Here is my code, which takes two version identifiers in the form "1, 5, 0, 4" or "1.5.0.4" and determines which is the newer version.</p> <p>Suggestions or improvements, please!</p> <pre><code> /// &lt;summary&gt; /// Compares two specified version strings and returns an integer that /// indicates their relationship to one another in the sort order. /// &lt;/summary&gt; /// &lt;param name="strA"&gt;the first version&lt;/param&gt; /// &lt;param name="strB"&gt;the second version&lt;/param&gt; /// &lt;returns&gt;less than zero if strA is less than strB, equal to zero if /// strA equals strB, and greater than zero if strA is greater than strB&lt;/returns&gt; public static int CompareVersions(string strA, string strB) { char[] splitTokens = new char[] {'.', ','}; string[] strAsplit = strA.Split(splitTokens, StringSplitOptions.RemoveEmptyEntries); string[] strBsplit = strB.Split(splitTokens, StringSplitOptions.RemoveEmptyEntries); int[] versionA = new int[4]; int[] versionB = new int[4]; for (int i = 0; i &lt; 4; i++) { versionA[i] = Convert.ToInt32(strAsplit[i]); versionB[i] = Convert.ToInt32(strBsplit[i]); } // now that we have parsed the input strings, compare them return RecursiveCompareArrays(versionA, versionB, 0); } /// &lt;summary&gt; /// Recursive function for comparing arrays, 0-index is highest priority /// &lt;/summary&gt; private static int RecursiveCompareArrays(int[] versionA, int[] versionB, int idx) { if (versionA[idx] &lt; versionB[idx]) return -1; else if (versionA[idx] &gt; versionB[idx]) return 1; else { Debug.Assert(versionA[idx] == versionB[idx]); if (idx == versionA.Length - 1) return 0; else return RecursiveCompareArrays(versionA, versionB, idx + 1); } } </code></pre> <hr> <p>@ <a href="https://stackoverflow.com/questions/30494/compare-version-identifiers#30510">Darren Kopp</a>:</p> <p>The version class does not handle versions of the format 1.0.0.5.</p>
[ { "answer_id": 30510, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 5, "selected": false, "text": "Version a = new Version(\"1.0.0.0\");\nVersion b = new Version(\"2.0.0.0\");\n\nConsole.WriteLine(string.Format(\"Newer: {0}\", (a > b) ? \"a\" : \"b\"));\n// prints b\n" }, { "answer_id": 30514, "author": "Adam Haile", "author_id": 194, "author_profile": "https://Stackoverflow.com/users/194", "pm_score": 0, "selected": false, "text": "public static int CompareVersions(string strA, string strB)\n{\n char[] splitTokens = new char[] {'.', ','};\n string[] strAsplit = strA.Split(splitTokens, StringSplitOptions.RemoveEmptyEntries);\n string[] strBsplit = strB.Split(splitTokens, StringSplitOptions.RemoveEmptyEntries);\n int versionA = 0;\n int versionB = 0;\n string vA = string.Empty;\n string vB = string.Empty;\n\n for (int i = 0; i < 4; i++)\n {\n vA += strAsplit[i];\n vB += strBsplit[i];\n versionA[i] = Convert.ToInt32(strAsplit[i]);\n versionB[i] = Convert.ToInt32(strBsplit[i]);\n }\n\n versionA = Convert.ToInt32(vA);\n versionB = Convert.ToInt32(vB);\n\n if(vA > vB)\n return 1;\n else if(vA < vB)\n return -1;\n else\n return 0; //they are equal\n}\n" }, { "answer_id": 30629, "author": "Antti Kissaniemi", "author_id": 2948, "author_profile": "https://Stackoverflow.com/users/2948", "pm_score": 6, "selected": true, "text": " /// <summary>\n /// Compare versions of form \"1,2,3,4\" or \"1.2.3.4\". Throws FormatException\n /// in case of invalid version.\n /// </summary>\n /// <param name=\"strA\">the first version</param>\n /// <param name=\"strB\">the second version</param>\n /// <returns>less than zero if strA is less than strB, equal to zero if\n /// strA equals strB, and greater than zero if strA is greater than strB</returns>\n public static int CompareVersions(String strA, String strB)\n {\n Version vA = new Version(strA.Replace(\",\", \".\"));\n Version vB = new Version(strB.Replace(\",\", \".\"));\n\n return vA.CompareTo(vB);\n }\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1490/" ]
30,504
<p>I know there is a registry key indicating the install directory, but I don't remember what it is off-hand.</p> <p>I am currently interested in Visual&nbsp;Studio&nbsp;2008 install directory, though it wouldn't hurt to list others for future reference.</p>
[ { "answer_id": 30524, "author": "Emperor XLII", "author_id": 2495, "author_profile": "https://Stackoverflow.com/users/2495", "pm_score": 3, "selected": false, "text": "VS*COMNTOOLS" }, { "answer_id": 30528, "author": "Sam Hasler", "author_id": 2541, "author_profile": "https://Stackoverflow.com/users/2541", "pm_score": 0, "selected": false, "text": "VCToolkitInstallDir" }, { "answer_id": 2460746, "author": "peter", "author_id": 295486, "author_profile": "https://Stackoverflow.com/users/295486", "pm_score": 2, "selected": false, "text": "Environment.GetEnvironmentVariable(\"VS90COMNTOOLS\");" }, { "answer_id": 7363241, "author": "Dim_Ka", "author_id": 936971, "author_profile": "https://Stackoverflow.com/users/936971", "pm_score": 4, "selected": false, "text": " private string GetVisualStudioInstallationPath()\n {\n string installationPath = null;\n if (Environment.Is64BitOperatingSystem)\n {\n installationPath = (string)Registry.GetValue(\n \"HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Wow6432Node\\\\Microsoft\\\\VisualStudio\\\\10.0\\\\\",\n \"InstallDir\",\n null);\n }\n else\n {\n installationPath = (string)Registry.GetValue(\n \"HKEY_LOCAL_MACHINE\\\\SOFTWARE \\\\Microsoft\\\\VisualStudio\\\\10.0\\\\\",\n \"InstallDir\",\n null);\n }\n return installationPath;\n\n }\n" }, { "answer_id": 8579591, "author": "Kevin Kibler", "author_id": 56739, "author_profile": "https://Stackoverflow.com/users/56739", "pm_score": 3, "selected": false, "text": "string visualStudioRegistryKeyPath = @\"SOFTWARE\\Microsoft\\VisualStudio\";\nstring visualCSharpExpressRegistryKeyPath = @\"SOFTWARE\\Microsoft\\VCSExpress\";\n\nList<Version> vsVersions = new List<Version>() { new Version(\"10.0\"), new Version(\"9.0\"), new Version(\"8.0\") };\nforeach (var version in vsVersions)\n{\n foreach (var isExpress in new bool[] { false, true })\n {\n RegistryKey registryBase32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);\n RegistryKey vsVersionRegistryKey = registryBase32.OpenSubKey(\n string.Format(@\"{0}\\{1}.{2}\", (isExpress) ? visualCSharpExpressRegistryKeyPath : visualStudioRegistryKeyPath, version.Major, version.Minor));\n if (vsVersionRegistryKey == null) { continue; }\n Console.WriteLine(vsVersionRegistryKey.GetValue(\"InstallDir\", string.Empty).ToString());\n }\n" }, { "answer_id": 23328706, "author": "Stefan Cepcik", "author_id": 3579195, "author_profile": "https://Stackoverflow.com/users/3579195", "pm_score": 2, "selected": false, "text": "$vsEnvVars = (dir Env:).Name -match \"VS[0-9]{1,3}COMNTOOLS\"\n$latestVs = $vsEnvVars | Sort-Object | Select -Last 1\n$vsPath = Get-Content Env:\\$latestVs\n" }, { "answer_id": 26874379, "author": "JJS", "author_id": 26877, "author_profile": "https://Stackoverflow.com/users/26877", "pm_score": 2, "selected": false, "text": "@echo off\n:: BATCH doesn't have logical or, otherwise I'd use it\nSET platform=\nIF /I [%PROCESSOR_ARCHITECTURE%]==[amd64] set platform=true\nIF /I [%PROCESSOR_ARCHITEW6432%]==[amd64] set platform=true\n\n:: default to VS2012 = 11.0\n:: the Environment variable VisualStudioVersion is set by devenv.exe\n:: if this batch is a child of devenv.exe external tools, we know which version to look at\nif not defined VisualStudioVersion SET VisualStudioVersion=11.0\n\nif defined platform (\nset VSREGKEY=HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\%VisualStudioVersion%\n) ELSE (\nset VSREGKEY=HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\%VisualStudioVersion%\n)\nfor /f \"skip=2 tokens=2,*\" %%A in ('reg query \"%VSREGKEY%\" /v InstallDir') do SET VSINSTALLDIR=%%B\n\necho %VSINSTALLDIR%\n" }, { "answer_id": 55049214, "author": "vik_78", "author_id": 5148765, "author_profile": "https://Stackoverflow.com/users/5148765", "pm_score": 2, "selected": false, "text": " try {\n var query = new SetupConfiguration();\n var query2 = (ISetupConfiguration2)query;\n var e = query2.EnumAllInstances();\n\n var helper = (ISetupHelper)query;\n\n int fetched;\n var instances = new ISetupInstance[1];\n do {\n e.Next(1, instances, out fetched);\n if (fetched > 0)\n Console.WriteLine(instances[0].GetInstallationPath());\n }\n while (fetched > 0);\n return 0;\n }\n catch (COMException ex) when (ex.HResult == REGDB_E_CLASSNOTREG) {\n Console.WriteLine(\"The query API is not registered. Assuming no instances are installed.\");\n return 0;\n }\n" }, { "answer_id": 55910148, "author": "HanT", "author_id": 10375413, "author_profile": "https://Stackoverflow.com/users/10375413", "pm_score": 2, "selected": false, "text": "vswhere.exe" }, { "answer_id": 56410974, "author": "SunsetQuest", "author_id": 2352507, "author_profile": "https://Stackoverflow.com/users/2352507", "pm_score": 1, "selected": false, "text": "var vsPath = VS_Tools.GetVSPath(avoidPrereleases:true, requiredWorkload:\"NativeDesktop\");\nvar vsPath = VS_Tools.GetVSPath();\nvar vsPath = VS_Tools.GetVSPath(specificVersion:\"15\");\n" }, { "answer_id": 60920478, "author": "Eng. M.Hamdy", "author_id": 8179345, "author_profile": "https://Stackoverflow.com/users/8179345", "pm_score": 0, "selected": false, "text": "Environment.GetEnvironmentVariable(\"VSAPPIDDIR\")" }, { "answer_id": 65869986, "author": "lauxjpn", "author_id": 2618319, "author_profile": "https://Stackoverflow.com/users/2618319", "pm_score": 1, "selected": false, "text": "Common7\\IDE" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2495/" ]
30,505
<p>I frequently work with multiple instances of Visual Studio, often working on different branches of the same solution.</p> <p><a href="https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Strictly_32-bit_versions" rel="noreferrer">Visual C++ 6.0</a> used to display the full path of the current source file in its title bar, but Visual&nbsp;Studio 2005 doesn't appear to do this. This makes it slightly more awkward than it should be to work out which branch of the solution I'm currently looking at (the quickest way I know of is to hover over a tab so you get the source file's path as a tooltip).</p> <p>Is there a way to get the full solution or file path into the title bar, or at least somewhere that's always visible, so I can quickly tell which branch is loaded into each instance?</p>
[ { "answer_id": 5870729, "author": "Drew Miller", "author_id": 459949, "author_profile": "https://Stackoverflow.com/users/459949", "pm_score": 3, "selected": false, "text": "Private timer As System.Threading.Timer\n\nDeclare Auto Function SetWindowText Lib \"user32\" (ByVal hWnd As System.IntPtr, ByVal lpstring As String) As Boolean\n\nPrivate _branchName As String = String.Empty\n\nPrivate Sub SolutionEvents_Opened() Handles SolutionEvents.Opened\n Try\n If timer Is Nothing Then\n ' Create timer which refreshes the caption because\n ' IDE resets the caption very often\n Dim autoEvent As New System.Threading.AutoResetEvent(False)\n Dim timerDelegate As System.Threading.TimerCallback = _\n AddressOf tick\n timer = New System.Threading.Timer(timerDelegate, autoEvent, 0, 25)\n End If\n Dim sourceIndex As Integer = DTE.Solution.FullName.IndexOf(\"\\Source\")\n Dim shortTitle As String = DTE.Solution.FullName.Substring(0, sourceIndex)\n Dim lastIndex As Integer = shortTitle.LastIndexOf(\"\\\")\n _branchName = shortTitle.Substring(lastIndex + 1)\n showTitle(_branchName)\n Catch ex As Exception\n\n End Try\nEnd Sub\n\n\nPrivate Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing\n If Not timer Is Nothing Then\n timer.Dispose()\n End If\nEnd Sub\n\n\n''' <summary>Dispose the timer on IDE shutdown.</summary>\nPublic Sub DTEEvents_OnBeginShutdown() Handles DTEEvents.OnBeginShutdown\n If Not timer Is Nothing Then\n timer.Dispose()\n End If\nEnd Sub\n\n\n'''<summary>Called by timer.</summary>\nPublic Sub tick(ByVal state As Object)\n Try\n showTitle(_branchName)\n Catch ex As System.Exception\n End Try\nEnd Sub\n\n\n'''<summary>Shows the title in main window.</summary>\nPrivate Sub showTitle(ByVal title As String)\n SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & \" - \" & DTE.Name)\nEnd Sub\n" }, { "answer_id": 11224520, "author": "superlogical", "author_id": 52360, "author_profile": "https://Stackoverflow.com/users/52360", "pm_score": 2, "selected": false, "text": "Friendly Name: {repo}\nSolution Path Regex: (?<repo>.*)\n" }, { "answer_id": 29597246, "author": "Muad'Dib", "author_id": 2000151, "author_profile": "https://Stackoverflow.com/users/2000151", "pm_score": 0, "selected": false, "text": "'sln_dir + \"/\" + orig_title'\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30505", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1739/" ]
30,529
<p>How could i implement Type-Safe Enumerations in Delphi in a COM scenario ? Basically, i'd like to replace a set of primitive constants of a enumeration with a set of static final object references encapsulated in a class ? . In Java, we can do something like:</p> <pre><code>public final class Enum { public static final Enum ENUMITEM1 = new Enum (); public static final Enum ENUMITEM2 = new Enum (); //... private Enum () {} } </code></pre> <p>and make comparisons using the customized enumeration type:</p> <pre><code>if (anObject != Enum.ENUMITEM1) ... </code></pre> <p>I am currently using the old Delphi 5 and i would like to declare some enums parameters on the interfaces, not allowing that client objects to pass integers (or long) types in the place of the required enumeration type. Do you have a better way of implementing enums other than using the native delphi enums ? </p>
[ { "answer_id": 30654, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 2, "selected": false, "text": "type\n TMyEnum = (Item1, Item2, Item3);\n\nif MyEnum <> Item1 then...\n" }, { "answer_id": 37211, "author": "Barry Kelly", "author_id": 3712, "author_profile": "https://Stackoverflow.com/users/3712", "pm_score": 2, "selected": false, "text": "{$APPTYPE CONSOLE}\n{$SCOPEDENUMS ON}\ntype\n TFoo = (One, Two, Three);\n{$SCOPEDENUMS OFF}\n\nvar\n x: TFoo;\nbegin\n x := TFoo.One;\n if not (x in [TFoo.Two, TFoo.Three]) then\n Writeln('OK');\nend.\n" }, { "answer_id": 41266, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 1, "selected": false, "text": "type\n TSomeEnum = (Enum1 = 1, Enum2 = 6, Enum3 = 80); // Only since Delphi 6\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2015/" ]
30,539
<p>I'm looking for a good way to enumerate all the Video codecs on a Windows XP/Vista machine.</p> <p>I need present the user with a set of video codecs, including the compressors and decompressors. The output would look something like</p> <pre> Available Decoders DiVX Version 6.0 XVID Motion JPEG CompanyX's MPEG-2 Decoder Windows Media Video **Available Encoders** DiVX Version 6.0 Windows Media Video </pre> <p>The problem that I am running into is that there is no reliable way to to capture all of the decoders available to the system. For instance:</p> <ol> <li>You can enumerate all the decompressors using DirectShow, but this tells you nothing about the compressors (encoders).</li> <li>You can enumerate all the Video For Windows components, but you get no indication if these are encoders or decoders.</li> <li>There are DirectShow filters that may do the job for you perfectly well (Motion JPEG filter for example), but there is no indication that a particular DirectShow filter is a "video decoder".</li> </ol> <p>Has anyone found a generalizes solution for this problem using any of the Windows APIs? Does the Windows Vista <a href="http://en.wikipedia.org/wiki/Media_Foundation" rel="nofollow noreferrer">Media Foundation API</a> solve any of these issues?</p>
[ { "answer_id": 30596, "author": "Christopher", "author_id": 3186, "author_profile": "https://Stackoverflow.com/users/3186", "pm_score": 4, "selected": true, "text": "HRESULT extractFriendlyName( IMoniker* pMk, std::wstring& str )\n{\n assert( pMk != 0 );\n IPropertyBag* pBag = 0;\n HRESULT hr = pMk->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag );\n if( FAILED( hr ) || pBag == 0 )\n {\n return hr;\n }\n VARIANT var;\n var.vt = VT_BSTR;\n hr = pBag->Read(L\"FriendlyName\", &var, NULL);\n if( SUCCEEDED( hr ) && var.bstrVal != 0 )\n {\n str = reinterpret_cast<wchar_t*>( var.bstrVal );\n SysFreeString(var.bstrVal);\n }\n pBag->Release();\n return hr;\n}\n\n\nHRESULT enumerateDShowFilterList( const CLSID& category )\n{\n HRESULT rval = S_OK;\n HRESULT hr;\n ICreateDevEnum* pCreateDevEnum = 0; // volatile, will be destroyed at the end\n hr = ::CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, reinterpret_cast<void**>( &pCreateDevEnum ) );\n\n assert( SUCCEEDED( hr ) && pCreateDevEnum != 0 );\n if( FAILED( hr ) || pCreateDevEnum == 0 )\n {\n return hr;\n }\n\n IEnumMoniker* pEm = 0;\n hr = pCreateDevEnum->CreateClassEnumerator( category, &pEm, 0 );\n\n // If hr == S_FALSE, no error is occured. In this case pEm is NULL, because\n // a filter does not exist e.g no video capture devives are connected to\n // the computer or no codecs are installed.\n assert( SUCCEEDED( hr ) && ((hr == S_OK && pEm != 0 ) || hr == S_FALSE) );\n if( FAILED( hr ) )\n {\n pCreateDevEnum->Release();\n return hr;\n }\n\n if( hr == S_OK && pEm != 0 ) // In this case pEm is != NULL\n {\n pEm->Reset();\n ULONG cFetched;\n IMoniker* pM = 0;\n while( pEm->Next(1, &pM, &cFetched) == S_OK && pM != 0 )\n {\n std::wstring str;\n\n if( SUCCEEDED( extractFriendlyName( pM, str ) )\n {\n // str contains the friendly name of the filter\n // pM->BindToObject creates the filter\n std::wcout << str << std::endl;\n }\n\n pM->Release();\n }\n pEm->Release();\n }\n pCreateDevEnum->Release();\n return rval;\n}\n" }, { "answer_id": 30669, "author": "Christopher", "author_id": 3186, "author_profile": "https://Stackoverflow.com/users/3186", "pm_score": 2, "selected": false, "text": "CLSID_ActiveMovieCategories\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2813/" ]
30,540
<p>This error just started popping up all over our site.</p> <p><strong><em>Permission denied to call method to Location.toString</em></strong></p> <p>I'm seeing google posts that suggest that this is related to flash and our crossdomain.xml. What caused this to occur and how do you fix?</p>
[ { "answer_id": 30561, "author": "Grey Panther", "author_id": 1265, "author_profile": "https://Stackoverflow.com/users/1265", "pm_score": 4, "selected": true, "text": "<iframe name=\"foo\" src=\"foo.com/script.js\">\n<iframe name=\"bar\" src=\"bar.com/script.js\">\n" }, { "answer_id": 30672, "author": "Kevin Goff", "author_id": 1940, "author_profile": "https://Stackoverflow.com/users/1940", "pm_score": 0, "selected": false, "text": "<allow-http-request-headers-from domain=\"*\" headers=\"*\"/>\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1940/" ]
30,563
<p>I have one field that I need to sum lets say named items However that field can be part of group a or b In the end I need to have all of the items summed for group a and group b</p> <p>when I say grouped I mean there is a LEFT OUTER JOIN to another table the previous table has a type for the items and the one being joined has a group assigned for this item type</p> <p>Sorry guys Im a little new to sql I am going to try out what you have given me an get back to you</p> <p>Ok I feel like we are getting close just not yet allain's I can get them to separate but the issue I need to have both groups to sum on the same row which is difficult because I also have several LEFT OUTER JOIN's involved</p> <p>Tyler's looks like it might work too so I am trying to hash that out real fast</p> <p>Alain's seems to be the way to go but I have to tweek it a little more</p>
[ { "answer_id": 30578, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 3, "selected": true, "text": "SELECT groupname, SUM(value)\nFROM items\nWHERE groupname IN ('a', 'b')\nGROUP BY groupname\n" }, { "answer_id": 30579, "author": "FreeMemory", "author_id": 2132, "author_profile": "https://Stackoverflow.com/users/2132", "pm_score": 0, "selected": false, "text": "SELECT column,SUM( column ) FROM table GROUP BY column\n" }, { "answer_id": 30584, "author": "Leigh Caldwell", "author_id": 3267, "author_profile": "https://Stackoverflow.com/users/3267", "pm_score": 0, "selected": false, "text": "SELECT sum(item), groupingField FROM someTable GROUP BY groupingField\n" }, { "answer_id": 30704, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 0, "selected": false, "text": "SELECT B.[Group], COUNT(*) AS GroupCount\nFROM Table1 A\nLEFT JOIN Table2 B ON B.ItemType=A.ItemType\nGROUP BY B.[Group]\n" }, { "answer_id": 59008474, "author": "Senthuran", "author_id": 8563654, "author_profile": "https://Stackoverflow.com/users/8563654", "pm_score": -1, "selected": false, "text": "SELECT category_id,SUM(amount) AS count FROM expense GROUP BY category_id;\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2486/" ]
30,569
<p>Does anyone have the secret formula to resizing transparent images (mainly GIFs) <em>without</em> ANY quality loss - what so ever?</p> <p>I've tried a bunch of stuff, the closest I get is not good enough.</p> <p>Take a look at my main image:</p> <p><a href="http://www.thewallcompany.dk/test/main.gif" rel="noreferrer">http://www.thewallcompany.dk/test/main.gif</a></p> <p>And then the scaled image:</p> <p><a href="http://www.thewallcompany.dk/test/ScaledImage.gif" rel="noreferrer">http://www.thewallcompany.dk/test/ScaledImage.gif</a></p> <pre><code>//Internal resize for indexed colored images void IndexedRezise(int xSize, int ySize) { BitmapData sourceData; BitmapData targetData; AdjustSizes(ref xSize, ref ySize); scaledBitmap = new Bitmap(xSize, ySize, bitmap.PixelFormat); scaledBitmap.Palette = bitmap.Palette; sourceData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); try { targetData = scaledBitmap.LockBits(new Rectangle(0, 0, xSize, ySize), ImageLockMode.WriteOnly, scaledBitmap.PixelFormat); try { xFactor = (Double)bitmap.Width / (Double)scaledBitmap.Width; yFactor = (Double)bitmap.Height / (Double)scaledBitmap.Height; sourceStride = sourceData.Stride; sourceScan0 = sourceData.Scan0; int targetStride = targetData.Stride; System.IntPtr targetScan0 = targetData.Scan0; unsafe { byte* p = (byte*)(void*)targetScan0; int nOffset = targetStride - scaledBitmap.Width; int nWidth = scaledBitmap.Width; for (int y = 0; y &lt; scaledBitmap.Height; ++y) { for (int x = 0; x &lt; nWidth; ++x) { p[0] = GetSourceByteAt(x, y); ++p; } p += nOffset; } } } finally { scaledBitmap.UnlockBits(targetData); } } finally { bitmap.UnlockBits(sourceData); } } </code></pre> <p>I'm using the above code, to do the indexed resizing.</p> <p>Does anyone have improvement ideas?</p>
[ { "answer_id": 30582, "author": "Dillie-O", "author_id": 71, "author_profile": "https://Stackoverflow.com/users/71", "pm_score": 3, "selected": false, "text": "/// <summary>\n/// Resize image with GDI+ so that image is nice and clear with required size.\n/// </summary>\n/// <param name=\"SourceImage\">Image to resize</param>\n/// <param name=\"NewHeight\">New height to resize to.</param>\n/// <param name=\"NewWidth\">New width to resize to.</param>\n/// <returns>Image object resized to new dimensions.</returns>\n/// <remarks></remarks>\npublic static Image ImageResize(Image SourceImage, Int32 NewHeight, Int32 NewWidth)\n{\n System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(NewWidth, NewHeight, SourceImage.PixelFormat);\n\n if (bitmap.PixelFormat == Drawing.Imaging.PixelFormat.Format1bppIndexed | bitmap.PixelFormat == Drawing.Imaging.PixelFormat.Format4bppIndexed | bitmap.PixelFormat == Drawing.Imaging.PixelFormat.Format8bppIndexed | bitmap.PixelFormat == Drawing.Imaging.PixelFormat.Undefined | bitmap.PixelFormat == Drawing.Imaging.PixelFormat.DontCare | bitmap.PixelFormat == Drawing.Imaging.PixelFormat.Format16bppArgb1555 | bitmap.PixelFormat == Drawing.Imaging.PixelFormat.Format16bppGrayScale) \n {\n throw new NotSupportedException(\"Pixel format of the image is not supported.\");\n }\n\n System.Drawing.Graphics graphicsImage = System.Drawing.Graphics.FromImage(bitmap);\n\n graphicsImage.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality;\n graphicsImage.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;\n graphicsImage.DrawImage(SourceImage, 0, 0, bitmap.Width, bitmap.Height);\n graphicsImage.Dispose();\n return bitmap; \n}\n" }, { "answer_id": 30593, "author": "Markus Olsson", "author_id": 2114, "author_profile": "https://Stackoverflow.com/users/2114", "pm_score": 7, "selected": true, "text": "using (Image src = Image.FromFile(\"main.gif\"))\nusing (Bitmap dst = new Bitmap(100, 129))\nusing (Graphics g = Graphics.FromImage(dst))\n{\n g.SmoothingMode = SmoothingMode.AntiAlias;\n g.InterpolationMode = InterpolationMode.HighQualityBicubic;\n g.DrawImage(src, 0, 0, dst.Width, dst.Height);\n dst.Save(\"scale.png\", ImageFormat.Png);\n}\n" }, { "answer_id": 870665, "author": "Bela", "author_id": 107932, "author_profile": "https://Stackoverflow.com/users/107932", "pm_score": 1, "selected": false, "text": "Response.ContentType = \"image/png\";\ndst.Save( Response.OutputStream, ImageFormat.Png );\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2972/" ]
30,571
<p>In Maven, dependencies are usually set up like this:</p> <pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt; &lt;groupId&gt;wonderful-inc&lt;/groupId&gt; &lt;artifactId&gt;dream-library&lt;/artifactId&gt; &lt;version&gt;1.2.3&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>Now, if you are working with libraries that have frequent releases, constantly updating the &lt;version&gt; tag can be somewhat annoying. Is there any way to tell Maven to always use the latest available version (from the repository)? </p>
[ { "answer_id": 30628, "author": "Martin Klinke", "author_id": 1793, "author_profile": "https://Stackoverflow.com/users/1793", "pm_score": 7, "selected": false, "text": "<version>[1.2.3,)</version>\n" }, { "answer_id": 1172371, "author": "Rich Seller", "author_id": 123582, "author_profile": "https://Stackoverflow.com/users/123582", "pm_score": 11, "selected": true, "text": "LATEST" }, { "answer_id": 8795380, "author": "Adam Gent", "author_id": 318174, "author_profile": "https://Stackoverflow.com/users/318174", "pm_score": 7, "selected": false, "text": "mvn clean versions:use-latest-versions scm:checkin deploy -Dmessage=\"update versions\" -DperformRelease=true\n" }, { "answer_id": 31568725, "author": "mkobit", "author_id": 627727, "author_profile": "https://Stackoverflow.com/users/627727", "pm_score": 5, "selected": false, "text": "version" }, { "answer_id": 31782879, "author": "trung", "author_id": 497300, "author_profile": "https://Stackoverflow.com/users/497300", "pm_score": 3, "selected": false, "text": "mvn -U dependency:copy -Dartifact=com.foo:my-foo:LATEST\n// pull the latest snapshot for my-foo from all repositories\n" }, { "answer_id": 43852216, "author": "Markon", "author_id": 126125, "author_profile": "https://Stackoverflow.com/users/126125", "pm_score": 3, "selected": false, "text": "<properties>\n <myname.version>1.1.1</myname.version>\n</properties>\n" }, { "answer_id": 49895638, "author": "Arayan Singh", "author_id": 9339242, "author_profile": "https://Stackoverflow.com/users/9339242", "pm_score": 3, "selected": false, "text": "<properties>\n <spring.version>3.1.2.RELEASE</spring.version>\n</properties>\n\n<dependencies>\n\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-core</artifactId>\n <version>${spring.version}</version>\n </dependency>\n\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-context</artifactId>\n <version>${spring.version}</version>\n </dependency>\n\n</dependencies>\n" }, { "answer_id": 52685301, "author": "yilin ", "author_id": 5673607, "author_profile": "https://Stackoverflow.com/users/5673607", "pm_score": 2, "selected": false, "text": "<dependency>\n <groupId>yilin.sheng</groupId>\n <artifactId>webspherecore</artifactId>\n <version>LATEST</version> \n</dependency>\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1709/" ]
30,585
<p>Has anyone ever set up Cruise Control to build an OS X Cocoa/Objective-C project?</p> <p>If so, is there a preferred flavor of CruiseControl (CruiseControl.rb or just regular CruiseControl) that would be easier to do this with. </p> <p>I currently have a Ruby rake file that has steps for doing building and running tests, and wanted to automate this process after doing a checkin. </p> <p>Also, does CruiseControl have support for git? I couldn't find anything on the website for this.</p>
[ { "answer_id": 30705, "author": "Chris Blackwell", "author_id": 1329401, "author_profile": "https://Stackoverflow.com/users/1329401", "pm_score": 4, "selected": true, "text": "<exec>" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2813/" ]
30,627
<p>I'm looking for the best method to parse various XML documents using a Java application. I'm currently doing this with SAX and a custom content handler and it works great - zippy and stable. </p> <p>I've decided to explore the option having the same program, that currently recieves a single format XML document, receive two additional XML document formats, with various XML element changes. I was hoping to just swap out the ContentHandler with an appropriate one based on the first "startElement" in the document... but, uh-duh, the ContentHandler is set and <strong>then</strong> the document is parsed!</p> <pre><code>... constructor ... { SAXParserFactory spf = SAXParserFactory.newInstance(); try { SAXParser sp = spf.newSAXParser(); parser = sp.getXMLReader(); parser.setErrorHandler(new MyErrorHandler()); } catch (Exception e) {} ... parse StringBuffer ... try { parser.setContentHandler(pP); parser.parse(new InputSource(new StringReader(xml.toString()))); return true; } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } ... </code></pre> <p>So, it doesn't appear that I can do this in the way I initially thought I could.</p> <p>That being said, am I looking at this entirely wrong? What is the best method to parse multiple, discrete XML documents with the same XML handling code? <a href="https://stackoverflow.com/questions/23106/best-method-to-parse-various-custom-xml-documents-in-java">I tried to ask in a more general post earlier... but, I think I was being too vague</a>. For speed and efficiency purposes I never really looked at DOM because these XML documents are fairly large and the system receives about 1200 every few minutes. It's just a one way send of information</p> <p>To make this question too long and add to my confusion; following is a mockup of some various XML documents that I would like to have a single SAX, StAX, or ?? parser cleanly deal with. </p> <p>products.xml:</p> <pre><code>&lt;products&gt; &lt;product&gt; &lt;id&gt;1&lt;/id&gt; &lt;name&gt;Foo&lt;/name&gt; &lt;product&gt; &lt;id&gt;2&lt;/id&gt; &lt;name&gt;bar&lt;/name&gt; &lt;/product&gt; &lt;/products&gt; </code></pre> <p>stores.xml:</p> <pre><code>&lt;stores&gt; &lt;store&gt; &lt;id&gt;1&lt;/id&gt; &lt;name&gt;S1A&lt;/name&gt; &lt;location&gt;CA&lt;/location&gt; &lt;/store&gt; &lt;store&gt; &lt;id&gt;2&lt;/id&gt; &lt;name&gt;A1S&lt;/name&gt; &lt;location&gt;NY&lt;/location&gt; &lt;/store&gt; &lt;/stores&gt; </code></pre> <p>managers.xml:</p> <pre><code>&lt;managers&gt; &lt;manager&gt; &lt;id&gt;1&lt;/id&gt; &lt;name&gt;Fen&lt;/name&gt; &lt;store&gt;1&lt;/store&gt; &lt;/manager&gt; &lt;manager&gt; &lt;id&gt;2&lt;/id&gt; &lt;name&gt;Diz&lt;/name&gt; &lt;store&gt;2&lt;/store&gt; &lt;/manager&gt; &lt;/managers&gt; </code></pre>
[ { "answer_id": 30689, "author": "Bernie Perez", "author_id": 1992, "author_profile": "https://Stackoverflow.com/users/1992", "pm_score": 2, "selected": false, "text": "public class DataStructure {\n\n List<ProductStructure> products;\n\n List<StoreStructure> stors;\n\n List<ManagerStructure> managers;\n\n ...\n\n public int getProductCount() {\n return products.lenght();\n }\n\n ...\n}\n" }, { "answer_id": 30697, "author": "McDowell", "author_id": 304, "author_profile": "https://Stackoverflow.com/users/304", "pm_score": 3, "selected": true, "text": "public class DelegatingHandler extends DefaultHandler {\n\n private Map<String, DefaultHandler> saxHandlers;\n private DefaultHandler delegate = null;\n\n public DelegatingHandler(Map<String, DefaultHandler> delegates) {\n saxHandlers = delegates;\n }\n\n @Override\n public void startElement(String uri, String localName, String name,\n Attributes attributes) throws SAXException {\n if(delegate == null) {\n delegate = saxHandlers.get(name);\n }\n delegate.startElement(uri, localName, name, attributes);\n }\n\n @Override\n public void endElement(String uri, String localName, String name)\n throws SAXException {\n delegate.endElement(uri, localName, name);\n }\n\n//etcetera...\n" }, { "answer_id": 30896, "author": "jelovirt", "author_id": 2679, "author_profile": "https://Stackoverflow.com/users/2679", "pm_score": 2, "selected": false, "text": "SelectorContentHandler" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/828/" ]
30,651
<p>I would like to know if I can open 2 different diagrams using MS Visio and each diagram have its own window. I've tried in several ways, but I always end up with 1 Visio window ...</p> <p>I'm using a triple monitor setup and I'd like to put one diagram to each side of my main monitor.</p> <p>[]'s</p> <p>André Casteliano</p> <p>PS: I'm using Visio 2007 here.</p>
[ { "answer_id": 7533665, "author": "J D", "author_id": 961821, "author_profile": "https://Stackoverflow.com/users/961821", "pm_score": 5, "selected": false, "text": "Tools -> Options -> Advanced" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1213/" ]
30,660
<p>I'm running a master-slave MySQL binary log replication system (phew!) that, for some data, is not in sync (meaning, the master holds more data than the slave). But the slave stops very frequently on the slightest MySQL error, can this be disabled? (perhaps a my.cnf setting for the replicating slave ignore-replicating-errors or some of the sort ;) )</p> <p>This is what happens, every now and then, when the slave tries to replicate an item that does not exist, the slave just dies. a quick check at <strong>SHOW SLAVE STATUS \G;</strong> gives</p> <pre><code> Slave-IO-Running: Yes Slave-SQL-Running: No Replicate-Do-DB: Last-Errno: 1062 Last-Error: Error 'Duplicate entry '15218' for key 1' on query. Default database: 'db'. Query: 'INSERT INTO db.table ( FIELDS ) VALUES ( VALUES )' </code></pre> <p>which I promptly fix (once I realize that the slave has been stopped) by doing the following:</p> <pre><code>STOP SLAVE; RESET SLAVE; START SLAVE; </code></pre> <p>... lately this has been getting kind of tiresome, and before I spit out some sort of PHP which does this for me, i was wondering if there's some my.cnf entry which will not kill the slave on the first error.</p> <p>Cheers,</p> <p>/mp</p>
[ { "answer_id": 30714, "author": "thelsdj", "author_id": 163, "author_profile": "https://Stackoverflow.com/users/163", "pm_score": 2, "selected": false, "text": "mysqldump" }, { "answer_id": 60722, "author": "Erik", "author_id": 4484, "author_profile": "https://Stackoverflow.com/users/4484", "pm_score": 1, "selected": false, "text": "read_only" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30660", "https://Stackoverflow.com", "https://Stackoverflow.com/users/547/" ]
30,686
<p>How can you get the version information from a <code>.dll</code> or <code>.exe</code> file in PowerShell?</p> <p>I am specifically interested in <code>File Version</code>, though other version information (that is, <code>Company</code>, <code>Language</code>, <code>Product Name</code>, etc.) would be helpful as well.</p>
[ { "answer_id": 30702, "author": "EBGreen", "author_id": 1358, "author_profile": "https://Stackoverflow.com/users/1358", "pm_score": 3, "selected": false, "text": "[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"Path\\To\\File.dll\")\n" }, { "answer_id": 30708, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 8, "selected": true, "text": "[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"somefilepath\").FileVersion\n" }, { "answer_id": 30709, "author": "Adam Haile", "author_id": 194, "author_profile": "https://Stackoverflow.com/users/194", "pm_score": 2, "selected": false, "text": "[System.Diagnostics.FileVersionInfo]::GetVersionInfo(path).CompanyName\n" }, { "answer_id": 66005, "author": "Jaykul", "author_id": 8718, "author_profile": "https://Stackoverflow.com/users/8718", "pm_score": 8, "selected": false, "text": "FileVersionRaw" }, { "answer_id": 2159806, "author": "xcud", "author_id": 61396, "author_profile": "https://Stackoverflow.com/users/61396", "pm_score": 6, "selected": false, "text": "PS C:\\Windows> (dir .\\write.exe).VersionInfo | fl\n\n\nOriginalFilename : write\nFileDescription : Windows Write\nProductName : Microsoft® Windows® Operating System\nComments :\nCompanyName : Microsoft Corporation\nFileName : C:\\Windows\\write.exe\nFileVersion : 6.1.7600.16385 (win7_rtm.090713-1255)\nProductVersion : 6.1.7600.16385\nIsDebug : False\nIsPatched : False\nIsPreRelease : False\nIsPrivateBuild : False\nIsSpecialBuild : False\nLanguage : English (United States)\nLegalCopyright : © Microsoft Corporation. All rights reserved.\nLegalTrademarks :\nPrivateBuild :\nSpecialBuild :\n" }, { "answer_id": 6959632, "author": "Wes", "author_id": 880959, "author_profile": "https://Stackoverflow.com/users/880959", "pm_score": 4, "selected": false, "text": "(get-item .\\filename.exe).VersionInfo | FL\n" }, { "answer_id": 11740080, "author": "Chriseyre2000", "author_id": 662571, "author_profile": "https://Stackoverflow.com/users/662571", "pm_score": 2, "selected": false, "text": "function Get-Version($filePath)\n{\n $name = @{Name=\"Name\";Expression= {split-path -leaf $_.FileName}}\n $path = @{Name=\"Path\";Expression= {split-path $_.FileName}}\n dir -recurse -path $filePath | % { if ($_.Name -match \"(.*dll|.*exe)$\") {$_.VersionInfo}} | select FileVersion, $name, $path\n}\n" }, { "answer_id": 20265055, "author": "noelicus", "author_id": 865643, "author_profile": "https://Stackoverflow.com/users/865643", "pm_score": 3, "selected": false, "text": "(Get-Command C:\\Path\\YourFile.Dll).FileVersionInfo.FileVersion\n" }, { "answer_id": 25166557, "author": "Knuckle-Dragger", "author_id": 3093031, "author_profile": "https://Stackoverflow.com/users/3093031", "pm_score": 1, "selected": false, "text": "(Get-WmiObject -Class CIM_DataFile -Filter \"Name='C:\\\\Windows\\\\explorer.exe'\" | Select-Object Version).Version\n" }, { "answer_id": 50967364, "author": "m-smith", "author_id": 515857, "author_profile": "https://Stackoverflow.com/users/515857", "pm_score": 4, "selected": false, "text": "ls application.exe | % versioninfo\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30686", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2495/" ]
30,710
<p>I've heard that unit testing is "totally awesome", "really cool" and "all manner of good things" but 70% or more of my files involve database access (some read and some write) and I'm not sure how to write a unit test for these files.</p> <p>I'm using PHP and Python but I think it's a question that applies to most/all languages that use database access.</p>
[ { "answer_id": 30715, "author": "Sean Chambers", "author_id": 2993, "author_profile": "https://Stackoverflow.com/users/2993", "pm_score": 5, "selected": false, "text": "NHibernate" }, { "answer_id": 30759, "author": "Marcin", "author_id": 3105, "author_profile": "https://Stackoverflow.com/users/3105", "pm_score": 3, "selected": false, "text": "User" }, { "answer_id": 30772, "author": "BZ.", "author_id": 2349, "author_profile": "https://Stackoverflow.com/users/2349", "pm_score": 4, "selected": false, "text": " [Test]\n [ExpectedException(typeof(NotFoundException))]\n public void DeleteAttendee() {\n\n using(TransactionScope scope = new TransactionScope()) {\n Attendee anAttendee = Attendee.Get(3);\n anAttendee.Delete();\n anAttendee.Save();\n\n //Try reloading. Instance should have been deleted.\n Attendee deletedAttendee = Attendee.Get(3);\n }\n }\n" }, { "answer_id": 30818, "author": "Doug R", "author_id": 3271, "author_profile": "https://Stackoverflow.com/users/3271", "pm_score": 7, "selected": true, "text": "class Bar\n{\n private FooDataProvider _dataProvider;\n\n public instantiate(FooDataProvider dataProvider) {\n _dataProvider = dataProvider;\n }\n\n public getAllFoos() {\n // instead of calling Foo.GetAll() here, we are introducing an extra layer of abstraction\n return _dataProvider.GetAllFoos();\n }\n}\n\nclass FooDataProvider\n{\n public Foo[] GetAllFoos() {\n return Foo.GetAll();\n }\n}\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30710", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
30,729
<p>I want to create a simple http proxy server that does some very basic processing on the http headers (i.e. if header x == y, do z). The server may need to support hundreds of users. I can write the server in C# (pretty easy) or c++ (much harder). However, would a C# version have as good of performance as a C++ version? If not, would the difference in performance be big enough that it would not make sense to write it in C#?</p>
[ { "answer_id": 30755, "author": "Brian Ensink", "author_id": 1254, "author_profile": "https://Stackoverflow.com/users/1254", "pm_score": 0, "selected": false, "text": "if header x == y, do z\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30729", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3291/" ]
30,754
<p>Reading <a href="https://stackoverflow.com/questions/437/what-is-your-solution-to-the-fizzbuzz-problem">this question</a> I found this as (note the quotation marks) "code" to solve the problem (that's perl by the way). </p> <pre><code>100,{)..3%!'Fizz'*\5%!'Buzz'*+\or}%n* </code></pre> <p>Obviously this is an intellectual example without real (I hope to never see that in real code in my life) implications but, when you have to make the choice, when do you sacrifice code readability for performance? Do you apply just common sense, do you do it always as a last resort? What are your strategies?</p> <p>Edit: I'm sorry, seeing the answers I might have expressed the question badly (English is not my native language). I don't mean performance vs readability only <strong>after</strong> you've written the code, I ask about before you write it as well. Sometimes you can foresee a performance improvement in the future by making some darker design or providing with some properties that will make your class darker. You may decide you will use multiple threads or just a single one because you expect the scalability that such threads may give you, even when that will make the code much more difficult to understand.</p>
[ { "answer_id": 188736, "author": "Lev", "author_id": 7224, "author_profile": "https://Stackoverflow.com/users/7224", "pm_score": 0, "selected": false, "text": "typedef Pixel PixelModifierFunction(Pixel);\n\nvoid ModifyAllPixels(PixelModifierFunction);\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2695/" ]
30,763
<p>I have class method that returns a list of employees that I can iterate through. What's the best way to return the list? Typically I just return an ArrayList. However, as I understand, interfaces are better suited for this type of action. Which would be the best interface to use? Also, why is it better to return an interface, rather than the implementation (say ArrayList object)? It just seems like a lot more work to me.</p>
[ { "answer_id": 30774, "author": "levand", "author_id": 3044, "author_profile": "https://Stackoverflow.com/users/3044", "pm_score": 1, "selected": false, "text": "<Employee" }, { "answer_id": 30780, "author": "Marcin", "author_id": 3105, "author_profile": "https://Stackoverflow.com/users/3105", "pm_score": 0, "selected": false, "text": "IList<Employee>" }, { "answer_id": 30819, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 1, "selected": false, "text": "IEnumerable<Employee>" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2121/" ]
30,781
<p>What are the ways to retrieve data submitted to the web server from a form in the client HTML in ASP.NET?</p>
[ { "answer_id": 30784, "author": "Adam", "author_id": 1341, "author_profile": "https://Stackoverflow.com/users/1341", "pm_score": 0, "selected": false, "text": "value = Request.Form(\"formElementID\")\n" }, { "answer_id": 30792, "author": "palehorse", "author_id": 312, "author_profile": "https://Stackoverflow.com/users/312", "pm_score": 3, "selected": true, "text": "value = Request(\"formElementID\")\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1341/" ]
30,835
<p>Is there any Visual Studio Express plug ins for source versioning? I am starting a project on my own and only have the Express version of Visual Studio 2008.</p>
[ { "answer_id": 3732029, "author": "Wil", "author_id": 321053, "author_profile": "https://Stackoverflow.com/users/321053", "pm_score": 5, "selected": false, "text": "Title: HG New Repositry \nCommand: C:\\Program Files\\TortoiseHg\\hgtk.exe\nArguments: --nofork init Initial\ndirectory: $(SolutionDir)\n\nTitle: HG Commit \nCommand: C:\\Program Files\\TortoiseHg\\hgtk.exe \nArguments: --nofork init Initial directory: $(SolutionDir)\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30835", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2535/" ]
30,847
<p>How does one go about authoring a <em><strong>Regular Expression</strong></em> that matches against all strings that are valid URIs, while failing to match against all strings that are invalid URIs?</p> <p>To be specific about what I am referencing when I say URI, I have added a link below for the most current URI RFC standard. It defines the entity that I want to validate using a regular expression.</p> <p>I don't need it to be able to parse the URI. I just need a regular expression for validating.</p> <p>The <strong>.Net Regular Expression Format</strong> is preferred. (.Net V1.1)</p> <br> <h4>My Current Solution:</h4> <pre><code>^([a-zA-Z0-9+.-]+):(//([a-zA-Z0-9-._~!$&amp;'()*+,;=:]*)@)?([a-zA-Z0-9-._~!$&amp;'()*+,;=]+)(:(\\d*))?(/?[a-zA-Z0-9-._~!$&amp;'()*+,;=:/]+)?(\\?[a-zA-Z0-9-._~!$&amp;'()*+,;=:/?@]+)?(#[a-zA-Z0-9-._~!$&amp;'()*+,;=:/?@]+)?$(:(\\d*))?(/?[a-zA-Z0-9-._~!$&amp;'()*+,;=:/]+)?(\?[a-zA-Z0-9-._~!$&amp;'()*+,;=:/?@]+)?(\#[a-zA-Z0-9-._~!$&amp;'()*+,;=:/?@]+)?$ </code></pre>
[ { "answer_id": 30910, "author": "Daren Thomas", "author_id": 2260, "author_profile": "https://Stackoverflow.com/users/2260", "pm_score": 5, "selected": true, "text": "/^([a-z0-9+.-]+):(?://(?:((?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(?::(\\d*))?(/(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?|(/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?)(?:\\?((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?(?:#((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?$/i\n" }, { "answer_id": 10575584, "author": "jcsahnwaldt Reinstate Monica", "author_id": 131160, "author_profile": "https://Stackoverflow.com/users/131160", "pm_score": 4, "selected": false, "text": "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?" }, { "answer_id": 17813893, "author": "papercowboy", "author_id": 641934, "author_profile": "https://Stackoverflow.com/users/641934", "pm_score": 3, "selected": false, "text": "# RFC-3986 URI component: URI\n[A-Za-z][A-Za-z0-9+\\-.]* : # scheme \":\"\n(?: // # hier-part\n (?: (?:[A-Za-z0-9\\-._~!$&'()*+,;=:]|%[0-9A-Fa-f]{2})* @)?\n (?:\n \\[\n (?:\n (?:\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 [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 | [Vv][0-9A-Fa-f]+\\.[A-Za-z0-9\\-._~!$&'()*+,;=:]+\n )\n \\]\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 | (?:[A-Za-z0-9\\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*\n )\n (?: : [0-9]* )?\n (?:/ (?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})* )*\n| /\n (?: (?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+\n (?:/ (?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})* )*\n )?\n| (?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+\n (?:/ (?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})* )*\n|\n)\n(?:\\? (?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})* )? # [ \"?\" query ]\n(?:\\# (?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})* )? # [ \"#\" fragment ]\n" }, { "answer_id": 45690571, "author": "Lostfields", "author_id": 6330937, "author_profile": "https://Stackoverflow.com/users/6330937", "pm_score": 3, "selected": false, "text": "// named groups\n/^(?<scheme>[a-z][a-z0-9+.-]+):(?<authority>\\/\\/(?<user>[^@]+@)?(?<host>[a-z0-9.\\-_~]+)(?<port>:\\d+)?)?(?<path>(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])+(?:\\/(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])*)*|(?:\\/(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])+)*)?(?<query>\\?(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@]|[/?])+)?(?<fragment>\\#(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@]|[/?])+)?$/i\n\n// unnamed groups\n/^([a-z][a-z0-9+.-]+):(\\/\\/([^@]+@)?([a-z0-9.\\-_~]+)(:\\d+)?)?((?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])+(?:\\/(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])*)*|(?:\\/(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@])+)*)?(\\?(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@]|[/?])+)?(\\#(?:[a-z0-9-._~]|%[a-f0-9]|[!$&'()*+,;=:@]|[/?])+)?$/i\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/80/" ]
30,856
<p>How do I write the results from a mysql query to file? I just need something quick. Output can be CSV, XML, HTML, etc.</p>
[ { "answer_id": 30868, "author": "Matt Rogish", "author_id": 2590, "author_profile": "https://Stackoverflow.com/users/2590", "pm_score": 5, "selected": true, "text": "SELECT a,b,a+b \n FROM test_table\n INTO OUTFILE '/tmp/result.txt'\n FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'\n LINES TERMINATED BY '\\n'\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2363/" ]
30,861
<p>Given a username and a password for a domain user, what would be the best way to authenticate that user programatically?</p>
[ { "answer_id": 31665, "author": "David J. Sokol", "author_id": 1390, "author_profile": "https://Stackoverflow.com/users/1390", "pm_score": 3, "selected": false, "text": "Try\n Dim directoryEntry as New DirectoryEntry(\"LDAP://DomainController:389/dc=domain,dc=suffix\", \"username\", \"password\")\n Dim temp as Object = directoryEntry.NativeObject\n return true\nCatch\n return false\nEnd Try\n" }, { "answer_id": 32669, "author": "John Christensen", "author_id": 1194, "author_profile": "https://Stackoverflow.com/users/1194", "pm_score": 4, "selected": false, "text": "Private Function ValidateExternalUser(ByVal username As String, ByVal password As String) As Boolean\n Using context As PrincipalContext = New PrincipalContext(ContextType.Domain, _defaultDomain)\n Return context.ValidateCredentials(username, password, ContextOptions.Negotiate)\n End Using\nEnd Function\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1194/" ]
30,877
<p>I actually have an answer to my question but it is not parallelized so I am interested in ways to improve the algorithm. Anyway it might be useful as-is for some people.</p> <pre><code>int Until = 20000000; BitArray PrimeBits = new BitArray(Until, true); /* * Sieve of Eratosthenes * PrimeBits is a simple BitArray where all bit is an integer * and we mark composite numbers as false */ PrimeBits.Set(0, false); // You don't actually need this, just PrimeBits.Set(1, false); // remindig you that 2 is the smallest prime for (int P = 2; P &lt; (int)Math.Sqrt(Until) + 1; P++) if (PrimeBits.Get(P)) // These are going to be the multiples of P if it is a prime for (int PMultiply = P * 2; PMultiply &lt; Until; PMultiply += P) PrimeBits.Set(PMultiply, false); // We use this to store the actual prime numbers List&lt;int&gt; Primes = new List&lt;int&gt;(); for (int i = 2; i &lt; Until; i++) if (PrimeBits.Get(i)) Primes.Add(i); </code></pre> <p>Maybe I could use multiple <code>BitArray</code>s and <a href="http://msdn.microsoft.com/en-us/library/system.collections.bitarray.and.aspx" rel="noreferrer">BitArray.And()</a> them together?</p>
[ { "answer_id": 31604423, "author": "Raj", "author_id": 3872129, "author_profile": "https://Stackoverflow.com/users/3872129", "pm_score": -1, "selected": false, "text": " void PrimeNumber(long number)\n {\n bool IsprimeNumber = true;\n long value = Convert.ToInt32(Math.Sqrt(number));\n if (number % 2 == 0)\n {\n IsprimeNumber = false;\n MessageBox.Show(\"No It is not a Prime NUmber\");\n return;\n }\n for (long i = 3; i <= value; i=i+2)\n { \n if (number % i == 0)\n {\n\n MessageBox.Show(\"It is divisible by\" + i);\n IsprimeNumber = false;\n break;\n }\n\n }\n if (IsprimeNumber)\n {\n MessageBox.Show(\"Yes Prime NUmber\");\n }\n else\n {\n MessageBox.Show(\"No It is not a Prime NUmber\");\n }\n }\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3063/" ]
30,879
<p>Is there a pattern using Linq to dynamically create a filter?</p> <p>I have the need to create custom filtering on a list, in the past I would just dynamically create the SQL...it doesn't seem like this is possible with Linq.</p>
[ { "answer_id": 30887, "author": "Geoff", "author_id": 1097, "author_profile": "https://Stackoverflow.com/users/1097", "pm_score": 5, "selected": true, "text": "Dim Northwind As New NorthwindDataContext\nDim query = From q In Northwind.Products Where p.CategoryID = 2 And p.UnitPrice > 3 Order By p.SupplierID Select p\n\nGridview1.DataSource = query\nGridView1.DataBind()\n" }, { "answer_id": 30895, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 2, "selected": false, "text": "var myList = new List<string> { \"a\",\"b\",\"c\" };\nvar items = from item in db.Items\n where myList.Contains(item.Name)\n select item;\n" }, { "answer_id": 241290, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 4, "selected": false, "text": "IQueryable<Customer> query = db.Customers;\n\nif (searchingByName)\n{\n query = query.Where(c => c.Name.StartsWith(someletters));\n}\nif (searchingById)\n{\n query = query.Where(c => c.Id == Id);\n}\nif (searchingByDonuts)\n{\n query = query.Where(c => c.Donuts.Any(d => !d.IsEaten));\n}\nquery = query.OrderBy(c => c.Name);\nList<Customer> = query.Take(10).ToList();\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2858/" ]
30,884
<p>Suppose you have two seperate ASP.NET Web Application projects that both need to use a common MasterPage.</p> <p>What's the best way to share the MasterPage across projects without having to duplicate code? Preferably without having to resort to source control or file system hacks.</p>
[ { "answer_id": 94027, "author": "Chris James", "author_id": 3193, "author_profile": "https://Stackoverflow.com/users/3193", "pm_score": 0, "selected": false, "text": "System.Web.UI.MasterPage\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30884", "https://Stackoverflow.com", "https://Stackoverflow.com/users/247/" ]
30,903
<p>Is there a good, native Mac tool to view Mercurial repositories, similar to gitnub for Git?</p>
[ { "answer_id": 30943, "author": "nlucaroni", "author_id": 157, "author_profile": "https://Stackoverflow.com/users/157", "pm_score": 1, "selected": false, "text": "hg view" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30903", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3071/" ]
30,928
<p>[We have a Windows Forms database front-end application that, among other things, can be used as a CMS; clients create the structure, fill it, and then use a ASP.NET WebForms-based site to present the results to publicly on the Web. For added flexibility, they are sometimes forced to input actual HTML markup right into a text field, which then ends up as a varchar in the database. This works, but it's far from user-friendly.]</p> <p>As such… some clients want a WYSIWYG editor for HTML. I'd like to convince them that they'd benefit from using simpler language (namely, Markdown). Ideally, what I'd like to have is a WYSIWYG editor for that. They don't need tables, or anything sophisticated like that.</p> <p>A cursory search reveals <a href="http://aspnetresources.com/blog/markdown_announced.aspx" rel="noreferrer">a .NET Markdown to HTML converter</a>, and then we have <a href="http://www.codeproject.com/KB/edit/editor_in_windows_forms.aspx" rel="noreferrer">a Windows Forms-based text editor that outputs HTML</a>, but apparently nothing that brings the two together. As a result, we'd still have our varchars with markup in there, but at least it would be both quite human-readable and still easily parseable.</p> <p>Would this — a WYSIWYG editor that outputs Markdown, which is then later on parsed into HTML in ASP.NET — be feasible? Any alternative suggestions?</p>
[ { "answer_id": 58964550, "author": "KyleMit", "author_id": 1366033, "author_profile": "https://Stackoverflow.com/users/1366033", "pm_score": 4, "selected": false, "text": "SplitContainer" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1600/" ]
30,931
<p>I'm developing a Linux application that has its own file format. I want my app to open when you double-click on those files.</p> <p>How can I register a file extension and associate it with my application on Linux? I'm looking for a way that is standard (works with GNOME and KDE based systems) and can be done automatic when my program is installed or run for the first time.</p>
[ { "answer_id": 31836, "author": "skolima", "author_id": 3205, "author_profile": "https://Stackoverflow.com/users/3205", "pm_score": 7, "selected": true, "text": "xdg-utils" }, { "answer_id": 21085981, "author": "fastrizwaan", "author_id": 3189318, "author_profile": "https://Stackoverflow.com/users/3189318", "pm_score": 2, "selected": false, "text": "1. your application icon -> $APP = FIREFOX.png \n2. your mimetype icon -> application-x-$APP = HTML.png\n" }, { "answer_id": 73411313, "author": "phil294", "author_id": 3779853, "author_profile": "https://Stackoverflow.com/users/3779853", "pm_score": 0, "selected": false, "text": "#!/bin/bash\nset -e # stop on error\n\nAPP=my-app\nEXT=my-app\nCOMMENT=Comment\nEXEC=/usr/bin/my-app\nLOGO=./logo.png\n\nxdg-icon-resource install --context mimetypes --size 48 $LOGO application-x-$APP\n\necho \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\n<mime-info xmlns=\\\"http://www.freedesktop.org/standards/shared-mime-info\\\">\n <mime-type type=\\\"application/x-$APP\\\">\n <comment>$COMMENT</comment>\n <icon name=\\\"application-x-$APP\\\"/>\n <glob pattern=\\\"*.$EXT\\\"/>\n </mime-type>\n</mime-info>\" > $APP-mime.xml\n\nxdg-mime install $APP-mime.xml\nrm $APP-mime.xml\nupdate-mime-database $HOME/.local/share/mime\n\necho \"[Desktop Entry]\nName=$APP\nExec=$EXEC %U\nMimeType=application/x-$APP\nIcon=application-x-$APP\nTerminal=false\nType=Application\nCategories=\nComment=$COMMENT\n\"> $APP.desktop\ndesktop-file-install --dir=$HOME/.local/share/applications $APP.desktop\nrm $APP.desktop\nupdate-desktop-database $HOME/.local/share/applications\n\nxdg-mime default $APP.desktop application/x-$APP\n\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3306/" ]
30,946
<p>What is a good, simple encryption scheme for protecting passwords in a database? I don't necessarily need anything that's hyper-secure nor do I need anything that's lightning fast, but those things would be nice. Primarily, I just want something that's easy to implement without being terribly slow or insecure.</p>
[ { "answer_id": 30952, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 3, "selected": false, "text": "MD5CryptoServiceProvider hasher = new MD5CryptoServiceProvider();\nstring addSalt = string.Concat( \"ummm salty \", password );\nbyte[] hash = hasher.ComputeHash( Encoding.Unicode.GetBytes( addSalt ) );\n" }, { "answer_id": 30979, "author": "Neall", "author_id": 619, "author_profile": "https://Stackoverflow.com/users/619", "pm_score": 5, "selected": true, "text": "bcrypt" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30946", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2147/" ]
30,985
<p>I recently had to solve this problem and find I've needed this info many times in the past so I thought I would post it. Assuming the following table def, how would you write a query to find all differences between the two?</p> <p>table def:</p> <pre><code>CREATE TABLE feed_tbl ( code varchar(15), name varchar(40), status char(1), update char(1) CONSTRAINT feed_tbl_PK PRIMARY KEY (code) CREATE TABLE data_tbl ( code varchar(15), name varchar(40), status char(1), update char(1) CONSTRAINT data_tbl_PK PRIMARY KEY (code) </code></pre> <p>Here is my solution, as a view using three queries joined by unions. The <code>diff_type</code> specified is how the record needs updated: deleted from <code>_data(2)</code>, updated in <code>_data(1)</code>, or added to <code>_data(0)</code></p> <pre><code>CREATE VIEW delta_vw AS ( SELECT feed_tbl.code, feed_tbl.name, feed_tbl.status, feed_tbl.update, 0 as diff_type FROM feed_tbl LEFT OUTER JOIN data_tbl ON feed_tbl.code = data_tbl.code WHERE (data_tbl.code IS NULL) UNION SELECT feed_tbl.code, feed_tbl.name, feed_tbl.status, feed_tbl.update, 1 as diff_type FROM data_tbl RIGHT OUTER JOIN feed_tbl ON data_tbl.code = feed_tbl.code where (feed_tbl.name &lt;&gt; data_tbl.name) OR (data_tbl.status &lt;&gt; feed_tbl.status) OR (data_tbl.update &lt;&gt; feed_tbl.update) UNION SELECT data_tbl.code, data_tbl.name, data_tbl.status, data_tbl.update, 2 as diff_type FROM feed_tbl LEFT OUTER JOIN data_tbl ON data_tbl.code = feed_tbl.code WHERE (feed_tbl.code IS NULL) ) </code></pre>
[ { "answer_id": 31043, "author": "wcm", "author_id": 2173, "author_profile": "https://Stackoverflow.com/users/2173", "pm_score": 0, "selected": false, "text": "union" }, { "answer_id": 31060, "author": "hova", "author_id": 2170, "author_profile": "https://Stackoverflow.com/users/2170", "pm_score": 0, "selected": false, "text": "FULL OUTER JOIN" }, { "answer_id": 31061, "author": "JosephStyons", "author_id": 672, "author_profile": "https://Stackoverflow.com/users/672", "pm_score": 2, "selected": false, "text": "select dt.*\nfrom\n data_tbl dt\n ,( \n select code\n from\n ( \n select * from feed_tbl\n union\n select * from data_tbl \n )\n group by code\n having count(*) > 1 \n ) diffs --\"diffs\" will return all differences *except* those in the primary key itself \nwhere diffs.code = dt.code\nunion --plus the ones that are only in feed, but not in data\nselect * from feed_tbl ft where not exists(select code from data_tbl dt where dt.code = ft.code)\nunion --plus the ones that are only in data, but not in feed\nselect * from data_tbl dt where not exists(select code from feed_tbl ft where ft.code = dt.code)\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30985", "https://Stackoverflow.com", "https://Stackoverflow.com/users/292/" ]
30,998
<p>I like to use static functions in C++ as a way to categorize them, like C# does.</p> <pre><code>Console::WriteLine("hello") </code></pre> <p>Is this good or bad? If the functions are used often I guess it doesn't matter, but if not do they put pressure on memory?</p> <p>What about <code>static const</code>?</p>
[ { "answer_id": 31004, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 3, "selected": false, "text": "static class" }, { "answer_id": 31119, "author": "Tim Frey", "author_id": 1471, "author_profile": "https://Stackoverflow.com/users/1471", "pm_score": 1, "selected": false, "text": "public class TotalManager\n{\n public double getTotal(Hamburger burger)\n {\n return burger.getPrice() + burget.getTax();\n }\n}\n" }, { "answer_id": 31213, "author": "Johannes Hoff", "author_id": 3102, "author_profile": "https://Stackoverflow.com/users/3102", "pm_score": 2, "selected": false, "text": "namespace Console {\n void WriteLine(...) // ...\n}\n" }, { "answer_id": 10656010, "author": "Andrew", "author_id": 1403796, "author_profile": "https://Stackoverflow.com/users/1403796", "pm_score": 2, "selected": false, "text": "class X\n{\n public:\n static void f1 ()\n {\n ...\n f2 ();\n }\n\n private:\n static void f2 () {}\n};\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/30998", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2566/" ]
31,007
<p>I build up an array of strings with</p> <pre><code>string[] parts = string.spilt(" "); </code></pre> <p>And get an array with X parts in it, I would like to get a copy of the array of strings starting at element </p> <pre><code>parts[x-2] </code></pre> <p>Other than the obvious brute force approach (make a new array and insert strings), is there a more elegant way to do this in C#?</p>
[ { "answer_id": 31025, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": -1, "selected": false, "text": "string[] less = new string[parts.Length - (x - 2)];\nArray.Copy(parts, x - 2, less, 0, less.Length);\n" }, { "answer_id": 354726, "author": "joshperry", "author_id": 30587, "author_profile": "https://Stackoverflow.com/users/30587", "pm_score": 0, "selected": false, "text": "List<string> parts = new List<string>(s.Split(\" \"));\nparts.RemoveRange(0, x - 2);\n" }, { "answer_id": 379719, "author": "joshperry", "author_id": 30587, "author_profile": "https://Stackoverflow.com/users/30587", "pm_score": 3, "selected": false, "text": "ArraySegment<T>" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2723/" ]
31,031
<p>What's the best way to allow a user to browse for a file in C#?</p>
[ { "answer_id": 31036, "author": "Ryan Farley", "author_id": 1627, "author_profile": "https://Stackoverflow.com/users/1627", "pm_score": 5, "selected": true, "text": "using (OpenFileDialog dlg = new OpenFileDialog())\n{\n dlg.Title = \"Select a file\";\n if (dlg.ShowDialog()== DialogResult.OK)\n {\n //do something with dlg.FileName \n }\n}\n" }, { "answer_id": 31040, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 1, "selected": false, "text": "if (dlg.ShowDialog() == DialogResult.OK)\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31031", "https://Stackoverflow.com", "https://Stackoverflow.com/users/177/" ]
31,044
<p>How can I check the existence of an element in jQuery?</p> <p>The current code that I have is this:</p> <pre><code>if ($(selector).length &gt; 0) { // Do something } </code></pre> <p>Is there a more elegant way to approach this? Perhaps a plugin or a function?</p>
[ { "answer_id": 31047, "author": "Jake McGraw", "author_id": 302, "author_profile": "https://Stackoverflow.com/users/302", "pm_score": 10, "selected": false, "text": "jQuery.fn.exists = function(){ return this.length > 0; }\n\nif ($(selector).exists()) {\n // Do something\n}\n" }, { "answer_id": 85834, "author": "Devon", "author_id": 13850, "author_profile": "https://Stackoverflow.com/users/13850", "pm_score": 6, "selected": false, "text": "if ($(selector).is('*')) {\n // Do something\n}\n" }, { "answer_id": 444403, "author": "Jon Erickson", "author_id": 1950, "author_profile": "https://Stackoverflow.com/users/1950", "pm_score": 9, "selected": false, "text": "jQuery.fn.exists = function(){return ($(this).length > 0);}\nif ($(selector).exists()) { }\n" }, { "answer_id": 584536, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "if ( $('#myDiv').size() > 0 ) { //do something }\n" }, { "answer_id": 587408, "author": "Tim Büthe", "author_id": 60518, "author_profile": "https://Stackoverflow.com/users/60518", "pm_score": 12, "selected": true, "text": "0" }, { "answer_id": 5529517, "author": "Yanni", "author_id": 689782, "author_profile": "https://Stackoverflow.com/users/689782", "pm_score": 7, "selected": false, "text": "// if element exists\nif($('selector').length){ /* do something */ }\n" }, { "answer_id": 8122936, "author": "amypellegrini", "author_id": 527050, "author_profile": "https://Stackoverflow.com/users/527050", "pm_score": 6, "selected": false, "text": "if(document.getElementById(\"myElement\")) {\n //Do something...\n}\n" }, { "answer_id": 8819227, "author": "Magne", "author_id": 380607, "author_profile": "https://Stackoverflow.com/users/380607", "pm_score": 7, "selected": false, "text": "JavaScript" }, { "answer_id": 9166924, "author": "Oleg", "author_id": 632133, "author_profile": "https://Stackoverflow.com/users/632133", "pm_score": 5, "selected": false, "text": "if ($(selector).length) {}" }, { "answer_id": 10035967, "author": "jcreamer898", "author_id": 558672, "author_profile": "https://Stackoverflow.com/users/558672", "pm_score": 4, "selected": false, "text": "// Checks if an object exists.\n// Usage:\n//\n// $(selector).exists()\n//\n// Or:\n// \n// $(selector).exists(anotherSelector);\njQuery.fn.exists = function(selector) {\n return selector ? this.find(selector).length : this.length;\n};\n" }, { "answer_id": 10785067, "author": "SJG", "author_id": 886435, "author_profile": "https://Stackoverflow.com/users/886435", "pm_score": 5, "selected": false, "text": "$(selector).length && //Do something\n" }, { "answer_id": 11768171, "author": "andy_314", "author_id": 1101503, "author_profile": "https://Stackoverflow.com/users/1101503", "pm_score": 4, "selected": false, "text": " $.fn.ifExists = function(fn) {\n if (this.length) {\n $(fn(this));\n }\n };\n $(\"#element\").ifExists( \n function($this){\n $this.addClass('someClass').animate({marginTop:20},function(){alert('ok')}); \n }\n ); \n" }, { "answer_id": 13313296, "author": "SpYk3HH", "author_id": 900807, "author_profile": "https://Stackoverflow.com/users/900807", "pm_score": 6, "selected": false, "text": "if" }, { "answer_id": 16870190, "author": "王奕然", "author_id": 2245634, "author_profile": "https://Stackoverflow.com/users/2245634", "pm_score": 6, "selected": false, "text": "jQuery.fn.extend({\n exists: function() { return this.length }\n});\n\nif($(selector).exists()){/*do something*/}\n" }, { "answer_id": 19533724, "author": "hiway", "author_id": 1626906, "author_profile": "https://Stackoverflow.com/users/1626906", "pm_score": 6, "selected": false, "text": "$.contains()" }, { "answer_id": 21202125, "author": "Salman A", "author_id": 87015, "author_profile": "https://Stackoverflow.com/users/87015", "pm_score": 6, "selected": false, "text": "if ($(selector)[0]) { ... }\n" }, { "answer_id": 22183204, "author": "MAX POWER", "author_id": 372630, "author_profile": "https://Stackoverflow.com/users/372630", "pm_score": 4, "selected": false, "text": "function exists(selector) {\n return $(selector).length;\n}\n\nif (exists(selector)) {\n // do something\n}\n" }, { "answer_id": 24993631, "author": "Eternal1", "author_id": 2214752, "author_profile": "https://Stackoverflow.com/users/2214752", "pm_score": 5, "selected": false, "text": "$.fn.exists = function(callback) {\n var self = this;\n var wrapper = (function(){\n function notExists () {}\n\n notExists.prototype.otherwise = function(fallback){\n if (!self.length) { \n fallback.call();\n }\n };\n\n return new notExists;\n })();\n\n if(self.length) {\n callback.call(); \n }\n\n return wrapper;\n}\n" }, { "answer_id": 25254106, "author": "technosaurus", "author_id": 1162141, "author_profile": "https://Stackoverflow.com/users/1162141", "pm_score": 6, "selected": false, "text": ".length" }, { "answer_id": 30022188, "author": "Santiago Hernández", "author_id": 4343318, "author_profile": "https://Stackoverflow.com/users/4343318", "pm_score": 5, "selected": false, "text": "!" }, { "answer_id": 31317777, "author": "Anurag Deokar", "author_id": 3458967, "author_profile": "https://Stackoverflow.com/users/3458967", "pm_score": 6, "selected": false, "text": "// These by Id\nif ($(\"#elementid\").length > 0) {\n // Element is Present\n} else {\n // Element is not Present\n}\n\n// These by Class\nif ($(\".elementClass\").length > 0) {\n // Element is Present\n} else {\n // Element is not Present\n}\n" }, { "answer_id": 31900459, "author": "guest271314", "author_id": 2801559, "author_profile": "https://Stackoverflow.com/users/2801559", "pm_score": 5, "selected": false, "text": "DOM" }, { "answer_id": 33111577, "author": "Oliver", "author_id": 177710, "author_profile": "https://Stackoverflow.com/users/177710", "pm_score": 5, "selected": false, "text": "$.fn.exists = function() {\n return $.contains( document.documentElement, this[0] );\n}\n" }, { "answer_id": 35873574, "author": "ducdhm", "author_id": 1330990, "author_profile": "https://Stackoverflow.com/users/1330990", "pm_score": 4, "selected": false, "text": "exist" }, { "answer_id": 36218739, "author": "Kamuran Sönecek", "author_id": 4766521, "author_profile": "https://Stackoverflow.com/users/4766521", "pm_score": 4, "selected": false, "text": "$(\"selector\"" }, { "answer_id": 37902260, "author": "Sanu Uthaiah Bollera", "author_id": 2804790, "author_profile": "https://Stackoverflow.com/users/2804790", "pm_score": 5, "selected": false, "text": "function isExists(selector){\n return document.querySelectorAll(selector).length>0;\n}\n" }, { "answer_id": 38581695, "author": "Sunil Kumar", "author_id": 6116564, "author_profile": "https://Stackoverflow.com/users/6116564", "pm_score": 4, "selected": false, "text": "JQuery" }, { "answer_id": 38681468, "author": "abhirathore2006", "author_id": 1785635, "author_profile": "https://Stackoverflow.com/users/1785635", "pm_score": 4, "selected": false, "text": "var a = null;\n\nvar b = []\n\nvar c = undefined ;\n\nif(a) { console.log(\" a exist\")} else { console.log(\"a doesn't exit\")}\n// output: a doesn't exit\n\nif(b) { console.log(\" b exist\")} else { console.log(\"b doesn't exit\")}\n// output: b exist\n\nif(c) { console.log(\" c exist\")} else { console.log(\"c doesn't exit\")}\n// output: c doesn't exit\n" }, { "answer_id": 39102819, "author": "Jonathan Cardoz", "author_id": 4098272, "author_profile": "https://Stackoverflow.com/users/4098272", "pm_score": -1, "selected": false, "text": "let oElement = $(\".myElementClass\");\nif(oElement[0]) {\n // Do some jQuery operation here using oElement\n}\nelse {\n // Unable to fetch the object\n}\n" }, { "answer_id": 40842324, "author": "Pawel", "author_id": 696535, "author_profile": "https://Stackoverflow.com/users/696535", "pm_score": 5, "selected": false, "text": "if(document.querySelector('.a-class')) {\n // do something\n}\n" }, { "answer_id": 42954642, "author": "Tilak Madichetti", "author_id": 4546390, "author_profile": "https://Stackoverflow.com/users/4546390", "pm_score": 5, "selected": false, "text": "if ($(\"#myDiv\").length) {\n $(\"#myDiv\").show();\n}\n" }, { "answer_id": 44084113, "author": "Alireza", "author_id": 5423108, "author_profile": "https://Stackoverflow.com/users/5423108", "pm_score": 6, "selected": false, "text": "$.fn.exists = $.fn.exists || function() { \n return !!(this.length && (this[0] instanceof HTMLDocument || this[0] instanceof HTMLElement)); \n}\n" }, { "answer_id": 44649473, "author": "Andrei Todorut", "author_id": 6318702, "author_profile": "https://Stackoverflow.com/users/6318702", "pm_score": 4, "selected": false, "text": "0" }, { "answer_id": 46772630, "author": "sina_Islam", "author_id": 1657994, "author_profile": "https://Stackoverflow.com/users/1657994", "pm_score": 3, "selected": false, "text": "function exist(IdOrClassName, IsId) {\n var elementExit = false;\n if (IsId) {\n elementExit = $(\"#\" + \"\" + IdOrClassName + \"\").length ? true : false;\n } else {\n elementExit = $(\".\" + \"\" + IdOrClassName + \"\").length ? true : false;\n }\n return elementExit;\n}\n" }, { "answer_id": 49332073, "author": "Jonas Lundman", "author_id": 2445357, "author_profile": "https://Stackoverflow.com/users/2445357", "pm_score": 3, "selected": false, "text": "if($(selector).get(0)) { // Do stuff }\n" }, { "answer_id": 51877072, "author": "Manish Vadher", "author_id": 6313628, "author_profile": "https://Stackoverflow.com/users/6313628", "pm_score": 0, "selected": false, "text": "if($(selector).val())\n" }, { "answer_id": 51905917, "author": "Hassan Sadeghi", "author_id": 9881249, "author_profile": "https://Stackoverflow.com/users/9881249", "pm_score": 4, "selected": false, "text": "jQuery.fn.exists=function(){return !!this[0];}; //jQuery Plugin\n" }, { "answer_id": 51990277, "author": "Rafal Enden", "author_id": 3042543, "author_profile": "https://Stackoverflow.com/users/3042543", "pm_score": -1, "selected": false, "text": "querySelectorAll" }, { "answer_id": 53844610, "author": "Abdul Rahman", "author_id": 1821361, "author_profile": "https://Stackoverflow.com/users/1821361", "pm_score": 3, "selected": false, "text": " if($(\"#element\").length > 0){\n //the element exists in the page, you can do the rest....\n }\n" }, { "answer_id": 53865043, "author": "Majedur", "author_id": 3915410, "author_profile": "https://Stackoverflow.com/users/3915410", "pm_score": 3, "selected": false, "text": " if( $('#selector').length ) // use this if you are using id to check\n{\n // it exists\n}\n" }, { "answer_id": 58439064, "author": "chickens", "author_id": 1602301, "author_profile": "https://Stackoverflow.com/users/1602301", "pm_score": 2, "selected": false, "text": ">0" }, { "answer_id": 60629417, "author": "Amit Sharma", "author_id": 6827830, "author_profile": "https://Stackoverflow.com/users/6827830", "pm_score": 3, "selected": false, "text": "length" }, { "answer_id": 64024660, "author": "Greedo", "author_id": 11829408, "author_profile": "https://Stackoverflow.com/users/11829408", "pm_score": 2, "selected": false, "text": "$.fn.exist = function(){\n return !!this.length;\n};\n\nconsole.log($(\"#yes\").exist())\n\nconsole.log($(\"#no\").exist())" }, { "answer_id": 66033686, "author": "Gareth Compton", "author_id": 4892181, "author_profile": "https://Stackoverflow.com/users/4892181", "pm_score": 1, "selected": false, "text": "//you can check if it isnt defined or if its falsy by using OR\nconsole.log( $(selector) || 'this value doesnt exist' )\n\n//or run the selector if its true, and ONLY true\nconsole.log( $(selector) && 'this selector is defined, now lemme do somethin!' )\n\n//sometimes I do the following, and see how similar it is to SWITCH\nconsole.log(\n({ //return something only if its in the method name\n 'string':'THIS is a string',\n 'function':'THIS is a function',\n 'number':'THIS is a number',\n 'boolean':'THIS is a boolean'\n})[typeof $(selector)]||\n//skips to this value if object above is undefined\n'typeof THIS is not defined in your search')\n" }, { "answer_id": 70234944, "author": "Haroon Fayyaz", "author_id": 13380986, "author_profile": "https://Stackoverflow.com/users/13380986", "pm_score": 1, "selected": false, "text": "HTML" }, { "answer_id": 70245882, "author": "Vishwesh Chotaliya", "author_id": 15483583, "author_profile": "https://Stackoverflow.com/users/15483583", "pm_score": 3, "selected": false, "text": "if (typeof selector != \"undefined\") {\n console.log(\"selector exists\");\n} else {\n console.log(\"selector does not exists\");\n}\n" }, { "answer_id": 73512301, "author": "Vladislav Ladicky", "author_id": 9805590, "author_profile": "https://Stackoverflow.com/users/9805590", "pm_score": 0, "selected": false, "text": "jQuery.fn.extend({\n exists() { return !!this.length }\n});\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31044", "https://Stackoverflow.com", "https://Stackoverflow.com/users/302/" ]
31,053
<p>How can I replace lone instances of \n with \r\n (LF alone with CRLF) using a regular expression in C#?</p> <p>I know to do it using plan <code>String.Replace</code>, like:</p> <pre><code>myStr.Replace(&quot;\n&quot;, &quot;\r\n&quot;); myStr.Replace(&quot;\r\r\n&quot;, &quot;\r\n&quot;); </code></pre> <p>However, this is inelegant, and would destroy any &quot;\r+\r\n&quot; already in the text (although they are not likely to exist).</p>
[ { "answer_id": 31056, "author": "chakrit", "author_id": 3055, "author_profile": "https://Stackoverflow.com/users/3055", "pm_score": 7, "selected": true, "text": "[^\\r]\\n\n" }, { "answer_id": 31074, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 1, "selected": false, "text": "myStr.Replace(\"([^\\r])\\n\", \"$1\\r\\n\");\n" }, { "answer_id": 32704, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 6, "selected": false, "text": "(?<!\\r)\\n\n" }, { "answer_id": 6449289, "author": "wanted", "author_id": 811500, "author_profile": "https://Stackoverflow.com/users/811500", "pm_score": 4, "selected": false, "text": "myStr.Replace(\"(?<!\\r)\\n\", \"\\r\\n\")\n" }, { "answer_id": 24972759, "author": "Kevin Jin", "author_id": 444402, "author_profile": "https://Stackoverflow.com/users/444402", "pm_score": 1, "selected": false, "text": "myStr.Replace(\"\\r?\\n\", \"\\r\\n\");\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/838/" ]
31,057
<p>I didn't see any similar questions asked on this topic, and I had to research this for something I'm working on right now. Thought I would post the answer for it in case anyone else had the same question.</p>
[ { "answer_id": 31063, "author": "Mark Struzinski", "author_id": 1284, "author_profile": "https://Stackoverflow.com/users/1284", "pm_score": 9, "selected": true, "text": "CHAR(13)" }, { "answer_id": 31067, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 4, "selected": false, "text": "CREATE TABLE CRLF\n (\n col1 VARCHAR(1000)\n )\n\nINSERT CRLF SELECT 'The quick brown@'\nINSERT CRLF SELECT 'fox @jumped'\nINSERT CRLF SELECT '@over the '\nINSERT CRLF SELECT 'log@'\n\nSELECT col1 FROM CRLF\n\nReturns:\n\ncol1\n-----------------\nThe quick brown@\nfox @jumped\n@over the\nlog@\n\n(4 row(s) affected)\n\n\nUPDATE CRLF\nSET col1 = REPLACE(col1, '@', CHAR(13))\n" }, { "answer_id": 31174, "author": "Sören Kuklau", "author_id": 1600, "author_profile": "https://Stackoverflow.com/users/1600", "pm_score": 9, "selected": false, "text": "char(13)" }, { "answer_id": 31179, "author": "neslekkiM", "author_id": 3308, "author_profile": "https://Stackoverflow.com/users/3308", "pm_score": 2, "selected": false, "text": "varchar" }, { "answer_id": 549244, "author": "Frank V", "author_id": 18196, "author_profile": "https://Stackoverflow.com/users/18196", "pm_score": 7, "selected": false, "text": "INSERT CRLF SELECT 'fox \njumped'\n" }, { "answer_id": 2382010, "author": "Carl Niedner", "author_id": 435268, "author_profile": "https://Stackoverflow.com/users/435268", "pm_score": 3, "selected": false, "text": "INSERT" }, { "answer_id": 20222846, "author": "Bruce Allen", "author_id": 834328, "author_profile": "https://Stackoverflow.com/users/834328", "pm_score": 4, "selected": false, "text": "declare @tmp varchar(500) \nselect @tmp = msgbody from emailssentlog where id=6769;\nprint @tmp\n" }, { "answer_id": 32633945, "author": "AjV Jsy", "author_id": 2078245, "author_profile": "https://Stackoverflow.com/users/2078245", "pm_score": 5, "selected": false, "text": "PRINT 'Line 1\nLine 2\nLine 3'\nPRINT ''\n\nPRINT 'How long is a blank line feed?'\nPRINT LEN('\n')\nPRINT ''\n\nPRINT 'What are the ASCII values?'\nPRINT ASCII(SUBSTRING('\n',1,1))\nPRINT ASCII(SUBSTRING('\n',2,1))\n" }, { "answer_id": 54042155, "author": "Ken Kin", "author_id": 927012, "author_profile": "https://Stackoverflow.com/users/927012", "pm_score": 3, "selected": false, "text": "concat('This is line 1.', 0xd0a, 'This is line 2.')\n" }, { "answer_id": 59189881, "author": "Trubs", "author_id": 2608920, "author_profile": "https://Stackoverflow.com/users/2608920", "pm_score": 5, "selected": false, "text": "Tools" }, { "answer_id": 62384567, "author": "cjonas", "author_id": 9391130, "author_profile": "https://Stackoverflow.com/users/9391130", "pm_score": 0, "selected": false, "text": "select * from \n(\nvalues\n ('use STAGING'),\n ('go'),\n ('EXEC sp_MSforeachtable \n@command1=''select ''''?'''' as tablename,count(1) as anzahl from ? having count(1) = 0''')\n) as t([Copy_and_execute_this_statement])\ngo\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1284/" ]
31,059
<p>In VS .NET, when you are selecting a folder for a project, a dialog that looks like an OpenFileDialog or SaveFileDialog is displayed, but is set up to accept only folders. Ever since I've seen this I've wanted to know how it's done. I am aware of the FolderBrowserDialog, but I've never really liked that dialog. It starts too small and doesn't let me take advantage of being able to type a path.</p> <p>I'm almost certain by now there's not a way to do this from .NET, but I'm just as curious how you do it from unmanaged code as well. Short of completely reimplementing the dialog from scratch, how do you modify the dialog to have this behavior?</p> <p>I'd also like to restate that I am aware of the FolderBrowserDialog but sometimes I don't like to use it, in addition to being genuinely curious how to configure a dialog in this manner. Telling me to just use the FolderBrowserDialog helps me maintain a consistent UI experience but doesn't satisfy my curiosity so it won't count as an answer.</p> <p>It's not a Vista-specific thing either; I've been seeing this dialog since VS .NET 2003, so it is doable in Win2k and WinXP. This is less of a "I want to know the proper way to do this" question and more of a "I have been curious about this since I first wanted to do it in VS 2003" question. I understand that Vista's file dialog has an option to do this, but it's been working in XP so I know they did <em>something</em> to get it to work. Vista-specific answers are not answers, because Vista doesn't exist in the question context.</p> <p><strong>Update: I'm accepting Scott Wisniewski's answer because it comes with a working sample, but I think Serge deserves credit for pointing to the dialog customization (which is admittedly nasty from .NET but it <em>does</em> work) and Mark Ransom for figuring out that MS probably rolled a custom dialog for this task.</strong></p>
[ { "answer_id": 31082, "author": "Ryan Farley", "author_id": 1627, "author_profile": "https://Stackoverflow.com/users/1627", "pm_score": 5, "selected": false, "text": "using (FolderBrowserDialog dlg = new FolderBrowserDialog())\n{\n dlg.Description = \"Select a folder\";\n if (dlg.ShowDialog() == DialogResult.OK)\n {\n MessageBox.Show(\"You selected: \" + dlg.SelectedPath);\n }\n}\n" }, { "answer_id": 506298, "author": "Serge Wautier", "author_id": 12379, "author_profile": "https://Stackoverflow.com/users/12379", "pm_score": 4, "selected": false, "text": " m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILEDIALOG_IMPORTXLIFF);\n m_ofn.Flags |= OFN_ENABLETEMPLATE;\n" }, { "answer_id": 506364, "author": "demoncodemonkey", "author_id": 61697, "author_profile": "https://Stackoverflow.com/users/61697", "pm_score": 1, "selected": false, "text": "bool GetFolder(std::string& folderpath, const char* szCaption=NULL, HWND hOwner=NULL)\n{\n bool retVal = false;\n\n // The BROWSEINFO struct tells the shell how it should display the dialog.\n BROWSEINFO bi;\n memset(&bi, 0, sizeof(bi));\n\n bi.ulFlags = BIF_USENEWUI;\n bi.hwndOwner = hOwner;\n bi.lpszTitle = szCaption;\n\n // must call this if using BIF_USENEWUI\n ::OleInitialize(NULL);\n\n // Show the dialog and get the itemIDList for the selected folder.\n LPITEMIDLIST pIDL = ::SHBrowseForFolder(&bi);\n\n if(pIDL != NULL)\n {\n // Create a buffer to store the path, then get the path.\n char buffer[_MAX_PATH] = {'\\0'};\n if(::SHGetPathFromIDList(pIDL, buffer) != 0)\n {\n // Set the string value.\n folderpath = buffer;\n retVal = true;\n } \n\n // free the item id list\n CoTaskMemFree(pIDL);\n }\n\n ::OleUninitialize();\n\n return retVal;\n}\n" }, { "answer_id": 510035, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 4, "selected": false, "text": "CFileDialog dlg(true, NULL, \"Filename will be ignored\", OFN_HIDEREADONLY | OFN_NOVALIDATE | OFN_PATHMUSTEXIST | OFN_READONLY, NULL, this);\ndlg.DoModal();\n" }, { "answer_id": 514258, "author": "Avram", "author_id": 61883, "author_profile": "https://Stackoverflow.com/users/61883", "pm_score": 3, "selected": false, "text": "{\n openFileDialog2.FileName = \"\\r\";\n openFileDialog1.Filter = \"folders|*.neverseenthisfile\";\n openFileDialog1.CheckFileExists = false;\n openFileDialog1.CheckPathExists = false;\n}\n" }, { "answer_id": 625069, "author": "Cheeso", "author_id": 48082, "author_profile": "https://Stackoverflow.com/users/48082", "pm_score": 6, "selected": false, "text": "var dlg1 = new Ionic.Utils.FolderBrowserDialogEx();\ndlg1.Description = \"Select a folder to extract to:\";\ndlg1.ShowNewFolderButton = true;\ndlg1.ShowEditBox = true;\n//dlg1.NewStyle = false;\ndlg1.SelectedPath = txtExtractDirectory.Text;\ndlg1.ShowFullPathInEditBox = true;\ndlg1.RootFolder = System.Environment.SpecialFolder.MyComputer;\n\n// Show the FolderBrowserDialog.\nDialogResult result = dlg1.ShowDialog();\nif (result == DialogResult.OK)\n{\n txtExtractDirectory.Text = dlg1.SelectedPath;\n}\n" }, { "answer_id": 4998682, "author": "Ken Wayne VanderLinde", "author_id": 616815, "author_profile": "https://Stackoverflow.com/users/616815", "pm_score": 6, "selected": false, "text": "CommonOpenFileDialog" }, { "answer_id": 8720922, "author": "Josip Medved", "author_id": 144245, "author_profile": "https://Stackoverflow.com/users/144245", "pm_score": 1, "selected": false, "text": "var frm = (IFileDialog)(new FileOpenDialogRCW());\nuint options;\nfrm.GetOptions(out options);\noptions |= FOS_PICKFOLDERS;\nfrm.SetOptions(options);\n\nif (frm.Show(owner.Handle) == S_OK) {\n IShellItem shellItem;\n frm.GetResult(out shellItem);\n IntPtr pszString;\n shellItem.GetDisplayName(SIGDN_FILESYSPATH, out pszString);\n this.Folder = Marshal.PtrToStringAuto(pszString);\n}\n" }, { "answer_id": 9764339, "author": "lantran", "author_id": 1277704, "author_profile": "https://Stackoverflow.com/users/1277704", "pm_score": 1, "selected": false, "text": " openFileDialog.FileName = \"AnyFile\";\n openFileDialog.Filter = string.Empty;\n openFileDialog.CheckFileExists = false;\n openFileDialog.CheckPathExists = false;\n" }, { "answer_id": 33836349, "author": "ErikE", "author_id": 57611, "author_profile": "https://Stackoverflow.com/users/57611", "pm_score": 2, "selected": false, "text": "VistaDialog" }, { "answer_id": 46712973, "author": "AltF4_", "author_id": 1073481, "author_profile": "https://Stackoverflow.com/users/1073481", "pm_score": -1, "selected": false, "text": "OpenFileDialog" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31059", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2547/" ]
31,068
<p>How do I find the 'temp' directory in Linux? I am writing a platform neutral C++ function that returns the temp directory. In Mac and Windows, there is an API that returns these results. In Linux, I'm stumped. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>
[ { "answer_id": 31081, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "/tmp" }, { "answer_id": 31083, "author": "Adam Wright", "author_id": 1200, "author_profile": "https://Stackoverflow.com/users/1200", "pm_score": 4, "selected": false, "text": "tmpnam" }, { "answer_id": 31100, "author": "Greg Dan", "author_id": 3315, "author_profile": "https://Stackoverflow.com/users/3315", "pm_score": 5, "selected": false, "text": "TMPDIR" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3313/" ]
31,075
<p>I have an executable (compiled by someone else) that is hitting an assertion near my code. I work on the code in Visual C++ 2003, but I don't have a project file for this particular executable (the code is used to build many different tools). Is it possible to launch the binary in Visual C++'s debugger and just tell it where the sources are? I've done this before in GDB, so I know it ought to be possible.</p>
[ { "answer_id": 31148, "author": "Anders Sandvig", "author_id": 1709, "author_profile": "https://Stackoverflow.com/users/1709", "pm_score": 0, "selected": false, "text": ".exe" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31075", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1891/" ]
31,088
<p>I'm trying to set up an inheritance hierarchy similar to the following:</p> <pre><code>abstract class Vehicle { public string Name; public List&lt;Axle&gt; Axles; } class Motorcycle : Vehicle { } class Car : Vehicle { } abstract class Axle { public int Length; public void Turn(int numTurns) { ... } } class MotorcycleAxle : Axle { public bool WheelAttached; } class CarAxle : Axle { public bool LeftWheelAttached; public bool RightWheelAttached; } </code></pre> <p>I would like to only store MotorcycleAxle objects in a Motorcycle object's Axles array, and CarAxle objects in a Car object's Axles array. The problem is there is no way to override the array in the subclass to force one or the other. Ideally something like the following would be valid for the Motorcycle class:</p> <pre><code>class Motorcycle : Vehicle { public override List&lt;MotorcycleAxle&gt; Axles; } </code></pre> <p>but the types have to match when overriding. How can I support this architecture? Will I just have to do a lot of run-time type checking and casting wherever the Axles member is accessed? I don't like adding run-time type checks because you start to lose the benefits of strong typing and polymorphism. There have to be at least some run-time checks in this scenario since the WheelAttached and Left/RightWheelAttached properties depend on the type, but I would like to minimize them.</p>
[ { "answer_id": 31110, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 4, "selected": true, "text": "abstract class Vehicle<T> where T : Axle\n{\n public string Name;\n public List<T> Axles;\n}\n\nclass Motorcycle : Vehicle<MotorcycleAxle>\n{\n}\n\nclass Car : Vehicle<CarAxle>\n{\n}\n\nabstract class Axle\n{\n public int Length;\n public void Turn(int numTurns) { ... }\n}\n\nclass MotorcycleAxle : Axle\n{\n public bool WheelAttached;\n}\n\nclass CarAxle : Axle\n{\n public bool LeftWheelAttached;\n public bool RightWheelAttached;\n}\n" }, { "answer_id": 31273, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 0, "selected": false, "text": "abstract class Vehicle<TAxle> where TAxle : Axle {\n public List<TAxle> Axles;\n}\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/327/" ]
31,090
<p>The <code>Open</code> button on the open file dialog used in certain windows applications includes a dropdown arrow with a list of additional options &mdash; namely <code>Open With..</code>. </p> <p><a href="https://i.stack.imgur.com/GLM3T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GLM3T.png" alt="Open File Dialog"></a></p> <p>I haven't seen this in every Windows application, so you may have to try a few to get it, but SQL Server Management Studio and Visual Studio 2017 will both show the button that way if you go to the menu and choose <em><code>File</code>-><code>Open</code>-><code>File...</code></em></p> <p>I want to use a button like this with a built-in list in one of my applications, but I can't find the control they're using anywhere in Visual Studio. I should clarify that I'm looking for that specific button, not the entire dialog. Any thoughts?</p>
[ { "answer_id": 31202, "author": "Nick", "author_id": 1490, "author_profile": "https://Stackoverflow.com/users/1490", "pm_score": 2, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Windows.Forms;\nusing System.Windows.Forms.VisualStyles;\nusing System.Drawing;\nusing System.ComponentModel;\nusing System.Diagnostics;\n\n// Original: http://blogs.msdn.com/jfoscoding/articles/491523.aspx\n// Wyatt's fixes: http://wyday.com/splitbutton/\n// Trimmed down and redone significantly from that version (Nick 5/6/08)\nnamespace DF\n{\n public class SplitButton : Button\n {\n private ContextMenuStrip m_SplitMenu = null;\n private const int SplitSectionWidth = 14;\n private static int BorderSize = SystemInformation.Border3DSize.Width * 2;\n private bool mBlockClicks = false;\n private Timer mTimer;\n\n public SplitButton()\n {\n this.AutoSize = true;\n mTimer = new Timer();\n mTimer.Interval = 100;\n mTimer.Tick += new EventHandler(mTimer_Tick);\n }\n\n private void mTimer_Tick(object sender, EventArgs e)\n {\n mBlockClicks = false;\n mTimer.Stop();\n }\n\n #region Properties\n [DefaultValue(null)]\n public ContextMenuStrip SplitMenu\n {\n get\n {\n return m_SplitMenu;\n }\n set\n {\n if (m_SplitMenu != null)\n m_SplitMenu.Closing -= \n new ToolStripDropDownClosingEventHandler(m_SplitMenu_Closing);\n\n m_SplitMenu = value;\n\n if (m_SplitMenu != null)\n m_SplitMenu.Closing += \n new ToolStripDropDownClosingEventHandler(m_SplitMenu_Closing);\n }\n }\n\n private void m_SplitMenu_Closing(object sender, ToolStripDropDownClosingEventArgs e)\n {\n HideContextMenuStrip();\n // block click events for 0.5 sec to prevent re-showing the menu\n\n }\n\n private PushButtonState _state;\n private PushButtonState State\n {\n get\n {\n return _state;\n }\n set\n {\n if (!_state.Equals(value))\n {\n _state = value;\n Invalidate();\n }\n }\n }\n\n #endregion Properties\n\n protected override void OnEnabledChanged(EventArgs e)\n {\n if (Enabled)\n State = PushButtonState.Normal;\n else\n State = PushButtonState.Disabled;\n\n base.OnEnabledChanged(e);\n }\n\n protected override void OnMouseClick(MouseEventArgs e)\n {\n if (e.Button != MouseButtons.Left)\n return;\n if (State.Equals(PushButtonState.Disabled))\n return;\n if (mBlockClicks)\n return;\n\n if (!State.Equals(PushButtonState.Pressed))\n ShowContextMenuStrip();\n else\n HideContextMenuStrip();\n }\n\n protected override void OnMouseEnter(EventArgs e)\n {\n if (!State.Equals(PushButtonState.Pressed) && !State.Equals(PushButtonState.Disabled))\n {\n State = PushButtonState.Hot;\n }\n }\n\n protected override void OnMouseLeave(EventArgs e)\n {\n if (!State.Equals(PushButtonState.Pressed) && !State.Equals(PushButtonState.Disabled))\n {\n if (Focused)\n {\n State = PushButtonState.Default;\n }\n\n else\n {\n State = PushButtonState.Normal;\n }\n }\n }\n\n protected override void OnPaint(PaintEventArgs pevent)\n {\n base.OnPaint(pevent);\n\n Graphics g = pevent.Graphics;\n Rectangle bounds = this.ClientRectangle;\n\n // draw the button background as according to the current state.\n if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles)\n {\n Rectangle backgroundBounds = bounds;\n backgroundBounds.Inflate(-1, -1);\n ButtonRenderer.DrawButton(g, backgroundBounds, State);\n\n // button renderer doesnt draw the black frame when themes are off =(\n g.DrawRectangle(SystemPens.WindowFrame, 0, 0, bounds.Width - 1, bounds.Height - 1);\n }\n else\n {\n ButtonRenderer.DrawButton(g, bounds, State);\n }\n\n StringFormat format = new StringFormat();\n format.Alignment = StringAlignment.Center;\n format.LineAlignment = StringAlignment.Center;\n\n g.DrawString(Text, Font, SystemBrushes.ControlText, bounds, format);\n }\n\n private void ShowContextMenuStrip()\n {\n State = PushButtonState.Pressed;\n if (m_SplitMenu != null)\n {\n m_SplitMenu.Show(this, new Point(0, Height), ToolStripDropDownDirection.BelowRight);\n }\n }\n\n private void HideContextMenuStrip()\n {\n State = PushButtonState.Normal;\n m_SplitMenu.Hide();\n mBlockClicks = true;\n mTimer.Start();\n }\n }\n}\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3043/" ]
31,096
<p>I'm trying to find out how much memory my own .Net server process is using (for monitoring and logging purposes).</p> <p>I'm using:</p> <pre><code>Process.GetCurrentProcess().PrivateMemorySize64 </code></pre> <p>However, the Process object has several different properties that let me read the memory space used: Paged, NonPaged, PagedSystem, NonPagedSystem, Private, Virtual, WorkingSet</p> <p>and then the "peaks": which i'm guessing just store the maximum values these last ones ever took.</p> <p>Reading through the MSDN definition of each property hasn't proved too helpful for me. I have to admit my knowledge regarding how memory is managed (as far as paging and virtual goes) is very limited.</p> <p>So my question is obviously "which one should I use?", and I know the answer is "it depends".</p> <p>This process will basically hold a bunch of lists in memory of things that are going on, while other processes communicate with it and query it for stuff. I'm expecting the server where this will run on to require lots of RAM, and so i'm querying this data over time to be able to estimate RAM requirements when compared to the sizes of the lists it keeps inside.</p> <p>So... Which one should I use and why?</p>
[ { "answer_id": 31164, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 5, "selected": true, "text": "GC.GetTotalMemory(true)\n" }, { "answer_id": 289478, "author": "Michael Regan", "author_id": 1027, "author_profile": "https://Stackoverflow.com/users/1027", "pm_score": 3, "selected": false, "text": "using System.Threading;\nusing System.Diagnostics;\n\n//namespace...class...method\n\nProcess thisProc = Process.GetCurrentProcess();\nPerformanceCounter PC = new PerformanceCounter();\n\nPC.CategoryName = \"Process\";\nPC.CounterName = \"Working Set - Private\";\nPC.InstanceName = thisProc.ProcessName;\n\nwhile (true)\n{\n String privMemory = (PC.NextValue()/1000).ToString()+\"KB (Private Bytes)\";\n //Do something with string privMemory\n\n Thread.Sleep(1000);\n}\n" }, { "answer_id": 9223644, "author": "Nicholas Petersen", "author_id": 264031, "author_profile": "https://Stackoverflow.com/users/264031", "pm_score": 2, "selected": false, "text": "perfCounter.NextValue()/1000;" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31096", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3314/" ]
31,097
<p>Visual Basic code does not render correctly with <a href="https://code.google.com/archive/p/google-code-prettify" rel="nofollow noreferrer">prettify.js</a> from Google.</p> <p>on Stack Overflow:</p> <pre><code>Partial Public Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'set page title Page.Title = &quot;Something&quot; End Sub End Class </code></pre> <p>in Visual Studio...</p> <p><img src="https://i.stack.imgur.com/Fl1CM.jpg" alt="Visual Basic in Visual Studio" /></p> <p>I found this in the <a href="https://web.archive.org/web/20160428230325/http://google-code-prettify.googlecode.com:80/svn/trunk/README.html" rel="nofollow noreferrer">README</a> document:</p> <blockquote> <p>How do I specify which language my code is in?</p> <p>You don't need to specify the language since prettyprint() will guess. You can specify a language by specifying the language extension along with the prettyprint class like so:</p> <pre><code>&lt;pre class=&quot;prettyprint lang-html&quot;&gt; The lang-* class specifies the language file extensions. Supported file extensions include &quot;c&quot;, &quot;cc&quot;, &quot;cpp&quot;, &quot;cs&quot;, &quot;cyc&quot;, &quot;java&quot;, &quot;bsh&quot;, &quot;csh&quot;, &quot;sh&quot;, &quot;cv&quot;, &quot;py&quot;, &quot;perl&quot;, &quot;pl&quot;, &quot;pm&quot;, &quot;rb&quot;, &quot;js&quot;, &quot;html&quot;, &quot;html&quot;, &quot;xhtml&quot;, &quot;xml&quot;, &quot;xsl&quot;. &lt;/pre&gt; </code></pre> </blockquote> <p>I see no <em>lang-vb</em> or <em>lang-basic</em> option. Does anyone know if one exists as an add-in?</p> <hr /> <p>Note: This is related to the <a href="https://web.archive.org/web/20080914043525/http://stackoverflow.uservoice.com:80/pages/general/suggestions/18775" rel="nofollow noreferrer">VB.NET code blocks</a> suggestion for Stack Overflow.</p>
[ { "answer_id": 31860, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": true, "text": "GetXmlNamespace" }, { "answer_id": 149726, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 0, "selected": false, "text": "Sub TestMethod()\n 'Method body goes here'\nEnd Sub\n" }, { "answer_id": 885802, "author": "Mark Nold", "author_id": 4134, "author_profile": "https://Stackoverflow.com/users/4134", "pm_score": 2, "selected": false, "text": "<script type=\"text/javascript\" src=\"/External/css/prettify/prettify.js\"></script>\n<script type=\"text/javascript\" src=\"/External/css/prettify/lang-vb.js\"></script>\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31097", "https://Stackoverflow.com", "https://Stackoverflow.com/users/83/" ]
31,127
<p>When running a Java app from eclipse my ImageIcon shows up just fine.</p> <p>But after creating a jar the path to the image obviously gets screwed up.</p> <p>Is there a way to extract an image from the jar at runtime so I can then open it up? Or, is there a better way to do this?</p> <p>I'd like to distribute a single jar file if possible.</p>
[ { "answer_id": 31146, "author": "Tim Frey", "author_id": 1471, "author_profile": "https://Stackoverflow.com/users/1471", "pm_score": 5, "selected": false, "text": "InputStream stream = this.getClass().getClassLoader().getResourceAsStream(\"/images/image.jpg\");\n" }, { "answer_id": 45580, "author": "Tom Hawtin - tackline", "author_id": 4725, "author_profile": "https://Stackoverflow.com/users/4725", "pm_score": 6, "selected": true, "text": "ImageIcon" }, { "answer_id": 15353743, "author": "ekerner", "author_id": 233060, "author_profile": "https://Stackoverflow.com/users/233060", "pm_score": 4, "selected": false, "text": " - com\n - img\n ---- bg.png\n" }, { "answer_id": 42084902, "author": "Abdelsalam Shahlol", "author_id": 7199218, "author_profile": "https://Stackoverflow.com/users/7199218", "pm_score": 2, "selected": false, "text": "jToggleButton1.setIcon(new javax.swing.ImageIcon(this.getClass().getResource(\"/resources/image.jpg\")));\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
31,128
<p>The HTML standard defines a clear separation of concerns between CSS (presentation) and HTML (semantics or structure).</p> <p>Does anyone use a coding standards document for CSS and XHTML that has clauses which help to maintain this separation? What would be good clauses to include in such a coding standards document?</p>
[ { "answer_id": 32478, "author": "Lee Theobald", "author_id": 1900, "author_profile": "https://Stackoverflow.com/users/1900", "pm_score": 3, "selected": true, "text": "CSS" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2822/" ]
31,129
<p>I want to return <code>StudentId</code> to use elsewhere outside of the <em>scope</em> of the <code>$.getJSON()</code></p> <pre><code>j.getJSON(url, data, function(result) { var studentId = result.Something; }); //use studentId here </code></pre> <p>I would imagine this has to do with scoping, but it doesn't seem to work the same way <em>c#</em> does</p>
[ { "answer_id": 31153, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 6, "selected": true, "text": "var studentId = null;\nj.getJSON(url, data, function(result)\n{\n studentId = result.Something;\n});\n\n// studentId is still null right here, because this line \n// executes before the line that sets its value to result.Something\n" }, { "answer_id": 31212, "author": "travis", "author_id": 1414, "author_profile": "https://Stackoverflow.com/users/1414", "pm_score": -1, "selected": false, "text": "StudentId" }, { "answer_id": 494328, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "\nvar this.studentId = null;\n\n$.getJSON(url, data, \n function(result){\n $.fn.delegateJSONResult(result.Something);\n }\n);\n\n$.fn.delegateJSONResult = function(something){\n this.studentId = something;\n}\n\n" }, { "answer_id": 1008786, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "var mydata = [];\n$.ajax({\n url: 'data.php',\n async: false,\n dataType: 'json',\n success: function (json) {\n mydata = json.whatever;\n }\n});\n\nalert(mydata); // has value of json.whatever\n" }, { "answer_id": 15585054, "author": "bicycle", "author_id": 1160952, "author_profile": "https://Stackoverflow.com/users/1160952", "pm_score": 5, "selected": false, "text": "$.getJSON" }, { "answer_id": 44998393, "author": "Reinaldo Garcia", "author_id": 6177779, "author_profile": "https://Stackoverflow.com/users/6177779", "pm_score": -1, "selected": false, "text": "var context;\n$.ajax({\n url: 'file.json',\n async: false,\n dataType: 'json',\n success: function (json) { \n assignVariable(json);\n }\n});\n\nfunction assignVariable(data) {\n context = data;\n}\nalert(context);\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2993/" ]
31,140
<p>A number of forms in my project inherit from a base form. It is easy to get at the Controls collection of the derived forms, but I have not found a simple way to access the Components collection, since VS marks this as private. </p> <p>I assume this could be done with reflection, but I'm not really sure how best to go about it, not having worked with reflection before.</p> <p>Right now, I'm using a sort of clunky workaround, in which I override a function GetComponents and return an array of the components I'm interested in. This is obviously prone to errors, since it's easy to forget to implement the overridden function or update it when components are added.</p> <p>If anyone has any tips or can suggest a better way, I'd be glad to hear.</p>
[ { "answer_id": 17007925, "author": "Albert", "author_id": 2090753, "author_profile": "https://Stackoverflow.com/users/2090753", "pm_score": 0, "selected": false, "text": " public void SetComponentsStyle()\n {\n if (null != this.components)\n {\n foreach (Component comp in this.components.Components)\n {\n if (comp is ToolTip)\n {\n\n }\n else if (comp is ContextMenuStrip)\n {\n\n }\n }\n }\n }\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31140", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2899/" ]
31,151
<p>Alright.</p> <p>So I figure it's about time I get into unit testing, since everyone's been banging on about it for long enough. I've installed NUnit and gone through a few "intro to unit testing" type tutorials.</p> <p>I'm currently putting together a small framework to help with the rebuild of one of our web apps, so I've created a VS2008 project for my framework and I want to unit test it as I go.</p> <p>How on earth do I go about unit testing the WebControls? The methods are all protected or private, and since it's a framework, there isn't much else but WebControls.</p> <p>Any pointers?</p> <p>Burns</p>
[ { "answer_id": 31160, "author": "chakrit", "author_id": 3055, "author_profile": "https://Stackoverflow.com/users/3055", "pm_score": 3, "selected": false, "text": "assembly:InternalsVisibleTo" }, { "answer_id": 49176870, "author": "Vin Shahrdar", "author_id": 5908918, "author_profile": "https://Stackoverflow.com/users/5908918", "pm_score": 0, "selected": false, "text": "[Test]\npublic void ConditionQueryBuilderTest_RendersProperHtml()\n{\n var sw = new StringWriter();\n var queryBuilder = new ConditionQueryBuilderStub\n {\n ID = \"UnitTestbuilder\",\n QueryBuilderURL = @\"\\SomeAspxPage\\SomeWebMethod\",\n ResetQueryBuilderURL = @\"\\SomeAspxPage\\OnQueryBuilderReset\",\n FilterValuesCollection = new Dictionary<int, string> { {15, \"Some Condition\"}}\n };\n queryBuilder.RenderAllContents(new HtmlTextWriter(sw));\n\n AppendLog(sw.ToString());\n\n Assert.AreEqual(ExpectedHtml, sw.ToString()); // ExpectedHTML is the raw expected HTML\n}\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/366/" ]
31,163
<p>In Visual Studio 2005, whenever I would view a file in the main editor, the Solution Explorer would find and highlight that file. Some time ago, this stopped working and the Solution Explorer would do nothing.</p> <p>This has become quite a pain since following a chain of "Go To Definition"s can lead you all over your solution. Where is the setting to turn this back on?</p>
[ { "answer_id": 46193, "author": "Owen", "author_id": 4790, "author_profile": "https://Stackoverflow.com/users/4790", "pm_score": 5, "selected": false, "text": "Imports System\nImports EnvDTE\nImports EnvDTE80\nImports EnvDTE90\nImports System.Diagnostics\n\nPublic Module SyncItem\n\n Sub SyncSolutionExplorer()\n DTE.ExecuteCommand(\"View.TrackActivityinSolutionExplorer\")\n DTE.ExecuteCommand(\"View.TrackActivityinSolutionExplorer\")\n End Sub\n\nEnd Module\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3259/" ]
31,173
<p>What's the most useful hack you've discovered for Mozilla's new <a href="https://wiki.mozilla.org/Labs/Ubiquity" rel="nofollow noreferrer">Ubiquity</a> tool? ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>
[ { "answer_id": 35506, "author": "Jörg W Mittag", "author_id": 2988, "author_profile": "https://Stackoverflow.com/users/2988", "pm_score": 2, "selected": false, "text": "makeSearchCommand({\n name: \"stackoverflow-tagsearch\",\n author: { name: \"Jörg W Mittag\", email: \"JoergWMittag+Ubiquity@GoogleMail.Com\"},\n license: \"MIT X11\",\n url: \"http://Beta.StackOverflow.Com/questions/tagged/{QUERY}\",\n icon: \"http://StackOverflow.Com/favicon.ico\",\n description: \"Searches <a href=\\\"http://StackOverflow.Com\\\">StackOverflow.Com</a> for the given tag(s).\",\n help: \"Searches <a href=\\\"http://StackOverflow.Com\\\">StackOverflow.Com</a> for the given tag(s).\",\n preview: function(pBlock, directObj) {\n if (directObj.text)\n pBlock.innerHtml = \"Searches <a href=\\\"http://StackOverflow.Com\\\">StackOverflow.Com</a> for \" + directObj.text;\n else\n pBlock.innerHTML = \"Searches <a href=\\\"http://StackOverflow.Com\\\">StackOverflow.Com</a> for the given tag(s).\";\n }\n});\n" }, { "answer_id": 36116, "author": "aryeh", "author_id": 3288, "author_profile": "https://Stackoverflow.com/users/3288", "pm_score": 2, "selected": false, "text": "CmdUtils.CreateCommand({\n name: \"stackoverflow\",\n author: {name: \"Aryeh Goldsmith\"},\n homepage: \"http://www.appidx.com/ubiq/\",\n icon: \"http://stackoverflow.com/favicon.ico\",\n takes: {search: noun_arb_text},\n license: \"MPL\",\n description: \"Searches the highlighted text on stackoverflow.\",\n _version: \"52\",\n\n preview: function ( pblock, inputObject) {\n var query = inputObject.text;\n pblock.innerHTML = \"Search stackoverflow.com for \" + query + \"<br/>\";\n\n var url = \"http://stackoverflow.com/search\";\n params = {\"search-text\": query, \"hiddenstuff\": ''};\n\n jQuery.post( url, params, function( html ) {\n var $ = jQuery;\n pblock.innerHTML += \"<div style='display:none;'>\" + html + \"</div>\";\n var ques = $(pblock).find('.summary h3');\n var details = $(pblock).find('.summary .excerpt');\n var out = \"<div style='margin-bottom: 6px;'><b>Previewing the first 5 results:</b></div>\";\n for (var j = 0; j< ques.size() && j < 5; j++) {\n out += \"<div style='padding: 5px;'><b>\" + ques[j].innerHTML + \"</b><br />\";\n out += details[j].innerHTML + \"</div>\";\n }\n pblock.innerHTML = out;\n });\n },\n\n execute: function( inputObject ) {\n var query = inputObject.text;\n var url = \"http://stackoverflow.com/search\";\n var params = {\n \"search-text\": query,\n hiddenstuff: \"\"\n };\n\n// The following refuses to work... why? I just don't know! AFAIK it's correct.\n openUrl(url, params);\n },\n})\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372/" ]
31,201
<p>I'm currently creating an explicit reference to this in the outer class so that I have a name to refer to in the anonymous inner class. Is there a better way to do this?</p>
[ { "answer_id": 31216, "author": "John Topley", "author_id": 1450, "author_profile": "https://Stackoverflow.com/users/1450", "pm_score": 4, "selected": false, "text": "EnclosingClass.this" }, { "answer_id": 31218, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 8, "selected": true, "text": "OuterClassName.this" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1288/" ]
31,215
<p>I have a Person object with two constructors - one takes an int (personId), the other a string (logonName). I would like another constructor that takes a string (badgeNumber). I know this can't be done, but seems it might be a common situation. Is there a graceful way of handling this? I suppose this would apply to any overloaded method. Code:</p> <pre><code>public class Person { public Person() {} public Person(int personId) { this.Load(personId); } public Person(string logonName) { this.Load(logonName); } public Person(string badgeNumber) { //load logic here... } </code></pre> <p>...etc.</p>
[ { "answer_id": 31220, "author": "Zack Peterson", "author_id": 83, "author_profile": "https://Stackoverflow.com/users/83", "pm_score": 4, "selected": true, "text": "public Person(LogonName ln)\n{\n this.Load(ln.ToString());\n}\n\npublic Person(BadgeNumber bn)\n{\n //load logic here...\n}\n" }, { "answer_id": 31229, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 4, "selected": false, "text": "public static Person fromId(int id) {\n Person p = new Person();\n p.Load(id);\n return p;\n}\npublic static Person fromLogonName(string logonName) {\n Person p = new Person();\n p.Load(logonName);\n return p;\n}\npublic static Person fromBadgeNumber(string badgeNumber) {\n Person p = new Person();\n // load logic\n return p;\n}\nprivate Person() {}\n" }, { "answer_id": 31232, "author": "Tim Frey", "author_id": 1471, "author_profile": "https://Stackoverflow.com/users/1471", "pm_score": 1, "selected": false, "text": "public static Person fromLogon(String logon) { return new Person(logon, null); }\npublic static Person fromBadge(String badge) { return new Person(null, badge); }\n" }, { "answer_id": 31233, "author": "Adam Wright", "author_id": 1200, "author_profile": "https://Stackoverflow.com/users/1200", "pm_score": 0, "selected": false, "text": "public class Person {\n\n private Person() {}\n\n public static PersonFromID(int personId)\n {\n Person p = new Person().\n person.Load(personID);\n\n return p;\n this.Load(personId);\n }\n\n public static PersonFromID(string name)\n {\n Person p = new Person().\n person.LoadFromName(name);\n\n return p;\n }\n\n ...\n}\n" }, { "answer_id": 31240, "author": "Drakiula", "author_id": 2437, "author_profile": "https://Stackoverflow.com/users/2437", "pm_score": -1, "selected": false, "text": "public Person(int personId)\n{\n this.Load(personId);\n}\n\npublic Person(string logonName)\n{\n this.Load(logonName);\n}\n\npublic Person(Object badgeNumber)\n{\n //load logic here...\n}\n" }, { "answer_id": 31299, "author": "Derek Park", "author_id": 872, "author_profile": "https://Stackoverflow.com/users/872", "pm_score": 2, "selected": false, "text": "bool" }, { "answer_id": 32153, "author": "Jake Pearson", "author_id": 632, "author_profile": "https://Stackoverflow.com/users/632", "pm_score": 1, "selected": false, "text": "public Person()\n{\n}\n\npublic string Logon { get; set; }\npublic string Badge { get; set; }\n" }, { "answer_id": 66372459, "author": "Salim", "author_id": 2800651, "author_profile": "https://Stackoverflow.com/users/2800651", "pm_score": 0, "selected": false, "text": "public class Person\n{\n public string Logon { get; set; } = \"\";\n public string Badge { get; set; } = \"\";\n \n public Person(string logon=\"\", string badge=\"\") {}\n}\n// Use as follow \nPerson p1 = new Person(logon:\"MylogonName\");\nPerson p2 = new Person(badge:\"MyBadge\");\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1865/" ]
31,221
<p>I have a method that where I want to redirect the user back to a login page located at the root of my web application.</p> <p>I'm using the following code:</p> <pre><code>Response.Redirect("~/Login.aspx?ReturnPath=" + Request.Url.ToString()); </code></pre> <p>This doesn't work though. My assumption was that ASP.NET would automatically resolve the URL into the correct path. Normally, I would just use</p> <pre><code>Response.Redirect("../Login.aspx?ReturnPath=" + Request.Url.ToString()); </code></pre> <p>but this code is on a master page, and can be executed from any folder level. How do I get around this issue?</p>
[ { "answer_id": 31248, "author": "Marshall", "author_id": 1302, "author_profile": "https://Stackoverflow.com/users/1302", "pm_score": -1, "selected": false, "text": "Response.Redirect(String.Format(\"http://{0}/Login.aspx?ReturnPath={1}\", Request.ServerVariables[\"SERVER_NAME\"], Request.Url.ToString()));\n" }, { "answer_id": 31437, "author": "Duncan Smart", "author_id": 1278, "author_profile": "https://Stackoverflow.com/users/1278", "pm_score": 7, "selected": true, "text": "ResolveUrl" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31221", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1226/" ]
31,226
<p>I am writing a basic word processing application and am trying to settle on a native "internal" format, the one that my code parses in order to render to the screen. I'd like this to be XML so that I can, in the future, just write XSLT to convert it to ODF or XHTML or whatever.</p> <p>When searching for existing standards to use, the only one that looks promising is ODF. But that looks like massive overkill for what I need. All I need is paragraph tags, font selection, font size &amp; decoration...that's pretty much it. It would take me a long time to implement even a minimal ODF renderer, and I'm not sure it's worth the trouble.</p> <p>Right now I'm thinking of making my own XML format, but that's not really good practice. Better to use a standard, especially since then I can probably find the XSLTs I might need in the future already written.</p> <p>Or should I just bite the bullet and implement ODF?</p> <p><strong>EDIT: Regarding the Answer</strong></p> <p>I knew about XSL-FO before, but due to the weight of the spec hadn't really consdiered it. But you're right, a subset would give me everything I need to work with and room to grow. Thanks so much the reminder.</p> <p>Plus, by including a rendering library like FOP or RenderX, I get PDF generation for free. Not bad...</p>
[ { "answer_id": 35517, "author": "gz.", "author_id": 3665, "author_profile": "https://Stackoverflow.com/users/3665", "pm_score": 4, "selected": true, "text": "<yourcontainer xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n <fo:block font-family=\"Arial, sans-serif\" font-weight=\"bold\"\n font-size=\"16pt\">Example Heading</fo:block>\n <fo:block font-family=\"Times, serif\"\n font-size=\"12pt\">Paragraph text here etc etc...</fo:block>\n</yourcontainer>\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3044/" ]
31,238
<p>What I have is a collection of classes that all implement the same interface but can be pretty wildly different under the hood. I want to have a config file control which of the classes go into the collection upon starting the program, taking something that looks like :</p> <pre><code>&lt;class1 prop1="foo" prop2="bar"/&gt; </code></pre> <p>and turning that into :</p> <pre><code>blah = new class1(); blah.prop1="foo"; blah.prop2="bar"; </code></pre> <p>In a very generic way. The thing I don't know how to do is take the string <code>prop1</code> in the config file and turn that into the actual property accessor in the code. Are there any meta-programming facilities in C# to allow that?</p>
[ { "answer_id": 31252, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 2, "selected": false, "text": "Type" }, { "answer_id": 31258, "author": "Markus Olsson", "author_id": 2114, "author_profile": "https://Stackoverflow.com/users/2114", "pm_score": 3, "selected": false, "text": "public IYourInterface GetClass(string className)\n{\n foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) \n { \n foreach (Type type in asm.GetTypes())\n {\n if (type.Name == className)\n return Activator.CreateInstance(type) as IYourInterface;\n } \n }\n\n return null;\n}\n" }, { "answer_id": 31261, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 3, "selected": false, "text": "Type type = blah.GetType();\nPropertyInfo prop = type.GetProperty(\"prop1\");\nprop.SetValue(blah, \"foo\", null);\n" }, { "answer_id": 31488, "author": "Brian Ensink", "author_id": 1254, "author_profile": "https://Stackoverflow.com/users/1254", "pm_score": 3, "selected": false, "text": "Things" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/634/" ]
31,249
<p>Using WPF, I have a TreeView control that I want to set its ItemTemplate dynamically through procedural code. How do I do this? I assume I need to find the resource somewhere.</p> <pre><code>myTreeViewControl.ItemTemplate = ?? </code></pre>
[ { "answer_id": 31260, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 5, "selected": true, "text": "myTreeViewControl.ItemTemplate = this.Resources[\"SomeTemplate\"] as DataTemplate;\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31249", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3047/" ]
31,250
<p>What is the content type for MHT files?</p>
[ { "answer_id": 3262124, "author": "Luke Quinane", "author_id": 18437, "author_profile": "https://Stackoverflow.com/users/18437", "pm_score": 3, "selected": false, "text": "message/rfc822" }, { "answer_id": 13154862, "author": "feeela", "author_id": 341201, "author_profile": "https://Stackoverflow.com/users/341201", "pm_score": 2, "selected": false, "text": "multipart/related" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2141/" ]
31,297
<p>I developed a program in a mobile device (Pocket PC 2003) to access a web service, the web service is installed on a Windows XP SP2 PC with IIS, the PC has the IP 192.168.5.2. </p> <p>The device obtains from the wireless network the IP 192.168.5.118 and the program works OK, it calls the method from the web service and executes the action that is needed. This program is going to be used in various buildings.</p> <p>Now I have this problem, it turns that when I try to test it in another building (distances neraly about 100 mts. or 200 mts.) connected with the network, the program cannot connect to the webservice, at this moment the device gets from an Access Point the IP 192.168.10.25, and it accesses the same XP machine I stated before (192.168.5.2). I made a mobile aspx page to verify that I can reach the web server over the network and it loads it in the device, I even made a winform that access the same webservice in a PC from that building and also works there so I don't understand what is going on. I also tried to ping that 192.168.5.2 PC and it responds alive.</p> <p>After that fail I returned to the original place where I tested the program before and it happens that it works normally.</p> <p>The only thing that I look different here is that the third number in the IP is 10 instead of 5, another observation is that I can't ping to the mobile device. I feel confused I don't know what happens here? What could be the problem?</p> <p>This is how I call the web service;</p> <pre><code>//Connect to webservice svc = new TheWebService(); svc.Credentials = new System.Net.NetworkCredential(Settings.UserName, Settings.Password); svc.AllowAutoRedirect = false; svc.UserAgent = Settings.UserAgent; svc.PreAuthenticate = true; svc.Url = Settings.Url; svc.Timeout = System.Threading.Timeout.Infinite; //Send information to webservice svc.ExecuteMethod(info); </code></pre> <p>the content of the app.config in the mobile device is;</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;appSettings&gt; &lt;add key="UserName" value="administrator" /&gt; &lt;add key="Password" value="************" /&gt; &lt;add key="UserAgent" value="My User Agent" /&gt; &lt;add key="Url" value="http://192.168.5.2/WebServices/TWUD.asmx" /&gt; &lt;/appSettings&gt; &lt;/configuration&gt; </code></pre> <p>Does anyone have an idea what is going on?</p>
[ { "answer_id": 31724, "author": "Shaun Austin", "author_id": 1120, "author_profile": "https://Stackoverflow.com/users/1120", "pm_score": 0, "selected": false, "text": "255.255.255.0\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1130097/" ]
31,312
<p>I am working on a rails project. Using the tag observe_field, I am taking text typed into a text area, processing it in a control, and displaying the result in a div (very similar to the preview in stack overflow). Everything works fine until I type certain special chars.</p> <ol> <li>? => causes the variable not to be found in the params object</li> <li>(pound) => causes an invalid authenticity error</li> <li>% => stops the div from being updated</li> <li>&amp; => every thing after the &amp; is no longer passed into the variable on the server. </li> </ol> <p>Is there a way to solve this?</p> <p>--- code sample ---</p> <p>this is the view. ( 'postbody' is a text area)</p> <pre><code>&lt;%= observe_field 'postbody', :update =&gt; 'preview', :url =&gt; {:controller =&gt; 'blog', :action =&gt; 'textile_to_html'}, :frequency =&gt; 0.5, :with =&gt; 'postbody' -%&gt; </code></pre> <p>this is the controller that is called</p> <pre><code>def textile_to_html text = params['postbody'] if text == nil then @textile_to_html = '&lt;br/&gt;never set' else r = RedCloth.new text @textile_to_html = r.to_html end render :layout =&gt; false end </code></pre> <p>and this is the javascript that is created:</p> <pre><code>new Form.Element.Observer('postbody', 0.5, function(element, value) {new Ajax.Updater('preview', '/blog/textile_to_html', {asynchronous:true, evalScripts:true, parameters:'postbody=' + value + '&amp;authenticity_token=' + encodeURIComponent('22f7ee12eac9efd418caa0fe76ae9e862025ef97')})}) </code></pre>
[ { "answer_id": 287822, "author": "waldo", "author_id": 4870, "author_profile": "https://Stackoverflow.com/users/4870", "pm_score": 3, "selected": true, "text": " :with => \"'postbody=' + encodeURIComponent(value)\"\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1632/" ]
31,320
<p>What is the best way to profile a controller action in Ruby on Rails. Currently I am using the brute-force method of throwing in <code>puts Time.now</code> calls between what I think will be a bottleneck. But that feels really, really dirty. There has got to be a better way.</p>
[ { "answer_id": 31359, "author": "Chris Bunch", "author_id": 422, "author_profile": "https://Stackoverflow.com/users/422", "pm_score": 3, "selected": false, "text": "def test_do_something\n elapsed_time = Benchmark.realtime do\n 100.downto(1) do |index|\n # do something here\n end\n end\n assert elapsed_time < SOME_LIMIT\nend\n" }, { "answer_id": 9042581, "author": "Rob Davis", "author_id": 461347, "author_profile": "https://Stackoverflow.com/users/461347", "pm_score": 5, "selected": false, "text": "?profile=true" }, { "answer_id": 36879670, "author": "Minqi Pan", "author_id": 740014, "author_profile": "https://Stackoverflow.com/users/740014", "pm_score": -1, "selected": false, "text": " o=OpenStruct.new(logger: Rails.logger)\n o.extend ActiveSupport::Benchmarkable\n o.benchmark 'name' do\n # ... your code ...\n end\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/757/" ]
31,326
<p>I have a few internal .net web application here that require users to "log out" of them. I know this may seem moot on an Intranet application, but nonetheless it is there.</p> <p>We are using Windows authentication for our Intranet apps, so we tie in to our Active Directory with Basic Authentication and the credentials get stored in the browser cache, as opposed to a cookie when using .net forms authentication.</p> <p>In IE6+ you can leverage a special JavaScript function they created by doing the following:</p> <pre><code>document.execCommand("ClearAuthenticationCache", "false") </code></pre> <p>However, for the other browsers that are to be supported (namely Firefox at the moment, but I strive for multi-browser support), I simply display message to the user that they need to close their browser to log out of the application, which effectively flushes the application cache.</p> <p>Does anybody know of some commands/hacks/etc. that I can use in other browsers to flush the authentication cache?</p>
[ { "answer_id": 6289660, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 4, "selected": false, "text": "$j.ajax({\n url: '<%:Url.Action(\"LogOff401\", new { id = random })%>',\n type: 'POST',\n username: '<%:random%>',\n password: '<%:random%>',\n success: function () { alert('logged off'); }\n});\n" }, { "answer_id": 8497804, "author": "AnthonyVO", "author_id": 438458, "author_profile": "https://Stackoverflow.com/users/438458", "pm_score": 3, "selected": false, "text": "document.execCommand(\"ClearAuthenticationCache\", \"false\");\n" }, { "answer_id": 9443989, "author": "staromeste", "author_id": 680094, "author_profile": "https://Stackoverflow.com/users/680094", "pm_score": 3, "selected": false, "text": "window" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/71/" ]
31,340
<p>I've been trying to wrap my head around how threads work in Python, and it's hard to find good information on how they operate. I may just be missing a link or something, but it seems like the official documentation isn't very thorough on the subject, and I haven't been able to find a good write-up.</p> <p>From what I can tell, only one thread can be running at once, and the active thread switches every 10 instructions or so?</p> <p>Where is there a good explanation, or can you provide one? It would also be very nice to be aware of common problems that you run into while using threads with Python.</p>
[ { "answer_id": 31358, "author": "mmattax", "author_id": 1638, "author_profile": "https://Stackoverflow.com/users/1638", "pm_score": 4, "selected": false, "text": "import threading\nclass Foo (threading.Thread):\n def __init__(self,x):\n self.__x = x\n threading.Thread.__init__(self)\n def run (self):\n print str(self.__x)\n\nfor x in xrange(20):\n Foo(x).start()\n" }, { "answer_id": 49573860, "author": "anekix", "author_id": 6518118, "author_profile": "https://Stackoverflow.com/users/6518118", "pm_score": 4, "selected": false, "text": "thread" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/242853/" ]
31,346
<p>The MediaElement doesn't support rounded corners (radiusx, radiusy). Should I use a VideoBrush on a Rectangle with rounded corners?</p>
[ { "answer_id": 31454, "author": "Jonas Follesø", "author_id": 1199387, "author_profile": "https://Stackoverflow.com/users/1199387", "pm_score": 3, "selected": true, "text": "<MediaElement \n Height=\"132\" Width=\"176\" Source=\"Egypt2007.wmv\" \n Clip=\"M0.5,24.5 C0.5,11.245166 11.245166,0.5 24.5,0.5 L151.5,0.5\n C164.75484,0.5 175.5,11.245166 175.5,24.5 L175.5,107.5 C175.5,\n 120.75484 164.75484,131.5 151.5,131.5 L24.5,131.5 C11.245166,\n 131.5 0.5,120.75484 0.5,107.5 z\"/>\n" }, { "answer_id": 62177, "author": "Jim Lynn", "author_id": 6483, "author_profile": "https://Stackoverflow.com/users/6483", "pm_score": 0, "selected": false, "text": "<MediaElement x:Name=\"myElement\" Source=\"clip.wmv\" Visibility=\"Collapsed\"/>\n<Rectangle RadiusX=\"10\" RadiusY=\"10\" Width=\"640\" Height=\"480\">\n <Rectangle.Fill>\n <VideoBrush Source=\"myElement\" Stretch=\"Uniform\"/>\n </Rectangle.Fill>\n<Rectangle/>\n" }, { "answer_id": 33804268, "author": "Karthic G", "author_id": 4264464, "author_profile": "https://Stackoverflow.com/users/4264464", "pm_score": 0, "selected": false, "text": " <Border CornerRadius=\"8\" BorderBrush=\"Black\" Background=\"Black\" BorderThickness=\"3\">\n <MediaElement HorizontalAlignment=\"Center\" VerticalAlignment=\"Top\" Stretch=\"Fill\" x:Name=\"Player\" Source=\"/Assets/Videos/x.mp3\" />\n </Border>\n" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5/" ]
31,366
<p>I am performing a find and replace on the line feed character (<code>&amp;#10;</code>) and replacing it with the paragraph close and paragraph open tags using the following code:</p> <pre><code>&lt;xsl:template match="/STORIES/STORY"&gt; &lt;component&gt; &lt;xsl:if test="boolean(ARTICLEBODY)"&gt; &lt;p&gt; &lt;xsl:call-template name="replace-text"&gt; &lt;xsl:with-param name="text" select="ARTICLEBODY" /&gt; &lt;xsl:with-param name="replace" select="'&amp;#10;'" /&gt; &lt;xsl:with-param name="by" select="'&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;'" /&gt; &lt;/xsl:call-template&gt; &lt;/p&gt; &lt;/xsl:if&gt; &lt;/component&gt; &lt;/xsl:template&gt; &lt;xsl:template name="replace-text"&gt; &lt;xsl:param name="text"/&gt; &lt;xsl:param name="replace" /&gt; &lt;xsl:param name="by" /&gt; &lt;xsl:choose&gt; &lt;xsl:when test="contains($text, $replace)"&gt; &lt;xsl:value-of select="substring-before($text, $replace)"/&gt; &lt;xsl:value-of select="$by" disable-output-escaping="yes"/&gt; &lt;xsl:call-template name="replace-text"&gt; &lt;xsl:with-param name="text" select="substring-after($text, $replace)"/&gt; &lt;xsl:with-param name="replace" select="$replace" /&gt; &lt;xsl:with-param name="by" select="$by" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="$text"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; </code></pre> <p>This almost works perfectly, except that I really need it to de-dup the line feeds as the paragraphs tend to be separated by 2 or more resulting in <code>&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;</code>. </p> <p>Is it possible to get it so that it will only ever replace this once per paragraph?</p>
[ { "answer_id": 31517, "author": "Mike Haboustak", "author_id": 2146, "author_profile": "https://Stackoverflow.com/users/2146", "pm_score": 1, "selected": false, "text": "<xsl:value-of \n select=\"replace(string(.), '&#10;(\\s|&#10;)*', '&lt;/p&gt;&lt;p&gt;')\" />\n" }, { "answer_id": 31570, "author": "James Sulak", "author_id": 207, "author_profile": "https://Stackoverflow.com/users/207", "pm_score": 1, "selected": false, "text": " <xsl:template match=\"/STORIES/STORY\">\n <component>\n <xsl:if test=\"boolean(ARTICLEBODY)\">\n <xsl:call-template name=\"insert_paras\">\n <xsl:with-param name=\"text\" select=\"ARTICLEBODY/text()\"/>\n </xsl:call-template>\n </xsl:if>\n </component>\n </xsl:template>\n\n <xsl:template name=\"insert_paras\">\n <xsl:param name=\"text\" />\n\n <xsl:variable name=\"regex\">\n <xsl:text>&#10;(&#10;|\\s)*</xsl:text>\n </xsl:variable>\n <xsl:variable name=\"tokenized-text\" select=\"tokenize($text, $regex)\"/>\n\n <xsl:for-each select=\"$tokenized-text\">\n <p>\n <xsl:value-of select=\".\"/>\n </p>\n </xsl:for-each>\n </xsl:template>\n" }, { "answer_id": 31725, "author": "jelovirt", "author_id": 2679, "author_profile": "https://Stackoverflow.com/users/2679", "pm_score": 4, "selected": true, "text": "disable-output-escaping" } ]
2008/08/27
[ "https://Stackoverflow.com/questions/31366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/274/" ]
31,380
<p>I currently use the following function to do a simple HTTP GET.</p> <pre><code>public static String download(String url) throws java.io.IOException { java.io.InputStream s = null; java.io.InputStreamReader r = null; //java.io.BufferedReader b = null; StringBuilder content = new StringBuilder(); try { s = (java.io.InputStream)new URL(url).getContent(); r = new java.io.InputStreamReader(s); //b = new java.io.BufferedReader(r); char[] buffer = new char[4*1024]; int n = 0; while (n &gt;= 0) { n = r.read(buffer, 0, buffer.length); if (n &gt; 0) { content.append(buffer, 0, n); } } } finally { //if (b != null) b.close(); if (r != null) r.close(); if (s != null) s.close(); } return content.toString(); } </code></pre> <p>I see no reason to use the <code>BufferedReader</code> since I am just going to download everything in sequence. Am I right in thinking there is no use for the <code>BufferedReader</code> in this case?</p>
[ { "answer_id": 32509, "author": "McDowell", "author_id": 304, "author_profile": "https://Stackoverflow.com/users/304", "pm_score": 3, "selected": true, "text": " InputStream stream = new FileInputStream(\"in\");\n try { //no operations between open stream and try block\n //work\n } finally { //do nothing but close this one stream in the finally\n stream.close();\n }\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/338/" ]
31,394
<p>I see many similar questions, however I want to find the Username of the currently logged in user using Java.</p> <p>Its probably something like:</p> <pre><code>System.getProperty(current.user); </code></pre> <p>But, I'm not quite sure.</p>
[ { "answer_id": 31401, "author": "Chris Bunch", "author_id": 422, "author_profile": "https://Stackoverflow.com/users/422", "pm_score": 6, "selected": true, "text": "System.getProperty(\"user.name\")\n" }, { "answer_id": 41463, "author": "John Meagher", "author_id": 3535, "author_profile": "https://Stackoverflow.com/users/3535", "pm_score": 3, "selected": false, "text": "System.getProperties()" }, { "answer_id": 37172080, "author": "marklark", "author_id": 462234, "author_profile": "https://Stackoverflow.com/users/462234", "pm_score": 2, "selected": false, "text": "System.getProperty(\"user.name\")\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
31,412
<p>I am developing a GPL-licensed application in Python and need to know if the GPL allows my program to use proprietary plug-ins. This is <a href="http://www.gnu.org/licenses/gpl-faq.html" rel="noreferrer">what the FSF has to say</a> on the issue:</p> <blockquote> <p><strong>If a program released under the GPL uses plug-ins, what are the requirements for the licenses of a plug-in?</strong></p> <p>It depends on how the program invokes its plug-ins. If the program uses fork and exec to invoke plug-ins, then the plug-ins are separate programs, so the license for the main program makes no requirements for them.</p> <p>If the program dynamically links plug-ins, and they make function calls to each other and share data structures, we believe they form a single program, which must be treated as an extension of both the main program and the plug-ins. This means the plug-ins must be released under the GPL or a GPL-compatible free software license, and that the terms of the GPL must be followed when those plug-ins are distributed.</p> <p>If the program dynamically links plug-ins, but the communication between them is limited to invoking the ‘main’ function of the plug-in with some options and waiting for it to return, that is a borderline case.</p> </blockquote> <p>The distinction between fork/exec and dynamic linking, besides being kind of artificial, doesn't carry over to interpreted languages: what about a Python/Perl/Ruby plugin, which gets loaded via <code>import</code> or <code>execfile</code>?</p> <p>(edit: I understand why the distinction between fork/exec and dynamic linking, but it seems like someone who wanted to comply with the GPL but go against the &quot;spirit&quot; --I don't-- could just use fork/exec and interprocess communication to do pretty much anything).</p> <p>The best solution would be to add an exception to my license to explicitly allow the use of proprietary plugins, but I am unable to do so since I'm using <a href="http://trolltech.com/products/qt" rel="noreferrer">Qt</a>/<a href="http://www.riverbankcomputing.co.uk/software/pyqt/intro" rel="noreferrer">PyQt</a> which is GPL.</p>
[ { "answer_id": 31420, "author": "dmckee --- ex-moderator kitten", "author_id": 2509, "author_profile": "https://Stackoverflow.com/users/2509", "pm_score": 1, "selected": false, "text": "import" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3002/" ]
31,415
<p>Using regular expressions, what is the simplest way to fetch a websites HTML and find the value inside this tag (or any attribute's value for that matter):</p> <pre><code>&lt;html&gt; &lt;head&gt; [snip] &lt;meta name="generator" value="thevalue i'm looking for" /&gt; [snip] </code></pre>
[ { "answer_id": 31432, "author": "Mike Haboustak", "author_id": 2146, "author_profile": "https://Stackoverflow.com/users/2146", "pm_score": 4, "selected": true, "text": "StringBuilder html = new StringBuilder();\njava.net.URL url = new URL(\"http://www.google.com/\");\nBufferedReader input = null;\ntry {\n input new BufferedReader(\n new InputStreamReader(url.openStream()));\n\n String htmlLine;\n while ((htmlLine=input.readLine())!=null) {\n html.appendLine(htmlLine);\n }\n}\nfinally {\n input.close();\n}\n\nPattern exp = Pattern.compile(\n \"<meta name=\\\"generator\\\" value=\\\"([^\\\"]*)\\\" />\");\nMatcher matcher = exp.matcher(html.toString());\nif(matcher.find())\n{\n System.out.println(\"Generator: \"+matcher.group(1));\n}\n" }, { "answer_id": 31467, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 0, "selected": false, "text": "java.net.HttpURLConnection" }, { "answer_id": 137216, "author": "vrdhn", "author_id": 414441, "author_profile": "https://Stackoverflow.com/users/414441", "pm_score": 1, "selected": false, "text": "/html/head/meta[@name=generator]/@value" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2644/" ]
31,424
<p>When creating a criteria in NHibernate I can use</p> <p>Restriction.In() or<br> Restriction.InG()</p> <p>What is the difference between them?</p>
[ { "answer_id": 87823, "author": "Gareth", "author_id": 1313, "author_profile": "https://Stackoverflow.com/users/1313", "pm_score": 5, "selected": true, "text": "In(string propertyName, ICollection values)\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/493/" ]
31,446
<p>What would be the easiest way to detach a specific JPA Entity Bean that was acquired through an EntityManager. Alternatively, could I have a query return detached objects in the first place so they would essentially act as 'read only'?</p> <p>The reason why I want to do this is becuase I want to modify the data within the bean - with in my application only, but not ever have it persisted to the database. In my program, I eventually have to call flush() on the EntityManager, which would persist all changes from attached entities to the underyling database, but I want to exclude specific objects.</p>
[ { "answer_id": 31553, "author": "tonygambone", "author_id": 3344, "author_profile": "https://Stackoverflow.com/users/3344", "pm_score": 1, "selected": false, "text": "public Thing(Thing oldBean) {\n this.setPropertyOne(oldBean.getPropertyOne());\n // and so on\n}\n" }, { "answer_id": 2049477, "author": "James McMahon", "author_id": 20774, "author_profile": "https://Stackoverflow.com/users/20774", "pm_score": 4, "selected": false, "text": "public void detach(Object entity) {\n org.hibernate.Session session = (Session) entityManager.getDelegate();\n session.evict(entity);\n}\n" }, { "answer_id": 5491768, "author": "David Faulstich", "author_id": 684655, "author_profile": "https://Stackoverflow.com/users/684655", "pm_score": 1, "selected": false, "text": " public DocumentoAntigoDTO(Documento documentoAtual) {\n Method[] metodosDocumento = Documento.class.getMethods();\n for(Method metodo:metodosDocumento){\n if(metodo.getName().contains(\"get\")){\n try {\n Object resultadoInvoke = metodo.invoke(documentoAtual,null);\n Method[] metodosDocumentoAntigo = DocumentoAntigoDTO.class.getMethods();\n for(Method metodoAntigo : metodosDocumentoAntigo){\n String metodSetName = \"set\" + metodo.getName().substring(3);\n if(metodoAntigo.getName().equals(metodSetName)){\n metodoAntigo.invoke(this, resultadoInvoke);\n }\n }\n } catch (IllegalArgumentException e) {\n e.printStackTrace();\n } catch (IllegalAccessException e) {\n e.printStackTrace();\n } catch (InvocationTargetException e) {\n e.printStackTrace();\n }\n }\n }\n}\n" }, { "answer_id": 5500466, "author": "James", "author_id": 416206, "author_profile": "https://Stackoverflow.com/users/416206", "pm_score": 2, "selected": false, "text": "EclipseLink" }, { "answer_id": 6149959, "author": "Warren Crossing", "author_id": 772748, "author_profile": "https://Stackoverflow.com/users/772748", "pm_score": 0, "selected": false, "text": "for(RssItem i : result.getChannel().getItem()){\n}\n" }, { "answer_id": 12139908, "author": "Mehdi", "author_id": 482628, "author_profile": "https://Stackoverflow.com/users/482628", "pm_score": 5, "selected": false, "text": "entityManager.detach(object)" }, { "answer_id": 16928294, "author": "Chris B", "author_id": 121732, "author_profile": "https://Stackoverflow.com/users/121732", "pm_score": 1, "selected": false, "text": "public MyEntity myMethod(long id) {\n final MyEntity myEntity = retrieve(id);\n // myEntity is detached here\n}\n\n@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\npublic MyEntity retrieve(long id) {\n return entityManager.find(MyEntity.class, id);\n}\n" }, { "answer_id": 25649132, "author": "Roger Mori", "author_id": 4004848, "author_profile": "https://Stackoverflow.com/users/4004848", "pm_score": 1, "selected": false, "text": "class MyEntity\n{\n public static class MyEntityDO extends MyEntity {}\n\n}\n" }, { "answer_id": 52996053, "author": "Abhishek Tripathi", "author_id": 6517450, "author_profile": "https://Stackoverflow.com/users/6517450", "pm_score": 0, "selected": false, "text": "EntityManagerFactory emf;\nemf.getCache().evict(Entity);\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31446", "https://Stackoverflow.com", "https://Stackoverflow.com/users/506/" ]
31,462
<p>Without the use of any external library, what is the simplest way to fetch a website's HTML content into a String?</p>
[ { "answer_id": 31463, "author": "pek", "author_id": 2644, "author_profile": "https://Stackoverflow.com/users/2644", "pm_score": 7, "selected": true, "text": "String content = null;\nURLConnection connection = null;\ntry {\n connection = new URL(\"http://www.google.com\").openConnection();\n Scanner scanner = new Scanner(connection.getInputStream());\n scanner.useDelimiter(\"\\\\Z\");\n content = scanner.next();\n scanner.close();\n}catch ( Exception ex ) {\n ex.printStackTrace();\n}\nSystem.out.println(content);\n" }, { "answer_id": 31471, "author": "Justin Bennett", "author_id": 271, "author_profile": "https://Stackoverflow.com/users/271", "pm_score": 2, "selected": false, "text": "import org.apache.commons.HttpClient" }, { "answer_id": 33986, "author": "Scott Bennett-McLeish", "author_id": 1915, "author_profile": "https://Stackoverflow.com/users/1915", "pm_score": 4, "selected": false, "text": "URL url = new URL(theURL);\nInputStream is = url.openStream();\nint ptr = 0;\nStringBuffer buffer = new StringBuffer();\nwhile ((ptr = is.read()) != -1) {\n buffer.append((char)ptr);\n}\n" }, { "answer_id": 15219927, "author": "Scott Bennett-McLeish", "author_id": 1915, "author_profile": "https://Stackoverflow.com/users/1915", "pm_score": 1, "selected": false, "text": "String siteContent = new URL(\"http://www.google.com\").text\n" }, { "answer_id": 51337796, "author": "dinesh kandpal", "author_id": 4617050, "author_profile": "https://Stackoverflow.com/users/4617050", "pm_score": -1, "selected": false, "text": "sudo apt install curl\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2644/" ]
31,465
<p>When you get a badge or aren't logged in to stack overflow there's a groovy little notification bar at the top of the page that lets you know there's something going on.</p> <p>I know the SOflow team use JQuery, but I was wondering if anyone knew of an implementation of the same style of notification system in asp.net AJAX.</p> <p>On a side note, what's the "official" name for this style of notification bar?</p>
[ { "answer_id": 31463, "author": "pek", "author_id": 2644, "author_profile": "https://Stackoverflow.com/users/2644", "pm_score": 7, "selected": true, "text": "String content = null;\nURLConnection connection = null;\ntry {\n connection = new URL(\"http://www.google.com\").openConnection();\n Scanner scanner = new Scanner(connection.getInputStream());\n scanner.useDelimiter(\"\\\\Z\");\n content = scanner.next();\n scanner.close();\n}catch ( Exception ex ) {\n ex.printStackTrace();\n}\nSystem.out.println(content);\n" }, { "answer_id": 31471, "author": "Justin Bennett", "author_id": 271, "author_profile": "https://Stackoverflow.com/users/271", "pm_score": 2, "selected": false, "text": "import org.apache.commons.HttpClient" }, { "answer_id": 33986, "author": "Scott Bennett-McLeish", "author_id": 1915, "author_profile": "https://Stackoverflow.com/users/1915", "pm_score": 4, "selected": false, "text": "URL url = new URL(theURL);\nInputStream is = url.openStream();\nint ptr = 0;\nStringBuffer buffer = new StringBuffer();\nwhile ((ptr = is.read()) != -1) {\n buffer.append((char)ptr);\n}\n" }, { "answer_id": 15219927, "author": "Scott Bennett-McLeish", "author_id": 1915, "author_profile": "https://Stackoverflow.com/users/1915", "pm_score": 1, "selected": false, "text": "String siteContent = new URL(\"http://www.google.com\").text\n" }, { "answer_id": 51337796, "author": "dinesh kandpal", "author_id": 4617050, "author_profile": "https://Stackoverflow.com/users/4617050", "pm_score": -1, "selected": false, "text": "sudo apt install curl\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/493/" ]
31,494
<p>I have got a simple contacts database but I'm having problems with users entering in duplicate data. I have implemented a simple data comparison but unfortunately the duplicated data that is being entered is not exactly the same. For example, names are incorrectly spelled or one person will put in 'Bill Smith' and another will put in 'William Smith' for the same person.</p> <p>So is there some sort of algorithm that can give a percentage for how similar an entry is to another?</p>
[ { "answer_id": 56507233, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "rank" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/486/" ]
31,496
<p>I would like to enable/disable some code based on a custom solution configuration I added in Visual Studio. How do I check this value at runtime?</p>
[ { "answer_id": 31507, "author": "CiNN", "author_id": 2566, "author_profile": "https://Stackoverflow.com/users/2566", "pm_score": 3, "selected": false, "text": "#ifdef _ENABLE_CODE1_\nconst codeconfig = 1;\n#else\nconst codeconfig = 2;\n#endif\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/327/" ]
31,497
<p>What are some real world places that call for delegates? I'm curious what situations or patterns are present where this method is the best solution. No code required.</p>
[ { "answer_id": 31549, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 4, "selected": false, "text": "myList.Foreach( i => i.DoSomething());\n" }, { "answer_id": 2801349, "author": "dza", "author_id": 169854, "author_profile": "https://Stackoverflow.com/users/169854", "pm_score": 3, "selected": false, "text": "// Class Property Definition\npublic delegate void delPassData(TextBox text);\n\n\n// Click Handler\nprivate void btnSend_Click(object sender, System.EventArgs e)\n{\n Form2 frm= new Form2();\n delPassData del=new delPassData(frm.funData);\n del(this.textBox1);\n frm.Show();\n}\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31497", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1635/" ]
31,498
<p>I have a generic class that should allow any type, primitive or otherwise. The only problem with this is using <code>default(T)</code>. When you call default on a value type or a string, it initializes it to a reasonable value (such as empty string). When you call <code>default(T)</code> on an object, it returns null. For various reasons we need to ensure that if it is not a primitive type, then we will have a default instance of the type, <strong>not</strong> null. Here is attempt 1:</p> <pre><code>T createDefault() { if(typeof(T).IsValueType) { return default(T); } else { return Activator.CreateInstance&lt;T&gt;(); } } </code></pre> <p>Problem - string is not a value type, but it does not have a parameterless constructor. So, the current solution is:</p> <pre><code>T createDefault() { if(typeof(T).IsValueType || typeof(T).FullName == "System.String") { return default(T); } else { return Activator.CreateInstance&lt;T&gt;(); } } </code></pre> <p>But this feels like a kludge. Is there a nicer way to handle the string case?</p>
[ { "answer_id": 31512, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 4, "selected": false, "text": "if (typeof(T).IsValueType || typeof(T) == typeof(String))\n{\n return default(T);\n}\nelse\n{\n return Activator.CreateInstance<T>();\n}\n" }, { "answer_id": 31513, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 9, "selected": true, "text": "if (typeof(T) == typeof(String)) return (T)(object)String.Empty;\n" }, { "answer_id": 4984105, "author": "Anil", "author_id": 615020, "author_profile": "https://Stackoverflow.com/users/615020", "pm_score": -1, "selected": false, "text": " private T createDefault()\n { \n\n { \n if(typeof(T).IsValueType) \n { \n return default(T); \n }\n else if (typeof(T).Name == \"String\")\n {\n return (T)Convert.ChangeType(String.Empty,typeof(T));\n }\n else\n {\n return Activator.CreateInstance<T>();\n } \n } \n\n }\n" }, { "answer_id": 28435923, "author": "theoski", "author_id": 598807, "author_profile": "https://Stackoverflow.com/users/598807", "pm_score": 2, "selected": false, "text": "public static class Extensions { \n public static String Blank(this String me) { \n return String.Empty;\n }\n public static T Blank<T>(this T me) { \n var tot = typeof(T);\n return tot.IsValueType\n ? default(T)\n : (T)Activator.CreateInstance(tot)\n ;\n }\n}\nclass Program {\n static void Main(string[] args) {\n Object o = null;\n String s = null;\n int i = 6;\n Console.WriteLine(o.Blank()); //\"System.Object\"\n Console.WriteLine(s.Blank()); //\"\"\n Console.WriteLine(i.Blank()); //\"0\"\n Console.ReadKey();\n }\n}\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/67/" ]
31,500
<p>If I have a query like:</p> <pre><code>Select EmployeeId From Employee Where EmployeeTypeId IN (1,2,3) </code></pre> <p>and I have an index on the <code>EmployeeTypeId</code> field, does SQL server still use that index?</p>
[ { "answer_id": 31520, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 6, "selected": true, "text": "Employee" }, { "answer_id": 33584, "author": "lomaxx", "author_id": 493, "author_profile": "https://Stackoverflow.com/users/493", "pm_score": 1, "selected": false, "text": "int[] employeeIds = new int[]{1, 5, 23463, 32523};\nNHibernateSession.CreateCriteria(typeof(Employee))\n.Add(Restrictions.InG(\"EmployeeId\",employeeIds))\n" }, { "answer_id": 44158454, "author": "Tushar Rmesh Saindane", "author_id": 7034587, "author_profile": "https://Stackoverflow.com/users/7034587", "pm_score": 0, "selected": false, "text": "Select EmployeeId From Employee USE(INDEX(EmployeeTypeId))\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/493/" ]
31,535
<p>I'm trying to fetch some HTML from various blogs and have noticed that different providers use the same tag in different ways.</p> <p>For example, here are two major providers that use the meta name generator tag differently:</p> <ul> <li>Blogger: <code>&lt;meta content='blogger' name='generator'/&gt;</code> (content first, name later and, yes, single quotes!) </li> <li>WordPress: <code>&lt;meta name="generator" content="WordPress.com" /&gt;</code> (name first, content later)</li> </ul> <p>Is there a way to extract the value of content for all cases (single/double quotes, first/last in the row)?</p> <p>P.S. Although I'm using Java, the answer would probably help more people if it where for regular expressions generally.</p>
[ { "answer_id": 31595, "author": "martinatime", "author_id": 1353, "author_profile": "https://Stackoverflow.com/users/1353", "pm_score": 0, "selected": false, "text": "/<meta\\s.*content=.*>/" }, { "answer_id": 31622, "author": "dwestbrook", "author_id": 3119, "author_profile": "https://Stackoverflow.com/users/3119", "pm_score": 0, "selected": false, "text": "content\\s*=\\s*['\"].*?['\"]\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31535", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2644/" ]
31,551
<p>Using SqlServer, and trying to update rows from within the same table. I want to use a table alias for readability. This is the way I am doing it at the moment:</p> <pre><code>UPDATE ra SET ra.ItemValue = rb.ItemValue FROM dbo.Rates ra, dbo.Rates rb WHERE ra.ResourceID = rb.ResourceID AND ra.PriceSched = 't8' AND rb.PriceSched = 't9' </code></pre> <p>Are there easier / better ways?</p>
[ { "answer_id": 835999, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "UPDATE ra \n SET ra.ItemValue = rb.ItemValue\n FROM dbo.Rates ra\n INNER JOIN dbo.Rates rb\n ON ra.ResourceID = rb.ResourceID\nWHERE ra.PriceSched = 't8'\n AND rb.PriceSched = 't9';\n" }, { "answer_id": 14413368, "author": "Subhas Malik", "author_id": 1533745, "author_profile": "https://Stackoverflow.com/users/1533745", "pm_score": 1, "selected": false, "text": "UPDATE A_GeneralLedger set ScheduleId=g.ScheduleId\nfrom A_GeneralLedger l inner join A_AcGroup g on g.ACGroupID=l.AccountGroupID\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2027/" ]
31,559
<p><a href="http://www.devexpress.com/Products/NET/ORM/" rel="noreferrer">XPO</a> is the object relational mapper of choice at my company. Any thoughts on the pros and cons?</p> <hr> <p>I was just looking for general feeling and anecdotes about the product. We are not switching to XPO. We are just getting rid of hard coded sql strings living in the app and moving completely to ORM for all data access.</p>
[ { "answer_id": 2686616, "author": "Roman Eremin", "author_id": 318097, "author_profile": "https://Stackoverflow.com/users/318097", "pm_score": 0, "selected": false, "text": "using System;\nusing DevExpress.Xpo;\nusing DevExpress.Data.Filtering;\nusing NUnit.Framework;\n\nnamespace XpoTdd {\n public class Person:XPObject {\n public Person(Session session) : base(session) { }\n public string FirstName { get; set; }\n public string LastName { get; set; }\n [Persistent]\n public string FullName { get { return FirstName + \" \" + LastName; } }\n }\n [TestFixture]\n public class PersonTests {\n [Test]\n public void TestPersistence() {\n const string connStr = \"Integrated Security=SSPI;Pooling=false;Data Source=(local);Initial Catalog=XpoTddTest\";\n UnitOfWork session1 = new UnitOfWork();\n session1.ConnectionString = connStr;\n Person me = new Person(session1);\n me.FirstName = \"Roman\";\n me.LastName = \"Eremin\";\n session1.CommitChanges();\n UnitOfWork session2 = new UnitOfWork();\n session2.ConnectionString = connStr;\n me = session2.FindObject<Person>(CriteriaOperator.Parse(\"FullName = 'Roman Eremin'\"));\n Assert.AreEqual(\"Roman Eremin\", me.FullName);\n }\n }\n}\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1455/" ]
31,561
<p>Depending on my mood I seem to waffle back and forth between wanting a Lisp-1 and a Lisp-2. Unfortunately beyond the obvious name space differences, this leaves all kinds of amusing function name/etc problems you run into. Case in point, trying to write some code tonight I tried to do (map #'function listvar) which, of course, doesn't work in CL, at all. Took me a bit to remember I wanted mapcar, not map. Of course it doesn't help when slime/emacs shows map IS defined as something, though obviously not the same function at all.</p> <p>So, pointers on how to minimize this short of picking one or the other and sticking with it?</p>
[ { "answer_id": 31603, "author": "Alasdair", "author_id": 2654, "author_profile": "https://Stackoverflow.com/users/2654", "pm_score": 4, "selected": true, "text": "(map 'list #'function listvar)\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31561", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3326/" ]
31,567
<p>I'm trying to wrap my head around reflection, so I decided to add plugin capability to a program that I'm writing. The only way to understand a concept is to get your fingers dirty and write the code, so I went the route of creating a simple interface library consisting of the IPlugin and IHost interfaces, a plugin implementation library of classes that implement IPlugin, and a simple console project that instantiates the IHost implementation class that does simple work with the plugin objects. </p> <p>Using reflection, I wanted to iterate through the types contained inside my plugin implementation dll and create instances of types. I was able to sucessfully instantiate classes with this code, but I could not cast the created object to the interface.</p> <p>I tried this code but I couldn't cast object o as I expected. I stepped through the process with the debugger and the proper constructor was called. Quickwatching object o showed me that it had the fields and properties that I expected to see in the implementation class. </p> <pre><code>loop through assemblies loop through types in assembly // Filter out unwanted types if (!type.IsClass || type.IsNotPublic || type.IsAbstract ) continue; // This successfully created the right object object o = Activator.CreateInstance(type); // This threw an Invalid Cast Exception or returned null for an "as" cast // even though the object implemented IPlugin IPlugin i = (IPlugin) o; </code></pre> <p>I made the code work with this.</p> <pre><code>using System.Runtime.Remoting; ObjectHandle oh = Activator.CreateInstance(assembly.FullName, type.FullName); // This worked as I intended IPlugin i = (IPlugin) oh.Unwrap(); i.DoStuff(); </code></pre> <p>Here are my questions:</p> <ol> <li>Activator.CreateInstance(Type t) returns an object, but I couldn't cast the object to an interface that the object implemented. Why?</li> <li>Should I have been using a different overload of CreateInstance()?</li> <li>What are the reflection related tips and tricks?</li> <li>Is there some crucial part of reflection that I'm just not getting? </li> </ol>
[ { "answer_id": 31576, "author": "Haacked", "author_id": 598, "author_profile": "https://Stackoverflow.com/users/598", "pm_score": 0, "selected": false, "text": "Activator.CreateInstance(type, true);\n" }, { "answer_id": 178205, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "IPluginModule pluginModule = (IPluginModule)Activator.CreateInstance(curType);\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31567", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1880/" ]
31,572
<p>I'm working on a .net solution that is run completely inside a single network. When users make a change to the system, I want to launch an announcement and have everyone else hear it and act accordingly. Is there a way that we can broadcast out messages like this (like UDP will let you do) while keeping guaranteed delivery (like TCP)?</p> <p>This is on a small network (30ish clients), if that would make a difference.</p>
[ { "answer_id": 2099535, "author": "Matthew Herrmann", "author_id": 232066, "author_profile": "https://Stackoverflow.com/users/232066", "pm_score": 1, "selected": false, "text": "read(max_size=2)" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3259/" ]
31,584
<p>For classes that have a long list of setters that are used frequently, I found this way very useful (although I have recently read about the <a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="noreferrer">Builder pattern</a> in <em>Effective Java</em> that is kinda the same).</p> <p>Basically, all setter methods return the object itself so then you can use code like this:</p> <pre><code>myClass .setInt(1) .setString(&quot;test&quot;) .setBoolean(true); </code></pre> <p>Setters simply return this in the end:</p> <pre><code>public MyClass setInt(int anInt) { // [snip] return this; } </code></pre> <p>What is your opinion? What are the pros and cons? Does this have any impact on performance?</p> <p>Also referred to as the <a href="http://www.cs.technion.ac.il/users/yechiel/c++-faq/named-parameter-idiom.html" rel="noreferrer">named parameter idiom</a> in c++.</p>
[ { "answer_id": 31606, "author": "martinatime", "author_id": 1353, "author_profile": "https://Stackoverflow.com/users/1353", "pm_score": -1, "selected": false, "text": " MyClass\n .setInt(1)\n .setString(\"test\")\n .setBoolean(true)\n ;\n" }, { "answer_id": 31621, "author": "Cagatay", "author_id": 3071, "author_profile": "https://Stackoverflow.com/users/3071", "pm_score": 1, "selected": false, "text": "aWithB = myObject.withA(someA).withB(someB);\n" }, { "answer_id": 46858, "author": "Tom Hawtin - tackline", "author_id": 4725, "author_profile": "https://Stackoverflow.com/users/4725", "pm_score": 1, "selected": false, "text": "Something thing = new SomethingBuilder()\n .aProperty(wotsit)\n .anotherProperty(somethingElse)\n .create();\n" }, { "answer_id": 3741052, "author": "Sanjay Mishra", "author_id": 451308, "author_profile": "https://Stackoverflow.com/users/451308", "pm_score": 0, "selected": false, "text": "/**\n *\n * @author sanjay\n */\npublic class NewClass {\nprivate int left ;\nprivate int top;\npublic void set(int x,int y)\n {\n left=x;\n top=y;\n}\npublic NewClass UP(int x)\n {\n top+=x;\n return this;\n}\npublic NewClass DOWN(int x)\n {\n top-=x;\n return this;\n}\npublic NewClass RIGHT(int x)\n {\n left+=x;\n return this;\n}\npublic NewClass LEFT(int x)\n {\n left-=x;\n return this;\n}\npublic void Display()\n {\n System.out.println(\"TOP:\"+top);\n System.out.println(\"\\nLEFT\\n:\"+left);\n}\n}\npublic static void main(String[] args) {\n // TODO code application logic here\n NewClass test = new NewClass();\n test.set(0,0);\n test.Display();\n test.UP(20).UP(45).DOWN(12).RIGHT(32).LEFT(20);\n test.Display();\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2644/" ]
31,672
<p>I've recently come to maintain a large amount of scientific calculation-intensive FORTRAN code. I'm having difficulties getting a handle on all of the, say, nuances, of a forty year old language, despite google &amp; two introductory level books. The code is rife with "performance enhancing improvements". Does anyone have any guides or practical advice for <strong>de</strong>-optimizing FORTRAN into CS 101 levels? Does anyone have knowledge of how FORTRAN code optimization operated? Are there any typical FORTRAN 'gotchas' that might not occur to a Java/C++/.NET raised developer taking over a FORTRAN 77/90 codebase?</p>
[ { "answer_id": 67624, "author": "user7116", "author_id": 7116, "author_profile": "https://Stackoverflow.com/users/7116", "pm_score": 7, "selected": true, "text": "myloop: do ii = 1, nloops\n ! do something\nenddo myloop\n" }, { "answer_id": 8818294, "author": "J . A. Maruhn", "author_id": 1143047, "author_profile": "https://Stackoverflow.com/users/1143047", "pm_score": 3, "selected": false, "text": "GOTO" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1390/" ]
31,673
<p>Wifi support on Vista is fine, but <a href="http://msdn.microsoft.com/en-us/library/bb204766.aspx" rel="nofollow noreferrer">Native Wifi on XP</a> is half baked. <a href="http://msdn.microsoft.com/en-us/library/aa504121.aspx" rel="nofollow noreferrer">NDIS 802.11 Wireless LAN Miniport Drivers</a> only gets you part of the way there (e.g. network scanning). From what I've read (and tried), the 802.11 NDIS drivers on XP will <em>not</em> allow you to configure a wireless connection. You have to use the Native Wifi API in order to do this. (Please, correct me if I'm wrong here.) Applications like <a href="http://www.metageek.net/products/inssider" rel="nofollow noreferrer">InSSIDer</a> have helped me to understand the APIs, but InSSIDer is just a scanner and is not designed to configure Wifi networks.</p> <p>So, the question is: where can I find some code examples (C# or C++) that deal with the configuration of Wifi networks on XP -- e.g. profile creation and connection management?</p> <p>I should note that this is a XP Embedded application on a closed system where we can't use the built-in Wireless Zero Configuration (WZC). We have to build all Wifi management functionality into our .NET application.</p> <p>Yes, I've Googled myself blue. It seems that someone should have a solution to this problem, but I can't find it. That's why I'm asking here.</p> <p>Thanks.</p>
[ { "answer_id": 67624, "author": "user7116", "author_id": 7116, "author_profile": "https://Stackoverflow.com/users/7116", "pm_score": 7, "selected": true, "text": "myloop: do ii = 1, nloops\n ! do something\nenddo myloop\n" }, { "answer_id": 8818294, "author": "J . A. Maruhn", "author_id": 1143047, "author_profile": "https://Stackoverflow.com/users/1143047", "pm_score": 3, "selected": false, "text": "GOTO" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2514/" ]
31,693
<p>I mostly use Java and generics are relatively new. I keep reading that Java made the wrong decision or that .NET has better implementations etc. etc.</p> <p>So, what are the main differences between C++, C#, Java in generics? Pros/cons of each?</p>
[ { "answer_id": 31758, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 6, "selected": false, "text": "template <unsigned int N>\nstruct product {\n static unsigned int const VALUE = N * product<N - 1>::VALUE;\n};\n\ntemplate <>\nstruct product<1> {\n static unsigned int const VALUE = 1;\n};\n\n// Usage:\nunsigned int const p5 = product<5>::VALUE;\n" }, { "answer_id": 31778, "author": "izb", "author_id": 974, "author_profile": "https://Stackoverflow.com/users/974", "pm_score": 1, "selected": false, "text": "a = new ArrayList<String>()\na.getClass() => ArrayList\n" }, { "answer_id": 31821, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": false, "text": "template <typename T>\nstruct X {\n void foo() { }\n};\n\ntemplate <>\nstruct X<int> { };\n\ntypedef int my_int_type;\n\nX<my_int_type> a;\na.|\n" }, { "answer_id": 31866, "author": "serg10", "author_id": 1853, "author_profile": "https://Stackoverflow.com/users/1853", "pm_score": 3, "selected": false, "text": "// java.lang.Enum Definition in Java\npublic abstract class Enum<E extends Enum<E>> implements Comparable<E>, Serializable {\n" }, { "answer_id": 31929, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 10, "selected": true, "text": "List<Person> foo = new List<Person>();\n" }, { "answer_id": 1109644, "author": "Daniel Earwicker", "author_id": 27423, "author_profile": "https://Stackoverflow.com/users/27423", "pm_score": 2, "selected": false, "text": "public <T> void Foo(Collection<T> thing)\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2644/" ]
31,701
<p>I have a mapping application that needs to draw a path, and then display icons on top of the path. I can't find a way to control the order of virtual earth layers, other than the order in which they are added. </p> <p>Does anyone know how to change the z index of Virtual Earth shape layers, or force a layer to the front?</p>
[ { "answer_id": 31758, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 6, "selected": false, "text": "template <unsigned int N>\nstruct product {\n static unsigned int const VALUE = N * product<N - 1>::VALUE;\n};\n\ntemplate <>\nstruct product<1> {\n static unsigned int const VALUE = 1;\n};\n\n// Usage:\nunsigned int const p5 = product<5>::VALUE;\n" }, { "answer_id": 31778, "author": "izb", "author_id": 974, "author_profile": "https://Stackoverflow.com/users/974", "pm_score": 1, "selected": false, "text": "a = new ArrayList<String>()\na.getClass() => ArrayList\n" }, { "answer_id": 31821, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": false, "text": "template <typename T>\nstruct X {\n void foo() { }\n};\n\ntemplate <>\nstruct X<int> { };\n\ntypedef int my_int_type;\n\nX<my_int_type> a;\na.|\n" }, { "answer_id": 31866, "author": "serg10", "author_id": 1853, "author_profile": "https://Stackoverflow.com/users/1853", "pm_score": 3, "selected": false, "text": "// java.lang.Enum Definition in Java\npublic abstract class Enum<E extends Enum<E>> implements Comparable<E>, Serializable {\n" }, { "answer_id": 31929, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 10, "selected": true, "text": "List<Person> foo = new List<Person>();\n" }, { "answer_id": 1109644, "author": "Daniel Earwicker", "author_id": 27423, "author_profile": "https://Stackoverflow.com/users/27423", "pm_score": 2, "selected": false, "text": "public <T> void Foo(Collection<T> thing)\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2785/" ]
31,708
<p>I am using LINQ to query a generic dictionary and then use the result as the datasource for my ListView (WebForms).</p> <p>Simplified code:</p> <pre><code>Dictionary&lt;Guid, Record&gt; dict = GetAllRecords(); myListView.DataSource = dict.Values.Where(rec =&gt; rec.Name == "foo"); myListView.DataBind(); </code></pre> <p>I thought that would work but in fact it throws a <strong>System.InvalidOperationException</strong>: </p> <blockquote> <p>ListView with id 'myListView' must have a data source that either implements ICollection or can perform data source paging if AllowPaging is true.</p> </blockquote> <p>In order to get it working I have had to resort to the following:</p> <pre><code>Dictionary&lt;Guid, Record&gt; dict = GetAllRecords(); List&lt;Record&gt; searchResults = new List&lt;Record&gt;(); var matches = dict.Values.Where(rec =&gt; rec.Name == "foo"); foreach (Record rec in matches) searchResults.Add(rec); myListView.DataSource = searchResults; myListView.DataBind(); </code></pre> <p>Is there a small gotcha in the first example to make it work?</p> <p>(Wasn't sure what to use as the question title for this one, feel free to edit to something more appropriate)</p>
[ { "answer_id": 31710, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 6, "selected": true, "text": "var matches = dict.Values.Where(rec => rec.Name == \"foo\").ToList();\n" }, { "answer_id": 31712, "author": "lomaxx", "author_id": 493, "author_profile": "https://Stackoverflow.com/users/493", "pm_score": 1, "selected": false, "text": "myListView.DataSource = (List<Record>) dict.Values.Where(rec => rec.Name == \"foo\");\n" }, { "answer_id": 31713, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 2, "selected": false, "text": "var matches = new List<Record>(dict.Values.Where(rec => rec.Name == \"foo\"));\n" }, { "answer_id": 32016, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 3, "selected": false, "text": "myListView.DataSource = (\n from rec in GetAllRecords().Values\n where rec.Name == \"foo\"\n select rec ).ToList();\nmyListView.DataBind();\n" }, { "answer_id": 38828112, "author": "Elias MP", "author_id": 5770216, "author_profile": "https://Stackoverflow.com/users/5770216", "pm_score": 0, "selected": false, "text": "dict.Values.Where(rec => rec.Name == \"foo\")\n" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31708", "https://Stackoverflow.com", "https://Stackoverflow.com/users/202/" ]
31,722
<p>I'm interested in seeing a good diff algorithm, possibly in Javascript, for rendering a side-by-side diff of two HTML pages. The idea would be that the diff would show the differences of the <em>rendered</em> HTML.</p> <p>To clarify, I want to be able to see the side-by-side diffs <em>as</em> rendered output. So if I delete a paragraph, the side by side view would know to space things correctly.</p> <hr> <p>@Josh exactly. Though maybe it would show the deleted text in red or something. The idea is that if I use a WYSIWYG editor for my HTML content, I don't want to have to switch to HTML to do diffs. I want to do it with two WYSIWYG editors side by side maybe. Or at least display diffs side-by-side in an end-user friendly matter.</p>
[ { "answer_id": 31728, "author": "Josh", "author_id": 257, "author_profile": "https://Stackoverflow.com/users/257", "pm_score": 1, "selected": false, "text": "<font face=\"Arial\">Hi Mom</font>\n" }, { "answer_id": 33500, "author": "kamens", "author_id": 1335, "author_profile": "https://Stackoverflow.com/users/1335", "pm_score": 5, "selected": true, "text": "visibility:hidden" } ]
2008/08/28
[ "https://Stackoverflow.com/questions/31722", "https://Stackoverflow.com", "https://Stackoverflow.com/users/598/" ]