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_...
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{...
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{...
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://Stacko...
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": "...
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://...
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://...
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://...
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}\...
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": ...
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...
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"...
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 HR...
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_...
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"...
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 nam...
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,...
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<Mana...
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://Stackov...
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"...
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": "http...
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://Stac...
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, ...
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: $(...
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})*)(?::(\...
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 '\...
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\", \...
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(Mat...
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 O...
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": "h...
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 );\n...
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...
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": "ht...
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" }, { "an...
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()== Dialo...
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" }, ...
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": ...
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": "ht...
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.S...
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://...
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 : Veh...
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.Vi...
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, "...
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_pr...
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...
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 ...
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...
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, ...
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 ...
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+U...
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_pr...
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....
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...
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...
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...
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_pro...
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 ...
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 ...
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.__...
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.2...
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" }, { "answ...
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 //w...
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, ...
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 inpu...
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" }, { "answe...
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...
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...
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, ...
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.Crea...
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://Stackov...
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_...
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....
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...
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, ...
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, ...
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. Maruh...
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. Maruh...
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\nt...
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\nt...
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": "l...
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_...
2008/08/28
[ "https://Stackoverflow.com/questions/31722", "https://Stackoverflow.com", "https://Stackoverflow.com/users/598/" ]