qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
317,336
<p>I am looking for a way to pull the first 100 characters from a string variable to put in another variable for printing. </p> <p>Is there a function that can do this easily?</p> <p>For example:</p> <pre><code>$string1 = "I am looking for a way to pull the first 100 characters from a string variable to put in another variable for printing."; $string2 = 100charfunction($string1); print $string2 </code></pre> <p>To get:</p> <pre><code>I am looking for a way to pull the first 100 characters from a string vari </code></pre>
[ { "answer_id": 317350, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 9, "selected": true, "text": "$small = substr($big, 0, 100);\n" }, { "answer_id": 317354, "author": "Kostis", "author_id": 35913, "author_profile": "https://Stackoverflow.com/users/35913", "pm_score": 4, "selected": false, "text": "function summary($str, $limit=100, $strip = false) {\n $str = ($strip == true)?strip_tags($str):$str;\n if (strlen ($str) > $limit) {\n $str = substr ($str, 0, $limit - 3);\n return (substr ($str, 0, strrpos ($str, ' ')).'...');\n }\n return trim($str);\n}\n" }, { "answer_id": 317371, "author": "Stein G. Strindhaug", "author_id": 26115, "author_profile": "https://Stackoverflow.com/users/26115", "pm_score": 5, "selected": false, "text": "$string2 = substr($string1, 0, 100);\n" }, { "answer_id": 28234428, "author": "joan16v", "author_id": 1398876, "author_profile": "https://Stackoverflow.com/users/1398876", "pm_score": 2, "selected": false, "text": "function charFunction($myStr, $limit=100) { \n $result = \"\";\n for ($i=0; $i<$limit; $i++) {\n $result .= $myStr[$i];\n }\n return $result; \n}\n\n$string1 = \"I am looking for a way to pull the first 100 characters from a string variable to put in another variable for printing.\";\n\necho charFunction($string1);\n" }, { "answer_id": 37798055, "author": "Coz", "author_id": 1812355, "author_profile": "https://Stackoverflow.com/users/1812355", "pm_score": 5, "selected": false, "text": "$string = mb_strimwidth($string, 0, 100);\n$string = mb_strimwidth($string, 0, 97, '...'); //optional characters for end\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317336", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33194/" ]
317,362
<p>I've got in my webservice a simple <code>public boolean isAlive()</code> service. I defined it in my WSDL :</p> <pre><code>&lt;wsdl:types&gt; &lt;xsd:element name="isAliveResponse" type="xsd:boolean"&gt; &lt;/xsd:element&gt; &lt;/wsdl:types&gt; &lt;wsdl:message name="isAliveResponse"&gt; &lt;wsdl:part element="ns:isAliveResponse" name="parameters"/&gt; &lt;/wsdl:message&gt; &lt;wsdl:portType name="myService"&gt; &lt;wsdl:operation name="isAlive"&gt; &lt;wsdl:output message="ns:isAliveResponse"/&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:portType&gt; &lt;wsdl:binding name="myServiceSOAP" type="ns:myService"&gt; &lt;soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /&gt; &lt;wsdl:operation name="isAlive"&gt; &lt;soap:operation soapAction="http://myServiceURL/isAlive" /&gt; &lt;wsdl:input&gt; &lt;soap:body use="literal" /&gt; &lt;/wsdl:input&gt; &lt;wsdl:output&gt; &lt;soap:body use="literal" /&gt; &lt;/wsdl:output&gt; &lt;/wsdl:operation&gt; &lt;/wsdl:binding&gt; </code></pre> <p>When I generate the Service skeleton the method is generated but not in the client stub. Is there a problem in the WSDL ? Should I put a wsdl:input even if the method don't have arguments (I didn't put the whole WSDL but all the other method with a "request" arg are well generated) ? And if I have to put a wsdl:input what would be it's message ?</p> <p><strong>Edit</strong> : After validating the WSDL under Eclipse I have the warning <code>WS-I: (BP2208) wsdl:operation was not a request/response or one-way operation</code> after searching I found a description here : <a href="http://www.ws-i.org/Testing/Tools/2005/01/BP11_TAD_1-1.htm#BP2208" rel="nofollow noreferrer">http://www.ws-i.org/Testing/Tools/2005/01/BP11_TAD_1-1.htm#BP2208</a> (it seems the anchor doesn't work) so I guess the error is probably the missing wsdl:input.</p>
[ { "answer_id": 317473, "author": "ryan", "author_id": 2454, "author_profile": "https://Stackoverflow.com/users/2454", "pm_score": 0, "selected": false, "text": "<wsdl:types>\n <xsd:element name=\"isAliveResponse\" type=\"xsd:boolean\">\n</wsdl:types>\n" }, { "answer_id": 317704, "author": "Vinze", "author_id": 26859, "author_profile": "https://Stackoverflow.com/users/26859", "pm_score": 2, "selected": true, "text": "<wsdl:input message=\"ns:isAliveRequest\" />\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26859/" ]
317,364
<p>On Linux, the "top" command shows a detailed but high level overview of your memory usage, showing:</p> <p>Total Memory, Used Memory, Free Memory, Buffer Usage, Cache Usage, Swap size and Swap Usage.</p> <p>My question is, what commands are available to show these memory usage figures in a clear and simple way? Bonus points if they're present in the "Core" install of Solaris. 'sar' doesn't count :)</p>
[ { "answer_id": 412564, "author": "Martin Carpenter", "author_id": 39443, "author_profile": "https://Stackoverflow.com/users/39443", "pm_score": 4, "selected": false, "text": "ps(1)" }, { "answer_id": 484897, "author": "matli", "author_id": 23896, "author_profile": "https://Stackoverflow.com/users/23896", "pm_score": 4, "selected": false, "text": "# echo ::memstat | mdb -k\nPage Summary Pages MB %Tot\n------------ ---------------- ---------------- ----\nKernel 7308 57 23%\nAnon 9055 70 29%\nExec and libs 1968 15 6%\nPage cache 2224 17 7%\nFree (cachelist) 6470 50 20%\nFree (freelist) 4641 36 15%\n\nTotal 31666 247\nPhysical 31256 244\n" }, { "answer_id": 9140629, "author": "stolsvik", "author_id": 39334, "author_profile": "https://Stackoverflow.com/users/39334", "pm_score": -1, "selected": false, "text": "free" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40626/" ]
317,368
<p>I'm trying to figure out what the following line does exactly - specifically the %%s part?</p> <pre><code>cursor.execute('INSERT INTO mastertickets (%s, %s) VALUES (%%s, %%s)'%sourcedest, (self.tkt.id, n)) </code></pre> <p>Any good mini-tutorial about string formatting and inserting variables into strings with Python?</p>
[ { "answer_id": 317385, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 4, "selected": true, "text": "%%" }, { "answer_id": 317459, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "sourcedest" }, { "answer_id": 317478, "author": "Draemon", "author_id": 26334, "author_profile": "https://Stackoverflow.com/users/26334", "pm_score": 2, "selected": false, "text": "stmt = \"INSERT INTO mastertickets (%s, %s) VALUES (?, ?)\" % srcdest\n...\ncursor.execute( stmt, (self.tkt.id, n) )\n" }, { "answer_id": 317484, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 0, "selected": false, "text": "cursor.execute('INSERT INTO mastertickets (%s, %s) VALUES (:%s, :%s)' % \\\n tuple(sourcedest + sourcedest), dict(zip(sourcedest, (self.tkt.id, n))))\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317368", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6583/" ]
317,374
<p>I am trying to import a .csv file into WorldShip containing names, addresses, and zip codes. I have two profiles set up defining package weight, UPS service, bill transportation, package type, and reference numbers.</p> <p>Can I import just name, addresses and zip codes under a specific profile to keep the other variables constant? Or do I have to add those variables to the .csv file?</p> <p>Also, I want to be able to print shipping and return labels for several "batches" throughout the day, but only have a single end of day report. Will each batch be appended to the end of day report? The return shipping address will stay constant.</p> <p>I have basic programming abilities and fairly good computer skills, but I want to know if I am getting in over my head. </p> <p>Your help is greatly appreciated.</p>
[ { "answer_id": 317385, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 4, "selected": true, "text": "%%" }, { "answer_id": 317459, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "sourcedest" }, { "answer_id": 317478, "author": "Draemon", "author_id": 26334, "author_profile": "https://Stackoverflow.com/users/26334", "pm_score": 2, "selected": false, "text": "stmt = \"INSERT INTO mastertickets (%s, %s) VALUES (?, ?)\" % srcdest\n...\ncursor.execute( stmt, (self.tkt.id, n) )\n" }, { "answer_id": 317484, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 0, "selected": false, "text": "cursor.execute('INSERT INTO mastertickets (%s, %s) VALUES (:%s, :%s)' % \\\n tuple(sourcedest + sourcedest), dict(zip(sourcedest, (self.tkt.id, n))))\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317374", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,377
<p>I'm creating a stored procedure to return search results where some of the parameters are optional.</p> <p>I want an "if statement" in my <em>where</em> clause but can't get it working. The <em>where</em> clause should filter by only the non-null parameters.</p> <p>Here's the sp</p> <pre><code>ALTER PROCEDURE spVillaGet -- Add the parameters for the stored procedure here @accomodationFK int = null, @regionFK int = null, @arrivalDate datetime, @numberOfNights int, @sleeps int = null, @priceFloor money = null, @priceCeil money = null AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here select tblVillas.*, tblWeeklyPrices.price from tblVillas INNER JOIN tblWeeklyPrices on tblVillas.villaId = tblWeeklyPrices.villaFK where If @accomodationFK &lt;&gt; null then accomodationTypeFK = @accomodationFK @regionFK &lt;&gt; null Then And regionFK = @regionFK IF @sleeps &lt;&gt; null Then And sleeps = @sleeps IF @priceFloor &lt;&gt; null Then And price &gt;= @priceFloor And price &lt;= @priceCeil END </code></pre> <p>Any ideas how to do this?</p>
[ { "answer_id": 317386, "author": "Ovidiu Pacurar", "author_id": 28419, "author_profile": "https://Stackoverflow.com/users/28419", "pm_score": 6, "selected": true, "text": "select tblVillas.*, tblWeeklyPrices.price \nfrom tblVillas\nINNER JOIN tblWeeklyPrices on tblVillas.villaId = tblWeeklyPrices.villaFK\nwhere (@accomodationFK IS null OR accomodationTypeFK = @accomodationFK)\n AND (@regionFK IS null or regionFK = @regionFK)\n AND (@sleeps IS null OR sleeps = @sleeps)\n AND (@priceFloor IS null OR (price BETWEEN @priceFloor And @priceCeil))\n" }, { "answer_id": 317425, "author": "Charles Bretana", "author_id": 32632, "author_profile": "https://Stackoverflow.com/users/32632", "pm_score": 0, "selected": false, "text": "Where accomodationTypeFK = IsNull(@accomodationFK, accomodationTypeFK)\n And regionFK = Coalesce(@regionFK,regionFK)\n And sleeps = IsNull(@sleeps,sleeps ) \n And price Between IsNull(@priceFloor, Price) And IsNull(priceCeil, Price) \n" }, { "answer_id": 317480, "author": "Sean Hanley", "author_id": 7290, "author_profile": "https://Stackoverflow.com/users/7290", "pm_score": 1, "selected": false, "text": "COALESCE" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40623/" ]
317,378
<p>When the page is done loading I call a function which puts the hover event on $('a.tooltip'). When I want to <em>unbind</em> this event I do the following: </p> <pre><code> $('a.tooltip').unbind('mouseover mouseout'); </code></pre> <p>That works! However when I want rebind the hover event and I call the function that was first loaded at document ready again, it doesn't rebind the hover helper. How can I rebind it?</p> <p>Thank you,</p> <p>Ice</p>
[ { "answer_id": 317474, "author": "Nathan Long", "author_id": 4376, "author_profile": "https://Stackoverflow.com/users/4376", "pm_score": 2, "selected": false, "text": "$(this).unbind('mouseenter').unbind('mouseleave');\n" }, { "answer_id": 317597, "author": "Bryan A", "author_id": 29707, "author_profile": "https://Stackoverflow.com/users/29707", "pm_score": 0, "selected": false, "text": " $(this).hover( \n function() {\n if (okayToHover) { dowhatever; } \n },\n function() {\n if (okayToUnhover) { undowhatever; }\n });\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317378", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,381
<p>OK, So i have been watching some MVC vids and reading some bits. I am new to the entire MVC pattern, and until now have been happily wrapped up in the web forms world!</p> <p>Like with so many demos it all seems great and I'm sure I'll have lots I dont understand as I move along, but in the first instance...</p> <p>I can see that you can have a strongly typed view, which gets data from the controller. What happens if I want data in a view from different object types?? Say i want to show a grid of cars and a grid of people, which are not related in anyway??</p> <p>Thx Steve</p>
[ { "answer_id": 317394, "author": "BigJoe714", "author_id": 37786, "author_profile": "https://Stackoverflow.com/users/37786", "pm_score": 0, "selected": false, "text": "public class CarsPeopleModel\n {\n public List<Car> Cars { get; set; }\n public List<Person> People { get; set; }\n }\n" }, { "answer_id": 317397, "author": "terjetyl", "author_id": 29519, "author_profile": "https://Stackoverflow.com/users/29519", "pm_score": 3, "selected": true, "text": "public class MyViewData \n{ \n public IEnumerable<Car> Cars { get; set; }\n public IEnumerable<People> People { get; set; }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317381", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6125/" ]
317,389
<p>I'm testing the basics for exchanging rest messages between a asp.net mvc site and a WCF 3.5 service. The service is built using the template found in the WCF REST Starter Kit found on codeplex. I would like to exchange json messages using jquery. The REST Singleton service is working properly and it also provide examples of all the possible calling adding the help parameter ad the end of the uri. I arrive to perform GET requests with the built in jquery $.getJSON. I have problems doing the PUT (for updating values) and POST.</p> <pre><code>$.ajax({ type: "PUT", dataType: "json", url: "http://localhost:1045/Service.svc/?format=json", data: '{"Value":testvalue}' }); </code></pre> <p>What is the best approach for this? Is it possible not to use Ms. Ajax at all and is it correct to bypass it?</p>
[ { "answer_id": 317444, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 3, "selected": true, "text": "$.ajax({\n type: \"PUT\",\n dataType: \"json\",\n url: \"http://localhost:1045/Service.svc/?format=json\",\n data: { Value: \"testvalue\" }\n});\n" }, { "answer_id": 328570, "author": "MotoWilliams", "author_id": 2730, "author_profile": "https://Stackoverflow.com/users/2730", "pm_score": 3, "selected": false, "text": "contentType: \"application/json\"" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1929/" ]
317,400
<p>I'm making a simple Image Debugger Visualizer. Code is below. I'm not sure if i need to manually dispose of the Image instance? Because i'm making a windows Form window and the PictureBox inside that contains my dynamic image .. do i need to add some special code when the form is terminating, to dispose of this? </p> <p>here's the code..</p> <pre><code>using System.Diagnostics; using System.Drawing; using System.Windows.Forms; using Microsoft.VisualStudio.DebuggerVisualizers; using DebuggerVisualizers; [assembly: DebuggerVisualizer( typeof (ImageDebuggerVisualizer), typeof (VisualizerObjectSource), Target = typeof (Image), Description = "Image Visualizer")] namespace DebuggerVisualizers { public class ImageDebuggerVisualizer : DialogDebuggerVisualizer { protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { Image image = (Image) objectProvider.GetObject(); Form form = new Form { Text = ("Image Visualizer - " + image.HorizontalResolution + " " + image.VerticalResolution), Width = image.Width, Height = image.Height }; PictureBox pictureBox = new PictureBox {Image = image, SizeMode = PictureBoxSizeMode.AutoSize}; form.Controls.Add(pictureBox); form.ShowDialog(); } } } </code></pre> <p>thanks for any help :)</p>
[ { "answer_id": 317547, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "Image image = (Image) objectProvider.GetObject();\n" }, { "answer_id": 317626, "author": "MusiGenesis", "author_id": 14606, "author_profile": "https://Stackoverflow.com/users/14606", "pm_score": 3, "selected": true, "text": "protected override void Show(IDialogVisualizerService windowService,\n IVisualizerObjectProvider objectProvider) \n{ \n Image image = (Image) objectProvider.GetObject();\n using (Form form = new Form())\n { \n PictureBox pictureBox = new PictureBox(); \n pictureBox.Image = image; \n form.Controls.Add(pictureBox); \n form.ShowDialog();\n } \n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30674/" ]
317,413
<p>I am creating a GUI frontend for the Eve Online API in Python.</p> <p>I have successfully pulled the XML data from their server.</p> <p>I am trying to grab the value from a node called "name":</p> <pre><code>from xml.dom.minidom import parse dom = parse("C:\\eve.xml") name = dom.getElementsByTagName('name') print name </code></pre> <p>This seems to find the node, but the output is below:</p> <pre><code>[&lt;DOM Element: name at 0x11e6d28&gt;] </code></pre> <p>How could I get it to print the value of the node?</p>
[ { "answer_id": 317421, "author": "eduffy", "author_id": 7536, "author_profile": "https://Stackoverflow.com/users/7536", "pm_score": 9, "selected": true, "text": "name[0].firstChild.nodeValue\n" }, { "answer_id": 317494, "author": "Henrik Gustafsson", "author_id": 2010, "author_profile": "https://Stackoverflow.com/users/2010", "pm_score": 6, "selected": false, "text": "from xml.dom.minidom import parse\ndom = parse(\"C:\\\\eve.xml\")\nname = dom.getElementsByTagName('name')\n\nprint \" \".join(t.nodeValue for t in name[0].childNodes if t.nodeType == t.TEXT_NODE)\n" }, { "answer_id": 2626246, "author": "LarrikJ", "author_id": 130712, "author_profile": "https://Stackoverflow.com/users/130712", "pm_score": 3, "selected": false, "text": "from xml.etree import ElementTree as ET\nimport datetime\n\nf = ET.XML(data)\n\nfor element in f:\n if element.tag == \"currentTime\":\n # Handle time data was pulled\n currentTime = datetime.datetime.strptime(element.text, \"%Y-%m-%d %H:%M:%S\")\n if element.tag == \"cachedUntil\":\n # Handle time until next allowed update\n cachedUntil = datetime.datetime.strptime(element.text, \"%Y-%m-%d %H:%M:%S\")\n if element.tag == \"result\":\n # Process list of skills\n pass\n" }, { "answer_id": 4835703, "author": "samaksh", "author_id": 594782, "author_profile": "https://Stackoverflow.com/users/594782", "pm_score": 4, "selected": false, "text": "doc = parse('C:\\\\eve.xml')\nmy_node_list = doc.getElementsByTagName(\"name\")\nmy_n_node = my_node_list[0]\nmy_child = my_n_node.firstChild\nmy_text = my_child.data \nprint my_text\n" }, { "answer_id": 7880363, "author": "khany", "author_id": 242305, "author_profile": "https://Stackoverflow.com/users/242305", "pm_score": 2, "selected": false, "text": "images = xml.getElementsByTagName(\"imageUrl\")\nfor i in images:\n print \" \".join(t.nodeValue for t in i.childNodes if t.nodeType == t.TEXT_NODE)\n" }, { "answer_id": 38481043, "author": "LazyBrush", "author_id": 1374268, "author_profile": "https://Stackoverflow.com/users/1374268", "pm_score": 3, "selected": false, "text": "name[0].firstChild.nodeValue\n" }, { "answer_id": 49895264, "author": "Billal Begueradj", "author_id": 3329664, "author_profile": "https://Stackoverflow.com/users/3329664", "pm_score": 2, "selected": false, "text": "firstChild.data" }, { "answer_id": 61021445, "author": "TextGeek", "author_id": 266371, "author_profile": "https://Stackoverflow.com/users/266371", "pm_score": 2, "selected": false, "text": "def innerText(self, sep=''):\n t = \"\"\n for curNode in self.childNodes:\n if (curNode.nodeType == Node.TEXT_NODE):\n t += sep + curNode.nodeValue\n elif (curNode.nodeType == Node.ELEMENT_NODE):\n t += sep + curNode.innerText(sep=sep)\n return t\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30786/" ]
317,423
<p>I've posted this <a href="https://stackoverflow.com/questions/155739/detecting-unsaved-changes-using-javascript#317246">here</a>, but thought it might deserve a question on its own.</p> <p>What I'm trying to do is show a dialog box that asks the user if he/she wants to leave the page if there are unsaved changes. That all works fine. But the problem is described below:</p> <p>Has anyone come across the problem where Internet Explorer fires the onbeforeunload event twice? While Googling around, I found it has something to do with the fact that for (among others) an ASP.NET linkbutton the HTML code is <code>&lt;a href="javascript: __doPostBack...</code>. </p> <p>Apparently, when IE encouters a link that doesn't have a <code>href="#"</code>, it fires the onbeforeunload event. Then, when you confirm the javascript dialog box we're showing, the page will do the 'real' unload to navigate to the other page, and raise the onbeforeunload event a second time.</p> <p>A solution offered on the internet is to set a boolean variable and check on it before showing the dialog. So the second time, it wouldn't be shown. That's all well, but when the user cancels, the variable will still be set. So the next time the user wants to leave the page, the dialog won't be shown anymore.</p> <p>Hope this is a little clear, and I hope someone has found a way around this?</p>
[ { "answer_id": 317498, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 1, "selected": false, "text": "var bFlag = window.confirm('Do you want to leave this page?');\n" }, { "answer_id": 317560, "author": "Peter", "author_id": 15349, "author_profile": "https://Stackoverflow.com/users/15349", "pm_score": 4, "selected": true, "text": "var onBeforeUnloadFired = false;\n" }, { "answer_id": 1014529, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "document.onstop = function() \n{\n try\n {\n if( document.readyState != \"complete\" )\n {\n showLoadingDiv();\n }\n }\n catch( error )\n {\n handleError( error );\n }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15349/" ]
317,424
<p>I am running a query from ASP using a MySQL database, I want to create a variable (ssResult) based on the result with a person's name (fullname), if the record does not exist I want to assign the text 'N/A' to the variable, code below, I currently use a function getOther for my database connections which passes the column name "fullname":</p> <pre><code>ssResult = getOtherElse("SELECT fullname FROM table WHERE id=" &amp; inArr(j), "fullname") </code></pre> <p>Below is the code for the function getOtherElse which only works when a result is returned but not when there is an empty result:</p> <pre><code>Function getOtherElse(inSQL, getColumn) Dim conn, rstemp Set conn = Server.CreateObject("ADODB.Connection") conn.open myDSN Set Session("lp_conn") = conn Set rstemp = Server.CreateObject("ADODB.Recordset") rstemp.Open inSQL, conn if not rstemp.eof then rstemp.movefirst getOtherElse=rstemp.fields(getColumn) else getOtherElse="N/A" end if rstemp.close set rstemp=nothing conn.close set conn=nothing End Function </code></pre> <p>Thanks!</p>
[ { "answer_id": 317489, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 0, "selected": false, "text": "if not rstemp.eof then\n rstemp.movefirst\n getOtherElse=rstemp.fields(getColumn)\nelse\n getOtherElse=\"N/A\"\nend if\n" }, { "answer_id": 318042, "author": "ARemesal", "author_id": 36599, "author_profile": "https://Stackoverflow.com/users/36599", "pm_score": 2, "selected": true, "text": "if not rstemp.eof then\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317424", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13658/" ]
317,431
<p>I am trying to set up a masterpage that contains a javascript popup subroutine that can be used in multiple web pages. The popup already works in a single page environment. I now want to migrate it to a master page. Any ideas will be greatly appreciated. I already searched this site and tried a couple of the suggestions to no avail. W small working example would help. Thanks Bill </p>
[ { "answer_id": 486545, "author": "Jack Lawson", "author_id": 59616, "author_profile": "https://Stackoverflow.com/users/59616", "pm_score": 1, "selected": false, "text": "ScriptManager.RegisterClientScriptInclude(string Key, string URL)\nlike so:\nScriptManager.RegisterClientScriptInclude(\"uniqueIdentifier\", \"~/javascript/myjs.js\");\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40630/" ]
317,447
<p>I am using macros in excel 2007 for my work. I am working with many data and I need to sum data from 2 or more rows in the same coloumn according to the same month. However the month column is expressed as date.</p> <p>for example, i have series of data</p> <pre><code>A B 2/10/2008 2 2/10/2008 3 4/10/2008 3 5/11/2008 4 5/11/2008 5 </code></pre> <p>I want the result to be displayed in column C and D as followed</p> <pre><code>C D Oct/08 8 Nov/08 9 </code></pre> <p>I am very thankful if anyone can help me.</p> <p>regards,</p> <p>Tifu</p>
[ { "answer_id": 319411, "author": "Sparr", "author_id": 13675, "author_profile": "https://Stackoverflow.com/users/13675", "pm_score": 2, "selected": false, "text": " A B C D E F\n1 10/ 1/2008 24106 1 Oct-08 24106 8\n2 10/31/2008 24106 7 Nov-08 24107 11\n3 11/ 1/2008 24107 8 Dec-08 24108 6\n4 11/30/2008 24107 3 \n5 12/ 1/2008 24108 2 \n6 12/ 2/2008 24108 4 \n\nB1 =MONTH(A1)+YEAR(A1)*12\nE1 =MONTH(D1)+YEAR(D1)*12\nF1 =SUMIF(B$1:B$6,CONCATENATE(\"=\",E1),C$1:C$6)\n" }, { "answer_id": 322576, "author": "wakingrufus", "author_id": 37847, "author_profile": "https://Stackoverflow.com/users/37847", "pm_score": 1, "selected": false, "text": "=date(2008,small(month($A$1:$A$10),1),1)\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,450
<p>In the <a href="http://www.boost.org/doc/html/signals.html" rel="noreferrer" title="Boost Signals documentation">Boost Signals</a> library, they are overloading the () operator.</p> <p>Is this a convention in C++? For callbacks, etc.?</p> <p>I have seen this in code of a co-worker (who happens to be a big Boost fan). Of all the Boost goodness out there, this has only led to confusion for me.</p> <p>Any insight as to the reason for this overload?</p>
[ { "answer_id": 317458, "author": "JeffV", "author_id": 445087, "author_profile": "https://Stackoverflow.com/users/445087", "pm_score": 1, "selected": false, "text": "my_functor();\n" }, { "answer_id": 317470, "author": "Lodle", "author_id": 23339, "author_profile": "https://Stackoverflow.com/users/23339", "pm_score": 5, "selected": false, "text": "logger.log(\"Log this message\");\n" }, { "answer_id": 317475, "author": "Michel", "author_id": 31122, "author_profile": "https://Stackoverflow.com/users/31122", "pm_score": 2, "selected": false, "text": "std::for_each" }, { "answer_id": 317520, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 3, "selected": false, "text": "class Sum\n{\npublic:\n Sum() : m_total(0)\n {\n }\n void operator()(int value)\n {\n m_total += value;\n }\n int m_total;\n};\n" }, { "answer_id": 317528, "author": "Luc Touraille", "author_id": 20984, "author_profile": "https://Stackoverflow.com/users/20984", "pm_score": 8, "selected": true, "text": "struct Accumulator\n{\n int counter = 0;\n int operator()(int i) { return counter += i; }\n}\n...\nAccumulator acc;\ncout << acc(10) << endl; //prints \"10\"\ncout << acc(20) << endl; //prints \"30\"\n" }, { "answer_id": 317552, "author": "Statement", "author_id": 2166173, "author_profile": "https://Stackoverflow.com/users/2166173", "pm_score": 2, "selected": false, "text": "T t;\nt.write(\"Hello world\");\n" }, { "answer_id": 71954630, "author": "SridharKritha", "author_id": 1308589, "author_profile": "https://Stackoverflow.com/users/1308589", "pm_score": -1, "selected": false, "text": "Functor" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317450", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445087/" ]
317,462
<p>In my everlasting quest to suck less I'm trying to understand the "yield" statement, but I keep encountering the same error.</p> <blockquote> <p>The body of [someMethod] cannot be an iterator block because 'System.Collections.Generic.List&lt; AClass>' is not an iterator interface type.</p> </blockquote> <p>This is the code where I got stuck:</p> <pre><code>foreach (XElement header in headersXml.Root.Elements()){ yield return (ParseHeader(header)); } </code></pre> <p>What am I doing wrong? Can't I use yield in an iterator? Then what's the point? In this example it said that <code>List&lt;ProductMixHeader&gt;</code> is not an iterator interface type. <code>ProductMixHeader</code> is a custom class, but I imagine <code>List</code> is an iterator interface type, no?</p> <p><strong>--Edit--</strong><br> Thanks for all the quick answers.<br> I know this question isn't all that new and the same resources keep popping up.<br> It turned out I was thinking I could return <code>List&lt;AClass&gt;</code> as a return type, but since <code>List&lt;T&gt;</code> isn't lazy, it cannot. Changing my return type to <code>IEnumerable&lt;T&gt;</code> solved the problem :D</p> <p>A somewhat related question (not worth opening a new thread): is it worth giving <code>IEnumerable&lt;T&gt;</code> as a return type if I'm sure that 99% of the cases I'm going to go .ToList() anyway? What will the performance implications be?</p>
[ { "answer_id": 317477, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 6, "selected": true, "text": "IEnumerable<SomethingAppropriate>\nIEnumerator<SomethingApropriate>\n" }, { "answer_id": 317479, "author": "hugoware", "author_id": 17091, "author_profile": "https://Stackoverflow.com/users/17091", "pm_score": 0, "selected": false, "text": "public IEnumerable<string> GetValues() {\n foreach(string value in someArray) {\n if (value.StartsWith(\"A\")) { yield return value; }\n }\n}\n" }, { "answer_id": 317492, "author": "Ian P", "author_id": 10853, "author_profile": "https://Stackoverflow.com/users/10853", "pm_score": 2, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace YieldReturnTest\n{\n public class PrimeFinder\n {\n private Boolean isPrime(int integer)\n {\n if (0 == integer)\n return false;\n\n if (3 > integer)\n return true;\n\n for (int i = 2; i < integer; i++)\n {\n if (0 == integer % i)\n return false;\n }\n return true;\n }\n\n public IEnumerable<int> FindPrimes()\n {\n int i;\n\n for (i = 1; i < 2147483647; i++)\n {\n if (isPrime(i))\n {\n yield return i;\n }\n }\n }\n }\n\n class Program\n {\n static void Main(string[] args)\n {\n PrimeFinder primes = new PrimeFinder();\n\n foreach (int i in primes.FindPrimes())\n {\n Console.WriteLine(i);\n Console.ReadLine();\n }\n\n Console.ReadLine();\n Console.ReadLine();\n }\n }\n}\n" }, { "answer_id": 317496, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": false, "text": "IEnumerable[<T>]" }, { "answer_id": 317521, "author": "Simon Steele", "author_id": 4591, "author_profile": "https://Stackoverflow.com/users/4591", "pm_score": 2, "selected": false, "text": "yield" }, { "answer_id": 24692504, "author": "donttellya", "author_id": 672605, "author_profile": "https://Stackoverflow.com/users/672605", "pm_score": 1, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace YieldReturnTest\n{\n public class PrimeFinder\n {\n private Boolean isPrime(int integer)\n {\n if (0 == integer)\n return false;\n\n if (3 > integer)\n return true;\n\n for (int i = 2; i < integer; i++)\n {\n if (0 == integer % i)\n return false;\n }\n return true;\n }\n\n public IEnumerable<int> FindPrimesWithYield()\n {\n int i;\n\n for (i = 1; i < 2147483647; i++)\n {\n if (isPrime(i))\n {\n yield return i;\n }\n }\n }\n\n public IEnumerable<int> FindPrimesWithoutYield()\n {\n var primes = new List<int>();\n int i;\n for (i = 1; i < 2147483647; i++)\n {\n if (isPrime(i))\n {\n primes.Add(i);\n }\n }\n return primes;\n }\n }\n\n class Program\n {\n static void Main(string[] args)\n {\n PrimeFinder primes = new PrimeFinder();\n\n Console.WriteLine(\"Finding primes until 7 with yield...very fast...\");\n foreach (int i in primes.FindPrimesWithYield()) // FindPrimesWithYield DOES NOT iterate over all integers at once, it returns item by item\n {\n if (i > 7)\n {\n break;\n }\n Console.WriteLine(i);\n //Console.ReadLine();\n\n }\n\n Console.WriteLine(\"Finding primes until 7 without yield...be patient it will take lonkg time...\");\n foreach (int i in primes.FindPrimesWithoutYield()) // FindPrimesWithoutYield DOES iterate over all integers at once, it returns the complete list of primes at once\n {\n if (i > 7)\n {\n break;\n }\n Console.WriteLine(i);\n //Console.ReadLine();\n }\n\n Console.ReadLine();\n Console.ReadLine();\n }\n }\n}\n" }, { "answer_id": 30887187, "author": "Matt", "author_id": 1016343, "author_profile": "https://Stackoverflow.com/users/1016343", "pm_score": 2, "selected": false, "text": "yield" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
317,472
<p>I have a container element which I need to resize as its contents change. It contains 2 absolutely positioned divs which can both change height. If I don't specify the height of the container then anything after the container disappears under the contents. </p> <p>At the moment I am doing the following but I'd be pleased to find a less laborious alternative:</p> <p>(container has position:relative, #main and #sidebar are position:absolute, the contents of #sidebar have no positioning specified)</p> <p>css:</p> <pre><code>div#mapcontainer { position:relative; width:100%; height: 600px; } div#main { position:absolute; top: 0; left: 10px; width: 500px; height: 400px; } div#sidebar { position:absolute; top:10px; right:10px; width: 155px; height: 405px;} </code></pre> <p>html:</p> <pre><code>&lt;div id="container"&gt; &lt;div id="main"&gt;variable height content here&lt;/div&gt; &lt;div id="sidebar"&gt; &lt;div id="foo"&gt;...&lt;/div&gt; &lt;div id="bar"&gt;....&lt;/div&gt; ... &lt;/div&gt; &lt;div&gt; </code></pre> <p>js:</p> <pre><code>fixHeights = function() { var children_height = 0; $('#sidebar'). children().each(function(){children_height += $(this).height();}); $('#container').height(Math.max(children_height, $('#main').height())); }; </code></pre>
[ { "answer_id": 317495, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": true, "text": "<div style=\"clear:both;\"></div>\n" }, { "answer_id": 317525, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 2, "selected": false, "text": "#wrapper:after {\n clear:both;\n content:\".\";\n display:block;\n height:0;\n visibility:hidden;\n}\n" }, { "answer_id": 4466288, "author": "Greg", "author_id": 545432, "author_profile": "https://Stackoverflow.com/users/545432", "pm_score": 0, "selected": false, "text": "Overflow:visible;" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20074/" ]
317,527
<p>I know a lot about C# but this one is stumping me and Google isn't helping.</p> <p>I have an IEnumerable range of objects. I want to set a property on the first one. I do so, but when I enumerate over the range of objects after the modification, I don't see my change.</p> <p>Here's a good example of the problem:</p> <pre><code> public static void GenericCollectionModifier() { // 1, 2, 3, 4... 10 var range = Enumerable.Range(1, 10); // Convert range into SubItem classes var items = range.Select(i =&gt; new SubItem() {Name = "foo", MagicNumber = i}); Write(items); // Expect to output 1,2,3,4,5,6,7,8,9,10 // Make a change items.First().MagicNumber = 42; Write(items); // Expect to output 42,2,3,4,5,6,7,8,9,10 // Actual output: 1,2,3,4,5,6,7,8,9,10 } public static void Write(IEnumerable&lt;SubItem&gt; items) { Console.WriteLine(string.Join(", ", items.Select(item =&gt; item.MagicNumber.ToString()).ToArray())); } public class SubItem { public string Name; public int MagicNumber; } </code></pre> <p>What aspect of C# stops my "MagicNumber = 42" change from being output? Is there a way I can get my change to "stick" without doing some funky converting to List&lt;> or array?</p> <p>Thanks! -Mike</p>
[ { "answer_id": 317544, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 0, "selected": false, "text": "// Convert range into SubItem classes\nvar items = range.Select(i => new SubItem() {Name = \"foo\", MagicNumber = i});\n" }, { "answer_id": 317549, "author": "Simon Steele", "author_id": 4591, "author_profile": "https://Stackoverflow.com/users/4591", "pm_score": 4, "selected": true, "text": "Select(i => new SubItem() {Name = \"foo\", MagicNumber = i});\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5198/" ]
317,531
<p>given the following code: </p> <pre><code>import ctypes ip="192.168.1.1" thisdll = ctypes.cdll['aDLL'] thisdll.functionThatExpectsAnIP(ip) </code></pre> <p>how can I correctly pack this for a DLL that expects it as a c_ulong datatype?</p> <p>I've tried using: </p> <pre><code>ip_netFrmt = socket.inet_aton(ip) ip_netFrmt_c = ctypes.c_ulong(ip_netFrmt) </code></pre> <p>however, the <code>c_ulong()</code> method returns an error because it needs an integer. </p> <p>is there a way to use <code>struct.pack</code> to accomplish this? </p>
[ { "answer_id": 317572, "author": "user7461", "author_id": 7461, "author_profile": "https://Stackoverflow.com/users/7461", "pm_score": 0, "selected": false, "text": "ip=\"192.168.1.1\"\nip_long = reduce(lambda x,y:x*256+int(y), ip.split('.'), 0)\n" }, { "answer_id": 317577, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 0, "selected": false, "text": ">>> ip = \"192.168.1.1\"\n>>> struct.unpack('>I', struct.pack('BBBB', *map(int, ip.split('.'))))[0]\n3232235777L\n" }, { "answer_id": 317583, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 4, "selected": true, "text": ">>> import socket\n>>> packed_n= socket.inet_aton(\"128.0.0.1\")\n>>> import struct\n>>> struct.unpack( \"!L\", packed_n )\n(2147483649L,)\n>>> hex(_[0])\n'0x80000001L'\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40637/" ]
317,567
<p>How do I add new record to DataGridView control in VB.Net?</p> <p>I don't use dataset or database binding. I have a small form with 3 fields and when the user clicks OK they should be added to the DataGridView control as a new row.</p>
[ { "answer_id": 317624, "author": "GWLlosa", "author_id": 18071, "author_profile": "https://Stackoverflow.com/users/18071", "pm_score": 2, "selected": false, "text": "myDataGridView.Rows.Insert(4,new object[]{value1,value2,value3});\n" }, { "answer_id": 319052, "author": "codeConcussion", "author_id": 1321, "author_profile": "https://Stackoverflow.com/users/1321", "pm_score": 5, "selected": false, "text": "DataGridView1.Rows.Add(New String(){Value1, Value2, Value3})\n" }, { "answer_id": 5511021, "author": "Mr.Buntha Khin", "author_id": 551920, "author_profile": "https://Stackoverflow.com/users/551920", "pm_score": 1, "selected": false, "text": "Dim dtdata As New DataTable()\n\ndtdata = CType(bndsData.DataSource, DataTable)\n" }, { "answer_id": 9611966, "author": "Robert", "author_id": 1244656, "author_profile": "https://Stackoverflow.com/users/1244656", "pm_score": 1, "selected": false, "text": "DataGridView" }, { "answer_id": 12701166, "author": "cjbarth", "author_id": 271351, "author_profile": "https://Stackoverflow.com/users/271351", "pm_score": 1, "selected": false, "text": "Dim previousAllowUserToAddRows = dgvHistoricalInfo.AllowUserToAddRows\ndgvHistoricalInfo.AllowUserToAddRows = True\n\nDim newTimeRecord As DataGridViewRow = dgvHistoricalInfo.Rows(dgvHistoricalInfo.NewRowIndex).Clone\n\nWith record\n newTimeRecord.Cells(dgvcDate.Index).Value = .Date\n newTimeRecord.Cells(dgvcHours.Index).Value = .Hours\n newTimeRecord.Cells(dgvcRemarks.Index).Value = .Remarks\nEnd With\n\ndgvHistoricalInfo.Rows.Add(newTimeRecord)\n\ndgvHistoricalInfo.AllowUserToAddRows = previousAllowUserToAddRows\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317567", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,576
<p>I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields are varchar - last_name and first_name.</p> <p>When rows are inserted into this table, the first name and last name fields are supposed to be in all upper case, but somehow some values in these two fields are mixed case.</p> <p>I want to run a query that will show me all of the rows in the table that have first or last names with lowercase characters in it.</p> <p>I searched the net and found REGEXP_LIKE, but that must be for newer versions of oracle - it doesn't seem to work for me.</p> <p>Another thing I tried was to translate "abcde...z" to "$$$$$...$" and then search for a '$' in my field, but there has to be a better way?</p> <p>Thanks in advance!</p>
[ { "answer_id": 317601, "author": "BQ.", "author_id": 4632, "author_profile": "https://Stackoverflow.com/users/4632", "pm_score": 7, "selected": true, "text": "select id, first, last from mytable\nwhere first != upper(first) or last != upper(last);\n" }, { "answer_id": 317657, "author": "BrianH", "author_id": 40619, "author_profile": "https://Stackoverflow.com/users/40619", "pm_score": 2, "selected": false, "text": "first_name last_name\n---------- ---------\nbob johnson\nBob Johnson\nBOB JOHNSON\n" }, { "answer_id": 11741251, "author": "Piyush K", "author_id": 1565869, "author_profile": "https://Stackoverflow.com/users/1565869", "pm_score": 0, "selected": false, "text": " SELECT * \n FROM mytable \n WHERE FIRST_NAME IN (SELECT FIRST_NAME \n FROM MY_TABLE\n MINUS \n SELECT UPPER(FIRST_NAME) \n FROM MY_TABLE )\n" }, { "answer_id": 27226964, "author": "Dave", "author_id": 4311346, "author_profile": "https://Stackoverflow.com/users/4311346", "pm_score": -1, "selected": false, "text": "SELECT * FROM tbl_user WHERE LEFT(username,1) COLLATE Latin1_General_CS_AI <> UPPER(LEFT(username,1))\n" }, { "answer_id": 39191534, "author": "Sarath Subramanian", "author_id": 3312636, "author_profile": "https://Stackoverflow.com/users/3312636", "pm_score": 1, "selected": false, "text": "Column1\n.......\nMISS\nmiss\nMiSS\n" }, { "answer_id": 47526338, "author": "Quyen ht", "author_id": 9018741, "author_profile": "https://Stackoverflow.com/users/9018741", "pm_score": 0, "selected": false, "text": "SELECT * FROM YOU_TABLE WHERE REGEXP_LIKE(COLUMN1,'[a-z]','c'); => Miss, miss lower text\nSELECT * FROM YOU_TABLE WHERE REGEXP_LIKE(COLUMN1,'[A-Z]','c'); => Miss, MISS upper text\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40619/" ]
317,580
<p>I'm looking for the best way to interpret the standard (well, standardish) Ethernet PHY registers, to determine the speed that an Ethernet link is actually running at. (e.g. 10/100/1000 and full/half-duplex)</p> <p>I daresay that this is to be found in the source of things like Linux, and I'm just off to look there now, but if anyone has a good reference I'd be interested.</p> <p>What I'm interested in is if it actually linked and what it linked at, rather than the vast sea of possibilities that each end has advertised at the outset.</p>
[ { "answer_id": 317601, "author": "BQ.", "author_id": 4632, "author_profile": "https://Stackoverflow.com/users/4632", "pm_score": 7, "selected": true, "text": "select id, first, last from mytable\nwhere first != upper(first) or last != upper(last);\n" }, { "answer_id": 317657, "author": "BrianH", "author_id": 40619, "author_profile": "https://Stackoverflow.com/users/40619", "pm_score": 2, "selected": false, "text": "first_name last_name\n---------- ---------\nbob johnson\nBob Johnson\nBOB JOHNSON\n" }, { "answer_id": 11741251, "author": "Piyush K", "author_id": 1565869, "author_profile": "https://Stackoverflow.com/users/1565869", "pm_score": 0, "selected": false, "text": " SELECT * \n FROM mytable \n WHERE FIRST_NAME IN (SELECT FIRST_NAME \n FROM MY_TABLE\n MINUS \n SELECT UPPER(FIRST_NAME) \n FROM MY_TABLE )\n" }, { "answer_id": 27226964, "author": "Dave", "author_id": 4311346, "author_profile": "https://Stackoverflow.com/users/4311346", "pm_score": -1, "selected": false, "text": "SELECT * FROM tbl_user WHERE LEFT(username,1) COLLATE Latin1_General_CS_AI <> UPPER(LEFT(username,1))\n" }, { "answer_id": 39191534, "author": "Sarath Subramanian", "author_id": 3312636, "author_profile": "https://Stackoverflow.com/users/3312636", "pm_score": 1, "selected": false, "text": "Column1\n.......\nMISS\nmiss\nMiSS\n" }, { "answer_id": 47526338, "author": "Quyen ht", "author_id": 9018741, "author_profile": "https://Stackoverflow.com/users/9018741", "pm_score": 0, "selected": false, "text": "SELECT * FROM YOU_TABLE WHERE REGEXP_LIKE(COLUMN1,'[a-z]','c'); => Miss, miss lower text\nSELECT * FROM YOU_TABLE WHERE REGEXP_LIKE(COLUMN1,'[A-Z]','c'); => Miss, MISS upper text\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317580", "https://Stackoverflow.com", "https://Stackoverflow.com/users/987/" ]
317,587
<p>The navigation on the left menu in the below site uses CSS for mouseover links.<br /><a href="http://www.pvh.com/" rel="nofollow noreferrer">PVH</a></p> <p>When I take the code of the navigation and make it separate page. Then the mouseover links are not working. What could be the reason?<br /> <a href="http://shivanand.in/tmp/navigation.html" rel="nofollow noreferrer">Test</a></p>
[ { "answer_id": 317595, "author": "philistyne", "author_id": 16597, "author_profile": "https://Stackoverflow.com/users/16597", "pm_score": 3, "selected": true, "text": "<script src=\"menu_1b.js\" type=\"text/javascript\">\n</script>\n<script src=\"menu_com.js\" type=\"text/javascript\">\n" }, { "answer_id": 317639, "author": "Ian G", "author_id": 31765, "author_profile": "https://Stackoverflow.com/users/31765", "pm_score": 1, "selected": false, "text": "http://www.pvh.com/menu_1b.js\nhttp://www.pvh.com/menu_com.js\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34642/" ]
317,591
<p>is it possible to create my own custom keys in the asp.net web.config file and iterate through them with C#? How do you do both (where do I put the key? what format?)? I have an application for an intranet that does certain things based upon the IP address of the client. Instead of hard coding those in the codebehind file, I thought I would put them in the web.config and iterate through that. That way I could add or remove from my configuration file without recompiling everything.</p> <p>My key would have a name, IP address, and maybe other information.</p> <p>Thank you.</p>
[ { "answer_id": 317643, "author": "Bjørn Stærk", "author_id": 36164, "author_profile": "https://Stackoverflow.com/users/36164", "pm_score": 2, "selected": false, "text": "<configuration>\n <configSections>\n <sectionGroup name=\"MySectionGroup\">\n <section name=\"MySection\" type=\"[type and full assembly name]\"/>\n\n ...\n <MySectionGroup>\n <MySection>\n [some xml]\n" }, { "answer_id": 2524147, "author": "Solburn", "author_id": 75755, "author_profile": "https://Stackoverflow.com/users/75755", "pm_score": 5, "selected": true, "text": "<configSections>\n <section name=\"DataBaseKeys\" type=\"System.Configuration.NameValueFileSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"/>\n</configSections>\n<DataBaseKeys>\n <!--Connection Strings for databases (or IP Addresses or whatever)-->\n <add key=\"dbCon1\" value=\"Data Source=DbServerPath;Integrated Security=True;database=DbName1\"/>\n <add key=\"dbCon2\" value=\"Data Source=DbServerPath;Integrated Security=True;database=DbName1\"/>\n <add key=\"dbCon3\" value=\"Data Source=DbServerPath;Integrated Security=True;database=DbName1\"/>\n <add key=\"dbCon4\" value=\"Data Source=DbServerPath;Integrated Security=True;database=DbName1\"/>\n <add key=\"dbCon5\" value=\"Data Source=DbServerPath;Integrated Security=True;database=DbName1\"/> \n</DataBaseKeys>\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28045/" ]
317,606
<p>How can I select multiple elements using a WHERE...IN... type of clause as in</p> <pre><code>select * from orders where orderid in (1, 4, 5) </code></pre> <p>in LinqToSql? I'd prefer not to have a lambda expression since they scare me.</p>
[ { "answer_id": 317608, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 5, "selected": true, "text": "int[] validIds = { 1, 4, 5 };\nvar query = from order in db.Orders\n where validIds.Contains(order.Id)\n select order\n" }, { "answer_id": 317612, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 0, "selected": false, "text": "int[] arry = new int[] {1,4,5};\n\nvar q = from r in orders\n where Array.IndexOf(array, orderid) != -1\n select r;\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16440/" ]
317,611
<p>I have a view which contains a form, the form posts and the data gets processed etc, then I want to return the view Index, so return view("Index");</p> <p>however this will then complain about my ViewData not existing, I get the feeling that the controller code under Index() isn't being processed which adds the list it requires to the ViewData, anyone know what's wrong?</p> <p>Thanks</p> <p>edit: Apparently it's done to prevent recursion.. in which case, I'm lost as to what to do without repeating all my ViewData stuff both Controllers</p>
[ { "answer_id": 317753, "author": "CodeClimber", "author_id": 4724, "author_profile": "https://Stackoverflow.com/users/4724", "pm_score": 7, "selected": true, "text": "return RedirectToAction(\"Index\")" }, { "answer_id": 327031, "author": "Matthew", "author_id": 20162, "author_profile": "https://Stackoverflow.com/users/20162", "pm_score": 3, "selected": false, "text": "return View(\"Index\");" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317611", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29445/" ]
317,617
<p>I would like to write a utility that will provide me with a relatively unique ID in Java. Something pretty simple, like x bits from timestamp + y bits from random number.</p> <p>So, how would I implement the following method:</p> <pre><code>long getUniqueID() { long timestamp = System.currentTimeMillis(); long random = some random long ... return id; } </code></pre> <p>BONUS</p> <p>Any suggestions for other easily obtainable information I could use to form my ID?</p> <p>note: I am aware of GUIDs and I know Java has a UUID class, but I don't want something that is 128 bits long.</p>
[ { "answer_id": 317634, "author": "phihag", "author_id": 35070, "author_profile": "https://Stackoverflow.com/users/35070", "pm_score": 3, "selected": true, "text": "return java.util.UUID.randomUUID().getLeastSignificantBits();\n" }, { "answer_id": 319117, "author": "RealHowTo", "author_id": 25122, "author_profile": "https://Stackoverflow.com/users/25122", "pm_score": 1, "selected": false, "text": "public class UniqueID {\n static long current= System.currentTimeMillis();\n static public synchronized long get(){\n return current++;\n }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20498/" ]
317,619
<p>When ever I think I can use the yield keyword, I take a step back and look at how it will impact my project. I always end up returning a collection instead of yeilding because I feel the overhead of maintaining the state of the yeilding method doesn't buy me much. In almost all cases where I am returning a collection I feel that 90% of the time, the calling method will be iterating over all elements in the collection, or will be seeking a series of elements throughout the entire collection. </p> <p>I do understand its usefulness in linq, but I feel that only the linq team is writing such complex queriable objects that yield is useful.</p> <p>Has anyone written anything like or not like linq where yield was useful?</p>
[ { "answer_id": 317636, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 5, "selected": false, "text": "IEnumerator<T> Filter(this IEnumerator<T> coll, Func<T, bool> func)\n{\n foreach(T t in coll)\n if (func(t)) yield return t;\n}\n" }, { "answer_id": 317680, "author": "Pieter Breed", "author_id": 24172, "author_profile": "https://Stackoverflow.com/users/24172", "pm_score": 1, "selected": false, "text": "static IEnumerable<Person> GetAllPeople()\n{\n return new List<Person>()\n {\n new Person() { Name = \"George\", Surname = \"Bush\", City = \"Washington\" },\n new Person() { Name = \"Abraham\", Surname = \"Lincoln\", City = \"Washington\" },\n new Person() { Name = \"Joe\", Surname = \"Average\", City = \"New York\" }\n };\n}\n\nstatic IEnumerable<Person> GetPeopleFrom(this IEnumerable<Person> people, string where)\n{\n foreach (var person in people)\n {\n if (person.City == where) yield return person;\n }\n yield break;\n}\n\nstatic IEnumerable<Person> GetPeopleWithInitial(this IEnumerable<Person> people, string initial)\n{\n foreach (var person in people)\n {\n if (person.Name.StartsWith(initial)) yield return person;\n }\n yield break;\n}\n\nstatic void Main(string[] args)\n{\n var people = GetAllPeople();\n foreach (var p in people.GetPeopleFrom(\"Washington\"))\n {\n // do something with washingtonites\n }\n\n foreach (var p in people.GetPeopleWithInitial(\"G\"))\n {\n // do something with people with initial G\n }\n\n foreach (var p in people.GetPeopleWithInitial(\"P\").GetPeopleFrom(\"New York\"))\n {\n // etc\n }\n}\n" }, { "answer_id": 317683, "author": "macropas", "author_id": 40220, "author_profile": "https://Stackoverflow.com/users/40220", "pm_score": 2, "selected": false, "text": " public static class FuncUtils\n {\n public delegate T Func<T>();\n public delegate T Func<A0, T>(A0 arg0);\n public delegate T Func<A0, A1, T>(A0 arg0, A1 arg1);\n ... \n\n public static IEnumerable<T> Filter<T>(IEnumerable<T> e, Func<T, bool> filterFunc)\n {\n foreach (T el in e)\n if (filterFunc(el)) \n yield return el;\n }\n\n\n public static IEnumerable<R> Map<T, R>(IEnumerable<T> e, Func<T, R> mapFunc)\n {\n foreach (T el in e) \n yield return mapFunc(el);\n }\n ...\n" }, { "answer_id": 317695, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": false, "text": "for (DateTime date = schedule.StartDate; date <= schedule.EndDate; \n date = date.AddDays(1))\n" }, { "answer_id": 317852, "author": "Anton", "author_id": 341413, "author_profile": "https://Stackoverflow.com/users/341413", "pm_score": 0, "selected": false, "text": "public IEnumerable<string> GetData()\n{\n foreach(String name in _someInternalDataCollection)\n {\n yield return name;\n }\n}\n\n...\n\npublic void DoSomething()\n{\n foreach(String value in GetData())\n {\n //... Do something with value that doesn't modify _someInternalDataCollection\n }\n}\n" }, { "answer_id": 317896, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 3, "selected": false, "text": "yield" }, { "answer_id": 318116, "author": "Morten Christiansen", "author_id": 4055, "author_profile": "https://Stackoverflow.com/users/4055", "pm_score": 5, "selected": true, "text": "public IEnumerator<Expression<T>> GetEnumerator()\n{\n if (IsLeaf)\n {\n yield return this;\n }\n else\n {\n foreach (Expression<T> expr in LeftExpression)\n {\n yield return expr;\n }\n foreach (Expression<T> expr in RightExpression)\n {\n yield return expr;\n }\n yield return this;\n }\n}\n" }, { "answer_id": 335853, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 4, "selected": false, "text": "IList<string> LoadStuff() {\n var ret = new List<string>();\n foreach(var x in SomeExternalResource)\n ret.Add(x);\n return ret;\n}\n" }, { "answer_id": 3813106, "author": "Ohad Schneider", "author_id": 67824, "author_profile": "https://Stackoverflow.com/users/67824", "pm_score": 0, "selected": false, "text": "public static class CollectionSampling\n{\n public static IEnumerable<T> Sample<T>(this IEnumerable<T> coll, int max)\n {\n var rand = new Random();\n using (var enumerator = coll.GetEnumerator());\n {\n while (enumerator.MoveNext())\n {\n yield return enumerator.Current; \n int currentSample = rand.Next(max);\n for (int i = 1; i <= currentSample; i++)\n enumerator.MoveNext();\n }\n }\n } \n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45/" ]
317,621
<p>I have a ComboBox inside of a cell of a DataGridView Row on a Windows form. I need the following to happen: </p> <ol> <li>click on the ComboBox</li> <li>pick a value</li> <li>recalculate a total &amp; display inside of a lable that is sitting outside of the DataGridView.</li> </ol> <p>Currently, the following is happening: </p> <ol> <li>Click on the ComboBox</li> <li>Click it again to open the CB's Drop-down list</li> <li>select a value</li> <li>click outside of the cell to force a recalculation of the external label.</li> </ol> <p>I want to avoid, first, having to click the combo twice (once to set focus, and again to select the value). Second, I'd like for a live recalculation to happen after selecting a value.</p> <p>Does anyone have a trick or two to solve any of these?</p> <p>I've tried most of the events on the DGV without much luck.</p>
[ { "answer_id": 317658, "author": "kͩeͣmͮpͥ ͩ", "author_id": 26479, "author_profile": "https://Stackoverflow.com/users/26479", "pm_score": 3, "selected": true, "text": "private void vehicleTypeGridView_CellClick(object sender, DataGridViewCellEventArgs e)\n{\n if ( e.RowIndex == - 1 ) return; //Header Cell clicked -> ignore it.\n vehicleTypeGridView.BeginEdit ( true );\n var control = vehicleTypeGridView.EditingControl as DataGridViewComboBoxEditingControl;\n if ( control != null ) control.DroppedDown = true;\n}\n" }, { "answer_id": 4868112, "author": "Mark B", "author_id": 599099, "author_profile": "https://Stackoverflow.com/users/599099", "pm_score": 1, "selected": false, "text": "datagridview.EditMode = Windows.Forms.DataGridViewEditMode.EditOnEnter\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29990/" ]
317,630
<p>when i point my browser to <code>http://localhost/phpmyadmin</code>, instead of showing me its front page, it comes up with save as dialog.</p> <p>I'm running: Apache/2.2.3 (Debian) PHP/5.2.0-8+etch13 Server </p> <p>I've reinstalled both apache2 and php5. After re-install i don't have httpd.conf file, how can i get it back? Is there a standard file which i can just copy into /etc/apache2?</p> <p>I did a locate httpd.conf and the only file i got was the empty file i have under /etc/apache2/ which i made.</p>
[ { "answer_id": 317707, "author": "Vincent Van Den Berghe", "author_id": 39259, "author_profile": "https://Stackoverflow.com/users/39259", "pm_score": 2, "selected": false, "text": "httpd.conf" }, { "answer_id": 318686, "author": "Stepan Mazurov", "author_id": 40786, "author_profile": "https://Stackoverflow.com/users/40786", "pm_score": 1, "selected": false, "text": "$>locate httpd.conf\n/etc/httpd/conf/httpd.conf\n$>vim /etc/httpd/conf/httpd.conf" }, { "answer_id": 26523674, "author": "Nham Nguyen", "author_id": 4173041, "author_profile": "https://Stackoverflow.com/users/4173041", "pm_score": 2, "selected": false, "text": "sudo nano /etc/apache2/mods-available/suphp.conf\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37603/" ]
317,647
<p>I've attempted to use the EstimatedSize value during creation of an uninstaller registry key for an app I've developed, unfortunately the value I specify does not appear in the Add/Remove Program list next to my program's entry. I've tried to find the proper procedure for using this value but to no avail. Anyone have any experience on this issue? Your help would be appreciated.</p> <p><strong>Divo</strong> got me on the right track so I figured I'd post step-by-step instructions on how to correctly display the EstimatedSize value.</p> <ol> <li>Create the registry key with all relevant properties, including EstimatedSize. This value will be replicated in the ARPCache key in the registry</li> <li>Find the registry key inside the ARPCache folder, delete the SlowInfoCache binary value, and set the Changed value to 1.</li> <li>Next time the Add/Remove Programs list is opened you will see the value you specified in the EstimatedSize entry, not the arbitrary Windows generated one.</li> </ol>
[ { "answer_id": 318637, "author": "Dirk Vollmar", "author_id": 40347, "author_profile": "https://Stackoverflow.com/users/40347", "pm_score": 3, "selected": true, "text": "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{my-guid-value}\n" }, { "answer_id": 1765801, "author": "user214888", "author_id": 214888, "author_profile": "https://Stackoverflow.com/users/214888", "pm_score": 2, "selected": false, "text": "[...]\n\n; ARP = just convenience variable to hold the long reg key path\n!define ARP \"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${APPNAME}\"\n\n[...]\n\n; Specify a section ID like SEC_01, for obtaining its size in kilobytes later\nSection \"Install\" SEC_01\n\n; [...copy all files here, before SectionGetSize...]\n\n; Obtain the size of the files, in kilobytes, in section SEC_01\nSectionGetSize \"${SEC_01}\" $0\n\n; Create/Write the reg key with the dword value\nWriteRegDWORD HKLM \"${ARP}\" \"EstimatedSize\" \"$0\"\n\n[...write the other keys in the same reg path...]\n\nSectionEnd\n\n[...]\n" }, { "answer_id": 7095451, "author": "Carlos", "author_id": 898962, "author_profile": "https://Stackoverflow.com/users/898962", "pm_score": 1, "selected": false, "text": "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\\\{app_name}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317647", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40662/" ]
317,649
<p>The scenario is:</p> <ol> <li>svn cp or mv some file</li> <li>modify that file</li> <li>svn diff > mypatch</li> </ol> <p>On other machine (same working copy, but no changes):</p> <ol start="4"> <li>Try to apply mypatch.</li> <li>Fail -> tries to modify unexistant file.</li> </ol> <p>How can I make svn diff produce patch-appliable patch, or cleanly apply patch produced by svn diff in this case? I can't commit. I would like to preserve mergeinfo (because the obvious workaround is to add the file as totally new, without connection to the previous one).</p>
[ { "answer_id": 319853, "author": "Ray", "author_id": 40866, "author_profile": "https://Stackoverflow.com/users/40866", "pm_score": 6, "selected": false, "text": "svn diff --diff-cmd /usr/bin/diff -x \"-i -b\" > mypatch\n...\npatch -p0 < mypatch\n" }, { "answer_id": 15533829, "author": "Adrian Pronk", "author_id": 41861, "author_profile": "https://Stackoverflow.com/users/41861", "pm_score": 3, "selected": false, "text": "--show-copies-as-adds" }, { "answer_id": 36875766, "author": "Apteryx", "author_id": 2896799, "author_profile": "https://Stackoverflow.com/users/2896799", "pm_score": 4, "selected": false, "text": "svn diff --patch-compatible > mypatch.diff\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9403/" ]
317,679
<p>Which one is recommended considering readability, memory usage, other reasons?</p> <p><strong>1.</strong></p> <pre><code>String strSomething1 = someObject.getSomeProperties1(); strSomething1 = doSomeValidation(strSomething1); String strSomething2 = someObject.getSomeProperties2(); strSomething2 = doSomeValidation(strSomething2); String strSomeResult = strSomething1 + strSomething2; someObject.setSomeProperties(strSomeResult); </code></pre> <p><strong>2.</strong></p> <pre><code>someObject.setSomeProperties(doSomeValidation(someObject.getSomeProperties1()) + doSomeValidation(someObject.getSomeProperties2())); </code></pre> <p>If you would do it some other way, what would that be? Why would you do that way?</p>
[ { "answer_id": 317694, "author": "Greg", "author_id": 28002, "author_profile": "https://Stackoverflow.com/users/28002", "pm_score": 4, "selected": false, "text": "String strSomething1 = someObject.getSomeProperties1();\nString strSomething2 = someObject.getSomeProperties2();\n\n// clean-up spaces\nstrSomething1 = removeTrailingSpaces(strSomething1);\nstrSomething2 = removeTrailingSpaces(strSomething2);\n\nsomeObject.setSomeProperties(strSomething1 + strSomething2);\n" }, { "answer_id": 317706, "author": "bradheintz", "author_id": 40093, "author_profile": "https://Stackoverflow.com/users/40093", "pm_score": 5, "selected": true, "text": "String strSomething1 = doSomeValidation(someObject.getSomeProperties1());\nString strSomething2 = doSomeValidation(someObject.getSomeProperties2());\nsomeObject.setSomeProperties(strSomething1 + strSomething2);\n" }, { "answer_id": 317708, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 3, "selected": false, "text": "someObject.setSomeProperties(\n doSomeValidation( someObject.getSomeProperties1() ) + \n doSomeValidation( someObject.getSomeProperties2() ));\n" }, { "answer_id": 317710, "author": "Argelbargel", "author_id": 2992, "author_profile": "https://Stackoverflow.com/users/2992", "pm_score": 2, "selected": false, "text": "validatedProp1 = doValidation(someObject.getSomeProperty1());\nvalidatedProp2 = doValidation(someObject.getSomeProperty2());\nsomeObject.setSomeProperties(validatedProp1, validatedProp2);\n" }, { "answer_id": 318020, "author": "Aaron Digulla", "author_id": 34088, "author_profile": "https://Stackoverflow.com/users/34088", "pm_score": 2, "selected": false, "text": "setX(getX().getY()+getA().getB())\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317679", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37740/" ]
317,684
<p>Hi I have a view with several User Controls and I pass ViewData to all of them, I would like to know how you would determine the element count by specifying the string key. I understand that you cannot use comparison to an integer because ViewData is an object but I have it setup this way for explaining my question. I have also tried null but The ViewData object is never null, even for results where no data is populated in the ViewData. I.e</p> <p>In my View</p> <pre><code> &lt;%if(ViewData["Test"].Values &gt; 0) { %&gt; &lt;%=Html.RenderPartial("~/Views/UC/Test.ascx", ViewData["Test"])%&gt; &lt;% } %&gt; </code></pre>
[ { "answer_id": 389065, "author": "Ayo", "author_id": 24130, "author_profile": "https://Stackoverflow.com/users/24130", "pm_score": 0, "selected": false, "text": "public ActionResult Test(){\n var test = //your query;\n if(test.Count() > 0 )\n {\n ViewData[\"Test\"] = test;\n }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24130/" ]
317,687
<p>I have a bunch of Spring beans which are picked up from the classpath via annotations, e.g.</p> <pre><code>@Repository("personDao") public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao { // Implementation omitted } </code></pre> <p>In the Spring XML file, there's a <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html" rel="noreferrer">PropertyPlaceholderConfigurer</a> defined:</p> <pre class="lang-xml prettyprint-override"><code>&lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="location" value="/WEB-INF/app.properties" /&gt; &lt;/bean&gt; </code></pre> <p>I want to inject one of the properties from app.properites into the bean shown above. I can't simply do something like </p> <pre class="lang-xml prettyprint-override"><code>&lt;bean class="com.example.PersonDaoImpl"&gt; &lt;property name="maxResults" value="${results.max}"/&gt; &lt;/bean&gt; </code></pre> <p>Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations). I've got as far as the following:</p> <pre><code>@Repository("personDao") public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao { @Resource(name = "propertyConfigurer") protected void setProperties(PropertyPlaceholderConfigurer ppc) { // Now how do I access results.max? } } </code></pre> <p>But it's not clear to me how I access the property I'm interested in from <code>ppc</code>?</p>
[ { "answer_id": 318188, "author": "Dónal", "author_id": 2648, "author_profile": "https://Stackoverflow.com/users/2648", "pm_score": 3, "selected": false, "text": "<bean id=\"propertyConfigurer\" class=\"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer\">\n <property name=\"location\" value=\"/WEB-INF/app.properties\" />\n</bean> \n\n<util:properties id=\"appProperties\" location=\"classpath:/WEB-INF/app.properties\"/>\n" }, { "answer_id": 318195, "author": "Dónal", "author_id": 2648, "author_profile": "https://Stackoverflow.com/users/2648", "pm_score": 4, "selected": false, "text": "<bean id=\"propertyConfigurer\" \n class=\"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer\">\n <property name=\"location\" value=\"/WEB-INF/app.properties\" />\n</bean> \n\n\n<bean id=\"appProperties\" \n class=\"org.springframework.beans.factory.config.PropertiesFactoryBean\">\n <property name=\"singleton\" value=\"true\"/>\n\n <property name=\"properties\">\n <props>\n <prop key=\"results.max\">${results.max}</prop>\n </props>\n </property>\n</bean>\n" }, { "answer_id": 319963, "author": "DaWilli", "author_id": 33974, "author_profile": "https://Stackoverflow.com/users/33974", "pm_score": 3, "selected": false, "text": "<bean id=\"appProperties\" class=\"org.springframework.beans.factory.config.PropertiesFactoryBean\">\n <property name=\"singleton\" value=\"true\" />\n\n <property name=\"ignoreResourceNotFound\" value=\"true\" />\n <property name=\"locations\">\n <list>\n <value>classpath:live.properties</value>\n <value>classpath:development.properties</value>\n </list>\n </property>\n</bean>\n" }, { "answer_id": 339811, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 9, "selected": true, "text": "@Value(\"#{systemProperties.databaseName}\")\npublic void setDatabaseName(String dbName) { ... }\n\n@Value(\"#{strategyBean.databaseKeyGenerator}\")\npublic void setKeyGenerator(KeyGenerator kg) { ... }\n" }, { "answer_id": 577266, "author": "Ricardo Gladwell", "author_id": 48611, "author_profile": "https://Stackoverflow.com/users/48611", "pm_score": 3, "selected": false, "text": "@Property(key=\"property.key\", defaultValue=\"default\")\npublic void setProperty(String property) {\n this.property = property;\n}\n" }, { "answer_id": 1192859, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "@Value" }, { "answer_id": 1922161, "author": "Nik", "author_id": 233833, "author_profile": "https://Stackoverflow.com/users/233833", "pm_score": 2, "selected": false, "text": " <bean id=\"someFile\" class=\"java.io.File\">\n <constructor-arg value=\"${someFile}\"/>\n </bean>\n" }, { "answer_id": 7675420, "author": "barrymac", "author_id": 218635, "author_profile": "https://Stackoverflow.com/users/218635", "pm_score": 7, "selected": false, "text": "private @Value(\"${propertyName}\") String propertyField;\n" }, { "answer_id": 13161231, "author": "shane lee", "author_id": 354254, "author_profile": "https://Stackoverflow.com/users/354254", "pm_score": 5, "selected": false, "text": "<context:property-placeholder ... />" }, { "answer_id": 17160644, "author": "ben3000", "author_id": 2495717, "author_profile": "https://Stackoverflow.com/users/2495717", "pm_score": 2, "selected": false, "text": "AutowiredFakaSource fakeDataSource = ctx.getBean(AutowiredFakaSource.class);\n" }, { "answer_id": 23172801, "author": "ravi ranjan", "author_id": 2556445, "author_profile": "https://Stackoverflow.com/users/2556445", "pm_score": -1, "selected": false, "text": "<bean id=\"placeholderConfig\"\n class=\"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer\">\n <property name=\"locations\">\n <list>\n <value>/WEB-INF/classes/config_properties/dev/database.properties</value>\n </list>\n </property> \n</bean>\n\n<bean id=\"devDataSource\" class=\"com.mchange.v2.c3p0.ComboPooledDataSource\" destroy-method=\"close\">\n <property name=\"driverClass\" value=\"${dev.app.jdbc.driver}\"/>\n <property name=\"jdbcUrl\" value=\"${dev.app.jdbc.url}\"/>\n <property name=\"user\" value=\"${dev.app.jdbc.username}\"/>\n <property name=\"password\" value=\"${dev.app.jdbc.password}\"/>\n <property name=\"acquireIncrement\" value=\"3\"/>\n <property name=\"minPoolSize\" value=\"5\"/>\n <property name=\"maxPoolSize\" value=\"10\"/>\n <property name=\"maxStatementsPerConnection\" value=\"11000\"/>\n <property name=\"numHelperThreads\" value=\"8\"/>\n <property name=\"idleConnectionTestPeriod\" value=\"300\"/>\n <property name=\"preferredTestQuery\" value=\"SELECT 0\"/>\n</bean> \n" }, { "answer_id": 27868289, "author": "Alexis Gamarra", "author_id": 832031, "author_profile": "https://Stackoverflow.com/users/832031", "pm_score": 3, "selected": false, "text": "@PropertySource(\"classpath:/com/myProject/config/properties/database.properties\")\n" }, { "answer_id": 37358733, "author": "Alireza Fattahi", "author_id": 2648077, "author_profile": "https://Stackoverflow.com/users/2648077", "pm_score": 4, "selected": false, "text": "@Value" }, { "answer_id": 40161960, "author": "Sergei Pikalev", "author_id": 1721870, "author_profile": "https://Stackoverflow.com/users/1721870", "pm_score": 1, "selected": false, "text": "package org.some.beans;\n\npublic class MyBean {\n Long id;\n String name;\n\n public void setId(Long id) {\n this.id = id;\n }\n\n public Long getId() {\n return id;\n }\n\n public void setName(String name) {\n this.name = name;\n }\n\n public String getName() {\n return name;\n }\n}\n" }, { "answer_id": 40248621, "author": "hi.nitish", "author_id": 5620851, "author_profile": "https://Stackoverflow.com/users/5620851", "pm_score": 3, "selected": false, "text": "private @Value(\"${propertyName}\") \nString propertyField;" }, { "answer_id": 62633789, "author": "Vikrant Chaudhary", "author_id": 5700910, "author_profile": "https://Stackoverflow.com/users/5700910", "pm_score": 0, "selected": false, "text": "@ConfigurationProperties" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2648/" ]
317,725
<p>I have a table with almost 800,000 records and I am currently using dynamic sql to generate the query on the back end. The front end is a search page which takes about 20 parameters and depending on if a parameter was chosen, it adds an " AND ..." to the base query. I'm curious as to if dynamic sql is the right way to go ( doesn't seem like it because it runs slow). I am contemplating on just creating a denormalized table with all my data. Is this a good idea or should I just build the query all together instead of building it piece by piece using the dynamic sql. Last thing, is there a way to speed up dynamic sql?</p>
[ { "answer_id": 317744, "author": "kͩeͣmͮpͥ ͩ", "author_id": 26479, "author_profile": "https://Stackoverflow.com/users/26479", "pm_score": 2, "selected": false, "text": "CREATE PROCEDURE GetArticlesByAuthor (\n @AuthorId int,\n @EarliestDate datetime = Null )\nAS\n SELECT * --not in production code!\n FROM Articles\n WHERE AuthorId = @AuthorId\n AND (@EarliestDate is Null OR PublishedDate < @EarliestDate)\n" }, { "answer_id": 318120, "author": "Charles Graham", "author_id": 7705, "author_profile": "https://Stackoverflow.com/users/7705", "pm_score": 1, "selected": false, "text": "WHERE col2 = @col2 AND col1 = @col1\n" }, { "answer_id": 318231, "author": "Logicalmind", "author_id": 26977, "author_profile": "https://Stackoverflow.com/users/26977", "pm_score": 3, "selected": false, "text": "AND (@EarliestDate is Null OR PublishedDate < @EarliestDate)\n" }, { "answer_id": 1602407, "author": "Jeremy", "author_id": 193991, "author_profile": "https://Stackoverflow.com/users/193991", "pm_score": 0, "selected": false, "text": "CREATE PROCEDURE GetArticlesByAuthor ( \n @AuthorId int, \n @EarliestDate datetime = Null \n ) AS \n\nSELECT SomeColumn\nFROM Articles \nWHERE AuthorId = @AuthorId \nAND @EarliestDate is Null\nUNION\nSELECT SomeColumn\nFROM Articles \nWHERE AuthorId = @AuthorId \nAND PublishedDate < @EarliestDate\n" }, { "answer_id": 8483700, "author": "crokusek", "author_id": 538763, "author_profile": "https://Stackoverflow.com/users/538763", "pm_score": 0, "selected": false, "text": " SET STATISTICS TIME ON;\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33690/" ]
317,733
<p>I'm trying to redirect the java compiler output to a file. I thought it's supposed to be:</p> <pre><code>javac file.java &gt; log.txt </code></pre> <p>or something. Instead, I see all the output on the terminal and nothing in log.txt!</p> <p>Also, if I want to log errors too, do I do</p> <pre><code>javac file.java 2&gt;&amp;1 &gt; log.txt </code></pre> <p>?</p>
[ { "answer_id": 317752, "author": "Julien Oster", "author_id": 40111, "author_profile": "https://Stackoverflow.com/users/40111", "pm_score": 5, "selected": true, "text": "javac file.java 2> log.txt\n" }, { "answer_id": 317756, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 3, "selected": false, "text": "javac -Xstdout log.txt file.java\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31301/" ]
317,743
<p>What is the best way to make the SSRS reporr fit in to PDF page.</p>
[ { "answer_id": 40588894, "author": "Laxman Gite", "author_id": 7156345, "author_profile": "https://Stackoverflow.com/users/7156345", "pm_score": 0, "selected": false, "text": "For PDF you have to change page settings while creating report check below steps for that :\n\nif you have large data on page you should choose below option\n->Right Click on report \n->Click on Page Setup option\n->Change page orientation Portrait to Landscape\n->Click on OK\n\nif you don't have large data on page you should reduce size of your table on report design page and change below setting:\n\n->Right Click on report \n->Click on Page Setup option\n->Change page orientation Landscape to Portrait\n->Click on OK\n\nNow check PDF file.\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,749
<p>I have a master page with one form on it. It is a search form which must always be visible. When the button of that form is clicked I want the form data to be sent to search.aspx. The problem is, I don't know how. I cannot set the form action to search.aspx, because all my other pages which use the master form will go to search.aspx. This I don't want.</p> <p>Hope someone can help me out :)</p> <p>Thnx.</p>
[ { "answer_id": 317935, "author": "Nick", "author_id": 14072, "author_profile": "https://Stackoverflow.com/users/14072", "pm_score": 0, "selected": false, "text": "<asp:Button ID=\"btnSearch\" runat=\"server\" Text=\"Search\" PostBackUrl=\"~/search.aspx\" />\n" }, { "answer_id": 317982, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 0, "selected": false, "text": "runat=\"server\"" }, { "answer_id": 318430, "author": "HectorMac", "author_id": 1400, "author_profile": "https://Stackoverflow.com/users/1400", "pm_score": 0, "selected": false, "text": "<body>\n <form action=\"search.aspx>\n <!--search box and submit button-->\n </form>\n <form runat=\"server\">\n <!--rest of page inc placeholder-->\n </form>\n</body>\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40676/" ]
317,759
<p>I have a .NET assembly which I am accessing from VBScript (classic ASP) via COM interop. One class has an indexer (a.k.a. default property) which I got working from VBScript by adding the following attribute to the indexer: <code>[DispId(0)]</code>. It works in most cases, but not when accessing the class as a member of another object.</p> <p>How can I get it to work with the following syntax: <code>Parent.Member("key")</code> where Member has the indexer (similar to accessing the default property of the built-in <code>Request.QueryString</code>: <code>Request.QueryString("key")</code>)?</p> <p>In my case, there is a parent class <code>TestRequest</code> with a <code>QueryString</code> property which returns an <code>IRequestDictionary</code>, which has the default indexer.</p> <p>VBScript example:</p> <pre><code>Dim testRequest, testQueryString Set testRequest = Server.CreateObject("AspObjects.TestRequest") Set testQueryString = testRequest.QueryString testQueryString("key") = "value" </code></pre> <p>The following line causes an error instead of printing "value". This is the syntax I would like to get working:</p> <pre><code>Response.Write(testRequest.QueryString("key")) </code></pre> <blockquote> <p>Microsoft VBScript runtime (0x800A01C2)<br> Wrong number of arguments or invalid property assignment: 'QueryString'</p> </blockquote> <p>However, the following lines <em>do</em> work without error and output the expected "value" (note that the first line accesses the default indexer on a temporary variable):</p> <pre><code>Response.Write(testQueryString("key")) Response.Write(testRequest.QueryString.Item("key")) </code></pre> <p>Below are the simplified interfaces and classes in C# 2.0. They have been registered via <code>RegAsm.exe /path/to/AspObjects.dll /codebase /tlb</code>:</p> <pre><code>[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IRequest { IRequestDictionary QueryString { get; } } [ClassInterface(ClassInterfaceType.None)] public class TestRequest : IRequest { private IRequestDictionary _queryString = new RequestDictionary(); public IRequestDictionary QueryString { get { return _queryString; } } } [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IRequestDictionary : IEnumerable { [DispId(0)] object this[object key] { [DispId(0)] get; [DispId(0)] set; } } [ClassInterface(ClassInterfaceType.None)] public class RequestDictionary : IRequestDictionary { private Hashtable _dictionary = new Hashtable(); public object this[object key] { get { return _dictionary[key]; } set { _dictionary[key] = value; } } } </code></pre> <p>I've tried researching and experimenting with various options but have not yet found a solution. Any help would be appreciated to figure out why the <code>testRequest.QueryString("key")</code> syntax is not working and how to get it working.</p> <p>Note: This is a followup to <a href="https://stackoverflow.com/questions/299251/exposing-the-indexer-default-property-via-com-interop">Exposing the indexer / default property via COM Interop</a>.</p> <p>Update: Here is some the generated IDL from the type library (using <a href="http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&amp;displaylang=en" rel="nofollow noreferrer">oleview</a>):</p> <pre><code>[ uuid(C6EDF8BC-6C8B-3AB2-92AA-BBF4D29C376E), version(1.0), custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, AspObjects.IRequest) ] dispinterface IRequest { properties: methods: [id(0x60020000), propget] IRequestDictionary* QueryString(); }; [ uuid(8A494CF3-1D9E-35AE-AFA7-E7B200465426), version(1.0), custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, AspObjects.IRequestDictionary) ] dispinterface IRequestDictionary { properties: methods: [id(00000000), propget] VARIANT Item([in] VARIANT key); [id(00000000), propputref] void Item( [in] VARIANT key, [in] VARIANT rhs); }; </code></pre>
[ { "answer_id": 321147, "author": "Mike Henry", "author_id": 14934, "author_profile": "https://Stackoverflow.com/users/14934", "pm_score": 1, "selected": false, "text": "testRequest.QueryString()(\"key\")" }, { "answer_id": 1539519, "author": "mdraghi", "author_id": 186600, "author_profile": "https://Stackoverflow.com/users/186600", "pm_score": 4, "selected": true, "text": " [ComVisible(true)]\n [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]\n public interface IRequest\n {\n IRequestDictionary ManagedQueryString { get; } // Property to use form managed code\n object QueryString(object key); // Property to use from COM or unmanaged code\n }\n\n [ComVisible(true)]\n [ClassInterface(ClassInterfaceType.None)]\n public class TestRequest : IRequest\n {\n private IRequestDictionary _queryString = new RequestDictionary();\n\n public IRequestDictionary ManagedQueryString\n {\n get { return _queryString; }\n }\n\n public object QueryString(object key)\n {\n if (key is System.Reflection.Missing || key == null)\n return _queryString;\n else\n return _queryString[key];\n }\n }\n\n [ComVisible(true)]\n [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]\n public interface IRequestDictionary : IEnumerable\n {\n [DispId(0)]\n object this[object key]\n {\n [DispId(0)]\n get;\n [DispId(0)]\n set;\n }\n\n int Count { get; }\n }\n\n [ComVisible(true)]\n [ClassInterface(ClassInterfaceType.None)]\n public class RequestDictionary : IRequestDictionary\n {\n private Hashtable _dictionary = new Hashtable();\n\n public object this[object key]\n {\n get { return _dictionary[key]; }\n set { _dictionary[key] = value; }\n }\n\n public int Count { get { return _dictionary.Count; } }\n\n #region IEnumerable Members\n\n public IEnumerator GetEnumerator()\n {\n throw new NotImplementedException();\n }\n\n #endregion\n }\n" }, { "answer_id": 1789681, "author": "David Lee", "author_id": 217766, "author_profile": "https://Stackoverflow.com/users/217766", "pm_score": 1, "selected": false, "text": "Default Public ReadOnly Property Item(ByVal key As Object) As string\n Get\n Return strSomeVal\n\n End Get\nEnd Property\n" }, { "answer_id": 4124031, "author": "David Porcher", "author_id": 500689, "author_profile": "https://Stackoverflow.com/users/500689", "pm_score": 3, "selected": false, "text": " [ClassInterface(ClassInterfaceType.None)]\n [IDispatchImpl(IDispatchImplType.CompatibleImpl)]\n public class TestRequest : IRequest\n {\n private IRequestDictionary _queryString = new RequestDictionary();\n public IRequestDictionary QueryString\n {\n get { return _queryString; }\n }\n }\n" }, { "answer_id": 6895916, "author": "Meir Eliezer", "author_id": 777492, "author_profile": "https://Stackoverflow.com/users/777492", "pm_score": 2, "selected": false, "text": " // Called by CLR to invoke a member\n object IReflect.InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters)\n {\n try\n {\n // Test if it is an indexed Property - Getter\n if (name != \"Item\" && (invokeAttr & BindingFlags.GetProperty) == BindingFlags.GetProperty && args.Length > 0 && this.GetType().GetProperty(name) != null)\n {\n object IndexedProperty = this.GetType().InvokeMember(name, invokeAttr, binder, target, null, modifiers, culture, namedParameters);\n return IndexedProperty.GetType().InvokeMember(\"Item\", invokeAttr, binder, IndexedProperty, args, modifiers, culture, namedParameters);\n }\n // Test if it is an indexed Property - Setter\n // args == 2 : args(0)=Position, args(1)=Vlaue\n if (name != \"Item\" && (invokeAttr & BindingFlags.PutDispProperty) == BindingFlags.PutDispProperty && (args.Length == 2) && this.GetType().GetProperty(name) != null)\n {\n // Get The indexer Property\n BindingFlags invokeAttr2 = BindingFlags.GetProperty;\n object IndexedProperty = this.GetType().InvokeMember(name, invokeAttr2, binder, target, null, modifiers, culture, namedParameters);\n\n // Invoke the Setter Property\n return IndexedProperty.GetType().InvokeMember(\"Item\", invokeAttr, binder, IndexedProperty, args, modifiers, culture, namedParameters);\n }\n\n\n // default InvokeMember\n return this.GetType().InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters);\n }\n catch (MissingMemberException ex)\n {\n // Well-known HRESULT returned by IDispatch.Invoke:\n const int DISP_E_MEMBERNOTFOUND = unchecked((int)0x80020003);\n throw new COMException(ex.Message, DISP_E_MEMBERNOTFOUND);\n }\n }\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14934/" ]
317,760
<p>I know on client side (javascript) you can use windows.location.hash but could not find anyway to access from the server side. I'm using asp.net.</p>
[ { "answer_id": 1586300, "author": "Chris", "author_id": 192140, "author_profile": "https://Stackoverflow.com/users/192140", "pm_score": 8, "selected": true, "text": "window.location.hash" }, { "answer_id": 35903078, "author": "webaholik", "author_id": 1296209, "author_profile": "https://Stackoverflow.com/users/1296209", "pm_score": 0, "selected": false, "text": "http://example.com/yourDirectory?hash=video01" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317760", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4191/" ]
317,762
<p>I get this error during checkout:</p> <pre><code>cvs checkout: warning: new-born file.java has disappeared cvs [checkout aborted]: cannot make directory : No such file or directory cvs status: cannot rewrite CVS/Entries.Backup: Permission denied </code></pre> <p>I'm sure I have the proper permissions to this folder and it happens even when I try to check out to a new one. I'm also sure that these files exist in cvs..</p> <p>my checkout command is:</p> <pre><code>cvs co -d dir -N -r(num) -r(num)... file file... and so on </code></pre> <p>What does this new-born thing mean?</p>
[ { "answer_id": 317876, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 2, "selected": false, "text": "new-born" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31301/" ]
317,780
<p>I have a MySQL table consisting of:</p> <pre><code>CREATE TABLE `url_list` ( `id` int(10) unsigned NOT NULL auto_increment, `crc32` int(10) unsigned NOT NULL, `url` varchar(512) NOT NULL, PRIMARY KEY (`id`), KEY `crc32` (`crc32`) ); </code></pre> <p>When inserting data into a related table I need to lookup the primary key from this table, and using the crc32 really speeds that up whilst allowing a small index. The URLs do need to be unique, but I'd like to avoid having more index than actual data.</p> <p>If the value isn't present I need to insert it, but using structures such as <code>INSERT IGNORE</code>, or ON <code>DUPLICATE KEY</code> either requires me to put a unique on the huge varchar, or don't take advantage of my index.</p> <p>How can I "SELECT id else INSERT", whilst preserving the lookup speed for the 80-90% of hits that are already in the table?</p>
[ { "answer_id": 317906, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 3, "selected": true, "text": "id" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,784
<p>I am iterating though a TreeSet and printing it out:</p> <pre><code>while (it.hasNext()) { System.out.println(it.next()); } </code></pre> <p>output:</p> <pre><code>after explorers giant hoping internet into . . . virtual world </code></pre> <p>However, I would like to <i>only</i> print out those strings who's first character is within the range m-z. I have been playing around with java.util.regex, with no success:</p> <pre><code>String pattern = "[^m-z]"; </code></pre> <p>Do I have the right idea here? Or is there a simpler way of doing this? All I want to do is make sure I <strong>only print out those Strings in the TreeSet who's first character is within the range m-z.</strong></p>
[ { "answer_id": 317792, "author": "Julien Grenier", "author_id": 23051, "author_profile": "https://Stackoverflow.com/users/23051", "pm_score": 2, "selected": false, "text": "String.matches()" }, { "answer_id": 317795, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 3, "selected": false, "text": "\"^[m-z]\"\n" }, { "answer_id": 317829, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 2, "selected": false, "text": "wordSet.tailSet(\"m\", true);\n" }, { "answer_id": 318011, "author": "James Van Huis", "author_id": 31828, "author_profile": "https://Stackoverflow.com/users/31828", "pm_score": 2, "selected": false, "text": "while (it.hasNext()) {\n String element = it.next();\n if (element.toLowerCase().matches(\"^[m-z].*\")) {\n System.out.println(element);\n }\n}\n" }, { "answer_id": 318337, "author": "Grant Wagner", "author_id": 9254, "author_profile": "https://Stackoverflow.com/users/9254", "pm_score": 2, "selected": false, "text": "while (it.hasNext()) {\n String element = (String) it.next();\n char c = element.charAt(0);\n if (c >= 'm' && c <= 'z') {\n System.out.println(element);\n }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,794
<p>I am trying to see if Reg-Free COM is something we can use in our web application to ease deployment of legacy COM components. However, before I get onto looking into things like using it for Interop situations, I can't get a simple test to work. Here's what I have done :-</p> <p>1) Create a new VB ActiveX DLL project. Left all options as default apart from turning on binary compatibility. Added a class with a simple method called "SayHello".<br> 2) Create a new c# Console app in Vs.NET 2008 (SP1). Set the CPU to x86, and added a reference to my COM DLL.<br> 3) Turned on "Isolated" for the reference<br> 4) Call my SayHello method from the c# console app - all works.<br> 5) Manually un-register the COM dll with regsvr32 /u<br> 6) Try running the console app again. The app fails with a COM error because it can't find the COM registration information. I can confirm that the manifest is present (pasted below) </p> <p>I'm running this on Vista, 64Bit, if that makes a difference.</p> <p>Thanks for any pointers.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;assemblyIdentity name="TestRegFreeCom.exe" version="1.0.0.0" processorArchitecture="x86" type="win32" /&gt; &lt;file name="TestProject.dll" asmv2:size="20480"&gt; &lt;hash xmlns="urn:schemas-microsoft-com:asm.v2"&gt; &lt;dsig:Transforms&gt; &lt;dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /&gt; &lt;/dsig:Transforms&gt; &lt;dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /&gt; &lt;dsig:DigestValue&gt;uIK8e9FAnH4SQwk6PRfrjdZHWuw=&lt;/dsig:DigestValue&gt; &lt;/hash&gt; &lt;typelib tlbid="{08dcd362-63a1-424a-8c4e-e72dcda2a8e2}" version="1.0" helpdir="" resourceid="0" flags="HASDISKIMAGE" /&gt; &lt;comClass clsid="{c540c43a-4d80-4c87-9091-dff664df0021}" tlbid="{08dcd362-63a1-424a-8c4e-e72dcda2a8e2}" progid="TestProject.Testy" /&gt; &lt;/file&gt; &lt;/assembly&gt; </code></pre>
[ { "answer_id": 318396, "author": "Tim Farley", "author_id": 4425, "author_profile": "https://Stackoverflow.com/users/4425", "pm_score": 2, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" \n manifestVersion=\"1.0\">\n<assemblyIdentity\n type = \"win32\"\n name = \"client\"\n version = \"1.0.0.0\" />\n<dependency>\n <dependentAssembly>\n <assemblyIdentity\n type=\"win32\"\n name=\"MSFLXGRD.X\"\n version=\"6.1.97.82\" />\n </dependentAssembly>\n</dependency>\n</assembly>\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24109/" ]
317,801
<p>I need to create a new file handle so that any write operations to that handle get written to disk immediately. </p> <p>Extra info: The handle will be the inherited STDOUT of a child process, so I need any output from that process to immediately be written to disk.</p> <p>Studying the <code>CreateFile</code> documentation, the <code>FILE_FLAG_WRITE_THROUGH</code> flag looked like exactly what I need:</p> <blockquote> <p>Write operations will not go through any intermediate cache, they will go directly to disk.</p> </blockquote> <p>I wrote a very basic test program and, well, it's not working. I used the flag on CreateFile then used <code>WriteFile(myHandle,...)</code> in a long loop, writing about 100MB of data in about 15 seconds. (I added some <code>Sleep()</code>'s). </p> <p>I then set up a professional monitoring environment consisting of continuously hitting 'F5' in explorer. The results: the file stays at 0kB then jumps to 100MB about the time the test program ends.</p> <p>Next thing I tried was to manually flush the file after each write, with <code>FlushFileBuffers(myHandle)</code>. This makes the observed file size grow nice and steady, as expected.</p> <p>My question is, then, shouldn't the <code>FILE_FLAG_WRITE_THROUGH</code> have done this <strong>without</strong> manually flushing the file? Am I missing something? In the 'real world' program, I can't flush the file, 'cause I don't have any control over the child process that's using it.</p> <p>There's also the <code>FILE_FLAG_NO_BUFFERING</code> flag, that I can't be used for the same reason - no control over the process that's using the handle, so I can't manually align the writes as required by this flag.</p> <p>EDIT: I have made a separate project specifically for watching how the size of the file changes. It uses the .NET <a href="http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx" rel="noreferrer"><code>FileSystemWatcher</code></a> class. I also write less data - around 100kB in total.</p> <p>Here's the output. Check out the seconds in the timestamps.</p> <p>The 'builtin no-buffers' version: </p> <pre><code>25.11.2008 7:03:22 PM: 10230 bytes added. 25.11.2008 7:03:31 PM: 10240 bytes added. 25.11.2008 7:03:31 PM: 10240 bytes added. 25.11.2008 7:03:31 PM: 10240 bytes added. 25.11.2008 7:03:31 PM: 10200 bytes added. 25.11.2008 7:03:42 PM: 10240 bytes added. 25.11.2008 7:03:42 PM: 10240 bytes added. 25.11.2008 7:03:42 PM: 10240 bytes added. 25.11.2008 7:03:42 PM: 10240 bytes added. 25.11.2008 7:03:42 PM: 10190 bytes added. </code></pre> <p>... and the 'forced (manual) flush' version (<code>FlushFileBuffers()</code> is called every ~2.5 seconds):</p> <pre><code>25.11.2008 7:06:10 PM: 10230 bytes added. 25.11.2008 7:06:12 PM: 10230 bytes added. 25.11.2008 7:06:15 PM: 10230 bytes added. 25.11.2008 7:06:17 PM: 10230 bytes added. 25.11.2008 7:06:19 PM: 10230 bytes added. 25.11.2008 7:06:21 PM: 10230 bytes added. 25.11.2008 7:06:23 PM: 10230 bytes added. 25.11.2008 7:06:25 PM: 10230 bytes added. 25.11.2008 7:06:27 PM: 10230 bytes added. 25.11.2008 7:06:29 PM: 10230 bytes added. </code></pre>
[ { "answer_id": 318204, "author": "Tim Lesher", "author_id": 14942, "author_profile": "https://Stackoverflow.com/users/14942", "pm_score": 5, "selected": true, "text": "FILE_FLAG_WRITE_THROUGH" }, { "answer_id": 2374554, "author": "Ian Boyd", "author_id": 12597, "author_profile": "https://Stackoverflow.com/users/12597", "pm_score": 2, "selected": false, "text": "FlushFileBuffers" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11545/" ]
317,816
<p>I can create a literal long by appending an L to the value; why can't I create a literal short or byte in some similar way? Why do I need to use an int literal with a cast?</p> <p>And if the answer is "Because there was no short literal in C", then why are there no short literals in C?</p> <p>This doesn't actually affect my life in any meaningful way; it's easy enough to write (short) 0 instead of 0S or something. But the inconsistency makes me curious; it's one of those things that bother you when you're up late at night. Someone at some point made a design decision to make it possible to enter literals for some of the primitive types, but not for all of them. Why?</p>
[ { "answer_id": 317883, "author": "Julien Oster", "author_id": 40111, "author_profile": "https://Stackoverflow.com/users/40111", "pm_score": 5, "selected": true, "text": "int" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25468/" ]
317,822
<p>How can we write an update sql statement that would update records and the 'set' value changes every time?</p> <p>For example: If we have records like this</p> <pre><code>SomeNumber SomeV CurCode WhatCodeShouldBe 200802754 432 B08 B09 200802754 432 B08 B09 200802754 432 B08 B09 200808388 714 64B C00 200804119 270 64B C00 </code></pre> <p>I wish to update each 'SomeNumber' record so that 'CurCode' will be same as 'WhatCodeShouldBe'</p> <p>Thanks for any help!</p>
[ { "answer_id": 317832, "author": "Julien Oster", "author_id": 40111, "author_profile": "https://Stackoverflow.com/users/40111", "pm_score": 0, "selected": false, "text": "UPDATE yourtable SET CurCode = WhatCodeShouldBe" }, { "answer_id": 317833, "author": "Jack Ryan", "author_id": 28882, "author_profile": "https://Stackoverflow.com/users/28882", "pm_score": 0, "selected": false, "text": "UPDATE tableName SET CurCode = WhatCodeShouldBe \n" }, { "answer_id": 317909, "author": "Rob", "author_id": 3542, "author_profile": "https://Stackoverflow.com/users/3542", "pm_score": 0, "selected": false, "text": "WhatCodeShouldBe" }, { "answer_id": 317969, "author": "kristof", "author_id": 3241, "author_profile": "https://Stackoverflow.com/users/3241", "pm_score": 2, "selected": true, "text": "update a\nset\n 3rdColumn = b.2ndColumn\nfrom\n tableA a\n inner join tableB b\n on a.linkToB = b.linkToA\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,828
<p>Each of these variables has an integer value. But this syntax is not valid for some reason:</p> <pre><code>&lt;xsl:when test="$nextAnswerListItemPos &lt; $nextQuestionStemPos" &gt; </code></pre>
[ { "answer_id": 317839, "author": "Julien Oster", "author_id": 40111, "author_profile": "https://Stackoverflow.com/users/40111", "pm_score": 7, "selected": true, "text": "&lt;" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5653/" ]
317,835
<p>Is there some equivalent of "friend" or "internal" in php? If not, is there any pattern to follow to achieve this behavior? </p> <p><strong>Edit:</strong> Sorry, but standard Php isn't what I'm looking for. I'm looking for something along the lines of what ringmaster did.</p> <p>I have classes which are doing C-style system calls on the back end and the juggling has started to become cumbersome. I have functions in object A which take in object B as a parameter and have to call a method in object B passing in itself as an argument. The end user could call the method in B and the system would fall apart.</p>
[ { "answer_id": 317884, "author": "Robert Elwell", "author_id": 23102, "author_profile": "https://Stackoverflow.com/users/23102", "pm_score": -1, "selected": false, "text": "private function foo($arg1, $arg2) { /*function stuff goes here */ }\n" }, { "answer_id": 317903, "author": "ringmaster", "author_id": 40413, "author_profile": "https://Stackoverflow.com/users/40413", "pm_score": 7, "selected": true, "text": "class HasFriends\n{\n private $__friends = array('MyFriend', 'OtherFriend');\n\n public function __get($key)\n {\n $trace = debug_backtrace();\n if(isset($trace[1]['class']) && in_array($trace[1]['class'], $this->__friends)) {\n return $this->$key;\n }\n\n // normal __get() code here\n\n trigger_error('Cannot access private property ' . __CLASS__ . '::$' . $key, E_USER_ERROR);\n }\n\n public function __set($key, $value)\n {\n $trace = debug_backtrace();\n if(isset($trace[1]['class']) && in_array($trace[1]['class'], $this->__friends)) {\n return $this->$key = $value;\n }\n\n // normal __set() code here\n\n trigger_error('Cannot access private property ' . __CLASS__ . '::$' . $key, E_USER_ERROR);\n }\n}\n" }, { "answer_id": 25194480, "author": "jerseyboy", "author_id": 514128, "author_profile": "https://Stackoverflow.com/users/514128", "pm_score": 3, "selected": false, "text": "use($that,$anythingelseyouneed)" }, { "answer_id": 60960843, "author": "BruceOverflow", "author_id": 1799622, "author_profile": "https://Stackoverflow.com/users/1799622", "pm_score": 0, "selected": false, "text": "<?php\n\nclass FooWithFriend {\n\n private function guardOnlyFriend(): void \n {\n if (( is_a($this, BarFriendOfFoo::class) ) === false ) {\n throw new Exception('Only class BarFriendOfFoo he can create me');\n }\n }\n\n protected function __construct() \n {\n $this->guardOnlyFriend();\n echo 'Hello friend - ';\n }\n}\n\n\nfinal class BarFriendOfFoo extends FooWithFriend {\n public function __construct()\n {\n parent::__construct();\n }\n}\n\nfinal class Bar2FriendOfFoo extends FooWithFriend {\n public function __construct()\n {\n parent::__construct();\n }\n}\n\n$bar = new BarFriendOfFoo();\n$bar = new Bar2FriendOfFoo();\n$dummy = new FooWithFriend();\n" }, { "answer_id": 69494167, "author": "Milad Abooali", "author_id": 2421472, "author_profile": "https://Stackoverflow.com/users/2421472", "pm_score": 0, "selected": false, "text": "Class Friendship" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317835", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26566/" ]
317,857
<p>I have a bash script which will be run on a Mac via ssh. The script requires a particular network drive to already be mounted. On the Mac, I mount this drive by opening a folder "JPLemme" on that drive in Finder. This mounts the drive until the Mac goes to sleep at night.</p> <p>Obviously, Finder isn't available via ssh, so I want to create an AppleScript that will simulate what I do through the GUI. I've tried:</p> <pre><code>tell application "Finder" activate open "JPLemme" end tell </code></pre> <p>I receive the following error:</p> <pre><code>execution error: Finder got an error: Can't get "JPLemme". (-1728) </code></pre> <p>I assume I'm missing something obvious, but Google has failed me. I would also be willing to entertain better solutions like mounting the drive directly; I've avoided that approach because I don't want the Mac to choke trying to mount the drive a second time after I've already mounted it in an unexpected way. (I don't really like Macs or AppleScript...)</p>
[ { "answer_id": 318611, "author": "Philip Regan", "author_id": 11976, "author_profile": "https://Stackoverflow.com/users/11976", "pm_score": 3, "selected": true, "text": " tell application \"Finder\"\n try\n set theServer to mount volume \"smb://path/to/volume\" as username \"YourUserName\" with password \"YourPassword\" \n--Please note here that this is a plain string without any built-in security. Use at your own risk.\n on error\n set VolumeCount to (get count of disks)\n repeat with x from 1 to VolumeCount\n set thisVolume to disk x\n if name of thisVolume is \"JPLemme\" then\n set theServer to thisVolume\n exit repeat\n end if\n end repeat\n end try\n end tell\n" }, { "answer_id": 320955, "author": "Philip Regan", "author_id": 11976, "author_profile": "https://Stackoverflow.com/users/11976", "pm_score": 1, "selected": false, "text": "Tell Application \"Finder\"\n Mount Volume \"smb://username:password@server/sub/directory\"\nEnd Tell\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1019/" ]
317,860
<p>I been experimenting with the different methods for representing a hierarchical structures in memory that would allow for simple and efficient transversal both up and down to discover ancestor and descendant relationships. Does anyone have any suggestions or examples of the options that I have? Is there a collection type in .Net 3.5 that would help here? </p>
[ { "answer_id": 329504, "author": "GregUzelac", "author_id": 27068, "author_profile": "https://Stackoverflow.com/users/27068", "pm_score": 0, "selected": false, "text": " class Node<T> {\n public T Item;\n public LinkedList<T> Children;\n }\n" }, { "answer_id": 329568, "author": "Bryan Watts", "author_id": 37815, "author_profile": "https://Stackoverflow.com/users/37815", "pm_score": 0, "selected": false, "text": "System.Web.UI.IHierarchicalEnumerable" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317860", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27714/" ]
317,869
<p>I'm aiming to create a set of objects, each of which has a unique identifier. If an object already exists with that identifier, I want to use the existing object. Otherwise I want to create a new one. I'm trying not to use the word Singleton, because I know it's a dirty word here...</p> <p>I can use a factory method:</p> <pre><code> // A map of existing nodes, for getInstance. private static Map&lt;String, MyClass&gt; directory = new HashMap&lt;String, MyClass&gt;(); public static MyClass getInstance(String name) { MyClass node = directory.get(name); if(node == null) { node == new MyClass(name); } return node; } </code></pre> <p>Or equally, I could have a separate MyClassFactory method.</p> <p>But I had intended to subclass MyClass:</p> <pre><code>public class MySubClass extends MyClass; </code></pre> <p>If I do no more, and invoke MySubClass.getInstance():</p> <pre><code>MyClass subclassObj = MySubClass.getInstance("new name"); </code></pre> <p>... then subclassObj will be a plain MyClass, not a MySubClass.</p> <p>Yet overriding getInstance() in every subclass seems hacky.</p> <p>Is there a neat solution I'm missing?</p> <hr> <p>That's the generalised version of the question. More specifics, since the answerers asked for them.</p> <p>The program is for generating a directed graph of dependencies between nodes representing pieces of software. Subclasses include Java programs, Web Services, Stored SQL procedures, message-driven triggers, etc.</p> <p>So each class "is-a" element in this network, and has methods to navigate and modify dependency relationships with other nodes. The difference between the subclasses will be the implementation of the <code>populate()</code> method used to set up the object from the appropriate source.</p> <p>Let's say the node named 'login.java' learns that it has a dependency on 'checkpasswd.sqlpl':</p> <pre><code>this.addDependency( NodeFactory.getInstance("checkpasswd.sqlpl")); </code></pre> <p>The issue is that the checkpasswd.sqlpl object may or may not already exist at this time.</p>
[ { "answer_id": 317922, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 0, "selected": false, "text": "populate" }, { "answer_id": 318012, "author": "Alex Miller", "author_id": 7671, "author_profile": "https://Stackoverflow.com/users/7671", "pm_score": 1, "selected": false, "text": "private static Map<String, MyClass> directory = new HashMap<String, MyClass>();\n\npublic static <T extends MyClass> T getInstance(String name, Class<T> generatorClass)\n{\n MyClass node = directory.get(name); \n if(node == null) {\n node = generatorClass.getConstructor(String.class).newInstance(name);\n directory.put(name, node);\n }\n return node;\n}\n" }, { "answer_id": 323338, "author": "pvgoddijn", "author_id": 15355, "author_profile": "https://Stackoverflow.com/users/15355", "pm_score": 2, "selected": false, "text": "Public Interface Node<T> {\n public Object<T> getObject();\n public String getKey();\n public List<String> getDependencies();\n public void addDependence(String dep);\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7512/" ]
317,874
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/200574/linq-equivalent-of-foreach-for-ienumerablet">LINQ equivalent of foreach for IEnumerable&lt;T&gt;</a> </p> </blockquote> <p>The linq extension methods for ienumerable are very handy ... but not that useful if all you want to do is apply some computation to each item in the enumeration without returning anything. So I was wondering if perhaps I was just missing the right method, or if it truly doesn't exist as I'd rather use a built-in version if it's available ... but I haven't found one :-)</p> <p>I could have sworn there was a .ForEach method somewhere, but I have yet to find it. In the meantime, I did write my own version in case it's useful for anyone else:</p> <pre><code>using System.Collections; using System.Collections.Generic; public delegate void Function&lt;T&gt;(T item); public delegate void Function(object item); public static class EnumerableExtensions { public static void For(this IEnumerable enumerable, Function func) { foreach (object item in enumerable) { func(item); } } public static void For&lt;T&gt;(this IEnumerable&lt;T&gt; enumerable, Function&lt;T&gt; func) { foreach (T item in enumerable) { func(item); } } } </code></pre> <p>usage is:</p> <p><code>myEnumerable.For&lt;MyClass&gt;(delegate(MyClass item) { item.Count++; });</code></p>
[ { "answer_id": 317910, "author": "Jeff Yates", "author_id": 23234, "author_profile": "https://Stackoverflow.com/users/23234", "pm_score": 2, "selected": false, "text": "List<T>" }, { "answer_id": 318493, "author": "Neil", "author_id": 24315, "author_profile": "https://Stackoverflow.com/users/24315", "pm_score": 5, "selected": true, "text": " static void Main(string[] args)\n {\n IEnumerable<int> list = new List<int>() { -5, 3, -2, 1, 2, -7 };\n IEnumerable<bool> isPositiveList = list.Select<int, bool>(i => i > 0);\n\n foreach (bool isPositive in isPositiveList)\n {\n Console.WriteLine(isPositive);\n }\n\n Console.ReadKey(); \n }\n" }, { "answer_id": 2787820, "author": "Omer Mor", "author_id": 61061, "author_profile": "https://Stackoverflow.com/users/61061", "pm_score": 3, "selected": false, "text": "System.Interactive" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5416/" ]
317,878
<p>I've got a few dozen Linux machines running <code>cron</code> and I'd like to put the crontabs in some sort of revision control system. For source control I use Mercurial (<code>hg</code>), so that'd be ideal, but if there's some other system that is better suited to this task I'd consider it.</p> <p>One aspect which is specific to my situation is that all the crontabs belong to a common user (not a real person, but a placeholder "services" login). I'd like the revision history to include the actual author of each change, rather than the special account where the cron jobs actually run.</p>
[ { "answer_id": 317888, "author": "Daniel Bungert", "author_id": 21093, "author_profile": "https://Stackoverflow.com/users/21093", "pm_score": 2, "selected": false, "text": "/etc/shadow" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4323/" ]
317,891
<p>In asp.net 3.5, I have a problem that if I upload my global.asax to the remote web server, the app starts looking for my local sql server and eventually times out. I use a different config file for the local and remote because of the sql server login. Local is windows auth and remote is sql server auth. However, none of that info is stored in global.asax. global.asax only has</p> <p>but once it is uploaded, something causes the remote to try finding the local web.config's sql server login. Deleting global.asax on the remote causes everything to work fine. </p> <p>Any ideas?</p>
[ { "answer_id": 318072, "author": "4thSpace", "author_id": 40106, "author_profile": "https://Stackoverflow.com/users/40106", "pm_score": 0, "selected": false, "text": " [global::System.Configuration.DefaultSettingValueAttribute(\"Data Source=VISTADEV;Initial Catalog=Fin;Integrated Security=True\")]\n public string FinConnectionString {\n get {\n return ((string)(this[\"FinConnectionString\"]));\n }\n }\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40106/" ]
317,893
<p>For some reason my code won't work.</p> <pre><code> from tan in TANS where tan.ID.ToString().Count() != 1 select tan </code></pre> <p>I want to select all IDs that are duplicates in a table so I am using the count != 1 and I get this error.</p> <p>NotSupportedException: Sequence operators not supported for type 'System.String'</p> <p>Help please?</p>
[ { "answer_id": 317939, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 5, "selected": true, "text": "tan.ID.ToString()" }, { "answer_id": 317985, "author": "David", "author_id": 39552, "author_profile": "https://Stackoverflow.com/users/39552", "pm_score": 3, "selected": false, "text": "var dupes = (from tan in TANS\n group tan by tan.ID.ToString() into duplicates\n where duplicates.Count() > 1\n select duplicates.Select(d => d)).SelectMany(d => d);\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7644/" ]
317,916
<p>I need to be able to see if a form input in PHP is numeric. If it is not numeric, the website should redirect. I have tried is_numeric() but it does not seem to work.</p> <p>Code examples will be nice.</p> <p>I am developing a shopping cart that accepts an integer value for the quantity. I am trying this: </p> <pre><code>if(!is_numeric($quantity)){ //redirect($data['referurl']."/badinput"); echo "is not numeric"; } </code></pre>
[ { "answer_id": 317931, "author": "Rob", "author_id": 3542, "author_profile": "https://Stackoverflow.com/users/3542", "pm_score": 3, "selected": false, "text": "is_numeric()" }, { "answer_id": 317952, "author": "gpojd", "author_id": 28071, "author_profile": "https://Stackoverflow.com/users/28071", "pm_score": 1, "selected": false, "text": "$quantity == 0\n" }, { "answer_id": 317975, "author": "markus", "author_id": 11995, "author_profile": "https://Stackoverflow.com/users/11995", "pm_score": 5, "selected": true, "text": "if(!is_numeric($quantity == 0)){\n //redirect($data['referurl'].\"/badinput\");\n echo \"is not numeric\";\n" }, { "answer_id": 10063818, "author": "Mad Scientist", "author_id": 997603, "author_profile": "https://Stackoverflow.com/users/997603", "pm_score": 0, "selected": false, "text": "/^\\d+$/" }, { "answer_id": 10064922, "author": "John Conde", "author_id": 250259, "author_profile": "https://Stackoverflow.com/users/250259", "pm_score": 1, "selected": false, "text": "ctype_digit" }, { "answer_id": 24673046, "author": "fausto", "author_id": 2724527, "author_profile": "https://Stackoverflow.com/users/2724527", "pm_score": 0, "selected": false, "text": "$numeric = \"1\"; //true default\n\n$string = trim($_GET['string']);\n\n$chkarray = array(\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"0\", \",\", \".\");\n\nfor ($i=0; $i < strlen($string); $i++) { \n if (!in_array(substr($string, $i, 1), $chkarray)) {\n $numeric = \"0\";\n break;\n }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
317,921
<p>I'm just beginning to learn ASP.NET MVC and I've run into a question. I'm trying to determine whether I should use HtmlHelper to create client controls or if I should just roll my own. My gut wants to lean towards just rolling my own because it gives me total control - and use jQuery to decorate and add cross-browswer functionality. But then I can see advantages of using HtmlHelper for various complex controls that may involve things like paging.</p> <p>I'm looking for experiences about when it was better to use HtmlHelper and when it was better to roll your own.</p>
[ { "answer_id": 318397, "author": "CubanX", "author_id": 27555, "author_profile": "https://Stackoverflow.com/users/27555", "pm_score": 3, "selected": true, "text": "<%= Html.TextBox(\"LastName\", ViewData.Model.LastName, new { @class = \"required\" })%>\n" }, { "answer_id": 319145, "author": "Tim Scott", "author_id": 29493, "author_profile": "https://Stackoverflow.com/users/29493", "pm_score": 0, "selected": false, "text": "<%=this.TextBox(x => x.FirstName).Class(\"required\").Label(\"First Name:\")%>\n<%=this.CheckBox(\"enabled\").LabelAfter(\"Enabled\").Title(\"Click to enable.\").Styles(vertical_align => \"middle\")%>\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24908/" ]
317,944
<p>I have to change some connection strings in an incredibly old legacy application, and the programmers who made it thought it would be a great idea to plaster the entire app with connection strings all over the place.</p> <p>Visual Studio's "current project" search is incredible slow, and I don't trust Windows Search.</p> <p>So, what's the best free, non-indexed text search tool out there? All it should do is return a list with files that contain the wanted string inside a folder and its subfolders. </p> <p>I'm running Windows 2003 Server.</p>
[ { "answer_id": 13799990, "author": "JohnnyFromBF", "author_id": 906738, "author_profile": "https://Stackoverflow.com/users/906738", "pm_score": 8, "selected": false, "text": "findstr.exe" }, { "answer_id": 21604018, "author": "FIBA", "author_id": 3279600, "author_profile": "https://Stackoverflow.com/users/3279600", "pm_score": 2, "selected": false, "text": "@echo off\nif '%1' == '' goto NOPARAM\nif '%2' == '' goto NOPARAM\nif not exist %1 goto NOFOLDER\n\necho ------------------------------------------\necho - %1 : folder\necho - %2 : string to be searched in the folder\necho - PLEASE WAIT FOR THE RESULTS ...\nstrings -s %1\\* | findstr /i %2 > grep.txt\nnotepad.exe grep.txt\n\ngoto END\n\n:NOPARAM rem - input command not correct\necho ====================================\necho Usage of GREP.CMD:\necho Grep \"SearchFolder\" SearchString\necho Please specify all parameters\necho ====================================\ngoto END\n\n:NOFOLDER\necho Folder %1 does not exist\ngoto END\n\n:END rem - exit\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13466/" ]
317,963
<p>Say we have normal distribution n(x): mean=0 and \int_{-a}^{a} n(x) = P.</p> <p>What is the easiest way to compute standard deviation of such distribution? May be there are standard libraries for python or C, that are suitable for that task?</p>
[ { "answer_id": 318986, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 3, "selected": false, "text": "P = Prob[ -a <= X <= a ] = Prob[ -a/sigma <= N <= a/sigma ]\n = 2 Prob[ 0 <= N <= a/sigma ]\n = 2 ( Prob[ N <= a/sigma ] - 1/2 )\n" }, { "answer_id": 319878, "author": "dreeves", "author_id": 4234, "author_profile": "https://Stackoverflow.com/users/4234", "pm_score": 4, "selected": true, "text": "a/(sqrt(2)*inverseErf(P))\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317963", "https://Stackoverflow.com", "https://Stackoverflow.com/users/844/" ]
317,967
<p>I am developing on a LAMP(erl) stack and know of several ways to store obscured passwords. I'd like to hear from those who feel they have a best practice, given MySQL 4.1.1 and Perl 5.8, and the reasons why it's the best.</p> <p>One option I have read about, using the MySQL ENCODE() and DECODE() functions, sounds pretty good to me... your thoughts?</p>
[ { "answer_id": 317984, "author": "Rob", "author_id": 3542, "author_profile": "https://Stackoverflow.com/users/3542", "pm_score": 2, "selected": false, "text": "DECODE()" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26848/" ]
317,973
<p>I have just realized I've been coercing binding/dependency properties and not really fundamentally understanding the concept.</p> <p>Heres the dependency property:</p> <pre><code>public string Problem { get { return (string)GetValue(ProblemProperty); } set { SetValue(ProblemProperty, value); } } public static readonly DependencyProperty ProblemProperty = DependencyProperty.Register( "Problem", typeof(string), typeof(TextBox)); </code></pre> <p>The XAML is as so:</p> <pre><code>&lt;TextBlock Text="{Binding Path=Problem}"/&gt; </code></pre> <p>I'm manually setting the <code>Problem</code> property to a value in the constructor of the object but it doesn't update the <code>TextBlock</code> accordingly . . . any ideas? I've tried <code>Mode="OneWay"</code> and <code>Mode="TwoWay"</code> on the binding and it still doesn't work.</p> <p>I thought this was supposed to work automatically? Or am i fundamentally getting something wrong?</p> <p>Thanks</p>
[ { "answer_id": 318006, "author": "Micah", "author_id": 17744, "author_profile": "https://Stackoverflow.com/users/17744", "pm_score": 4, "selected": false, "text": "<TextBlock Text=\"{Binding Path=Problem,ElementName=_window}\" />\n" }, { "answer_id": 318209, "author": "Dave", "author_id": 28197, "author_profile": "https://Stackoverflow.com/users/28197", "pm_score": 0, "selected": false, "text": "public partial class Window1 : Window\n{\n public string Problem\n {\n get { return (string)GetValue(ProblemProperty); }\n set { SetValue(ProblemProperty, value); }\n }\n\n public static readonly DependencyProperty ProblemProperty =\n DependencyProperty.Register(\n \"Problem\",\n typeof(string),\n typeof(Window1));\n\n\n public Window1()\n {\n InitializeComponent();\n\n Problem = \"ifowiof\";\n }\n\n public void OnClick(object sender, EventArgs e)\n {\n Problem = \"behl\";\n }\n\n public void OnCancel(object sender, EventArgs e)\n {\n Problem = \"eioeopje\";\n }\n}\n" }, { "answer_id": 318335, "author": "Jobi Joy", "author_id": 8091, "author_profile": "https://Stackoverflow.com/users/8091", "pm_score": 2, "selected": false, "text": "<Window x:Class=\"WpfToolTip.Window1\"\nx:Name=\"_window\"\nxmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\nxmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n <StackPanel>\n <Button Click=\"OnClick\" Content=\"OK\" />\n <Button Click=\"OnCancel\" Content=\"Cancel\" />\n <TextBlock Text=\"{Binding Path=Problem,ElementName=_window}\" />\n</StackPanel>\n" }, { "answer_id": 579380, "author": "Simon D.", "author_id": 70060, "author_profile": "https://Stackoverflow.com/users/70060", "pm_score": 0, "selected": false, "text": "{Binding ElementName=m_ContentElement, Path=Problem}" }, { "answer_id": 9820089, "author": "panallen", "author_id": 1285594, "author_profile": "https://Stackoverflow.com/users/1285594", "pm_score": 2, "selected": false, "text": "typeof(object)" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28197/" ]
317,981
<p>I have a rich client application that uses Castle Windsor. At the moment all the assemblies including the application exe are in the one folder but it all looks rather untidy. I would like to put my dlls inside a subfolder such as "bin" but this prevents Castle from locating types etc when called upon. In fact the app crashes at start up. </p> <p>Is there a way to tell Castle to look somewhere else for the files?</p>
[ { "answer_id": 552813, "author": "Johan Andersson", "author_id": 66883, "author_profile": "https://Stackoverflow.com/users/66883", "pm_score": 0, "selected": false, "text": "public override void ProcessResource( Castle.Core.Resource.IResource source, Castle.MicroKernel.IConfigurationStore store )\n{\n base.ProcessResource( source, store );\n var baseDir = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location );\n foreach( var extraConfig in Directory.GetFiles( baseDir, \"*.dll.config\" ) )\n {\n try\n {\n var interpreter = new XmlInterpreter( extraConfig ) { Kernel = Kernel };\n interpreter.ProcessResource( interpreter.Source, store );\n } \n catch(ConfigurationErrorsException)\n {\n throw;\n }\n catch( Exception ex )\n {\n throw new InvalidOperationException( \"Failed to load configuration: \" + extraConfig, ex );\n }\n }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34260/" ]
317,997
<p>Delphi sometimes adds {$R *.res} in front of the unit path in the .dpr file uses clauses, then I get a duplicated resources warning when trying to compile.</p> <p>Anyone knows why the hell Delphi does that? I'm using Delphi 2009 but this happens since Delphi 2007 (maybe 2006 too)</p>
[ { "answer_id": 319075, "author": "Scott W", "author_id": 3032, "author_profile": "https://Stackoverflow.com/users/3032", "pm_score": 4, "selected": true, "text": "program Example;\n\n{$R *.res}\n\nuses\n Unit1 in 'Unit1.pas' {frmUnit1};\n\nbegin\n Application.Initialize;\n Application.CreateForm(TfrmUnit1, frmUnit1);\n Application.Run;\nend.\n" }, { "answer_id": 37747737, "author": "Z.B.", "author_id": 3957054, "author_profile": "https://Stackoverflow.com/users/3957054", "pm_score": 3, "selected": false, "text": "<DCCReference Include=\"..\\..\\..\\Core\\IF.Common\\uTranslation.Types.pas\">\n <Form>$R *.res</Form>\n</DCCReference>\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/317997", "https://Stackoverflow.com", "https://Stackoverflow.com/users/727/" ]
318,018
<p>In the admin section of a website i am building i would like to put together a dashboard page, or 'quick look' type page where the most recent changes/additions/etc in several different areas can be viewed.</p> <p>I was thinking the best way to do this would be to use partials and have each partial contain the markup for the data i need to display. </p> <p>My question is, is this the best approach? and if so, how do i separate the logic and presentation of these partials? For instance how do i put the logic in the dashboard controller, but keep the presentation in the partial rhtml?</p>
[ { "answer_id": 318082, "author": "capotej", "author_id": 1263, "author_profile": "https://Stackoverflow.com/users/1263", "pm_score": 3, "selected": true, "text": "<%= render :partial => \"name_of_partial\", :locals => { :some_var => @data_from_model } %>\n" }, { "answer_id": 318108, "author": "bradheintz", "author_id": 40093, "author_profile": "https://Stackoverflow.com/users/40093", "pm_score": 1, "selected": false, "text": "<%= render :partial => 'new_users_last7days', ;locals => { :new_user_count => @new_users.size } %>\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318018", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18811/" ]
318,056
<p>Not sure what's going on here.</p> <p>I have a DateTime object, and when I try:</p> <pre><code>String.Format( "{0:dd/MM/yyyy}", _date) </code></pre> <p>the value returned is:</p> <pre><code>"24-05-1967" </code></pre> <p>What I want is</p> <pre><code>"24/05/1967" </code></pre> <p>Can anyone explain why my format string is being ignored? </p> <p>A bit more background: This is a web app which started out life as .net 1.1, and I'm in the process of moving it up to 2.0/3.5. </p> <p>Update:</p> <p>If I change the format to {0:dd:MM:yyyy}, it returns 24:05:1967 - it's only the / in the format string that gets changed to the - char.</p> <hr> <p>Resolution:</p> <p>When updating the app to run under 2.0, the asp.net globalization settings were messed up. </p> <p>From the web site properties, ASP.NET tab, Edit Configuration, Application Tab - the culture and UI Culture were both set to the first item in the list (af-ZA) for some bizarre reason. </p>
[ { "answer_id": 318099, "author": "Oppositional", "author_id": 2029, "author_profile": "https://Stackoverflow.com/users/2029", "pm_score": 3, "selected": false, "text": "DateTime.Now.ToString(\"dd'/'MM'/'yyyy\");" }, { "answer_id": 318122, "author": "Carl Serrander", "author_id": 40272, "author_profile": "https://Stackoverflow.com/users/40272", "pm_score": 6, "selected": true, "text": "System.Threading.Thread.CurrentThread.CurrentCulture\n" }, { "answer_id": 318123, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 1, "selected": false, "text": "String.Format(CultureInfo.InvariantCulture, \"{0:dd/MM/yyyy}\", _date)\n" }, { "answer_id": 1769455, "author": "vijay", "author_id": 215308, "author_profile": "https://Stackoverflow.com/users/215308", "pm_score": 0, "selected": false, "text": "String.Format( \"{0:dd/MM/yyyy}\", Convert.ToDateTime(_date));\n" }, { "answer_id": 9079460, "author": "Mike Gledhill", "author_id": 391605, "author_profile": "https://Stackoverflow.com/users/391605", "pm_score": 0, "selected": false, "text": "outputFormat = outputFormat.Replace(\"/\", \"'/'\");\nvalueToExport = ImportedDate.ToString(outputFormat);\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4782/" ]
318,064
<p>How do I setup a class that represents an interface? Is this just an abstract base class?</p>
[ { "answer_id": 318084, "author": "bradtgmurray", "author_id": 1546, "author_profile": "https://Stackoverflow.com/users/1546", "pm_score": 8, "selected": false, "text": "class IDemo\n{\n public:\n virtual ~IDemo() {}\n virtual void OverrideMe() = 0;\n};\n\nclass Child : public IDemo\n{\n public:\n virtual void OverrideMe()\n {\n // do stuff\n }\n};\n" }, { "answer_id": 318137, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 11, "selected": true, "text": "class IDemo\n{\n public:\n virtual ~IDemo() {}\n virtual void OverrideMe() = 0;\n};\n\nclass Parent\n{\n public:\n virtual ~Parent();\n};\n\nclass Child : public Parent, public IDemo\n{\n public:\n virtual void OverrideMe()\n {\n //do stuff\n }\n};\n" }, { "answer_id": 318202, "author": "Dima", "author_id": 13313, "author_profile": "https://Stackoverflow.com/users/13313", "pm_score": 6, "selected": false, "text": "class A\n{\n virtual void foo() = 0;\n};\n" }, { "answer_id": 318261, "author": "Luc Hermitte", "author_id": 15934, "author_profile": "https://Stackoverflow.com/users/15934", "pm_score": 3, "selected": false, "text": "struct Contract1 : boost::noncopyable\n{\n virtual ~Contract1() = default;\n void f(Parameters p) {\n assert(checkFPreconditions(p)&&\"Contract1::f, pre-condition failure\");\n // + class invariants.\n do_f(p);\n // Check post-conditions + class invariants.\n }\nprivate:\n virtual void do_f(Parameters p) = 0;\n};\n...\nclass Concrete : public Contract1, public Contract2\n{\nprivate:\n void do_f(Parameters p) override; // From contract 1.\n void do_g(Parameters p) override; // From contract 2.\n};\n" }, { "answer_id": 318466, "author": "Rexxar", "author_id": 10016, "author_profile": "https://Stackoverflow.com/users/10016", "pm_score": 5, "selected": false, "text": "IDemo" }, { "answer_id": 319056, "author": "Rodyland", "author_id": 10681, "author_profile": "https://Stackoverflow.com/users/10681", "pm_score": 3, "selected": false, "text": "\n --- header file ----\n class foo {\n public:\n foo() {;}\n virtual ~foo() = 0;\n\n virtual bool overrideMe() {return false;}\n };\n\n ---- source ----\n foo::~foo()\n {\n }\n\n" }, { "answer_id": 1562554, "author": "Mark Ingram", "author_id": 986, "author_profile": "https://Stackoverflow.com/users/986", "pm_score": 3, "selected": false, "text": "struct __declspec(novtable) IFoo\n{\n virtual void Bar() = 0;\n};\n\nclass Child : public IFoo\n{\npublic:\n virtual void Bar() override { /* Do Something */ }\n}\n" }, { "answer_id": 9571456, "author": "Carlos C Soto", "author_id": 1229689, "author_profile": "https://Stackoverflow.com/users/1229689", "pm_score": 6, "selected": false, "text": "new" }, { "answer_id": 17299151, "author": "gnzlbg", "author_id": 1422197, "author_profile": "https://Stackoverflow.com/users/1422197", "pm_score": 4, "selected": false, "text": "struct Interface {\n explicit Interface(SomeType& other)\n : foo([=](){ return other.my_foo(); }), \n bar([=](){ return other.my_bar(); }), /*...*/ {}\n explicit Interface(SomeOtherType& other)\n : foo([=](){ return other.some_foo(); }), \n bar([=](){ return other.some_bar(); }), /*...*/ {}\n // you can add more types here...\n\n // or use a generic constructor:\n template<class T>\n explicit Interface(T& other)\n : foo([=](){ return other.foo(); }), \n bar([=](){ return other.bar(); }), /*...*/ {}\n\n const std::function<void(std::string)> foo;\n const std::function<void(std::string)> bar;\n // ...\n};\n" }, { "answer_id": 20685876, "author": "hims", "author_id": 1302665, "author_profile": "https://Stackoverflow.com/users/1302665", "pm_score": -1, "selected": false, "text": "class Shape \n{\npublic:\n // pure virtual function providing interface framework.\n virtual int getArea() = 0;\n void setWidth(int w)\n {\n width = w;\n }\n void setHeight(int h)\n {\n height = h;\n }\nprotected:\n int width;\n int height;\n};\n\nclass Rectangle: public Shape\n{\npublic:\n int getArea()\n { \n return (width * height); \n }\n};\nclass Triangle: public Shape\n{\npublic:\n int getArea()\n { \n return (width * height)/2; \n }\n};\n\nint main(void)\n{\n Rectangle Rect;\n Triangle Tri;\n\n Rect.setWidth(5);\n Rect.setHeight(7);\n\n cout << \"Rectangle area: \" << Rect.getArea() << endl;\n\n Tri.setWidth(5);\n Tri.setHeight(7);\n\n cout << \"Triangle area: \" << Tri.getArea() << endl; \n\n return 0;\n}\n" }, { "answer_id": 32811357, "author": "Yeo", "author_id": 764592, "author_profile": "https://Stackoverflow.com/users/764592", "pm_score": 0, "selected": false, "text": "__interface" }, { "answer_id": 38594093, "author": "lorro", "author_id": 6292621, "author_profile": "https://Stackoverflow.com/users/6292621", "pm_score": 1, "selected": false, "text": "virtual" }, { "answer_id": 47148505, "author": "Chen Li", "author_id": 6949852, "author_profile": "https://Stackoverflow.com/users/6949852", "pm_score": -1, "selected": false, "text": "abstract class" }, { "answer_id": 67573858, "author": "Nathan Xabedi", "author_id": 8260266, "author_profile": "https://Stackoverflow.com/users/8260266", "pm_score": 2, "selected": false, "text": "concept" }, { "answer_id": 68391066, "author": "rustyhu", "author_id": 4366445, "author_profile": "https://Stackoverflow.com/users/4366445", "pm_score": 0, "selected": false, "text": "#include <iostream>\n#include <string>\n\n// Static binding interface\n// Notice: instantiation of this interface should be usefuless and forbidden.\nclass IBase {\n protected:\n IBase() = default;\n ~IBase() = default;\n\n public:\n // Methods that must be implemented by the derived class\n void behaviorA();\n void behaviorB();\n\n void behaviorC() {\n std::cout << \"This is an interface default implementation of bC().\\n\";\n };\n};\n\nclass CCom : public IBase {\n std::string name_;\n\n public:\n void behaviorA() { std::cout << \"CCom bA called.\\n\"; };\n};\n\nclass CDept : public IBase {\n int ele_;\n\n public:\n void behaviorB() { std::cout << \"CDept bB called.\\n\"; };\n void behaviorC() {\n // Overwrite the interface default implementation\n std::cout << \"CDept bC called.\\n\";\n IBase::behaviorC();\n };\n};\n\nint main(void) {\n // Forbid the instantiation of the interface type itself.\n // GCC error: ‘constexpr IBase::IBase()’ is protected within this context\n // IBase o;\n\n CCom acom;\n // If you want to use these interface methods, you need to implement them in\n // your derived class. This is controled by the interface definition.\n acom.behaviorA();\n // ld: undefined reference to `IBase::behaviorB()'\n // acom.behaviorB();\n acom.behaviorC();\n\n CDept adept;\n // adept.behaviorA();\n adept.behaviorB();\n adept.behaviorC();\n // adept.IBase::behaviorC();\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5618/" ]
318,066
<p>When executing the following (complete) SQL query on Microsoft SQL Server 2000:</p> <pre><code>SELECT B.ARTIFACTTNS, B.ARTIFACTNAME, B.ARTIFACTTYPE, B.INITIALBYTES, B.TIMESTAMP1, B.FILENAME, B.BACKINGCLASS, B.CHARENCODING, B.APPNAME, B.COMPONENTTNS, B.COMPONENTNAME, B.SCAMODULENAME, B.SCACOMPONENTNAME FROM (SELECT DISTINCT A.ARTIFACTTYPE, A.ARTIFACTTNS, A.ARTIFACTNAME FROM (SELECT DISTINCT ARTIFACTTYPE, ARTIFACTTNS, ARTIFACTNAME FROM CUSTPROPERTIES WHERE PNAME = 'AcmeSystemName' AND PVALUE = 'MyRuleGroup' UNION SELECT DISTINCT ARTIFACTTYPE, ARTIFACTTNS, ARTIFACTNAME FROM CUSTPROPERTIES WHERE PNAME = 'AcmeSystemDisplayName' AND PVALUE = 'MyRuleGroup') A, (SELECT DISTINCT ARTIFACTTYPE, ARTIFACTTNS, ARTIFACTNAME FROM CUSTPROPERTIES WHERE PNAME = 'AcmeSystemTargetNameSpace' AND PVALUE = 'http://MyModule') B WHERE A.ARTIFACTTYPE = B.ARTIFACTTYPE AND A.ARTIFACTTNS = B.ARTIFACTTNS AND A.ARTIFACTNAME = B.ARTIFACTNAME) A, BYTESTORE B WHERE (A.ARTIFACTTYPE = 'BRG') AND A.ARTIFACTTYPE = B.ARTIFACTTYPE AND A.ARTIFACTTNS = B.ARTIFACTTNS AND A.ARTIFACTNAME = B.ARTIFACTNAME ORDER BY ARTIFACTTYPE, ARTIFACTTNS, ARTIFACTNAME </code></pre> <p>I get the following exception:</p> <pre><code>java.sql.SQLException: [Acme][SQLServer JDBC Driver][SQLServer] Ambiguous column name 'ARTIFACTTYPE'. </code></pre> <p>What am I doing wrong here and how can I correct it?</p>
[ { "answer_id": 318089, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 6, "selected": true, "text": "ARTIFACTTYPE" }, { "answer_id": 318285, "author": "Dave Costa", "author_id": 6568, "author_profile": "https://Stackoverflow.com/users/6568", "pm_score": 2, "selected": false, "text": "SQL> create table props (pname varchar2(100),\n 2 pvalue varchar2(100),\n 3 artifacttype number,\n 4 artifacttns number,\n 5 artifactname number);\n\nTable created.\n\nSQL> SELECT \n 2 DISTINCT A.ARTIFACTTYPE, A.ARTIFACTTNS, A.ARTIFACTNAME\n 3 FROM\n 4 (SELECT DISTINCT \n 5 ARTIFACTTYPE, \n 6 ARTIFACTTNS, \n 7 ARTIFACTNAME \n 8 FROM props \n 9 WHERE PNAME = 'AcmeSystemName' \n 10 AND PVALUE = 'MyRuleGroup' \n 11 UNION \n 12 SELECT DISTINCT \n 13 ARTIFACTTYPE, \n 14 ARTIFACTTNS, \n 15 ARTIFACTNAME \n 16 FROM props\n 17 WHERE PNAME = 'AcmeSystemDisplayName' \n 18 AND PVALUE = 'MyRuleGroup') A, \n 19 (SELECT DISTINCT \n 20 ARTIFACTTYPE, \n 21 ARTIFACTTNS, \n 22 ARTIFACTNAME \n 23 FROM props \n 24 WHERE PNAME = 'AcmeSystemTargetNameSpace' \n 25 AND PVALUE = 'http://mymodule') B\n 26 WHERE A.ARTIFACTTYPE = B.ARTIFACTTYPE \n 27 AND A.ARTIFACTTNS = B.ARTIFACTTNS \n 28 AND A.ARTIFACTNAME = B.ARTIFACTNAME\n 29 /\n\nno rows selected\n" }, { "answer_id": 429184, "author": "Paul Reiners", "author_id": 7648, "author_profile": "https://Stackoverflow.com/users/7648", "pm_score": 0, "selected": false, "text": "ORDER BY" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7648/" ]
318,068
<p>I am working on an If statement and I want to satisfy two conditions to ignore the loop. This seemed easy at first, but now... I don't know. this is my dilemma...</p> <pre><code>if((radButton1.checked == false)&amp;&amp;(radButton2.checked == false)) { txtTitle.Text = "go to work"; } </code></pre> <p>The dilemma is "go to work" is not executed if radButton1 is false and radButton2 is true. Shouldn't it require both conditions to be false in order to skip the statement?</p>
[ { "answer_id": 318081, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 4, "selected": false, "text": "if ((radButton1.checked == false) && (radButton2.checked == false)) {\n txtTitle.Text = \"Go to work\";\n}\n" }, { "answer_id": 318086, "author": "Mitchel Sellers", "author_id": 13279, "author_profile": "https://Stackoverflow.com/users/13279", "pm_score": 2, "selected": false, "text": "txtTitle.Text =\"go to work\"" }, { "answer_id": 318091, "author": "Elie", "author_id": 23249, "author_profile": "https://Stackoverflow.com/users/23249", "pm_score": 0, "selected": false, "text": "if (condition1 && condition2) {\n doSomething();\n}\n" }, { "answer_id": 318117, "author": "Powerlord", "author_id": 15880, "author_profile": "https://Stackoverflow.com/users/15880", "pm_score": 3, "selected": false, "text": "A" }, { "answer_id": 318182, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "if(!((radButton1.checked == true)&&(radButton2.checked == true)))\n{\n ...\n}\n" }, { "answer_id": 318232, "author": "Draemon", "author_id": 26334, "author_profile": "https://Stackoverflow.com/users/26334", "pm_score": 2, "selected": false, "text": "if(!((radButton1.checked == true)&&(radButton2.checked == true))) { ... }\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
318,069
<p>Let's say we're tracking the end-user IP for a web service:</p> <pre><code>ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If ip = "" Then ip = Request.ServerVariables("REMOTE_ADDR") End If </code></pre> <p>I've read that this is the best method of retrieving end-user IP because it works even for users on a transparent proxy.</p> <p>If we're using the end-user IP address to filter malicious users, are there are any security implications with the above method instead of, say, just using Request.ServerVariables("REMOTE_ADDR")?</p> <p>For example, if we banned a malicious user by end-user IP, could they easily change their IP via a proxy and continue using our web service?</p> <p>Thanks in advance for your help.</p>
[ { "answer_id": 318093, "author": "Powerlord", "author_id": 15880, "author_profile": "https://Stackoverflow.com/users/15880", "pm_score": 4, "selected": true, "text": "REMOTE_ADDR" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19471/" ]
318,087
<p>I'm trying to map a joined-subclass scenario using Fluent NHibernate. I have a class Entity defined in the namespace Core, and a class SubClass : Entity in the namespace SomeModule</p> <p>Now I obviously don't want class Entity to know about its derived types, the SomeModules namespace references Core - not the other way around.</p> <p>All the examples I've been able to find use something like:</p> <pre><code>public class EntityMap : ClassMap&lt;Entity&gt; { public EntityMap() { Id(x =&gt; x.Id) var subClassMap = JoinedSubClass&lt;SubClass&gt;("SubClassId", sub =&gt; sub.Map(x =&gt; x.Id)); subClassMap.Map(x =&gt; x.SomeProperty) ... } } </code></pre> <p>This simply won't work in my situation - I need something akin to the NHibernate xml mapping:</p> <pre><code>&lt;joined-subclass name="SubClass" extends="Entity, Core" &gt; &lt;key column="SubClassId" foreign-key="FK_KollegiumEntity"/&gt; &lt;property name="Name" length="255" not-null="true" /&gt; ... &lt;/joined-subclass&gt; </code></pre> <p>Has anyone achieved this with Fluent NHibernate?</p>
[ { "answer_id": 324038, "author": "Magnus Bertilsson", "author_id": 41395, "author_profile": "https://Stackoverflow.com/users/41395", "pm_score": 0, "selected": false, "text": "public class EntityMap : ClassMap<Entity> {\n public EntityMap() {\n Id(x => x.Id)\n\n JoinedSubClass<SubClass>(\"SubClassId\", sub => { \n sub.Map(x => x.Name); \n sub.Map(x => x.SomeProperty); \n });\n }\n}\n" }, { "answer_id": 374056, "author": "Magnus Bertilsson", "author_id": 41395, "author_profile": "https://Stackoverflow.com/users/41395", "pm_score": 1, "selected": false, "text": "public class SubClassMap : JoinedSubClassPart< SubClass >\n{\n public SubClassMap()\n : base(\"SubClassId\")\n {\n Map(x => x.Name); \n Map(x => x.SomeProperty); \n }\n}\n" }, { "answer_id": 417600, "author": "Nagyman", "author_id": 45715, "author_profile": "https://Stackoverflow.com/users/45715", "pm_score": 1, "selected": false, "text": "public class EntityMap : ClassMap<Entity> {\n public EntityMap() {\n Id(x => x.Id)\n AddPart(new SubClassMap()); // Adds the subclass mapping!\n }\n}\n\npublic class SubClassMap : JoinedSubClassPart<SubClass>\n{\n public SubClassMap()\n : base(\"SubClassId\")\n {\n Map(x => x.Name); \n Map(x => x.SomeProperty); \n }\n}\n" }, { "answer_id": 2782456, "author": "Sean Lynch", "author_id": 191902, "author_profile": "https://Stackoverflow.com/users/191902", "pm_score": 3, "selected": false, "text": "public class SomeSubclassMap : SubclassMap<SomeSubclass> {\n public SomeSubclassMap()\n {\n KeyColumn(\"SomeKeyColumnID\");\n Map(x => x.SomeSubClassProperty);\n ...\n }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318087", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7147/" ]
318,090
<p>Simple question:</p> <p>How do I do this on one line:</p> <pre><code>my $foo = $bar-&gt;{baz}; fizz(\$foo); </code></pre> <p>I've tried \$bar->{baz}, \${$bar->{baz}}, and numerous others. Is this even possible?</p> <p>-fREW</p> <p><strong>Update</strong>: Ok, the hashref is coming from DBI and I am passing the scalar ref into template toolkit. I guess now that I look more closely the issue is something to do with how TT does all of this. Effectively I want to say:</p> <pre><code>$template-&gt;process(\$row-&gt;{body}, $data); </code></pre> <p>But TT doesn't work that way, TT takes a scalar ref and puts the data there, so I'd have to do this:</p> <pre><code>$template-&gt;process(\$row-&gt;{body}, $shopdata, \$row-&gt;{data}); </code></pre> <p>Anyway, thanks for the help. I'll at least only have one reference instead of two.</p>
[ { "answer_id": 318153, "author": "jimtut", "author_id": 13563, "author_profile": "https://Stackoverflow.com/users/13563", "pm_score": 2, "selected": false, "text": "my %hash;\nmy $bar = \\%hash;\n$hash{baz} = \"found it\\n\";\nsub fizz {\n my $ref = shift;\n print $$ref;\n}\n" }, { "answer_id": 318156, "author": "runrig", "author_id": 10415, "author_profile": "https://Stackoverflow.com/users/10415", "pm_score": 4, "selected": true, "text": "\\$bar->{baz}\n" }, { "answer_id": 318159, "author": "Yanick", "author_id": 10356, "author_profile": "https://Stackoverflow.com/users/10356", "pm_score": 2, "selected": false, "text": "my $bar = { baz => 1 };\nprint $bar->{baz}, \"\\n\"; # prints 1\nmy $ref = \\$bar->{baz};\nprint $$ref, \"\\n\"; # prints 1\n$$ref = 2;\nprint $bar->{baz}, \"\\n\"; # prints 2 \n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12448/" ]
318,096
<p>I have a generic list of objects in C#, for example sake, here's what the object might be.</p> <pre><code>public class Thing { public string Name { get; set; } public DateTime EditDate { get; set; } } var things = new List&lt;Thing&gt;(); </code></pre> <p>Now I want to call:</p> <pre><code>thing.Sort((t1, t2) =&gt; t1.EditDate.CompareTo(t2.EditDate)); </code></pre> <p>However, some of my EditDate properties are null. I want these objects with a null EditDate property to show up at the top of my list (i.e. closer to the zero index). How can I do this?</p>
[ { "answer_id": 318111, "author": "BCS", "author_id": 1343, "author_profile": "https://Stackoverflow.com/users/1343", "pm_score": 0, "selected": false, "text": "TheList.Sort(int delegate(Type a, Type b)\n{\n if (a.memeber == null) return -1;\n if (b.memeber == null) return 1;\n if (a.memeber<b.memeber) return -1;\n if (b.memeber<a.memeber) return 1;\n return 0;\n}\n" }, { "answer_id": 318119, "author": "Jeff Yates", "author_id": 23234, "author_profile": "https://Stackoverflow.com/users/23234", "pm_score": 5, "selected": true, "text": "things.Sort((t1, t2) => \n{\n if (t1 == null)\n {\n return (t2 == null) ? 0 : -1;\n }\n if (t2 == null)\n {\n return 1;\n }\n return t1.EditDate.CompareTo(t2.EditDate);\n});\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318096", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4541/" ]
318,129
<p>Sometimes software installers force you to scroll to the end of the EULA before the “I agree” box is enabled. How can I produce the same effect on a web page?</p>
[ { "answer_id": 318130, "author": "Jeremy Stein", "author_id": 9702, "author_profile": "https://Stackoverflow.com/users/9702", "pm_score": 4, "selected": true, "text": "<html>\n <head>\n <script type=\"text/javascript\">\n function setupPage() {\n var agreement = document.getElementById(\"agreetext\");\n var visibleHeight = agreement.clientHeight;\n var scrollableHeight = agreement.scrollHeight;\n if (scrollableHeight > visibleHeight) {\n var checkbox = document.getElementById(\"agreebox\");\n checkbox.checked=false;\n checkbox.disabled=true;\n agreement.onscroll = handleScroll;\n }\n }\n\n function handleScroll() {\n var agreement = document.getElementById(\"agreetext\");\n var visibleHeight = agreement.clientHeight;\n var scrollableHeight = agreement.scrollHeight;\n var position = agreement.scrollTop;\n if (position + visibleHeight == scrollableHeight) {\n document.getElementById(\"agreebox\").disabled=false;\n }\n }\n </script>\n </head>\n <body>\n <form>\n <textarea id=\"agreetext\" rows=\"8\" cols=\"40\">Long agreement</textarea>\n <br/><br/>\n <input type=\"checkbox\" id=\"agreebox\" value=\"true\"/> <label id=\"agreelabel\" for=\"agreebox\">I agree</label>\n <br/><br/>\n <input type=\"submit\" value=\"Continue\"/>\n </form>\n <script type=\"text/javascript\">\n // We put this at the end of the page rather than in an document.onload\n // because the document.onload event doesn't fire until all images have loaded.\n setupPage();\n </script>\n </body>\n</html>\n" }, { "answer_id": 9620186, "author": "Myke Black", "author_id": 821146, "author_profile": "https://Stackoverflow.com/users/821146", "pm_score": 1, "selected": false, "text": "function setupPage() {\n var agreement = document.getElementById(\"agreetext\");\n var visibleHeight = agreement.clientHeight;\n var scrollableHeight = agreement.scrollHeight;\n if (scrollableHeight > visibleHeight) {\n var checkbox = document.getElementById(\"agreebox\");\n checkbox.checked=false;\n checkbox.disabled=true;\n document.getElementById(\"agreelabel\").style.color = \"#777\";\n agreement.onscroll = handleScroll;\n }\n}\n\nfunction handleScroll() {\n var agreement = document.getElementById(\"agreetext\");\n var visibleHeight = agreement.clientHeight;\n var scrollableHeight = agreement.scrollHeight;\n var position = agreement.scrollTop;\n if (position + visibleHeight == scrollableHeight) {\n document.getElementById(\"agreebox\").disabled=false;\n document.getElementById(\"agreelabel\").style.color = \"black\";\n }\n}\n" }, { "answer_id": 29529842, "author": "Bassem", "author_id": 181448, "author_profile": "https://Stackoverflow.com/users/181448", "pm_score": 1, "selected": false, "text": "$(function () {\n var serviceAgreementScrolled = false;\n $('#service-agreement-textarea').scroll(\n function () {\n if (this.scrollTop + $(this).height() + 30 >= this.scrollHeight) {\n serviceAgreementScrolled = true;\n }\n }\n );\n\n $('#accept-service-agreement-checkbox').change(\n function () {\n if ($(this).is(':checked') && !serviceAgreementScrolled) {\n alert('Please scroll to read the rest of the service agreement.');\n $(this).prop('checked', false);\n }\n }\n );\n});\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9702/" ]
318,144
<p>My question is similar to "<a href="https://stackoverflow.com/questions/156362/what-is-the-difference-between-include-and-extend-in-ruby">What is the difference between include and extend in Ruby?</a>".</p> <p>What's the difference between <code>require</code> and <code>include</code> in Ruby? If I just want to use the methods from a module in my class, should I <code>require</code> it or <code>include</code> it?</p>
[ { "answer_id": 318170, "author": "HanClinto", "author_id": 26933, "author_profile": "https://Stackoverflow.com/users/26933", "pm_score": 10, "selected": true, "text": "require" }, { "answer_id": 318180, "author": "bradheintz", "author_id": 40093, "author_profile": "https://Stackoverflow.com/users/40093", "pm_score": 6, "selected": false, "text": "require" }, { "answer_id": 6082775, "author": "Pratik Khadloya", "author_id": 238880, "author_profile": "https://Stackoverflow.com/users/238880", "pm_score": 7, "selected": false, "text": "require()" }, { "answer_id": 14212020, "author": "Peter Dang", "author_id": 1957600, "author_profile": "https://Stackoverflow.com/users/1957600", "pm_score": 7, "selected": false, "text": "extend" }, { "answer_id": 17057245, "author": "Boris Stitnicky", "author_id": 1153747, "author_profile": "https://Stackoverflow.com/users/1153747", "pm_score": 3, "selected": false, "text": "require" }, { "answer_id": 34592408, "author": "Shrinivas", "author_id": 3382541, "author_profile": "https://Stackoverflow.com/users/3382541", "pm_score": 2, "selected": false, "text": "require(name)\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318144", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2109/" ]
318,145
<p>How do I setup an Ant task to generate a Findbugs report when the source folder has many jars in it?</p> <p>I'm looking for a worked example of the ant task required to output the fancy HTML from a folder containing multiple jars</p>
[ { "answer_id": 318170, "author": "HanClinto", "author_id": 26933, "author_profile": "https://Stackoverflow.com/users/26933", "pm_score": 10, "selected": true, "text": "require" }, { "answer_id": 318180, "author": "bradheintz", "author_id": 40093, "author_profile": "https://Stackoverflow.com/users/40093", "pm_score": 6, "selected": false, "text": "require" }, { "answer_id": 6082775, "author": "Pratik Khadloya", "author_id": 238880, "author_profile": "https://Stackoverflow.com/users/238880", "pm_score": 7, "selected": false, "text": "require()" }, { "answer_id": 14212020, "author": "Peter Dang", "author_id": 1957600, "author_profile": "https://Stackoverflow.com/users/1957600", "pm_score": 7, "selected": false, "text": "extend" }, { "answer_id": 17057245, "author": "Boris Stitnicky", "author_id": 1153747, "author_profile": "https://Stackoverflow.com/users/1153747", "pm_score": 3, "selected": false, "text": "require" }, { "answer_id": 34592408, "author": "Shrinivas", "author_id": 3382541, "author_profile": "https://Stackoverflow.com/users/3382541", "pm_score": 2, "selected": false, "text": "require(name)\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15352/" ]
318,155
<p>I'm evaluating subversion's branch/merge capabilities, and I decided to do a simple test - I branched an existing project, changed a comment in one file, and then did a merge reintegrate via Tortoise.</p> <p>It failed:</p> <blockquote> <p>Command: Reintegrate merge <a href="https://oscar/svn/Baxtech/ViM/Branches/Test3" rel="nofollow noreferrer">https://oscar/svn/Baxtech/ViM/Branches/Test3</a> into C:\Inntec\VS2008\Baxtech\ViM<br> Error: Cannot reintegrate from '<a href="https://oscar/svn/Baxtech/ViM/Branches/Test3" rel="nofollow noreferrer">https://oscar/svn/Baxtech/ViM/Branches/Test3</a>' yet:<br> Error: Some revisions have been merged under it that have not been merged<br> Error: into the reintegration target; merge them first, then retry. </p> </blockquote> <p>I googled around for this, and I found some posts saying that this has to do with mergeinfo being created by renames and directory changes in old versions of Tortoise.</p> <p>I did recently upgrade from the previous version of Tortoise to 1.5.5, however it seems like this problem was pre-1.5.*... <strong>And I only changed some comments in one file. I didn't do any renames or directory structure changes.</strong></p> <p>Then again, we've been working with the trunk for some time (without any branching), so maybe the problem exists in there?</p> <p>So, if there is a fix for this I would appreciate really appreciate some help. Also, though - is this typical? This was really a <em>very</em> simple test, and sadly right now I'm a little scared to use Subversion for branching.</p> <p>Subversion: 1.5.4 (via VisualSVN Server)<br> Tortoise: 1.5.5</p> <p>We're also using Visual Studio 2008.</p> <p>Thanks!</p> <p>Brian</p>
[ { "answer_id": 318165, "author": "Ben Scheirman", "author_id": 3381, "author_profile": "https://Stackoverflow.com/users/3381", "pm_score": 1, "selected": false, "text": "svn merge -r N:M SOURCE [PATH]\n" }, { "answer_id": 318747, "author": "Devrin", "author_id": 5269, "author_profile": "https://Stackoverflow.com/users/5269", "pm_score": 0, "selected": false, "text": "../ViM/branches/.." } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16082/" ]
318,157
<p>I'm trying to get distinct results using the Criteria API in NHibernate. I know this is possible using HQL, but I would prefer to do this using the Criteria API, because the rest of my app is written using only this method. I <a href="http://forum.hibernate.org/viewtopic.php?t=941669," rel="noreferrer">found this forum post</a>, but haven't been able to get it to work. Is there a way with the criteria API to get distinct result sets?</p> <p>Edit: In doing this, I also wanted to exclude the Primary Key column, which is also an identity, and get the remaining distinct records. Is there a way to do this? As it is, the distinct records are returning duplicates because the primary key is unique for each row, but all other fields are the same.</p>
[ { "answer_id": 318196, "author": "Juanma", "author_id": 3730, "author_profile": "https://Stackoverflow.com/users/3730", "pm_score": 6, "selected": true, "text": "session.CreateCriteria(typeof(Product)\n .Add(...)\n .SetResultTransformer(new DistinctEntityRootTransformer())\n" }, { "answer_id": 385079, "author": "Aidan Boyle", "author_id": 32719, "author_profile": "https://Stackoverflow.com/users/32719", "pm_score": 7, "selected": false, "text": "ICriteria criteria = session.CreateCriteria(typeof(Person));\ncriteria.SetProjection(\n Projections.Distinct(Projections.ProjectionList()\n .Add(Projections.Alias(Projections.Property(\"FirstName\"), \"FirstName\"))\n .Add(Projections.Alias(Projections.Property(\"LastName\"), \"LastName\"))));\n\ncriteria.SetResultTransformer(\n new NHibernate.Transform.AliasToBeanResultTransformer(typeof(Person)));\n\nIList<Person> people = criteria.List<Person>();\n" }, { "answer_id": 1088977, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": " var suppliers = (from supplier in session.Linq<Supplier>()\n from product in supplier.Products\n where product.Category.Name == produtCategoryName\n select supplier).ToList().Distinct();\n" }, { "answer_id": 26876450, "author": "beauXjames", "author_id": 370605, "author_profile": "https://Stackoverflow.com/users/370605", "pm_score": -1, "selected": false, "text": "CurrentSession()\n .QueryOver<GoodBadAndUgly>\n .Where(...)\n .TransformUsing(Transformers.DistinctRootEntity)\n" }, { "answer_id": 61229196, "author": "Marcin", "author_id": 8537786, "author_profile": "https://Stackoverflow.com/users/8537786", "pm_score": 2, "selected": false, "text": "Criteria.SetProjection(\nProjections.Distinct(Projections.Entity(typeof(YourEntityHere), \"this\")));\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1284/" ]
318,158
<p>I am trying to set the margin of an object from JavaScript. I am able to do it in Opera &amp; Firefox, but the code doesn't work in Internet Explorer.</p> <p>Here is the JavaScript I have:</p> <pre class="lang-js prettyprint-override"><code>function SetTopMargin (ObjectID, Value) { document.getElementById(ObjectID).style.marginTop = Value.toString() + "px"; } </code></pre> <p>And it is called like this:</p> <pre class="lang-js prettyprint-override"><code>SetTopMargin("test_div_id", 100); </code></pre> <p>So does anyone know some code that will work in Internet Explorer?</p>
[ { "answer_id": 318174, "author": "phihag", "author_id": 35070, "author_profile": "https://Stackoverflow.com/users/35070", "pm_score": 6, "selected": true, "text": "document.getElementById(ObjectId).style.marginTop = Value.ToString() + 'px';\n" }, { "answer_id": 318176, "author": "BraveSirFoobar", "author_id": 39263, "author_profile": "https://Stackoverflow.com/users/39263", "pm_score": -1, "selected": false, "text": "elem.style = \"margin: 10px\"" }, { "answer_id": 318203, "author": "JamesEggers", "author_id": 28540, "author_profile": "https://Stackoverflow.com/users/28540", "pm_score": 2, "selected": false, "text": "<html>\n <head>\n <script type=\"text/javascript\"> \n function SetTopMargin (ObjectID, Value)\n { \n document.getElementById(ObjectID).style.marginTop = Value.toString() + \"px\";\n }\n </script>\n </head>\n <body>\n <button id=\"btnTest\" onclick=\"SetTopMargin('btnTest', 100);\">Test</button>\n </body>\n</html>\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318158", "https://Stackoverflow.com", "https://Stackoverflow.com/users/126280/" ]
318,160
<p>The two key event argument classes <code>KeyEventArgs</code> and <code>PreviewKeyDownEventArgs</code> each have two properties, <code>KeyCode</code> and <code>KeyData</code>, which are both of the enumeration type Keys.</p> <p>What is the difference between these two properties? Do the values in them ever differ from each other? If so, when and why?</p>
[ { "answer_id": 318177, "author": "gcores", "author_id": 40256, "author_profile": "https://Stackoverflow.com/users/40256", "pm_score": 7, "selected": true, "text": "KeyCode" }, { "answer_id": 318190, "author": "Chris Ammerman", "author_id": 2729, "author_profile": "https://Stackoverflow.com/users/2729", "pm_score": 3, "selected": false, "text": "KeyCode" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2729/" ]
318,175
<p>Does anyone know, or have a link to an article or a step by step tutorial, that would tell me how to distribute a .net MONO application with a minimum install? The full package of Mono is like 75 MB but I know al lot of that is the compiler and libraries that I don't need.</p> <p>I just want the minimum runtime files.</p> <p>What files would I need to distribute for a simple 'Hello World' WinForms app?</p> <p>I tried just deleting files until I came up with something that worked but it only worked on the machine that had Mono installed on it. Here are the files I tried</p> <p>I created a directory for my app. In that directory I created two more directories</p> <ul> <li><code>\bin</code></li> <li><code>\lib\mono\2.0</code></li> </ul> <p>in the <code>\mono\lib\mono\2.0</code> I put the <code>mscorlib.dll</code> file in the <code>\bin</code> directory I put the following</p> <ul> <li><code>Accessibility.dll</code></li> <li><code>MyApp.exe </code>(this is the basic World I did in VS2005)</li> <li><code>iconv.dll</code>,</li> <li><code>intl.dll</code>,</li> <li><code>libglib-2.0-0.dll</code>,</li> <li><code>libgthread-2.0-0.dll</code>,</li> <li><code>Microsoft.VisualBasic.dll</code>,</li> <li><code>mono.dll</code>,</li> <li><code>mono.exe</code>,</li> <li><code>Mono.Posix.dll</code>,</li> <li><code>System.dll</code>,</li> <li><code>System.Drawing.dll</code>,</li> <li><code>System.Windows.Forms.dll</code></li> </ul> <p>Then, from the <code>\bin</code> directory I ran 'mono <code>MyApp.exe</code>' and it worked on my Mono installed machine but no others.</p> <p>What I'd prefer is an 'xcopy' solution where there would be no actual installation necessary but just need the runtime files included (like when you run from a thumb drive)</p> <p>Please note that this is to run on a Windows computer, not a Linux box.</p> <hr /> <p>I tried running mkbundle2 (it is a .net 2.0 app) and got this error</p> <blockquote> <p><code>C:\Program</code> Files\Mono-2.0.1\bin&gt;mkbundle2<br /> <code>C:\Projects\SingleExeTest\bin\Release\SingleExeTest.exe</code> --deps OS is:<br /> Windows Sources: 1 Auto-dependencies: True embedding:<br /> <code>C:\Projects\SingleExeTest\bin\Release\SingleExeTest.exe</code> embedding:<br /> <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\mscorlib.dll</code> embedding:<br /> <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\Microsoft.VisualBasic.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.dll</code><br /> embedding:<br /> <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.Configuration.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.Xml.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.Security.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\Mono.Security.dll</code><br /> embedding:<br /> <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.Windows.Forms.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.Drawing.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.Data.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\Mono.Data.Tds.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.Transactions.dll</code><br /> embedding:<br /> <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\System.EnterpriseServices.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\Mono.WebBrowser.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\Mono.Posix.dll</code><br /> embedding: <code>C:\PROGRA~1\MONO-2~1.1\lib\mono\2.0\Accessibility.dll</code><br /> Compiling: as -o temp.o <code>temp.s</code></p> <p>Unhandled Exception: System.ComponentModel.Win32Exception:<br /> ApplicationName='sh', CommandLine='-c &quot;as -o temp.o <code>temp.s</code> &quot;',<br /> CurrentDirectory='' at System.Diagnostics.Process.Start_noshell<br /> (System.Diagnostics.ProcessStartIn fo startInfo,<br /> System.Diagnostics.Process process) [0x00000] at<br /> System.Diagnostics.Process.Start_common<br /> (System.Diagnostics.ProcessStartInf o startInfo,<br /> System.Diagnostics.Process process) [0x00000] at<br /> System.Diagnostics.Process.Start (System.Diagnostics.ProcessStartInfo<br /> start Info) [0x00000] at MakeBundle.Execute (System.String cmdLine)<br /> [0x00000] at MakeBundle.GenerateBundles<br /> (System.Collections.ArrayList files) [0x00000] at MakeBundle.Main<br /> (System.String[] args) [0x00000]</p> <p><code>C:\Program Files\Mono-2.0.1\bin&gt;</code>\</p> </blockquote>
[ { "answer_id": 319072, "author": "user40711", "author_id": 40711, "author_profile": "https://Stackoverflow.com/users/40711", "pm_score": 2, "selected": true, "text": "c:\\mono" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40711/" ]
318,186
<p>We have to accept large file uploads (video content) and want to do that in a way that works well across all standards-compliant browsers and plug-ins. Our current setup looks like this:</p> <ul> <li><a href="http://swfupload.org" rel="nofollow noreferrer">SWFUpload</a></li> <li>input type="file" for graceful degradation</li> </ul> <p>On the server-side, we have <a href="http://nginx.net/" rel="nofollow noreferrer">nginx</a> and the <a href="http://www.grid.net.ru/nginx/upload.en.html" rel="nofollow noreferrer">upload module</a> streaming the uploaded files into the server, then handing the requests off to a merb app.</p> <p>Unfortunately, it looks like the recently released Adobe Flash Player 10 broke every single free/open uploading flash component out there (and then, some other sites which have their own proprietary versions as well), but some other sites, such as <a href="http://flickr.com" rel="nofollow noreferrer">Flickr</a> and <a href="http://vimeo.com" rel="nofollow noreferrer">Vimeo</a>, seem to work just fine.</p> <p>I've been poking around looking for other ways of doing this, but since compatibility with both Flash 9 and 10 is mandatory, I couldn't find a suitable solution. Any ideas?</p>
[ { "answer_id": 365882, "author": "Mauricio Scheffer", "author_id": 21239, "author_profile": "https://Stackoverflow.com/users/21239", "pm_score": 2, "selected": false, "text": "input type=\"file\"" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16944/" ]
318,198
<p>I'm generating titles out of a few other fields, and want the "right" way to do:</p> <pre><code>Me.Title.Value = Join(Array([Conference], [Speaker], partstr), " - ") </code></pre> <p>Except any of [conference], [speaker] or partstr might be null, and I don't want the extra "-"'s. Are there any functions that'll make this job straightforward?</p>
[ { "answer_id": 318253, "author": "DJ.", "author_id": 10492, "author_profile": "https://Stackoverflow.com/users/10492", "pm_score": 3, "selected": true, "text": "Dim Temp As String\n\nIf Not IsNull([Conference]) Then\n Temp = Temp & [Conference] & \" - \"\nEnd If\n\nIf Not IsNull([Speaker]) Then\n Temp = Temp & [Speaker] & \" - \"\nEnd If\n\nIf Not IsNull(partstr) Then\n Temp = Temp & partstr & \" - \"\nEnd If\n\nIf Temp > \"\" then\n Me.Title.Value = Left(Temp, Len(Temp) - 3)\nElse\n Me.Title.Value = Null\nEnd If\n" }, { "answer_id": 318299, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 0, "selected": false, "text": " IIf(IsNull(Partstr), IIf(IsNull(Conference), Speaker, Conference & \" - \" + Speaker), Conference + \" - \" & Speaker + \" - \" & Partstr)\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12874/" ]
318,199
<p>I'm planning to write a javascript-based web application. I'm wondering what the best way to implement it in terms of file stucture is.</p> <p>There is one main page (main.html) containing a menu and a main div section. The way it works is simple: When the user clicks on one of the links in the menu (for example 'Page 1'), the content of the div section is refreshed with the content of the page1.html file. This is done using javascript (jquery). If the user clicks on 'Page 2', the content of the page2.html file is loaded into the div section, etc.</p> <p>Each page has its own javascript code and as I prefer to keep it separate I've implemented a sort of 'code behind' like in asp.net:</p> <p><b>page1.html</b>:<br> &lt; script type="text/javascript" src="<b>page1.js"</b> >&lt; /script> <br> &lt;... html code ...> <br><br> <b>page2.html</b>:<br> &lt; script type="text/javascript" src="<b>page2.js"</b> >&lt; /script > <br> &lt;... html code ...></p> <p>When the user clicks on 'Page 1', the content of the page1.html file is loaded into the main div section of main.html. As page1.html is referencing page1.js, the javascript code in page1.js is also loaded.</p> <p>This seems to work fine but I'm wondering if it is the best way to implement this. At some point I was thinking of referencing all the javascript files in main.html This would also work fine but it would mean all the javascript files would have to be loaded in memory even if they are not going to be used. With the 1st approach, a javascript file is only loaded in memory before being actually used.</p> <p>Any ideas? What are the 'best practises' for this? Keep in mind that this is a web application (as opposed to a website). It will be available over the internet but only to some users (and it will be password protected) so I don't care about SEO etc.</p>
[ { "answer_id": 320630, "author": "Kornel", "author_id": 27009, "author_profile": "https://Stackoverflow.com/users/27009", "pm_score": 1, "selected": false, "text": "<script>…</script>" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15928/" ]
318,208
<p>Is it possible to cast an object in Java to a combined generic type?</p> <p>I have a method like:</p> <pre><code>public static &lt;T extends Foo &amp; Bar&gt; void doSomething(T object) { //do stuff } </code></pre> <p>Calling this method is no problem if I have a class that implements both interfaces (Foo &amp; Bar).</p> <p>The problem is when I need to call this method the object I need to pass to it is received as <code>java.lang.Object</code> and I need to cast it to make the compiler happy. But I can't figure out how to make this cast.</p> <p>edit:</p> <p>The problem lies in a function like this:</p> <pre><code>public void problemFunction (Object o) { if ( o instanceof Foo &amp;&amp; o instanceof Bar) { doSomething((Problematic cast) o); } } </code></pre> <p>}</p>
[ { "answer_id": 318325, "author": "erickson", "author_id": 3474, "author_profile": "https://Stackoverflow.com/users/3474", "pm_score": 4, "selected": false, "text": "interface Baz extends Foo, Bar { }\n\npublic void caller(Object w) {\n doSomething((Baz) w);\n}\n" }, { "answer_id": 318367, "author": "sk.", "author_id": 16399, "author_profile": "https://Stackoverflow.com/users/16399", "pm_score": -1, "selected": false, "text": "private interface FooBar extends Foo, Bar {}\npublic void problemFunction (Object o) {\n if ( o instanceof Foo && o instanceof Bar) {\n doSomething((FooBar) o);\n }\n}\n" }, { "answer_id": 318730, "author": "James Van Huis", "author_id": 31828, "author_profile": "https://Stackoverflow.com/users/31828", "pm_score": 3, "selected": false, "text": "public static <T extends Foo & Bar> void doSomething(T object)\n" }, { "answer_id": 27254181, "author": "user4316588", "author_id": 4316588, "author_profile": "https://Stackoverflow.com/users/4316588", "pm_score": 3, "selected": false, "text": "private <Q extends Foo & Bar> Q upcast(final Object in) {\n return (Q) in;\n}\n\n// ... elsewhere...\n\nif (myObject instanceof Foo && myObject instanceof Bar) {\n doSomething(upcast(myObject));\n}\n" }, { "answer_id": 33048780, "author": "Ron C", "author_id": 5230059, "author_profile": "https://Stackoverflow.com/users/5230059", "pm_score": 6, "selected": true, "text": "Object" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15355/" ]
318,210
<p>I'm trying to assert that one object is "equal" to another object. </p> <p>The objects are just instances of a class with a bunch of public properties. Is there an easy way to have NUnit assert equality based on the properties?</p> <p>This is my current solution but I think there may be something better:</p> <pre><code>Assert.AreEqual(LeftObject.Property1, RightObject.Property1) Assert.AreEqual(LeftObject.Property2, RightObject.Property2) Assert.AreEqual(LeftObject.Property3, RightObject.Property3) ... Assert.AreEqual(LeftObject.PropertyN, RightObject.PropertyN) </code></pre> <p>What I'm going for would be in the same spirit as the CollectionEquivalentConstraint wherein NUnit verifies that the contents of two collections are identical.</p>
[ { "answer_id": 318223, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 7, "selected": true, "text": "Assert.AreEqual(LeftObject, RightObject);\n" }, { "answer_id": 318238, "author": "Juanma", "author_id": 3730, "author_profile": "https://Stackoverflow.com/users/3730", "pm_score": 7, "selected": false, "text": "public static class AssertEx\n{\n public static void PropertyValuesAreEquals(object actual, object expected)\n {\n PropertyInfo[] properties = expected.GetType().GetProperties();\n foreach (PropertyInfo property in properties)\n {\n object expectedValue = property.GetValue(expected, null);\n object actualValue = property.GetValue(actual, null);\n\n if (actualValue is IList)\n AssertListsAreEquals(property, (IList)actualValue, (IList)expectedValue);\n else if (!Equals(expectedValue, actualValue))\n Assert.Fail(\"Property {0}.{1} does not match. Expected: {2} but was: {3}\", property.DeclaringType.Name, property.Name, expectedValue, actualValue);\n }\n }\n\n private static void AssertListsAreEquals(PropertyInfo property, IList actualList, IList expectedList)\n {\n if (actualList.Count != expectedList.Count)\n Assert.Fail(\"Property {0}.{1} does not match. Expected IList containing {2} elements but was IList containing {3} elements\", property.PropertyType.Name, property.Name, expectedList.Count, actualList.Count);\n\n for (int i = 0; i < actualList.Count; i++)\n if (!Equals(actualList[i], expectedList[i]))\n Assert.Fail(\"Property {0}.{1} does not match. Expected IList with element {1} equals to {2} but was IList with element {1} equals to {3}\", property.PropertyType.Name, property.Name, expectedList[i], actualList[i]);\n }\n}\n" }, { "answer_id": 432214, "author": "Chris Yoxall", "author_id": 53803, "author_profile": "https://Stackoverflow.com/users/53803", "pm_score": 5, "selected": false, "text": "// Sample class. This would be in your main assembly.\nclass Person\n{\n public string Name { get; set; }\n public int Age { get; set; }\n}\n\n// Unit tests\n[TestFixture]\npublic class PersonTests\n{\n private class PersonComparer : IEqualityComparer<Person>\n {\n public bool Equals(Person x, Person y)\n {\n if (x == null && y == null)\n {\n return true;\n }\n\n if (x == null || y == null)\n {\n return false;\n }\n\n return (x.Name == y.Name) && (x.Age == y.Age);\n }\n\n public int GetHashCode(Person obj)\n {\n throw new NotImplementedException();\n }\n }\n\n [Test]\n public void Test_PersonComparer()\n {\n Person p1 = new Person { Name = \"Tom\", Age = 20 }; // Control data\n\n Person p2 = new Person { Name = \"Tom\", Age = 20 }; // Same as control\n Person p3 = new Person { Name = \"Tom\", Age = 30 }; // Different age\n Person p4 = new Person { Name = \"Bob\", Age = 20 }; // Different name.\n\n Assert.IsTrue(new PersonComparer().Equals(p1, p2), \"People have same values\");\n Assert.IsFalse(new PersonComparer().Equals(p1, p3), \"People have different ages.\");\n Assert.IsFalse(new PersonComparer().Equals(p1, p4), \"People have different names.\");\n }\n}\n" }, { "answer_id": 4141219, "author": "Casey Burns", "author_id": 323778, "author_profile": "https://Stackoverflow.com/users/323778", "pm_score": 0, "selected": false, "text": "Test 'Telecom.SDP.SBO.App.Customer.Translator.UnitTests.TranslateEaiCustomerToDomain_Tests.TranslateNew_GivenEaiCustomer_ShouldTranslateToDomainCustomer_Test(\"ApprovedRatingInDb\")' failed:\n Expected string length 2841 but was 5034. Strings differ at index 443.\n Expected: \"...taClasses\" />\\r\\n <ContactMedia />\\r\\n <Party i:nil=\"true\" /...\"\n But was: \"...taClasses\" />\\r\\n <ContactMedia>\\r\\n <ContactMedium z:Id=\"...\"\n ----------------------------------------------^\n TranslateEaiCustomerToDomain_Tests.cs(201,0): at Telecom.SDP.SBO.App.Customer.Translator.UnitTests.TranslateEaiCustomerToDomain_Tests.Assert_CustomersAreEqual(Customer expectedCustomer, Customer actualCustomer)\n TranslateEaiCustomerToDomain_Tests.cs(114,0): at Telecom.SDP.SBO.App.Customer.Translator.UnitTests.TranslateEaiCustomerToDomain_Tests.TranslateNew_GivenEaiCustomer_ShouldTranslateToDomainCustomer_Test(String custRatingScenario)\n" }, { "answer_id": 7440471, "author": "dkl", "author_id": 243263, "author_profile": "https://Stackoverflow.com/users/243263", "pm_score": 7, "selected": false, "text": "dto.Should().BeEquivalentTo(customer) \n" }, { "answer_id": 10352071, "author": "Max", "author_id": 496991, "author_profile": "https://Stackoverflow.com/users/496991", "pm_score": 7, "selected": false, "text": "public static void AreEqualByJson(object expected, object actual)\n{\n var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();\n var expectedJson = serializer.Serialize(expected);\n var actualJson = serializer.Serialize(actual);\n Assert.AreEqual(expectedJson, actualJson);\n}\n" }, { "answer_id": 15434702, "author": "onedaywhen", "author_id": 15354, "author_profile": "https://Stackoverflow.com/users/15354", "pm_score": 2, "selected": false, "text": "Constraint" }, { "answer_id": 16819526, "author": "samaspin", "author_id": 763163, "author_profile": "https://Stackoverflow.com/users/763163", "pm_score": 2, "selected": false, "text": "public string GetObjectAsJson(object obj)\n {\n System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();\n return oSerializer.Serialize(obj);\n }\n" }, { "answer_id": 17040854, "author": "TiMoch", "author_id": 1121403, "author_profile": "https://Stackoverflow.com/users/1121403", "pm_score": 1, "selected": false, "text": "/// <summary>\n/// Returns the names of the properties that are not equal on a and b.\n/// </summary>\n/// <param name=\"a\"></param>\n/// <param name=\"b\"></param>\n/// <returns>An array of names of properties with distinct \n/// values or null if a and b are null or not of the same type\n/// </returns>\npublic static string[] GetDistinctProperties(object a, object b) {\n if (object.ReferenceEquals(a, b))\n return null;\n if (a == null)\n return null;\n if (b == null)\n return null;\n\n var aType = a.GetType();\n var bType = b.GetType();\n\n if (aType != bType)\n return null;\n\n var props = aType.GetProperties();\n\n if (props.Any(prop => prop.GetIndexParameters().Length != 0))\n throw new ArgumentException(\"Types with index properties not supported\");\n\n return props\n .Where(prop => !Equals(prop.GetValue(a, null), prop.GetValue(b, null)))\n .Select(prop => prop.Name).ToArray();\n} \n" }, { "answer_id": 28283833, "author": "Carlo V. Dango", "author_id": 454017, "author_profile": "https://Stackoverflow.com/users/454017", "pm_score": 1, "selected": false, "text": "class A\n{\n public DateTime X;\n public DateTime Y { get; set; }\n public string Name;\n}\n" }, { "answer_id": 28545338, "author": "Todd Menier", "author_id": 62600, "author_profile": "https://Stackoverflow.com/users/62600", "pm_score": 5, "selected": false, "text": "Expected string length 2326 but was 2342. Strings differ at index 1729.\n" }, { "answer_id": 30420126, "author": "In91", "author_id": 997502, "author_profile": "https://Stackoverflow.com/users/997502", "pm_score": 2, "selected": false, "text": " [TestMethod]\n public void Test_Person_Equals_with_ExpectedObjects()\n {\n //use extension method ToExpectedObject() from using ExpectedObjects namespace to project Person to ExpectedObject\n var expected = new Person\n {\n Id = 1,\n Name = \"A\",\n Age = 10,\n }.ToExpectedObject();\n\n var actual = new Person\n {\n Id = 1,\n Name = \"A\",\n Age = 10,\n };\n\n //use ShouldEqual to compare expected and actual instance, if they are not equal, it will throw a System.Exception and its message includes what properties were not match our expectation.\n expected.ShouldEqual(actual);\n }\n\n [TestMethod]\n public void Test_PersonCollection_Equals_with_ExpectedObjects()\n {\n //collection just invoke extension method: ToExpectedObject() to project Collection<Person> to ExpectedObject too\n var expected = new List<Person>\n {\n new Person { Id=1, Name=\"A\",Age=10},\n new Person { Id=2, Name=\"B\",Age=20},\n new Person { Id=3, Name=\"C\",Age=30},\n }.ToExpectedObject();\n\n var actual = new List<Person>\n {\n new Person { Id=1, Name=\"A\",Age=10},\n new Person { Id=2, Name=\"B\",Age=20},\n new Person { Id=3, Name=\"C\",Age=30},\n };\n\n expected.ShouldEqual(actual);\n }\n\n [TestMethod]\n public void Test_ComposedPerson_Equals_with_ExpectedObjects()\n {\n //ExpectedObject will compare each value of property recursively, so composed type also simply compare equals.\n var expected = new Person\n {\n Id = 1,\n Name = \"A\",\n Age = 10,\n Order = new Order { Id = 91, Price = 910 },\n }.ToExpectedObject();\n\n var actual = new Person\n {\n Id = 1,\n Name = \"A\",\n Age = 10,\n Order = new Order { Id = 91, Price = 910 },\n };\n\n expected.ShouldEqual(actual);\n }\n\n [TestMethod]\n public void Test_PartialCompare_Person_Equals_with_ExpectedObjects()\n {\n //when partial comparing, you need to use anonymous type too. Because only anonymous type can dynamic define only a few properties should be assign.\n var expected = new\n {\n Id = 1,\n Age = 10,\n Order = new { Id = 91 }, // composed type should be used anonymous type too, only compare properties. If you trace ExpectedObjects's source code, you will find it invoke config.IgnoreType() first.\n }.ToExpectedObject();\n\n var actual = new Person\n {\n Id = 1,\n Name = \"B\",\n Age = 10,\n Order = new Order { Id = 91, Price = 910 },\n };\n\n // partial comparing use ShouldMatch(), rather than ShouldEqual()\n expected.ShouldMatch(actual);\n }\n" }, { "answer_id": 33717316, "author": "Paul Hicks", "author_id": 3195526, "author_profile": "https://Stackoverflow.com/users/3195526", "pm_score": 3, "selected": false, "text": "Assert.That(ActualObject, Has.Property(\"Prop1\").EqualTo(ExpectedObject.Prop1)\n & Has.Property(\"Prop2\").EqualTo(ExpectedObject.Prop2)\n & Has.Property(\"Prop3\").EqualTo(ExpectedObject.Prop3)\n // ...\n" }, { "answer_id": 37198353, "author": "user2315856", "author_id": 2315856, "author_profile": "https://Stackoverflow.com/users/2315856", "pm_score": 2, "selected": false, "text": "NUnit.Framework.Is.EqualTo" }, { "answer_id": 46894327, "author": "Alex Zhukovskiy", "author_id": 2559709, "author_profile": "https://Stackoverflow.com/users/2559709", "pm_score": 1, "selected": false, "text": "public static class AllFieldsEqualityComprision<T>\n{\n public static Comparison<T> Instance { get; } = GetInstance();\n\n private static Comparison<T> GetInstance()\n {\n var type = typeof(T);\n ParameterExpression[] parameters =\n {\n Expression.Parameter(type, \"x\"),\n Expression.Parameter(type, \"y\")\n };\n var result = type.GetProperties().Aggregate<PropertyInfo, Expression>(\n Expression.Constant(true),\n (acc, prop) =>\n Expression.And(acc,\n Expression.Equal(\n Expression.Property(parameters[0], prop.Name),\n Expression.Property(parameters[1], prop.Name))));\n var areEqualExpression = Expression.Condition(result, Expression.Constant(0), Expression.Constant(1));\n return Expression.Lambda<Comparison<T>>(areEqualExpression, parameters).Compile();\n }\n}\n" }, { "answer_id": 71508710, "author": "Cristian Rusanu", "author_id": 2065371, "author_profile": "https://Stackoverflow.com/users/2065371", "pm_score": 0, "selected": false, "text": "public static class Helpers {\n\n public static bool DeepCompare(this object actual, object expected) {\n var properties = expected.GetType().GetProperties();\n foreach (var property in properties) {\n var expectedValue = property.GetValue(expected, null);\n var actualValue = property.GetValue(actual, null);\n\n if (actualValue == null && expectedValue == null) {\n return true;\n }\n\n if (actualValue == null || expectedValue == null) {\n return false;\n }\n\n if (actualValue is IList actualList) {\n if (!AreListsEqual(actualList, (IList)expectedValue)) {\n return false;\n }\n }\n else if (IsValueType(expectedValue)) {\n if(!Equals(expectedValue, actualValue)) {\n return false;\n }\n }\n else if (expectedValue is string) {\n return actualValue is string && Equals(expectedValue, actualValue);\n }\n else if (!DeepCompare(expectedValue, actualValue)) {\n return false;\n }\n \n }\n return true;\n }\n\n private static bool AreListsEqual(IList actualList, IList expectedList) {\n if (actualList == null && expectedList == null) {\n return true;\n }\n\n if (actualList == null || expectedList == null) {\n return false;\n }\n\n if (actualList.Count != expectedList.Count) {\n return false;\n }\n\n if (actualList.Count == 0) {\n return true;\n }\n\n var isValueTypeOrString = IsValueType(actualList[0]) || actualList[0] is string;\n\n if (isValueTypeOrString) {\n for (var i = 0; i < actualList.Count; i++) {\n if (!Equals(actualList[i], expectedList[i])) {\n return false;\n }\n }\n }\n else {\n for (var i = 0; i < actualList.Count; i++) {\n if (!DeepCompare(actualList[i], expectedList[i])) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n private static bool IsValueType(object obj) {\n return obj != null && obj.GetType().IsValueType;\n }\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29/" ]
318,215
<p>is it possible to create something like <a href="https://web.archive.org/web/20200805044711/http://geekswithblogs.net/AzamSharp/archive/2008/02/24/119946.aspx" rel="nofollow noreferrer">this</a> i ASP.NET MVC beta 1</p> <p>i have tried but the</p> <pre><code>override bool OnPreAction(string actionName, System.Reflection.MethodInfo methodInfo) </code></pre> <p>does not exsist anymore and</p> <pre><code>override void OnActionExecuting(ActionExecutingContext filterContext) </code></pre> <p>don't give me access to the action name</p>
[ { "answer_id": 318280, "author": "Rune", "author_id": 40348, "author_profile": "https://Stackoverflow.com/users/40348", "pm_score": 4, "selected": true, "text": "[Authorize(Roles=\"Admin, Editor\")]\npublic ActionResult Delete(int id){\n (...)\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31296/" ]
318,236
<p>I don't need to validate that the IP address is reachable or anything like that. I just want to validate that the string is in dotted-quad (xxx.xxx.xxx.xxx) IPv4 format, where xxx is between 0 and 255.</p>
[ { "answer_id": 318256, "author": "Martin Cote", "author_id": 9936, "author_profile": "https://Stackoverflow.com/users/9936", "pm_score": 2, "selected": false, "text": "bool validate_ip_address(const std::string& s)\n{\n static const boost::regex e(\"\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\");\n return regex_match(s, e);\n}\n" }, { "answer_id": 318326, "author": "Steve", "author_id": 1965047, "author_profile": "https://Stackoverflow.com/users/1965047", "pm_score": 3, "selected": false, "text": "bool IsIPAddress(std::string & ipaddr)\n { \n\n StringTokenizer quads(ipaddr,\".\");\n\n if (quads.countTokens() != 4) return false;\n\n for (int i=0; i < 4; i++)\n {\n std::string quad = quads.nextToken();\n for (int j=0; j < quad.length(); j++\n if (!isdigit(quad[j])) return false;\n\n int quad = atoi(quads.GetTokenAt(i));\n if (quad < 0) || (quad > 255)) return false;\n }\n\n return true;\n }\n" }, { "answer_id": 318343, "author": "Mihai Limbășan", "author_id": 14444, "author_profile": "https://Stackoverflow.com/users/14444", "pm_score": 4, "selected": false, "text": "192.168.1.010" }, { "answer_id": 335263, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 6, "selected": false, "text": "#include <arpa/inet.h>\n// ...\nbool Config::validateIpAddress(const string &ipAddress)\n{\n struct sockaddr_in sa;\n int result = inet_pton(AF_INET, ipAddress.c_str(), &(sa.sin_addr));\n return result != 0;\n}\n" }, { "answer_id": 1630159, "author": "Björn Pollex", "author_id": 160206, "author_profile": "https://Stackoverflow.com/users/160206", "pm_score": 6, "selected": false, "text": "std::string ipAddress = \"127.0.0.1\";\nboost::system::error_code ec;\nboost::asio::ip::address::from_string( ipAddress, ec );\nif ( ec )\n std::cerr << ec.message( ) << std::endl;\n" }, { "answer_id": 6655926, "author": "Amir", "author_id": 781864, "author_profile": "https://Stackoverflow.com/users/781864", "pm_score": 1, "selected": false, "text": "vector<string> &split(const string &s, char delim, vector<string> &elems) {\n stringstream ss(s);\n string item;\n while(getline(ss, item, delim)) {\n elems.push_back(item);\n }\n return elems;\n}\n\nvector<string> split(const string &s, char delim) {\n vector<string> elems;\n return split(s, delim, elems);\n}\n\n\nbool isIPAddress(string ipaddr){\n\n if (ipaddr.length()){\n vector<string> _ip=split(ipaddr,'.');\n if (_ip.size()==4){\n for (int i=0; i < 4; i++){\n for (int j=0; j < _ip[i].length(); j++)\n if (!isdigit(_ip[i][j])) return false;\n if ((atoi(_ip[i].c_str()) < 0) || (atoi(_ip[i].c_str()) > 255)) return false;\n }\n return true;\n }\n }\n return false;\n }\n" }, { "answer_id": 10200328, "author": "Savi", "author_id": 1339941, "author_profile": "https://Stackoverflow.com/users/1339941", "pm_score": 2, "selected": false, "text": " // strTokenFunction.cpp : Check if the specified address is a valid numeric IP address.\n // This function is equavalent to the IPAddress.TryParse() method in C#\n\n#include \"stdafx.h\"\n#include <stdio.h>\n#include <conio.h>\n#include <string.h>\n\nbool isValidIpAddress(char *st)\n{\n int num, i, len;\n char *ch;\n\n //counting number of quads present in a given IP address\n int quadsCnt=0;\n\n printf(\"Split IP: \\\"%s\\\"\\n\", st);\n\n len = strlen(st);\n\n // Check if the string is valid\n if(len<7 || len>15)\n return false;\n\n ch = strtok(st, \".\");\n\n while (ch != NULL) \n {\n quadsCnt++;\n printf(\"Quald %d is %s\\n\", quadsCnt, ch);\n\n num = 0;\n i = 0;\n\n // Get the current token and convert to an integer value\n while(ch[i]!='\\0')\n {\n num = num*10;\n num = num+(ch[i]-'0');\n i++;\n }\n\n if(num<0 || num>255)\n {\n printf(\"Not a valid ip\\n\");\n return false;\n }\n\n if( (quadsCnt == 1 && num == 0) || (quadsCnt == 4 && num == 0))\n {\n printf(\"Not a valid ip, quad: %d AND/OR quad:%d is zero\\n\", quadsCnt, quadsCnt);\n return false;\n }\n\n ch = strtok(NULL, \".\");\n }\n\n // Check the address string, should be n.n.n.n format\n if(quadsCnt!=4)\n {\n return false;\n }\n\n // Looks like a valid IP address\n return true;\n}\n\nint main() \n{\n char st[] = \"192.255.20.30\";\n //char st[] = \"255.255.255.255\";\n //char st[] = \"0.255.255.0\";\n\n if(isValidIpAddress(st))\n {\n printf(\"The given IP is a valid IP address\\n\"); \n }\n else\n {\n printf(\"The given IP is not a valid IP address\\n\");\n }\n}\n" }, { "answer_id": 13009193, "author": "user1740538", "author_id": 1740538, "author_profile": "https://Stackoverflow.com/users/1740538", "pm_score": 3, "selected": false, "text": "WSAStringToAddress" }, { "answer_id": 20760364, "author": "user2314327", "author_id": 2314327, "author_profile": "https://Stackoverflow.com/users/2314327", "pm_score": 1, "selected": false, "text": "\n\n\n #include <iostream>\n #include <vector>\n #include <string>\n #include <sstream>\n #include <algorithm>\n #include <iterator>\n #include <stdio.h>\n\n using namespace std;\n\n vector split(char* str, char delimiter)\n {\n const string data(str);\n vector elements;\n string element;\n for(int i = 0; i 0) {//resolve problem: 127.0..1\n elements.push_back(element);\n element.clear();\n }\n }\n else if (data[i] != ' ')\n {\n element += data[i];\n }\n\n }\n if (element.length() > 0)//resolve problem: 127.0..1\n elements.push_back(element);\n return elements;\n }\n\n bool toInt(const string& str, int* result)\n {\n if (str.find_first_not_of(\"0123456789\") != string::npos)\n return false;\n\n stringstream stream(str);\n stream >> *result; // Should probably check the return value here\n return true;\n }\n\n /** ipResult: the good ip address, e.g. spaces are removed */\n bool validate(char* ip, string *ipResult)\n {\n const static char delimiter = '.';\n const vector parts = split(ip, delimiter);\n *ipResult = \"\";\n if (parts.size() != 4)\n return NULL;\n\n for(int i = 0; i 255)\n return NULL;\n\n if (i == 3) {\n *ipResult += parts[i];\n } else {\n *ipResult += (parts[i] +\".\");\n }\n\n }\n return true;\n }\n\n int main()\n {\n string ip;\n printf(\"right %d\\n\", validate(\"127.0.0.1\", &ip));\n printf(\"good ip: %s\\n\", ip.c_str());\n printf(\"wrong %d\\n\", validate(\"127.0.0.-1\", &ip));\n printf(\"good ip: %s\\n\", ip.c_str());\n printf(\"wrong %d\\n\", validate(\"127..0.1\", &ip));\n printf(\"good ip: %s\\n\", ip.c_str());\n printf(\"wrong %d\\n\", validate(\"...0.1\", &ip));\n printf(\"good ip: %s\\n\", ip.c_str());\n printf(\"wrong %d\\n\", validate(\"127.0.0.\", &ip));\n printf(\"good ip: %s\\n\", ip.c_str());\n printf(\"right %d\\n\", validate(\"192.168.170.99\", &ip));\n printf(\"good ip: %s\\n\", ip.c_str());\n printf(\"right %d\\n\", validate(\"127.0 .0 .1\", &ip));\n printf(\"good ip: %s\\n\", ip.c_str());\n printf(\"\\n\");\n\n system(\"pause\");\n\n return 0;\n }\n\n" }, { "answer_id": 50539355, "author": "Kim Ninh", "author_id": 8296502, "author_profile": "https://Stackoverflow.com/users/8296502", "pm_score": 3, "selected": false, "text": "bool isValidIPv4(const char *IPAddress)\n{\n unsigned char a,b,c,d;\n return sscanf(IPAddress,\"%d.%d.%d.%d\", &a, &b, &c, &d) == 4;\n}\n" }, { "answer_id": 54157885, "author": "A. Smoliak", "author_id": 9334808, "author_profile": "https://Stackoverflow.com/users/9334808", "pm_score": 1, "selected": false, "text": "8.8.8.8" }, { "answer_id": 56296939, "author": "Piotr K", "author_id": 11551533, "author_profile": "https://Stackoverflow.com/users/11551533", "pm_score": 0, "selected": false, "text": "void validate_ip_address(const std::string& s) {\n const std::string number_0_255 = \"((([0-9])|([1-9][0-9])|(1[0-9][0-9]|2[0-4][0-9]|25[0-5])){1})\";\n const std::string dot = \"(\\\\.){1}\";\n static const boost::regex e(number_0_255 + dot + number_0_255 + dot + number_0_255 + dot + number_0_255);\n if (!regex_match(s, e)) {\n throw std::runtime_error(std::string(\"Uncorrect address IP: \") + s);\n }\n}\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1288/" ]
318,239
<p>How do I set environment variables from Java? I see that I can do this for subprocesses using <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html" rel="noreferrer"><code>ProcessBuilder</code></a>. I have several subprocesses to start, though, so I'd rather modify the current process's environment and let the subprocesses inherit it.</p> <p>There's a <code>System.getenv(String)</code> for getting a single environment variable. I can also get a <code>Map</code> of the complete set of environment variables with <code>System.getenv()</code>. But, calling <code>put()</code> on that <code>Map</code> throws an <code>UnsupportedOperationException</code> -- apparently they mean for the environment to be read only. And, there's no <code>System.setenv()</code>.</p> <p>So, is there any way to set environment variables in the currently running process? If so, how? If not, what's the rationale? (Is it because this is Java and therefore I shouldn't be doing evil nonportable obsolete things like touching my environment?) And if not, any good suggestions for managing the environment variable changes that I'm going to need to be feeding to several subprocesses?</p>
[ { "answer_id": 318247, "author": "matt b", "author_id": 4249, "author_profile": "https://Stackoverflow.com/users/4249", "pm_score": -1, "selected": false, "text": "java -cp <classpath> -Dkey1=value -Dkey2=value ...\n" }, { "answer_id": 318252, "author": "Michael Myers", "author_id": 13531, "author_profile": "https://Stackoverflow.com/users/13531", "pm_score": 8, "selected": true, "text": "void setUpEnvironment(ProcessBuilder builder) {\n Map<String, String> env = builder.environment();\n // blah blah\n}\n" }, { "answer_id": 496849, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "public static void set(Map<String, String> newenv) throws Exception {\n Class[] classes = Collections.class.getDeclaredClasses();\n Map<String, String> env = System.getenv();\n for(Class cl : classes) {\n if(\"java.util.Collections$UnmodifiableMap\".equals(cl.getName())) {\n Field field = cl.getDeclaredField(\"m\");\n field.setAccessible(true);\n Object obj = field.get(env);\n Map<String, String> map = (Map<String, String>) obj;\n map.clear();\n map.putAll(newenv);\n }\n }\n}\n" }, { "answer_id": 4487735, "author": "anonymous", "author_id": 548337, "author_profile": "https://Stackoverflow.com/users/548337", "pm_score": 5, "selected": false, "text": "// this is a dirty hack - but should be ok for a unittest.\nprivate void setNewEnvironmentHack(Map<String, String> newenv) throws Exception\n{\n Class<?> processEnvironmentClass = Class.forName(\"java.lang.ProcessEnvironment\");\n Field theEnvironmentField = processEnvironmentClass.getDeclaredField(\"theEnvironment\");\n theEnvironmentField.setAccessible(true);\n Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);\n env.clear();\n env.putAll(newenv);\n Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField(\"theCaseInsensitiveEnvironment\");\n theCaseInsensitiveEnvironmentField.setAccessible(true);\n Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);\n cienv.clear();\n cienv.putAll(newenv);\n}\n" }, { "answer_id": 7201825, "author": "pushy", "author_id": 663130, "author_profile": "https://Stackoverflow.com/users/663130", "pm_score": 8, "selected": false, "text": "protected static void setEnv(Map<String, String> newenv) throws Exception {\n try {\n Class<?> processEnvironmentClass = Class.forName(\"java.lang.ProcessEnvironment\");\n Field theEnvironmentField = processEnvironmentClass.getDeclaredField(\"theEnvironment\");\n theEnvironmentField.setAccessible(true);\n Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);\n env.putAll(newenv);\n Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField(\"theCaseInsensitiveEnvironment\");\n theCaseInsensitiveEnvironmentField.setAccessible(true);\n Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);\n cienv.putAll(newenv);\n } catch (NoSuchFieldException e) {\n Class[] classes = Collections.class.getDeclaredClasses();\n Map<String, String> env = System.getenv();\n for(Class cl : classes) {\n if(\"java.util.Collections$UnmodifiableMap\".equals(cl.getName())) {\n Field field = cl.getDeclaredField(\"m\");\n field.setAccessible(true);\n Object obj = field.get(env);\n Map<String, String> map = (Map<String, String>) obj;\n map.clear();\n map.putAll(newenv);\n }\n }\n }\n}\n" }, { "answer_id": 19040660, "author": "Paul Blair", "author_id": 1476910, "author_profile": "https://Stackoverflow.com/users/1476910", "pm_score": 3, "selected": false, "text": "java.lang.String cannot be cast to java.lang.ProcessEnvironment$Variable\n" }, { "answer_id": 20437164, "author": "Hans-Christoph Steiner", "author_id": 306864, "author_profile": "https://Stackoverflow.com/users/306864", "pm_score": 3, "selected": false, "text": "java.lang.ProcessEnvironment" }, { "answer_id": 22315463, "author": "user3404318", "author_id": 3404318, "author_profile": "https://Stackoverflow.com/users/3404318", "pm_score": 4, "selected": false, "text": "Libcore.os.setenv(\"VAR\", \"value\", bOverwrite);\nLibcore.os.getenv(\"VAR\"));\n" }, { "answer_id": 38073822, "author": "mangusbrother", "author_id": 1860517, "author_profile": "https://Stackoverflow.com/users/1860517", "pm_score": 4, "selected": false, "text": "java version \"1.8.0_92\"\nJava(TM) SE Runtime Environment (build 1.8.0_92-b14)\nJava HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)\n" }, { "answer_id": 40682052, "author": "Hubert Grzeskowiak", "author_id": 2445864, "author_profile": "https://Stackoverflow.com/users/2445864", "pm_score": 5, "selected": false, "text": "public static void setEnv(String key, String value) {\n try {\n Map<String, String> env = System.getenv();\n Class<?> cl = env.getClass();\n Field field = cl.getDeclaredField(\"m\");\n field.setAccessible(true);\n Map<String, String> writableEnv = (Map<String, String>) field.get(env);\n writableEnv.put(key, value);\n } catch (Exception e) {\n throw new IllegalStateException(\"Failed to set environment variable\", e);\n }\n}\n" }, { "answer_id": 42964302, "author": "Tim Ryan", "author_id": 6471212, "author_profile": "https://Stackoverflow.com/users/6471212", "pm_score": 3, "selected": false, "text": "private Map<String, String> getModifiableEnvironmentMap() {\n try {\n Map<String,String> unmodifiableEnv = System.getenv();\n Class<?> cl = unmodifiableEnv.getClass();\n Field field = cl.getDeclaredField(\"m\");\n field.setAccessible(true);\n Map<String,String> modifiableEnv = (Map<String,String>) field.get(unmodifiableEnv);\n return modifiableEnv;\n } catch(Exception e) {\n throw new RuntimeException(\"Unable to access writable environment variable map.\");\n }\n}\n\nprivate Map<String, String> getModifiableEnvironmentMap2() {\n try {\n Class<?> processEnvironmentClass = Class.forName(\"java.lang.ProcessEnvironment\");\n Field theUnmodifiableEnvironmentField = processEnvironmentClass.getDeclaredField(\"theUnmodifiableEnvironment\");\n theUnmodifiableEnvironmentField.setAccessible(true);\n Map<String,String> theUnmodifiableEnvironment = (Map<String,String>)theUnmodifiableEnvironmentField.get(null);\n\n Class<?> theUnmodifiableEnvironmentClass = theUnmodifiableEnvironment.getClass();\n Field theModifiableEnvField = theUnmodifiableEnvironmentClass.getDeclaredField(\"m\");\n theModifiableEnvField.setAccessible(true);\n Map<String,String> modifiableEnv = (Map<String,String>) theModifiableEnvField.get(theUnmodifiableEnvironment);\n return modifiableEnv;\n } catch(Exception e) {\n throw new RuntimeException(\"Unable to access writable environment variable map.\");\n }\n}\n\nprivate Map<String, String> clearEnvironmentVars(String[] keys) {\n\n Map<String,String> modifiableEnv = getModifiableEnvironmentMap();\n\n HashMap<String, String> savedVals = new HashMap<String, String>();\n\n for(String k : keys) {\n String val = modifiableEnv.remove(k);\n if (val != null) { savedVals.put(k, val); }\n }\n return savedVals;\n}\n\nprivate void setEnvironmentVars(Map<String, String> varMap) {\n getModifiableEnvironmentMap().putAll(varMap); \n}\n\n@Test\npublic void myTest() {\n String[] keys = { \"key1\", \"key2\", \"key3\" };\n Map<String, String> savedVars = clearEnvironmentVars(keys);\n\n // do test\n\n setEnvironmentVars(savedVars);\n}\n" }, { "answer_id": 51167959, "author": "Rik", "author_id": 2219288, "author_profile": "https://Stackoverflow.com/users/2219288", "pm_score": -1, "selected": false, "text": "fun setEnv(newEnv: Map<String, String>) {\n val unmodifiableMapClass = Collections.unmodifiableMap<Any, Any>(mapOf()).javaClass\n with(unmodifiableMapClass.getDeclaredField(\"m\")) {\n isAccessible = true\n @Suppress(\"UNCHECKED_CAST\")\n get(System.getenv()) as MutableMap<String, String>\n }.apply {\n clear()\n putAll(newEnv)\n }\n}\n" }, { "answer_id": 55881892, "author": "GarouDan", "author_id": 727184, "author_profile": "https://Stackoverflow.com/users/727184", "pm_score": 1, "selected": false, "text": "@Suppress(\"UNCHECKED_CAST\")\n@Throws(Exception::class)\nfun setEnv(newenv: Map<String, String>) {\n try {\n val processEnvironmentClass = Class.forName(\"java.lang.ProcessEnvironment\")\n val theEnvironmentField = processEnvironmentClass.getDeclaredField(\"theEnvironment\")\n theEnvironmentField.isAccessible = true\n val env = theEnvironmentField.get(null) as MutableMap<String, String>\n env.putAll(newenv)\n val theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField(\"theCaseInsensitiveEnvironment\")\n theCaseInsensitiveEnvironmentField.isAccessible = true\n val cienv = theCaseInsensitiveEnvironmentField.get(null) as MutableMap<String, String>\n cienv.putAll(newenv)\n } catch (e: NoSuchFieldException) {\n val classes = Collections::class.java.getDeclaredClasses()\n val env = System.getenv()\n for (cl in classes) {\n if (\"java.util.Collections\\$UnmodifiableMap\" == cl.getName()) {\n val field = cl.getDeclaredField(\"m\")\n field.setAccessible(true)\n val obj = field.get(env)\n val map = obj as MutableMap<String, String>\n map.clear()\n map.putAll(newenv)\n }\n }\n }\n" }, { "answer_id": 57274095, "author": "Alex", "author_id": 417291, "author_profile": "https://Stackoverflow.com/users/417291", "pm_score": -1, "selected": false, "text": "was.app.config.properties.toSystemProperties\n" }, { "answer_id": 58399256, "author": "Keith K", "author_id": 2249575, "author_profile": "https://Stackoverflow.com/users/2249575", "pm_score": 0, "selected": false, "text": "def set_env(newenv):\n from java.lang import Class\n process_environment = Class.forName(\"java.lang.ProcessEnvironment\")\n environment_field = process_environment.getDeclaredField(\"theEnvironment\")\n environment_field.setAccessible(True)\n env = environment_field.get(None)\n env.putAll(newenv)\n invariant_environment_field = process_environment.getDeclaredField(\"theCaseInsensitiveEnvironment\");\n invariant_environment_field.setAccessible(True)\n invevn = invariant_environment_field.get(None)\n invevn.putAll(newenv)\n" }, { "answer_id": 59522743, "author": "mike rodent", "author_id": 595305, "author_profile": "https://Stackoverflow.com/users/595305", "pm_score": 2, "selected": false, "text": "import java.lang.reflect.Field\n\ndef getModifiableEnvironmentMap() {\n def unmodifiableEnv = System.getenv()\n Class cl = unmodifiableEnv.getClass()\n Field field = cl.getDeclaredField(\"m\")\n field.accessible = true\n field.get(unmodifiableEnv)\n}\n\ndef clearEnvironmentVars( def keys ) {\n def savedVals = [:]\n keys.each{ key ->\n String val = modifiableEnvironmentMap.remove(key)\n // thinking about it, I'm not sure why we need this test for null\n // but haven't yet done any experiments\n if( val != null ) {\n savedVals.put( key, val )\n }\n }\n savedVals\n}\n\ndef setEnvironmentVars(Map varMap) {\n modifiableEnvironmentMap.putAll(varMap)\n}\n\n// pretend existing Env Var doesn't exist\ndef PATHVal1 = System.env.PATH\nprintln \"PATH val1 |$PATHVal1|\"\nString[] keys = [\"PATH\", \"key2\", \"key3\"]\ndef savedVars = clearEnvironmentVars(keys)\ndef PATHVal2 = System.env.PATH\nprintln \"PATH val2 |$PATHVal2|\"\n\n// return to reality\nsetEnvironmentVars(savedVars)\ndef PATHVal3 = System.env.PATH\nprintln \"PATH val3 |$PATHVal3|\"\nprintln \"System.env |$System.env|\"\n\n// pretend a non-existent Env Var exists\nsetEnvironmentVars( [ 'key4' : 'key4Val' ])\nprintln \"key4 val |$System.env.key4|\"\n" }, { "answer_id": 59594835, "author": "Tiarê Balbi", "author_id": 1415751, "author_profile": "https://Stackoverflow.com/users/1415751", "pm_score": 0, "selected": false, "text": "import java.util.Collections\nimport kotlin.reflect.KProperty\n​\nclass EnvironmentDelegate {\n operator fun getValue(thisRef: Any?, property: KProperty<*>): String {\n return System.getenv(property.name) ?: \"-\"\n }\n​\n operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {\n val key = property.name\n​\n val classes: Array<Class<*>> = Collections::class.java.declaredClasses\n val env = System.getenv()\n​\n val cl = classes.first { \"java.util.Collections\\$UnmodifiableMap\" == it.name }\n​\n val field = cl.getDeclaredField(\"m\")\n field.isAccessible = true\n val obj = field[env]\n val map = obj as MutableMap<String, String>\n map.putAll(mapOf(key to value))\n }\n}\n​\nclass KnownProperties {\n var JAVA_HOME: String by EnvironmentDelegate()\n var sample: String by EnvironmentDelegate()\n}\n​\nfun main() {\n val knowProps = KnownProperties()\n knowProps.sample = \"2\"\n​\n println(\"Java Home: ${knowProps.JAVA_HOME}\")\n println(\"Sample: ${knowProps.sample}\")\n}\n" }, { "answer_id": 63736173, "author": "Arun Sharma", "author_id": 5810983, "author_profile": "https://Stackoverflow.com/users/5810983", "pm_score": 1, "selected": false, "text": "setx JAVA_LOC C:/Java/JDK\n" }, { "answer_id": 67635072, "author": "Ashley Frieze", "author_id": 1355930, "author_profile": "https://Stackoverflow.com/users/1355930", "pm_score": 3, "selected": false, "text": "public class JUnitTest {\n\n @Rule\n public EnvironmentVariables environmentVariables = new EnvironmentVariables();\n\n @Test\n public void someTest() {\n environmentVariables.set(\"SOME_VARIABLE\", \"myValue\");\n \n // now System.getenv does what you want\n }\n}\n" }, { "answer_id": 69579032, "author": "geosmart", "author_id": 3480359, "author_profile": "https://Stackoverflow.com/users/3480359", "pm_score": 2, "selected": false, "text": "setEnv(\"k1\",\"v1\")" }, { "answer_id": 69630862, "author": "Johan Ansems", "author_id": 6110300, "author_profile": "https://Stackoverflow.com/users/6110300", "pm_score": 2, "selected": false, "text": "private static void setEnv(String key, String value) {\n if(isWindows()) {\n if (!Kernel32.INSTANCE.SetEnvironmentVariable(key, value)) {\n System.err.println(\"Unable to set the environemnt variable: \" + key);\n }\n }\n}\n" }, { "answer_id": 70095906, "author": "deddu", "author_id": 2168258, "author_profile": "https://Stackoverflow.com/users/2168258", "pm_score": 2, "selected": false, "text": "@Test\n@SetEnvironmentVariable(key = \"some variable\",value = \"new value\")\nvoid test() {\n assertThat(System.getenv(\"some variable\")).\n isEqualTo(\"new value\");\n}\n\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18103/" ]
318,241
<p>I am trying to use symbolic links in one of the applications I have running on Tomcat5. Thanks to some help from <a href="https://stackoverflow.com/questions/315093/configure-symlinks-for-single-directory-in-tomcat">another StackOverflow question</a> I was able to do it by creating a context.xml file in</p> <p>/...myapplication/META-INF/context.xml</p> <p>I am now trying to implement this on a production server. However, there are other applications running on it. And there is another context file</p> <p>/...tomcat/conf/context.xml</p> <p>It seems to me these are setting configurations server-wide to all applications. If I allowLinks in the conf/context.xml file, my symbolic links work. If I don't allowLinks in conf/context.xml, my application's symbolic links do not work, even though I have allowed them in the META-INF/context.xml</p> <p>My question is, does the conf/context.xml control all applications? If I want symbolic links to work only in one application, do I need to remove the conf/context.xml and create new context files for each application? Or is there a way I can allow symbolic links in myapplication only?</p>
[ { "answer_id": 322676, "author": "netjeff", "author_id": 41191, "author_profile": "https://Stackoverflow.com/users/41191", "pm_score": 4, "selected": true, "text": "allowLinks" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318241", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28351/" ]
318,246
<p>how do i define a named_scope to return all the records that were created within the last 7 days, and then how do i use that named scope in a controller?</p>
[ { "answer_id": 318346, "author": "TonyLa", "author_id": 1295, "author_profile": "https://Stackoverflow.com/users/1295", "pm_score": 0, "selected": false, "text": " named_scope \\\n :this_week,\n :conditions => [\n %created_at > :time!,\n proc {{:time => Time.now}}\n ]\n" }, { "answer_id": 318380, "author": "mwilliams", "author_id": 23909, "author_profile": "https://Stackoverflow.com/users/23909", "pm_score": 4, "selected": true, "text": " named_scope :recent, \n lambda { |*args| {:conditions => [\"created_at > ?\", (args.first || 7.days.ago)]} }\n" }, { "answer_id": 56857896, "author": "Datt", "author_id": 1398515, "author_profile": "https://Stackoverflow.com/users/1398515", "pm_score": 0, "selected": false, "text": "last 7 days" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18811/" ]
318,255
<p>I have a string like "1234567890". Now I need to store/print out this with the following format, 123-456-7890</p> <p>What is the best method to implement this in C?</p> <p>Thanks for comments/answers.</p>
[ { "answer_id": 318382, "author": "BIBD", "author_id": 685, "author_profile": "https://Stackoverflow.com/users/685", "pm_score": 0, "selected": false, "text": "strncpy (dest, src + startPos, copyLength)\n" }, { "answer_id": 318492, "author": "efotinis", "author_id": 12320, "author_profile": "https://Stackoverflow.com/users/12320", "pm_score": 0, "selected": false, "text": "const char* input = \"1234567890\";\nchar output[20]; // allocate a buffer big enough to fit the result\n\nconst char* src = input; // the current source byte\nchar* dst = output; // the current destination\nint charsCopied = 0; // counter\n\n// loop until we reach the terminating NUL of the source string\nwhile (*src) {\n\n // insert the dash in the output when needed\n if (charsCopied == 3 || charsCopied == 6) {\n *dst++ = '-';\n }\n\n // copy the current character and move to the next\n *dst++ = *src++;\n charsCopied += 1;\n}\n\n// terminate the output string and print it\n*dst = '\\0';\nputs(output);\n" }, { "answer_id": 318755, "author": "Doug Currie", "author_id": 33252, "author_profile": "https://Stackoverflow.com/users/33252", "pm_score": 2, "selected": false, "text": "printf(\"%c%c%c-%c%c%c-%c%c%c%c\"\n , s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9]);\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
318,265
<p>I'm trying to launch another process from a service (it's a console app that collects some data and writes it to the registry) but for some reason I can't get it to launch properly.</p> <p>I basics of what I'm am trying to do is as follows:</p> <ol> <li>Launch the process</li> <li>Wait for the process to finish</li> <li>Retrieve the return code from the process</li> </ol> <p>I am currently using the following code:</p> <pre><code>STARTUPINFO info={sizeof(info)}; PROCESS_INFORMATION processInfo; if (CreateProcess(PATH, ARGS, NULL, NULL, TRUE, 0, NULL, NULL, &amp;info, &amp;processInfo)) { ::WaitForSingleObject(processInfo.hProcess, INFINITE); DWORD exit = 100; GetExitCodeProcess(processInfo.hProcess, &amp;exit); CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); return exit; } </code></pre> <p>Upon calling CreateProcess(), it succeeds and enters the body of the if statement. The call to WaitForSingleObject returns immediately, which it should not, as the process should take approximately 20-30 seconds to finish. And, finally, calling GetExitCodeProcess() fails and does not set the value "exit".</p> <p>FYI, this is code I have actually used elsewhere with success, just not in a service.</p> <p>Could it be that it's being launched from a service and there are permissions issues?? </p> <p><strong>Edit:</strong> I've now realized that it will actually launch the app (I can see it in TaskMan) but it seems to be stuck. It's there, but isn't doing anything.<br> Based on Rob Kennedy's <a href="https://stackoverflow.com/questions/318265/launching-a-process-from-a-service#318314">suggestion</a>, I fixed the process handle issue, and it actually does wait for the process to finish. But it never does finish unless I kill it manually.</p>
[ { "answer_id": 318314, "author": "Rob Kennedy", "author_id": 33732, "author_profile": "https://Stackoverflow.com/users/33732", "pm_score": 3, "selected": true, "text": "WaitForSingleObject" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194/" ]
318,288
<p>When I use the <code>MouseUp</code> event, I can get it to fire with a mouse right-click. But <code>MouseLeftButtonUp</code> won't fire with either click!</p> <pre class="lang-xml prettyprint-override"><code>&lt;Button MouseLeftButtonUp="btnNewConfig_MouseUp" Name="btnNewConfig"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Source="Icons\new.ico" Height="24" Width="24" Margin="5"/&gt; &lt;TextBlock VerticalAlignment="Center"&gt;New&lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;/Button&gt; </code></pre> <p>I know this is most likely something simple. Thanks for the help!</p>
[ { "answer_id": 318304, "author": "Jobi Joy", "author_id": 8091, "author_profile": "https://Stackoverflow.com/users/8091", "pm_score": 6, "selected": true, "text": "Button" }, { "answer_id": 6933339, "author": "matfillion", "author_id": 778066, "author_profile": "https://Stackoverflow.com/users/778066", "pm_score": 2, "selected": false, "text": "Button" }, { "answer_id": 50263185, "author": "ILIA BROUDNO", "author_id": 788301, "author_profile": "https://Stackoverflow.com/users/788301", "pm_score": 3, "selected": false, "text": "btnNewConfig.AddHandler(MouseLeftButtonUpEvent, \n new RoutedEventHandler(btnNewConfig_MouseUp), \n true);\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318288", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13688/" ]
318,303
<p>When I try to use the code below I get a duplicate variable error because variables are immutable. How do I set the smaller of the two variables (<code>$nextSubPartPos</code> and <code>$nextQuestionStemPos</code>) as my new variable (<code>$nextQuestionPos</code>)?</p> <pre><code> &lt;xsl:variable name="nextQuestionPos"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$nextSubPartPos &amp;lt; $nextQuestionStemPos"&gt; &lt;xsl:variable name="nextQuestionPos" select="$nextSubPartPos"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:variable name="nextQuestionPos" select="$nextSubPartPos"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; </code></pre>
[ { "answer_id": 318318, "author": "nsayer", "author_id": 13757, "author_profile": "https://Stackoverflow.com/users/13757", "pm_score": 3, "selected": true, "text": "</xsl:variable>" }, { "answer_id": 318372, "author": "phihag", "author_id": 35070, "author_profile": "https://Stackoverflow.com/users/35070", "pm_score": 2, "selected": false, "text": "min" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318303", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5653/" ]
318,311
<p>I have a table with a credit and debit column.</p> <p>I need to get the highest balance out of that, and I think a stored procedure is the way to do it, but I have no idea how.</p> <p>I need to start with the first row, add the debits, subtract the credits and store the value A.</p> <p>Second row is A+debit-credit=B; A = max(A,B) Repeat last step till the end.</p> <p>Remember, I'm looking for the highest EVER, not the current, which would just be sum(debit-credit)</p>
[ { "answer_id": 318331, "author": "friol", "author_id": 23034, "author_profile": "https://Stackoverflow.com/users/23034", "pm_score": -1, "selected": false, "text": "select max(debit-credit) from yourtable\n" }, { "answer_id": 318439, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": true, "text": "A+credit-debit" }, { "answer_id": 318972, "author": "bbutle01", "author_id": 13704, "author_profile": "https://Stackoverflow.com/users/13704", "pm_score": 0, "selected": false, "text": "cc" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13704/" ]
318,334
<p>I've got a program that tends to crash quite often while I'm asleep and I need to keep it running. So I thought I might writeup a vb6 application that monitors the process list, if something disappears it will relaunch it. Anyone know of an easy way?</p>
[ { "answer_id": 318429, "author": "Arvo", "author_id": 35777, "author_profile": "https://Stackoverflow.com/users/35777", "pm_score": 0, "selected": false, "text": "tasklist |find \"myapp.exe\" >nul || c:\\mypath\\myapp.exe\n" }, { "answer_id": 342725, "author": "Eugenio Miró", "author_id": 41236, "author_profile": "https://Stackoverflow.com/users/41236", "pm_score": 2, "selected": false, "text": "Public Declare Function EnumProcesses Lib \"psapi.dll\" ( _\n ByRef idProcess As Long, ByVal cb As Long, _\n ByRef cbNeeded As Long) As Long\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
318,336
<p>I'm using the Fish Gadget (<a href="http://abowman.com/google-modules/fish/" rel="noreferrer">http://abowman.com/google-modules/fish/</a>) within a wiki based CMS, and need to reposition the gadget from one HTML element to another. (Note: the fish gadget is an example -- the problem occurs with other gadgets as well.)</p> <p>If I directly reposition the gadget using the gadgets base class "ig_reset", then everything works. If I try to reposition using a surrounding wrapper, then the iframe used by the gadget seems to take over. Unfortunately I need the flexibility of repositioning using the surrounding wrapper. </p> <p>This seems to have something to do with moving a SCRIPT tag around in the DOM. The gadget dynamically creates a script and a style tag. If I <em>remove</em> the dynamically created script tag from the DOM, and then reposition the wrapper to another location in the DOM, all works well. If I try to <em>move</em> the script tag to another DOM element then the original problem occurs. So <em>moving</em> a script tag around the DOM seems to be the cause -- regardless of when the move occurs (even post-load).</p> <p>I'd like to understand what is happening here to cause the frame to take over the page, and also find a better solution than removing the dynamically created script tag.</p> <p>I put a test up here: <a href="http://solidgone.com/jquery/google-gadget.html" rel="noreferrer">http://solidgone.com/jquery/google-gadget.html</a> -- the demo uses jQuery, but I don't think this is related to jQuery...</p>
[ { "answer_id": 318406, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 3, "selected": false, "text": "$(\"#with-wrapper\").click(function () \n{\n $('.sidebar-content-wrapper').contents().appendTo($(\"#sidebar\"));\n});\n" } ]
2008/11/25
[ "https://Stackoverflow.com/questions/318336", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34783/" ]