qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
241,425
<p>I'm also interested in other Symbian SDKs that allow to set their emulator's IMEI.</p>
[ { "answer_id": 280431, "author": "David Jacobson", "author_id": 28484, "author_profile": "https://Stackoverflow.com/users/28484", "pm_score": 1, "selected": false, "text": "#ifdef __WINS__" }, { "answer_id": 915150, "author": "JOM", "author_id": 113079, "author_profile": "https://Stackoverflow.com/users/113079", "pm_score": 2, "selected": true, "text": " TPlpVariantMachineId imei;\n PlpVariant::GetMachineIdL(imei); \n imei.Copy(_L(\"123456789012345\"));\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241425", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15647/" ]
241,453
<p>I'm experimenting with JavaFX making a small game. </p> <p>I want to add sound. How?</p> <p>I tried <code>MediaPlayer</code> with <code>media</code> defined with relative <code>source</code> attribute like:</p> <pre><code>attribute media = Media{ source: "{__FILE__}/sound/hormpipe.mp3" } attribute player = MediaPlayer{ autoPlay:true media:media } </code></pre> <p>It doesn't play. I get </p> <blockquote> <p><code>FX Media Object caught Exception com.sun.media.jmc.MediaUnavailableException: Media unavailable: file: ... Sound.class/sound/hormpipe.mp3</code></p> </blockquote>
[ { "answer_id": 368256, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "var player = javafx.scene.media.MediaPlayer {\n repeatCount: javafx.scene.media.MediaPlayer.REPEAT_FOREVER\n media: Media { source: \"{\\_\\_DIR\\_\\_}clip.wav\"\n };\n};\nplayer.play();\n" }, { "answer_id": 2957187, "author": "lindelof", "author_id": 1428, "author_profile": "https://Stackoverflow.com/users/1428", "pm_score": 0, "selected": false, "text": "{__FILE__}" }, { "answer_id": 3076042, "author": "MKA", "author_id": 371074, "author_profile": "https://Stackoverflow.com/users/371074", "pm_score": 0, "selected": false, "text": "{__DIR__}" }, { "answer_id": 20890384, "author": "daevon", "author_id": 2624587, "author_profile": "https://Stackoverflow.com/users/2624587", "pm_score": 0, "selected": false, "text": "MediaPlayer audio = new MediaPlayer(\n new Media(\n new File(\"file.mp3\").toURI().toString()));\n" }, { "answer_id": 39737525, "author": "ivanivan", "author_id": 6867430, "author_profile": "https://Stackoverflow.com/users/6867430", "pm_score": 0, "selected": false, "text": "Media sound=new Media(new File(\"noises/roll.wav\").toURI().toString());\nMediaPlayer mediaPlayer=new MediaPlayer(sound);\nmediaPlayer.play();\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1514822/" ]
241,454
<p>What is the best way to manage a database connection in a Java servlet?</p> <p>Currently, I simply open a connection in the <code>init()</code> function, and then close it in <code>destroy()</code>. </p> <p>However, I am concerned that "permanently" holding onto a database connection could be a bad thing. </p> <p>Is this the correct way to handle this? If not, what are some better options?</p> <p>edit: to give a bit more clarification: I have tried simply opening/closing a new connection for each request, but with testing I've seen performance issues due to creating too many connections.</p> <p>Is there any value in sharing a connection over multiple requests? The requests for this application are almost all "read-only" and come fairly rapidly (although the data requested is fairly small).</p>
[ { "answer_id": 241464, "author": "John Topley", "author_id": 1450, "author_profile": "https://Stackoverflow.com/users/1450", "pm_score": 1, "selected": false, "text": "doGet/doPost" }, { "answer_id": 241569, "author": "anjanb", "author_id": 11142, "author_profile": "https://Stackoverflow.com/users/11142", "pm_score": 1, "selected": false, "text": "doget" }, { "answer_id": 907320, "author": "Dan Rosenstark", "author_id": 8047, "author_profile": "https://Stackoverflow.com/users/8047", "pm_score": 5, "selected": false, "text": "finally" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12983/" ]
241,467
<p>As title. I didn't find one via google, at any rate.</p> <p>Update: thanks for the links from the two answers; this is very useful, but not what I was after - I am curious to see whether it is possible to query an IRepository backed by memcached (or some other distributed cache), backed by a RDBMS. I've really no idea how that might work in practise; I don't know very much about the internals of either distributed caches or LINQ providers.</p> <p>I'm maybe envisaging something like the cache LINQ provider generating cache-keys based on the query automatically (where query could be Expression> or some kind of Specification pattern implementation), and basically can be plumped down inbetween my app and my DB. Does that sound useful?</p>
[ { "answer_id": 352064, "author": "Funky81", "author_id": 37509, "author_profile": "https://Stackoverflow.com/users/37509", "pm_score": 1, "selected": false, "text": " public static IEnumerable<User> GetAllUsers() \n { \n // Retrieve from cache if it exists, otherwise run the query \n return (from u in ctx.Users select u).CachedQuery(\"allusers\"); \n } \n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20971/" ]
241,470
<p>I am designing a simple internal framework for handling time series data. Given that LINQ is my current toy hammer, I want to hit everything with it.</p> <p>I want to implement methods in class TimeSeries (Select(), Where() and so on) so that I can use LINQ syntax to handle time series data</p> <p>Some things are straight forward, e.g. (from x in A select x+10), giving a new time series.</p> <p>What is the best syntax design for combining two or more time series? (from a in A from b in B select a+b) is not great, since it expresses a nested loop. Maybe some join? This should correspond to join on the implicit time variable. (What I have in mind corresponds to the lisp 'zip' function)</p> <hr> <p><strong>EDIT:</strong> <em>Some clarification is necessary.</em></p> <p>A time series is a kind of function depending on time, e.g. stock quotes. A combination of time series could be the difference between two stock prices, as a function of time.</p> <pre><code>Stock1.MyJoin(Stock2, (a,b)=&gt;a-b) </code></pre> <p>is possible, but can this be expressed neatly using some LINQ syntax? I am expecting to implement LINQ methods in <code>class MyTimeSeries</code> myself.</p>
[ { "answer_id": 241478, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "Union" }, { "answer_id": 241563, "author": "Greg Beech", "author_id": 13552, "author_profile": "https://Stackoverflow.com/users/13552", "pm_score": 1, "selected": true, "text": "System.Linq.Enumerable" }, { "answer_id": 241590, "author": "Cameron MacFarland", "author_id": 3820, "author_profile": "https://Stackoverflow.com/users/3820", "pm_score": 1, "selected": false, "text": "public static IEnumerable<TResult> Zip<T1, T2, TResult>(\n this IEnumerable<T1> source1, \n IEnumerable<T2> source2, \n Func<T1, T2, TResult> combine)\n{\n if (source1 == null)\n throw new ArgumentNullException(\"source1\");\n if (source2 == null)\n throw new ArgumentNullException(\"source2\");\n if (combine == null)\n throw new ArgumentNullException(\"combine\");\n\n IEnumerator<T1> data1 = source1.GetEnumerator();\n IEnumerator<T2> data2 = source2.GetEnumerator();\n while (data1.MoveNext() && data2.MoveNext())\n {\n yield return combine(data1.Current, data2.Current);\n }\n}\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31890/" ]
241,507
<p>I think the title pretty much says it all... I'm looking to implement an interface similar to the standard OS X sidebar used in all the above mentioned programs, and I'm wondering if anybody has any thoughts as to the easiest way to do it, namely about what view to use for the left hand selection pane. Really I don't think I even need the hierarchical component as seen in the apple apps, I just need a good looking flat list of choices which determine what's shown in the right hand pane.</p> <p>The obvious start is a vertical split layout view, but beyond that I'm not entirely sure where to go. A collection view with only one column or something like that?</p>
[ { "answer_id": 241853, "author": "Ken", "author_id": 17320, "author_profile": "https://Stackoverflow.com/users/17320", "pm_score": 4, "selected": false, "text": "Highlight: Source List" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1512/" ]
241,512
<p>My HTML is as follows:</p> <pre><code>&lt;ul id="nav"&gt; &lt;li&gt;&lt;a href="./"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/About"&gt;About&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/Contact"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And my css:</p> <pre><code>#nav { display: inline; } </code></pre> <p>However the whitespace between the li's shows up. I can remove the whitespace by collapsing them like so:</p> <pre><code>&lt;ul id="nav"&gt; &lt;li&gt;&lt;a href="./"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/About"&gt;About&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/Contact"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>But this is being maintained largely by hand and I was wondering if there was a cleaner way of doing it.</p>
[ { "answer_id": 241523, "author": "thismat", "author_id": 14045, "author_profile": "https://Stackoverflow.com/users/14045", "pm_score": 6, "selected": true, "text": "<ul id=\"navigation\">\n <li><a href=\"#\" title=\"\">Home</a></li>\n <li><a href=\"#\" title=\"\">Home</a></li>\n <li><a href=\"#\" title=\"\">Home</a></li>\n</ul>\n" }, { "answer_id": 3143465, "author": "J. Holmes", "author_id": 373378, "author_profile": "https://Stackoverflow.com/users/373378", "pm_score": 4, "selected": false, "text": "<ul id=\"nav\"\n ><li><a href=\"./\">Home</a></li\n ><li><a href=\"/About\">About</a></li\n ><li><a href=\"/Contact\">Contact</a></li\n></ul>\n" }, { "answer_id": 3617275, "author": "Marius Schulz", "author_id": 362634, "author_profile": "https://Stackoverflow.com/users/362634", "pm_score": 5, "selected": false, "text": "font-size" }, { "answer_id": 4849282, "author": "guimihanui", "author_id": 596609, "author_profile": "https://Stackoverflow.com/users/596609", "pm_score": 3, "selected": false, "text": "</li>" }, { "answer_id": 6958307, "author": "Louisa", "author_id": 880805, "author_profile": "https://Stackoverflow.com/users/880805", "pm_score": 3, "selected": false, "text": "#nav li{float:left; width:auto;}\n" }, { "answer_id": 14598125, "author": "user2024227", "author_id": 2024227, "author_profile": "https://Stackoverflow.com/users/2024227", "pm_score": 0, "selected": false, "text": "<html>\n<head>\n<style>\nul li, ul li:before,ul li:after{display:inline; content:' '; }\n</style>\n</head>\n<body>\n<ul><li>one</li><li>two</li><li>three</li></ul>\n<ul>\n <li>one</li>\n <li>two</li>\n <li>three</li>\n</ul>\n</body>\n</html>\n" }, { "answer_id": 16908678, "author": "user764728", "author_id": 764728, "author_profile": "https://Stackoverflow.com/users/764728", "pm_score": 3, "selected": false, "text": "<ul style=\"font-size:0px;\">\n<li style=\"font-size:12px;\">\n</ul>\n" }, { "answer_id": 26307400, "author": "micha", "author_id": 1725482, "author_profile": "https://Stackoverflow.com/users/1725482", "pm_score": 1, "selected": false, "text": "<ul id=\"nav\">\n <li><a href=\"./\">Home</a></li>\n <li><a href=\"/About\">About</a></li>\n <li><a href=\"/Contact\">Contact</a></li>\n</ul>\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
241,513
<p>I've been trying to follow the information from:</p> <p><a href="http://www.datasprings.com/Resources/ArticlesInformation/Sharepoint2007CustomWebParts/tabid/775/Default.aspx" rel="nofollow noreferrer">Long URL clipped to stop breaking the page</a></p> <p>and</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms415817.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms415817.aspx</a></p> <p>Which more or less have the same instructions. I've been copying the .dll file from the build over to the BIN directory of the Sharepoint site.</p> <p>When I click the Web Part Gallery and hit new, both articles say that the web part should show up in the list.</p> <p>I have tried every possible way that I can think, but my web part will not show up in that list. Is there a step that I missed somewhere? Are there permissions that I should be thinking about? How exactly does Sharepoint recognize that there is a new web part. Is it simply from having the assembly placed in the BIN directory, or is it from adding the control in the safe list of web.config?</p> <p>I've added it to the safe controls list. I've tried every different combination that I could think of, but nothing has worked.</p> <p>Do I need to rename the .DLL assembly to something else?</p> <p>For the life of me I cannot figure this out.</p>
[ { "answer_id": 241527, "author": "AdamBT", "author_id": 22426, "author_profile": "https://Stackoverflow.com/users/22426", "pm_score": 2, "selected": false, "text": "... Namespace=\"*\" TypeName=\"*\" ..." }, { "answer_id": 241918, "author": "AdamBT", "author_id": 22426, "author_profile": "https://Stackoverflow.com/users/22426", "pm_score": 1, "selected": false, "text": "[assembly: AllowPartiallyTrustedCallers]\n" }, { "answer_id": 259601, "author": "Darren Steinweg", "author_id": 418, "author_profile": "https://Stackoverflow.com/users/418", "pm_score": 1, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<WebPart xmlns=\"http://schemas.microsoft.com/WebPart/v2\" >\n <Title>My Sample Web Part</Title>\n <Description>This web part displays \"Hello World\" on the page.</Description>\n <Assembly>My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ed03eac7f647a61</Assembly>\n <TypeName>My.Assembly.MyWebPartClassName</TypeName>\n <!-- Specify initial values for any additional base class or custom properties here. -->\n</WebPart>\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10420/" ]
241,526
<p>I've been tasked with build an accessible RSS feed for my company's job listings. I already have an RSS feed from our recruiting partner; so I'm transforming their RSS XML to our own proxy RSS feed to add additional data as well limit the number of items in the feed so we list on the latest jobs.</p> <p>The RSS validates via feedvalidator.org (with warnings); but the problem is this. Unfortunately, no matter how many times I tell them not to; my company's HR team directly copies and pastes their Word documents into our Recruiting partners CMS when inserting new job listings, leaving WordML in my feed. I believe this WordML is causing issues with Feedburner's BrowserFriendly feature; which we want to show up to make it easier for people to subscribe. Therefore, I need to remove the WordML markup in the feed.</p> <p>Anybody have experience doing this? Can anyone point me to a good solution to this problem?</p> <p>Preferably; I'd like to be pointed to a solution in .Net (VB or C# is fine) and/or XSL.</p> <p>Any advice on this is greatly appreciated.</p> <p>Thanks.</p>
[ { "answer_id": 241562, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "char[] charToRemove = { (char)8217, (char)8216, (char)8220, (char)8221, (char)8211 };\nchar[] charToAdd = { (char)39, (char)39, (char)34, (char)34, '-' };\nstring cleanedStr = \"Your WordML filled Feed Text.\";\n\nfor (int i = 0; i < charToRemove.Length; i++)\n{\n cleanedStr = cleanedStr.Replace(charToRemove.GetValue(i).ToString(), charToAdd.GetValue(i).ToString());\n}\n" }, { "answer_id": 243423, "author": "ChuckB", "author_id": 28605, "author_profile": "https://Stackoverflow.com/users/28605", "pm_score": 2, "selected": true, "text": " <!-- Copy all elements, and recur on their child nodes. -->\n <xsl:template match=\"*\">\n <xsl:copy>\n <xsl:apply-templates select=\"@*\"/>\n <xsl:apply-templates/>\n </xsl:copy>\n </xsl:template>\n\n <!-- Copy all non-element nodes. -->\n <xsl:template match=\"@*|text()|comment()|processing-instruction()\">\n <xsl:copy/>\n </xsl:template>\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10922/" ]
241,533
<p>I want to write a program that would print every combination of a set of variables to a text file, creating a word list. Each answer should be written on a separate line and write all of the results for 1 digit, 2 digits, and 3 digits to a single text file.</p> <p>Is there a simple way I can write a python program that can accomplish this? Here is an example of the output I am expecting when printing all the binary number combinations possible for 1, 2, and 3 digits:</p> <pre><code>Output: 0 1 00 01 10 11 000 001 010 011 100 101 110 111 </code></pre>
[ { "answer_id": 241542, "author": "wprl", "author_id": 17847, "author_profile": "https://Stackoverflow.com/users/17847", "pm_score": 2, "selected": false, "text": "for(int i=0; i < 2^digits; i++)\n{\n WriteLine(ToBinaryString(i));\n}\n" }, { "answer_id": 241557, "author": "Darius Bacon", "author_id": 27024, "author_profile": "https://Stackoverflow.com/users/27024", "pm_score": 2, "selected": false, "text": "# Given two lists of strings, return a list of all ways to concatenate\n# one from each.\ndef combos(xs, ys):\n return [x + y for x in xs for y in ys]\n\ndigits = ['0', '1']\nfor c in combos(digits, combos(digits, digits)):\n print c\n\n#. 000\n#. 001\n#. 010\n#. 011\n#. 100\n#. 101\n#. 110\n#. 111\n" }, { "answer_id": 241577, "author": "Andrew Walker", "author_id": 2246, "author_profile": "https://Stackoverflow.com/users/2246", "pm_score": 2, "selected": false, "text": "def perms(seq):\n if seq == []:\n yield []\n else:\n res = []\n for index,item in enumerate(seq):\n rest = seq[:index] + seq[index+1:]\n for restperm in perms(rest):\n yield [item] + restperm\n\nalist = [1,1,0]\nfor permuation in perms(alist):\n print permuation\n" }, { "answer_id": 242141, "author": "zvoase", "author_id": 31600, "author_profile": "https://Stackoverflow.com/users/31600", "pm_score": 3, "selected": true, "text": "def combinations(words, length):\n if length == 0:\n return []\n result = [[word] for word in words]\n while length > 1:\n new_result = []\n for combo in result:\n new_result.extend(combo + [word] for word in words)\n result = new_result[:]\n length -= 1\n return result\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241533", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
241,539
<p>I am extending a class defined in a library which I cannot change:</p> <pre><code>public class Parent { public void init(Map properties) { ... } } </code></pre> <p>If I am defining a class 'Child' that extends Parent and I am using Java 6 with generics, what is the best way to override the init method without getting unchecked warnings?</p> <pre><code>public class Child extends Parent { // warning: Map is a raw type. References to generic type Map&lt;K,V&gt; should be parameterized public void init(Map properties) { } } </code></pre> <p>If I add generic parameters, I get:</p> <pre><code> // error: The method init(Map&lt;Object,Object&gt;) of type Child has the same erasure as init(Map) of type Parent but does not override it public void init(Map&lt;Object,Object&gt;) { ... } // same error public void init(Map&lt;? extends Object,? extends Object&gt;) { ... } // same error public void init(Map&lt;?,?&gt;) { ... } </code></pre> <p>This error occurs regardless of whether I use a specific type, a bounded wildcard, or an unbounded wildcard. Is there a correct or idiomatic way to override a non-generic method without warnings, and without using @SuppressWarnings("unchecked")?</p>
[ { "answer_id": 241933, "author": "Dov Wasserman", "author_id": 26010, "author_profile": "https://Stackoverflow.com/users/26010", "pm_score": 5, "selected": true, "text": "@SuppressWarnings(\"unchecked\")" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16399/" ]
241,540
<p>I'm a little unsure how the open source licensing stuff works. If I were to choose a particular open source license, what do you actually have to do to make it applicable to your software? I would imagine it would be a little more involved than just 'stating' that you're releasing your software under LGPL. And how does this 'contract' bind legally to your software?</p>
[ { "answer_id": 241556, "author": "Kirk Strauser", "author_id": 32538, "author_profile": "https://Stackoverflow.com/users/32538", "pm_score": 2, "selected": false, "text": "<one line to give the program's name and a brief idea of what it does.>\nCopyright (C) <year> <name of author>\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <http://www.gnu.org/licenses/>.\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241540", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30563/" ]
241,541
<p>We decided to use the minimumRequiredVersion in our clickOnce application manifest, and now when we try to rollback to a previous version when the user launches the application it fails to start. It says the application manifest has a earlier version than the required version and the user can not use the application. We did not have this problem withou the minimumRequiredVersion, but we would like to use that. </p>
[ { "answer_id": 11282320, "author": "Hasani Blackwell", "author_id": 79668, "author_profile": "https://Stackoverflow.com/users/79668", "pm_score": 0, "selected": false, "text": "\nusing System;\nusing System.Deployment.Application;\nusing System.Reflection;\n\nnamespace ClickOnceAppRollback\n{\n static class Program\n {\n /// \n /// The main entry point for the application.\n /// \n static void Main()\n {\n string appId = string.Format(\"{0}#{1}, Version={2}, Culture={3}, PublicKeyToken={4}, processorArchitecture={5}/{6}, Version={7}, Culture={8}, PublicKeyToken={9}, processorArchitecture={10}, type={11}\",\n /*The URI location of the app*/@\"http://www.microsoft.com/coolapp.exe.application\",\n /*The application's assemblyIdentity name*/\"coolapp.app\",\n /*The application's assemblyIdentity version*/\"10.8.62.17109\",\n /*The application's assemblyIdentity language*/\"neutral\",\n /*The application's assemblyIdentity public Key Token*/\"0000000000000000\",\n /*The application's assemblyIdentity processor architecture*/\"msil\",\n /*The deployment's dependentAssembly name*/\"coolapp.exe\",\n /*The deployment's dependentAssembly version*/\"10.8.62.17109\",\n /*The deployment's dependentAssembly language*/\"neutral\",\n /*The deployment's dependentAssembly public Key Token*/\"0000000000000000\",\n /*The deployment's dependentAssembly processor architecture*/\"msil\",\n /*The deployment's dependentAssembly type*/\"win32\");\n\n var ctor = typeof(ApplicationDeployment).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(string) }, null);\n var appDeployment = ctor.Invoke(new object[] { appId });\n\n var subState = appDeployment.GetType().GetField(\"_subState\", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(appDeployment);\n var subStore = appDeployment.GetType().GetField(\"_subStore\", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(appDeployment);\n try\n {\n subStore.GetType().GetMethod(\"RollbackSubscription\").Invoke(subStore, new object[] { subState });\n }\n catch\n {\n subStore.GetType().GetMethod(\"UninstallSubscription\").Invoke(subStore, new object[] { subState });\n }\n }\n }\n}\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5102/" ]
241,550
<p>What are some good jQuery Resources along with some gotchas when using it with ASP.Net?</p>
[ { "answer_id": 241588, "author": "Adam Lassek", "author_id": 1249, "author_profile": "https://Stackoverflow.com/users/1249", "pm_score": 3, "selected": false, "text": "$('[id$=myid]')" }, { "answer_id": 241658, "author": "tsimon", "author_id": 1685, "author_profile": "https://Stackoverflow.com/users/1685", "pm_score": 3, "selected": true, "text": "protected override void RenderAttributes(HtmlTextWriter writer) {\n HtmlControlImpl.RenderAttributes(this, writer);\n}\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26931/" ]
241,570
<p>Is there anyway to automatically run <code>javascript:window.print()</code> when the page finishes loading? </p>
[ { "answer_id": 241572, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 8, "selected": true, "text": "<body onload=\"window.print()\">" }, { "answer_id": 10467046, "author": "drftorres", "author_id": 1327395, "author_profile": "https://Stackoverflow.com/users/1327395", "pm_score": 4, "selected": false, "text": "<script type=\"text/javascript\">\n<!--\nwindow.print();\n//-->\n</script>\n" }, { "answer_id": 39100730, "author": "hojjat.mi", "author_id": 5281989, "author_profile": "https://Stackoverflow.com/users/5281989", "pm_score": 3, "selected": false, "text": " <script type=\"text/javascript\">\n window.onload = function() { window.print(); }\n </script>\n" }, { "answer_id": 52680691, "author": "Daniyal Tariq", "author_id": 6101193, "author_profile": "https://Stackoverflow.com/users/6101193", "pm_score": 3, "selected": false, "text": "<head>\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n</head>\n\n<script type=\"text/javascript\">\n\n$(document).ready(function () {\n window.print();\n});\n\n</script>\n" }, { "answer_id": 61132833, "author": "Justin", "author_id": 4907950, "author_profile": "https://Stackoverflow.com/users/4907950", "pm_score": 0, "selected": false, "text": "<script>window.print();</script>" }, { "answer_id": 64756676, "author": "DanyMartinez_", "author_id": 3562098, "author_profile": "https://Stackoverflow.com/users/3562098", "pm_score": 1, "selected": false, "text": " window.open(basePath + \"Controller/Route/?ID=\" + param, '_blank').print();\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26004/" ]
241,579
<p>If I import a library to use a method, would it be worth it? Does importing take up a lot of memory?</p>
[ { "answer_id": 241583, "author": "Leon Timmermans", "author_id": 4727, "author_profile": "https://Stackoverflow.com/users/4727", "pm_score": 3, "selected": false, "text": "my %number_for = (\n jan => 1,\n feb => 2,\n#etc...\n);\n#...\ndo_something_with($number_for{$month})\n" }, { "answer_id": 241589, "author": "Oskar", "author_id": 5472, "author_profile": "https://Stackoverflow.com/users/5472", "pm_score": 6, "selected": true, "text": "%mon2num = qw(\n jan 1 feb 2 mar 3 apr 4 may 5 jun 6\n jul 7 aug 8 sep 9 oct 10 nov 11 dec 12\n);\n" }, { "answer_id": 241841, "author": "Aristotle Pagaltzis", "author_id": 9410, "author_profile": "https://Stackoverflow.com/users/9410", "pm_score": 2, "selected": false, "text": "my %month_num = do { my $i = 1; map {; $_ => $i++ } (\n qw( jan feb mar apr may jun jul aug sep oct nov dec )\n) };\n" }, { "answer_id": 242025, "author": "Robert Krimen", "author_id": 25171, "author_profile": "https://Stackoverflow.com/users/25171", "pm_score": 4, "selected": false, "text": "my %month; @month{qw/jan feb mar apr may jun\n jul aug sep oct nov dec/} = (1 .. 12);\n" }, { "answer_id": 242217, "author": "Sam Kington", "author_id": 6832, "author_profile": "https://Stackoverflow.com/users/6832", "pm_score": 1, "selected": false, "text": "my @months = qw(Jan Feb Mar Apr May Jun\n Jul Aug Sep Oct Nov Dec);\nmy %monthnum = map { $_ => $months[ $_ - 1 ] } 1..12;\n" }, { "answer_id": 244198, "author": "EvdB", "author_id": 5349, "author_profile": "https://Stackoverflow.com/users/5349", "pm_score": 2, "selected": false, "text": "# create a lookup table of month abbreviations to month numbers\nmy %month_abbr_to_number_lkup = (\n jan => 1,\n feb => 2,\n mar => 3,\n apr => 4,\n may => 5,\n jun => 6,\n jul => 7,\n aug => 8,\n sep => 9,\n oct => 10,\n nov => 11,\n dec => 12,\n);\n\n# get the number for a month\nmy $number = $month_abbr_to_number_lkup{$abbr}\n || die \"Could not convert month abbreviation '$abbr' to a number.\";\n" }, { "answer_id": 244873, "author": "F5.", "author_id": 13769, "author_profile": "https://Stackoverflow.com/users/13769", "pm_score": 2, "selected": false, "text": "%mon_2_num = (jan => 1,\n feb => 2,\n ...);\n\n$month_number = $mon_2_num{lc($month_name_abbrev)};\n" }, { "answer_id": 248829, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 2, "selected": false, "text": "@month{qw(jan feb mar apr may jun jul aug sep oct nov dec)} = 1..12;\n" }, { "answer_id": 63093790, "author": "BitDreamer", "author_id": 4921154, "author_profile": "https://Stackoverflow.com/users/4921154", "pm_score": 0, "selected": false, "text": "my $months = '1=January 2=February 3=March 4=April 5=May 6=June 7=July 8=August 9=September 10=October 11=November 12=December';\n\nmy $month = 'jan'; # anything that looks like a month name\nmy $monthnumber = $1 if $months =~ m\"(\\d+)=$month\"i;\nmy $monthname = $1 if $months =~ m\"$monthnumber=(\\S+)\";\nmy $monthabbreviation = $1 if $months =~ m\"$monthnumber=(...)\";\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31301/" ]
241,581
<p>I have no trouble building 1.35.0, as well as 1.36.0 on the timesys arm-gcc toolchain, both statically (link-static) as well as dynamically (.so, default option).</p> <p>However, when I try to link a simple sample filesystem app:</p> <pre><code>#include &lt;boost/filesystem.hpp> #include &lt;iostream> namespace fs = boost::filesystem; int main(int argc, char *argv[]) { const char* fileName = argv[1]; std::cout &lt;&lt; "file: " &lt;&lt; fileName &lt;&lt; " => " &lt;&lt; fs::exists(fileName) &lt;&lt; std::endl; return 0; } </code></pre> <p>I get the following linker error:</p> <pre><code> developer@eldp01:~/boost/test$ /opt/timesys/at91sam9263_ek/toolchain/bin/armv5l-timesys-linux-gnueabi-gcc exists.cpp -o exists.exe -I ../boost_1_35_0/ -lboost_filesystem -lboost_system -lstdc++ -L . /tmp/ccex3NGb.o: In function `boost::detail::atomic_decrement(int*)': exists.cpp:(.text._ZN5boost6detail16atomic_decrementEPi[boost::detail::atomic_decrement(int*)]+0x1c): undefined reference to `__sync_fetch_and_add_4' /tmp/ccex3NGb.o: In function `boost::detail::atomic_increment(int*)': exists.cpp:(.text._ZN5boost6detail16atomic_incrementEPi[boost::detail::atomic_increment(int*)]+0x1c): undefined reference to `__sync_fetch_and_add_4' collect2: ld returned 1 exit status </code></pre> <p>Does anyone know how I can get Boost to build for the gcc-arm toolchain?</p>
[ { "answer_id": 241583, "author": "Leon Timmermans", "author_id": 4727, "author_profile": "https://Stackoverflow.com/users/4727", "pm_score": 3, "selected": false, "text": "my %number_for = (\n jan => 1,\n feb => 2,\n#etc...\n);\n#...\ndo_something_with($number_for{$month})\n" }, { "answer_id": 241589, "author": "Oskar", "author_id": 5472, "author_profile": "https://Stackoverflow.com/users/5472", "pm_score": 6, "selected": true, "text": "%mon2num = qw(\n jan 1 feb 2 mar 3 apr 4 may 5 jun 6\n jul 7 aug 8 sep 9 oct 10 nov 11 dec 12\n);\n" }, { "answer_id": 241841, "author": "Aristotle Pagaltzis", "author_id": 9410, "author_profile": "https://Stackoverflow.com/users/9410", "pm_score": 2, "selected": false, "text": "my %month_num = do { my $i = 1; map {; $_ => $i++ } (\n qw( jan feb mar apr may jun jul aug sep oct nov dec )\n) };\n" }, { "answer_id": 242025, "author": "Robert Krimen", "author_id": 25171, "author_profile": "https://Stackoverflow.com/users/25171", "pm_score": 4, "selected": false, "text": "my %month; @month{qw/jan feb mar apr may jun\n jul aug sep oct nov dec/} = (1 .. 12);\n" }, { "answer_id": 242217, "author": "Sam Kington", "author_id": 6832, "author_profile": "https://Stackoverflow.com/users/6832", "pm_score": 1, "selected": false, "text": "my @months = qw(Jan Feb Mar Apr May Jun\n Jul Aug Sep Oct Nov Dec);\nmy %monthnum = map { $_ => $months[ $_ - 1 ] } 1..12;\n" }, { "answer_id": 244198, "author": "EvdB", "author_id": 5349, "author_profile": "https://Stackoverflow.com/users/5349", "pm_score": 2, "selected": false, "text": "# create a lookup table of month abbreviations to month numbers\nmy %month_abbr_to_number_lkup = (\n jan => 1,\n feb => 2,\n mar => 3,\n apr => 4,\n may => 5,\n jun => 6,\n jul => 7,\n aug => 8,\n sep => 9,\n oct => 10,\n nov => 11,\n dec => 12,\n);\n\n# get the number for a month\nmy $number = $month_abbr_to_number_lkup{$abbr}\n || die \"Could not convert month abbreviation '$abbr' to a number.\";\n" }, { "answer_id": 244873, "author": "F5.", "author_id": 13769, "author_profile": "https://Stackoverflow.com/users/13769", "pm_score": 2, "selected": false, "text": "%mon_2_num = (jan => 1,\n feb => 2,\n ...);\n\n$month_number = $mon_2_num{lc($month_name_abbrev)};\n" }, { "answer_id": 248829, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 2, "selected": false, "text": "@month{qw(jan feb mar apr may jun jul aug sep oct nov dec)} = 1..12;\n" }, { "answer_id": 63093790, "author": "BitDreamer", "author_id": 4921154, "author_profile": "https://Stackoverflow.com/users/4921154", "pm_score": 0, "selected": false, "text": "my $months = '1=January 2=February 3=March 4=April 5=May 6=June 7=July 8=August 9=September 10=October 11=November 12=December';\n\nmy $month = 'jan'; # anything that looks like a month name\nmy $monthnumber = $1 if $months =~ m\"(\\d+)=$month\"i;\nmy $monthname = $1 if $months =~ m\"$monthnumber=(\\S+)\";\nmy $monthabbreviation = $1 if $months =~ m\"$monthnumber=(...)\";\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4829/" ]
241,622
<p>I am not as familiar with Oracle as I would like to be. I have some 250k records, and I want to display them 100 per page. Currently I have one stored procedure which retrieves all quarter of a million records to a dataset using a data adapter, and dataset, and the dataadapter.Fill(dataset) method on the results from the stored proc. If I have "Page Number" and "Number of records per page" as integer values I can pass as parameters, what would be the best way to get back just that particular section. Say, if I pass 10 as a page number, and 120 as number of pages, from the select statement it would give me the 1880th through 1200th, or something like that, my math in my head might be off. </p> <p>I'm doing this in .NET with C#, thought that's not important, if I can get it right on the sql side, then I should be cool. </p> <p>Update: I was able to use Brian's suggestion, and it is working great. I'd like to work on some optimization, but the pages are coming up in 4 to 5 seconds rather than a minute, and my paging control was able to integrate in very well with my new stored procs. </p>
[ { "answer_id": 241643, "author": "Brian Schmitt", "author_id": 30492, "author_profile": "https://Stackoverflow.com/users/30492", "pm_score": 8, "selected": true, "text": "SELECT * FROM\n(\n SELECT a.*, rownum r__\n FROM\n (\n SELECT * FROM ORDERS WHERE CustomerID LIKE 'A%'\n ORDER BY OrderDate DESC, ShippingDate DESC\n ) a\n WHERE rownum < ((pageNumber * pageSize) + 1 )\n)\nWHERE r__ >= (((pageNumber-1) * pageSize) + 1)\n" }, { "answer_id": 241657, "author": "Chobicus", "author_id": 1514822, "author_profile": "https://Stackoverflow.com/users/1514822", "pm_score": 7, "selected": false, "text": "select * from (\n select /*+ first_rows(25) */\n object_id,object_name,\n row_number() over\n (order by object_id) rn\n from all_objects\n)\nwhere rn between :n and :m\norder by rn;\n" }, { "answer_id": 20617033, "author": "Furetto", "author_id": 532392, "author_profile": "https://Stackoverflow.com/users/532392", "pm_score": 3, "selected": false, "text": "SELECT *\nFROM\n (SELECT FIELDA,\n FIELDB,\n FIELDC,\n ROW_NUMBER() OVER (ORDER BY FIELDC) R\n FROM TABLE_NAME\n WHERE FIELDA = 10\n )\nWHERE R >= 10\nAND R <= 15;\n" }, { "answer_id": 29927794, "author": "JoelC", "author_id": 2019162, "author_profile": "https://Stackoverflow.com/users/2019162", "pm_score": 7, "selected": false, "text": "SELECT *\nFROM user\nORDER BY first_name\nOFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY;\n" }, { "answer_id": 33498058, "author": "Vadim Kirilchuk", "author_id": 2728956, "author_profile": "https://Stackoverflow.com/users/2728956", "pm_score": 4, "selected": false, "text": "SELECT * FROM V$VERSION\n" }, { "answer_id": 61062846, "author": "Ferdous Wahid", "author_id": 2828176, "author_profile": "https://Stackoverflow.com/users/2828176", "pm_score": 0, "selected": false, "text": " public public List<Map<String, Object>> getAllProductOfferWithPagination(int pageNo, int pageElementSize, Long productOfferId, String productOfferName) {\n try {\n\n if(pageNo==1){\n //do nothing\n } else{\n pageNo=(pageNo-1)*pageElementSize+1;\n }\n System.out.println(\"algo pageNo: \" + pageNo +\" pageElementSize: \"+ pageElementSize+\" productOfferId: \"+ productOfferId+\" productOfferName: \"+ productOfferName);\n\n String sql = \"SELECT * FROM ( SELECT * FROM product_offer po WHERE po.deleted=0 AND (po.product_offer_id=? OR po.product_offer_name LIKE ? )\" +\n \" ORDER BY po.PRODUCT_OFFER_ID asc) foo OFFSET ? ROWS FETCH NEXT ? ROWS ONLY \";\n\n return jdbcTemplate.queryForList(sql,new Object[] {productOfferId,\"%\"+productOfferName+\"%\",pageNo-1, pageElementSize});\n\n } catch (Exception e) {\n System.out.println(e);\n e.printStackTrace();\n return null;\n }\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18893/" ]
241,631
<p>I'm writing a web application that <em>dynamically</em> creates URL's based off of some input, to be consumed by a client at another time. For discussion sake these URL's can contain certain characters, like a <strong>forward slash (i.e. '/')</strong>, which should not be interpreted as part of the actual URL, but just as an argument. For example:</p> <pre>http://mycompany.com/PartOfUrl1/PartOfUrl2/ArgumentTo/Url/GoesHere</pre> <p>As you can see, the <strong>ArgumentTo/Url/GoesHere</strong> does indeed have forward slashes but these should be <em>ignored or escaped</em>.</p> <p>This may be a bad example but the question in hand is more general and applies to other <em>special characters</em>.</p> <h3>So, if there are pieces of a URL that are just <em>argument</em>s and should not be used to resolve the actual web request, what's a good way of handling this?</h3> <h1>Update:</h1> <p>Given some of the answers I realized that I failed to point out a few pieces that hopefully will help clarify.</p> <p>I would like to keep this fairly language agnostic as it would be great if the client could just make a request. For example, if the client knew that it wanted to pass <strong>ArgumentTo/Url/GoesHere</strong>, it would be great if that could be <em>encoded</em> into a <em>unique</em> string in which the server could turn around and <em>decode</em> it to use.</p> <p>Can we assume that similar functions like HttpUtility.HtmlEncode/HtmlDecode in the .NET Framework are available on other systems/platforms? The URL does not have to be <em>pretty</em> by any means so having <em>real words</em> in the path does not really matter.</p> <h3>Would something like a base64 encoding of the argument work?</h3> <p>It seems that base64 encoding/decoding is fairly readily available on any platform/language.</p>
[ { "answer_id": 241639, "author": "Ross", "author_id": 2025, "author_profile": "https://Stackoverflow.com/users/2025", "pm_score": 3, "selected": false, "text": "urlencode" }, { "answer_id": 241648, "author": "dgw", "author_id": 5991, "author_profile": "https://Stackoverflow.com/users/5991", "pm_score": 2, "selected": false, "text": "http:// mycompany.com/PartOfUrl1/PartOfUrl2" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4916/" ]
241,634
<p>In Cygwin a space in a path has to be escaped with a backslash Not true in Windows, put the whole path in a quote</p> <p>Is there a way to convert to this automatically in Ruby?</p> <p>Otherwise, how in Ruby do I detect if I am running with Windows or Cygwin?</p>
[ { "answer_id": 1582028, "author": "knoopx", "author_id": 62368, "author_profile": "https://Stackoverflow.com/users/62368", "pm_score": 2, "selected": true, "text": "sys.escape(\"foo bar\")\n# gives on Windows: '\"foo bar\"'\n# other systems: 'foo\\ bar'\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2167252/" ]
241,645
<p>I have the Profile, CCK, and Views2 modules installed on a Drupal 6 site. I added a string field to the user profile. I can filter easily on preset values, thru the Views GUI builder, really nicely. However, I'd like the filter criteria to be dynamically set based on other environment variables (namely the <code>$_SERVER['SERVER_NAME']</code>).</p> <p>Is there a basic 'How-to-write-a-custom-drupal-views-filter' somewhere out there? I've been looking thru the documentation, but it's not obvious to my simple mind on how to do it.</p>
[ { "answer_id": 835510, "author": "AbhiG", "author_id": 59182, "author_profile": "https://Stackoverflow.com/users/59182", "pm_score": 2, "selected": false, "text": "<?php custom_views_embed_view($view_name, $display_id) {\n$view = views_get_view($view_name);\n$view->set_display($display_id);\n$id = $view->add_item($display_id, 'filter', 'node', 'created',\n array( 'value' => array('type' => 'date', 'value' => date('c')), 'operator' => '<='));\nreturn $view->execute_display($display_id);\n}\n?>\n" }, { "answer_id": 8225383, "author": "yrk", "author_id": 1059019, "author_profile": "https://Stackoverflow.com/users/1059019", "pm_score": 0, "selected": false, "text": "viewsphpfilter" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6824/" ]
241,663
<pre><code>$fp_src=fopen('file','r'); $filter = stream_filter_prepend($fp_src, 'convert.iconv.ISO-8859-1/UTF-8'); while(fread($fp_src,4096)){ ++$count; if($count%1000==0) print ftell($fp_src)."\n"; } </code></pre> <p>When I run this the script ends up consuming ~ 200 MB of RAM after going through just 35MB of the file. </p> <p>Running it without the stream_filter zips right through with a constant memory footprint of ~10 MB.</p> <p>What gives?</p>
[ { "answer_id": 241701, "author": "Peter Bailey", "author_id": 8815, "author_profile": "https://Stackoverflow.com/users/8815", "pm_score": 0, "selected": false, "text": "stream_filter_prepend()" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241663", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
241,673
<pre><code>if(!eregi("^([0-9a-z_\[\]\*\- ])+$", $subuser)) $form-&gt;setError($field, "* Username not alphanumeric"); </code></pre> <p>Can anybody tell me why it is not allowing characters such as <code>-</code> and <code>*</code>?</p> <pre><code>if(!eregi("^([0-9a-z])+$", $subuser)) $form-&gt;setError($field, "* Username not alphanumeric"); </code></pre> <p>That is the original piece of code. A friend changed it to the top piece and it will allow a-z and 0-9 but it wont allow the other characters I need it to. Can anyone help me?</p> <p>Thanks in advance.</p>
[ { "answer_id": 241680, "author": "Henning", "author_id": 29549, "author_profile": "https://Stackoverflow.com/users/29549", "pm_score": 3, "selected": false, "text": "else if (!preg_match(\"/^([0-9a-z_\\[\\]* -])+$/i\", $subuser)) {\n$form->setError($field, \"* Username not alphanumeric\");\n}\n" }, { "answer_id": 241684, "author": "Peter Bailey", "author_id": 8815, "author_profile": "https://Stackoverflow.com/users/8815", "pm_score": 2, "selected": false, "text": "if ( preg_match( \"/^[^0-9a-z_\\[\\]* -]$/i\", $subuser )\n{\n $form->setError( $field, \"* Username not alphanumeric\" );\n}\n" }, { "answer_id": 241685, "author": "Trent", "author_id": 31912, "author_profile": "https://Stackoverflow.com/users/31912", "pm_score": 3, "selected": true, "text": "]" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29912/" ]
241,691
<p>Rather than scraping a Ruby version of this algorithm off the net I wanted to create my own based on its description <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="noreferrer">here</a>. However I cannot figure out two things</p> <pre><code>def primeSieve(n) primes = Array.new for i in 0..n-2 primes[i] = i+2 end index = 0 while Math.sqrt(primes.last).ceil &gt; primes[index] (primes[index] ** 2).step(primes.length - 1, primes[index]) {|x| x % primes[index] == 0 ? primes.delete(x) : ""} index += 1 end primes end </code></pre> <ol> <li>Why it doesn't iterate to the end of the array?</li> <li>According to the description in the link above the loop should be broken out of when the squareroot of the last element in the array is greater than the current prime - mine does this one before. </li> </ol> <p>I'm fairly sure it has something to do with the delete operation modifying the length of the array. For example my function currently yields 2,3,5,7,9,10 when I enter n=10 which is obviously not correct. Any suggestions on how I can go about alterating this to make it work like it's supposed to?</p>
[ { "answer_id": 241752, "author": "Andru Luvisi", "author_id": 5922, "author_profile": "https://Stackoverflow.com/users/5922", "pm_score": 4, "selected": true, "text": "while primes[index]**2 <= primes.last\n prime = primes[index]\n primes = primes.select { |x| x == prime || x%prime != 0 }\n index += 1\nend\n" }, { "answer_id": 432889, "author": "Mike Woodhouse", "author_id": 1060, "author_profile": "https://Stackoverflow.com/users/1060", "pm_score": 4, "selected": false, "text": "def sieve_upto(top)\n sieve = []\n for i in 2 .. top\n sieve[i] = i\n end\n for i in 2 .. Math.sqrt(top)\n next unless sieve[i]\n (i*i).step(top, i) do |j|\n sieve[j] = nil\n end\n end\n sieve.compact\nend\n" }, { "answer_id": 9564096, "author": "nes1983", "author_id": 52573, "author_profile": "https://Stackoverflow.com/users/52573", "pm_score": 2, "selected": false, "text": "#!/usr/bin/env ruby -w\n\nrequire 'rubygems'\nrequire 'bitarray'\n\ndef eratosthenes(n)\n\n a = BitArray.new(n+1)\n\n (4..n).step(2) { |i|\n a[i] = 1\n }\n\n (3..(Math.sqrt(n))).each { |i|\n if(a[i] == 0)\n ((i*i)..n).step(2*i) { |j|\n a[j] = 1\n }\n end\n }\n a\n end\n\ndef primes(n)\n primes = Array.new\n eratosthenes(n).each_with_index { |isPrime, idx|\n primes << idx if isPrime == 0\n }\n primes[2..-1]\nend\n" }, { "answer_id": 19416525, "author": "pjammer", "author_id": 156561, "author_profile": "https://Stackoverflow.com/users/156561", "pm_score": 0, "selected": false, "text": "x = []\nPrime.each(123) do |p|\n x << p\nend\n" }, { "answer_id": 23588178, "author": "shin", "author_id": 119198, "author_profile": "https://Stackoverflow.com/users/119198", "pm_score": 1, "selected": false, "text": "n = 1000000\nns = (n**0.5).to_i + 1\nis_prime = [false, false] + [true]*(n-1)\n2.upto(ns) do |i|\n next if !is_prime[i]\n (i*i).step(n, i) do |j|\n is_prime[j] = false\n end\nend\n\ncount = 0\nlist = (0..n).map do |i|\n count += 1 if is_prime[i]\n count\nend\n\nwhile gets\n puts list[$_.to_i]\nend\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2294/" ]
241,694
<p>I have a loop running that will process 1000's of records, currently once the loop is running it can't be stopped and the user must wait until it is finished. How can I stop the loop when someone clicks a 'Cancel' button? How do I break into that other routine?</p> <p>Thanks</p>
[ { "answer_id": 241707, "author": "chakrit", "author_id": 3055, "author_profile": "https://Stackoverflow.com/users/3055", "pm_score": 4, "selected": false, "text": "backgroundworker1.WorkerSupportsCancellation = true;\n" }, { "answer_id": 241791, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "backgroundworker" }, { "answer_id": 241803, "author": "Dan F", "author_id": 11569, "author_profile": "https://Stackoverflow.com/users/11569", "pm_score": 0, "selected": false, "text": "WorkerSupportsCancellation" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241694", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
241,715
<p>I am writing PHP code where I want to pass the session id myself using POST. I don't want a cookie to store the session, as it should get lost when the user gets out of the POST cycle.</p> <p>PHP automatically sets the cookie where available. I learned it is possible to change this behaviour by setting <code>session.use_cookies</code> to 0 in <code>php.ini</code>. Unfortunately, I don't have access to that file and I also wouldn't want to break the behaviour of other scripts running on the same server.</p> <p>Is there a way to disable or void the session cookie inside the PHP script?</p> <p><strong>EDIT:</strong> As the proposed solutions don't work for me, I used $_SESSION = array() at positions in the code where I found the session should be invalidated.</p>
[ { "answer_id": 241719, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 5, "selected": false, "text": "ini_set('session.use_cookies', '0');\n" }, { "answer_id": 241726, "author": "lock", "author_id": 24744, "author_profile": "https://Stackoverflow.com/users/24744", "pm_score": 4, "selected": true, "text": "SetEnv session.use_cookies='0';\n" }, { "answer_id": 241934, "author": "staticsan", "author_id": 28832, "author_profile": "https://Stackoverflow.com/users/28832", "pm_score": -1, "selected": false, "text": "if( !array_key_exists('sessionid', $_POST) ) {\n // recreate the sessionid\n $sessionid = md5(rand().' '.microtime()); // Or something\n} else {\n $sessionid = $_POST['sessionid'];\n\nsession_id($sessionid);\nsession_start();\n" }, { "answer_id": 244610, "author": "Nathan Strong", "author_id": 9780, "author_profile": "https://Stackoverflow.com/users/9780", "pm_score": 2, "selected": false, "text": "// Initialize the session.\n// If you are using session_name(\"something\"), don't forget it now!\nsession_start();\n\n// Unset all of the session variables.\n$_SESSION = array();\n\n// If it's desired to kill the session, also delete the session cookie.\n// Note: This will destroy the session, and not just the session data!\nif (isset($_COOKIE[session_name()])) {\n setcookie(session_name(), '', time()-42000, '/');\n}\n\n// Finally, destroy the session.\nsession_destroy();\n" }, { "answer_id": 8778645, "author": "Michael Shebanow", "author_id": 1079359, "author_profile": "https://Stackoverflow.com/users/1079359", "pm_score": 2, "selected": false, "text": "// If it's desired to kill the session, also delete the session cookie.\n// Note: This will destroy the session, and not just the session data!\nif (ini_get(\"session.use_cookies\")) {\n $params = session_get_cookie_params();\n setcookie(session_name(), '', time() - 42000,\n $params[\"path\"], $params[\"domain\"],\n $params[\"secure\"], $params[\"httponly\"]\n );\n}\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21974/" ]
241,725
<p>I'm trying to call a web service in an Excel Macro:</p> <pre><code>Set objHTTP = New MSXML.XMLHTTPRequest objHTTP.Open "post", "https://www.server.com/EIDEServer/EIDEService.asmx" objHTTP.setRequestHeader "Content-Type", "text/xml" objHTTP.setRequestHeader "SOAPAction", "PutSchedule" objHTTP.send strXML </code></pre> <p>And I get back the following response:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;soap:Body&gt; &lt;soap:Fault&gt; &lt;faultcode&gt;soap:Client&lt;/faultcode&gt; &lt;faultstring&gt;Server did not recognize the value of HTTP Header SOAPAction: PutSchedule.&lt;/faultstring&gt; &lt;detail /&gt; &lt;/soap:Fault&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt; </code></pre> <p>Anybody out there done something like this before?</p>
[ { "answer_id": 241956, "author": "Ray Lu", "author_id": 11413, "author_profile": "https://Stackoverflow.com/users/11413", "pm_score": 3, "selected": true, "text": "\"http://tempri.org/PutSchedule\"\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1766771/" ]
241,727
<p>If I had the following select, and did not know the value to use to select an item in advance like in this <a href="https://stackoverflow.com/questions/196684/jquery-get-select-option-text">question</a> or the index of the item I wanted selected, how could I select one of the options with jQuery if I did know the text value like Option C?</p> <pre><code>&lt;select id='list'&gt; &lt;option value='45'&gt;Option A&lt;/option&gt; &lt;option value='23'&gt;Option B&lt;/option&gt; &lt;option value='17'&gt;Option C&lt;/option&gt; &lt;/select&gt; </code></pre>
[ { "answer_id": 241743, "author": "eyelidlessness", "author_id": 17964, "author_profile": "https://Stackoverflow.com/users/17964", "pm_score": 5, "selected": true, "text": "var option;\n$('#list option').each(function() {\n if($(this).text() == 'Option C') {\n option = this;\n return false;\n }\n});\n" }, { "answer_id": 241751, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 4, "selected": false, "text": "// option text to search for\nvar optText = \"Option B\";\n// find option value that corresponds\nvar optVal = $(\"#list option:contains('\"+optText+\"')\").attr('value');\n// select the option value \n$(\"#list\").val( optVal )\n" }, { "answer_id": 1364498, "author": "RhinoDevX64", "author_id": 166845, "author_profile": "https://Stackoverflow.com/users/166845", "pm_score": 2, "selected": false, "text": "function SelectItemInDropDownList(itemToFind){ \n var option;\n $('#list option').each(function(){\n if($(this).text() == itemToFind) {\n option = this;\n option.selected = true;\n return false; \n }\n }); }\n" }, { "answer_id": 4653913, "author": "Pavel Chuchuva", "author_id": 14131, "author_profile": "https://Stackoverflow.com/users/14131", "pm_score": 3, "selected": false, "text": "$(\"#list option\").each(function() {\n this.selected = $(this).text() == \"Option C\";\n});\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241727", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25335/" ]
241,746
<p>In a database prototype, I have a set of fields (like name, description, status) that are required in multiple, functionally different tables.</p> <p>These fields always have the same end user functionality for labeling, display, search, filtering etc. They are not part of a foreign key constraint. How should this be modeled?</p> <p>I can think of the following variants:</p> <ul> <li><p>Each table gets all these attributes. In this case, how would you name them? The same, in each table, or with a table name prefix (like usrName, prodName)</p></li> <li><p>Move them into a table Attributes, add a foreign key to the "core" tables, referencing Attributes.PK</p></li> <li><p>As above, but instead of a foreign key, use the Attributes.PK as PK in the respective core table as well.</p></li> </ul>
[ { "answer_id": 241832, "author": "Terry G Lorber", "author_id": 809, "author_profile": "https://Stackoverflow.com/users/809", "pm_score": 2, "selected": false, "text": "order_status_types\n- id\n- name\n- description\n\nshipping_accounts\n- id\n- name\n- description\n\norders\n- order_status_type_id\n- shipping_account_id\n\npreferences\n- shipping_account_id\n" }, { "answer_id": 241836, "author": "Owen", "author_id": 4853, "author_profile": "https://Stackoverflow.com/users/4853", "pm_score": 4, "selected": true, "text": "user.name" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241746", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31317/" ]
241,758
<p>In VB6 you can do this:</p> <pre><code>Dim a As Variant a = Array(1, 2, 3)</code></pre> <p>Can you do a similar thing in VB.NET with specific types, like so?:</p> <pre><code>Dim a() As Integer a = <strong>Array</strong>(1, 2, 3)</code></pre>
[ { "answer_id": 241762, "author": "Jonathan Allen", "author_id": 5274, "author_profile": "https://Stackoverflow.com/users/5274", "pm_score": 5, "selected": true, "text": "Dim a() As Integer = New Integer() {1, 2, 3}\n" } ]
2008/10/27
[ "https://Stackoverflow.com/questions/241758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1670/" ]
241,783
<p>I'm interfacing with a payment gateway and not having any luck with Net::SSLeay and its post_https subroutine. The payment gateway has issued me a client certificate that must be used for authentication. The Net::SSLeay perldoc has the following example:</p> <pre><code>($page, $response, %reply_headers) = post_https('www.bacus.pt', 443, '/foo.cgi', # 3b make_headers('Authorization' =&gt; 'Basic ' . MIME::Base64::encode("$user:$pass",'')), make_form(OK =&gt; '1', name =&gt; 'Sampo'), $mime_type6, $path_to_crt7, $path_to_key8); </code></pre> <p>My own version is below and returns the error <strong>Too many arguments for Net::SSLeay::post_https</strong>:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use Net::SSLeay qw(post_https); my %post = ( #snip ); my ($page, $response, %reply_headers) = post_https( 'www.example.com', 443, '/submit', '', make_form(%post), 'text/xml', '/path/to/cert', '/path/to/key', ); </code></pre> <p>Why is this error occurring?</p>
[ { "answer_id": 241800, "author": "Andru Luvisi", "author_id": 5922, "author_profile": "https://Stackoverflow.com/users/5922", "pm_score": 1, "selected": false, "text": "sub post_https ($$$;***) { do_httpx2(POST => 1, @_) }\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6406/" ]
241,789
<p>I'm trying to parse an international datetime string similar to:</p> <pre><code>24-okt-08 21:09:06 CEST </code></pre> <p>So far I've got something like:</p> <pre><code>CultureInfo culture = CultureInfo.CreateSpecificCulture("nl-BE"); DateTime dt = DateTime.ParseExact("24-okt-08 21:09:06 CEST", "dd-MMM-yy HH:mm:ss ...", culture); </code></pre> <p>The problem is what should I use for the '...' in the format string? Looking at the <a href="http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx" rel="noreferrer">Custom Date and Time Format String</a> MSDN page doesn't seem to list a format string for parsing timezones in PST/CEST/GMT/UTC form.</p>
[ { "answer_id": 241885, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 6, "selected": true, "text": "DateTime dt1 = DateTime.ParseExact(\"24-okt-08 21:09:06 CEST\".Replace(\"CEST\", \"+2\"), \"dd-MMM-yy HH:mm:ss z\", culture);\nDateTime dt2 = DateTime.ParseExact(\"24-okt-08 21:09:06 CEST\".Replace(\"CEST\", \"+02\"), \"dd-MMM-yy HH:mm:ss zz\", culture);\nDateTime dt3 = DateTime.ParseExact(\"24-okt-08 21:09:06 CEST\".Replace(\"CEST\", \"+02:00\"), \"dd-MMM-yy HH:mm:ss zzz\", culture);\n" }, { "answer_id": 7662252, "author": "Deep Kumar", "author_id": 790860, "author_profile": "https://Stackoverflow.com/users/790860", "pm_score": -1, "selected": false, "text": "string datetimevalue = hidfileDateTime.Value; \n\ndatetimevalue= datetimevalue.Replace(\"EDT\", \"EST\"); \ndatetimevalue = datetimevalue.Replace(\"CDT\", \"CST\");\nif (datetimevalue.Contains(\"CST\"))\n{\n filedt = DateTime.ParseExact(datetimevalue, \"ddd MMM d HH:mm:ss CST yyyy\", provider).ToUniversalTime().AddHours(1).ToLocalTime();\n}\nelse\n{\n filedt = DateTime.ParseExact(datetimevalue, \"ddd MMM d HH:mm:ss EST yyyy\", provider);\n}\n" }, { "answer_id": 22868721, "author": "Jodrell", "author_id": 659190, "author_profile": "https://Stackoverflow.com/users/659190", "pm_score": 5, "selected": false, "text": "\"AMT\"" }, { "answer_id": 30303587, "author": "Jussi Palo", "author_id": 1441451, "author_profile": "https://Stackoverflow.com/users/1441451", "pm_score": 4, "selected": false, "text": "Dictionary<string, string> _timeZones = new Dictionary<string, string>() {\n {\"ACDT\", \"+1030\"},\n {\"ACST\", \"+0930\"},\n {\"ADT\", \"-0300\"},\n {\"AEDT\", \"+1100\"},\n {\"AEST\", \"+1000\"},\n {\"AHDT\", \"-0900\"},\n {\"AHST\", \"-1000\"},\n {\"AST\", \"-0400\"},\n {\"AT\", \"-0200\"},\n {\"AWDT\", \"+0900\"},\n {\"AWST\", \"+0800\"},\n {\"BAT\", \"+0300\"},\n {\"BDST\", \"+0200\"},\n {\"BET\", \"-1100\"},\n {\"BST\", \"-0300\"},\n {\"BT\", \"+0300\"},\n {\"BZT2\", \"-0300\"},\n {\"CADT\", \"+1030\"},\n {\"CAST\", \"+0930\"},\n {\"CAT\", \"-1000\"},\n {\"CCT\", \"+0800\"},\n {\"CDT\", \"-0500\"},\n {\"CED\", \"+0200\"},\n {\"CET\", \"+0100\"},\n {\"CEST\", \"+0200\"},\n {\"CST\", \"-0600\"},\n {\"EAST\", \"+1000\"},\n {\"EDT\", \"-0400\"},\n {\"EED\", \"+0300\"},\n {\"EET\", \"+0200\"},\n {\"EEST\", \"+0300\"},\n {\"EST\", \"-0500\"},\n {\"FST\", \"+0200\"},\n {\"FWT\", \"+0100\"},\n {\"GMT\", \"GMT\"},\n {\"GST\", \"+1000\"},\n {\"HDT\", \"-0900\"},\n {\"HST\", \"-1000\"},\n {\"IDLE\", \"+1200\"},\n {\"IDLW\", \"-1200\"},\n {\"IST\", \"+0530\"},\n {\"IT\", \"+0330\"},\n {\"JST\", \"+0900\"},\n {\"JT\", \"+0700\"},\n {\"MDT\", \"-0600\"},\n {\"MED\", \"+0200\"},\n {\"MET\", \"+0100\"},\n {\"MEST\", \"+0200\"},\n {\"MEWT\", \"+0100\"},\n {\"MST\", \"-0700\"},\n {\"MT\", \"+0800\"},\n {\"NDT\", \"-0230\"},\n {\"NFT\", \"-0330\"},\n {\"NT\", \"-1100\"},\n {\"NST\", \"+0630\"},\n {\"NZ\", \"+1100\"},\n {\"NZST\", \"+1200\"},\n {\"NZDT\", \"+1300\"},\n {\"NZT\", \"+1200\"},\n {\"PDT\", \"-0700\"},\n {\"PST\", \"-0800\"},\n {\"ROK\", \"+0900\"},\n {\"SAD\", \"+1000\"},\n {\"SAST\", \"+0900\"},\n {\"SAT\", \"+0900\"},\n {\"SDT\", \"+1000\"},\n {\"SST\", \"+0200\"},\n {\"SWT\", \"+0100\"},\n {\"USZ3\", \"+0400\"},\n {\"USZ4\", \"+0500\"},\n {\"USZ5\", \"+0600\"},\n {\"USZ6\", \"+0700\"},\n {\"UT\", \"-0000\"},\n {\"UTC\", \"-0000\"},\n {\"UZ10\", \"+1100\"},\n {\"WAT\", \"-0100\"},\n {\"WET\", \"-0000\"},\n {\"WST\", \"+0800\"},\n {\"YDT\", \"-0800\"},\n {\"YST\", \"-0900\"},\n {\"ZP4\", \"+0400\"},\n {\"ZP5\", \"+0500\"},\n {\"ZP6\", \"+0600\"}\n };\n" }, { "answer_id": 49252458, "author": "Stefan Steiger", "author_id": 155077, "author_profile": "https://Stackoverflow.com/users/155077", "pm_score": 1, "selected": false, "text": "string dateString = reader.ReadContentAsString();\nint timeZonePos = dateString.LastIndexOf(' ') + 1;\nstring tz = dateString.Substring(timeZonePos);\ndateString = dateString.Substring(0, dateString.Length - tz.Length );\ndateString += s_timeZoneOffsets[tz];\n\n// https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx\n//string es = reader.ReadElementString(\"pubDate\");\nthis.m_value = System.DateTime.ParseExact(dateString, \"ddd, dd MMM yyyy HH:mm zzz\", System.Globalization.CultureInfo.InvariantCulture);\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/163/" ]
241,790
<p>There have been a couple of questions that sort of dealt with this but not covering my exact question so here we go.</p> <p>For site settings, if these are stored in a database do you:</p> <ol> <li>retrieve them from the db every time someone makes a request</li> <li>store them in a session variable on login</li> <li>???????</li> </ol> <p>For user specific settings do I do the same as site settings??</p> <p>Any guidance/best practice would be greatly appreciated.</p> <p>Cheers</p>
[ { "answer_id": 241946, "author": "Jeff Fritz", "author_id": 29156, "author_profile": "https://Stackoverflow.com/users/29156", "pm_score": 2, "selected": true, "text": " #region Data Access\n\nprivate string GetSettingsFromDb(string settingName)\n{\n return \"\";\n}\nprivate Dictionary<string,string> GetSettingsFromDb()\n{\n return new Dictionary<string, string>();\n}\n\n#endregion\n\nprivate const string KEY_SETTING1 = \"Setting1\";\npublic string Setting1\n{\n get\n {\n if (Cache.Get(KEY_SETTING1) != null)\n return Cache.Get(KEY_SETTING1).ToString();\n\n Setting1 = GetSettingsFromDb(KEY_SETTING1);\n\n return Setting1;\n\n } \n set\n {\n Cache.Remove(KEY_SETTING1);\n Cache.Insert(KEY_SETTING1, value, null, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(2));\n }\n}\n\nprivate Cache Cache { get { return HttpContext.Current.Cache; } }\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29376/" ]
241,819
<p>What's the difference between the two and when should I use each:</p> <pre><code>&lt;person&gt; &lt;firstname&gt;Joe&lt;/firstname&gt; &lt;lastname&gt;Plumber&lt;/lastname&gt; &lt;/person&gt; </code></pre> <p>versus</p> <pre><code>&lt;person firstname="Joe" lastname="Plumber" /&gt; </code></pre> <p>Thanks</p>
[ { "answer_id": 241834, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "<address>" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24059/" ]
241,822
<p>I'm preparing a class on Visual Basic 2005 targeting Visual Basic 6 programmers migrating to the .NET platform.</p> <p>My primary concern is to teach my students the best practices for developing in .NET, and I am wondering about whether to consider the use of the VB runtime functions VB.NET legitimate or not.</p> <p>I have read that many of the VB functions in VB.NET actually invoke methods on the .NET Framework, so it appears they exist primarily to ease the transition from earlier versions of Visual Basic to VB.NET. However, <a href="http://blogs.msdn.com/vbteam/" rel="nofollow noreferrer">the VB.NET team</a> seems to recommend to use them whenvever possible since they claim they put some optimizations in there on top of the .NET framework APIs.</p> <p>What's your take on this? </p>
[ { "answer_id": 241922, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 4, "selected": true, "text": "Trim(), Replace(), Len(), UCase()" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26396/" ]
241,839
<p>I need to choose a database management system (DBMS) that uses the least amount of main memory since we are severely constrained. Since a DBMS will use more and more memory to hold the index in main memory, how exactly do I tell which DBMS has the smallest memory footprint? </p> <p>Right now I just have a memory monitor program open while I perform a series of queries we'll call X. Then I run the same set of queries X on a different DBMS and see how much memory is used in its lifetime and compare with the other memory footprints. </p> <p>Is this a not-dumb way of going about it? Is there a better way?</p> <p>Thanks, Jbu</p>
[ { "answer_id": 241986, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 1, "selected": false, "text": "Collection" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241839", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
241,857
<p>I'm trying to use XPath to parse an XML document. One of my NSXMLElement's looks like the following, hypothetically speaking:</p> <pre><code>&lt;foo bar="yummy"&gt; </code></pre> <p>I'm trying to get the value for the attribute bar, however any interpretation of code I use, gives me back bar="woo", which means I need to do further string processing in order to obtain access to woo and woo alone.</p> <p>Essentially I'm doing something like</p> <pre><code>NSArray *nodes = [xmlDoc nodesForXPath:@"foo/@bar" error:&amp;error]; xmlElement = [nodes objectAtIndex:0]; </code></pre> <p>Is there anyway to write the code above to just give me yummy, versus bar="yummy" so I can relieve myself of parsing the string?</p> <p>Thanks.</p> <hr> <p>Assuming TouchXML is being used, is there still anyway to obtain similar results? As in grabbing just the value for the attribute, without the attribute="value"? That results in then further having to parse the string to get the value out.</p>
[ { "answer_id": 241888, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 2, "selected": false, "text": "-attributeForName:" }, { "answer_id": 242218, "author": "Brian Gianforcaro", "author_id": 3415, "author_profile": "https://Stackoverflow.com/users/3415", "pm_score": 3, "selected": true, "text": " NSArray *nodes = [xmlDoc nodesForXPath:@\"./foo/@bar\" error:&err];\n NSString *value = [[nodes objectAtIndex:0] stringValue];\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
241,860
<p>Say I want to get the HTML of</p> <pre>http://www.google.com</pre> <p>as a String using some built-in classes of the Cocoa Touch framework.</p> <p>What is the least amount of code I need to write?</p> <p>I've gotten this far, but can't figure out how to progress. There must be an easier way.</p> <pre><code>CFHTTPMessageRef req; NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; req = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), (CFURLRef)url, kCFHTTPVersion1_1); </code></pre>
[ { "answer_id": 241875, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 4, "selected": true, "text": "+stringWithContentsOfURL:" }, { "answer_id": 242257, "author": "Brian Gianforcaro", "author_id": 3415, "author_profile": "https://Stackoverflow.com/users/3415", "pm_score": 3, "selected": false, "text": "NSURL *url = [ NSURL URLWithString: @\"http://www.google.com\"]; \nNSURLRequest *req = [ NSURLRequest requestWithURL:url\n cachePolicy:NSURLRequestReloadIgnoringCacheData\n timeoutInterval:30.0 ];\nNSError *err;\nNSURLResponse *res;\nNSData *d = [ NSURLConnection sendSynchronousRequest:req\n returningResponse:&res\n error:&err ];\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241860", "https://Stackoverflow.com", "https://Stackoverflow.com/users/338/" ]
241,873
<p>i need to redirect all of the stdout of a program except the first line into a file. </p> <p>Is there a common unix program that removes lines from stdin and spits the rest out to stdout?</p>
[ { "answer_id": 241884, "author": "Andru Luvisi", "author_id": 5922, "author_profile": "https://Stackoverflow.com/users/5922", "pm_score": 6, "selected": true, "text": "sed 1d\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17076/" ]
241,882
<p>I'm trying to do an image capture on a high end Nokia phone (N95). The phone's internal camera is very good (4 megapixels) but in j2me I only seem to be able to get a maximum of 1360x1020 image out. I drew largely from this example <a href="http://developers.sun.com/mobility/midp/articles/picture/" rel="nofollow noreferrer">http://developers.sun.com/mobility/midp/articles/picture/</a></p> <p>What I did was start with 640x480 and increase the width and height by 80 and 60, respectively until it failed. The line of code is:</p> <p>jpg = mVideoControl.getSnapshot("encoding=jpeg&amp;quality=100&amp;width=" + width + "&amp;height=" + height);</p> <p>So the two issues are: 1. The phone throws an exception when getting an image larger than 1360x1020. 2. The higher resolution images appear to be just smoothed versions of the smaller ones. E.g. When I take a 640x480 image and increase it in photoshop I can't tell the difference between this and one that's supposedly 1360x1020.</p> <p>Is this a limitation of j2me on the phone? If so does anyone know of a way to get a higher resolution from within a j2me application and/or how to access the native camera from within another application?</p>
[ { "answer_id": 242582, "author": "izb", "author_id": 974, "author_profile": "https://Stackoverflow.com/users/974", "pm_score": 1, "selected": false, "text": "jpg = mVideoControl.getSnapshot(\"encoding=jpeg&quality=100&width=2048&height=1536\");\n" }, { "answer_id": 347403, "author": "SuperRoach", "author_id": 25031, "author_profile": "https://Stackoverflow.com/users/25031", "pm_score": 2, "selected": false, "text": "byte[] raw = mVideoControl.getSnapshot(null);\nImage image = Image.createImage(raw, 0, raw.length);\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241882", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8207/" ]
241,892
<p>I'm investigating SUDS as a SOAP client for python. I want to inspect the methods available from a specified service, and the types required by a specified method.</p> <p>The aim is to generate a user interface, allowing users to select a method, then fill in values in a dynamically generated form.</p> <p>I can get some information on a particular method, but am unsure how to parse it:</p> <pre><code>client = Client(url) method = client.sd.service.methods['MyMethod'] </code></pre> <p>I am unable to <strong>programmaticaly</strong> figure out what object type I need to create to be able to call the service</p> <pre><code>obj = client.factory.create('?') res = client.service.MyMethod(obj, soapheaders=authen) </code></pre> <p>Does anyone have some sample code?</p>
[ { "answer_id": 1842812, "author": "artdanil", "author_id": 214178, "author_profile": "https://Stackoverflow.com/users/214178", "pm_score": 4, "selected": false, "text": "suds" }, { "answer_id": 1858144, "author": "sj26", "author_id": 158252, "author_profile": "https://Stackoverflow.com/users/158252", "pm_score": 5, "selected": false, "text": "suds.client.Client" }, { "answer_id": 16616472, "author": "gbutler", "author_id": 1535087, "author_profile": "https://Stackoverflow.com/users/1535087", "pm_score": 3, "selected": false, "text": "import suds\n\ndef list_all(url):\n client = suds.client.Client(url)\n for service in client.wsdl.services:\n for port in service.ports:\n methods = port.methods.values()\n for method in methods:\n print(method.name)\n for part in method.soap.input.body.parts:\n part_type = part.type\n if(not part_type):\n part_type = part.element[0]\n print(' ' + str(part.name) + ': ' + str(part_type))\n o = client.factory.create(part_type)\n print(' ' + str(o))\n" }, { "answer_id": 17830415, "author": "toudi", "author_id": 1915230, "author_profile": "https://Stackoverflow.com/users/1915230", "pm_score": 2, "selected": false, "text": "from suds.client import Client\nc = Client('http://some/wsdl/link')\n\ntypes = c.sd[0].types\n" }, { "answer_id": 34442878, "author": "fomars", "author_id": 3316574, "author_profile": "https://Stackoverflow.com/users/3316574", "pm_score": 1, "selected": false, "text": "__metadata__" }, { "answer_id": 40762187, "author": "SAMI UL HUDA", "author_id": 3214350, "author_profile": "https://Stackoverflow.com/users/3214350", "pm_score": 1, "selected": false, "text": "from suds.client import Client\nurl = 'http://localhost:1234/sami/2009/08/reporting?wsdl'\nclient = Client(url)\nfunctions = [m for m in client.wsdl.services[0].ports[0].methods]\ncount = 0\nfor function_name in functions:\n print (function_name)\n count+=1\nprint (\"\\nNumber of services exposed : \" ,count)\n" }, { "answer_id": 61767522, "author": "alex", "author_id": 4444742, "author_profile": "https://Stackoverflow.com/users/4444742", "pm_score": 0, "selected": false, "text": "from suds.client import Client client =\nClient(\"https://wsvc.cdiscount.com/MarketplaceAPIService.svc?wsdl\")\nprint client\n" }, { "answer_id": 61842870, "author": "alex", "author_id": 4444742, "author_profile": "https://Stackoverflow.com/users/4444742", "pm_score": 0, "selected": false, "text": "from suds.client import Client client =\nClient(\"https://wsvc.cdiscount.com/MarketplaceAPIService.svc?wsdl\")\nprint client\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18138/" ]
241,897
<p>How do I alternate HTML table row colors using JSP?</p> <p>My CSS looks something like:</p> <pre><code>tr.odd {background-color: #EEDDEE} tr.even {background-color: #EEEEDD} </code></pre> <p>I want to use <code>&lt;c:forEach&gt;</code> to iterate over a collection. </p> <pre><code>&lt;c:forEach items="${element}" var="myCollection"&gt; &lt;tr&gt; &lt;td&gt;&lt;c:out value="${element.field}"/&gt;&lt;/td&gt; ... &lt;/tr&gt; &lt;/c:forEach&gt; </code></pre> <p>I need an int count variable or boolean odd/even variable to track the row. Then my <code>&lt;tr&gt;</code> tag would look something like:</p> <pre><code>&lt;tr class="odd or even depending on the row"&gt; </code></pre>
[ { "answer_id": 241917, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 1, "selected": false, "text": "counter = 0\nforeach (elements)\n counter = counter + 1\n output: <tr class=\"row{counter % 2}\">...</tr>\n" }, { "answer_id": 241927, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "String oddEven=\"\";\n<c:forEach items=\"${element}\" var=\"myCollection\">\n oddEven = (oddEven == \"even\") ? \"odd\" : \"even\";\n <tr class='\"'+oddEven+'\"'>\n <td><c:out value=\"${element.field}\"/></td>\n ...\n </tr>\n</c:forEach>\n" }, { "answer_id": 241939, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 7, "selected": true, "text": "varStatus" }, { "answer_id": 242002, "author": "Andy Ford", "author_id": 17252, "author_profile": "https://Stackoverflow.com/users/17252", "pm_score": 2, "selected": false, "text": "tr.odd td {}\ntr.even td {}\n" }, { "answer_id": 7594526, "author": "Cifi", "author_id": 915369, "author_profile": "https://Stackoverflow.com/users/915369", "pm_score": 2, "selected": false, "text": "table tr:nth-child(odd) { background-color: #ccc; }\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24396/" ]
241,925
<p>I have a number of generated .sql files that I want to run in succession. I'd like to run them from a SQL statement in a query (i.e. Query Analyzer/Server Management Studio).<br> Is it possible to do something like this and if so what is the syntax for doing this?</p> <p>I'm hoping for something like:</p> <pre><code>exec 'c:\temp\file01.sql' exec 'c:\temp\file02.sql' </code></pre> <p>I am using SQL Server 2005 and running queries in management studio.</p>
[ { "answer_id": 241940, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 7, "selected": true, "text": "EXEC xp_cmdshell 'sqlcmd -S ' + @DBServerName + ' -d ' + @DBName + ' -i ' + @FilePathName\n" }, { "answer_id": 241941, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 3, "selected": false, "text": "xp_cmdshell" }, { "answer_id": 6614716, "author": "Bruce Thompson", "author_id": 834057, "author_profile": "https://Stackoverflow.com/users/834057", "pm_score": 3, "selected": false, "text": "/* \nexecute a list of .sql files against the server and DB specified \n*/ \nSET NOCOUNT ON \n\nSET XACT_ABORT ON \nBEGIN TRAN \n\nDECLARE @DBServerName VARCHAR(100) = 'servername' \nDECLARE @DBName VARCHAR(100) = 'db name' \nDECLARE @FilePath VARCHAR(200) = 'path to scrips\\' \n/*\n\ncreate a holder for all filenames to be executed \n\n*/ \nDECLARE @FileList TABLE (Files NVARCHAR(MAX)) \n\nINSERT INTO @FileList VALUES ('script 1.sql') \nINSERT INTO @FileList VALUES ('script 2.sql') \nINSERT INTO @FileList VALUES ('script X.sql') \n\nWHILE (SELECT COUNT(Files) FROM @FileList) > 0 \nBEGIN \n /* \n execute each file one at a time \n */ \n DECLARE @FileName NVARCHAR(MAX) = (SELECT TOP(1) Files FROM @FileList) \n DECLARE @command VARCHAR(500) = 'sqlcmd -S ' + @DBServerName + ' -d ' + @DBName + ' -i \"' + @FilePath + @Filename +'\"' \n EXEC xp_cmdshell @command \n\n PRINT 'EXECUTED: ' + @FileName \n DELETE FROM @FileList WHERE Files = @FileName \nEND \nCOMMIT TRAN \n" }, { "answer_id": 11775904, "author": "Archi Moore", "author_id": 597425, "author_profile": "https://Stackoverflow.com/users/597425", "pm_score": 4, "selected": false, "text": "xp_cmdshell" }, { "answer_id": 40998657, "author": "Pesche Helfer", "author_id": 298494, "author_profile": "https://Stackoverflow.com/users/298494", "pm_score": 3, "selected": false, "text": "DECLARE @SQL varchar(MAX)\nSELECT @SQL = BulkColumn\nFROM OPENROWSET\n ( BULK 'MeinPfad\\MeinSkript.sql'\n , SINGLE_BLOB ) AS MYTABLE\n\n--PRINT @sql\nEXEC (@sql)\n" }, { "answer_id": 52988397, "author": "Alper Ebicoglu", "author_id": 1767482, "author_profile": "https://Stackoverflow.com/users/1767482", "pm_score": 2, "selected": false, "text": "sqlcmd -S localhost -d NorthWind -i \"C:\\MyScript.sql\"\n" }, { "answer_id": 57572931, "author": "Adam Henderson", "author_id": 1339507, "author_profile": "https://Stackoverflow.com/users/1339507", "pm_score": 2, "selected": false, "text": "DECLARE @Dir NVARCHAR(512) = 'd:\\SQLScriptsDirectory'\n\nDECLARE @FileList TABLE (\n subdirectory NVARCHAR(512),\n depth int,\n [file] bit\n)\n\nINSERT @FileList\nEXEC Master.dbo.xp_DirTree @Dir,1,1\n\nWHILE (SELECT COUNT(*) FROM @FileList) > 0 \nBEGIN \n DECLARE @FileName NVARCHAR(MAX) = (SELECT TOP(1) subdirectory FROM @FileList) \n DECLARE @FullPath NVARCHAR(MAX) = @Dir + '\\' + @FileName\n\n DECLARE @SQL NVARCHAR(MAX)\n DECLARE @SQL_TO_EXEC NVARCHAR(MAX)\n SELECT @SQL_TO_EXEC = 'select @SQL = BulkColumn\n FROM OPENROWSET\n ( BULK ''' + @FullPath + '''\n , SINGLE_BLOB ) AS MYTABLE'\n\n DECLARE @parmsdeclare NVARCHAR(4000) = '@SQL varchar(max) OUTPUT' \n\n EXEC sp_executesql @stmt = @SQL_TO_EXEC\n , @params = @parmsdeclare\n , @SQL = @SQL OUTPUT \n\n EXEC (@sql)\n DELETE FROM @FileList WHERE subdirectory = @FileName \n\n PRINT 'EXECUTED: ' + @FileName \nEND\n" }, { "answer_id": 57794320, "author": "live-love", "author_id": 436341, "author_profile": "https://Stackoverflow.com/users/436341", "pm_score": 2, "selected": false, "text": " sqlcmd -S localhost\\SQLEXPRESS -d DatabaseName-i \"c:\\temp\\script.sql\"\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25719/" ]
241,936
<p>The deceptively simple foundation of dynamic code generation within a C/C++ framework has already been covered in <a href="https://stackoverflow.com/questions/45408/">another question</a>. Are there any gentle introductions into topic with code examples? </p> <p>My eyes are starting to bleed staring at highly intricate open source JIT compilers when my needs are much more modest.</p> <p>Are there good texts on the subject that don't assume a doctorate in computer science? I'm looking for well worn patterns, things to watch out for, performance considerations, etc. Electronic or tree-based resources can be equally valuable. You can assume a working knowledge of (not just x86) assembly language.</p>
[ { "answer_id": 241997, "author": "Evan Teran", "author_id": 13430, "author_profile": "https://Stackoverflow.com/users/13430", "pm_score": 3, "selected": true, "text": "typedef void (*code_ptr)();\nunsigned long instruction_pointer = entry_point;\nstd::map<unsigned long, code_ptr> code_map;\n\n\nvoid execute_block() {\n code_ptr f;\n std::map<unsigned long, void *>::iterator it = code_map.find(instruction_pointer);\n if(it != code_map.end()) {\n f = it->second\n } else {\n f = generate_code_block();\n code_map[instruction_pointer] = f;\n }\n f();\n instruction_pointer = update_instruction_pointer();\n}\n\nvoid execute() {\n while(true) {\n execute_block();\n }\n}\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1892/" ]
241,953
<p>I'm using an <em>Edit in Place</em> jquery plugin which needs to post the data to a script that will do the actual database update.</p> <p>The URL to this update script is easily viewable in the html source as well as with Firebug, so I need to add some sort of authentication check before the update is processed. This is of course so the user can't just pass in any old userid / field / value they want and mess with other people's records.</p> <p>I was initially passing their username and password in as well, but this isn't ideal as it's in a GET request so it's all in the URL. The site itself is SSL at least, but still not a best practice by any stretch.</p> <p>What's the best way to authenticate this type of update?</p> <p>FWIW, the update script is in PHP, and the Edit in Place plugin is: <a href="http://www.appelsiini.net/projects/jeditable" rel="nofollow noreferrer">jeditable</a>.</p> <p><strong>Edit:</strong> To clarify: The actual data payload is POSTed to the script, but the edit in place plugin has no explicit method for authentication, so I was passing the authentication as part of the URL to the update script, which was then taking those variables via GET and using them to check.</p> <p><strong>Edit 2:</strong> Yes, I can access the session info from the update script, so I've decided to just pull the previously saved User ID and using that in the db update statement. That would appear to be the most secure method.</p>
[ { "answer_id": 242008, "author": "Már Örlygsson", "author_id": 16271, "author_profile": "https://Stackoverflow.com/users/16271", "pm_score": 2, "selected": false, "text": "submitdata" }, { "answer_id": 378336, "author": "akaihola", "author_id": 15770, "author_profile": "https://Stackoverflow.com/users/15770", "pm_score": 2, "selected": false, "text": "$(\".edit_area\")\n .editable(\"http://www.example.com/save.php\", { \n submitdata: { \n userid: 'johnsmith',\n pageid: '123', // or other value unique to the page\n timestamp: '1324354657', // time when page loaded\n hash: '0bee89b07a248e27c83fc3d5951213c1' }\n // ..other settings, etc.\n});\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241953", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
241,955
<p>I find myself writing code that looks like this a lot:</p> <pre><code>set&lt;int&gt; affected_items; while (string code = GetKeyCodeFromSomewhere()) { if (code == "some constant" || code == "some other constant") { affected_items.insert(some_constant_id); } else if (code == "yet another constant" || code == "the constant I didn't mention yet") { affected_items.insert(some_other_constant_id); } // else if etc... } for (set&lt;int&gt;::iterator it = affected_items.begin(); it != affected_items.end(); it++) { switch(*it) { case some_constant_id: RunSomeFunction(with, these, params); break; case some_other_constant_id: RunSomeOtherFunction(with, these, other, params); break; // etc... } } </code></pre> <p>The reason I end up writing this code is that I need to only run the functions in the second loop once even if I've received multiple key codes that might cause them to run.</p> <p>This just doesn't seem like the best way to do it. Is there a neater way?</p>
[ { "answer_id": 241972, "author": "Don Neufeld", "author_id": 13097, "author_profile": "https://Stackoverflow.com/users/13097", "pm_score": 2, "selected": true, "text": "// Ahead of time you build a static map from your strings to bit values.\nstd::map< std::string, int > codesToValues;\ncodesToValues[ \"some constant\" ] = 1;\ncodesToValues[ \"some other constant\" ] = 1;\ncodesToValues[ \"yet another constant\" ] = 2;\ncodesToValues[ \"the constant I didn't mention yet\" ] = 2;\n\n// When you want to do your work\nint affected_items = 0;\nwhile (string code = GetKeyCodeFromSomewhere())\n affected_items |= codesToValues[ code ];\n\nif( affected_items & 1 )\n RunSomeFunction(with, these, params);\nif( affected_items & 2 )\n RunSomeOtherFunction(with, these, other, params);\n// etc...\n" }, { "answer_id": 241996, "author": "Andru Luvisi", "author_id": 5922, "author_profile": "https://Stackoverflow.com/users/5922", "pm_score": 2, "selected": false, "text": "if(done[code])\n continue;\ndone[code] = true;\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20889/" ]
241,960
<p>How do I drop a Groovlet into a Grails app? Say, for example, in web-app/groovlet.groovy</p> <pre> import java.util.Date if (session == null) { session = request.getSession(true); } if (session.counter == null) { session.counter = 1 } println """ &lt;html> &lt;head> &lt;title>Groovy Servlet&lt;/title> &lt;/head> &lt;body> Hello, ${request.remoteHost}: Counter: ${session.counter}! Date: ${new Date()} &lt;br> """ </pre>
[ { "answer_id": 242030, "author": "kolrie", "author_id": 14540, "author_profile": "https://Stackoverflow.com/users/14540", "pm_score": 0, "selected": false, "text": "class DateController {\n def index = {\n if (session == null) {\n session = request.getSession(true);\n }\n\n if (session.counter == null) {\n session.counter = 1\n }\n }\n}\n" }, { "answer_id": 242041, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 4, "selected": true, "text": "grails install-templates" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241960", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
241,964
<p>How to set internationalization to a <code>DateTimepicker</code> or <code>Calendar WinForm</code> control in .Net when the desire culture is different to the one installed in the PC?</p>
[ { "answer_id": 242010, "author": "Hapkido", "author_id": 27646, "author_profile": "https://Stackoverflow.com/users/27646", "pm_score": 0, "selected": false, "text": "dtp.Format = DateTimePickerFormat.Custom;\ndtp.CustomFormat = \"yyyy-MM-dd\"; // or the format you prefer\n" }, { "answer_id": 448443, "author": "Bigballs", "author_id": 55614, "author_profile": "https://Stackoverflow.com/users/55614", "pm_score": 0, "selected": false, "text": "System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(\"fr\");\nSystem.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;\n" }, { "answer_id": 1972534, "author": "heejong", "author_id": 1746309, "author_profile": "https://Stackoverflow.com/users/1746309", "pm_score": -1, "selected": false, "text": "dateTimePicker.Format = DateTimePickerFormat.Custom;\nstring[] formats = dateTimePicker.Value.GetDateTimeFormats(Application.CurrentCulture);\ndateTimePicker.CustomFormat = formats[0];\n" }, { "answer_id": 2028345, "author": "KaDim", "author_id": 246475, "author_profile": "https://Stackoverflow.com/users/246475", "pm_score": 3, "selected": false, "text": "dateTimePicker.Format = DateTimePickerFormat.Custom;\ndateTimePicker.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;\n" }, { "answer_id": 58179461, "author": "user12146889", "author_id": 12146889, "author_profile": "https://Stackoverflow.com/users/12146889", "pm_score": -1, "selected": false, "text": "Application.CurrentCulture = new CultureInfo(\"fa-IR\"); \nradDateTimePicker1.Format = DateTimePickerFormat.Custom;\nradDateTimePicker1.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14440/" ]
241,967
<p>I am playing with the new stuff of C#3.0 and I have this code (mostly taken from <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx" rel="noreferrer">MSDN</a>) but I can only get true,false,true... and not the real value :</p> <pre><code> int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var oddNumbers = numbers.Select(n =&gt; n % 2 == 1); Console.WriteLine("Numbers &lt; 5:"); foreach (var x in oddNumbers) { Console.WriteLine(x); } </code></pre> <p>How can I fix that to show the list of integer?</p>
[ { "answer_id": 241975, "author": "TheSoftwareJedi", "author_id": 18941, "author_profile": "https://Stackoverflow.com/users/18941", "pm_score": 6, "selected": true, "text": " int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };\n\n var oddNumbers = numbers.Where(n => n % 2 == 1);\n\n Console.WriteLine(\"Odd Number:\");\n foreach (var x in oddNumbers)\n {\n Console.WriteLine(x);\n }\n" }, { "answer_id": 241981, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 3, "selected": false, "text": "numbers.Select(n => n % 2 == 1);\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13913/" ]
241,971
<p>i have a web service hosted on another server with the Anonymous Access CheckBox in IIS is already checked. when my local web application is trying to access the web service, i still get the "The request failed with HTTP status 401: Access Denied." error. my web application is calling the web service like the following:</p> <p>MyObject.WebService ws = new MyObject.WebService (); ws.Retrieve(someParams);</p> <p>what am i missing here?</p>
[ { "answer_id": 242088, "author": "Vlad N", "author_id": 28472, "author_profile": "https://Stackoverflow.com/users/28472", "pm_score": 0, "selected": false, "text": "MyObject.WebService ws = new MyObject.WebService(); \nws.PreAuthenticate = true;\nresponse = ws.Retrieve(someParams);\n" }, { "answer_id": 12948644, "author": "Anish V", "author_id": 1646305, "author_profile": "https://Stackoverflow.com/users/1646305", "pm_score": 1, "selected": false, "text": "//Assigning DefaultCredentials to the Credentials property\n//of the Web service client proxy (myProxy).\nmyProxy.Credentials= System.Net.CredentialCache.DefaultCredentials;" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31936/" ]
241,989
<p>When I restart my apache2 and reload a page, the log file shows</p> <pre><code>boogie.tontut.fi - - [28/Oct/2008:03:27:49 +0200] "GET /test HTTP/1.1" 404 457 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3" </code></pre> <p>...as supposed to, as it's <code>03:27:49</code> now. However, when I click the refresh button again, the new log entry is:</p> <pre><code>boogie.tontut.fi - - [27/Oct/2008:21:27:52 -0400] "GET /test HTTP/1.1" 404 457 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3" </code></pre> <p>Offset has changed from <code>+0200 to -0400</code> and I have no clue where this comes from.</p> <p>How can I start troubleshooting this problem?</p>
[ { "answer_id": 242011, "author": "Kevin Hakanson", "author_id": 22514, "author_profile": "https://Stackoverflow.com/users/22514", "pm_score": 0, "selected": false, "text": "httpd.conf" }, { "answer_id": 242138, "author": "Martin Redmond", "author_id": 30541, "author_profile": "https://Stackoverflow.com/users/30541", "pm_score": 0, "selected": false, "text": "gettimeofday" }, { "answer_id": 242185, "author": "che", "author_id": 7806, "author_profile": "https://Stackoverflow.com/users/7806", "pm_score": 0, "selected": false, "text": "GMT+2" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30141/" ]
241,991
<p>We have a weird intermittent problem with saving from Word 2007 to our SharePoint 2007 (MOSS) document libraries that gives a dialog box that never goes away - it is titled "Content Types" and the message "Getting list of available content types..." with a green progress-type bar that keeps scrolling. It happens a lot on our training server (self-contained virtual machine with separate SQL Server) but more worryingly is happening on our live production server (which is in a medium server farm arrangement - web application server, another server for search/indexing and a SQL Server). All servers in the farms are 64 bit.</p> <p>It is strangely random - the user has to kill Word 2007, then they recover their document and try to save to the same document library and it saves without a problem. </p> <p>It happens more on the training server than the live server. The live web application server rarely goes over 20% CPU (usually around 5%) and memory peaks at 2Gb of the available 4Gb (usually at 1.5Gb) so I don't think its a resources issue. </p> <p>The document libraries are customised and deployed using Features in a Solution. The only content type in them is the standard Documents content type. </p> <p><strong>Update</strong> We opened this with Microsoft as a support issue and it is a known issue that is targeted to be addressed in a Cumulative Update hotfix package for SharePoint in February 2009.</p> <p><em>Edit</em> Copied the above response to an answer so this question could be flagged as answered.</p>
[ { "answer_id": 242011, "author": "Kevin Hakanson", "author_id": 22514, "author_profile": "https://Stackoverflow.com/users/22514", "pm_score": 0, "selected": false, "text": "httpd.conf" }, { "answer_id": 242138, "author": "Martin Redmond", "author_id": 30541, "author_profile": "https://Stackoverflow.com/users/30541", "pm_score": 0, "selected": false, "text": "gettimeofday" }, { "answer_id": 242185, "author": "che", "author_id": 7806, "author_profile": "https://Stackoverflow.com/users/7806", "pm_score": 0, "selected": false, "text": "GMT+2" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20977/" ]
241,994
<p>This is something that I have always wondered about, but never bothered to profile.</p> <p>Is it more efficient to assign a value to a temp variable, than to keep using that value. An Example may be clearer:</p> <pre><code>string s = reader.GetItem[0].ToString(); someClass.SomeField = s; someOtherClass.someField = s; </code></pre> <p>OR</p> <pre><code>someClass.SomeField = reader.GetItem[0].ToString(); someOtherClass.someField = reader.GetItem[0].ToString(); </code></pre> <p>My initial thought would the top example would be more efficient as it doesn't have to access the Item collection or call ToString.</p> <p>Would be interested to hear other peoples ideas, or definitive answer either way.</p>
[ { "answer_id": 242007, "author": "Johann Gerell", "author_id": 6345, "author_profile": "https://Stackoverflow.com/users/6345", "pm_score": 0, "selected": false, "text": "ToString" }, { "answer_id": 242416, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": false, "text": "someOtherClass.someField = someClass.SomeField = reader.GetItem[0].ToString();\n" }, { "answer_id": 1449758, "author": "grantwparks", "author_id": 117773, "author_profile": "https://Stackoverflow.com/users/117773", "pm_score": 0, "selected": false, "text": "s" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241994", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1075/" ]
241,995
<p>I would like to be able to drop to the python REPL from the debugger -- if this is not possible is there an easier way to evaluate python expressions in the context of the current breakpoint other than manually adding them all as watch expressions?</p>
[ { "answer_id": 242774, "author": "nosklo", "author_id": 17160, "author_profile": "https://Stackoverflow.com/users/17160", "pm_score": 3, "selected": true, "text": "import code\ncode.interact(local=locals())\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/241995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2168/" ]
242,012
<p>After looking on MSDN, it's still unclear to me how I should form a proper predicate to use the Find() method in List using a member variable of T (where T is a class)</p> <p>For example:</p> <pre><code>public class Car { public string Make; public string Model; public int Year; } { // somewhere in my code List&lt;Car&gt; carList = new List&lt;Car&gt;(); // ... code to add Cars ... Car myCar = new Car(); // Find the first of each car made between 1980 and 2000 for (int x = 1980; x &lt; 2000; x++) { myCar = carList.Find(byYear(x)); Console.Writeline(myCar.Make + myCar.Model); } } </code></pre> <p>What should my "byYear" predicate look like? </p> <p>(The MSDN example only talks about a List of dinosaurs and only searches for an unchanging value "saurus" -- It doesn't show how to pass a value into the predicate...)</p> <p>EDIT: I'm using VS2005/.NET2.0, so I don't think Lambda notation is available to me...</p> <p>EDIT2: Removed "1999" in the example because I may want to "Find" programatically based on different values. Example changed to range of cars from 1980 to 2000 using for-do loop.</p>
[ { "answer_id": 242020, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 2, "selected": false, "text": "Func<int, Predicate<Car>> byYear = i => (c => c.Year == i);\n" }, { "answer_id": 242024, "author": "Dan Finucane", "author_id": 30026, "author_profile": "https://Stackoverflow.com/users/30026", "pm_score": 5, "selected": false, "text": "myCar = carList.Find(car => car.Year == 1999);\n" }, { "answer_id": 242033, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 6, "selected": true, "text": "static Predicate<Car> ByYear(int year)\n{\n return delegate(Car car)\n {\n return car.Year == year;\n };\n}\n\nstatic void Main(string[] args)\n{\n // yeah, this bit is C# 3.0, but ignore it - it's just setting up the list.\n List<Car> list = new List<Car>\n {\n new Car { Year = 1940 },\n new Car { Year = 1965 },\n new Car { Year = 1973 },\n new Car { Year = 1999 }\n };\n var car99 = list.Find(ByYear(1999));\n var car65 = list.Find(ByYear(1965));\n\n Console.WriteLine(car99.Year);\n Console.WriteLine(car65.Year);\n}\n" }, { "answer_id": 242058, "author": "Todd", "author_id": 31940, "author_profile": "https://Stackoverflow.com/users/31940", "pm_score": 4, "selected": false, "text": "Car myCar = cars.Find(delegate(Car c) { return c.Year == x; });\n\n// If not found myCar will be null\nif (myCar != null)\n{\n Console.Writeline(myCar.Make + myCar.Model);\n}\n" }, { "answer_id": 242281, "author": "Ajaxx", "author_id": 25228, "author_profile": "https://Stackoverflow.com/users/25228", "pm_score": 3, "selected": false, "text": "myCar = carList.Find(delegate(Car car) { return car.Year == i; });\n" }, { "answer_id": 23519671, "author": "phclummia", "author_id": 3611320, "author_profile": "https://Stackoverflow.com/users/3611320", "pm_score": 1, "selected": false, "text": "var existData =\n cars.Find(\n c => c.Year== 1999);\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242012", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21244/" ]
242,032
<p>Is there a way to get the directory of a project in Eclipse? We are writing a plugin that will allow the user to select files, and then run some processes on those files. I would ideally like to be able to get all the files with a certain extension, but that is not necessary.</p>
[ { "answer_id": 242075, "author": "AdamC", "author_id": 16476, "author_profile": "https://Stackoverflow.com/users/16476", "pm_score": 4, "selected": true, "text": "ResourcesPlugin.getWorkspace().getRoot().getProjects()\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17712/" ]
242,065
<p>I have been enjoying learning the basics of python, but before I started reading things I tried to install various python versions and modules clumsily. Now that I have some ideas of what I want to do and how to do it I'm finding that various aspects are broken. For instance, 2.6 IDLE won't launch, and when I try to import modules they usually don't work.</p> <p>My question is, how would you recommend I clean this up and start fresh? I have read information about modifying the 2.6 install, but I still can't get it to work.</p> <p>IDLE 2.4 works, and when I launch python from the terminal I am running python 2.4.4.</p>
[ { "answer_id": 248884, "author": "orestis", "author_id": 32617, "author_profile": "https://Stackoverflow.com/users/32617", "pm_score": 1, "selected": false, "text": "which python" }, { "answer_id": 286372, "author": "dbr", "author_id": 745, "author_profile": "https://Stackoverflow.com/users/745", "pm_score": 1, "selected": false, "text": "/sw/" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20824/" ]
242,066
<p>I am currently validating a client's HTML Source and I am getting a lot of validation errors for images and input files which do not have the Omittag. I would do it manually but this client literally has thousands of files, with a lot of instances where the is not .</p> <p>This client has validated some img tags (for whatever reason).</p> <p>Just wondering if there is a unix command I could run to check to see if the does not have a Omittag to add it.</p> <p>I have done simple search and replaces with the following command:</p> <pre><code>find . \! -path '*.svn*' -type f -exec sed -i -n '1h;1!H;${;g;s/&lt;b&gt;/&lt;strong&gt;/g;p}' {} \; </code></pre> <p>But never something this large. Any help would be appreciated.</p>
[ { "answer_id": 242374, "author": "Anirvan", "author_id": 31100, "author_profile": "https://Stackoverflow.com/users/31100", "pm_score": 2, "selected": false, "text": ".orig" }, { "answer_id": 242377, "author": "joelhardi", "author_id": 11438, "author_profile": "https://Stackoverflow.com/users/11438", "pm_score": 1, "selected": true, "text": "/" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
242,073
<p>This is similar to <a href="https://stackoverflow.com/questions/18932/sql-how-can-i-remove-duplicate-rows">this question</a>, but it seems like some of the answers there aren't quite compatible with MySQL (or I'm not doing it right), and I'm having a heck of a time figuring out the changes I need. Apparently my SQL is rustier than I thought it was. I'm also looking to change a column value rather than delete, but I think at least <b>that</b> part is simple...</p> <p>I have a table like:</p> <pre>rowid SERIAL fingerprint TEXT duplicate BOOLEAN contents TEXT created_date DATETIME</pre> <p>I want to set duplicate=true for all but the first (by created_date) of each group by fingerprint. It's easy to mark <em>all</em> of the rows with duplicate fingerprints as dupes. The part I'm getting stuck on is keeping the first.</p> <p>One of the apps that populates the table does bulk loads of data, with multiple workers loading data from different sources, and the workers' data isn't necessarily partitioned by date, so it's a pain to try to mark these all as they come in (the first one inserted isn't necessarily the first one by date). Also, I already have a bunch of data in there I'll need to clean up either way. So I'd rather just have a relatively efficient query I can run after a bulk load to clean up than try to build it into that app.</p> <p>Thanks!</p>
[ { "answer_id": 242336, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 0, "selected": false, "text": "SET @rowid := 0;\n\nUPDATE mytable\nSET duplicate = (rowid = @rowid), \n rowid = (@rowid:=rowid)\nORDER BY rowid, created_date;\n" }, { "answer_id": 245950, "author": "sliderhouserules", "author_id": 31385, "author_profile": "https://Stackoverflow.com/users/31385", "pm_score": 0, "selected": false, "text": "UPDATE t1\nSET duplicate = 1\nFROM MyTable t1\nWHERE rowid != (\n SELECT TOP 1 rowid FROM MyTable t2\n WHERE t2.fingerprint = t1.fingerprint ORDER BY created_date DESC\n)\n" }, { "answer_id": 254436, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 0, "selected": false, "text": "UPDATE" }, { "answer_id": 667923, "author": "Dipin", "author_id": 67976, "author_profile": "https://Stackoverflow.com/users/67976", "pm_score": 2, "selected": false, "text": "max_sort_length" }, { "answer_id": 842445, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 0, "selected": false, "text": "UPDATE TheAnonymousTable\n SET duplicate = TRUE\n WHERE rowid NOT IN\n (SELECT rowid\n FROM (SELECT MIN(created_date) AS created_date, fingerprint\n FROM TheAnonymousTable\n GROUP BY fingerprint\n ) AS M,\n TheAnonymousTable AS T\n WHERE M.created_date = T.created_date\n AND M.fingerprint = T.fingerprint\n );\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
242,079
<p>In Java, we can always use an array to store object reference. Then we have an ArrayList or HashTable which is automatically expandable to store objects. But does anyone know a native way to have an auto-expandable array of object references?</p> <p>Edit: What I mean is I want to know if the Java API has some class with the ability to store references to objects (but not storing the actual object like XXXList or HashTable do) AND the ability of auto-expansion.</p>
[ { "answer_id": 242093, "author": "Kevin Day", "author_id": 10973, "author_profile": "https://Stackoverflow.com/users/10973", "pm_score": 4, "selected": true, "text": "String myStrings[10];\n" }, { "answer_id": 242844, "author": "mtruesdell", "author_id": 6479, "author_profile": "https://Stackoverflow.com/users/6479", "pm_score": 1, "selected": false, "text": "Foo myFoo = new Foo();\nFoo anotherFoo = myFoo;\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8203/" ]
242,097
<p>What's a more elegant way of having the code below where i want to return a derived class based on the type of another class.</p> <pre><code> if (option_ is Rectangle) { modelInputs = new Foo(); } else if (option_ is Circle) { modelInputs = new Bar(); } else if (option_ is Triangle) { modelInputs = new Bar2(); } </code></pre>
[ { "answer_id": 242109, "author": "mmiika", "author_id": 6846, "author_profile": "https://Stackoverflow.com/users/6846", "pm_score": 4, "selected": true, "text": "interface IHasModelInput\n{\n IModelInput GetModelInput();\n}\n" }, { "answer_id": 242198, "author": "Andrew Stapleton", "author_id": 28506, "author_profile": "https://Stackoverflow.com/users/28506", "pm_score": 2, "selected": false, "text": " public static class FactoryMethod<T> where T : IModelInput, new()\n {\n public static IModelInput Create()\n {\n return new T();\n }\n }\n\n delegate IModelInput ModelInputCreateFunction();\n\n IModelInput CreateIModelInput(object item)\n {\n\n Dictionary<Type, ModelInputCreateFunction> factory = new Dictionary<Type, ModelInputCreateFunction>();\n\n\n factory.Add(typeof(Rectangle), FactoryMethod<Foo>.Create);\n factory.Add(typeof(Circle), FactoryMethod<Bar>.Create);\n // Add more type mappings here\n\n\n\n\n IModelInput modelInput;\n foreach (Type t in factory.Keys)\n {\n if ( item.GetType().IsSubclassOf(t) || item.GetType().Equals(t))\n {\n modelInput = factory[t].Invoke();\n break;\n }\n }\n return modelInput;\n }\n" }, { "answer_id": 242222, "author": "Dave Markle", "author_id": 24995, "author_profile": "https://Stackoverflow.com/users/24995", "pm_score": 1, "selected": false, "text": "Hashtable ht = new Hashtable();\nht.Add(typeof(Rectangle), typeof(Bar));\nht.Add(typeof(Square), typeof(Bar2));\n\nmodelInputs = Activator.CreateInstance(ht[option.GetType()]);\n" }, { "answer_id": 242232, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 0, "selected": false, "text": "public class TaskFactory\n{\n private Dictionary<String, Type> _taskTypes = new Dictionary<String, Type>();\n\n public TaskFactory()\n {\n // Preload the Task Types into a dictionary so we can look them up later\n foreach (Type type in typeof(TaskFactory).Assembly.GetTypes())\n {\n if (type.IsSubclassOf(typeof(CCTask)))\n {\n _taskTypes[type.Name.ToLower()] = type;\n }\n }\n }\n\n public CCTask CreateTask(XmlElement task)\n {\n if (task != null)\n {\n string taskName = task.Name;\n taskName = taskName.ToLower() + \"task\";\n\n // If the Type information is in our Dictionary, instantiate a new instance of that task\n Type taskType;\n if (_taskTypes.TryGetValue(taskName, out taskType))\n {\n return (CCTask)Activator.CreateInstance(taskType, task);\n }\n else\n {\n throw new ArgumentException(\"Unrecognized Task:\" + task.Name);\n } \n }\n else\n {\n return null;\n }\n }\n}\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242097", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
242,118
<p>Assuming a Perl script that allows users to specify several text filter expressions in a config file, is there a safe way to let them enter regular expressions as well, without the possibility of unintended side effects or code execution? Without actually parsing the regexes and checking them for problematic constructs, that is. There won't be any substitution, only matching.</p> <p>As an aside, is there a way to test if the specified regex is valid before actually using it? I'd like to issue warnings if something like <code>/foo (bar/</code> was entered.</p> <p>Thanks, Z.</p> <p><hr> EDIT:<br> Thanks for the very interesting answers. I've since found out that the following dangerous constructs will only be evaluated in regexes if the <code>use re 'eval'</code> pragma is used:</p> <pre><code>(?{code}) (??{code}) ${code} @{code} </code></pre> <p>The default is <code>no re 'eval'</code>; so unless I'm missing something, it should be safe to read regular expressions from a file, with the only check being the eval/catch posted by Axeman. At least I haven't been able to hide anything evil in them in my tests.</p> <p>Thanks again. Z.</p>
[ { "answer_id": 242122, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "(?{ code })\n" }, { "answer_id": 242132, "author": "Axeman", "author_id": 11289, "author_profile": "https://Stackoverflow.com/users/11289", "pm_score": 4, "selected": false, "text": "eval { \n qr/$re/;\n};\nif ( $@ ) { \n # do something\n}\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31682/" ]
242,143
<p>I am using WCF to upload data to a server.</p> <p>If the communication fails, is there any way to resume the upload?</p>
[ { "answer_id": 242122, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "(?{ code })\n" }, { "answer_id": 242132, "author": "Axeman", "author_id": 11289, "author_profile": "https://Stackoverflow.com/users/11289", "pm_score": 4, "selected": false, "text": "eval { \n qr/$re/;\n};\nif ( $@ ) { \n # do something\n}\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242143", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1368/" ]
242,147
<p>I have just discovered the nifty unhandled exception handler for cocoa-touch.</p> <p>Now that I can gracefully notify the user about any unhandled exceptions that might crash my application, I'd like to shut down my application after notifying the user that a crash has occured.</p> <p>Does anyone know how to shut down an application programmatically?</p>
[ { "answer_id": 242388, "author": "Rich", "author_id": 22003, "author_profile": "https://Stackoverflow.com/users/22003", "pm_score": 2, "selected": false, "text": "exit(0);\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242147", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8918/" ]
242,160
<p>How is profiling different from logging?</p> <p>Is it just that profiling is used for performance measurements to see how long each function takes? Or am I off?</p> <p>Typically, how are profiling libraries used?</p> <p>What types of stats are obtained by profiling?</p>
[ { "answer_id": 242166, "author": "Adam Liss", "author_id": 29157, "author_profile": "https://Stackoverflow.com/users/29157", "pm_score": 6, "selected": true, "text": "if" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
242,172
<blockquote> <p><strong>Edit:</strong> The code here still has some bugs in it, and it could do better in the performance department, but instead of trying to fix this, for the record I took the problem over to the Intel discussion groups and got lots of great feedback, and if all goes well a polished version of Atomic float will be included in a near future release of Intel's Threading Building Blocks</p> </blockquote> <p>Ok here's a tough one, I want an Atomic float, not for super-fast graphics performance, but to use routinely as data-members of classes. And I don't want to pay the price of using locks on these classes, because it provides no additional benefits for my needs. </p> <p>Now with intel's tbb and other atomic libraries I've seen, integer types are supported, but not floating points. So I went on and implemented one, and it works... but I'm not sure if it REALLY works, or I'm just very lucky that it works.</p> <p>Anyone here knows if this is not some form of threading heresy?</p> <pre><code>typedef unsigned int uint_32; struct AtomicFloat { private: tbb::atomic&lt;uint_32&gt; atomic_value_; public: template&lt;memory_semantics M&gt; float fetch_and_store( float value ) { const uint_32 value_ = atomic_value_.tbb::atomic&lt;uint_32&gt;::fetch_and_store&lt;M&gt;((uint_32&amp;)value); return reinterpret_cast&lt;const float&amp;&gt;(value_); } float fetch_and_store( float value ) { const uint_32 value_ = atomic_value_.tbb::atomic&lt;uint_32&gt;::fetch_and_store((uint_32&amp;)value); return reinterpret_cast&lt;const float&amp;&gt;(value_); } template&lt;memory_semantics M&gt; float compare_and_swap( float value, float comparand ) { const uint_32 value_ = atomic_value_.tbb::atomic&lt;uint_32&gt;::compare_and_swap&lt;M&gt;((uint_32&amp;)value,(uint_32&amp;)compare); return reinterpret_cast&lt;const float&amp;&gt;(value_); } float compare_and_swap(float value, float compare) { const uint_32 value_ = atomic_value_.tbb::atomic&lt;uint_32&gt;::compare_and_swap((uint_32&amp;)value,(uint_32&amp;)compare); return reinterpret_cast&lt;const float&amp;&gt;(value_); } operator float() const volatile // volatile qualifier here for backwards compatibility { const uint_32 value_ = atomic_value_; return reinterpret_cast&lt;const float&amp;&gt;(value_); } float operator=(float value) { const uint_32 value_ = atomic_value_.tbb::atomic&lt;uint_32&gt;::operator =((uint_32&amp;)value); return reinterpret_cast&lt;const float&amp;&gt;(value_); } float operator+=(float value) { volatile float old_value_, new_value_; do { old_value_ = reinterpret_cast&lt;float&amp;&gt;(atomic_value_); new_value_ = old_value_ + value; } while(compare_and_swap(new_value_,old_value_) != old_value_); return (new_value_); } float operator*=(float value) { volatile float old_value_, new_value_; do { old_value_ = reinterpret_cast&lt;float&amp;&gt;(atomic_value_); new_value_ = old_value_ * value; } while(compare_and_swap(new_value_,old_value_) != old_value_); return (new_value_); } float operator/=(float value) { volatile float old_value_, new_value_; do { old_value_ = reinterpret_cast&lt;float&amp;&gt;(atomic_value_); new_value_ = old_value_ / value; } while(compare_and_swap(new_value_,old_value_) != old_value_); return (new_value_); } float operator-=(float value) { return this-&gt;operator+=(-value); } float operator++() { return this-&gt;operator+=(1); } float operator--() { return this-&gt;operator+=(-1); } float fetch_and_add( float addend ) { return this-&gt;operator+=(-addend); } float fetch_and_increment() { return this-&gt;operator+=(1); } float fetch_and_decrement() { return this-&gt;operator+=(-1); } }; </code></pre> <p>Thanks!</p> <p><strong>Edit:</strong> changed size_t to uint32_t as Greg Rogers suggested, that way its more portable</p> <p><strong>Edit:</strong> added listing for the entire thing, with some fixes.</p> <p><strong>More Edits:</strong> Performance wise using a locked float for 5.000.000 += operations with 100 threads on my machine takes 3.6s, while my atomic float even with its silly do-while takes 0.2s to do the same work. So the >30x performance boost means its worth it, (and this is the catch) if its correct.</p> <p><strong>Even More Edits:</strong> As Awgn pointed out my <code>fetch_and_xxxx</code> parts were all wrong. Fixed that and removed parts of the API I'm not sure about (templated memory models). And implemented other operations in terms of operator += to avoid code repetition</p> <p><strong>Added:</strong> Added operator *= and operator /=, since floats wouldn't be floats without them. Thanks to Peterchen's comment that this was noticed</p> <p><strong>Edit:</strong> Latest version of the code follows (I'll leave the old version for reference though)</p> <pre><code> #include &lt;tbb/atomic.h&gt; typedef unsigned int uint_32; typedef __TBB_LONG_LONG uint_64; template&lt;typename FLOATING_POINT,typename MEMORY_BLOCK&gt; struct atomic_float_ { /* CRC Card ----------------------------------------------------- | Class: atmomic float template class | | Responsability: handle integral atomic memory as it were a float, | but partially bypassing FPU, SSE/MMX, so it is | slower than a true float, but faster and smaller | than a locked float. | *Warning* If your float usage is thwarted by | the A-B-A problem this class isn't for you | *Warning* Atomic specification says we return, | values not l-values. So (i = j) = k doesn't work. | | Collaborators: intel's tbb::atomic handles memory atomicity ----------------------------------------------------------------*/ typedef typename atomic_float_&lt;FLOATING_POINT,MEMORY_BLOCK&gt; self_t; tbb::atomic&lt;MEMORY_BLOCK&gt; atomic_value_; template&lt;memory_semantics M&gt; FLOATING_POINT fetch_and_store( FLOATING_POINT value ) { const MEMORY_BLOCK value_ = atomic_value_.tbb::atomic&lt;MEMORY_BLOCK&gt;::fetch_and_store&lt;M&gt;((MEMORY_BLOCK&amp;)value); //atomic specification requires returning old value, not new one return reinterpret_cast&lt;const FLOATING_POINT&amp;&gt;(value_); } FLOATING_POINT fetch_and_store( FLOATING_POINT value ) { const MEMORY_BLOCK value_ = atomic_value_.tbb::atomic&lt;MEMORY_BLOCK&gt;::fetch_and_store((MEMORY_BLOCK&amp;)value); //atomic specification requires returning old value, not new one return reinterpret_cast&lt;const FLOATING_POINT&amp;&gt;(value_); } template&lt;memory_semantics M&gt; FLOATING_POINT compare_and_swap( FLOATING_POINT value, FLOATING_POINT comparand ) { const MEMORY_BLOCK value_ = atomic_value_.tbb::atomic&lt;MEMORY_BLOCK&gt;::compare_and_swap&lt;M&gt;((MEMORY_BLOCK&amp;)value,(MEMORY_BLOCK&amp;)compare); //atomic specification requires returning old value, not new one return reinterpret_cast&lt;const FLOATING_POINT&amp;&gt;(value_); } FLOATING_POINT compare_and_swap(FLOATING_POINT value, FLOATING_POINT compare) { const MEMORY_BLOCK value_ = atomic_value_.tbb::atomic&lt;MEMORY_BLOCK&gt;::compare_and_swap((MEMORY_BLOCK&amp;)value,(MEMORY_BLOCK&amp;)compare); //atomic specification requires returning old value, not new one return reinterpret_cast&lt;const FLOATING_POINT&amp;&gt;(value_); } operator FLOATING_POINT() const volatile // volatile qualifier here for backwards compatibility { const MEMORY_BLOCK value_ = atomic_value_; return reinterpret_cast&lt;const FLOATING_POINT&amp;&gt;(value_); } //Note: atomic specification says we return the a copy of the base value not an l-value FLOATING_POINT operator=(FLOATING_POINT rhs) { const MEMORY_BLOCK value_ = atomic_value_.tbb::atomic&lt;MEMORY_BLOCK&gt;::operator =((MEMORY_BLOCK&amp;)rhs); return reinterpret_cast&lt;const FLOATING_POINT&amp;&gt;(value_); } //Note: atomic specification says we return an l-value when operating among atomics self_t&amp; operator=(self_t&amp; rhs) { const MEMORY_BLOCK value_ = atomic_value_.tbb::atomic&lt;MEMORY_BLOCK&gt;::operator =((MEMORY_BLOCK&amp;)rhs); return *this; } FLOATING_POINT&amp; _internal_reference() const { return reinterpret_cast&lt;FLOATING_POINT&amp;&gt;(atomic_value_.tbb::atomic&lt;MEMORY_BLOCK&gt;::_internal_reference()); } FLOATING_POINT operator+=(FLOATING_POINT value) { FLOATING_POINT old_value_, new_value_; do { old_value_ = reinterpret_cast&lt;FLOATING_POINT&amp;&gt;(atomic_value_); new_value_ = old_value_ + value; //floating point binary representation is not an issue because //we are using our self's compare and swap, thus comparing floats and floats } while(self_t::compare_and_swap(new_value_,old_value_) != old_value_); return (new_value_); //return resulting value } FLOATING_POINT operator*=(FLOATING_POINT value) { FLOATING_POINT old_value_, new_value_; do { old_value_ = reinterpret_cast&lt;FLOATING_POINT&amp;&gt;(atomic_value_); new_value_ = old_value_ * value; //floating point binary representation is not an issue becaus //we are using our self's compare and swap, thus comparing floats and floats } while(self_t::compare_and_swap(new_value_,old_value_) != old_value_); return (new_value_); //return resulting value } FLOATING_POINT operator/=(FLOATING_POINT value) { FLOATING_POINT old_value_, new_value_; do { old_value_ = reinterpret_cast&lt;FLOATING_POINT&amp;&gt;(atomic_value_); new_value_ = old_value_ / value; //floating point binary representation is not an issue because //we are using our self's compare and swap, thus comparing floats and floats } while(self_t::compare_and_swap(new_value_,old_value_) != old_value_); return (new_value_); //return resulting value } FLOATING_POINT operator-=(FLOATING_POINT value) { return this-&gt;operator+=(-value); //return resulting value } //Prefix operator FLOATING_POINT operator++() { return this-&gt;operator+=(1); //return resulting value } //Prefix operator FLOATING_POINT operator--() { return this-&gt;operator+=(-1); //return resulting value } //Postfix operator FLOATING_POINT operator++(int) { const FLOATING_POINT temp = this; this-&gt;operator+=(1); return temp//return resulting value } //Postfix operator FLOATING_POINT operator--(int) { const FLOATING_POINT temp = this; this-&gt;operator+=(1); return temp//return resulting value } FLOATING_POINT fetch_and_add( FLOATING_POINT addend ) { const FLOATING_POINT old_value_ = atomic_value_; this-&gt;operator+=(addend); //atomic specification requires returning old value, not new one as in operator x= return old_value_; } FLOATING_POINT fetch_and_increment() { const FLOATING_POINT old_value_ = atomic_value_; this-&gt;operator+=(+1); //atomic specification requires returning old value, not new one as in operator x= return old_value_; } FLOATING_POINT fetch_and_decrement() { const FLOATING_POINT old_value_ = atomic_value_; this-&gt;operator+=(-1); //atomic specification requires returning old value, not new one as in operator x= return old_value_; } }; typedef atomic_float_&lt;float,uint_32&gt; AtomicFloat; typedef atomic_float_&lt;double,uint_64&gt; AtomicDouble; </code></pre>
[ { "answer_id": 242178, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 2, "selected": false, "text": "sizeof(size_t) == sizeof(float)" }, { "answer_id": 242210, "author": "Greg Rogers", "author_id": 5963, "author_profile": "https://Stackoverflow.com/users/5963", "pm_score": 4, "selected": true, "text": "operator float()" }, { "answer_id": 242319, "author": "Robert Gould", "author_id": 15124, "author_profile": "https://Stackoverflow.com/users/15124", "pm_score": 1, "selected": false, "text": " #include <tbb/atomic.h>\n typedef unsigned int uint_32;\n typedef __TBB_LONG_LONG uint_64;\n\n template<typename FLOATING_POINT,typename MEMORY_BLOCK>\n struct atomic_float_\n {\n /* CRC Card -----------------------------------------------------\n | Class: atmomic float template class\n |\n | Responsability: handle integral atomic memory as it were a float,\n | but partially bypassing FPU, SSE/MMX, so it is\n | slower than a true float, but faster and smaller\n | than a locked float.\n | *Warning* If your float usage is thwarted by\n | the A-B-A problem this class isn't for you\n | *Warning* Atomic specification says we return,\n | values not l-values. So (i = j) = k doesn't work.\n |\n | Collaborators: intel's tbb::atomic handles memory atomicity\n ----------------------------------------------------------------*/\n typedef typename atomic_float_<FLOATING_POINT,MEMORY_BLOCK> self_t;\n\n tbb::atomic<MEMORY_BLOCK> atomic_value_;\n\n template<memory_semantics M>\n FLOATING_POINT fetch_and_store( FLOATING_POINT value ) \n {\n const MEMORY_BLOCK value_ = \n atomic_value_.tbb::atomic<MEMORY_BLOCK>::fetch_and_store<M>((MEMORY_BLOCK&)value);\n //atomic specification requires returning old value, not new one\n return reinterpret_cast<const FLOATING_POINT&>(value_);\n }\n\n FLOATING_POINT fetch_and_store( FLOATING_POINT value ) \n {\n const MEMORY_BLOCK value_ = \n atomic_value_.tbb::atomic<MEMORY_BLOCK>::fetch_and_store((MEMORY_BLOCK&)value);\n //atomic specification requires returning old value, not new one\n return reinterpret_cast<const FLOATING_POINT&>(value_);\n }\n\n template<memory_semantics M>\n FLOATING_POINT compare_and_swap( FLOATING_POINT value, FLOATING_POINT comparand ) \n {\n const MEMORY_BLOCK value_ = \n atomic_value_.tbb::atomic<MEMORY_BLOCK>::compare_and_swap<M>((MEMORY_BLOCK&)value,(MEMORY_BLOCK&)compare);\n //atomic specification requires returning old value, not new one\n return reinterpret_cast<const FLOATING_POINT&>(value_);\n }\n\n FLOATING_POINT compare_and_swap(FLOATING_POINT value, FLOATING_POINT compare)\n {\n const MEMORY_BLOCK value_ = \n atomic_value_.tbb::atomic<MEMORY_BLOCK>::compare_and_swap((MEMORY_BLOCK&)value,(MEMORY_BLOCK&)compare);\n //atomic specification requires returning old value, not new one\n return reinterpret_cast<const FLOATING_POINT&>(value_);\n }\n\n operator FLOATING_POINT() const volatile // volatile qualifier here for backwards compatibility \n {\n const MEMORY_BLOCK value_ = atomic_value_;\n return reinterpret_cast<const FLOATING_POINT&>(value_);\n }\n\n //Note: atomic specification says we return the a copy of the base value not an l-value\n FLOATING_POINT operator=(FLOATING_POINT rhs) \n {\n const MEMORY_BLOCK value_ = atomic_value_.tbb::atomic<MEMORY_BLOCK>::operator =((MEMORY_BLOCK&)rhs);\n return reinterpret_cast<const FLOATING_POINT&>(value_);\n }\n\n //Note: atomic specification says we return an l-value when operating among atomics\n self_t& operator=(self_t& rhs) \n {\n const MEMORY_BLOCK value_ = atomic_value_.tbb::atomic<MEMORY_BLOCK>::operator =((MEMORY_BLOCK&)rhs);\n return *this;\n }\n\n FLOATING_POINT& _internal_reference() const\n {\n return reinterpret_cast<FLOATING_POINT&>(atomic_value_.tbb::atomic<MEMORY_BLOCK>::_internal_reference());\n }\n\n FLOATING_POINT operator+=(FLOATING_POINT value)\n {\n FLOATING_POINT old_value_, new_value_;\n do\n {\n old_value_ = reinterpret_cast<FLOATING_POINT&>(atomic_value_);\n new_value_ = old_value_ + value;\n //floating point binary representation is not an issue because\n //we are using our self's compare and swap, thus comparing floats and floats\n } while(self_t::compare_and_swap(new_value_,old_value_) != old_value_);\n return (new_value_); //return resulting value\n }\n\n FLOATING_POINT operator*=(FLOATING_POINT value)\n {\n FLOATING_POINT old_value_, new_value_;\n do\n {\n old_value_ = reinterpret_cast<FLOATING_POINT&>(atomic_value_);\n new_value_ = old_value_ * value;\n //floating point binary representation is not an issue becaus\n //we are using our self's compare and swap, thus comparing floats and floats\n } while(self_t::compare_and_swap(new_value_,old_value_) != old_value_);\n return (new_value_); //return resulting value\n }\n\n FLOATING_POINT operator/=(FLOATING_POINT value)\n {\n FLOATING_POINT old_value_, new_value_;\n do\n {\n old_value_ = reinterpret_cast<FLOATING_POINT&>(atomic_value_);\n new_value_ = old_value_ / value;\n //floating point binary representation is not an issue because\n //we are using our self's compare and swap, thus comparing floats and floats\n } while(self_t::compare_and_swap(new_value_,old_value_) != old_value_);\n return (new_value_); //return resulting value\n }\n\n FLOATING_POINT operator-=(FLOATING_POINT value)\n {\n return this->operator+=(-value); //return resulting value\n }\n\n //Prefix operator\n FLOATING_POINT operator++()\n {\n return this->operator+=(1); //return resulting value\n }\n\n //Prefix operator\n FLOATING_POINT operator--() \n {\n return this->operator+=(-1); //return resulting value\n }\n\n //Postfix operator\n FLOATING_POINT operator++(int)\n {\n const FLOATING_POINT temp = this;\n this->operator+=(1);\n return temp//return resulting value\n }\n\n //Postfix operator\n FLOATING_POINT operator--(int) \n {\n const FLOATING_POINT temp = this;\n this->operator+=(1);\n return temp//return resulting value\n }\n\n FLOATING_POINT fetch_and_add( FLOATING_POINT addend ) \n {\n const FLOATING_POINT old_value_ = atomic_value_;\n this->operator+=(addend);\n //atomic specification requires returning old value, not new one as in operator x=\n return old_value_; \n }\n\n FLOATING_POINT fetch_and_increment() \n {\n const FLOATING_POINT old_value_ = atomic_value_;\n this->operator+=(+1);\n //atomic specification requires returning old value, not new one as in operator x=\n return old_value_; \n }\n\n FLOATING_POINT fetch_and_decrement() \n {\n const FLOATING_POINT old_value_ = atomic_value_;\n this->operator+=(-1);\n //atomic specification requires returning old value, not new one as in operator x=\n return old_value_; \n }\n };\n\n typedef atomic_float_<float,uint_32> AtomicFloat;\n typedef atomic_float_<double,uint_64> AtomicDouble;\n" }, { "answer_id": 242677, "author": "peterchen", "author_id": 31317, "author_profile": "https://Stackoverflow.com/users/31317", "pm_score": 1, "selected": false, "text": "1 + 1 = 1.70141e+038 \n100 + 1 = -1.46937e-037 \n100 + 0.01 = 1.56743e+038 \n23 + 42 = -1.31655e-036 \n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242172", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15124/" ]
242,177
<p>I understand object oriented programming, and have been writing OO programs for a long time. People seem to talk about aspect-oriented programming, but I've never really learned what it is or how to use it. What is the basic paradigm?</p> <p>This question is related, but doesn't quite ask it:</p> <p><a href="https://stackoverflow.com/questions/232884/aspect-oriented-programming-vs-object-oriented-programming">Aspect-Oriented Programming vs. Object Oriented Programming</a></p>
[ { "answer_id": 242194, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 9, "selected": true, "text": "function mainProgram()\n{ \n var x = foo();\n doSomethingWith(x);\n return x;\n}\n\naspect logging\n{ \n before (mainProgram is called):\n { \n log.Write(\"entering mainProgram\");\n }\n\n after (mainProgram is called):\n { \n log.Write( \"exiting mainProgram with return value of \"\n + mainProgram.returnValue);\n }\n } \n\naspect verification\n{ \n before (doSomethingWith is called):\n { \n if (doSomethingWith.arguments[0] == null) \n { \n throw NullArgumentException();\n }\n\n if (!doSomethingWith.caller.isAuthenticated)\n { \n throw Securityexception();\n }\n }\n }\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31952/" ]
242,181
<p>I have a form with several checkboxes which values are pulled from a database. I managed to display them in the form, assign an appropriate value to each, but cannot insert their values into other database.</p> <p>Here's the code:</p> <pre><code>&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;&gt; &lt;?php $info_id = $_GET['info_id']; $kv_dodatoci = mysql_query(&quot;SELECT * FROM `dodatoci`&quot;) or die('ERROR DISPLAYING: ' . mysql_error()); while ($kol = mysql_fetch_array($kv_dodatoci)){ $id_dodatoci = $kol['id_dodatoci']; $mk = $kol['mk']; echo '&lt;input type=&quot;checkbox&quot; name=&quot;id_dodatoci[]&quot; id=&quot;id_dodatoci&quot; value=&quot;' . $id_dodatoci . '&quot; /&gt;'; echo '&lt;label for=&quot;' . $id_dodatoci.'&quot;&gt;' . $mk . '&lt;/label&gt;&lt;br /&gt;'; } ?&gt; &lt;input type=&quot;hidden&quot; value=&quot;&lt;?=$info_id?&gt;&quot; name=&quot;info_id&quot; /&gt; &lt;input name=&quot;insert_info&quot; type=&quot;submit&quot; value=&quot;Insert Additional info&quot; /&gt; &lt;/form&gt; &lt;?php if (isset($_POST['insert_info']) &amp;&amp; is_array($id_dodatoci)) { echo $id_dodatoci . '&lt;br /&gt;'; echo $mk . '&lt;br /&gt;'; // --- Guess here's the problem ----- // foreach ($_POST['id_dodatoci'] as $dodatok) { $dodatok_kv = mysql_query(&quot;INSERT INTO `dodatoci_hotel` (id_dodatoci, info_id) VALUES ('$dodatok', '$info_id')&quot;) or die('ERROR INSERTING: '.mysql_error()); } } </code></pre> <p>My problem is to loop through all checkboxes, and for each checked, populate a separate record in a database. Actually I don't know how to recognize the which box is checked, and put the appropriate value in db.</p>
[ { "answer_id": 242215, "author": "Eli", "author_id": 27580, "author_profile": "https://Stackoverflow.com/users/27580", "pm_score": 2, "selected": false, "text": "<input type='checkbox' name='ShowCloseWindowLink' value='1'/> Show the 'Close Window' link at the bottom of the form.\n" }, { "answer_id": 242562, "author": "bastiandoeen", "author_id": 371953, "author_profile": "https://Stackoverflow.com/users/371953", "pm_score": 0, "selected": false, "text": "<input type=\"checkbox\" name=\"my_checkbox[<?=$id_of_checkbox?>]\">\n<input type=\"hidden\" name=\"array_checkboxes[<?=$id_of_checkbox?>]\" value=\"is_on_page\">\n" }, { "answer_id": 242782, "author": "Ryan McCue", "author_id": 2575, "author_profile": "https://Stackoverflow.com/users/2575", "pm_score": 0, "selected": false, "text": "<label>" }, { "answer_id": 244535, "author": "Eli", "author_id": 27580, "author_profile": "https://Stackoverflow.com/users/27580", "pm_score": 0, "selected": false, "text": "echo '<input type=\"checkbox\" name=\"id_dodatoci[]\" value=\"'.$id_dodatoci.'\" />';\n" }, { "answer_id": 244954, "author": "Bertrand Gorge", "author_id": 30955, "author_profile": "https://Stackoverflow.com/users/30955", "pm_score": -1, "selected": false, "text": "<input type=\"hidden\" name=\"my_checkbox\" value=\"N\" />\n<input type=\"checkbox\" name=\"my_checkbox\" value=\"Y\" />\n" }, { "answer_id": 245552, "author": "dede", "author_id": 432217, "author_profile": "https://Stackoverflow.com/users/432217", "pm_score": 0, "selected": false, "text": "$i" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
242,182
<p>I have a page with a "Print" link that takes the user to a printer-friendly page. The client wants a print dialog box to appear automatically when the user arrives at the print-friendly page. How can I do this with javascript?</p>
[ { "answer_id": 242190, "author": "Mark", "author_id": 26310, "author_profile": "https://Stackoverflow.com/users/26310", "pm_score": 9, "selected": true, "text": "window.print(); \n" }, { "answer_id": 242192, "author": "mmiika", "author_id": 6846, "author_profile": "https://Stackoverflow.com/users/6846", "pm_score": 6, "selected": false, "text": "<body onload=\"window.print()\">\n...\n</body>\n" }, { "answer_id": 242200, "author": "Eli", "author_id": 27580, "author_profile": "https://Stackoverflow.com/users/27580", "pm_score": 3, "selected": false, "text": "<a href=\"javascript:alert('Please be sure to set your printer to Landscape.');window.print();\">Print Me...</a>\n" }, { "answer_id": 17352555, "author": "Daryl H", "author_id": 2088442, "author_profile": "https://Stackoverflow.com/users/2088442", "pm_score": 5, "selected": false, "text": "function printPage() {\n var w = window.open();\n\n var headers = $(\"#headers\").html();\n var field= $(\"#field1\").html();\n var field2= $(\"#field2\").html();\n\n var html = \"<!DOCTYPE HTML>\";\n html += '<html lang=\"en-us\">';\n html += '<head><style></style></head>';\n html += \"<body>\";\n\n //check to see if they are null so \"undefined\" doesnt print on the page. <br>s optional, just to give space\n if(headers != null) html += headers + \"<br/><br/>\";\n if(field != null) html += field + \"<br/><br/>\";\n if(field2 != null) html += field2 + \"<br/><br/>\";\n\n html += \"</body>\";\n w.document.write(html);\n w.window.print();\n w.document.close();\n};\n" }, { "answer_id": 38635307, "author": "Limitless isa", "author_id": 1256632, "author_profile": "https://Stackoverflow.com/users/1256632", "pm_score": -1, "selected": false, "text": " mywindow.print();\n" }, { "answer_id": 47117332, "author": "thestar", "author_id": 2418867, "author_profile": "https://Stackoverflow.com/users/2418867", "pm_score": 2, "selected": false, "text": "window.print();\n" }, { "answer_id": 56296607, "author": "Dan Sinclair", "author_id": 1304050, "author_profile": "https://Stackoverflow.com/users/1304050", "pm_score": 3, "selected": false, "text": "<a href=\"javascript:window.print();\">Print Page</a>\n" }, { "answer_id": 58851876, "author": "James Heffer", "author_id": 3656152, "author_profile": "https://Stackoverflow.com/users/3656152", "pm_score": 2, "selected": false, "text": "@inject IJSRuntime JSRuntime\n" }, { "answer_id": 70298748, "author": "John Nico Novero", "author_id": 9923490, "author_profile": "https://Stackoverflow.com/users/9923490", "pm_score": 0, "selected": false, "text": "<script>\n const _print = () => {\n window.print();\n }\n</script>\n" }, { "answer_id": 73668592, "author": "dvicemuse", "author_id": 1155184, "author_profile": "https://Stackoverflow.com/users/1155184", "pm_score": 0, "selected": false, "text": "/*\n Example:\n <a href=\"//example.com\" class=\"print-url\">Print</a>\n*/\n\n//LISTEN FOR PRINT URL ITEMS TO BE CLICKED\n$(document).off('click.PrintUrl').on('click.PrintUrl', '.print-url', function(e){\n\n //PREVENT OTHER CLICK EVENTS FROM PROPAGATING\n e.preventDefault();\n\n //TRY TO ASK THE URL TO TRIGGER A PRINT DIALOGUE BOX\n printUrl($(this).attr('href'));\n});\n\n//TRIGGER A PRINT DIALOGE BOX FROM A URL\nfunction printUrl(url) { \n\n //CREATE A HIDDEN IFRAME AND APPEND IT TO THE BODY THEN WAIT FOR IT TO LOAD\n $('<iframe src=\"'+url+'\"></iframe>').hide().appendTo('body').on('load', function(){\n \n var oldTitle = $(document).attr('title'); //GET THE ORIGINAL DOCUMENT TITLE\n var that = $(this); //STORE THIS IFRAME AS A VARIABLE \n var title = $(that).contents().find('title').text(); //GET THE IFRAME TITLE\n $(that).focus(); //CALL THE IFRAME INTO FOCUS (FOR OLDER BROWSERS) \n\n //SET THE DOCUMENT TITLE FROM THE IFRAME (THIS NAMES THE DOWNLOADED FILE)\n if(title && title.length) $(document).attr('title', title);\n \n //TRIGGER THE IFRAME TO CALL THE PRINT\n $(that)[0].contentWindow.print();\n\n //LISTEN FOR THE PRINT DIALOGUE BOX TO CLOSE\n $(window).off('focus.PrintUrl').on('focus.PrintUrl', function(e){\n e.stopPropagation(); //PREVENT OTHER WINDOW FOCUS EVENTS FROM RUNNING \n $(that).remove(); //GET RID OF THE IFRAME\n if(title && title.length) $(document).attr('title', oldTitle); //RESET THE PAGE TITLE\n $(window).off('focus.PrintUrl'); //STOP LISTENING FOR WINDOW FOCUS\n });\n }); \n};\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242182", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
242,255
<p>If I have class names such as "left", "right", "clear" and xhtml like</p> <pre><code>&lt;a href="index.php" class="right continueLink"&gt;Continue&lt;/a&gt; </code></pre> <p>With CSS like</p> <pre><code>.right { float: right; } </code></pre> <p>I know it's not a semantic name, but it does make things much easier sometimes.</p> <p>Anyway, what are your thoughts?</p>
[ { "answer_id": 242277, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 5, "selected": true, "text": ".right" }, { "answer_id": 242325, "author": "eyelidlessness", "author_id": 17964, "author_profile": "https://Stackoverflow.com/users/17964", "pm_score": 2, "selected": false, "text": ".right" }, { "answer_id": 242705, "author": "Hauge", "author_id": 17368, "author_profile": "https://Stackoverflow.com/users/17368", "pm_score": 0, "selected": false, "text": "float:right" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31671/" ]
242,264
<p>I am digging into LINQ--trying to understand basic models (it seems pretty cool to me). The code below is the code to perform before committing an update. </p> <pre><code> Linq01.Account acc = context.Accounts.Single( pc =&gt; pc.AccountID == AccountID ); acc.Name = textboxAccountNameRead.Text.Trim(); context.SubmitChanges(); </code></pre> <p>So far, so good. But what do you do if the Single() method failed--if the account ID wasn't found? </p> <p>Thank you!</p>
[ { "answer_id": 242266, "author": "Aaron Powell", "author_id": 11388, "author_profile": "https://Stackoverflow.com/users/11388", "pm_score": 4, "selected": true, "text": "SingleOrDefault" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2536/" ]
242,276
<p>I have an embedded flash that is transparent so it looks like part of the background. I achieved that by setting wmode to transparent.</p> <p>My problem is that the area underneath the flash becomes inaccessible, even though the flash is transparent. Therefore I cannot click on any links or buttons that are under the flash object.</p> <p>How do I make the flash unobtrusive?</p> <p>Clarifications: <br> - the flash is transparent but it has an animation that shows in the background.<br> - wmode set to transparent lets you click the contents underneath in IE but not Firefox.</p>
[ { "answer_id": 242308, "author": "joelhardi", "author_id": 11438, "author_profile": "https://Stackoverflow.com/users/11438", "pm_score": 4, "selected": true, "text": "object" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/131/" ]
242,282
<p>Are there any html helpers for page navigation. eg. if i have 1000 records to display, i want to display the Previous 1 2 3 4 ... etc Next link stuff under the filtered collection.</p> <p>Anyone know of anything out there?</p>
[ { "answer_id": 249367, "author": "µBio", "author_id": 9796, "author_profile": "https://Stackoverflow.com/users/9796", "pm_score": 0, "selected": false, "text": "public string Render()\n{\n var buffer = new StringBuilder( 1000 );\n buffer.AppendLine( @\"<ul class=\"\"datatable_pager\"\">\" )\n .AppendLine( \"\\t<li>Additional Pages:</li>\" );\n int numberOfPages = TotalItemCount % PageSize == 0 ? TotalItemCount / PageSize : TotalItemCount / PageSize + 1;\n\n for( int i = 0; i < numberOfPages; i++ )\n {\n AppendPageLink( buffer, i );\n }\n\n buffer.AppendLine( \"\\t</ul>\" );\n AppendPagingJS( buffer );\n\n return buffer.ToString( );\n}\n\nprivate void AppendPageLink( StringBuilder buffer, int i )\n{\n buffer.Append( \"\\t\\t<li><a href=\\\"\" )\n .Append( PagingLink.Replace( \"$PAGE$\", i.ToString( ) ) )\n .Append( \"\\\">\" )\n .Append( i.ToString( ) )\n .Append( \"</a>\" )\n .AppendLine( \"\\t\\t</li>\" );\n}\n\n\nprivate void AppendPagingJS( StringBuilder buffer )\n{\n buffer.AppendLine( @\"\n <script type=\"\"text/javascript\"\">\n function page( page, size, updateElement )\n {\n $.post( '\" + PagingUrl + @\"',\n {\n pageNumber: page, \n pageSize: size,\n },\n function(response) \n {\n $(\"\"#\"\" + updateElement).html(response);\n },\n \"\"html\"\"\n );\n }\n </script>\" );\n}\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242282", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30674/" ]
242,284
<p>While surfing, I came to know that somebody has done Tower of Hanoi using vim. WOW!!!</p> <p>Can you people share what all cool things you have been doing in vim.</p> <p>Edit: Not sure about the Tower of Hanoi solution using vim being all that useful. But I think this question should be re-opened to allow people to comment on any useful things that they've done using vim. For me? See my answer below. (-:</p>
[ { "answer_id": 245329, "author": "Diomidis Spinellis", "author_id": 20520, "author_profile": "https://Stackoverflow.com/users/20520", "pm_score": 3, "selected": false, "text": "system \"$vimrt\\\\gvim.exe\", qq{ \n -c \"edit /tmp/tmpcode.$ext \" \n -c \"source $vimrt/syntax/2html.vim\" \n -c \"write! /tmp/tmpcode.html\" \n -c \"qa!\"};\n" }, { "answer_id": 245971, "author": "Adam Liss", "author_id": 29157, "author_profile": "https://Stackoverflow.com/users/29157", "pm_score": 3, "selected": false, "text": "vim" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29405/" ]
242,286
<p>Mine would have to be the float and margin bugs...</p> <p>If you float an element, and then specify a margin for it, it will double the margin.</p> <p>The solution to this is to add <code>display: inline</code> to the element. This will stop the double margin, and all other browsers will ignore it because only block level objects can be floated.</p>
[ { "answer_id": 358172, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 2, "selected": false, "text": "<td><img src=\"myimage.jpg\"></td>\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31671/" ]
242,295
<blockquote> <p><strong>EDIT</strong>: This question duplicates <a href="https://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number#111173">How to access the current Subversion build number?</a> (Thanks for the heads up, Charles!)</p> </blockquote> <p>Hi there,</p> <p>This question is similar to <a href="https://stackoverflow.com/questions/16248/getting-the-subversion-repository-number-into-code">Getting the subversion repository number into code</a></p> <p>The differences being:</p> <ol> <li><p>I would like to add the revision number to Python</p></li> <li><p>I want the revision of the repository (not the checked out file)</p></li> </ol> <p>I.e. I would like to extract the Revision number from the return from 'svn info', likeso:</p> <p>$ svn info</p> <pre><code>Path: . URL: svn://localhost/B/trunk Repository Root: svn://localhost/B Revision: 375 Node Kind: directory Schedule: normal Last Changed Author: bmh Last Changed Rev: 375 Last Changed Date: 2008-10-27 12:09:00 -0400 (Mon, 27 Oct 2008) </code></pre> <p>I want a variable with 375 (the Revision). It's easy enough with put $Rev$ into a variable to keep track of changes on a file. However, I would like to keep track of the repository's version, and I understand (and it seems based on my tests) that $Rev$ only updates when the file changes.</p> <p>My initial thoughts turn to using the svn/libsvn module built in to Python, though I can't find any documentation on or examples of how to use them.</p> <p>Alternatively, I've thought calling 'svn info' and regex'ing the code out, though that seems rather brutal. :)</p> <p>Help would be most appreciated.</p> <p>Thanks &amp; Cheers.</p>
[ { "answer_id": 242327, "author": "Jerub", "author_id": 14648, "author_profile": "https://Stackoverflow.com/users/14648", "pm_score": 1, "selected": false, "text": "svnRev=$(echo \"$(svn info)\" | grep \"^Revision\" | awk -F\": \" '{print $2};')\necho $svnRev\n" }, { "answer_id": 242508, "author": "JesperE", "author_id": 13051, "author_profile": "https://Stackoverflow.com/users/13051", "pm_score": 2, "selected": false, "text": "from svn import fs, repos, core\nrepository = repos.open(root_path)\nfs_ptr = repos.fs(repository)\nyoungest_revision_number = fs.youngest_rev(fs_ptr)\n" }, { "answer_id": 242515, "author": "CesarB", "author_id": 28258, "author_profile": "https://Stackoverflow.com/users/28258", "pm_score": 3, "selected": true, "text": "svnversion" }, { "answer_id": 243088, "author": "pobk", "author_id": 7829, "author_profile": "https://Stackoverflow.com/users/7829", "pm_score": 2, "selected": false, "text": "def get_svn_revision(path=None):\n rev = None\n if path is None:\n path = MODULE.__path__[0]\n entries_path = '%s/.svn/entries' % path\n\n if os.path.exists(entries_path):\n entries = open(entries_path, 'r').read()\n # Versions >= 7 of the entries file are flat text. The first line is\n # the version number. The next set of digits after 'dir' is the revision.\n if re.match('(\\d+)', entries):\n rev_match = re.search('\\d+\\s+dir\\s+(\\d+)', entries)\n if rev_match:\n rev = rev_match.groups()[0]\n # Older XML versions of the file specify revision as an attribute of\n # the first entries node.\n else:\n from xml.dom import minidom\n dom = minidom.parse(entries_path)\n rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')\n\n if rev:\n return u'SVN-%s' % rev\n return u'SVN-unknown'\n" }, { "answer_id": 245505, "author": "Brian M. Hunt", "author_id": 19212, "author_profile": "https://Stackoverflow.com/users/19212", "pm_score": 0, "selected": false, "text": "try:\n from subprocess import Popen, PIPE\n _p = Popen([\"svnversion\", \".\"], stdout=PIPE)\n REVISION= _p.communicate()[0]\n _p = None # otherwise we get a wild exception when Django auto-reloads\nexcept Exception, e:\n print \"Could not get revision number: \", e\n REVISION=\"Unknown\"\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19212/" ]
242,304
<p>I'm running Windows Server 2008 64-bit "workstation" and would like to get <a href="http://msdn.microsoft.com/en-us/library/ms164699%28v=vs.80%29.aspx" rel="nofollow noreferrer">corflags.exe</a>. Which SDK do I need to download? </p> <p>I know about <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=1AEF6FCE-6E06-4B66-AFE4-9AAD3C835D3D&amp;displaylang=en#Overview" rel="nofollow noreferrer">.NET Framework 2.0 Software Development Kit (SDK) (x64)</a> and <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&amp;displaylang=en" rel="nofollow noreferrer">Windows SDK for Windows Server 2008 and .NET Framework 3.5</a> but I was hoping to find something smaller as these are quite large downloads.</p> <p>Also the note about 2.0 SDK seems to suggest to download the 3.5 one, should I follow that?</p>
[ { "answer_id": 2456723, "author": "antiplex", "author_id": 294930, "author_profile": "https://Stackoverflow.com/users/294930", "pm_score": 3, "selected": false, "text": "coreflags.exe" }, { "answer_id": 45020509, "author": "langlauf.io", "author_id": 4480139, "author_profile": "https://Stackoverflow.com/users/4480139", "pm_score": 0, "selected": false, "text": "choco install windows-sdk-10.1\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242304", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6846/" ]
242,314
<p>Using gnuplot 4.2, is it possible to obtain the value of a specific column/row and use that value somehow?</p> <p>For example, let's say my datafile contains the following</p> <pre><code>#1 2 7 13 5 11 23 17 53 12 </code></pre> <p>For a simple plot where column 1 is the x axis and column 2 is the y axis I would:-</p> <pre><code>plot 'datafile' using 1:2 </code></pre> <p>What I'm trying to do is to normalize the all data in column 2 by the first element in that column (13). Is there a way to do this in gnuplot itself (i.e., without resorting to a scripting language or something to preprocess the data first)?</p> <p>Cheers</p>
[ { "answer_id": 28361017, "author": "Jonatan Lindén", "author_id": 167319, "author_profile": "https://Stackoverflow.com/users/167319", "pm_score": 3, "selected": false, "text": "base" }, { "answer_id": 71218187, "author": "Vikram Govindarajan", "author_id": 10584300, "author_profile": "https://Stackoverflow.com/users/10584300", "pm_score": 1, "selected": false, "text": "stats" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242314", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11688/" ]
242,320
<p>Is there a way to bind a Generic List to a multicolumn listbox, yes listbox...I know but this is what I am stuck with and can't add a grid or listview.</p> <p>Thanks</p>
[ { "answer_id": 242408, "author": "Alexander Prokofyev", "author_id": 11256, "author_profile": "https://Stackoverflow.com/users/11256", "pm_score": 3, "selected": true, "text": "List<int> list = new List<int> { 1, 2, 4, 8, 16 };\nlistBox1.DataSource = list;\n" }, { "answer_id": 1372200, "author": "AMissico", "author_id": 163921, "author_profile": "https://Stackoverflow.com/users/163921", "pm_score": 1, "selected": false, "text": "UseCustomTabOffsets" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23667/" ]
242,341
<p>I'm writing a utility to export evernote notes into Outlook on a schedule. The Outlook API's need plain text, and Evernote outputs a XHTML doc version of the plain text note. What I need is to strip out all the Tags and unescape the source XHTML doc embedded in the Evernote export file.</p> <p>Basically I need to turn;</p> <pre><code>&lt;note&gt; &lt;title&gt;Test Sync Note 1&lt;/title&gt; &lt;content&gt; &lt;![CDATA[ &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml.dtd"&gt; &lt;en-note bgcolor="#FFFFFF"&gt; &lt;div&gt;Test Sync Note 1&lt;/div&gt; &lt;div&gt;This i has some text in it&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;and a second line&lt;/div&gt; &lt;/en-note&gt; ]]&gt; &lt;/content&gt; &lt;created&gt;20081028T045727Z&lt;/created&gt; &lt;updated&gt;20081028T051346Z&lt;/updated&gt; &lt;tag&gt;Test&lt;/tag&gt; &lt;/note&gt; </code></pre> <p>Into </p> <pre> Test Sync Note 1 This i has some text in it and a second line </pre> <p>I can easily parse out the CDATA section and get just the 4 lines of text, but I need a reliable way to strip the div's, unescape and deal with any extra HTML that might have snuck in there.</p> <p>I'm assuming that there's some MS API combo that will do the job, but I don't know it.</p>
[ { "answer_id": 242379, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 0, "selected": false, "text": " string xml = @\"<note>\n <title>Test Sync Note 1</title> \n <content>\n <![CDATA[ <?xml version=\"\"1.0\"\" encoding=\"\"UTF-8\"\"?>\n <!DOCTYPE en-note SYSTEM \"\"http://xml.evernote.com/pub/enml.dtd\"\">\n\n <en-note bgcolor=\"\"#FFFFFF\"\">\n <div>Test Sync Note 1</div>\n <div>This i has some text in it</div>\n <div> </div>\n <div> </div>\n <div>and a second line</div>\n </en-note>\n\n ]]> \n </content>\n <created>20081028T045727Z</created> \n <updated>20081028T051346Z</updated> \n <tag>Test</tag> \n </note>\n \";\n XPathDocument doc = new XPathDocument(new StringReader(xml));\n XPathNavigator nav = doc.CreateNavigator();\n\n // Compile a standard XPath expression\n\n XPathExpression expr;\n expr = nav.Compile(\"/note/content\");\n XPathNodeIterator iterator = nav.Select(expr);\n\n // Iterate on the node set\n\n try\n {\n while (iterator.MoveNext())\n {\n //Get the XML in the CDATA\n XPathNavigator nav2 = iterator.Current.Clone();\n XPathDocument doc2 = new XPathDocument(new StringReader(nav2.Value.Trim()));\n\n //Parse the XML in the CDATA\n XPathNavigator nav3 = doc2.CreateNavigator();\n expr = nav3.Compile(\"/en-note\");\n XPathNodeIterator iterator2 = nav3.Select(expr);\n iterator2.MoveNext();\n XPathNavigator nav4 = iterator2.Current.Clone();\n\n //Output the value directly, does not preserve the formatting\n Console.WriteLine(\"Direct Try:\");\n Console.WriteLine(nav4.Value);\n\n //This works, but is ugly\n Console.WriteLine(\"Ugly Try:\");\n Console.WriteLine(nav4.InnerXml.Replace(\"<div>\",\"\").Replace(\"</div>\",Environment.NewLine));\n }\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex.Message);\n }\n" }, { "answer_id": 242451, "author": "Xian", "author_id": 4642, "author_profile": "https://Stackoverflow.com/users/4642", "pm_score": 1, "selected": false, "text": "Regex.Replace(\"<div>your html in here</div>\",@\"<(.|\\n)*?>\",string.Empty)" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
242,344
<p>I want this page to return 200 whilst still sending the redirect...</p> <pre><code>&lt;script&gt; sub page_load 'Get the parameters dim content As String content = request.querystring("text") response.redirect ("http://100.200.100.10/test1/Default.aspx?CommandParm=" + content) end sub &lt;/script&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;form runat="server"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
[ { "answer_id": 242358, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 0, "selected": false, "text": "Response.Redirect()" }, { "answer_id": 242370, "author": "Ray Lu", "author_id": 11413, "author_profile": "https://Stackoverflow.com/users/11413", "pm_score": 1, "selected": false, "text": "<script type\"text/javascript\">\n<!--\nfunction redirect()\n{\n window.location = \"http://100.200.100.10/test1/Default.aspx?CommandParm=\" + content\n}\n//-->\n</script>\n" }, { "answer_id": 242719, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 2, "selected": false, "text": "<meta http-equiv=\"refresh\" content=\"5;url=http://example.com/\"/>\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
242,363
<p>I want create a drop shadow around the canvas component in flex. Technically speaking it will not be a shadow, as I want it to wrap around the component giving the component a floating look. I may be able to do it with glow, but can anyone drop an line or two who has already done it?</p> <p>Thanks in advance.</p>
[ { "answer_id": 242373, "author": "Mozammel", "author_id": 20165, "author_profile": "https://Stackoverflow.com/users/20165", "pm_score": 3, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<mx:Canvas xmlns:mx=\"http://www.adobe.com/2006/mxml\" \n width=\"780\" height=\"100%\" borderStyle=\"solid\" borderColor=\"gray\"\n creationComplete=\"init();\" backgroundColor=\"white\">\n\n <mx:Script>\n <![CDATA[\n import mx.styles.StyleManager;\n\n\n private function init():void {\n var glow:GlowFilter = new GlowFilter();\n glow.color = StyleManager.getColorName(\"gray\");\n glow.alpha = 0.8;\n glow.blurX = 4;\n glow.blurY = 4;\n glow.strength = 6;\n glow.quality = BitmapFilterQuality.HIGH;\n\n this.filters = [glow];\n }\n ]]>\n </mx:Script>\n\n\n\n</mx:Canvas>\n" }, { "answer_id": 242392, "author": "eyelidlessness", "author_id": 17964, "author_profile": "https://Stackoverflow.com/users/17964", "pm_score": 2, "selected": false, "text": "DropShadowFilter" }, { "answer_id": 251623, "author": "Ben Throop", "author_id": 27899, "author_profile": "https://Stackoverflow.com/users/27899", "pm_score": 0, "selected": false, "text": "<mx:Application xmlns:mx=\"http://www.adobe.com/2006/mxml\" \n width=\"780\" height=\"100%\">\n\n <mx:Canvas filters=\"[dropShadow]\" width=\"200\" height=\"200\" backgroundColor=\"white\"/>\n <mx:DropShadowFilter id=\"dropShadow\" distance=\"0\"/>\n\n</mx:Application>\n" }, { "answer_id": 4318662, "author": "Willtriv", "author_id": 525735, "author_profile": "https://Stackoverflow.com/users/525735", "pm_score": 2, "selected": false, "text": " <fx:Declarations>\n <s:GlowFilter\n id=\"glowBlack\"\n alpha=\".6\"\n color=\"0x000000\"\n inner=\"false\"\n blurX=\"10\"\n blurY=\"10\"\n quality = \"2\"\n\n />\n" }, { "answer_id": 8784430, "author": "Scott Evernden", "author_id": 11397, "author_profile": "https://Stackoverflow.com/users/11397", "pm_score": 0, "selected": false, "text": "<mx:Canvas ... dropShadowEnabled=\"true\" shadowDirection=\"right\">\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20165/" ]
242,367
<p>I am developing iPhone application and In that application I've one <code>TableViewController</code>, and that <code>TableViewController</code> made up of Custom table cell.<br> into those cell I am loading image from URL, but the <code>scrolling</code> is not that smooth, (because each cell load images every time when scrolling happen).</p> <p>So I decided to store those images into application document folder, but I don't know how to use document folder in iPhone when application is in running state.</p> <p>Any suggestion?</p> <p>And on other forums I found that SQLITE has blob datatype to store binary data,</p> <p>Which method is efficient, document folder or sqlite to store image?</p>
[ { "answer_id": 242528, "author": "leonho", "author_id": 30883, "author_profile": "https://Stackoverflow.com/users/30883", "pm_score": 0, "selected": false, "text": "NSFileManager" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/451867/" ]
242,383
<p>I want to autowire a bean partially - that is, I want some args to be autowired but other to be explicitly set. For example:</p> <p>public MyClient(Service svc, boolean b)</p> <p>In the case of this constructor, I would like to specify in my xml the value for b, but have svc autowired. Is that possible?</p> <p>Thanks, Lowell</p>
[ { "answer_id": 242443, "author": "NR.", "author_id": 11701, "author_profile": "https://Stackoverflow.com/users/11701", "pm_score": 2, "selected": false, "text": "public MyClient() {}\n\n@Autowired\npublic setService (Service svc) {...}\n\npublic setBoolean (boolean b) {...}\n" }, { "answer_id": 245347, "author": "lowellk", "author_id": 22063, "author_profile": "https://Stackoverflow.com/users/22063", "pm_score": 2, "selected": false, "text": "<bean class=\"MyClient\" autowire=\"constructor\">\n <constructor-arg index=\"1\">...</constructor-arg>\n<bean>\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22063/" ]
242,393
<p>I have the following classes</p> <pre><code>public interface InterfaceBase { } public class ImplementA:InterfaceBase { } public class ImplementB:InterfaceBase { } public void TestImplementType&lt;T&gt;(T obj) where T: InterfaceBase { } </code></pre> <p>How to infer what the T is whether ImplementA or ImplementB? I tried to use </p> <pre><code>typeof(T) is ImplementA </code></pre> <p>but this expression is always evaluated to false. </p> <p>Edit: And how am I going to cast obj to ImplementA or ImplementB?</p>
[ { "answer_id": 242395, "author": "Toby", "author_id": 291137, "author_profile": "https://Stackoverflow.com/users/291137", "pm_score": 3, "selected": true, "text": "obj is ImplementA" }, { "answer_id": 242396, "author": "Andrew Stapleton", "author_id": 28506, "author_profile": "https://Stackoverflow.com/users/28506", "pm_score": 0, "selected": false, "text": " if(obj.GetType().Equals(typeof(ImplementA)))\n {\n // ...\n }\n" }, { "answer_id": 242397, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "typeof(T)" }, { "answer_id": 242402, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": false, "text": " bool testObj = obj is ImplementA;\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242393", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
242,404
<p>Four 2D points in an array. I need to sort them in clockwise order. I think it can be done with just one swap operation but I have not been able to put this down formally.</p> <p><strike>Edit: The four points are a convex polygon in my case.</strike></p> <p>Edit: The four points are the vertices of a convex polygon. They need not be in order.</p>
[ { "answer_id": 242469, "author": "Agnel Kurian", "author_id": 45603, "author_profile": "https://Stackoverflow.com/users/45603", "pm_score": 0, "selected": false, "text": "// Take signed area of ABC.\n// If negative,\n// Swap B and C.\n// Otherwise,\n// Take signed area of ACD.\n// If negative, swap C and D.\n" }, { "answer_id": 242473, "author": "Wedge", "author_id": 332, "author_profile": "https://Stackoverflow.com/users/332", "pm_score": 1, "selected": false, "text": "x>0\n AND y >= 0\n angle = arctan(y/x)\n AND y < 0\n angle = arctan(y/x) + 2*pi\nx==0\n AND y >= 0\n angle = 0\n AND y < 0\n angle = 3*pi/2\nx<0\n angle = arctan(y/x) + pi\n" }, { "answer_id": 242509, "author": "SmacL", "author_id": 22564, "author_profile": "https://Stackoverflow.com/users/22564", "pm_score": 3, "selected": false, "text": "int side(double x1,double y1,double x2,double y2,double px,double py)\n{\n double dx1,dx2,dy1,dy2;\n double o;\n\n dx1 = x2 - x1;\n dy1 = y2 - y1;\n dx2 = px - x1;\n dy2 = py - y1;\n o = (dx1*dy2)-(dy1*dx2);\n if (o > 0.0) return(LEFT_SIDE);\n if (o < 0.0) return(RIGHT_SIDE);\n return(COLINEAR);\n}\n" }, { "answer_id": 242526, "author": "vmarquez", "author_id": 10740, "author_profile": "https://Stackoverflow.com/users/10740", "pm_score": -1, "selected": false, "text": "centerPonintX = Min(x) + ( (Max(x) – Min(x)) / 2 )\ncenterPonintY = Min(y) + ( (Max(y) – Min(y)) / 2 )\n" }, { "answer_id": 242710, "author": "Menkboy", "author_id": 29539, "author_profile": "https://Stackoverflow.com/users/29539", "pm_score": -1, "selected": false, "text": "if( (p2.x-p1.x)*(p3.y-p1.y) > (p3.x-p1.x)*(p2.y-p1.y) )\n swap( &p1, &p3 );\n" }, { "answer_id": 242740, "author": "Pablo Retyk", "author_id": 30729, "author_profile": "https://Stackoverflow.com/users/30729", "pm_score": 0, "selected": false, "text": " class Point : IComparable<Point>\n {\n public int X { set; get; }\n public int Y { set; get; }\n\n public double Angle\n {\n get\n {\n return Math.Atan2(X, Y);\n }\n }\n\n #region IComparable<Point> Members\n\n public int CompareTo(Point other)\n {\n return this.Angle.CompareTo(other.Angle);\n }\n\n #endregion\n\n public static List<Point> Sort(List<Point> points)\n {\n return points.Sort();\n }\n}\n" }, { "answer_id": 245079, "author": "Oliver Hallam", "author_id": 19995, "author_profile": "https://Stackoverflow.com/users/19995", "pm_score": 5, "selected": true, "text": "A B C D\nB C D A\nC D A B\nD A B C\n" }, { "answer_id": 245659, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 0, "selected": false, "text": "if AB crosses CD\n swap B,C\nelif AD crosses BC\n swap C,D\n\nif area (ABC) > 0\n swap B,D\n\n(I mean area(ABC) > 0 when A->B->C is counter-clockwise).\nLet p*x + q*y + r = 0 be the straight line that joins A and B.\nThen AB crosses CD if p*Cx + q*Cy + r and p*Dx + q*Dy + r\nhave different sign, i.e. their product is negative.\n" }, { "answer_id": 246063, "author": "Agnel Kurian", "author_id": 45603, "author_profile": "https://Stackoverflow.com/users/45603", "pm_score": 2, "selected": false, "text": "#include <cstdio>\n#include <algorithm>\n\nstruct PointF {\n float x;\n float y;\n};\n\n// Returns the z-component of the cross product of a and b\ninline double CrossProductZ(const PointF &a, const PointF &b) {\n return a.x * b.y - a.y * b.x;\n}\n\n// Orientation is positive if abc is counterclockwise, negative if clockwise.\n// (It is actually twice the area of triangle abc, calculated using the\n// Shoelace formula: http://en.wikipedia.org/wiki/Shoelace_formula .)\ninline double Orientation(const PointF &a, const PointF &b, const PointF &c) {\n return CrossProductZ(a, b) + CrossProductZ(b, c) + CrossProductZ(c, a);\n}\n\nvoid Sort4PointsClockwise(PointF points[4]){\n PointF& a = points[0];\n PointF& b = points[1];\n PointF& c = points[2];\n PointF& d = points[3];\n\n if (Orientation(a, b, c) < 0.0) {\n // Triangle abc is already clockwise. Where does d fit?\n if (Orientation(a, c, d) < 0.0) {\n return; // Cool!\n } else if (Orientation(a, b, d) < 0.0) {\n std::swap(d, c);\n } else {\n std::swap(a, d);\n }\n } else if (Orientation(a, c, d) < 0.0) {\n // Triangle abc is counterclockwise, i.e. acb is clockwise.\n // Also, acd is clockwise.\n if (Orientation(a, b, d) < 0.0) {\n std::swap(b, c);\n } else {\n std::swap(a, b);\n }\n } else {\n // Triangle abc is counterclockwise, and acd is counterclockwise.\n // Therefore, abcd is counterclockwise.\n std::swap(a, c);\n }\n}\n\nvoid PrintPoints(const char *caption, const PointF points[4]){\n printf(\"%s: (%f,%f),(%f,%f),(%f,%f),(%f,%f)\\n\", caption,\n points[0].x, points[0].y, points[1].x, points[1].y,\n points[2].x, points[2].y, points[3].x, points[3].y);\n}\n\nint main(){\n PointF points[] = {\n {5.0f, 20.0f},\n {5.0f, 5.0f},\n {20.0f, 20.0f},\n {20.0f, 5.0f}\n };\n\n for(int i = 0; i < 4; i++){\n for(int j = 0; j < 4; j++){\n if(j == i) continue;\n for(int k = 0; k < 4; k++){\n if(j == k || i == k) continue;\n for(int l = 0; l < 4; l++){\n if(j == l || i == l || k == l) continue;\n PointF sample[4];\n sample[0] = points[i];\n sample[1] = points[j];\n sample[2] = points[k];\n sample[3] = points[l];\n\n PrintPoints(\"input: \", sample);\n Sort4PointsClockwise(sample);\n PrintPoints(\"output: \", sample);\n printf(\"\\n\");\n }\n }\n }\n }\n\n return 0;\n}\n" }, { "answer_id": 10110480, "author": "Rui Marques", "author_id": 1085483, "author_profile": "https://Stackoverflow.com/users/1085483", "pm_score": 3, "selected": false, "text": " // top-left = 0; top-right = 1; \n // right-bottom = 2; left-bottom = 3;\n List<Point> orderRectCorners(List<Point> corners) { \n if(corners.size() == 4) { \n ordCorners = orderPointsByRows(corners);\n \n if(ordCorners.get(0).x > ordCorners.get(1).x) { // swap points\n Point tmp = ordCorners.get(0);\n ordCorners.set(0, ordCorners.get(1));\n ordCorners.set(1, tmp);\n }\n \n if(ordCorners.get(2).x < ordCorners.get(3).x) { // swap points\n Point tmp = ordCorners.get(2);\n ordCorners.set(2, ordCorners.get(3));\n ordCorners.set(3, tmp);\n } \n return ordCorners;\n } \n return empty list or something;\n }\n\n List<Point> orderPointsByRows(List<Point> points) {\n Collections.sort(points, new Comparator<Point>() {\n public int compare(Point p1, Point p2) {\n if (p1.y < p2.y) return -1;\n if (p1.y > p2.y) return 1;\n return 0;\n }\n });\n return points;\n }\n" }, { "answer_id": 12141521, "author": "Shekhar", "author_id": 825822, "author_profile": "https://Stackoverflow.com/users/825822", "pm_score": 1, "selected": false, "text": "var arr = [{x:3,y:3},{x:4,y:1},{x:0,y:2},{x:5,y:2},{x:1,y:1}];\nvar reference = {x:2,y:2};\narr.sort(function(a,b) {\n var aTanA = Math.atan2((a.y - reference.y),(a.x - reference.x));\n var aTanB = Math.atan2((b.y - reference.y),(b.x - reference.x));\n if (aTanA < aTanB) return -1;\n else if (aTanB < aTanA) return 1;\n return 0;\n});\nconsole.log(arr);\n" }, { "answer_id": 43973648, "author": "Eisneim", "author_id": 3177057, "author_profile": "https://Stackoverflow.com/users/3177057", "pm_score": 1, "selected": false, "text": "corners.sort(key=lambda ii: ii[1], reverse=True)\ntopRow = corners[0:2]\nbottomRow = corners[2:]\n\ntopRow.sort(key=lambda ii: ii[0])\nbottomRow.sort(key=lambda ii: ii[0])\n# clockwise\nreturn [topRow[0], topRow[1], bottomRow[1], bottomRow[0]]\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45603/" ]
242,406
<p>So I have action_mailer_optional_tls (<a href="http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls" rel="nofollow noreferrer">http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls</a>) and this in my enviroment.rb</p> <pre><code>ActionMailer::Base.server_settings = { :tls =&gt; true, :address =&gt; "smtp.gmail.com", :port =&gt; "587", :domain =&gt; "www.somedomain.com", :authentication =&gt; :plain, :user_name =&gt; "someusername", :password =&gt; "somepassword" } </code></pre> <p>But now what If I want to send emails from different email accounts? How do I override the user_name and password fields on the fly?</p> <p>What Im looking for is a solution which allows dynamic switching between accounts. Example the following scenario: 10 "Admins" can send out notices to our customers. Each has their own gmail account, when they fill out a form on the site rails connects using their account and sends the mail.</p> <p>Thanks in advance!</p> <p>Ali</p>
[ { "answer_id": 244343, "author": "Daniel Beardsley", "author_id": 13216, "author_profile": "https://Stackoverflow.com/users/13216", "pm_score": 1, "selected": false, "text": "before_filter :load_email_settings\n\ndef load_email_settings\n ActionMailer::Base.server_settings.merge!(:user_name => current_user.email, :password => current_user.email_password)\nend\n\ndef current_user\n @current_user ||= User.find(session[:user_id])\nend\n" }, { "answer_id": 1564683, "author": "uv.", "author_id": 109216, "author_profile": "https://Stackoverflow.com/users/109216", "pm_score": 0, "selected": false, "text": "action_mailer_optional_tls" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242406", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31975/" ]
242,417
<p>I have two lists that are of the same length, is it possible to loop through these two lists at once?</p> <p>I am looking for the correct syntax to do the below</p> <pre><code>foreach itemA, itemB in ListA, ListB { Console.WriteLine(itemA.ToString()+","+itemB.ToString()); } </code></pre> <p>do you think this is possible in C#? And if it is, what is the lambda expression equivalent of this?</p>
[ { "answer_id": 242420, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": false, "text": "IEnumerable<T>" }, { "answer_id": 242422, "author": "jcelgin", "author_id": 26582, "author_profile": "https://Stackoverflow.com/users/26582", "pm_score": 4, "selected": false, "text": "for(int i=0; i<ListA.Length; i++)\n{\n Console.WriteLine(ListA[i].ToString() + \", \" + ListB[i].ToString());\n}\n" }, { "answer_id": 242433, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "IEnumerator ListAEnum = ListA.GetEnumerator();\nIEnumerator ListBEnum = ListB.GetEnumerator();\n\nListBEnum.MoveNext();\nwhile(ListAEnum.MoveNext()==true)\n{\n itemA=ListAEnum.getCurrent();\n itemB=ListBEnum.getCurrent();\n Console.WriteLine(itemA.ToString()+\",\"+itemB.ToString());\n}\n" }, { "answer_id": 242489, "author": "gimel", "author_id": 6491, "author_profile": "https://Stackoverflow.com/users/6491", "pm_score": -1, "selected": false, "text": "itertools.izip" }, { "answer_id": 242564, "author": "PiRX", "author_id": 25718, "author_profile": "https://Stackoverflow.com/users/25718", "pm_score": 2, "selected": false, "text": "for(int i=0; i<ListA.Length; i++)\n{\n Console.WriteLine(ListA[i].ToString() + \", \" + ListB[i].ToString());\n}\n" }, { "answer_id": 9931679, "author": "sonjz", "author_id": 740575, "author_profile": "https://Stackoverflow.com/users/740575", "pm_score": 1, "selected": false, "text": "class Stock {\n string symbol;\n List<decimal> hourlyPrice; // provides a list of 24 decimals\n}\n\n// get hourly prices from yesterday and today\nList<Stock> stockMondays = Stocks.GetStock(\"GOOGL,IBM,AAPL\", DateTime.Now.AddDay(-1));\nList<Stock> stockTuesdays = Stocks.GetStock(\"GOOGL,IBM,AAPL\", DateTime.Now);\n\ntry {\n foreach(Stock sMonday in stockMondays) {\n Stock sTuesday = stockTuesday[stockMondays.IndexOf(sMonday)];\n\n foreach(decimal mondayPrice in sMonday.prices) {\n decimal tuesdayPrice = sTuesday.prices[sMonday.prices.IndexOf(mondayPrice)];\n // do something now\n }\n\n }\n} catch (Exception ex) { // some reason why list counts aren't matching? }\n" }, { "answer_id": 41531092, "author": "Joy Fernandes", "author_id": 4519455, "author_profile": "https://Stackoverflow.com/users/4519455", "pm_score": 0, "selected": false, "text": "public List<SqlData> SqlDataBinding(List<SqlData> schema, List<dynamic> data)\n{\n foreach (SqlData item in schema)\n {\n item.Values = data[schema.IndexOf(item)];\n }\n return schema\n}\n" }, { "answer_id": 68089024, "author": "MarredCheese", "author_id": 5405967, "author_profile": "https://Stackoverflow.com/users/5405967", "pm_score": 4, "selected": true, "text": "int[] numbers = { 1, 2, 3, 4 };\nstring[] words = { \"one\", \"two\", \"three\" };\n\nforeach (var (number, word) in numbers.Zip(words))\n Console.WriteLine($\"{number}, {word}\");\n\n// 1, one\n// 2, two\n// 3, three\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242417", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
242,421
<p>I am trying to execute this SQL query prior to restoring a .BAK file in SQL Express. Initially, I had the file on the Desktop of my user account. I am logged in as Administrator.</p> <p>When I try to access the .BAK file on the desktop like this</p> <pre><code>RESTORE FILELISTONLY FROM DISK= 'C:\Documents and Settings\Administrator\Desktop\file.bak' </code></pre> <p>I get an error.</p> <pre>Msg 3201, Level 16, State 2, Line 1 Cannot open backup device 'C:\Documents and Settings\Administrator\Desktop\file.bak'. Operating system error 5(Access is denied.). Msg 3013, Level 16, State 1, Line 1 RESTORE FILELIST is terminating abnormally.</pre> <p>However, when I move the .BAK file to <code>C:\temp</code>, and execute this </p> <pre><code>RESTORE FILELISTONLY FROM DISK= 'C:\temp\file.bak' </code></pre> <p>It works just fine.</p> <p>I cant figure out what is going on. Is there a way to access files on Desktop using Windows Authentication with SQL Express?</p>
[ { "answer_id": 53519678, "author": "Marcello Miorelli", "author_id": 1501497, "author_profile": "https://Stackoverflow.com/users/1501497", "pm_score": 0, "selected": false, "text": "select * from\nsys.dm_server_services\n\nSELECT DSS.servicename,\n DSS.startup_type_desc,\n DSS.status_desc,\n DSS.last_startup_time,\n DSS.service_account,\n DSS.is_clustered,\n DSS.cluster_nodename,\n DSS.filename,\n DSS.startup_type,\n DSS.status,\n DSS.process_id\nFROM sys.dm_server_services AS DSS;\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31979/" ]
242,424
<p>I know how to move a layer based on touch. But I would also like to be able to rotate the image. </p> <p>Is there any sample code that shows how to do this? Or can anyone give me some advice?</p> <p>Thanks!</p>
[ { "answer_id": 242858, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 5, "selected": true, "text": "float angle = M_PI; //rotate 180°, or 1 π radians\nlayer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0);\n" }, { "answer_id": 244749, "author": "rksprst", "author_id": 23695, "author_profile": "https://Stackoverflow.com/users/23695", "pm_score": 4, "selected": false, "text": "CGAffineTransform transform = CGAffineTransformMakeRotation(angle);\n[[self viewWithTag:999] setTransform:transform];\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23695/" ]
242,438
<p>I've a performance related question regarding use of StringBuilder. In a very long loop I'm manipulating a <code>StringBuilder</code> and passing it to another method like this:</p> <pre><code>for (loop condition) { StringBuilder sb = new StringBuilder(); sb.append("some string"); . . . sb.append(anotherString); . . . passToMethod(sb.toString()); } </code></pre> <p>Is instantiating <code>StringBuilder</code> at every loop cycle is a good solution? And is calling a delete instead better, like the following?</p> <pre><code>StringBuilder sb = new StringBuilder(); for (loop condition) { sb.delete(0, sb.length); sb.append("some string"); . . . sb.append(anotherString); . . . passToMethod(sb.toString()); } </code></pre>
[ { "answer_id": 242449, "author": "Peter", "author_id": 26483, "author_profile": "https://Stackoverflow.com/users/26483", "pm_score": 5, "selected": false, "text": "for (loop condition) {\n StringBuilder sb = new StringBuilder(4096);\n}\n" }, { "answer_id": 242455, "author": "Epaga", "author_id": 6583, "author_profile": "https://Stackoverflow.com/users/6583", "pm_score": 6, "selected": false, "text": "public class ScratchPad {\n\n static String a;\n\n public static void main( String[] args ) throws Exception {\n long time = System.currentTimeMillis();\n for( int i = 0; i < 10000000; i++ ) {\n StringBuilder sb = new StringBuilder();\n sb.append( \"someString\" );\n sb.append( \"someString2\"+i );\n sb.append( \"someStrin4g\"+i );\n sb.append( \"someStr5ing\"+i );\n sb.append( \"someSt7ring\"+i );\n a = sb.toString();\n }\n System.out.println( System.currentTimeMillis()-time );\n time = System.currentTimeMillis();\n StringBuilder sb = new StringBuilder();\n for( int i = 0; i < 10000000; i++ ) {\n sb.delete( 0, sb.length() );\n sb.append( \"someString\" );\n sb.append( \"someString2\"+i );\n sb.append( \"someStrin4g\"+i );\n sb.append( \"someStr5ing\"+i );\n sb.append( \"someSt7ring\"+i );\n a = sb.toString();\n }\n System.out.println( System.currentTimeMillis()-time );\n }\n}\n" }, { "answer_id": 242536, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": false, "text": "toString" }, { "answer_id": 250110, "author": "Jack Leow", "author_id": 31506, "author_profile": "https://Stackoverflow.com/users/31506", "pm_score": 3, "selected": false, "text": "for (loop condition) {\n String s = \"some string\";\n . . .\n s += anotherString;\n . . .\n passToMethod(s);\n}\n" }, { "answer_id": 1025697, "author": "Dave Jarvis", "author_id": 59087, "author_profile": "https://Stackoverflow.com/users/59087", "pm_score": 5, "selected": false, "text": "public class ScratchPad {\n\n private static String a;\n\n public static void main( String[] args ) throws Exception {\n final long time = System.currentTimeMillis();\n\n // Pre-allocate enough space to store all appended strings.\n // StringBuilder, ultimately, uses an array of characters.\n final StringBuilder sb = new StringBuilder( 128 );\n\n for( int i = 0; i < 10000000; i++ ) {\n // Resetting the string is faster than creating a new object.\n // Since this is a critical loop, every instruction counts.\n sb.setLength( 0 );\n sb.append( \"someString\" );\n sb.append( \"someString2\" );\n sb.append( \"someStrin4g\" );\n sb.append( \"someStr5ing\" );\n sb.append( \"someSt7ring\" );\n setA( sb.toString() );\n }\n\n System.out.println( System.currentTimeMillis() - time );\n }\n\n private static void setA( final String aString ) {\n a = aString;\n }\n}\n" }, { "answer_id": 1134977, "author": "brianegge", "author_id": 14139, "author_profile": "https://Stackoverflow.com/users/14139", "pm_score": 1, "selected": false, "text": "private void clear() throws Exception {\n long time = System.currentTimeMillis();\n int maxLength = 0;\n StringBuilder sb = new StringBuilder();\n\n for( int i = 0; i < 10000000; i++ ) {\n // Resetting the string is faster than creating a new object.\n // Since this is a critical loop, every instruction counts.\n //\n sb.setLength( 0 );\n sb.append( \"someString\" );\n sb.append( \"someString2\" ).append( i );\n sb.append( \"someStrin4g\" ).append( i );\n sb.append( \"someStr5ing\" ).append( i );\n sb.append( \"someSt7ring\" ).append( i );\n maxLength = Math.max(maxLength, sb.toString().length());\n }\n\n System.out.println(maxLength);\n System.out.println(\"Clear buffer: \" + (System.currentTimeMillis()-time) );\n}\n\nprivate void preAllocate() throws Exception {\n long time = System.currentTimeMillis();\n int maxLength = 0;\n\n for( int i = 0; i < 10000000; i++ ) {\n StringBuilder sb = new StringBuilder(82);\n sb.append( \"someString\" );\n sb.append( \"someString2\" ).append( i );\n sb.append( \"someStrin4g\" ).append( i );\n sb.append( \"someStr5ing\" ).append( i );\n sb.append( \"someSt7ring\" ).append( i );\n maxLength = Math.max(maxLength, sb.toString().length());\n }\n\n System.out.println(maxLength);\n System.out.println(\"Pre allocate: \" + (System.currentTimeMillis()-time) );\n}\n\npublic void testBoth() throws Exception {\n for(int i = 0; i < 5; i++) {\n clear();\n preAllocate();\n }\n}\n" }, { "answer_id": 16941816, "author": "johnmartel", "author_id": 1270280, "author_profile": "https://Stackoverflow.com/users/1270280", "pm_score": 1, "selected": false, "text": "time = System.currentTimeMillis();\nStringBuilder sb2 = new StringBuilder();\nfor (int i = 0; i < 10000000; i++) {\n sb2.append( \"someString\" );\n sb2.append( \"someString2\"+i );\n sb2.append( \"someStrin4g\"+i );\n sb2.append( \"someStr5ing\"+i );\n sb2.append( \"someSt7ring\"+i );\n a = sb2.toString();\n sb2.setLength(0);\n}\nSystem.out.println( System.currentTimeMillis()-time );\n" }, { "answer_id": 19075395, "author": "Shen liang", "author_id": 1765981, "author_profile": "https://Stackoverflow.com/users/1765981", "pm_score": 1, "selected": false, "text": " System.arraycopy(value, start+len, value, start, count-end);\n" }, { "answer_id": 58503489, "author": "Ulrich K.", "author_id": 12257130, "author_profile": "https://Stackoverflow.com/users/12257130", "pm_score": 0, "selected": false, "text": " String a;\n StringBuilder sb = new StringBuilder();\n long time = 0;\n\n System.gc();\n time = System.currentTimeMillis();\n for (int i = 0; i < 100000000; i++) {\n StringBuilder sb3 = new StringBuilder();\n sb3.append(\"someString\");\n sb3.append(\"someString2\");\n sb3.append(\"someStrin4g\");\n sb3.append(\"someStr5ing\");\n sb3.append(\"someSt7ring\");\n a = sb3.toString();\n }\n System.out.println(System.currentTimeMillis() - time);\n\n System.gc();\n time = System.currentTimeMillis();\n for (int i = 0; i < 100000000; i++) {\n sb.setLength(0);\n sb.delete(0, sb.length());\n sb.append(\"someString\");\n sb.append(\"someString2\");\n sb.append(\"someStrin4g\");\n sb.append(\"someStr5ing\");\n sb.append(\"someSt7ring\");\n a = sb.toString();\n }\n System.out.println(System.currentTimeMillis() - time);\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27789/" ]
242,444
<p>I have a little pet web app project I'd like to show someone who doesn't have an application server themselves (and who has no clue about application servers).</p> <p>What is the easiest and quickest way for them to get my WAR file running with zero configuration, preferably something I could send along with or bundle with the WAR file? Is there a slimmed down version of Jetty, for example? Something else?</p>
[ { "answer_id": 242476, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": true, "text": "* servlet-api-2.5-6.x.jar\n* jetty-util-6.x.jar\n* jetty-6.x.jar\n\n\n/usr/local/jetty-6.1.4/lib> ls -la servlet-api-2.5-6.1.4.jar jetty-*\n-rw-rw-r-- 1 wwwrun admin 476213 2007-06-15 08:42 jetty-6.1.4.jar\n-rw-rw-r-- 1 wwwrun admin 128026 2007-06-15 08:40 jetty-util-6.1.4.jar\n-rw-rw-r-- 1 wwwrun admin 131977 2007-06-15 08:40 servlet-api-2.5-6.1.4.jar\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6583/" ]
242,453
<p>I am trying to compare two decimal values in Java script. I have two objects as one assogned value "3" and the other as "3.00". When i say if (obj1 == obj2) it does not pass the condition as it is does the string comparision. </p> <p>I would instead want it to do a decimal comparision where 3 = 3.00. Please let me know how to do this.</p>
[ { "answer_id": 242461, "author": "eyelidlessness", "author_id": 17964, "author_profile": "https://Stackoverflow.com/users/17964", "pm_score": 0, "selected": false, "text": "if(parseFloat(obj1) == parseFloat(obj2)) { // ...\n" }, { "answer_id": 242464, "author": "Vincent Ramdhanie", "author_id": 27439, "author_profile": "https://Stackoverflow.com/users/27439", "pm_score": 0, "selected": false, "text": "if(parseFloat(obj1) == parseFloat(obj2))\n" }, { "answer_id": 242467, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 2, "selected": false, "text": "var a = \"3.00\";\nvar b = \"3\";\n\nNumber(a) == Number(b) // This will be true\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20951/" ]
242,468
<p>In my ASP.NET application I have a web.config file. In the web.config file I have a connection string...</p> <pre><code>&lt;connectionStrings&gt; &lt;add name="HRDb" connectionString="xxxxx" providerName="System.Data.SqlClient" /&gt; &lt;/connectionStrings&gt; </code></pre> <p>Yet, when I retrieve this value using <code>ConfigurationManager.ConnectionStringsp["HRDb"]</code>, I get the my old connection string, not the new one.</p> <p>Where else (apart from web.config) does the <code>ConfigurationManager</code> read connection string values from?</p> <p>I'm running the application from VS.NET (not deployed to IIS).</p>
[ { "answer_id": 242490, "author": "Rune Grimstad", "author_id": 30366, "author_profile": "https://Stackoverflow.com/users/30366", "pm_score": 1, "selected": false, "text": "<clear />" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22702/" ]
242,485
<p>This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.</p>
[ { "answer_id": 242506, "author": "monkut", "author_id": 24718, "author_profile": "https://Stackoverflow.com/users/24718", "pm_score": 5, "selected": false, "text": "testlist = [1,2,3,4,5, 0]\n\nprev_i = None\nfor i in testlist:\n if not prev_i:\n prev_i = i\n else:\n result = prev_i/i\n" }, { "answer_id": 242514, "author": "Florian Bösch", "author_id": 19435, "author_profile": "https://Stackoverflow.com/users/19435", "pm_score": 8, "selected": true, "text": "import pdb, traceback, sys\n\ndef bombs():\n a = []\n print a[0]\n\nif __name__ == '__main__':\n try:\n bombs()\n except:\n extype, value, tb = sys.exc_info()\n traceback.print_exc()\n pdb.post_mortem(tb)\n" }, { "answer_id": 242531, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 6, "selected": false, "text": "import sys\n\ndef info(type, value, tb):\n if hasattr(sys, 'ps1') or not sys.stderr.isatty():\n # we are in interactive mode or we don't have a tty-like\n # device, so we call the default hook\n sys.__excepthook__(type, value, tb)\n else:\n import traceback, pdb\n # we are NOT in interactive mode, print the exception...\n traceback.print_exception(type, value, tb)\n print\n # ...then start the debugger in post-mortem mode.\n # pdb.pm() # deprecated\n pdb.post_mortem(tb) # more \"modern\"\n\nsys.excepthook = info\n" }, { "answer_id": 2438834, "author": "Catherine Devlin", "author_id": 86209, "author_profile": "https://Stackoverflow.com/users/86209", "pm_score": 9, "selected": false, "text": "python -m pdb -c continue myscript.py\n" }, { "answer_id": 4873570, "author": "Amandasaurus", "author_id": 161922, "author_profile": "https://Stackoverflow.com/users/161922", "pm_score": 2, "selected": false, "text": "import pdb ; pdb.set_trace()\n" }, { "answer_id": 23113690, "author": "vlad-ardelean", "author_id": 1037251, "author_profile": "https://Stackoverflow.com/users/1037251", "pm_score": -1, "selected": false, "text": "pdb.set_trace" }, { "answer_id": 34733850, "author": "Zlatko Karakaš", "author_id": 4447387, "author_profile": "https://Stackoverflow.com/users/4447387", "pm_score": 2, "selected": false, "text": "python -m pdb -c c <script name>\n" }, { "answer_id": 35039165, "author": "wodow", "author_id": 167806, "author_profile": "https://Stackoverflow.com/users/167806", "pm_score": 5, "selected": false, "text": "python myscript.py arg1 arg2\n" }, { "answer_id": 35489235, "author": "blueFast", "author_id": 647991, "author_profile": "https://Stackoverflow.com/users/647991", "pm_score": 2, "selected": false, "text": "python -m mymodule\n" }, { "answer_id": 51050899, "author": "Willemoes", "author_id": 2047185, "author_profile": "https://Stackoverflow.com/users/2047185", "pm_score": 4, "selected": false, "text": "ipython" }, { "answer_id": 65653479, "author": "dlukes", "author_id": 1826241, "author_profile": "https://Stackoverflow.com/users/1826241", "pm_score": 0, "selected": false, "text": "ipdb" }, { "answer_id": 71375486, "author": "Jonathan Dauwe", "author_id": 17229877, "author_profile": "https://Stackoverflow.com/users/17229877", "pm_score": 0, "selected": false, "text": "try:\n ... # The line that raises an error\nexcept:\n breakpoint()\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24530/" ]
242,504
<p>How can I generate a report in access with the data from a recordset (instead of a query or table). I have updates to the recordset that also must be shown in the report.</p>
[ { "answer_id": 243544, "author": "BIBD", "author_id": 685, "author_profile": "https://Stackoverflow.com/users/685", "pm_score": 3, "selected": true, "text": "Private Sub Report_Open(Cancel As Integer)\n Me.RecordSource = gMyRecordSet.Name\nEnd Sub\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31132/" ]
242,517
<p>I have a certain application which feeds information into an object, after comparing the new information to the old information. It goes something like</p> <pre><code>set { oldval=_value; _value=value; if (some comparison logic) raiseEvent(); } </code></pre> <p>This all happens on a background thread, in an infinite loop, which intermittently sleeps for 100ms. The really odd part is that it works the first time, the comparison logic turns up true, and the event is raised. After that, the information keeps flowing, it keep entering the object, I know this because I set MessageBoxes to display the old and new values all the time, but its as if it somehow bypasses the set clause! I set a messagebox in the beginning of the clause, an it just doesn't pop up! This is really wierd, since I am sure that the value keeps updating.</p> <p>Any Thoughts?</p> <hr> <p>Yeah, I know, but unfortunately theres not much more I can show... Let me try to explain the overall structure again: I have a separate background thread running an infinite loop. This loop continuously pulls data from a Data object, which is updated by a whole other set of threads. All of this is of course under synchronization with Monitor.Enter and Exit. The data pulled from the Data object is then inputted into the Comparer object.</p> <pre><code>while(true) { Thread.Sleep(100); Monitor.Enter(Data); Comparer.Value = Data.Value; Monitor.Exit(Data); } </code></pre> <p>The Comparer.Value is the property I mentioned in the first post. Its really quite weird since I set up a MessageBox in the end of the loop:</p> <pre><code>MessageBox.Show(Comparer.Value + " - " + Data.Value); </code></pre> <p>and the values DO actually update, it just somehow seems to bypass the set clause, which is impossible... This is truly weird.</p> <p>And Rob, the loop doesn't do any of the checking, it just simulates a stream of information into Comparer.Value; It's set clause contains the comparison logic.</p> <p>bh213, I'm pretty that it is, but I can't tell because the comparison stops before any meaningful checking is done.</p> <hr> <p>Alright, I've solved the problem, apparently my question was wrong, the problem was in a whole other place. Thanks for all the help, the question may be closed.</p>
[ { "answer_id": 242521, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": false, "text": "void SomeHandler(object sender, EventArgs args)\n{\n this.Invoke((MethodInvoker)delegate {\n this.Text = \"Something happened\";\n });\n}\n" }, { "answer_id": 242575, "author": "Marco M.", "author_id": 28375, "author_profile": "https://Stackoverflow.com/users/28375", "pm_score": 2, "selected": false, "text": "set\n{\n if (_value != value)\n {\n _value=value;\n RaiseSomeEvent();\n }\n}\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30884/" ]
242,529
<p>I just saw the anouncement for the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814&amp;displaylang=en" rel="nofollow noreferrer">Visual Studio CTP</a> today, and am currently waiting for all those files to download...</p> <p>Have you already tried the CTP, or maybe a previous version? What are your thoughts? There is another question <a href="https://stackoverflow.com/questions/206943/what-features-would-you-most-like-to-see-in-visual-studio-2010">What features would you most like to see in Visual Studio 2010</a>, now here it is, what do you think?</p>
[ { "answer_id": 463967, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 0, "selected": false, "text": "dynamic" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11410/" ]
242,534
<pre><code>private const int THE_ANSWER = 42; </code></pre> <p>or</p> <pre><code>private const int theAnswer = 42; </code></pre> <p>Personally I think with modern IDEs we should go with camelCase as ALL_CAPS looks strange. What do you think?</p>
[ { "answer_id": 242539, "author": "dove", "author_id": 30913, "author_profile": "https://Stackoverflow.com/users/30913", "pm_score": 4, "selected": false, "text": "private const int Answer = 42;\n" }, { "answer_id": 242545, "author": "bh213", "author_id": 28912, "author_profile": "https://Stackoverflow.com/users/28912", "pm_score": 6, "selected": false, "text": "private const int TheAnswer = 42;\n" }, { "answer_id": 242549, "author": "Greg Beech", "author_id": 13552, "author_profile": "https://Stackoverflow.com/users/13552", "pm_score": 10, "selected": true, "text": "private const int TheAnswer = 42;\n" }, { "answer_id": 20890557, "author": "DavidRR", "author_id": 1497596, "author_profile": "https://Stackoverflow.com/users/1497596", "pm_score": 4, "selected": false, "text": "class Calendar3\n{\n const int months = 12;\n const int weeks = 52;\n const int days = 365;\n\n const double daysPerWeek = (double) days / (double) weeks;\n const double daysPerMonth = (double) days / (double) months;\n}\n" }, { "answer_id": 23787775, "author": "usefulBee", "author_id": 2093880, "author_profile": "https://Stackoverflow.com/users/2093880", "pm_score": 7, "selected": false, "text": "const int THE_ANSWER = 42;\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242534", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6846/" ]
242,538
<p>Basically I need to run the script with paths related to the shell script file location, how can I change the current directory to the same directory as where the script file resides?</p>
[ { "answer_id": 242550, "author": "TheMarko", "author_id": 31099, "author_profile": "https://Stackoverflow.com/users/31099", "pm_score": 10, "selected": true, "text": "#!/usr/bin/env bash\n\nBASEDIR=$(dirname \"$0\")\necho \"$BASEDIR\"\n" }, { "answer_id": 242557, "author": "Mez", "author_id": 20010, "author_profile": "https://Stackoverflow.com/users/20010", "pm_score": 6, "selected": false, "text": "#!/bin/bash\n\ncurrent_dir=$(pwd)\nscript_dir=$(dirname \"$0\")\n\necho $current_dir\necho $script_dir\n" }, { "answer_id": 444349, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "echo `pwd`/`dirname $0`\n" }, { "answer_id": 1638397, "author": "al.", "author_id": 198265, "author_profile": "https://Stackoverflow.com/users/198265", "pm_score": 9, "selected": false, "text": "readlink" }, { "answer_id": 2473033, "author": "docwhat", "author_id": 108857, "author_profile": "https://Stackoverflow.com/users/108857", "pm_score": 5, "selected": false, "text": "#!/bin/bash\n\npushd $(dirname \"${0}\") > /dev/null\nbasedir=$(pwd -L)\n# Use \"pwd -P\" for the path without links. man bash for more info.\npopd > /dev/null\n\necho \"${basedir}\"\n" }, { "answer_id": 4693587, "author": "blueyed", "author_id": 15690, "author_profile": "https://Stackoverflow.com/users/15690", "pm_score": 4, "selected": false, "text": "cd $(dirname $(readlink -f $0))\n" }, { "answer_id": 6255065, "author": "ranamalo", "author_id": 756470, "author_profile": "https://Stackoverflow.com/users/756470", "pm_score": 5, "selected": false, "text": "BASEDIR=$(dirname $0)\necho $BASEDIR\n" }, { "answer_id": 13958777, "author": "Zombo", "author_id": 1002260, "author_profile": "https://Stackoverflow.com/users/1002260", "pm_score": 1, "selected": false, "text": "read < <(readlink -f $0 | xargs dirname)\ncd $REPLY\n" }, { "answer_id": 15824974, "author": "Daniel", "author_id": 124704, "author_profile": "https://Stackoverflow.com/users/124704", "pm_score": 6, "selected": false, "text": "echo this file: \"$BASH_SOURCE\"\necho this dir: \"$(dirname \"$BASH_SOURCE\")\"\n" }, { "answer_id": 43919044, "author": "Ján Sáreník", "author_id": 1255163, "author_profile": "https://Stackoverflow.com/users/1255163", "pm_score": 4, "selected": false, "text": "a=\"/$0\"; a=\"${a%/*}\"; a=\"${a:-.}\"; a=\"${a##/}/\"; BINDIR=$(cd \"$a\"; pwd)\n" }, { "answer_id": 44644933, "author": "Alexandro de Oliveira", "author_id": 1781470, "author_profile": "https://Stackoverflow.com/users/1781470", "pm_score": 5, "selected": false, "text": "DIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\n" }, { "answer_id": 45392962, "author": "michael", "author_id": 127971, "author_profile": "https://Stackoverflow.com/users/127971", "pm_score": 2, "selected": false, "text": "readlink" }, { "answer_id": 49964642, "author": "thebunnyrules", "author_id": 1059127, "author_profile": "https://Stackoverflow.com/users/1059127", "pm_score": 3, "selected": false, "text": "#!/usr/bin/env bash\n\nBASEDIR=$(dirname \"$0\")\necho \"$BASEDIR\"\n" }, { "answer_id": 50772450, "author": "Richard Gomes", "author_id": 62131, "author_profile": "https://Stackoverflow.com/users/62131", "pm_score": 3, "selected": false, "text": "dir=$(dirname $(test -L \"$BASH_SOURCE\" && readlink -f \"$BASH_SOURCE\" || echo \"$BASH_SOURCE\"))\n" }, { "answer_id": 52293841, "author": "searchrome", "author_id": 2342649, "author_profile": "https://Stackoverflow.com/users/2342649", "pm_score": 4, "selected": false, "text": "BASE_DIR=\"$(cd \"$(dirname \"$0\")\"; pwd)\";\necho \"BASE_DIR => $BASE_DIR\"\n" }, { "answer_id": 55472432, "author": "Rohith", "author_id": 1771949, "author_profile": "https://Stackoverflow.com/users/1771949", "pm_score": 5, "selected": false, "text": "BASEDIR=$(dirname $(realpath \"$0\"))\necho \"$BASEDIR\"\n" }, { "answer_id": 66962790, "author": "Leslie Krause", "author_id": 9216142, "author_profile": "https://Stackoverflow.com/users/9216142", "pm_score": 0, "selected": false, "text": ":h" }, { "answer_id": 70174488, "author": "anton_rh", "author_id": 5447906, "author_profile": "https://Stackoverflow.com/users/5447906", "pm_score": 1, "selected": false, "text": "dir=$(dirname $0)\n" }, { "answer_id": 71603179, "author": "johansenj", "author_id": 897289, "author_profile": "https://Stackoverflow.com/users/897289", "pm_score": 0, "selected": false, "text": "#!/bin/sh\nrelative_dir=`perl -e 'use Cwd \"realpath\";$pwd = realpath(shift); $pwd =~ s/\\/[^\\/]*$//; print $pwd' $0`\ncd $relative_dir\n" } ]
2008/10/28
[ "https://Stackoverflow.com/questions/242538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16371/" ]