qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
372,807
<p>I have a problem with a bash script. I have to use the operator * to multiplicate. Instead the script bugs me with expansion and using as operator the name of the script itself. I tried with single quotes but it doesn't work :( Here's the code</p> <pre><code>#!/bin/bash -x # Bash script that calculates an arithmetic expression # NO PRECEDENCE FOR OPERATORS # Operators: + - * if [ "$#" -lt "3" ] then echo "Usage: ./calcola.scr &lt;num&gt; &lt;op&gt; &lt;num&gt; ..." exit 1 fi result=0 op=+ j=0 for i in "$@" do if [ "$j" -eq "0" ] then # first try #result=$(( $result $op $i )) # second try let "result$op=$i" j=1 else op=$i j=0 fi done echo "Result is $result" exit 0 </code></pre>
[ { "answer_id": 372871, "author": "Jason Day", "author_id": 737, "author_profile": "https://Stackoverflow.com/users/737", "pm_score": 2, "selected": false, "text": "* $ ./calcola.scr 2 \\* 3\n+ '[' 3 -lt 3 ']'\n+ result=0\n+ op=+\n+ j=0\n+ for i in '\"$@\"'\n+ '[' 0 -eq 0 ']'\n+ let resul...
2008/12/16
[ "https://Stackoverflow.com/questions/372807", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41977/" ]
372,808
<p>I have uploaded some files to a directory under public and I try to access them using Dir.glob. But I get no results back. </p> <p>The Dir.glob works fine on dev server (mongrel) and also works fine when using script/console on the site installed on site5</p> <p>is there a way to get this working or a different way to get the list of files?</p>
[ { "answer_id": 372851, "author": "Keltia", "author_id": 16143, "author_profile": "https://Stackoverflow.com/users/16143", "pm_score": 2, "selected": true, "text": "Dir.entries(\"public\").each do |f|\n puts(f)\nend\n" }, { "answer_id": 373068, "author": "AndreasKnudsen", ...
2008/12/16
[ "https://Stackoverflow.com/questions/372808", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36465/" ]
372,812
<p>I am running C# framework 2.0 and I would like to get some of the data from a list? The list is a List&lt;>. How can I do that without looping and doing comparaison manually on each element of the List&lt;>?</p>
[ { "answer_id": 372822, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 3, "selected": true, "text": " static void Main()\n {\n List<SimpleObject> list = new List<SimpleObject>();\n list.Add(new ...
2008/12/16
[ "https://Stackoverflow.com/questions/372812", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46829/" ]
372,815
<pre><code> for m := 0 to 300 do if Pos(certain_String, string(arrayitem(m)) &lt;&gt; 0 then begin randomize; x := random(100); begin case x of 0..69 : function(m); // 70 percent 70..79 : function(m+1); // 10 percent 80..84 : function(m+2); // 5 percent 85..88 : function(m+3); // 5 percent 89..91 : function(m+4); // 2 percent 92..94 : function(m+5); // 3 percent 95..97 : function(m+6); // 3 percent 98..98 : function(m+7); // 1 percent 99..99 : function(m+8); // 1 percent end; m := 300; end; </code></pre> <p>Trying to make this thing loop through a rather large array, but if it finds a certain string in it stop entirely and go to the next thing, had to take out some proprietary function names but m := 300; seems to be the problem, doesn't like me assigning m a value in the middle of a for loop. Sorry for the lack of knowledge here, got a halfdone pascal project dropped on my lap and have never even seen the stuff before.</p>
[ { "answer_id": 372840, "author": "pyon", "author_id": 46571, "author_profile": "https://Stackoverflow.com/users/46571", "pm_score": 0, "selected": false, "text": "break" }, { "answer_id": 372855, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https:/...
2008/12/16
[ "https://Stackoverflow.com/questions/372815", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
372,820
<p>I'm looking at this control, and it seems to be lacking the standard .net "datasource" and "datamember" properties for databinding. Is this control not bindable? I can write some custom function that populates the treeview from a given data source, I suppose, and embed data objects as necessary, but is that the 'best practice'? Or does everyone simply use a 3rd party treeview control? </p>
[ { "answer_id": 373514, "author": "TheCodeMonk", "author_id": 28956, "author_profile": "https://Stackoverflow.com/users/28956", "pm_score": 3, "selected": false, "text": "class Node\n{\n System.Collections.Generic.List<Node> _Children;\n String Description;\n\n void Node()\n {...
2008/12/16
[ "https://Stackoverflow.com/questions/372820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18071/" ]
372,828
<p>I wrote below code to remove checked item from radio group in my form by double click.</p> <pre><code>$("input[type='radio']").each(function(){ $(this).dblclick(function(){ $(this).removeAttr("checked"); }); }); </code></pre> <p>but this code doesn't work in FireFox but work in IE. anybody know what's the problem?</p> <p>tanx</p>
[ { "answer_id": 1298571, "author": "Andy Gaskell", "author_id": 30697, "author_profile": "https://Stackoverflow.com/users/30697", "pm_score": 2, "selected": false, "text": "$(\"input[type='radio']\").dblclick(function(){\n $(this).removeAttr(\"checked\");\n});\n" } ]
2008/12/16
[ "https://Stackoverflow.com/questions/372828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46110/" ]
372,834
<p>I am trying to create a SQL server login and database user from within my application, along with a custom application user row. I want these users to be able to create other users - i.e. the application will control who can/can't create users but I need all users to have permissions for creating SQL server logins and database users.</p> <p>I have got the server login permissions working - i.e. an existing user/login can create a new login - by adding the logins to the 'securityadmin' server role - which grants the 'ALTER ANY LOGIN' privilege. </p> <p>I tried to do the same with the database users - adding them to the 'db_accessadmin' database role - which supposedly grants the ALTER ANY USER privilege, which is required for CREATE USER. </p> <p>However any time I try to create a new database user using a user with the above privileges I get a permissions exception.</p> <p>I have tried manually granting the ALTER ANY USER permission to a particular user (GRANT ALTER ANY USER TO demouser) but this doesn't work either.</p>
[ { "answer_id": 10096634, "author": "Hemanshu", "author_id": 1325127, "author_profile": "https://Stackoverflow.com/users/1325127", "pm_score": 0, "selected": false, "text": "/* \nTOPIC: create a login ,who can add other logins to databases (securityadmin server role)\n*/\n\nUSE MASTER \n...
2008/12/16
[ "https://Stackoverflow.com/questions/372834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
372,837
<p>I spend some time customizing the colors for syntax highlighting in Eclipse (Java, JSP, HTML, CSS, etc.) but whenever I try to export these settings via File|Export|General|Preferences and reimport them, the settings never completely get imported back. Some colors are restored and others are left unchanged, leaving me in an 'in between' state - very frustrating.</p> <p>I'm using Eclipse 3.4 Ganymede, by the way.</p> <p>Has anyone found a reliable way to save and restore Eclipse syntax highlighting settings?</p>
[ { "answer_id": 598146, "author": "foxdonut", "author_id": 26353, "author_profile": "https://Stackoverflow.com/users/26353", "pm_score": 8, "selected": true, "text": ".epf .epf {Eclipse workspace directory}/.metadata/.plugins/org.eclipse.core.runtime/.settings/*.prefs" }, { "answe...
2008/12/16
[ "https://Stackoverflow.com/questions/372837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26353/" ]
372,862
<p>I'm an old (but not too old) Java programmer, that decided to learn C++. But I have seen that much of C++ programming style, is... well, just damn ugly!</p> <p>All that stuff of putting the class definition in a header file, and the methods in a different source file- Calling functions out of nowhere, instead of using methods <strong>inside classes</strong>. All that just seems... wrong!</p> <p>So finally, is there any reason for me to continue with this massacre to the OOP, and anything that is good and righteous in programming, or can I just ignore that old-fashioned C++ conventions, and use my good Java programing style?</p> <p>By the way I'm learning C++, because I want to do game programing.</p> <p>Here is an example:</p> <p>In an C++ website I found a Windows implementation:</p> <pre><code>class WinClass { public: WinClass (WNDPROC wndProc, char const * className, HINSTANCE hInst); void Register () { ::RegisterClass (&amp;_class); } private: WNDCLASS _class; }; </code></pre> <p>That class is located in a header file and the constructor:</p> <pre><code>WinClass::WinClass (WNDPROC wndProc, char const * className, HINSTANCE hInst) { _class.style = 0; _class.lpfnWndProc = wndProc; // Window Procedure: mandatory _class.cbClsExtra = 0; _class.cbWndExtra = 0; _class.hInstance = hInst; // Owner of the class: mandatory _class.hIcon = 0; _class.hCursor = ::LoadCursor (0, IDC_ARROW); // Optional _class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // Optional _class.lpszMenuName = 0; _class.lpszClassName = className; // Mandatory } </code></pre> <p>Is located at a .cpp source file.</p> <p>What I could just do is:</p> <pre><code>class WinClass { public: WinClass (WNDPROC wndProc, char const * className, HINSTANCE hInst) { _class.style = 0; _class.lpfnWndProc = wndProc; // Window Procedure: mandatory _class.cbClsExtra = 0; _class.cbWndExtra = 0; _class.hInstance = hInst; // Owner of the class: mandatory _class.hIcon = 0; _class.hCursor = ::LoadCursor (0, IDC_ARROW); // Optional _class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // Optional _class.lpszMenuName = 0; _class.lpszClassName = className; // Mandatory } void Register () { ::RegisterClass (&amp;_class); } private: WNDCLASS _class; }; </code></pre> <p>And now the constructor is inside its class.</p>
[ { "answer_id": 372948, "author": "Adam", "author_id": 1366, "author_profile": "https://Stackoverflow.com/users/1366", "pm_score": 6, "selected": true, "text": "// Vehicle.h\nclass Wheel {\n private:\n Car& m_parent;\n public:\n Wheel( Car& p ) : m_parent( p ) {\n ...
2008/12/16
[ "https://Stackoverflow.com/questions/372862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2605/" ]
372,865
<p><a href="https://msdn.microsoft.com/en-us/library/system.io.path.combine%28v=vs.110%29.aspx" rel="noreferrer">Path.Combine</a> is handy, but is there a similar function in the .NET framework for <a href="http://en.wikipedia.org/wiki/Uniform_resource_locator" rel="noreferrer">URLs</a>?</p> <p>I'm looking for syntax like this:</p> <pre><code>Url.Combine("http://MyUrl.com/", "/Images/Image.jpg") </code></pre> <p>which would return:</p> <p><code>"http://MyUrl.com/Images/Image.jpg"</code></p>
[ { "answer_id": 372888, "author": "Ryan Cook", "author_id": 43029, "author_profile": "https://Stackoverflow.com/users/43029", "pm_score": 7, "selected": false, "text": "Uri.TryCreate( ... ) Uri result = null;\n\nif (Uri.TryCreate(new Uri(\"http://msdn.microsoft.com/en-us/library/\"), \"/e...
2008/12/16
[ "https://Stackoverflow.com/questions/372865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16082/" ]
372,869
<p>I get the name of a variable from the script user as the first argument and I echo the value of said variable back to the console:</p> <pre><code>#!/bin/bash variablename=$1 echo "The value of $variablename is: " ${!variablename} </code></pre> <p>This works great!</p> <p>What I can't get to work is if I want to change that variable into the value of the second argument from the user. An example with a syntax error is:</p> <pre><code>#!/bin/bash variablename=$1 echo "The value of $variablename is: " ${!variablename} echo "I will now try to change the value into $2." (!variablename}=$2 # The above line generates: {!variablename}=2: command not found </code></pre> <p>In other words: If it is possible, how do I get a variable <em>name</em> from the user and both read (already solved) and write to said variable?</p>
[ { "answer_id": 372876, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": true, "text": "#!/bin/bash\nvariablename=$1\necho \"The value of $variablename is: \" ${!variablename}\necho \"I will now try to change the va...
2008/12/16
[ "https://Stackoverflow.com/questions/372869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
372,872
<p>When converting from PNG to JPG using the MagickWand API, how do I set the background to white for transparent pixels?</p>
[ { "answer_id": 4318947, "author": "Oldes", "author_id": 494472, "author_profile": "https://Stackoverflow.com/users/494472", "pm_score": 2, "selected": false, "text": "if(current_wand && IsMagickWand(current_wand)){\n status=MagickReadImage(current_wand, \"test.png\");\n if (status ...
2008/12/16
[ "https://Stackoverflow.com/questions/372872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
372,877
<p>I have Default.aspx page, which inherits from BasePage.cs, which inherits from System.Web.UI.Page. BasePage is where I do some common things every page must do upon loading.</p> <p>In BasePage, lets say I'm checking for X. If X=1, then I will redirect to my "Discontinued.aspx" page immediately and stop execution of BasePage. If I find X=1, I say:</p> <p>HttpContext.Current.Response.Redirect("Discontinued.aspx", true);</p> <p>I want the redirect to stop execution of BasePage and immediately jump out - hence the "true" in the above statement - which should stop execution of the current page as I understand. The problem is, it doesn't. I'm expecting the redirect to throw the "thread abort exception". </p> <p>When I run in debug mode, it contines stepping through as though it didn't just redirect and leave. </p> <p>But the redirect was still started as well - once I get done stepping through the rest of BasePage, the "Discontinued" page then begins to load as a result of the redirect. </p> <p>Is there a reason my Redirect will not kill execution of BasePage?</p>
[ { "answer_id": 372930, "author": "Steven A. Lowe", "author_id": 9345, "author_profile": "https://Stackoverflow.com/users/9345", "pm_score": 5, "selected": true, "text": "...redirect(stopit,true);\nreturn;\n" }, { "answer_id": 372940, "author": "recursive", "author_id": 44...
2008/12/16
[ "https://Stackoverflow.com/questions/372877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44698/" ]
372,885
<p>How do I connect to a MySQL database using a python program?</p>
[ { "answer_id": 372896, "author": "George Stocker", "author_id": 16587, "author_profile": "https://Stackoverflow.com/users/16587", "pm_score": 8, "selected": false, "text": "#!/usr/bin/python\nimport MySQLdb\n\n# Connect\ndb = MySQLdb.connect(host=\"localhost\",\n user...
2008/12/16
[ "https://Stackoverflow.com/questions/372885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
372,893
<p>I want to create a file that only resides in memory... In looking through some documentation I saw a recommendation to use a shell extension as a virtual file. Im not sure that is a workable solution but I would like to know</p> <ol> <li>Is it a good approach (or should I be using a ramdisk instead)</li> <li>Where is a good place to start to read up on it</li> </ol> <p>Note: This is on the Windows platform</p>
[ { "answer_id": 372896, "author": "George Stocker", "author_id": 16587, "author_profile": "https://Stackoverflow.com/users/16587", "pm_score": 8, "selected": false, "text": "#!/usr/bin/python\nimport MySQLdb\n\n# Connect\ndb = MySQLdb.connect(host=\"localhost\",\n user...
2008/12/16
[ "https://Stackoverflow.com/questions/372893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38734/" ]
372,907
<p>How do I maintain the scroll position of the parent page when I open new window using window.open()? The parent page returns to the top of the page.</p> <p>Here is my current code:</p> <pre><code>&lt;a href="#" onclick="javascript: window.open('myPage.aspx');"&gt; Open New Window &lt;/a&gt; </code></pre>
[ { "answer_id": 372924, "author": "Grant Wagner", "author_id": 9254, "author_profile": "https://Stackoverflow.com/users/9254", "pm_score": 4, "selected": true, "text": "<a href=\"#\" onclick=\"window.open('myPage.aspx');return false;\">Open New Window</a>\n javascript: <a href=\"#\">Scrol...
2008/12/16
[ "https://Stackoverflow.com/questions/372907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26327/" ]
372,914
<p>I have the following code to zip all the files and then save it to the harddisk. I want zip all the files (this is done) and then attach the zip file to the Response stream so that the user have the option to save it! </p> <pre><code>protected void DownloadSelectedFiles_Click(object sender, EventArgs e) { string path = String.Empty; string zipFilePath = @"C:\MyZipFile.zip"; ZipOutputStream zipStream = new ZipOutputStream(File.Create(zipFilePath)); byte[] buffer = new byte[4096]; foreach (GridViewRow row in gvFiles.Rows) { bool isSelected = (row.FindControl("chkSelect") as CheckBox).Checked; if (isSelected) { path = (row.FindControl("lblUrl") as Label).Text; ZipEntry entry = new ZipEntry(Path.GetFileName(path)); entry.DateTime = DateTime.Now; zipStream.PutNextEntry(entry); using (FileStream fs = File.OpenRead(path)) { int sourceBytes; do { sourceBytes = fs.Read(buffer, 0, buffer.Length); zipStream.Write(buffer, 0, sourceBytes); } while (sourceBytes &gt; 0); } } } zipStream.Finish(); zipStream.Close(); Response.ContentType = "application/x-zip-compressed"; Response.AppendHeader("Content-Disposition", "attachment; filename=SS.zip"); Response.WriteFile(zipFilePath); Response.End(); } </code></pre>
[ { "answer_id": 373238, "author": "Stefan", "author_id": 19307, "author_profile": "https://Stackoverflow.com/users/19307", "pm_score": 1, "selected": false, "text": " Response.Buffer = true;\n Response.Clear();\n Response.ClearContent();\n Response.ClearHeaders();\n Response.Flush()\n...
2008/12/16
[ "https://Stackoverflow.com/questions/372914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3797/" ]
372,915
<p>I'm dealing with game dialogue files (conversation between player and non-playable-characters) where dialogue choices and their outcome depend on certain conditions and result in certain actions. Now, I could write a simple parser to handle some sort of language for specifying the pre and post-conditions, but a friend of mine suggested using XML. Conditions could be stored as attributes of a dialogue element and choices and actions are inner elements. I'd then use an eval function to parse these conditions and statements (I'm using Ruby to make this game). To make such an approach simpler, I could then write a simple GUI to manipulate these files without worrying about ugly XML. </p> <p>But it strikes me as an odd choice to handle logic in XML files. My understanding is that XML files are for the storage and exchange of data, and I always read rants about how people overuse XML for all sorts of things it wasn't designed for. My friends responds by noting how XML IS used for everything, including XHTML and <a href="http://www.asahi-net.or.jp/~cs8k-cyu/bulletml/index_e.html" rel="noreferrer">this bullet description language</a> (which also illustrates some logic). </p> <p>To be honest, using XML would simplify a lot of things for me. Writing a parser can be painful and time consuming, and my requirements are generally simple. But is it really okay or would I regret such a choice later?</p> <p>For people interested in details, here's what a basic dialogue exchange might look like in an XML file:</p> <pre><code>&lt;dialogue id="101" condition="!npc.carsFixed"&gt; &lt;message&gt;Man, fix my car!&lt;/message&gt; &lt;choices&gt; &lt;choice condition="hero.carFixingSkill &gt; 5" priority="7" id="Sure!"&gt; &lt;command&gt;hero.carFixingSkills += 1&lt;/command&gt; &lt;command&gt;npc.carFixed = true&lt;/command&gt; &lt;command&gt;hero.playSmokeAnimation()&lt;/command&gt; &lt;command&gt;nextDialogue = 104&lt;/command&gt; &lt;/choice&gt; &lt;choice condition="hero.carFixingSkill &lt;= 5" id="I can't..."&gt; &lt;command&gt;nextDialogue = 105&lt;/command&gt; &lt;/choice&gt; &lt;choice id="Fix it yourself"&gt; &lt;command&gt;npc.likesHero -= 1&lt;/command&gt; &lt;/choice&gt; &lt;/choices&gt; &lt;/dialogue&gt; </code></pre> <p>The corresponding code if written in Ruby would be:</p> <pre><code>def dialogue101 if !npc.carsFixed showMessage("Man, fix my car!") choices = [] if hero.carFixingSkill &gt; 5 choices.push(Choice.new("Sure!", 7)) else choices.push(Choice.new("I can't")) end choices.push(Choice.new("Fix it yourself")) choices = selectTopPriority(choices) if choices.size &gt; 4 result = showChoices(choices) case result when "Sure" hero.carFixingSkills += 1 npc.carFixed = true hero.playSmokeAnimation dialogue104 when "I can't" dialogue105 when "Fix it yourself" npc.likesHero -= 1 end end end </code></pre> <p>Stuff like likesHero and carFixingSkills are knowledge pieces player and NPCs can have, which would probably be stored in a hash in the real implementation. I find the dialogue file approach more flexible because I could make an editor to easily edit dialogue and conditions/actions, and because of the complex nature of game conversation trees. A scripting language like Ruby or Lua helps, but it'll require complex structures to handle to logic of such trees. </p> <p>Back to the original question, is XML the right tool for the job or am I missing something?</p>
[ { "answer_id": 373141, "author": "Guge", "author_id": 37771, "author_profile": "https://Stackoverflow.com/users/37771", "pm_score": 1, "selected": false, "text": "<category>\n<pattern>WHAT ARE YOU</pattern>\n<template>\n <think><set name=\"topic\">Me</set></think> \n I am the lates...
2008/12/16
[ "https://Stackoverflow.com/questions/372915", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23153/" ]
372,916
<p>OK,</p> <p>This question has probably been answered before, but I'm not sure of how to word the Title.</p> <p>I have a class that has methods which return many composite LINQ queries. Most of these queries form Anonymous Types in order to get the data I need. I found out that I'm not able to return an Anonymous Type from a method, so I've been creating sub classes and populating them in the "select new" part of the query.</p> <p>Is there a better way of doing this? All of these methods return an IEnumerable of some kind and I really want to keep things extracted.</p> <p>Thanks!</p>
[ { "answer_id": 373750, "author": "Chaowlert Chaisrichalermpol", "author_id": 2398110, "author_profile": "https://Stackoverflow.com/users/2398110", "pm_score": 0, "selected": false, "text": "// Useful? probably not.\nprivate void foo()\n{\n var user = AnonCast(GetUserTuple(), new { Nam...
2008/12/16
[ "https://Stackoverflow.com/questions/372916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36269/" ]
372,925
<p>My reuirement:</p> <p>Input File:</p> <p>1,abc,xyx</p> <p>2,def,mno</p> <p>3,ghi,suv</p> <p>DB Table Structure:</p> <p>Col1 char</p> <p>col2 char</p> <p>col3 char</p> <p>col4 char</p> <p>col5 char</p> <p>Data in Table after BCP:</p> <p>col1 col2 col3 col4 col5</p> <p>1 abc xyz ab xy</p> <p>2 def mno de mn</p> <p>3 ghi suv gh su</p> <p>Basically the col4 and col5 are calculated values from col2 and col3 values.</p> <p>Does SQL Server BCP utility support such kind of operation? Any pointers will be appreciated.</p> <p>Cheers GT</p>
[ { "answer_id": 373536, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 2, "selected": false, "text": "BULK INSERT BULK INSERT INSERT INTO" }, { "answer_id": 924943, "author": "edosoft", "author_id": 6399, ...
2008/12/16
[ "https://Stackoverflow.com/questions/372925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
372,933
<p>I am taking in a string from user input, and splitting it on whitespace (using \w) into an array of strings. I then loop through the array, and append a part of the where clause like this:</p> <pre><code> query += " AND ( " + "field1 LIKE '%" + searchStrings[i] +"%' " + " OR field2 LIKE '%" + searchStrings[i] +"%' " + " OR field3 LIKE '%" + searchStrings[i] +"%' " + ") "; </code></pre> <p>I feel like this is dangerous, since I am appending user input to my query. However, I know that there isn't any whitespace in any of the search strings, since I split the initial input on whitespace.</p> <p>Is it possible to attack this via a SQL injection? Giving <code>Robert');DROP TABLE students;--</code> wouldn't actually drop anything, since there needs to be whitespace in there. In that example, it would not behave properly, but no damage would be done.</p> <p>Can anyone with more experience fighting SQL injections help me either fix this, or put my mind at ease?</p> <p>Thanks!</p> <p><strong>EDIT:</strong></p> <p>Wow, that is a lot of great input. Thank you everyone who responded. I will investigate full-text search and, at a minimum, parameterize my query.</p> <p>Just so I can better understand the problem, would it be possible to inject if all whitespace <strong>AND</strong> single quotes were escaped?</p>
[ { "answer_id": 372962, "author": "BenAlabaster", "author_id": 40650, "author_profile": "https://Stackoverflow.com/users/40650", "pm_score": 5, "selected": true, "text": "+ field1 like @PropertyVal Or field2 like @PropertyVal Or field3 like @PropertyVal etc...\n Query.Parameters.Add(new S...
2008/12/16
[ "https://Stackoverflow.com/questions/372933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4257/" ]
372,934
<p>By "fixed vector" I mean a static list of values, like 1 through 24.</p> <p>The current query looks like this (simplified)</p> <pre><code>SELECT Period, Profit FROM Projections </code></pre> <p>But the data is "sparse" &#8212; so there's not a row for every period.</p> <p>What query will give me a row for peiods 1-24 every time, with zeros (or NULLs) where there's no data? </p> <p>I would like to do this with just the query to avoid a mess of client code.</p> <p>Thanks!</p>
[ { "answer_id": 372962, "author": "BenAlabaster", "author_id": 40650, "author_profile": "https://Stackoverflow.com/users/40650", "pm_score": 5, "selected": true, "text": "+ field1 like @PropertyVal Or field2 like @PropertyVal Or field3 like @PropertyVal etc...\n Query.Parameters.Add(new S...
2008/12/16
[ "https://Stackoverflow.com/questions/372934", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4525/" ]
372,955
<p>If I'm rendering a regular view in asp.net mvc the only domain object properties that show up in my page the ones I specifically write out. For example:</p> <pre><code>&lt;div&gt;&lt;%= Customer.FirstName %&gt;&lt;/div&gt; </code></pre> <p>However, if I serialize a domain object for json it will include every property. Example:</p> <pre><code>public JsonResult Customer (int? id) { Customer customer = _serviceLayer.GetCustomer (id.Value); return Json (customer); } </code></pre> <p>Since I don't want every Customer property exposed what is the best way to filter the output properties for json in this case? Can you use an include/exclude list like UpdateModel()? Use a proxy class such as public class JsonCustomer? What would you recommend?</p>
[ { "answer_id": 372977, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 5, "selected": true, "text": "var customer = from c in serviceLayer.GetCustomers()\n where c.Id == id.Value\n select new {...
2008/12/16
[ "https://Stackoverflow.com/questions/372955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31624/" ]
372,961
<p>I have a SQL statement similar to this:</p> <pre><code>SELECT COUNT(*) AS foo, SUM(foo) AS foo_sum FROM bar </code></pre> <p>But MySQL doesn't allow this because foo is an alias. Does anyone have an idea of how this could be accomplished in SQL?</p>
[ { "answer_id": 372987, "author": "Harper Shelby", "author_id": 21196, "author_profile": "https://Stackoverflow.com/users/21196", "pm_score": 1, "selected": false, "text": "SELECT SUM(foo) as foo_sum\nFROM \n(\n SELECT COUNT(*) AS foo\n FROM bar\n GROUP BY baz\n)\n" }, { ...
2008/12/16
[ "https://Stackoverflow.com/questions/372961", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46540/" ]
372,974
<p>I want to programmatically invoke an event handler for a control. For example:</p> <pre><code>DateTimePicker dtpLastConsummated; </code></pre> <p>I want to trigger the TextChanged event handler for the <code>dtpLastConsummated</code>, how can i do it?</p> <p>In other languages I would call something akin to:</p> <pre><code>dtpLastConsummated.TextChanged(this, new EventArgs()); </code></pre> <p>but in .NET you can have multiple event handlers:</p> <pre><code>dtpLastConsummated.Click +=new EventHandler(dtpLastConsummated_TextChanged); dtpLastConsummated.Click +=new EventHandler(dtpLastConsummated_AnotherHandler); dtpLastConsummated.Click +=new EventHandler(dtpLastConsummated_MoreHandlers); ... dtpLastConsummated.Click +=new EventHandler(dtpLastConsummated_Nminus1); </code></pre> <p>so you need a way to trigger all the attached event handlers.</p> <hr> <h2>Answer</h2> <p>The following code will fire the event:</p> <pre><code>Toolkit.FireEvent(dtpLastConsummated, "TextChanged", new EventArgs()); </code></pre> <p>And here's the code of the static toolkit function:</p> <pre><code>/// &lt;summary&gt; /// Programatically fire an event handler of an object /// &lt;/summary&gt; /// &lt;param name="targetObject"&gt;&lt;/param&gt; /// &lt;param name="eventName"&gt;&lt;/param&gt; /// &lt;param name="e"&gt;&lt;/param&gt; public static void FireEvent(Object targetObject, string eventName, EventArgs e) { /* * By convention event handlers are internally called by a protected * method called OnEventName * e.g. * public event TextChanged * is triggered by * protected void OnTextChanged * * If the object didn't create an OnXxxx protected method, * then you're screwed. But your alternative was over override * the method and call it - so you'd be screwed the other way too. */ //Event thrower method name //e.g. OnTextChanged String methodName = "On" + eventName; MethodInfo mi = targetObject.GetType().GetMethod( methodName, BindingFlags.Instance | BindingFlags.NonPublic); if (mi == null) throw new ArgumentException("Cannot find event thrower named "+methodName); mi.Invoke(targetObject, new object[] { e }); } </code></pre> <hr> <p><strong>Note:</strong> I'm not creating a subclass of every control in the .NET framework, and every 3rd party control, and convincing an enterprise worth of developers to retrofit every form to use my custom controls.</p>
[ { "answer_id": 373567, "author": "Jon B", "author_id": 27414, "author_profile": "https://Stackoverflow.com/users/27414", "pm_score": 2, "selected": false, "text": "class MyButton : Button\n{\n public void CauseClick()\n {\n this.OnClick();\n }\n}\n" }, { "answer_i...
2008/12/16
[ "https://Stackoverflow.com/questions/372974", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
372,980
<p>The ISO C committee (<a href="http://www.open-std.org/JTC1/SC22/WG14/" rel="noreferrer">ISO/IEC JTC1/SC21/WG14</a>) has published <a href="http://www.open-std.org/JTC1/SC22/WG14/www/projects#24731-1" rel="noreferrer">TR 24731-1</a> and is working on <a href="http://www.open-std.org/JTC1/SC22/WG14/www/projects#24731-1" rel="noreferrer">TR 24731-2</a>:</p> <blockquote> <h3>TR 24731-1: Extensions to the C Library Part I: Bounds-checking interfaces</h3> <p>WG14 is working on a TR on safer C library functions. This TR is oriented towards modifying existing programs, often by adding an extra parameter with the buffer length. The latest draft is in document N1225. A rationale is in document N1173. This is to become a Technical Report type 2.</p> <h3>TR 24731-2: Extensions to the C Library - Part II: Dynamic allocation functions</h3> <p>WG14 is working on a TR on safer C library functions. This TR is oriented towards new programs using dynamic allocation instead of an extra parameter for the buffer length. The latest draft is in document N1337. This is to become a Technical Report type 2.</p> </blockquote> <h2>Questions</h2> <ul> <li>Do you use a library or compiler with support for the TR24731-1 functions?</li> <li>If so, which compiler or library and on which platform(s)?</li> <li>Did you uncover any bugs as a result of fixing your code to use these functions?</li> <li>Which functions provide the most value?</li> <li>Are there any that provide no value or negative value?</li> <li>Are you planning to use the library in the future?</li> <li>Are you tracking the TR24731-2 work at all?</li> </ul>
[ { "answer_id": 373911, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 5, "selected": false, "text": "%n tmpfile_s() tmpnam_s() mkstemp() strerrorlen_s() asprintf() vasprintf() strdup() char * strcpy() strcat() strc...
2008/12/16
[ "https://Stackoverflow.com/questions/372980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15168/" ]
372,982
<p>I have from the backend a time on the format 00:12:54 and I display it to the screen. But, I would like to have this time to continue to go down. I have though to create a variable in javascript that will old the time and with <code>setTimeout</code> to loop to display with document.getElementById the new value. I think it can be problematic if I have many time to go down in same time. I might require an array?</p> <p>How would you do that? If I have no other suggestion, I will try my way, but I am curious to know if it does have a more secure way to do it.</p>
[ { "answer_id": 372986, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 2, "selected": false, "text": " $('#until2d4h').countdown({until: '+12M +54S'});\n" }, { "answer_id": 373010, "author": "Ates Gora...
2008/12/16
[ "https://Stackoverflow.com/questions/372982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46829/" ]
372,988
<p>I'm new to database indexing, if I have 2 columns in a table that are good choices for indexing like for example,</p> <pre><code>[Posts]( [PostID] [int] IDENTITY(1,1) NOT NULL, [UserName] [nvarchar](64) NOT NULL, [ApplicationType] [smallint] NOT NULL, ... ) </code></pre> <p>in this case PostID would be the PRIMARY KEY CLUSTERED index, then I want to do more indexing since it's a large table and I want to do on UserName and ApplicationType, now should I index each individually (one on UserName, one on ApplicationType) or index them as a whole (one index on UserName, ApplicationType together)? Is there a limit to the number of indexes I can have before making it bad practice? What generally is the rule of thumb on this?</p> <p>Thanks,</p> <p>Ray.</p>
[ { "answer_id": 373024, "author": "BCS", "author_id": 1343, "author_profile": "https://Stackoverflow.com/users/1343", "pm_score": 1, "selected": false, "text": "a b" } ]
2008/12/16
[ "https://Stackoverflow.com/questions/372988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32240/" ]
373,002
<p>I'm trying to find a markdown interpreter class/module that I can use in a rakefile.</p> <p>So far I've found <a href="http://maruku.rubyforge.org/" rel="noreferrer">maruku</a>, but I'm a bit wary of beta releases.</p> <p>Has anyone had any issues with maruku? Or, do you know of a better alternative?</p>
[ { "answer_id": 373446, "author": "outcassed", "author_id": 18424, "author_profile": "https://Stackoverflow.com/users/18424", "pm_score": 9, "selected": true, "text": "BlueCloth: 13.029987s total time, 00.130300s average\n Maruku: 08.424132s total time, 00.084241s average\nRDiscount: 00...
2008/12/16
[ "https://Stackoverflow.com/questions/373002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15031/" ]
373,012
<p>I am trying to create a simple dialog in MFC using Visual C++. My problem is that when I get the dialog on the screen and try to type in an Edit Box field, if I type the letter 'a' once, it appears in the edit box as 'aaaaaaaaaaa' (that's 12 a's). Furthermore, if I try to navigate around in the box using the arrow keys, the carat moves 12 characters at a time.</p> <p>It's not just a display error, as the output from the editbox is still "aaaaaaaaaaaa".</p> <p>I'd post code, but there's really none to post. I added the edit box using the Toolbox in Visual Studio and assigned a variable to it in my class so this isn't any sort of special edit box.</p> <p>If anyone has any thoughts as to what might be happening it would be greatly appreciated. Unfortunately, I don't know where to begin.</p> <p>Thank as always.</p>
[ { "answer_id": 422786, "author": "rec", "author_id": 14022, "author_profile": "https://Stackoverflow.com/users/14022", "pm_score": 1, "selected": false, "text": "BOOL DialogName::PreTranslateMessage(MSG* pMsg)\n{\n\n if(pMsg->message==WM_KEYDOWN)\n {\n // TODO: see what is g...
2008/12/16
[ "https://Stackoverflow.com/questions/373012", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34731/" ]
373,017
<p>Which techniqes would you use to implement a search for contents in a column on a very big table in MySql? Say for instance that you have 10.000.000 emails stored in a table in the database and would like to implement a subject search, that would enable me to search for one or more words that was present in the email subject. If the user searched for "christmas santa" you should find a emails with subjects like "Santa visits us this christmas" and "christmas, will santa ever show".</p> <p>My idea is to process all the words in the subjects (strip all numbers, special signs, commas etc) and save each word in an index table, where I have a unique index on the word column. Then I would link that to the email table by a many to many relationship table.</p> <p>Is there a better way to perform wildcard searches on very big tables ?</p> <p>Is there databases that natively supports this kind of searches ?</p>
[ { "answer_id": 373041, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "FULLTEXT" }, { "answer_id": 373044, "author": "Eli", "author_id": 5958, "author_profile": "https:/...
2008/12/16
[ "https://Stackoverflow.com/questions/373017", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37119/" ]
373,020
<p>Is there a way to find the application name of the current active window at a given time on Mac OS X using Python?</p>
[ { "answer_id": 373210, "author": "Peter Hosey", "author_id": 30461, "author_profile": "https://Stackoverflow.com/users/30461", "pm_score": 3, "selected": false, "text": "window = NSApp.mainWindow()\n appName = NSProcessInfo.processInfo().processName()\n ProcessSerialNumber psn = { 0L, 0L...
2008/12/16
[ "https://Stackoverflow.com/questions/373020", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40195/" ]
373,022
<p>I'm trying to retrive a dataset to a Gridview, but I just don't get any row in my Gridview. What am I doing wrong?</p> <p>the page code</p> <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load CType(Master, AreaTrabalho).AlteraTitulo = "Projectos" Using oSQL As New clsSQL(System.Configuration.ConfigurationManager.AppSettings("ConnectionString1")) If oSQL.OpenConnection Then oSQL.ToDataGrid(Me.GridView1, "Select * from users") End If End Using End Sub </code></pre> <p>the class functions used to fetch data</p> <pre><code>Public Function ToDataGrid(ByVal oDataGrid As GridView, _ ByVal sQuery As String, _ Optional ByVal sTable As String = "") As Boolean Try Dim objDataSet As New Data.DataSet 'Preenche o dataset objDataSet = ToDataSet(sQuery, sTable) oDataGrid.DataSource = objDataSet.Tables(0) objDataSet.Dispose() objDataSet = Nothing Return True Catch ex As Exception RaiseEvent OnError("ToDataGrid", ex) End Try End Function Public Function ToDataSet(ByVal sQuery As String, Optional ByVal sTable As String = "") As Data.DataSet Try m_objCommand = New SqlCommand(sQuery, m_objConnection) Dim objDataSet As New Data.DataSet Dim objSqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(m_objCommand) 'Verifica se foi defenido a tabela If sTable = "" Then objSqlDataAdapter.Fill(objDataSet) Else objSqlDataAdapter.Fill(objDataSet, sTable) End If objSqlDataAdapter.Dispose() objSqlDataAdapter = Nothing Return objDataSet Catch ex As Exception RaiseEvent OnError("ToDataSet", ex) Return Nothing End Try End Function </code></pre> <p>Thanks</p>
[ { "answer_id": 373210, "author": "Peter Hosey", "author_id": 30461, "author_profile": "https://Stackoverflow.com/users/30461", "pm_score": 3, "selected": false, "text": "window = NSApp.mainWindow()\n appName = NSProcessInfo.processInfo().processName()\n ProcessSerialNumber psn = { 0L, 0L...
2008/12/16
[ "https://Stackoverflow.com/questions/373022", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2019426/" ]
373,027
<p>I'm getting this error in a PHP (Drupal) application:</p> <pre><code>(104)Connection reset by peer: FastCGI: comm with server "/opt/php-5.2.5/bin/php-cgi" aborted: read failed </code></pre> <p>It is often followed by this error:</p> <pre><code>FastCGI: incomplete headers (0 bytes) received from server "/opt/php-5.2.5/bin/php-cgi" </code></pre> <p>The basic Apache configuration for PHP looks like this:</p> <pre><code> FastCgiServer /opt/php-5.2.5/bin/php-cgi -initial-env PHP_FCGI_CHILDREN=32 ScriptAlias /fcgi-bin/php-5.2.5 /opt/php-5.2.5/bin/php-cgi &lt;Location /fcgi-bin/php-5.2.5&gt; Options +ExecCGI SetHandler fastcgi-script SetOutputFilter INCLUDES &lt;/Location&gt; # send php5.2-fastcgi handler to our scriptalias Action php-5.2.5-fastcgi /fcgi-bin/php-5.2.5 </code></pre> <p>Now, my basic question is, what are the general causes of the "comm with server" error? In this particular case, the error appears intermittently, but certain pages generate it more often than others. I'd like to know what to look for when debugging my code.</p>
[ { "answer_id": 4496035, "author": "sacabuche", "author_id": 259337, "author_profile": "https://Stackoverflow.com/users/259337", "pm_score": -1, "selected": false, "text": "#.htaccess file\nAddHandler fastcgi-script .py\n" }, { "answer_id": 9804240, "author": "Yuriy", "aut...
2008/12/16
[ "https://Stackoverflow.com/questions/373027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32137/" ]
373,057
<p>I'm performing a bulk insert with an ADO.NET 2.0 SqlBulkCopy object from a C# method into a MS SQL 2005 database, using a database user with limited permissions. When I try to run the operation, I get the error message:</p> <blockquote> <p>Bulk copy failed. User does not have ALTER TABLE permission on table 'theTable'. ALTER TABLE permission is required on the target table of a bulk copy operation if the table has triggers or check constraints, but <code>'FIRE_TRIGGERS'</code> or <code>'CHECK_CONSTRAINTS'</code> bulk hints are not specified as options to the bulk copy command.</p> </blockquote> <p>I read some documentation and created the bulk copy object with the constructor that lets me specify such things:</p> <pre><code> SqlBulkCopy bc = new SqlBulkCopy( System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"], SqlBulkCopyOptions.FireTriggers &amp; SqlBulkCopyOptions.CheckConstraints); </code></pre> <p>But this doesn't change anything - I get the same error message as before. I tried fiddling with some of the other SqlBulkCopyOptions values but no luck. I really thought this would fix the problem, am I missing something?</p> <p>I tested the procedure after granting ALTER on the table to my user, and the operation succeeded. However this is not an option for my situation.</p>
[ { "answer_id": 373963, "author": "gbn", "author_id": 27535, "author_profile": "https://Stackoverflow.com/users/27535", "pm_score": 2, "selected": false, "text": "ALTER TABLE dbo.SomeTable ENABLE TRIGGER ALL" }, { "answer_id": 374691, "author": "James Orr", "author_id": 41...
2008/12/16
[ "https://Stackoverflow.com/questions/373057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41457/" ]
373,064
<p>My goal is to make sure that in most scenarios objects are used via a "read-only interface" that is a subset of the full interface.</p> <ul> <li>As an example, if I were using C++, I would just return a <code>const</code> object.</li> <li>In C#, if I could achieve this with interfaces, I would just implement a read-only interface and use it everywhere. However, I need operator overloading, which is not allowed for interfaces. That's why I have to use an abstract base class.</li> <li>But if I define an abstract base class, I am not allowed to change accessibility in the derived type.</li> </ul> <p>So, how can I achieve my goal in C#?</p>
[ { "answer_id": 373353, "author": "Paul Kapustin", "author_id": 38325, "author_profile": "https://Stackoverflow.com/users/38325", "pm_score": 1, "selected": false, "text": "protected double accuracy;\npublic double Accuracy { get { return accuracy; } }\n public new double Accuracy\n{\n ...
2008/12/16
[ "https://Stackoverflow.com/questions/373064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38325/" ]
373,067
<p>I'm creating a simple API that creates typed classes based on JSON data that has a mandatory 'type' field defined in it. It uses this string to define a new type, add the fields in the JSON object, instantiate it, and then populate the fields on the instance.</p> <p>What I want to be able to do is allow for these types to be optionally pre-defined in whatever application is using my module. This is so methods and other application-specific attributes not found in the JSON object can be added. I'd like to have my module check if a type already exists, and if it does, use that instead of dynamically creating the type. It would still add attributes from the JSON object, but it would be recycling the existing type.</p> <p>My JSON data is:</p> <pre><code>{ "type": "Person", "firstName": "John", "lastName": "Smith", "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": 10021 }, "phoneNumbers": [ "212 555-1234", "646 555-4567" ] } </code></pre> <p>My code so far (assume json_object is a dict at this point):</p> <pre><code>if not json_object.has_key('type'): raise TypeError('JSON stream is missing a "type" attribute.') ##### THIS IS WHERE I WANT TO CHECK IF THE TYPE BY THAT NAME EXISTS ALREADY #### # create a type definition and add attributes to it definition = type(json_object['type'], (object,), {}) for key in json_object.keys(): setattr(definition, key, None) # instantiate and populate a test object tester = definition() for key, value in json_object.iteritems(): setattr(tester, key, value) </code></pre>
[ { "answer_id": 373076, "author": "Can Berk Güder", "author_id": 2119, "author_profile": "https://Stackoverflow.com/users/2119", "pm_score": 0, "selected": false, "text": "dir() Python 2.5.2 (r252:60911, Oct 5 2008, 19:29:17)\n[GCC 4.3.2] on linux2\nType \"help\", \"copyright\", \"credit...
2008/12/16
[ "https://Stackoverflow.com/questions/373067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,084
<p>Address records are probably used in most database, but I've seen a number of slightly different sets of fields used to store them. The number of fields seems to vary from 3-7, and sometimes all fields are simple labelled address1..addressN, other times given specific meaning (town, city, etc).</p> <p>This is UK specific, though I'm open to comments about the rest of the world too. Here you need the first line of the address (actually just the number) and the post code to identify the address - everything else is mostly an added bonus.</p> <p>I'm currently favouring:</p> <ul> <li>Address 1</li> <li>Address 2</li> <li>Address 3</li> <li>Town</li> <li>County</li> <li>Post Code</li> </ul> <p>We could add Country if we ever needed it (unlikely).</p> <p>What do you think? Is this too little, too much?</p>
[ { "answer_id": 373133, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 0, "selected": false, "text": "Lloyds TSB\nIsle of Man Offshore Centre\nPeveril Buildings\nPeveril Square\nDouglas\nIsle of Man\nIM99 0XX\nUnite...
2008/12/16
[ "https://Stackoverflow.com/questions/373084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26334/" ]
373,087
<p>I use jQuery to make an AJAX POST request to my server, which can return HTTP response with status 302. Then JavaScript just sends GET request to this URL, while I'd like to redirect user to URL in this response. Is this possible?</p>
[ { "answer_id": 373130, "author": "Strelok", "author_id": 2788, "author_profile": "https://Stackoverflow.com/users/2788", "pm_score": -1, "selected": false, "text": "function doAjaxCall() {\n $.ajaxSetup({complete: onRequestCompleted});\n $.get(yourUrl,yourData,yourCallback);\n}\n\nfu...
2008/12/16
[ "https://Stackoverflow.com/questions/373087", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46854/" ]
373,089
<p>What is the purpose of this Rails config setting...</p> <pre><code>config.action_controller.consider_all_requests_local = true </code></pre> <p>It's set to true by default in <code>config/environments/development.rb</code>.</p> <p>Thanks,</p> <p>Ethan</p>
[ { "answer_id": 373135, "author": "Gordon Wilson", "author_id": 23071, "author_profile": "https://Stackoverflow.com/users/23071", "pm_score": 8, "selected": true, "text": "consider_all_requests_local" } ]
2008/12/16
[ "https://Stackoverflow.com/questions/373089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42595/" ]
373,126
<p>I am trying to so something like <a href="https://stackoverflow.com/questions/48475/database-design-for-tagging">Database Design for Tagging</a>, except each of my tags are grouped into categories.</p> <p>For example, let's say I have a database about vehicles. Let's say we actually don't know very much about vehicles, so we can't specify the columns all vehicles will have. Therefore we shall "tag" vehicles with information.</p> <pre><code>1. manufacture: Mercedes model: SLK32 AMG convertible: hardtop 2. manufacture: Ford model: GT90 production phase: prototype 3. manufacture: Mazda model: MX-5 convertible: softtop </code></pre> <p>Now as you can see all cars are tagged with their manufacture and model, but the other categories don't all match. Note that a car can only have one of each category. IE. A car can only have one manufacturer.</p> <p>I want to design a database to support a search for all Mercedes, or to be able to list all manufactures.</p> <p>My current design is something like this:</p> <pre><code>vehicles int vid String vin vehicleTags int vid int tid tags int tid String tag int cid categories int cid String category </code></pre> <p>I have all the right primary and foreign keys in place, except I can't handle the case where each car can only have one manufacturer. Or can I?</p> <p>Can I add a foreign key constraint to the composite primary key in vehicleTags? IE. Could I add a constraint such that the composite primary key (vid, tid) can only be added to vehicleTags only if there isn't already a row in vehicleTags such that for the same vid, there isn't already a tid in the with the same cid?</p> <p>My guess is no. I think the solution to this problem is add a cid column to vehicleTags, and make the new composite primary key (vid, cid). It would look like:</p> <pre><code>vehicleTags int vid int cid int tid </code></pre> <p>This would prevent a car from having two manufacturers, but now I have duplicated the information that tid is in cid.</p> <p>What should my schema be?</p> <p>Tom noticed this problem in my database schema in my previous question, <a href="https://stackoverflow.com/questions/372399/how-do-you-do-many-to-many-table-outer-joins">How do you do many to many table outer joins?</a></p> <p><strong>EDIT</strong><br/> I know that in the example manufacture should really be a column in the vehicle table, but let's say you can't do that. The example is just an example.</p>
[ { "answer_id": 373208, "author": "Dan Vinton", "author_id": 21849, "author_profile": "https://Stackoverflow.com/users/21849", "pm_score": 0, "selected": false, "text": "vehicles\n int vid\n string vin\n\ntags\n int tid\n int cid\n string key\n\ncategories\n int cid\n string catego...
2008/12/16
[ "https://Stackoverflow.com/questions/373126", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21838/" ]
373,134
<p>I have just installed darcs 2.1.2.2. When I type darcs help, sth less-like shows up. When I dismiss it with q it goes away but I don't get prompt and can't execute any commands. C-c doesn't work either. I am using bash on gentoo.</p>
[ { "answer_id": 411496, "author": "Steve Baker", "author_id": 13566, "author_profile": "https://Stackoverflow.com/users/13566", "pm_score": 3, "selected": true, "text": "cmd | less\n" } ]
2008/12/16
[ "https://Stackoverflow.com/questions/373134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5978/" ]
373,142
<p>What techniques can be used to speed up C++ compilation times?</p> <p>This question came up in some comments to Stack Overflow question <em><a href="https://stackoverflow.com/questions/372862">C++ programming style</a></em>, and I'm interested to hear what ideas there are.</p> <p>I've seen a related question, <em><a href="https://stackoverflow.com/questions/318398">Why does C++ compilation take so long?</a></em>, but that doesn't provide many solutions.</p>
[ { "answer_id": 373158, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": false, "text": "-j<N> -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.\n 3 GNU gold ld" }, ...
2008/12/16
[ "https://Stackoverflow.com/questions/373142", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11898/" ]
373,149
<p>I am trying to encode/decode MIME headers in Ruby.</p>
[ { "answer_id": 374045, "author": "Keltia", "author_id": 16143, "author_profile": "https://Stackoverflow.com/users/16143", "pm_score": 3, "selected": true, "text": "require \"base64\"\n Base64.decode64 Base64.encode64" } ]
2008/12/16
[ "https://Stackoverflow.com/questions/373149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39529/" ]
373,153
<p>When you're using a factory pattern, how do you inject dependencies into constructors at runtime?</p> <p>I'm building Foos with different formats - boolean, array, freetext, matrix, etc. That format list will grow as we find different uses for Foo. Here's my basic core domain:</p> <pre><code>public interface IFoo { FooFormat Format { get; } } public class Foo : IFoo { private FooFormat _format; internal Foo(FooFormat format) { _format = format; } public FooFormat Format { get { return _format; } } } public abstract class FooFormat { } public class DefaultFooFormat : FooFormat { } public class BooleanFooFormat : FooFormat { public IList&lt;bool&gt; Values { get; set; } } public class ArrayFooFormat : FooFormat { private IList&lt;string&gt; _values; public ArrayFooFormat(IList&lt;string&gt; values) { _values = values; } public IList&lt;string&gt; Values { get { return _values; } } } </code></pre> <p>IFoo is decorated for the consumer context:</p> <pre><code>public abstract class FooDecorator : IFoo { private IFoo _foo; protected FooDecorator(IFoo foo) { _foo = foo; } public FooFormat Format { get { return _foo.Format; } } protected IFoo foo { get { return _foo; } } } </code></pre> <p>I don't want my consumer to instantiate a Foo directly, so I force them to use a factory:</p> <pre><code>public abstract class FooFactory { protected IFoo Build&lt;T&gt;() { FooFormat format = GetFormat&lt;T&gt;(); return new Foo(format); } private FooFormat GetFormat&lt;T&gt;() { if (typeof(T) == typeof(ArrayFooFormat)) return new ArrayFooFormat(new List&lt;string&gt;()); if (typeof(T) == typeof(BooleanFooFormat)) return new BooleanFooFormat(); return new DefaultFooFormat(); } } </code></pre> <p>And even then, they need to derive a factory from my abstract factory for their particular context.</p> <p>I'm specifically building foos in an html context, like so:</p> <pre><code>public class HtmlFoo : FooDecorator { public HtmlFoo(IFoo foo) : base(foo) { } public string ToHtml() { return "&lt;div&gt;" + this.Format.ToString() + "&lt;/div&gt;"; } } public class HtmlFooFactory : FooFactory { public IFoo BuildFoo&lt;T&gt;() { IFoo foo = Build&lt;T&gt;(); return new HtmlFoo(foo); } } public class HtmlFooConsumer { public void DoSomeFoo() { var factory = new HtmlFooFactory(); var htmlBooleanFoo = factory.BuildFoo&lt;BooleanFooFormat&gt;(); var htmlArrayFoo = factory.BuildFoo&lt;ArrayFooFormat&gt;(); } } </code></pre> <p>My problem is in my abstract FooFactory: I'm always injecting an empty value list into my ArrayFooFormat. I want to be able to pass in a value list from the consumer. For other FooFormats, I want to pass in the right constructor arguments from the consumer. But I want to keep the public API dead simple - I don't want a bunch of overloads on BuildFoo().</p> <p>So how do I pass a custom value list into the factory.BuildFoo&lt;T&gt;() call from inside HtmlFooConsumer.DoSomeFoo()? Any ideas, stackoverflow gurus?</p>
[ { "answer_id": 373797, "author": "Andrew Kennan", "author_id": 22506, "author_profile": "https://Stackoverflow.com/users/22506", "pm_score": 3, "selected": true, "text": "public interface IFooFormat\n{\n}\n\npublic class FooFormat<TValue> : IFooFormat\n{\n private TValue _value;\n\n ...
2008/12/16
[ "https://Stackoverflow.com/questions/373153", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33157/" ]
373,156
<p>I'm scared that one day, I'm going to put a space or miss out something in the command I currently use:</p> <pre><code>rm -rf ./* </code></pre> <p>Is there a safer way of emptying the current directory's contents?</p>
[ { "answer_id": 373164, "author": "Chris Kloberdanz", "author_id": 28714, "author_profile": "https://Stackoverflow.com/users/28714", "pm_score": 0, "selected": false, "text": "-i pwd" }, { "answer_id": 373175, "author": "Pyrolistical", "author_id": 21838, "author_profi...
2008/12/16
[ "https://Stackoverflow.com/questions/373156", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3410/" ]
373,157
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/321113/how-can-i-pre-set-arguments-in-javascript-function-call-partial-function-appli">How can I pre-set arguments in JavaScript function call? (Partial Function Application)</a> </p> </blockquote> <p>I need to able to <strong>pass a reference to a function with a given set of parameters</strong>.</p> <p>Here is an example of passing a reference <strong><em>without</strong> parameters</em>:</p> <pre><code>var f = function () { //Some logic here... }; var fr = f; //Here I am passing a reference to function 'f', without parameters fr(); //the 'f' function is invoked, without parameters </code></pre> <p>Now what I need to do is pass the same <code>f</code> function, but this time I would need to pass parameters to the reference. Now, I can do it with an anonymous function and invoke the <code>f</code> function with parameters inside the newly created function, like such:</p> <pre><code>var f = function () { //Some logic here... }; var fr = function (pars) { f(pars); }; //Here I am creating an anonymous function, and invoking f inside it fr({p : 'a parameter'}); //Invoking the fr function, that will later invoke the f function with parameters </code></pre> <p>But my question is, <strong>Is there a way to pass a direct reference to the <code>f</code> function With parameters to <code>fr</code>, but without enclosing it in an anonymous function?</strong></p> <p><em>What do I need to assign to <code>fr</code> to make it invokable without parameters (<code>fr()</code>), so that f(1,2,3) is executed when <code>fr</code> is invoked?</em> </p> <p><strong>[UPDATE]</strong> I followed <a href="https://stackoverflow.com/questions/373157/javascript-passing-a-reference-to-a-function-with-parameters#373216">Jason Bunting</a>'s answer to <a href="https://stackoverflow.com/questions/321113">here</a> about the <em>Partial Function</em> and the JavaScript function he posts there is exactly what I was looking for. Here is the solution:</p> <pre><code>function partial(func /*, 0..n args */) { var args = Array.prototype.slice.call(arguments).splice(1); return function() { var allArguments = args.concat(Array.prototype.slice.call(arguments)); return func.apply(this, allArguments); }; } </code></pre>
[ { "answer_id": 373216, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 7, "selected": true, "text": "var fr = partial(f, 1, 2, 3);\n\n// now, when you invoke fr() it will invoke f(1,2,3)\nfr();\n" }, { "answer_id...
2008/12/16
[ "https://Stackoverflow.com/questions/373157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44084/" ]
373,182
<p>I bet I've got elementary question, but I couldn't solve it for two nights. I've got 1 "ul" element and I just want it to move any amount of pixels every e.g. 2 sec to the left. I want him to move like this step by step and then come back to the original position and start moving again. I've been stucked, my script only moves it to the final position and finish. </p> <pre><code>window.onload = function moveUl(){ var eUl = document.getElementById('change'); var eLi = eUl.getElementsByTagName('li'); x = -300; function move(){ for(i=0;i&lt; eLi.length;i++){ eUl.style.marginLeft = i*x+'px'; } } setInterval(move,1000); } </code></pre> <p>This is the simpliest I can think of. I know this script executes whole loop after 1 sec, but I try to do something like this : Move this element to the left, wait, move more to left and so on. </p>
[ { "answer_id": 373201, "author": "hhafez", "author_id": 42303, "author_profile": "https://Stackoverflow.com/users/42303", "pm_score": 0, "selected": false, "text": " for(i=eLi.length; i>0 ;i--){\n eUl.style.marginLeft = i*x+'px'; \n }\n" }, { "answer_id": 373222, ...
2008/12/16
[ "https://Stackoverflow.com/questions/373182", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46866/" ]
373,186
<p>I see that I can declare a function with (say)</p> <pre><code>public double Function(double parameter) </code></pre> <p>but what if I do want to take the derivative of that function?</p>
[ { "answer_id": 373265, "author": "pyon", "author_id": 46571, "author_profile": "https://Stackoverflow.com/users/46571", "pm_score": 5, "selected": false, "text": " [f(x+h) - f(x-h)] / 2h [f(x-2h) - 8f(x-h) + 8f(x+h) - f(x+2h)] / 12h delegate double RealFunction(double arg);\n public dou...
2008/12/16
[ "https://Stackoverflow.com/questions/373186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46827/" ]
373,194
<p>I've come up with:</p> <pre><code>re.findall("([a-fA-F\d]*)", data) </code></pre> <p>but it's not very fool proof, is there a better way to grab all MD5-hash codes?</p>
[ { "answer_id": 373207, "author": "Marc Novakowski", "author_id": 27020, "author_profile": "https://Stackoverflow.com/users/27020", "pm_score": 7, "selected": true, "text": "re.findall(r\"([a-fA-F\\d]{32})\", data)\n" }, { "answer_id": 373286, "author": "Greg Hewgill", "au...
2008/12/16
[ "https://Stackoverflow.com/questions/373194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32933/" ]
373,212
<p>I've created a <em>very</em> simple app, which presents an easygui entrybox() and continues to loop this indefinitely as it receives user input.</p> <p>I can quit the program using the Cancel button as this returns None, but I would also like to be able to use the standard 'close' button to quit the program. (ie. top right of a Windows window, top left of a Mac window) This button currently does nothing.</p> <p>Taking a look at the easygui module I found this line: </p> <pre><code>root.protocol('WM_DELETE_WINDOW', denyWindowManagerClose ) </code></pre> <p>This would seem to be the culprit. I'm no TKinter expert but I could probably work out how to alter this handler to act the way I want.</p> <p>However, as I'd rather not mess about with the easygui module, Is there a way to override this behavior from my main script, and have the close button either close the program outright or return None?</p>
[ { "answer_id": 373267, "author": "Angel", "author_id": 23285, "author_profile": "https://Stackoverflow.com/users/23285", "pm_score": 0, "selected": false, "text": "root.protocol('WM_DELETE_WINDOW', self.quit)\n root.protocol('WM_DELETE_WINDOW', self.destroy)\n \"Tkinter protocol WM_DEL...
2008/12/16
[ "https://Stackoverflow.com/questions/373212", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44817/" ]
373,214
<p>I was asking about specifics with this approach earlier today <a href="https://stackoverflow.com/questions/372572/how-to-block-the-ui-thread-from-another-thread-or-force-a-form-to-run-within-th">here</a> but the confused responses has me wondering if I'm going about this all wrong.</p> <p>So here's the problem. I need to architect a WinForms application that periodically checks a value from some external service. If it is in a certain state the application is supposed to pop up a modal form blocking the user from interacting with the application until such time that the state changes. The blocked UI should act just like when a form is displayed using ShowDialog(). That is to say the user should not be able to interact with the ui in any way until the dialog is closed (in this case this can only be done by the application).</p> <p>In my particular application I have the requirement crop up in several instances. For example, at one point the application runs a timer that repeatedly checks the value of a cell in a db table that is constantly being updated by a weighing device. If the value is below a certain threshold the user is prompted to place items on the scale - he or she may not proceed nor interact with the UI until they do so.</p> <p>Every solution I have tried has been chock full of threading problems. Either the dialog won't block the UI, or the timer will not continue checking the external service or the application cannot close the form when the time comes.</p> <p>This seems like a fairly standard winforms requirement and there must be a relevant design pattern that does not bring in Windows.Forms.Timer (I like keep it <a href="http://codebetter.com/blogs/jeremy.miller/archive/2007/05/30/build-your-own-cab-part-4-the-passive-view.aspx" rel="nofollow noreferrer">my views passive</a>). How would you do this?</p>
[ { "answer_id": 373225, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 0, "selected": false, "text": ".Join() public partial class Form1 : Form\n{\n Random r = new Random();\n public Form1()\n {\n ...
2008/12/16
[ "https://Stackoverflow.com/questions/373214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
373,219
<p>I have a silverlight control which has a reference to a silverlight enabled wcf service.</p> <p>When I add a reference to the service in my silverlight control, it adds the following to my clientconfig file:</p> <pre><code>&lt;configuration&gt; &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;binding name="BasicHttpBinding_DataAccess" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"&gt; &lt;security mode="None" /&gt; &lt;/binding&gt; &lt;/basicHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://localhost:3097/MyApp/DataAccess.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DataAccess" contract="svcMyService.DataAccess" name="BasicHttpBinding_DataAccess" /&gt; &lt;/client&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <p>How do I specify a relative url in the endpoint address instead of the absolute url? I want it to work no matter where I deploy the web app to without having to edit the clientconfig file, because the silverlight component and the web app will always be deployed together. I thought I'd be able to specify just "DataAccess.svc" but it doesn't seem to like that.</p>
[ { "answer_id": 375394, "author": "Jeremy", "author_id": 9266, "author_profile": "https://Stackoverflow.com/users/9266", "pm_score": 4, "selected": false, "text": "svcMyService.DataAccessClient svcProxy_m;\n\nSystem.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttp...
2008/12/16
[ "https://Stackoverflow.com/questions/373219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9266/" ]
373,230
<p>How do I check to see if a column exists in a <code>SqlDataReader</code> object? In my data access layer, I have create a method that builds the same object for multiple stored procedures calls. One of the stored procedures has an additional column that is not used by the other stored procedures. I want to modified the method to accommodate for every scenario.</p> <p>My application is written in C#.</p>
[ { "answer_id": 373250, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 5, "selected": false, "text": "public static bool HasColumn(this IDataRecord r, string columnName)\n{\n try\n {\n return r.GetOrdinal(colu...
2008/12/17
[ "https://Stackoverflow.com/questions/373230", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26327/" ]
373,233
<p>Why does adding an "||" OR between 2 "!=" not work for me? </p> <p>When 'name' is "test" or "test2" my if statement doesn't work if I've used 2 "!=" but if I use just one it does, please tell me why.</p> <pre><code>if (col.Name != "test" || col.Name != "test2") { MessageBox.Show("No" + col.Name.ToString()); //This shows "No test" and "No test2" } else { MessageBox.Show("YES " + col.Name.ToString()); //does not reach here } </code></pre> <p>this works with no "||".</p> <pre><code>if (col.Name != "test") { MessageBox.Show("No" + col.Name.ToString()); } else { MessageBox.Show("YES " + col.Name.ToString()); //Shows "YES test" } </code></pre> <p>Thanks all</p>
[ { "answer_id": 373240, "author": "Dan Vinton", "author_id": 21849, "author_profile": "https://Stackoverflow.com/users/21849", "pm_score": 4, "selected": false, "text": "col.Name != \"test\" && col.Name != \"test2\"\n" }, { "answer_id": 373246, "author": "Matthew Crumley", ...
2008/12/17
[ "https://Stackoverflow.com/questions/373233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,234
<p>How can I grab my local changelist and send it to someone else in Perforce? More specifically, I would like to send unsubmitted changes from a local pending changelist to another user's pending changelist.</p>
[ { "answer_id": 373434, "author": "Ana Betts", "author_id": 5728, "author_profile": "https://Stackoverflow.com/users/5728", "pm_score": 5, "selected": true, "text": "set P4DIFF=C:\\cygwin\\bin\\diff.exe\np4 diff -du -c 12345 > patch-to-head.diff\n\n# On Other machine\npatch -p1 < patch-to...
2008/12/17
[ "https://Stackoverflow.com/questions/373234", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46869/" ]
373,243
<p>I use ls to obtain my filename which has white space so it looks something like: </p> <p><code>my file with whitespace.tar.bz2</code></p> <p>I want to pipe this to tar similar to:</p> <pre><code>ls | grep mysearchstring | tar xvjf </code></pre> <p>How can I insert double quotes before piping it to tar?</p>
[ { "answer_id": 373296, "author": "Zan Lynx", "author_id": 13422, "author_profile": "https://Stackoverflow.com/users/13422", "pm_score": 3, "selected": false, "text": "find . -name '*.tar.bz2' -print0 | xargs -0 -n1 tar xjf\n for archive in *.tar.bz2; do tar xvjf \"$archive\"; done\n" }...
2008/12/17
[ "https://Stackoverflow.com/questions/373243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23120/" ]
373,252
<p>Recently saw someone commending another user on their use of sizeof var instead of sizeof(type). I always thought that was just a style choice. Is there any significant difference? As an example, the lines with f and ff were considered better than the lines with g and gg:</p> <pre><code> typedef struct _foo {} foo; foo *f = malloc(count * sizeof f); foo *g = malloc(sizeof(foo) * count); foo **ff = malloc(count * sizeof *ff); foo **gg = malloc(sizeof(foo*) * count); </code></pre> <p>In my opinion, the first set is just a matter of style. But in the second pair of lines, the extra second * can easily be confused for a multiplication.</p>
[ { "answer_id": 373272, "author": "Martin v. Löwis", "author_id": 33006, "author_profile": "https://Stackoverflow.com/users/33006", "pm_score": 2, "selected": false, "text": "sizeof f sizeof *f sizeof(*f)" }, { "answer_id": 373343, "author": "Johannes Schaub - litb", "auth...
2008/12/17
[ "https://Stackoverflow.com/questions/373252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44065/" ]
373,253
<p>Given an array like {"one two", "three four five"}, how'd you calculate the total number of words contained in it using LINQ?</p>
[ { "answer_id": 373260, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 3, "selected": false, "text": "var stringArray = new[] {\"one two\", \"three four five\"};\nvar numWords = stringArray.SelectMany(segment => s...
2008/12/17
[ "https://Stackoverflow.com/questions/373253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1670/" ]
373,257
<p>I have many sites that use the same root category of the Main Site. Each product that is added is added to the site it was added to (wow.) and also the Main Site. However, I would like categories on a per site basis to only appear if there are products on that site.</p> <p>If I have:</p> <pre><code>Category1 Category2 Category3 </code></pre> <p>But Site1 only has products in Category1 and Category2, whereas Site2 and Site3 have products in Category2 and Category3; I only want Category1/2 to appear on Site1 and only Category2/3 to only appear on Site2 and Site3.</p> <p>However, because all products in Site1/2/3 are also added to the Main Site; the Main Site would list Category1/2/3.</p> <p>No products are added directly to the Main Site. It simply serves as a repository for the other sites.</p> <p>Now, if there is no really easy way to enable this (as I'm sure), would it be as simple as writing my own theme that lists categories that only have products on the site that the template is being displayed on?</p> <p>I am not a novice in the technologies that Magento uses; so writing custom code is no problem. I would, however, not like to edit it that much so that upgrading my code base would be easier in the future with later versions of Magento.</p> <p>Thanks, <br /> -nelson</p>
[ { "answer_id": 11385618, "author": "Amir Shakya", "author_id": 1102707, "author_profile": "https://Stackoverflow.com/users/1102707", "pm_score": 0, "selected": false, "text": "<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>\n<?php if($_menu): ?>\n<div>\n <ul id=\"nav\...
2008/12/17
[ "https://Stackoverflow.com/questions/373257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,258
<p>Let's in fact generalize to a <code>c</code>-confidence interval. Let the common rate parameter be <code>a</code>. (Note that the mean of an exponential distribution with rate parameter <code>a</code> is <code>1/a</code>.)</p> <p>First find the cdf of the sum of <code>n</code> such i.i.d. random variables. Use that to compute a <code>c</code>-confidence interval on the sum. Note that the max likelihood estimate (MLE) of the sum is <code>n/a</code>, ie, <code>n</code> times the mean of a single draw.</p> <p>Background: This comes up in a program I'm writing to make time estimates via random samples. If I take samples according to a Poisson process (ie, the gaps between samples have an exponential distribution) and <code>n</code> of them happen during Activity X, what's a good estimate for the duration of Activity X? I'm pretty sure the answer is the answer to this question.</p>
[ { "answer_id": 373751, "author": "dreeves", "author_id": 4234, "author_profile": "https://Stackoverflow.com/users/4234", "pm_score": 3, "selected": true, "text": "F[x_] := 1 - GammaRegularized[n, a*x];\n Fi[p_] := InverseGammaRegularized[n, 1 - p]/a;\n ci[c_, a_, n_] := {Fi[a, n, (1-c)/2...
2008/12/17
[ "https://Stackoverflow.com/questions/373258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4234/" ]
373,261
<p>I am developing an OpenGL application and I am seeing some strange things happen. The machine I am testing with is equipped with an NVidia Quadro FX 4600 and it is running RHEL WS 4.3 x86_64 (kernel 2.6.9-34.ELsmp).</p> <p>I've stepped through the application with a debugger and I've noticed that it is hanging on OpenGL calls that are receiving information from the OpenGL API: i.e. - glGetError, glIsEnabled, etc. Each time it hangs up, the system is unresponsive for 3-4 seconds.</p> <p>Another thing that is interesting is that if this same code is run on RHEL 4.5 (Kernel 2.6.9-67.ELsmp), it runs completely fine. The same code also runs perfectly on Windows XP. All machines are using the exact same hardware:</p> <ul> <li>PNY nVidia Quadro FX4600 768mb PCI Express </li> <li>Dual Intel Xeon DP Quad Core E5345 2.33hz </li> <li>4096 MB 667 MHz Fully Buffered DDR2 </li> <li>Super Micro X7DAL-E Intel 5000X Chipset Dual Xeon Motherboard </li> <li>Enermax Liberty 620 watt Power Supply </li> </ul> <p>I have upgraded to the latest 64bit drivers: Version 177.82, Release Date: Nov 12, 2008 and the result is the exact same.</p> <p>Does anyone have any idea what could be causing the system to hang on these OpenGL calls?</p>
[ { "answer_id": 381477, "author": "Andrew Garrison", "author_id": 16460, "author_profile": "https://Stackoverflow.com/users/16460", "pm_score": 2, "selected": true, "text": "__GL_YIELD \"NOTHING\"" } ]
2008/12/17
[ "https://Stackoverflow.com/questions/373261", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16460/" ]
373,262
<p>How can the XOR operation (on two 32 bit ints) be implemented using only basic arithmetic operations? Do you have to do it bitwise after dividing by each power of 2 in turn, or is there a shortcut? I don't care about execution speed so much as about the simplest, shortest code.</p> <p><strong>Edit:</strong> This is not homework, but a riddle posed on a <a href="http://www.hacker.org" rel="noreferrer">hacker.org</a>. The point is to implement XOR on a stack-based virtual machine with very limited operations (similar to the <a href="http://en.wikipedia.org/wiki/Brainfuck" rel="noreferrer">brainfuck</a> language and yes - no shift or mod). Using that VM is the difficult part, though of course made easier by an algorithm that is short and simple.</p> <p>While FryGuy's solution is clever, I'll have to go with my original ideal (similar to litb's solution) because comparisons are difficult to use as well in that environment.</p>
[ { "answer_id": 373290, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "uint32_t mod_op(uint32_t a, uint32_t b) {\n uint32_t int_div = a / b;\n return a - (b * int_div);\n}\n...
2008/12/17
[ "https://Stackoverflow.com/questions/373262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16883/" ]
373,266
<p>I am trying to create an XML schema representing an 'order' for a shopping cart</p> <p>I want this to completely abstract away my shopping cart's implementation -- and eventually support partners sending us orders using this schema. (yes i'm planning on integrating this schema into our existing cart)</p> <p>It will have original order items, repeat shipping items and domain specific things. I'm quite capable of building this, but i was wondering if there are many things out there like this that I could at least base mine upon. </p> <p>I know there are standards out there for certain schema elements like this, but I've lost track of which are the best/standard and how you might extend them etc.</p> <p>obviously if i want a partner to send me an 'order' i'd like to use a standard if one exists.</p>
[ { "answer_id": 373592, "author": "George Stocker", "author_id": 16587, "author_profile": "https://Stackoverflow.com/users/16587", "pm_score": 2, "selected": false, "text": "<?xml version=\"1.0\"?>\n <Order>\n <Date>2003/07/04</Date>\n <CustomerId>123</CustomerId>\n <CustomerName>Acme ...
2008/12/17
[ "https://Stackoverflow.com/questions/373266", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16940/" ]
373,287
<p>Is it possible to send messages from a PHP script to the console in Eclipse? Has anyone attempted this already? I'm not very familiar with how the console works, so I'm not sure if there is a standardized method for communicating with it.</p>
[ { "answer_id": 374991, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<?php\n\necho \"Hello World\\n\";\n\n?>\n" }, { "answer_id": 399042, "author": "Uresu", "author_id": 11552, ...
2008/12/17
[ "https://Stackoverflow.com/questions/373287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5291/" ]
373,295
<p>Has anyone came across where they have to deal with .truststore file? and knowing how to import .cer into .truststore file? </p> <p>I am not sure if I have to use Java Keytool or Linux command (such as openssl command).</p> <p>Thanks</p>
[ { "answer_id": 373307, "author": "Strelok", "author_id": 2788, "author_profile": "https://Stackoverflow.com/users/2788", "pm_score": 9, "selected": true, "text": "# Copy the certificate into the directory Java_home\\Jre\\Lib\\Security\n# Change your directory to Java_home\\Jre\\Lib\\Secu...
2008/12/17
[ "https://Stackoverflow.com/questions/373295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44534/" ]
373,297
<p>I have Windows Server 2008 installed on a Sony laptop and the brightness control doesn't work. I'd like to write a program to allow me to change it.</p> <p>Currently what I have to do is open the Power control panel, click advanced settings, and fight through so many UAC boxes that anybody watching me must think I'm completely crazy.</p> <p>I just want a simple little program to do it but i dont know what API to call</p>
[ { "answer_id": 799207, "author": "Lucas", "author_id": 24231, "author_profile": "https://Stackoverflow.com/users/24231", "pm_score": 4, "selected": true, "text": "ManagementClass mclass = new ManagementClass(\"WmiMonitorBrightnessMethods\");\nmclass.Scope = new ManagementScope(@\"\\\\.\\...
2008/12/17
[ "https://Stackoverflow.com/questions/373297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16940/" ]
373,305
<p>I am trying to develop a slideshow with a pause between slides. So I'm trying to use the setTimeout statement as shown below. This is written to swap 2.jpg for 1.jpg with a pause of 10 seconds on clicking the button. But it does now work. Can anyone help me. Thanks.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var t; function swap(newImage) { var fileName=newImage.toString()+".jpg" document.slideshow.src=fileName t=setTimeout("swap()",10000) } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;img name="slideshow" src="1.jpg" width="450" height="335" /&gt; &lt;br /&gt;&lt;br /&gt; &lt;input type="button" onClick="swap('2')" value="Change image" /&gt; &lt;br /&gt;&lt;br /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
[ { "answer_id": 373340, "author": "Eran Galperin", "author_id": 10585, "author_profile": "https://Stackoverflow.com/users/10585", "pm_score": 3, "selected": false, "text": " setTimeout(function() { swap(); },10000);\n //Or\n setTimeout(swap,10000); //Passing the actual function as the cal...
2008/12/17
[ "https://Stackoverflow.com/questions/373305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39973/" ]
373,324
<p>I seem to recall that there is an HTML tag that escapes absolutely everything inside it except the matching closing tag. Kind of like <a href="http://www.htmlref.com/reference/AppA/tag_plaintext.htm" rel="noreferrer"><code>&lt;plaintext&gt;</code></a> but not fundamentally broken.</p>
[ { "answer_id": 373337, "author": "EndangeredMassa", "author_id": 106, "author_profile": "https://Stackoverflow.com/users/106", "pm_score": 5, "selected": true, "text": "<xmp>some stuff <tags></tags> too</xmp>\n" }, { "answer_id": 373389, "author": "Greg Hewgill", "author_...
2008/12/17
[ "https://Stackoverflow.com/questions/373324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1343/" ]
373,328
<p>During development (and for debugging) it is very useful to run a Java class' <em>public static void main(String[] argv)</em> method directly from inside Eclipse (using the Run As context menu).</p> <p>Is there a similarily quick way to specify command line parameters for the run? What I do now is go to the "Run Dialog", click through the various settings to the tab where I can specify VM and program arguments and enter them there. Too many steps, plus I do not want to mix the more permanent runtime configuration settings with the one-off invokation parameters. What I want instead is to check a box somewhere (or have a separate menu item "Run as Java application with command line") and then be prompted for the commandline every time (with a nice history).</p>
[ { "answer_id": 374220, "author": "Esko", "author_id": 44523, "author_profile": "https://Stackoverflow.com/users/44523", "pm_score": 4, "selected": false, "text": "Run -> Run configurations... Java Application Program arguments \"a b c\"" }, { "answer_id": 374260, "author": "R...
2008/12/17
[ "https://Stackoverflow.com/questions/373328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14955/" ]
373,335
<p>I'm looking for a library in Python which will provide <code>at</code> and <code>cron</code> like functionality.</p> <p>I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.</p> <p>For those unfamiliar with <code>cron</code>: you can schedule tasks based upon an expression like: </p> <pre><code> 0 2 * * 7 /usr/bin/run-backup # run the backups at 0200 on Every Sunday 0 9-17/2 * * 1-5 /usr/bin/purge-temps # run the purge temps command, every 2 hours between 9am and 5pm on Mondays to Fridays. </code></pre> <p>The cron time expression syntax is less important, but I would like to have something with this sort of flexibility. </p> <p>If there isn't something that does this for me out-the-box, any suggestions for the building blocks to make something like this would be gratefully received.</p> <p><strong>Edit</strong> I'm not interested in launching processes, just "jobs" also written in Python - python functions. By necessity I think this would be a different thread, but not in a different process.</p> <p>To this end, I'm looking for the expressivity of the cron time expression, but in Python. </p> <p>Cron <em>has</em> been around for years, but I'm trying to be as portable as possible. I cannot rely on its presence.</p>
[ { "answer_id": 374207, "author": "Brian", "author_id": 9493, "author_profile": "https://Stackoverflow.com/users/9493", "pm_score": 6, "selected": false, "text": "from datetime import datetime, timedelta\nimport time\n\n# Some utility classes / functions first\nclass AllMatch(set):\n \...
2008/12/17
[ "https://Stackoverflow.com/questions/373335", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4737/" ]
373,342
<p>I have a line of Fortran code, which includes some text. I'm changing the text, which makes the code line too long for Fortran, so I split it over two lines using 'a'. </p> <p>Was:</p> <pre><code> IF (MYVAR .EQ. 1) THEN WRITE(iott,'(A) (A)') 'ABC=', SOMEVAR </code></pre> <p>Changed to:</p> <pre><code> IF (MYVAR .EQ. 1) THEN WRITE(iott,'(A) (A)') 'ABC DEF GHI JK a ' // 'L=', SOMEVAR </code></pre> <p>My question is, on the new line (starting with 'a'), does the white space between the 'a' and the first ' get appended to the string? Or do I need the ' to be the char next to a to prevent additional white space?</p> <p>As you can tell, I'm not used to Fortran...</p>
[ { "answer_id": 373424, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 0, "selected": false, "text": "a" }, { "answer_id": 373600, "author": "Scottie T", "author_id": 6688, "author_profile": "https://S...
2008/12/17
[ "https://Stackoverflow.com/questions/373342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,351
<p><strong>The situation:</strong></p> <p>I need to convert our current development environment from Windows&nbsp;XP 32-bit to Windows&nbsp;Vista 64-bit (*). Naturally, I've run into plenty of places in our build system where hardcoded paths were problematic (e.g. "<code>C:\Program Files</code>" becoming "<code>C:\Program Files (x86)</code>"). Fortunately, there is a <code>%ProgramFiles%</code> environment variable which maps to the proper directory based on the source process (32-bit or 64-bit). So I updated the build scripts with <code>%ProgramFiles%</code>, and I was sure it'd be the end of that.</p> <p>The build environment is called from the command-line (<code>C:\Windows\System32\cmd.exe</code>).</p> <p><b>The problem:</b> On one specific machine (namely my dev machine at work), it turns out that <code>C:\Windows\System32\cmd.exe</code> is actually a 32bit process, so the scripts find the <code>x86</code> version of the <code>Program Files</code> directory and everything works great.</p> <p>On every other 64bit machine I can find (including my home machine), <code>C:\Windows\System32\cmd.exe</code> is the 64bit version, and the 32bit version is in <code>C:\Windows\SysWow64\cmd.exe</code>. So the build scripts can't find anything they're looking for and fail.</p> <p>I understand now that the 32bit <code>cmd.exe</code> should be called explicitly if that's what you need, and by default you get a 64bit <code>cmd.exe</code>. Typical case of <code>WORKSFORME</code>...</p> <p><b>The question is</b>, what happened to the machine where this is not true? Why am I getting a 32bit <code>cmd.exe</code> by default on one machine but not on others? In all cases I am explicitly executing <code>C:\Windows\System32\cmd.exe</code> from the <code>Start|Run</code> menu but getting different results <em>on one machine only</em>. All are running the same edition of Vista 64bit.</p> <p>Any thoughts or insight?</p> <p>(*) Please accept that I <em>must</em> do this. I am not at liberty to say <em>why</em> I am doing this. Re-installing the OS and everything from scratch would probably work, but it is surely overkill. Besides, it was hard enough convincing our IT department to give out Vista machines!</p>
[ { "answer_id": 373583, "author": "Benoit Miller", "author_id": 46807, "author_profile": "https://Stackoverflow.com/users/46807", "pm_score": 1, "selected": false, "text": "cmd.exe cmd c:\\windows\\system32\\cmd.exe *32 Processes cmd explorer.exe" }, { "answer_id": 437548, "au...
2008/12/17
[ "https://Stackoverflow.com/questions/373351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46807/" ]
373,357
<p>Is there any way to get the exposure settings (aperture, shutter speed, ISO) for a photo taken on an iPhone?</p> <p>An app running on the iPhone can use the UIImagePickerController interface for taking pictures, but that doesn't provide much info about the picture.</p> <p>The EXIF data for a photo taken on the iPhone contains aperture info, but not shutter speed or ISO.</p>
[ { "answer_id": 373583, "author": "Benoit Miller", "author_id": 46807, "author_profile": "https://Stackoverflow.com/users/46807", "pm_score": 1, "selected": false, "text": "cmd.exe cmd c:\\windows\\system32\\cmd.exe *32 Processes cmd explorer.exe" }, { "answer_id": 437548, "au...
2008/12/17
[ "https://Stackoverflow.com/questions/373357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1175/" ]
373,365
<p>I want to write out a text file.</p> <p>Instead of the default UTF-8, I want to write it encoded as ISO-8859-1 which is code page 28591. I have no idea how to do this...</p> <p>I'm writing out my file with the following very simple code:</p> <pre><code>using (StreamWriter sw = File.CreateText(myfilename)) { sw.WriteLine("my text..."); sw.Close(); } </code></pre>
[ { "answer_id": 373368, "author": "Steven Behnke", "author_id": 42588, "author_profile": "https://Stackoverflow.com/users/42588", "pm_score": -1, "selected": false, "text": "sw.Encoding = Encoding.GetEncoding(28591);\n" }, { "answer_id": 373372, "author": "Dave Markle", "a...
2008/12/17
[ "https://Stackoverflow.com/questions/373365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44004/" ]
373,366
<p>I'm having an issue setting up one of my projects in TeamCity (v4.0), specifically when it comes to using Object Initializers.</p> <p>The project builds fine normally, however it would seem that TeamCity transforms the build file into something it likes (some MSBuild mutation) and when it comes to compiling the code for a part of the solution it balks when it sees an Object Initializer.</p> <p>Specifically the errors are:</p> <pre><code>[11:16:21]: ErrorView.xaml.cs(22, 187): error CS1026: ) expected [11:16:21]: ErrorView.xaml.cs(22, 208): error CS0116: A namespace does not directly contain members such as fields or methods [11:16:21]: ErrorView.xaml.cs(27, 16): error CS1518: Expected class, delegate, enum, interface, or struct [11:16:21]: ErrorView.xaml.cs(35, 16): error CS1518: Expected class, delegate, enum, interface, or struct [11:16:21]: ErrorView.xaml.cs(46, 91): error CS1031: Type expected [11:16:21]: ErrorView.xaml.cs(46, 119): error CS0116: A namespace does not directly contain members such as fields or methods [11:16:21]: ErrorView.xaml.cs(48, 17): error CS1022: Type or namespace definition, or end-of-file expected </code></pre> <p>When I look into this further it would seem the problem ties back to the transformation of the build file to TeamCity format using CSC from the v2.0 framework directory.</p> <p>Is it possible to compile code using object initializers (a .NET 3.0 feature) with the .NET 2.0 compiler (I would assume not, though I may be missing something), and if not, does anyone know a way to force it to use the 3.0 compiler (if one exists) or the 3.5 compiler?</p> <p>For those interested, the CSC command being executed is:</p> <pre><code>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:..\..\..\build\blah.Logging.dll /reference:..\..\..\build\blah.Presentation.Interfaces.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.VisualBasic.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.Luna.dll" /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Design.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationProvider.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" /debug+ /debug:full /filealign:512 /keyfile:..\..\..\resources\blah.snk /optimize- /out:obj\Debug\blah.dll /resource:obj\Debug\blah.UserInterface.Properties.Resources.resources /resource:obj\Debug\blah.UserInterface.blah.exe.license /target:library /win32icon:blah.ico SignalStrengthIndicator.xaml.cs TrayNotifier.xaml.cs ConnectedView.xaml.cs ConnectionProgressView.xaml.cs NetworkPasswordView.xaml.cs TrayProgress.xaml.cs NetworkConnectionView.xaml.cs ClassFiles\NetworkTypeConverter.cs ClassFiles\SecurityImageConverter.cs ClassFiles\SecurityTooltipConverter.cs ClassFiles\SignalStrengthTooltipConverter.cs ClassFiles\SignalVisibilityConverter.cs ClassFiles\SynchronizedObservableCollection.cs ConnectionOption.xaml.cs DisconnectionProgressView.xaml.cs ErrorView.xaml.cs ..\..\..\config\assemblyversion.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs </code></pre> <p>Thanks!</p> <p>Update: I have partially (read: I'm not happy with it) fixed the problem by changing the build runner from Nant to command runner - this just executed the Nant build file as it was intended without any manipulation, though the feedback level is different. Any other suggestions would be appreciated.</p>
[ { "answer_id": 373422, "author": "Mike Two", "author_id": 23659, "author_profile": "https://Stackoverflow.com/users/23659", "pm_score": 3, "selected": true, "text": "<msbuild project=\"SimpleEcho.v35.proj\">\n <!-- this property enables MSBuild 3.5 -->\n <property name=\"teamcity_dot...
2008/12/17
[ "https://Stackoverflow.com/questions/373366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18434/" ]
373,370
<p>The best I can come up with for now is this monstrosity:</p> <pre><code>&gt;&gt;&gt; datetime.utcnow() \ ... .replace(tzinfo=pytz.UTC) \ ... .astimezone(pytz.timezone("Australia/Melbourne")) \ ... .replace(hour=0,minute=0,second=0,microsecond=0) \ ... .astimezone(pytz.UTC) \ ... .replace(tzinfo=None) datetime.datetime(2008, 12, 16, 13, 0) </code></pre> <p>I.e., in English, get the current time (in UTC), convert it to some other timezone, set the time to midnight, then convert back to UTC.</p> <p>I'm not just using now() or localtime() as that would use the server's timezone, not the user's timezone.</p> <p>I can't help feeling I'm missing something, any ideas?</p>
[ { "answer_id": 373379, "author": "Ignacio Vazquez-Abrams", "author_id": 20862, "author_profile": "https://Stackoverflow.com/users/20862", "pm_score": 0, "selected": false, "text": ">>> time.gmtime()\n(2008, 12, 17, 1, 16, 46, 2, 352, 0)\n>>> time.localtime()\n(2008, 12, 16, 20, 16, 47, 1...
2008/12/17
[ "https://Stackoverflow.com/questions/373370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3715/" ]
373,383
<p>I'm using python and I need to map locations like "Bloomington, IN" to GPS coordinates so I can measure distances between them. What Geocoding libraries/APIs do you recommend? Solutions in other languages are also welcome.</p>
[ { "answer_id": 4514033, "author": "xster", "author_id": 167638, "author_profile": "https://Stackoverflow.com/users/167638", "pm_score": 3, "selected": false, "text": "print Geocoder.geocode(\"Montreal, Canada\")[0].coordinates\n Geocoder.geocode(\"sushi, San Francisco\").count\n Geocoder...
2008/12/17
[ "https://Stackoverflow.com/questions/373383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/280/" ]
373,386
<p>I have a block of code that is repeated within a DB2 stored procedure. I would like to separate this out into a new procedure that I can call with parameters and have it return a value.</p> <p>How do I create a procedure to return a value and how do I call this procedure from inside my original procedure?</p>
[ { "answer_id": 376425, "author": "molasses", "author_id": 11293, "author_profile": "https://Stackoverflow.com/users/11293", "pm_score": 3, "selected": false, "text": "CREATE PROCEDURE myschema.add(IN a INT, IN b INT, OUT c INT)\nBEGIN\n SET c = a + b;\nEND\n DECLARE result INT DEFAULT...
2008/12/17
[ "https://Stackoverflow.com/questions/373386", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11293/" ]
373,387
<p>For a project I am doing I need to manually create a .net project. I am currently using a <code>StreamWriter</code> to create the .sln, .csproj and base (empty for now) class. I am also generating the AssemblyInfo.cs class. I have copied exactly the files and folder structure VS.Net creates when you create an empty windows class library project.</p> <p>For some reason when I try to open the .sln file nothing at all happens. I can open the .csproj file fine, but the project will not compile. I don't get any error messages, just nothing happens. I have checked all of the files I am creating against the ones created by Visual Studio using Beyond Compare and they are exactly the same except for the project name and GUID. </p> <p>Does anyone know if Visual Studio is doing something behind the scenes when it creates a project? Is there something else I could be missing?</p>
[ { "answer_id": 376425, "author": "molasses", "author_id": 11293, "author_profile": "https://Stackoverflow.com/users/11293", "pm_score": 3, "selected": false, "text": "CREATE PROCEDURE myschema.add(IN a INT, IN b INT, OUT c INT)\nBEGIN\n SET c = a + b;\nEND\n DECLARE result INT DEFAULT...
2008/12/17
[ "https://Stackoverflow.com/questions/373387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4244/" ]
373,388
<p>I'll soon be working on a large c# project and would like to build in multi-language support from the start. I've had a play around and can get it working using a separate resource file for each language, then use a resource manager to load up the strings.</p> <p>Are there any other good approaches that I could look into?</p>
[ { "answer_id": 4333182, "author": "JxXx", "author_id": 315333, "author_profile": "https://Stackoverflow.com/users/315333", "pm_score": 2, "selected": false, "text": "public partial class App : Application \n{ \n public App() \n { \n } \n \n protected overr...
2008/12/17
[ "https://Stackoverflow.com/questions/373388", "https://Stackoverflow.com", "https://Stackoverflow.com/users/74652/" ]
373,395
<p>I am a Java programmer and need to work on a Flex/ActionScript project right now. I got an example of using ITreeDataDesriptor from Flex 3 Cookbook, but there is one line of actionscript code that's hard for me to understand. I appreciate if someone could explain this a little further. </p> <pre><code>public function getData(node:Object, model:Object=null):Object { if (node is Office) { return {children:{label:node.name, label:node.address}}; } } </code></pre> <p>The part that I didn't understand was "{children:{label:node.name, label:node.address}}". Office is simply a value object that contains two String properties: name and address.</p>
[ { "answer_id": 373423, "author": "Luke", "author_id": 21406, "author_profile": "https://Stackoverflow.com/users/21406", "pm_score": 1, "selected": false, "text": "var myobject = {\n 'prop1': 100,\n 'prop2': {\n 'a': 1\n }\n}\n\ntrace( myobject.prop1 ); // 100\ntrace( myobjec...
2008/12/17
[ "https://Stackoverflow.com/questions/373395", "https://Stackoverflow.com", "https://Stackoverflow.com/users/455772/" ]
373,419
<p>What is the difference between </p> <ol> <li>a parameter passed by reference</li> <li>a parameter passed by value?</li> </ol> <p>Could you give me some examples, please?</p>
[ { "answer_id": 373429, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 7, "selected": false, "text": "ref // passes a pointer (called reference in java) to an integer\nvoid call_by_value(int *p) { // :1\n p...
2008/12/17
[ "https://Stackoverflow.com/questions/373419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,421
<p>I have analyzed a hibernate generated oracle database and discovered that a delete of a row from a single table will spawn the firing of 1200+ triggers in order to delete the related rows in child tables. The triggers are all auto-generated the same - an automatic delete of a child row without checking for existence first. As it is impossible to predict which child tables will actually have related rows, I think a viable solution to preventing the firing of the cascaded delete down a deeply branched completely empty limb, would be to check for the existence of a related row before attempting to delete. In other dbms', I could simply state " if exists....." before deleting. Is there a comparable way to do this in oracle?</p>
[ { "answer_id": 373466, "author": "Ricardo Villamil", "author_id": 19314, "author_profile": "https://Stackoverflow.com/users/19314", "pm_score": 0, "selected": false, "text": "DECLARE \nX NUMBER;\nBEGIN\n SELECT COUNT(*) INTO X FROM DBA_OBJECTS WHERE OBJECT_TYPE = 'TRIGGER' AND OB...
2008/12/17
[ "https://Stackoverflow.com/questions/373421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,449
<p>I have a Delphi 2009 program that handles a lot of data and needs to be as fast as possible and not use too much memory.</p> <p>What <strong>small simple</strong> changes have you made to your Delphi code that had the biggest impact on the performance of your program by noticeably reducing execution time or memory use?</p> <hr> <p>Thanks everyone for all your answers. Many great tips.</p> <p>For completeness, I'll post a few important articles on Delphi optimization that I found.</p> <p><a href="http://delphi.about.com/od/objectpascalide/a/beforeoptimize.htm" rel="noreferrer">Before you start optimizing Delphi code</a> at About.com</p> <p><a href="http://delphi.about.com/od/objectpascalide/a/speedsize.htm" rel="noreferrer">Speed and Size: Top 10 Tricks</a> also at About.com</p> <p><a href="http://effovex.com/OptimalCode/basics.htm" rel="noreferrer">Code Optimization Fundamentals</a> and <a href="http://effovex.com/OptimalCode/opguide.htm" rel="noreferrer">Delphi Optimization Guidelines</a> at High Performance Delphi, relating to Delphi 7 but still very pertinent.</p>
[ { "answer_id": 373806, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 2, "selected": false, "text": "TQuery TTable DisableControls" }, { "answer_id": 1198694, "author": "Guy Gordon", "author_id": 652328,...
2008/12/17
[ "https://Stackoverflow.com/questions/373449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30176/" ]
373,454
<p>The code</p> <pre><code>&lt;%=Html.CheckBox("SendEmail") %&gt; </code></pre> <p>evaluates to two HTML elements when it's rendered</p> <pre><code>&lt;input id="SendEmail" name="SendEmail" type="checkbox" value="true" /&gt; &lt;input name="SendEmail" type="hidden" value="false" /&gt; </code></pre> <p>Is this by a bug? Or by design? If it's by design, why?</p>
[ { "answer_id": 374632, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 2, "selected": false, "text": " // Render an additional <input type=\"hidden\".../> for checkboxes. This\n // addresses scenario...
2008/12/17
[ "https://Stackoverflow.com/questions/373454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
373,459
<p>I'd like to split a string using one or more separator characters.</p> <p>E.g. "a b.c", split on " " and "." would give the list ["a", "b", "c"].</p> <p>At the moment, I can't see anything in the standard library to do this, and my own attempts are a bit clumsy. E.g.</p> <pre><code>def my_split(string, split_chars): if isinstance(string_L, basestring): string_L = [string_L] try: split_char = split_chars[0] except IndexError: return string_L res = [] for s in string_L: res.extend(s.split(split_char)) return my_split(res, split_chars[1:]) print my_split("a b.c", [' ', '.']) </code></pre> <p>Horrible! Any better suggestions?</p>
[ { "answer_id": 373474, "author": "Ignacio Vazquez-Abrams", "author_id": 20862, "author_profile": "https://Stackoverflow.com/users/20862", "pm_score": 6, "selected": true, "text": ">>> import re\n>>> re.split('[ .]', 'a b.c')\n['a', 'b', 'c']\n" }, { "answer_id": 373576, "auth...
2008/12/17
[ "https://Stackoverflow.com/questions/373459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29903/" ]
373,462
<p>I'm trying to do a simple erase and keep getting errors.</p> <p>Here is the snippet of code for my erase:</p> <pre><code>std::list&lt;Mine*&gt;::iterator iterMines = mines.begin(); for(int i = oldSizeOfMines; i &gt;0 ; i--, iterMines++) { if(player-&gt;distanceFrom(*iterMines) &lt; radiusOfOnScreen) { onScreen.push_back(*iterMines); iterMines = onScreen.erase(iterMines); iterMines--; } } </code></pre> <p>I keep getting a compiler message:</p> <pre><code>1&gt;c:\users\owner\desktop\bosconian\code\bosconian\environment.cpp(158) : error C2664: 'std::list&lt;_Ty&gt;::_Iterator&lt;_Secure_validation&gt; std::list&lt;_Ty&gt;::erase(std::list&lt;_Ty&gt;::_Iterator&lt;_Secure_validation&gt;)' : cannot convert parameter 1 from 'std::list&lt;_Ty&gt;::_Iterator&lt;_Secure_validation&gt;' to 'std::list&lt;_Ty&gt;::_Iterator&lt;_Secure_validation&gt;' 1&gt; with 1&gt; [ 1&gt; _Ty=SpaceObject *, 1&gt; _Secure_validation=true 1&gt; ] 1&gt; and 1&gt; [ 1&gt; _Ty=Mine *, 1&gt; _Secure_validation=true 1&gt; ] 1&gt; and 1&gt; [ 1&gt; _Ty=SpaceObject *, 1&gt; _Secure_validation=true 1&gt; ] 1&gt; No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called </code></pre> <p>I'm puzzled because I believe I'm giving it the correct iterator.</p> <p>Mine is a subclass of SpaceObject (a second generation subclass that is)</p> <p>Does this have anything to do with it? And how would I fix it?</p>
[ { "answer_id": 373505, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 2, "selected": false, "text": "std::list<Mine*>::iterator iterMines = mines.begin();\nfor(int i = oldSizeOfMines; i >0 ; i--, iterMines++)...
2008/12/17
[ "https://Stackoverflow.com/questions/373462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39189/" ]
373,490
<p>We are building a query to count the number of events per hour, per day. Most days there are hours that do not have any activity and therefore where the query is run the count of activities per hour show up but there are gaps and the query excludes these. We still want to show the hours that do not have activity and display a zero so that zero value can then be charted. The query we using looks like this …</p> <pre><code>select datepart(Year, dev_time) as Year, datepart(Month, dev_time) as Month, datepart(Day, dev_time) as Day, datepart(Hour, dev_time) as Hour, count(tdm_msg) as Total_ACTIVITES from TCKT_ACT where tdm_msg = ‘4162′ and dev_time &gt;= DATEADD(day, - 1, GETDATE()) group by datepart(Year, dev_time) , datepart(Month, dev_time) , datepart(Day, dev_time), datepart(Hour, dev_time) order by datepart(Year, dev_time) asc, datepart(Month, dev_time) asc, datepart(Day, dev_time) asc, datepart(Hour, dev_time) asc </code></pre>
[ { "answer_id": 373509, "author": "Dave Markle", "author_id": 24995, "author_profile": "https://Stackoverflow.com/users/24995", "pm_score": 2, "selected": false, "text": "DECLARE @MinDate DATETIME;\nSET @MinDate = CONVERT(varchar, GETDATE(), 101);\n\nWITH times AS (\n SELECT @MinDate ...
2008/12/17
[ "https://Stackoverflow.com/questions/373490", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,518
<p>Using the Java URL class, I can connect to an external <code>HTTPS</code> server (such as our production site), but using a local URL I get following exception. </p> <pre><code>"SunCertPathBuilderException: unable to find valid certification path to requested target". </code></pre> <p>How do I get a valid certification path?</p> <p>EDIT: I'm not using this URL to directly create a connection, I am passing the URL to an <code>itext</code> <code>PDFReader</code>, which is then having the connection issue.</p>
[ { "answer_id": 373526, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 0, "selected": false, "text": "try {\n int port = 443;\n ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();\n Serv...
2008/12/17
[ "https://Stackoverflow.com/questions/373518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/943/" ]
373,520
<p>I have a program in Perl I'm working on where I would need multiple keys, and a way of giving each key multiple values and follow that by being able to both read them in and write them out to an external file depending on if the key matches what the person enters into standard input. I've looked across several sites and have found information somewhat useful in reading in hashes of arrays, but not writing them out, and I would also need to be able able to add to the array in the external file.</p> <p>Is this possible?</p> <p>Edit: Is there a way that it could be done with starter Perl? I'm a beginner. Hashes of arrays seemed like the best way to make it work, but what I really need is a way to show multiple values for the same key while only showing the key once.</p>
[ { "answer_id": 373553, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 5, "selected": true, "text": "#!/bin/perl -w\nuse strict;\nuse Data::Dumper;\n\nmy(%hash);\n\n$hash{key1} = [ 1, \"b\", \"c\" ];\n$hash{key2} = ...
2008/12/17
[ "https://Stackoverflow.com/questions/373520", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,541
<p>I need to do a LINQ2DataSet query that does a join on more than one field (as</p> <pre><code>var result = from x in entity join y in entity2 on x.field1 = y.field1 and x.field2 = y.field2 </code></pre> <p>I have yet found a suitable solution (I can add the extra constraints to a where clause, but this is far from a suitable solution, or use <a href="https://stackoverflow.com/questions/345427/linq-to-sql-join-multiple-columns-from-the-same-table">this</a> solution, but that assumes an equijoin).</p> <p>Is it possible in LINQ to join on multiple fields in a single join?</p> <p><strong>EDIT</strong></p> <pre><code>var result = from x in entity join y in entity2 on new { x.field1, x.field2 } equals new { y.field1, y.field2 } </code></pre> <p>is the solution I referenced as assuming an equijoin above.</p> <p>Further <strong>EDIT</strong></p> <p>To answer criticism that my original example was an equijoin, I do acknowledge that, My current requirement is for an equijoin and I have already employed the solution I referenced above.</p> <p>I am, however, trying to understand what possibilities and best practices I have / should employ with LINQ. I am going to need to do a Date range query join with a table ID soon, and was just pre-empting that issue, It looks like I shall have to add the date range in the where clause.</p> <p>Thanks, as always, for all suggestions and comments given</p>
[ { "answer_id": 373550, "author": "KristoferA", "author_id": 11241, "author_profile": "https://Stackoverflow.com/users/11241", "pm_score": 7, "selected": false, "text": "var result = from x in entity\n join y in entity2 on new { x.field1, x.field2 } equals new { y.field1, y.field2 }\n" ...
2008/12/17
[ "https://Stackoverflow.com/questions/373541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5302/" ]
373,589
<p>I'm playing with the new geography column in SQL Server 2008 and the STGeomFromText function. Here is my code (works with AdventureWorks2008)</p> <pre><code>DECLARE @region geography; set @region = geography::STGeomFromText('POLYGON(( -80.0 50.0, -90.0 50.0, -90.0 25.0, -80.0 25.0, -80.0 50.0))', 4326); SELECT @region; </code></pre> <p>My question is about the 4326 in the code. It is supposed to be a spacial Reference ID. When I go to MSDN there isn't a lot on it. If I change the value to 56 I get an error telling me the value must be in the sys.spatial_reference_systems table.</p> <p>You can look at that table by executing:</p> <pre><code>select * from sys.spatial_reference_systems </code></pre> <p>There is a well_known_text column in that table, but it doesn't tell me much. The value for 4326 is:</p> <pre><code>GEOGCS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84", 6378137, 298.257223563]], PRIMEM["Greenwich", 0], UNIT["Degree", 0.0174532925199433]] </code></pre> <p>Can anyone explain this mystery to me? What is the SRID?</p>
[ { "answer_id": 3566801, "author": "Andy Jones", "author_id": 5096, "author_profile": "https://Stackoverflow.com/users/5096", "pm_score": 1, "selected": false, "text": "select srs.unit_of_measure from sys.spatial_reference_systems as srs where srs.spatial_reference_id = 4326 DECLARE @addr...
2008/12/17
[ "https://Stackoverflow.com/questions/373589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9443/" ]
373,599
<p>I am using a route like this one:</p> <pre><code>routes.MapRoute("Invoice-New-NewCustomer", "Invoice/New/Customer/New/{*name}", new { controller = "Customer", action = "NewInvoice" }, new { name = @"[^\.]*" }); </code></pre> <p>There is an action which handles this route:</p> <pre><code>public ActionResult NewInvoice(string name) { AddClientSideValidation(); CustomerViewData viewData = GetNewViewData(); viewData.InvoiceId = "0"; viewData.Customer.Name = name; return View("New", viewData); } </code></pre> <p>When I call <code>return RedirectToAction("NewInvoice", "Customer", new {name});</code> and name is equal to "The C# Guy", the "name" parameter is truncated to "The C".</p> <p>So my question is : What is the best way to handle this kind of special character with ASP.NET MVC?</p> <p>Thanks!</p>
[ { "answer_id": 373640, "author": "EndangeredMassa", "author_id": 106, "author_profile": "https://Stackoverflow.com/users/106", "pm_score": 2, "selected": false, "text": "Server.URLencode(strURL)\n" }, { "answer_id": 375718, "author": "Haacked", "author_id": 598, "auth...
2008/12/17
[ "https://Stackoverflow.com/questions/373599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1195872/" ]
373,605
<p>How do I load a dropdown list in asp.net and c#?</p>
[ { "answer_id": 373608, "author": "keithwarren7", "author_id": 40714, "author_profile": "https://Stackoverflow.com/users/40714", "pm_score": 1, "selected": false, "text": "DropDownLists DropDownList1.Items.Add( \"what you are adding\" );\n" }, { "answer_id": 373614, "author": ...
2008/12/17
[ "https://Stackoverflow.com/questions/373605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
373,615
<p><strong>The question, in brief:</strong></p> <p>In MVC, how do you distinguish between a checkbox click (or a selectbox or listbox change) from a human meaning "Controller, modify the model", and a checkbox click (or a selectbox or listbox change) from the Controller meaning "I'm updating the view because the model has changed"?</p> <hr> <p><strong>The example:</strong></p> <p>I have a JS app (all one big HTML+JS page; there's a server behind it, and AJAX going on, but it's not important to the example) which has the notion of "Vertices" connected by "Edges". The UI lets you add and remove Vertices on a map, and enable or disable Edges between pairs of Vertices.</p> <p>There are two ways to disable an Edge from Vertex A to Vertex B:</p> <ol> <li>click on the Edge to make the "Edge Details" window provide you with a "Disable This Edge" button; or</li> <li>click on Vertex A (or B) to make the "Vertex Details" window provide you with a checklist of nearby Vertices, from which you can uncheck Vertex B (or A).</li> </ol> <p>Here's how this works under the hood in MVC (<em>but see the end of this post for an update, where I correct problems in my understanding</em>):</p> <ul> <li>Model: a list of Vertex objects and a list of Edge objects.</li> <li>View: a GMaps UI, with markers and polylines, plus checkboxes and buttons and "Vertex Details" and "Edge Details" DIVs.</li> <li>Controller: <ul> <li>JS functions that update the model when events on the checkboxes and buttons fire; and</li> <li>JS functions that update the view when events on the models fire.</li> </ul></li> </ul> <p><strong>Here's the specific inelegance</strong>:</p> <ol> <li>The user has the Vertex Details Window focused on Vertex A, and the Edge Details Window focused on the Edge from Vertex A to Vertex B.</li> <li>The user clicks "Disable This Edge" in the Edge Details window.</li> <li>Controller function 1 gets the click event, and calls disable() on the Edge model object.</li> <li>The Edge model object fires the "I just got disabled" event.</li> <li>Controller function 2 receives the "I just got disabled" event, and <ol> <li>redraws the Edge Details Window to say "I'm disabled!" and</li> <li><strong>unchecks Vertex B in the Vertex Details Window.</strong> <ol> <li><strong>Crap!</strong> This fires Controller function 1 again, which was listening for UI events that mean an edge was disabled!</li> </ol></li> </ol></li> </ol> <p>So there's an unnecessary re-update of the Model, and re-update of the View. In a more complex view with events that fire events that fire events, this can make for dozens of extraneous updates!</p> <p><hr> <strong>Update: a great answer.</strong></p> <p>I misunderstood MVC a bit. I don't have just one View, as I described above: I have several Views into several Models. In particular, I have a checkbox-list View of Edges to a particular Node, and a separate, "detailed window-style" View of an Edge.</p> <p>Furthermore, I shouldn't have one controller function updating all views when the Model changes: each View should modify <em>itself</em> when the Model changes.</p> <p>So if each View registers for "state updated" events on the Model, and each View updates itself upon receipt of those events, then the answer to my circular events question is simply this:</p> <p><strong>The checkbox-list View will disable checkbox events for the moment that it is updating the checkboxes after a Model state change.</strong></p> <p>Now if a user disables an Edge via the Edge Detail window, the Controller updates the Edge Model, the checkbox-list View receives notification of the update, and the checkbox-list View is smart enough to silence checkbox events while changing the status of the appropriate checkbox.</p> <p>This is much more palatable than my original solution, where one Controller updates ALL Views -- and thus has to know which views need special care and feeding to avoid loops. Instead, only the single View with troublesome UI elements has to deal with the problem. </p> <p>Thanks to those who answered my question!</p>
[ { "answer_id": 375619, "author": "Juliet", "author_id": 40516, "author_profile": "https://Stackoverflow.com/users/40516", "pm_score": 0, "selected": false, "text": "\npublic interface GraphView\n{\n event Action ToggleEdge;\n}\n \npublic class UI : UserControl, GraphView\n{\n publi...
2008/12/17
[ "https://Stackoverflow.com/questions/373615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4105/" ]
373,623
<p>This database will store a list of children. But the problem is, they will have their weight measured once a day. How can I store the changes so I can easily query their actual weight and the weight variation over one day, one week and one month?</p>
[ { "answer_id": 373633, "author": "warren", "author_id": 4418, "author_profile": "https://Stackoverflow.com/users/4418", "pm_score": 4, "selected": true, "text": "table kid\n int pkey(id)\n text name\n\ntable weight\n date when\n int kidid fkey(kid.id)\n int weight\n int...
2008/12/17
[ "https://Stackoverflow.com/questions/373623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46921/" ]
373,626
<p>In all my projects till now, I use to use singleton pattern to access Application configuration throughout the application. Lately I see lot of articles taking about not to use singleton pattern , because this pattern does not promote of testability also it hides the Component dependency. My question is what is the best way to store Application configuration, which is easily accessible throughout the application without passing the configuration object all over the application ?.</p> <p>Thanks in Advance</p> <p>Madhu </p>
[ { "answer_id": 373645, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 6, "selected": true, "text": "Lazy<T>" }, { "answer_id": 599126, "author": "Protagonist", "author_id": 460006, "author_profile": "...
2008/12/17
[ "https://Stackoverflow.com/questions/373626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46922/" ]
373,639
<p>I'm trying to run an interactive command through paramiko. The cmd execution tries to prompt for a password but I do not know how to supply the password through paramiko's exec_command and the execution hangs. Is there a way to send values to the terminal if a cmd execution expects input interactively?</p> <pre><code>ssh = paramiko.SSHClient() ssh.connect(server, username=username, password=password) ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("psql -U factory -d factory -f /tmp/data.sql") </code></pre> <p>Does anyone know how this can addressed? Thank you.</p>
[ { "answer_id": 373742, "author": "monkut", "author_id": 24718, "author_profile": "https://Stackoverflow.com/users/24718", "pm_score": 2, "selected": false, "text": "ssh_stdin.write('input value')\nssh_stdin.flush()\n" }, { "answer_id": 373870, "author": "James Brady", "au...
2008/12/17
[ "https://Stackoverflow.com/questions/373639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46920/" ]
373,643
<p>I'm trying to center a page and then make it <code>100%</code> in height. I have a div called "content" as the parent element of all elements in the HTML page. What do I need to do next? I'd like to stay away from any CSS-hacks. This is currently working in IE7, but not in Firefox 3.</p> <p><strong>EDIT:</strong> I added height: <code>100%</code>; to <code>#content</code> that's what made it work in IE. Firefox still not solved.</p> <p>My stylesheet so far is:</p> <pre><code>html, body { width: 100%; height: 100%; } body { background-color: #000; text-align: center; margin-top: 0px; margin-left: auto; margin-right: auto; } #content { position: relative; text-align: left; background-color: #fff; margin-left: auto; margin-right: auto; margin-top: 0px; width: 840px; height: 100%; padding: 0px 5px 5px 5px; } </code></pre>
[ { "answer_id": 373703, "author": "fasih.rana", "author_id": 46024, "author_profile": "https://Stackoverflow.com/users/46024", "pm_score": 0, "selected": false, "text": "body\n{\n background-color: #000;\n text-align: center; \n margin-top: 0px;\n margin-left: auto;\n margi...
2008/12/17
[ "https://Stackoverflow.com/questions/373643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36590/" ]