qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
121,025
<p>How do I get the modified date/time of a file in Python?</p>
[ { "answer_id": 121030, "author": "Thomas Wouters", "author_id": 17624, "author_profile": "https://Stackoverflow.com/users/17624", "pm_score": 6, "selected": true, "text": "os.path.getmtime(filepath)\n" }, { "answer_id": 6110132, "author": "Dingo", "author_id": 291667, "author_profile": "https://Stackoverflow.com/users/291667", "pm_score": 4, "selected": false, "text": "import time\nprint time.strftime(\"%m/%d/%Y %I:%M:%S %p\",time.localtime(os.path.getmtime(fname)))\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121025", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17693/" ]
121,051
<p>How do I go about making an image or section of the page full screen on the iPhone?</p> <p>I have an image that is 480 x 320 and I want to pull that up full screen on the iPhone but it has to be within a webpage so that I can make the image a link back to the previous page.</p> <p>Currently if I drop the image on a blank page and I open it up on the iPhone it just shows up in the top left corner.</p>
[ { "answer_id": 121097, "author": "Hans Sjunnesson", "author_id": 8683, "author_profile": "https://Stackoverflow.com/users/8683", "pm_score": 4, "selected": false, "text": "<head>\n <meta name=\"viewport\" content=\"width=device-width,user-scalable=no\" />\n</head>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8897/" ]
121,059
<p>What is the best way to divide a 32 bit integer into four (unsigned) chars in C#.</p>
[ { "answer_id": 121089, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 2, "selected": false, "text": "int x = yourNumber();\nchar a = (char)(x & 0xff);\nchar b = (char)((x >> 8) & 0xff);\nchar c = (char)((x >> 16) & 0xff);\nchar d = (char)((x >> 24) & 0xff);\n" }, { "answer_id": 121093, "author": "Matthias Meid", "author_id": 17713, "author_profile": "https://Stackoverflow.com/users/17713", "pm_score": 0, "selected": false, "text": "int a = i & 255; // bin 11111111\nint b = i & 65280; // bin 1111111100000000\n" }, { "answer_id": 121106, "author": "Sam", "author_id": 7021, "author_profile": "https://Stackoverflow.com/users/7021", "pm_score": 3, "selected": false, "text": "Byte[] b = BitConverter.GetBytes(i);\nChar c = (Char)b[0];\n[...]\n" }, { "answer_id": 121107, "author": "VVS", "author_id": 21038, "author_profile": "https://Stackoverflow.com/users/21038", "pm_score": 4, "selected": true, "text": "int value = 0x48454C4F;\nConsole.WriteLine(Encoding.ASCII.GetString(\n BitConverter.GetBytes(value).Reverse().ToArray()\n));\n" }, { "answer_id": 121332, "author": "Matt Howells", "author_id": 16881, "author_profile": "https://Stackoverflow.com/users/16881", "pm_score": 2, "selected": false, "text": "Encoding.ASCII.GetChars(BitConverter.GetBytes(x));\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121059", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14759/" ]
121,063
<p>I've recently acquired a second monitor and now run VS2008 SP1 maximized on my secondary (and bigger) monitor. This theoretically has the benefit of opening the application under development on the primary monitor, where -- as it seems to me -- all newly started applications go. So far, so good. The problem though is now, that the exception helper popup is <strong>not</strong> opened on the secondary monitor. Even worse, it is <strong>only</strong> shown when the Studio window is far enough on the primary monitor! If I drag the studio with an opened exception helper from the primary to the secondary monitor, the helper is dragged with the window until it hits the border between the two monitors, where it suddenly <strong>disappears</strong>.</p> <p>Has somebody experienced this too? Is there any workaround? Anything else I should try?</p>
[ { "answer_id": 121089, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 2, "selected": false, "text": "int x = yourNumber();\nchar a = (char)(x & 0xff);\nchar b = (char)((x >> 8) & 0xff);\nchar c = (char)((x >> 16) & 0xff);\nchar d = (char)((x >> 24) & 0xff);\n" }, { "answer_id": 121093, "author": "Matthias Meid", "author_id": 17713, "author_profile": "https://Stackoverflow.com/users/17713", "pm_score": 0, "selected": false, "text": "int a = i & 255; // bin 11111111\nint b = i & 65280; // bin 1111111100000000\n" }, { "answer_id": 121106, "author": "Sam", "author_id": 7021, "author_profile": "https://Stackoverflow.com/users/7021", "pm_score": 3, "selected": false, "text": "Byte[] b = BitConverter.GetBytes(i);\nChar c = (Char)b[0];\n[...]\n" }, { "answer_id": 121107, "author": "VVS", "author_id": 21038, "author_profile": "https://Stackoverflow.com/users/21038", "pm_score": 4, "selected": true, "text": "int value = 0x48454C4F;\nConsole.WriteLine(Encoding.ASCII.GetString(\n BitConverter.GetBytes(value).Reverse().ToArray()\n));\n" }, { "answer_id": 121332, "author": "Matt Howells", "author_id": 16881, "author_profile": "https://Stackoverflow.com/users/16881", "pm_score": 2, "selected": false, "text": "Encoding.ASCII.GetChars(BitConverter.GetBytes(x));\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121063", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4918/" ]
121,066
<p>I want to attach a click event to a button element and then later remove it, but I can't get <code>unclick()</code> or <code>unbind()</code> event(s) to work as expected. In the code below, the button is <code>tan</code> colour and the click event works.</p> <pre><code>window.onload = init; function init() { $("#startButton").css('background-color', 'beige').click(process_click); $("#startButton").css('background-color', 'tan').unclick(); } </code></pre> <p>How can I remove events from my elements?</p>
[ { "answer_id": 121084, "author": "redsquare", "author_id": 6440, "author_profile": "https://Stackoverflow.com/users/6440", "pm_score": 2, "selected": false, "text": "$(\"#startButton\").unbind('click')\n" }, { "answer_id": 121142, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 5, "selected": true, "text": "unclick()" }, { "answer_id": 3719001, "author": "alessioalex", "author_id": 405799, "author_profile": "https://Stackoverflow.com/users/405799", "pm_score": 3, "selected": false, "text": "$('#selector').click(function(event){\n alert(1);\n $(this).unbind(event);\n});\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121066", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
121,111
<p>I'm running VS2008 and have used <a href="http://msdn2.microsoft.com/en-us/library/ms724947.aspx" rel="noreferrer">SystemParametersInfo</a> to activate "Focus Follows Mouse" and "Do not Raise On Focus." Sadly though, VS2008 (with and without SP1) doesn't honour the "Do not Raise" part and eagerly pushes into the foreground every time the pointer touches its window.</p> <p>A while ago I complained about that on my <a href="http://dasz.at/index.php/2008/01/focus-follow-mouse-or-not/" rel="noreferrer">blog and posted an example app</a> to set the parameters. Two others also reported having that problem, but they too didn't know how to proceed.</p> <p>How could I fix/workaround this problem? Anything else I should try?</p>
[ { "answer_id": 64425715, "author": "Yorimyorimyorim", "author_id": 14477636, "author_profile": "https://Stackoverflow.com/users/14477636", "pm_score": 2, "selected": false, "text": "Options -> Environment -> Tabs and Windows -> uncheck both entries under 'Floating Windows'." } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121111", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4918/" ]
121,112
<p>I have a legacy application that is written in C# and it displays a very complex treeview with 10 to 20 thousand elements.</p> <p>In the past I encountered a similar problem (but in C++) that i solved with the OWNERDATA capability offered by the Win32 API.</p> <p>Is there a similar mechanism in C#?</p> <p>EDIT: The plan is to optimize the creation time as well as browsing time. The method available through Win32 API is excellent in both of these cases as it reduce initialization time to nothing and the number of requests for elements are limited to only the ones visible at any one time. Joshl: We are actually doing exactly what you suggest already, but we still need more efficiency.</p>
[ { "answer_id": 121270, "author": "Seb Nilsson", "author_id": 2429, "author_profile": "https://Stackoverflow.com/users/2429", "pm_score": 3, "selected": false, "text": "TreeView tree = new TreeView();\nTreeNode root = new TreeNode(\"Root\");\nPopulateRootNode(root); // Get all your data\ntree.Nodes.Add(root);\n" }, { "answer_id": 121331, "author": "Alex Lyman", "author_id": 5897, "author_profile": "https://Stackoverflow.com/users/5897", "pm_score": 3, "selected": false, "text": "TreeNode.Tag" }, { "answer_id": 71238120, "author": "cheny", "author_id": 797133, "author_profile": "https://Stackoverflow.com/users/797133", "pm_score": 0, "selected": false, "text": " Visible = false;\n ...\n Visible = true;\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19912/" ]
121,116
<p>I have a managed DLL (written in C++/CLI) that contains a class used by a C# executable. In the constructor of the class, I need to get access to the full path of the executable referencing the DLL. In the actual app I know I can use the Application object to do this, but how can I do it from a managed DLL?</p>
[ { "answer_id": 121137, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 5, "selected": true, "text": "Assembly.GetCallingAssembly()\n" }, { "answer_id": 121725, "author": "Brian Stewart", "author_id": 3114, "author_profile": "https://Stackoverflow.com/users/3114", "pm_score": 3, "selected": false, "text": "String^ appPathString = Assembly::GetEntryAssembly()->Location;\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3114/" ]
121,117
<p>Are there any good webservices out there that provide good lookup information for Countries and States/Provinces?</p> <p>If so what ones do you use?</p>
[ { "answer_id": 121160, "author": "Owen", "author_id": 2109, "author_profile": "https://Stackoverflow.com/users/2109", "pm_score": 4, "selected": true, "text": "http://SERVERNAME/ShippingAPITest.dll?API=Verify&XML=<AddressValidateRequest%20USERID=\"xxxxxxx\"><Address ID=\"0\"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>\n" }, { "answer_id": 7563476, "author": "cjbarth", "author_id": 271351, "author_profile": "https://Stackoverflow.com/users/271351", "pm_score": 2, "selected": false, "text": "USZIP.GetInfoByZIP(ZIP).SelectSingleNode(\"//STATE\").InnerText" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8897/" ]
121,147
<p>I'd like to be able to determine if a directory such as a '.app' is considered to be a package or bundle from Finder's point of view on the command line. I don't think this would be difficult to do with a small shell program, but I'd rather not re-invent the wheel if I don't have to.</p>
[ { "answer_id": 121703, "author": "Hagelin", "author_id": 5156, "author_profile": "https://Stackoverflow.com/users/5156", "pm_score": 2, "selected": false, "text": "getFileInfo -aB directory_name\n" }, { "answer_id": 122426, "author": "Mecki", "author_id": 15809, "author_profile": "https://Stackoverflow.com/users/15809", "pm_score": 3, "selected": true, "text": "mdls" }, { "answer_id": 742131, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "$ FILE=/Users/myuser/Desktop/foo.rtfd\n$ osascript -e \"tell application \\\"System Events\\\" to get package folder of alias POSIX file \\\"${FILE}\\\"\"\n" }, { "answer_id": 742145, "author": "Nicholas Riley", "author_id": 6372, "author_profile": "https://Stackoverflow.com/users/6372", "pm_score": 1, "selected": false, "text": "<plug>" }, { "answer_id": 12233785, "author": "Anonymous Coward", "author_id": 1641442, "author_profile": "https://Stackoverflow.com/users/1641442", "pm_score": 3, "selected": false, "text": "mdls -name kMDItemContentTypeTree /Path/To/Directory\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121147", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4468/" ]
121,162
<p>What does the <code>explicit</code> keyword mean in C++?</p>
[ { "answer_id": 121163, "author": "Skizz", "author_id": 1898, "author_profile": "https://Stackoverflow.com/users/1898", "pm_score": 13, "selected": true, "text": "class Foo\n{\nprivate:\n int m_foo;\n\npublic:\n // single parameter constructor, can be used as an implicit conversion\n Foo (int foo) : m_foo (foo) {}\n\n int GetFoo () { return m_foo; }\n};\n" }, { "answer_id": 121216, "author": "Eddie", "author_id": 21116, "author_profile": "https://Stackoverflow.com/users/21116", "pm_score": 10, "selected": false, "text": "String" }, { "answer_id": 122174, "author": "cjm", "author_id": 8355, "author_profile": "https://Stackoverflow.com/users/8355", "pm_score": 8, "selected": false, "text": "String(const char* s)" }, { "answer_id": 1506749, "author": "fmuecke", "author_id": 105643, "author_profile": "https://Stackoverflow.com/users/105643", "pm_score": 5, "selected": false, "text": "arg2" }, { "answer_id": 13485522, "author": "SankararaoMajji", "author_id": 1840657, "author_profile": "https://Stackoverflow.com/users/1840657", "pm_score": 6, "selected": false, "text": "explicit" }, { "answer_id": 16539571, "author": "Helixirr", "author_id": 2028887, "author_profile": "https://Stackoverflow.com/users/2028887", "pm_score": 5, "selected": false, "text": "explicit" }, { "answer_id": 19250874, "author": "Gautam", "author_id": 793930, "author_profile": "https://Stackoverflow.com/users/793930", "pm_score": 6, "selected": false, "text": "class Foo\n{\npublic:\n Foo(int x) : m_x(x)\n {\n }\n\nprivate:\n int m_x;\n};\n" }, { "answer_id": 31351956, "author": "Pixelchemist", "author_id": 951423, "author_profile": "https://Stackoverflow.com/users/951423", "pm_score": 6, "selected": false, "text": "explicit" }, { "answer_id": 39054305, "author": "selfboot", "author_id": 1380954, "author_profile": "https://Stackoverflow.com/users/1380954", "pm_score": 5, "selected": false, "text": "struct A\n{\n A(int) { } // converting constructor\n A(int, int) { } // converting constructor (C++11)\n operator bool() const { return true; }\n};\n\nstruct B\n{\n explicit B(int) { }\n explicit B(int, int) { }\n explicit operator bool() const { return true; }\n};\n\nint main()\n{\n A a1 = 1; // OK: copy-initialization selects A::A(int)\n A a2(2); // OK: direct-initialization selects A::A(int)\n A a3 {4, 5}; // OK: direct-list-initialization selects A::A(int, int)\n A a4 = {4, 5}; // OK: copy-list-initialization selects A::A(int, int)\n A a5 = (A)1; // OK: explicit cast performs static_cast\n if (a1) cout << \"true\" << endl; // OK: A::operator bool()\n bool na1 = a1; // OK: copy-initialization selects A::operator bool()\n bool na2 = static_cast<bool>(a1); // OK: static_cast performs direct-initialization\n\n// B b1 = 1; // error: copy-initialization does not consider B::B(int)\n B b2(2); // OK: direct-initialization selects B::B(int)\n B b3 {4, 5}; // OK: direct-list-initialization selects B::B(int, int)\n// B b4 = {4, 5}; // error: copy-list-initialization does not consider B::B(int,int)\n B b5 = (B)1; // OK: explicit cast performs static_cast\n if (b5) cout << \"true\" << endl; // OK: B::operator bool()\n// bool nb1 = b2; // error: copy-initialization does not consider B::operator bool()\n bool nb2 = static_cast<bool>(b2); // OK: static_cast performs direct-initialization\n}\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121162", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1898/" ]
121,167
<p>What are some of the lesser-known but useful features and techniques that people are using in their Greasemonkey scripts?</p> <p>(Please, just one feature per answer.)</p> <p>Similar threads:</p> <ul> <li><a href="https://stackoverflow.com/questions/61088/hidden-features-of-javascript">Hidden Features of JavaScript</a></li> <li><a href="https://stackoverflow.com/questions/15496/hidden-features-of-java">Hidden Features of Java</a></li> <li><a href="https://stackoverflow.com/questions/75538/hidden-features-of-c">Hidden Features of C++</a></li> <li><a href="https://stackoverflow.com/questions/9033/hidden-features-of-c">Hidden Features of C#</a></li> </ul>
[ { "answer_id": 121197, "author": "Chris Noe", "author_id": 14749, "author_profile": "https://Stackoverflow.com/users/14749", "pm_score": 3, "selected": false, "text": "GM_setValue(keyname, value)" }, { "answer_id": 121327, "author": "Chris Noe", "author_id": 14749, "author_profile": "https://Stackoverflow.com/users/14749", "pm_score": 2, "selected": false, "text": "http://mysite.com/logo.gif?zippyver=1.0" }, { "answer_id": 121601, "author": "Robert J. Walker", "author_id": 4287, "author_profile": "https://Stackoverflow.com/users/4287", "pm_score": 4, "selected": false, "text": "document.evaluate()" }, { "answer_id": 144415, "author": "mislav", "author_id": 11687, "author_profile": "https://Stackoverflow.com/users/11687", "pm_score": 4, "selected": false, "text": "==UserScript==\n...\n@require http://ajax.googleapis.com/ajax/framework-of-your/choice.js\n==/UserScript==\n" }, { "answer_id": 664485, "author": "PotatoEngineer", "author_id": 26257, "author_profile": "https://Stackoverflow.com/users/26257", "pm_score": 3, "selected": false, "text": "var foo={people:['Bob','George','Smith','Grognak the Destroyer'],pie:true};\nGM_setValue('myVeryOwnFoo',uneval(foo));\nvar fooReborn=eval(GM_getValue('myVeryOwnFoo','new Object()'));\nGM_log('People: '+fooReborn.people+' Pie:'+fooReborn.pie);\n" }, { "answer_id": 8764806, "author": "Darth Egregious", "author_id": 973810, "author_profile": "https://Stackoverflow.com/users/973810", "pm_score": 1, "selected": false, "text": "GM_info" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14749/" ]
121,199
<p>How is it possible in Eclipse JDT to convert a multiline selection to String. Like the following</p> <p>From:</p> <pre><code>xxxx yyyy zzz </code></pre> <p>To:</p> <pre><code>"xxxx " + "yyyy " + "zzz" </code></pre> <p>I tried the following template </p> <pre><code>"${line_selection}${cursor}"+ </code></pre> <p>but that way I only get the whole block surrounded not each line separately. How can I achieve a multiline processing like commenting the selected block?</p>
[ { "answer_id": 121420, "author": "Diomidis Spinellis", "author_id": 20520, "author_profile": "https://Stackoverflow.com/users/20520", "pm_score": 2, "selected": false, "text": "sed 's/^/\"/;s/$/\"+/'\n" }, { "answer_id": 121428, "author": "Rafał Dowgird", "author_id": 12166, "author_profile": "https://Stackoverflow.com/users/12166", "pm_score": 2, "selected": false, "text": "^(.*)$\n" }, { "answer_id": 121513, "author": "Grundlefleck", "author_id": 4120, "author_profile": "https://Stackoverflow.com/users/4120", "pm_score": 6, "selected": false, "text": "\"xxxx\\n\" + \n\"yyyy\\n\" + \n\"zzz\"\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
121,202
<p>I work with quite a bit of multi-platform C/C++ code, separated by common #defines (#if WIN, #if UNIX, etc). It would be nice if I could have vim automatically fold the sections I'm currently not interested in when I open a file. I've searched through the vim script archives, but I haven't found anything useful. Any suggestions? Places to start?</p>
[ { "answer_id": 121278, "author": "hometoast", "author_id": 2009, "author_profile": "https://Stackoverflow.com/users/2009", "pm_score": 3, "selected": false, "text": ":syn region myFold start=\"\\#IF\" end=\"\\#ENDIF\" transparent fold\n:syn sync fromstart\n:set foldmethod=syntax\n" }, { "answer_id": 121390, "author": "skymt", "author_id": 18370, "author_profile": "https://Stackoverflow.com/users/18370", "pm_score": 0, "selected": false, "text": "$VIMRUNTIME/syntax/c.vim" }, { "answer_id": 673965, "author": "Fire Crow", "author_id": 80479, "author_profile": "https://Stackoverflow.com/users/80479", "pm_score": 0, "selected": false, "text": "set foldmethod=marker\nset foldmarker=<(,)>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121202", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21138/" ]
121,203
<p>There was a post this morning asking about how many people disable JavaScript. Then I began to wonder what techniques might be used to determine if the user has it disabled. </p> <p>Does anyone know of some short/simple ways to detect if JavaScript is disabled? My intention is to give a warning that the site is not able to function properly without the browser having JS enabled. </p> <p>Eventually I would want to redirect them to content that is able to work in the absence of JS, but I need this detection as a placeholder to start.</p>
[ { "answer_id": 121211, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 8, "selected": false, "text": "noscript" }, { "answer_id": 121220, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 2, "selected": false, "text": "gif" }, { "answer_id": 121224, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "<script type=\"text/javascript\">\n...some javascript script to insert data...\n</script>\n<noscript>\n <p>Access the <a href=\"http://someplace.com/data\">data.</a></p>\n</noscript>\n" }, { "answer_id": 121259, "author": "Marc Gear", "author_id": 6563, "author_profile": "https://Stackoverflow.com/users/6563", "pm_score": 9, "selected": true, "text": "<noscript>" }, { "answer_id": 125775, "author": "Andrew Hedges", "author_id": 11577, "author_profile": "https://Stackoverflow.com/users/11577", "pm_score": 5, "selected": false, "text": "<form onsubmit=\"this.js_enabled.value=1;return true;\">\n <input type=\"hidden\" name=\"js_enabled\" value=\"0\">\n <input type=\"submit\" value=\"go\">\n</form>\n" }, { "answer_id": 608888, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "<noscript><meta http-equiv=\"refresh\" content=\"0; url=whatyouwant.html\" /></noscript>\n" }, { "answer_id": 3265514, "author": "Brian", "author_id": 393928, "author_profile": "https://Stackoverflow.com/users/393928", "pm_score": 4, "selected": false, "text": "<span name=\"jsOnly\" style=\"display: none;\"></span>\n" }, { "answer_id": 3926750, "author": "hairbo", "author_id": 474887, "author_profile": "https://Stackoverflow.com/users/474887", "pm_score": 9, "selected": false, "text": "<noscript>\n <style type=\"text/css\">\n .pagecontainer {display:none;}\n </style>\n <div class=\"noscriptmsg\">\n You don't have javascript enabled. Good luck with that.\n </div>\n</noscript>\n" }, { "answer_id": 4393432, "author": "borrel", "author_id": 423777, "author_profile": "https://Stackoverflow.com/users/423777", "pm_score": 4, "selected": false, "text": ".pagecontainer {\n display: none;\n}\n" }, { "answer_id": 5511645, "author": "the_seeker_who", "author_id": 687345, "author_profile": "https://Stackoverflow.com/users/687345", "pm_score": 4, "selected": false, "text": "<noscript>\n <meta http-equiv=\"refresh\" runat=\"server\" id=\"mtaJSCheck\" content=\"0;logon.aspx\" />\n</noscript>\n" }, { "answer_id": 5591600, "author": "Jorge", "author_id": 679330, "author_profile": "https://Stackoverflow.com/users/679330", "pm_score": 0, "selected": false, "text": "<head>\n <title>Please Activate Javascript</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n <script type=\"text/javascript\" src=\"js/jquery-1.3.2.min.js\"></script> \n</head>\n\n<body>\n\n<script language=\"JavaScript\">\n $(document).ready(function() {\n location.href = \"code/home.php\";\n }); \n</script>\n\n<noscript>\n <h2>This web site needs javascript activated to work properly. Please activate it. Thanks!</h2>\n</noscript>\n\n</body>\n\n</html>\n" }, { "answer_id": 7259031, "author": "Explosion Pills", "author_id": 454533, "author_profile": "https://Stackoverflow.com/users/454533", "pm_score": 2, "selected": false, "text": "noscript" }, { "answer_id": 10318429, "author": "zadubz", "author_id": 946923, "author_profile": "https://Stackoverflow.com/users/946923", "pm_score": 5, "selected": false, "text": " document.body.className = document.body.className.replace(\"no-js\",\"js\");\n" }, { "answer_id": 14302385, "author": "Jen", "author_id": 1524533, "author_profile": "https://Stackoverflow.com/users/1524533", "pm_score": 2, "selected": false, "text": "// Jquery\n$('body').addClass('js-enabled');\n\n/* CSS */\n.menu-mobile {display:none;}\nbody.js-enabled .menu-mobile {display:block;}\n" }, { "answer_id": 14733160, "author": "RohitG", "author_id": 1972968, "author_profile": "https://Stackoverflow.com/users/1972968", "pm_score": -1, "selected": false, "text": "<?php $jsEnabledVar = 0; ?> \n\n<script type=\"text/javascript\">\nvar jsenabled = 1;\nif(jsenabled == 1)\n{\n <?php $jsEnabledVar = 1; ?>\n}\n</script>\n\n<noscript>\nvar jsenabled = 0;\nif(jsenabled == 0)\n{\n <?php $jsEnabledVar = 0; ?>\n}\n</noscript>\n" }, { "answer_id": 15027965, "author": "Umesh Patil", "author_id": 2833565, "author_profile": "https://Stackoverflow.com/users/2833565", "pm_score": 4, "selected": false, "text": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <noscript>\n <meta http-equiv=\"refresh\" content=\"0; /?javascript=false\">\n </noscript>\n <meta charset=\"UTF-8\"/>\n <title></title>\n </head>\n</html>\n" }, { "answer_id": 18397577, "author": "Unbroken", "author_id": 1559998, "author_profile": "https://Stackoverflow.com/users/1559998", "pm_score": 2, "selected": false, "text": "CREATE TABLE IF NOT EXISTS `log_JS` (\n `logJS_id` int(11) NOT NULL AUTO_INCREMENT,\n `data_ins` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `session_id` varchar(50) NOT NULL,\n `JS_ON` tinyint(1) NOT NULL DEFAULT '0',\n `agent` varchar(255) DEFAULT NULL,\n PRIMARY KEY (`logJS_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n" }, { "answer_id": 18754750, "author": "Chris Pesoa", "author_id": 1485400, "author_profile": "https://Stackoverflow.com/users/1485400", "pm_score": 2, "selected": false, "text": "<style>\n#jsDis:after {\n content:\"Javascript is Disable. Please turn it ON!\";\n font:bold 11px Verdana;\n color:#FF0000;\n}\n\n#jsEn {\n background-color:#dedede;\n}\n\n#jsEn:after {\n content:\"Javascript is Enable. Well Done!\";\n font:bold 11px Verdana;\n color:#333333;\n}\n</style>\n" }, { "answer_id": 18834035, "author": "David N. Jafferian", "author_id": 1590397, "author_profile": "https://Stackoverflow.com/users/1590397", "pm_score": 1, "selected": false, "text": "<?php\n/*****************************************************************************\n * JAVASCRIPT DETECTION *\n *****************************************************************************/\n\n// Progressive enhancement and graceful degradation are not sufficient if we\n// want to avoid sending HTML or JavaScript code that won't be useful on the\n// client side. A normal HTTP request will not include any explicit indicator\n// that JavaScript is enabled in the client. So a \"preflight response\" is\n// needed to prompt the client to provide an indicator in a follow-up request.\n// Once the state of JavaScript availability has been received the state of\n// data received in the original request must be restored before proceding.\n// To the user, this handshake should be as invisible as possible.\n// \n// The most convenient place to store the original data is in a PHP session.\n// The PHP session extension will try to use a cookie to pass the session ID\n// but if cookies are not enabled it will insert it into the query string.\n// This violates our preference for invisibility. When Javascript is not\n// enabled the only way to effect a client side redirect is with a \"meta\"\n// element with its \"http-equiv\" attribute set to \"refresh\". In this case\n// modifying the URL is the only way to pass the session ID back.\n//\n// But when cookies are disabled and JavaScript is enabled then a client side\n// redirect can be effected by setting the \"window.onload\" method to a function\n// which submits a form. The form has a \"method\" attribute of \"post\" and an\n// \"action\" attribute set to the original URL. The form contains two hidden\n// input elements, one in which the session ID is stored and one in which the\n// state of JavaScript availability is stored. Both values are thereby passed\n// back to the server in a POST request while the URL remains unchanged. The\n// follow-up request will be a POST even if the original request was a GET, but\n// since the original request data is restored, the containing script ought to\n// process the request as though it were a GET.\n\n// In order to ensure that the constant SID is defined as the caller of this\n// script would expect, call session_start if it hasn't already been called.\n$session = isset($_SESSION);\nif (!$session) session_start();\n\n// Use a separate session for Javascript detection. Save the caller's session\n// name and ID. If this is the followup request then close the caller's\n// session and reopen the Javascript detection session. Otherwise, generate a\n// new session ID, close the caller's session and create a new session for\n// Javascript detection.\n$session_name = session_name();\n$session_id = session_id();\nsession_write_close();\nsession_name('JS_DETECT');\nif (isset($_COOKIE['JS_DETECT'])) {\n session_id($_COOKIE['JS_DETECT']);\n} elseif (isset($_REQUEST['JS_DETECT'])) {\n session_id($_REQUEST['JS_DETECT']);\n} else {\n session_id(sha1(mt_rand()));\n}\nsession_start();\n\nif (isset($_SESSION['_SERVER'])) {\n // Preflight response already sent.\n // Store the JavaScript availability status in a constant.\n define('JS_ENABLED', 0+$_REQUEST['JS_ENABLED']);\n // Store the cookie availability status in a constant.\n define('COOKIES_ENABLED', isset($_COOKIE['JS_DETECT']));\n // Expire the cookies if they exist.\n setcookie('JS_DETECT', 0, time()-3600);\n setcookie('JS_ENABLED', 0, time()-3600);\n // Restore the original request data.\n $_GET = $_SESSION['_GET'];\n $_POST = $_SESSION['_POST'];\n $_FILES = $_SESSION['_FILES'];\n $_COOKIE = $_SESSION['_COOKIE'];\n $_SERVER = $_SESSION['_SERVER'];\n $_REQUEST = $_SESSION['_REQUEST'];\n // Ensure that uploaded files will be deleted if they are not moved or renamed.\n function unlink_uploaded_files () {\n foreach (array_keys($_FILES) as $k)\n if (file_exists($_FILES[$k]['tmp_name']))\n unlink($_FILES[$k]['tmp_name']);\n }\n register_shutdown_function('unlink_uploaded_files');\n // Reinitialize the superglobal.\n $_SESSION = array();\n // Destroy the Javascript detection session.\n session_destroy();\n // Reopen the caller's session.\n session_name($session_name);\n session_id($session_id);\n if ($session) session_start();\n unset($session, $session_name, $session_id, $tmp_name);\n // Complete the request.\n} else {\n // Preflight response not sent so send it.\n // To cover the case where cookies are enabled but JavaScript is disabled,\n // initialize the cookie to indicate that JavaScript is disabled.\n setcookie('JS_ENABLED', 0);\n // Prepare the client side redirect used when JavaScript is disabled.\n $content = '0; url='.$_SERVER['REQUEST_URI'];\n if (!$_GET['JS_DETECT']) {\n $content .= empty($_SERVER['QUERY_STRING']) ? '?' : '&';\n $content .= 'JS_DETECT='.session_id();\n }\n // Remove request data which should only be used here.\n unset($_GET['JS_DETECT'],$_GET['JS_ENABLED'],\n $_POST['JS_DETECT'],$_POST['JS_ENABLED'],\n $_COOKIE['JS_DETECT'],$_COOKIE['JS_ENABLED'],\n $_REQUEST['JS_DETECT'],$_REQUEST['JS_ENABLED']);\n // Save all remaining request data in session data.\n $_SESSION['_GET'] = $_GET;\n $_SESSION['_POST'] = $_POST;\n $_SESSION['_FILES'] = $_FILES;\n $_SESSION['_COOKIE'] = $_COOKIE;\n $_SESSION['_SERVER'] = $_SERVER;\n $_SESSION['_REQUEST'] = $_REQUEST;\n // Rename any uploaded files so they won't be deleted by PHP. When using\n // a clustered web server, upload_tmp_dir must point to shared storage.\n foreach (array_keys($_FILES) as $k) {\n $tmp_name = $_FILES[$k]['tmp_name'].'x';\n if (move_uploaded_file($_FILES[$k]['tmp_name'], $tmp_name))\n $_SESSION['_FILES'][$k]['tmp_name'] = $tmp_name;\n }\n// Have the client inform the server as to the status of Javascript.\n?>\n<!DOCTYPE html>\n<html>\n<head>\n <script>\n document.cookie = 'JS_ENABLED=1';\n// location.reload causes a confirm box in FireFox\n// if (document.cookie) { location.reload(true); }\n if (document.cookie) { location.href = location; }\n </script>\n <meta http-equiv=\"refresh\" content=\"<?=$content?>\" />\n</head>\n<body>\n <form id=\"formid\" method=\"post\" action=\"\" >\n <input type=\"hidden\" name=\"<?=$session_name?>\" value=\"<?=$session_id?>\" />\n <input type=\"hidden\" name=\"JS_DETECT\" value=\"<?=session_id()?>\" />\n <input type=\"hidden\" name=\"JS_ENABLED\" value=\"1\" />\n </form>\n <script>\n document.getElementById('formid').submit();\n </script>\n</body>\n</html>\n<?php\n exit;\n}\n?>\n" }, { "answer_id": 21620527, "author": "Zack", "author_id": 1365084, "author_profile": "https://Stackoverflow.com/users/1365084", "pm_score": 5, "selected": false, "text": "<noscript>" }, { "answer_id": 29414911, "author": "Alpha2k", "author_id": 3257288, "author_profile": "https://Stackoverflow.com/users/3257288", "pm_score": 3, "selected": false, "text": "<noscript>\n <style>\n body *{ /*hides all elements inside the body*/\n display: none;\n }\n h1{ /* even if this h1 is inside head tags it will be first hidden, so we have to display it again after all body elements are hidden*/\n display: block;\n }\n </style>\n <h1>JavaScript is not enabled, please check your browser settings.</h1>\n</noscript>\n" }, { "answer_id": 50908173, "author": "Pavan Kumar", "author_id": 7775044, "author_profile": "https://Stackoverflow.com/users/7775044", "pm_score": 2, "selected": false, "text": "<noscript>" }, { "answer_id": 62476224, "author": "rexfordkelly", "author_id": 1459860, "author_profile": "https://Stackoverflow.com/users/1459860", "pm_score": 1, "selected": false, "text": "<script>document.getElementsByTagName('html')[0].classList.add('js-enabled');</script>" }, { "answer_id": 68101868, "author": "Mikko Rantalainen", "author_id": 334451, "author_profile": "https://Stackoverflow.com/users/334451", "pm_score": 1, "selected": false, "text": "let" }, { "answer_id": 70893260, "author": "HariHaran", "author_id": 8368871, "author_profile": "https://Stackoverflow.com/users/8368871", "pm_score": 1, "selected": false, "text": "BaseController" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10676/" ]
121,218
<p>Is it possible to detect the HTTP request method (e.g. GET or POST) of a page from JavaScript? If so, how?</p>
[ { "answer_id": 121290, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 4, "selected": false, "text": "<meta>" }, { "answer_id": 6760459, "author": "Andy", "author_id": 608042, "author_profile": "https://Stackoverflow.com/users/608042", "pm_score": 3, "selected": false, "text": "document.referrer == document.URL\n" }, { "answer_id": 53132930, "author": "coder", "author_id": 10470741, "author_profile": "https://Stackoverflow.com/users/10470741", "pm_score": -1, "selected": false, "text": "function getURIQueryString(){\n var params = {};\n var qstring = window.location.toString().substring(window.location.toString().indexOf(\"?\") + 1);\n var regex = /([^&=]+)=([^&=]+)/g;\n var m;\n while (m = regex.exec(qstring)){\n params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]) \n }\n return params\n}\n" }, { "answer_id": 67752437, "author": "DennyStackOverFlow", "author_id": 12653780, "author_profile": "https://Stackoverflow.com/users/12653780", "pm_score": 0, "selected": false, "text": "<?php \n $foo = $_POST[\"fooRequest\"]; # The actual response.\n\n # do something with the foo variable like:\n # echo \"Response got: \" + $foo;\n?>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3420/" ]
121,237
<p>I would like to convert a string into a node. I have a method that is defined to take a node, but the value I have is a string (it is hard coded). How do I turn that string into a node?</p> <p>So, given an XQuery method:</p> <pre><code>define function foo($bar as node()*) as node() { (: unimportant details :) } </code></pre> <p>I have a string that I want to pass to the foo method. How do I convert the string to a node so that the method will accept the string.</p>
[ { "answer_id": 121249, "author": "Sixty4Bit", "author_id": 1681, "author_profile": "https://Stackoverflow.com/users/1681", "pm_score": 5, "selected": true, "text": "xdmp:unquote($string).\n" }, { "answer_id": 121467, "author": "Jim Burger", "author_id": 20164, "author_profile": "https://Stackoverflow.com/users/20164", "pm_score": 2, "selected": false, "text": "saxon:parse" }, { "answer_id": 276520, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "text { \"your string goes here\" }\n" }, { "answer_id": 67906474, "author": "the hand of NOD", "author_id": 3564455, "author_profile": "https://Stackoverflow.com/users/3564455", "pm_score": 0, "selected": false, "text": "fn:parse-xml(xs:string)" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1681/" ]
121,240
<p>What is the best (cleanest, most efficient) way to write saturating addition in C?</p> <p>The function or macro should add two unsigned inputs (need both 16- and 32-bit versions) and return all-bits-one (0xFFFF or 0xFFFFFFFF) if the sum overflows.</p> <p>Target is x86 and ARM using gcc (4.1.2) and Visual Studio (for simulation only, so a fallback implementation is OK there).</p>
[ { "answer_id": 121263, "author": "DGentry", "author_id": 4761, "author_profile": "https://Stackoverflow.com/users/4761", "pm_score": 3, "selected": false, "text": "uint32_t saturate_add32(uint32_t a, uint32_t b)\n{\n uint32_t sum = a + b;\n if ((sum < a) || (sum < b))\n return ~((uint32_t)0);\n else\n return sum;\n} /* saturate_add32 */\n\nuint16_t saturate_add16(uint16_t a, uint16_t b)\n{\n uint16_t sum = a + b;\n if ((sum < a) || (sum < b))\n return ~((uint16_t)0);\n else\n return sum;\n} /* saturate_add16 */\n" }, { "answer_id": 121271, "author": "Frank Szczerba", "author_id": 8964, "author_profile": "https://Stackoverflow.com/users/8964", "pm_score": 2, "selected": false, "text": "#define sadd16(a, b) (uint16_t)( ((uint32_t)(a)+(uint32_t)(b)) > 0xffff ? 0xffff : ((a)+(b)))\n#define sadd32(a, b) (uint32_t)( ((uint64_t)(a)+(uint64_t)(b)) > 0xffffffff ? 0xffffffff : ((a)+(b)))\n" }, { "answer_id": 121314, "author": "Igor Semenov", "author_id": 11401, "author_profile": "https://Stackoverflow.com/users/11401", "pm_score": 2, "selected": false, "text": "add eax, ebx\njno @@1\nor eax, 0FFFFFFFFh\n@@1:\n.......\n" }, { "answer_id": 121323, "author": "Nils Pipenbrinck", "author_id": 15955, "author_profile": "https://Stackoverflow.com/users/15955", "pm_score": 4, "selected": false, "text": "uint32_t SatAddUnsigned8(uint32_t x, uint32_t y) \n{\n uint32_t signmask = 0x80808080;\n uint32_t t0 = (y ^ x) & signmask;\n uint32_t t1 = (y & x) & signmask;\n x &= ~signmask;\n y &= ~signmask;\n x += y;\n t1 |= t0 & x;\n t1 = (t1 << 1) - (t1 >> 7);\n return (x ^ t0) | t1;\n}\n" }, { "answer_id": 121355, "author": "Skizz", "author_id": 1898, "author_profile": "https://Stackoverflow.com/users/1898", "pm_score": 4, "selected": false, "text": "uint32_t sadd32(uint32_t a, uint32_t b)\n{\n#if defined IA32\n __asm\n {\n mov eax,a\n xor edx,edx\n add eax,b\n setnc dl\n dec edx\n or eax,edx\n }\n#elif defined ARM\n // ARM code\n#else\n // non-IA32/ARM way, copy from above\n#endif\n}\n" }, { "answer_id": 121801, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 2, "selected": false, "text": "\nuint32_t sadd32(uint32_t a, uint32_t b)\n{\n __asm\n {\n movl eax, a\n addl eax, b\n movl edx, 0xffffffff\n cmovc eax, edx\n }\n}\n" }, { "answer_id": 122288, "author": "Remo.D", "author_id": 16827, "author_profile": "https://Stackoverflow.com/users/16827", "pm_score": 5, "selected": false, "text": "uint16_t sadd16(uint16_t a, uint16_t b) {\n return (a > 0xFFFF - b) ? 0xFFFF : a + b;\n}\n \nuint32_t sadd32(uint32_t a, uint32_t b) {\n return (a > 0xFFFFFFFF - b) ? 0xFFFFFFFF : a + b;\n}\n" }, { "answer_id": 122346, "author": "Dark Shikari", "author_id": 11206, "author_profile": "https://Stackoverflow.com/users/11206", "pm_score": 3, "selected": false, "text": "sub8x8_dct8_c: 1332 clocks\nsub8x8_dct8_mmx: 182 clocks\nsub8x8_dct8_sse2: 127 clocks\n" }, { "answer_id": 124709, "author": "Kevin", "author_id": 6386, "author_profile": "https://Stackoverflow.com/users/6386", "pm_score": 2, "selected": false, "text": "unsigned saturate_add_uint(unsigned x, unsigned y)\n{\n if (y > UINT_MAX - x) return UINT_MAX;\n return x + y;\n}\n\nunsigned short saturate_add_ushort(unsigned short x, unsigned short y)\n{\n if (y > USHRT_MAX - x) return USHRT_MAX;\n return x + y;\n}\n" }, { "answer_id": 166393, "author": "MSalters", "author_id": 15416, "author_profile": "https://Stackoverflow.com/users/15416", "pm_score": 6, "selected": true, "text": "uint16_t add16(uint16_t a, uint16_t b)\n{\n uint16_t c = a + b;\n if (c < a) /* Can only happen due to overflow */\n c = -1;\n return c;\n}\n" }, { "answer_id": 3431717, "author": "R.. GitHub STOP HELPING ICE", "author_id": 379897, "author_profile": "https://Stackoverflow.com/users/379897", "pm_score": 3, "selected": false, "text": "uint32_t sadd32(uint32_t a, uint32_t b)\n{\n uint64_t s = (uint64_t)a+b;\n return -(s>>32) | (uint32_t)s;\n}\n" }, { "answer_id": 24263421, "author": "0xbadf00d", "author_id": 547231, "author_profile": "https://Stackoverflow.com/users/547231", "pm_score": 0, "selected": false, "text": "template<typename T>\nT sadd(T first, T second)\n{\n static_assert(std::is_integral<T>::value, \"sadd is not defined for non-integral types\");\n return first > std::numeric_limits<T>::max() - second ? std::numeric_limits<T>::max() : first + second;\n}\n" }, { "answer_id": 28074266, "author": "Ian Rogers", "author_id": 4479555, "author_profile": "https://Stackoverflow.com/users/4479555", "pm_score": 1, "selected": false, "text": "add %eax,%ebx\nsbb $0,%ebx\n" }, { "answer_id": 32883349, "author": "Hannodje", "author_id": 5396658, "author_profile": "https://Stackoverflow.com/users/5396658", "pm_score": 2, "selected": false, "text": "int32_t sadd(int32_t a, int32_t b){\n int32_t sum = a+b;\n int32_t overflow = ((a^sum)&(b^sum))>>31;\n return (overflow<<31)^(sum>>overflow);\n }\n" }, { "answer_id": 35877883, "author": "twostickes", "author_id": 6036406, "author_profile": "https://Stackoverflow.com/users/6036406", "pm_score": 0, "selected": false, "text": "//function-like macro to add signed vals, \n//then test for overlow and clamp to max if required\n#define SATURATE_ADD(a,b,val) ( {\\\nif( (a>=0) && (b>=0) )\\\n{\\\n val = a + b;\\\n if (val < 0) {val=0x7fffffff;}\\\n}\\\nelse if( (a<=0) && (b<=0) )\\\n{\\\n val = a + b;\\\n if (val > 0) {val=-1*0x7fffffff;}\\\n}\\\nelse\\\n{\\\n val = a + b;\\\n}\\\n})\n" }, { "answer_id": 46358478, "author": "Shangchih Huang", "author_id": 7537655, "author_profile": "https://Stackoverflow.com/users/7537655", "pm_score": 1, "selected": false, "text": "int saturating_add(int x, int y)\n{\n int w = sizeof(int) << 3;\n int msb = 1 << (w-1);\n\n int s = x + y;\n int sign_x = msb & x;\n int sign_y = msb & y;\n int sign_s = msb & s;\n\n int nflow = sign_x && sign_y && !sign_s;\n int pflow = !sign_x && !sign_y && sign_s;\n\n int nmask = (~!nflow + 1);\n int pmask = (~!pflow + 1);\n\n return (nmask & ((pmask & s) | (~pmask & ~msb))) | (~nmask & msb);\n}\n" }, { "answer_id": 52411672, "author": "Alexei Shcherbakov", "author_id": 7815105, "author_profile": "https://Stackoverflow.com/users/7815105", "pm_score": 0, "selected": false, "text": "#ifdef" }, { "answer_id": 70403351, "author": "Arty", "author_id": 941531, "author_profile": "https://Stackoverflow.com/users/941531", "pm_score": 0, "selected": false, "text": "uint32_t" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8964/" ]
121,243
<p>What are some hidden features of <a href="http://en.wikipedia.org/wiki/Microsoft_SQL_Server" rel="nofollow noreferrer">SQL Server</a>?</p> <p>For example, undocumented system stored procedures, tricks to do things which are very useful but not documented enough?</p> <hr> <h2>Answers</h2> <p><em>Thanks to everybody for all the great answers!</em></p> <p><strong>Stored Procedures</strong></p> <ul> <li><strong>sp_msforeachtable:</strong> Runs a command with '?' replaced with each table name (v6.5 and up)</li> <li><strong>sp_msforeachdb:</strong> Runs a command with '?' replaced with each database name (v7 and up)</li> <li><strong>sp_who2:</strong> just like sp_who, but with a lot more info for troubleshooting blocks (v7 and up)</li> <li><strong>sp_helptext:</strong> If you want the code of a stored procedure, view &amp; UDF</li> <li><strong>sp_tables:</strong> return a list of all tables and views of database in scope.</li> <li><strong>sp_stored_procedures:</strong> return a list of all stored procedures</li> <li><strong>xp_sscanf:</strong> Reads data from the string into the argument locations specified by each format argument.</li> <li><strong>xp_fixeddrives:</strong>: Find the fixed drive with largest free space</li> <li><strong>sp_help:</strong> If you want to know the table structure, indexes and constraints of a table. Also views and UDFs. Shortcut is Alt+F1</li> </ul> <p><strong>Snippets</strong></p> <ul> <li>Returning rows in random order</li> <li>All database User Objects by Last Modified Date</li> <li>Return Date Only</li> <li>Find records which date falls somewhere inside the current week.</li> <li>Find records which date occurred last week.</li> <li>Returns the date for the beginning of the current week.</li> <li>Returns the date for the beginning of last week.</li> <li>See the text of a procedure that has been deployed to a server</li> <li>Drop all connections to the database</li> <li>Table Checksum</li> <li>Row Checksum</li> <li>Drop all the procedures in a database</li> <li>Re-map the login Ids correctly after restore</li> <li>Call Stored Procedures from an INSERT statement</li> <li>Find Procedures By Keyword</li> <li>Drop all the procedures in a database</li> <li>Query the transaction log for a database programmatically.</li> </ul> <p><strong>Functions</strong></p> <ul> <li>HashBytes()</li> <li>EncryptByKey</li> <li>PIVOT command</li> </ul> <p><strong>Misc</strong></p> <ul> <li>Connection String extras</li> <li>TableDiff.exe</li> <li>Triggers for Logon Events (New in Service Pack 2)</li> <li>Boosting performance with persisted-computed-columns (pcc).</li> <li>DEFAULT_SCHEMA setting in sys.database_principles</li> <li>Forced Parameterization</li> <li>Vardecimal Storage Format</li> <li>Figuring out the most popular queries in seconds</li> <li>Scalable Shared Databases</li> <li>Table/Stored Procedure Filter feature in SQL Management Studio</li> <li>Trace flags</li> <li>Number after a <code>GO</code> repeats the batch</li> <li>Security using schemas</li> <li>Encryption using built in encryption functions, views and base tables with triggers</li> </ul>
[ { "answer_id": 121275, "author": "Sklivvz", "author_id": 7028, "author_profile": "https://Stackoverflow.com/users/7028", "pm_score": 3, "selected": false, "text": "sp_tables\n" }, { "answer_id": 121496, "author": "Sklivvz", "author_id": 7028, "author_profile": "https://Stackoverflow.com/users/7028", "pm_score": 3, "selected": false, "text": "DECLARE @filename varchar (20), @message varchar (20)\nEXEC xp_sscanf 'sync -b -fproducts10.tmp -rrandom', 'sync -b -f%s -r%s', \n @filename OUTPUT, @message OUTPUT\nSELECT @filename, @message\n" }, { "answer_id": 121613, "author": "ICW", "author_id": 17664, "author_profile": "https://Stackoverflow.com/users/17664", "pm_score": 3, "selected": false, "text": "EXEC master..xp_fixeddrives\n" }, { "answer_id": 121618, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 6, "selected": false, "text": "sp_msforeachtable" }, { "answer_id": 121634, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 5, "selected": false, "text": "-- Return rows in a random order\nSELECT \n SomeColumn \nFROM \n SomeTable\nORDER BY \n CHECKSUM(NEWID())\n" }, { "answer_id": 121791, "author": "Gordon Bell", "author_id": 16473, "author_profile": "https://Stackoverflow.com/users/16473", "pm_score": 3, "selected": false, "text": "select name, modify_date, \ncase when type_desc = 'USER_TABLE' then 'Table'\nwhen type_desc = 'SQL_STORED_PROCEDURE' then 'Stored Procedure'\nwhen type_desc in ('SQL_INLINE_TABLE_VALUED_FUNCTION', 'SQL_SCALAR_FUNCTION', 'SQL_TABLE_VALUED_FUNCTION') then 'Function'\nend as type_desc\nfrom sys.objects\nwhere type in ('U', 'P', 'FN', 'IF', 'TF')\nand is_ms_shipped = 0\norder by 2 desc\n" }, { "answer_id": 121915, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 3, "selected": false, "text": "Select Cast(Floor(Cast(Getdate() As Float))As Datetime)\n" }, { "answer_id": 121924, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 3, "selected": false, "text": "where dateadd( week, datediff( week, 0, TransDate ), 0 ) =\ndateadd( week, datediff( week, 0, getdate() ), 0 )\n" }, { "answer_id": 121927, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 4, "selected": false, "text": "Use Master\nGo\n\nDeclare @dbname sysname\n\nSet @dbname = 'name of database you want to drop connections from'\n\nDeclare @spid int\nSelect @spid = min(spid) from master.dbo.sysprocesses\nwhere dbid = db_id(@dbname)\nWhile @spid Is Not Null\nBegin\n Execute ('Kill ' + @spid)\n Select @spid = min(spid) from master.dbo.sysprocesses\n where dbid = db_id(@dbname) and spid > @spid\nEnd\n" }, { "answer_id": 121933, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 4, "selected": false, "text": "Select CheckSum_Agg(Binary_CheckSum(*)) From Table With (NOLOCK)\n" }, { "answer_id": 121995, "author": "Christopher Klein", "author_id": 17632, "author_profile": "https://Stackoverflow.com/users/17632", "pm_score": 0, "selected": false, "text": "select * from sys.dm_os_performance_counters\n\nselect * from sys.dm_exec_requests\n" }, { "answer_id": 122218, "author": "cheeves", "author_id": 15826, "author_profile": "https://Stackoverflow.com/users/15826", "pm_score": 2, "selected": false, "text": "DECLARE @procedureName NVARCHAR( MAX ), @procedureText NVARCHAR( MAX )\n\nSET @procedureName = 'myproc_Proc1'\n\nSET @procedureText = (\n SELECT OBJECT_DEFINITION( object_id )\n FROM sys.procedures \n WHERE Name = @procedureName\n )\n\nPRINT @procedureText\n" }, { "answer_id": 122233, "author": "cheeves", "author_id": 15826, "author_profile": "https://Stackoverflow.com/users/15826", "pm_score": 1, "selected": false, "text": "SELECT IDENTITY ( int, 1, 1 ) id, \n [name] \nINTO #tmp \nFROM sys.procedures \nWHERE [type] = 'P' \n AND is_ms_shipped = 0 \n\nDECLARE @i INT \n\nSELECT @i = COUNT( id ) FROM #tmp \nWHILE @i > 0 \nBEGIN \n DECLARE @name VARCHAR( 100 ) \n SELECT @name = name FROM #tmp WHERE id = @i \n EXEC ( 'DROP PROCEDURE ' + @name ) \n SET @i = @i-1 \nEND\n\nDROP TABLE #tmp\n" }, { "answer_id": 122280, "author": "Eduardo Molteni", "author_id": 2385, "author_profile": "https://Stackoverflow.com/users/2385", "pm_score": 4, "selected": false, "text": "sp_helptext 'ProcedureName'\n" }, { "answer_id": 122612, "author": "Kolten", "author_id": 13959, "author_profile": "https://Stackoverflow.com/users/13959", "pm_score": 4, "selected": false, "text": "EXEC sp_change_users_login 'Auto_Fix', 'Mary', NULL, 'B3r12-36'\n" }, { "answer_id": 138366, "author": "edomaur", "author_id": 14262, "author_profile": "https://Stackoverflow.com/users/14262", "pm_score": 4, "selected": false, "text": "CREATE TABLE #toto (v1 int, v2 int, v3 char(4), status char(6))\nINSERT #toto (v1, v2, v3, status) EXEC dbo.sp_fulubulu(sp_param1)\nSELECT * FROM #toto\nDROP TABLE #toto\n" }, { "answer_id": 140015, "author": "Eduardo Molteni", "author_id": 2385, "author_profile": "https://Stackoverflow.com/users/2385", "pm_score": 5, "selected": false, "text": "sp_help 'TableName'\n" }, { "answer_id": 140753, "author": "Ollie", "author_id": 4453, "author_profile": "https://Stackoverflow.com/users/4453", "pm_score": 0, "selected": false, "text": "CAST(CONVERT(varchar,getdate(),103) as datetime)\n" }, { "answer_id": 141065, "author": "GilM", "author_id": 10192, "author_profile": "https://Stackoverflow.com/users/10192", "pm_score": 7, "selected": false, "text": "PRINT 'X'\nGO 10\n" }, { "answer_id": 149665, "author": "Sklivvz", "author_id": 7028, "author_profile": "https://Stackoverflow.com/users/7028", "pm_score": 4, "selected": false, "text": "select * from sys.dm_exec_query_stats \norder by execution_count desc\n" }, { "answer_id": 159835, "author": "Meff", "author_id": 9647, "author_profile": "https://Stackoverflow.com/users/9647", "pm_score": 2, "selected": false, "text": "SELECT OBJECT_NAME(ID) FROM SysComments \nWHERE Text LIKE '%SearchString%' \nAND OBJECTPROPERTY(id, 'IsProcedure') = 1\n" }, { "answer_id": 207184, "author": "Chris Roland", "author_id": 27975, "author_profile": "https://Stackoverflow.com/users/27975", "pm_score": 2, "selected": false, "text": "USE mydatabase;\nSELECT *\nFROM ::fn_dblog(NULL, NULL)\n" }, { "answer_id": 232772, "author": "MarlonRibunal", "author_id": 10385, "author_profile": "https://Stackoverflow.com/users/10385", "pm_score": 0, "selected": false, "text": "SELECT T.NAME AS [TABLE NAME], C.NAME AS [COLUMN NAME], P.NAME AS [DATA TYPE], P.MAX_LENGTH AS[SIZE], CAST(P.PRECISION AS VARCHAR) +‘/’+ CAST(P.SCALE AS VARCHAR) AS [PRECISION/SCALE]\nFROM ADVENTUREWORKS.SYS.OBJECTS AS T\nJOIN ADVENTUREWORKS.SYS.COLUMNS AS C\nON T.OBJECT_ID=C.OBJECT_ID\nJOIN ADVENTUREWORKS.SYS.TYPES AS P\nON C.SYSTEM_TYPE_ID=P.SYSTEM_TYPE_ID\nWHERE T.TYPE_DESC=‘USER_TABLE’;\n" }, { "answer_id": 234226, "author": "Eduardo Molteni", "author_id": 2385, "author_profile": "https://Stackoverflow.com/users/2385", "pm_score": 2, "selected": false, "text": "sp_executesql \n" }, { "answer_id": 262870, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "sp_depends" }, { "answer_id": 318659, "author": "Logicalmind", "author_id": 26977, "author_profile": "https://Stackoverflow.com/users/26977", "pm_score": 0, "selected": false, "text": "exec sp_configure 'show advanced options', 1;\nreconfigure;\ngo\nexec sp_configure 'blocked process threshold', 30;\nreconfigure; \n" }, { "answer_id": 321159, "author": "NotMe", "author_id": 2424, "author_profile": "https://Stackoverflow.com/users/2424", "pm_score": 3, "selected": false, "text": "declare @orderby varchar(10)\n\nset @orderby = 'NAME'\n\nselect * \n from Users\n ORDER BY \n CASE @orderby\n WHEN 'NAME' THEN LastName\n WHEN 'EMAIL' THEN EmailAddress\n END\n" }, { "answer_id": 532766, "author": "Binoj Antony", "author_id": 33015, "author_profile": "https://Stackoverflow.com/users/33015", "pm_score": 4, "selected": false, "text": "SELECT ( ROW_NUMBER() OVER (ORDER BY OrderId) ) AS RowNumber,\n GrandTotal, CustomerId, PurchaseDate\nFROM Orders\n" }, { "answer_id": 542907, "author": "Yordan Georgiev", "author_id": 65706, "author_profile": "https://Stackoverflow.com/users/65706", "pm_score": 0, "selected": false, "text": "use db\ngo \nDECLARE @procName varchar(100) \nDECLARE @cursorProcNames CURSOR \nSET @cursorProcNames = CURSOR FOR \nselect name from sys.procedures where modify_date > '2009-02-05 13:12:15.273' order by modify_date desc \n\nOPEN @cursorProcNames \nFETCH NEXT \nFROM @cursorProcNames INTO @procName \nWHILE @@FETCH_STATUS = 0 \nBEGIN \n-- see the text of the last stored procedures modified on \n-- the db , hint Ctrl + T would give you the procedures test \nset nocount off; \nexec sp_HelpText @procName --- or print them \n-- print @procName \n\nFETCH NEXT \nFROM @cursorProcNames INTO @procName \nEND \nCLOSE @cursorProcNames \n\nselect @@error \n" }, { "answer_id": 543052, "author": "Yordan Georgiev", "author_id": 65706, "author_profile": "https://Stackoverflow.com/users/65706", "pm_score": 0, "selected": false, "text": "use db\ngo \n\nselect o.name \n, (SELECT [definition] AS [text()] \n FROM sys.all_sql_modules \n WHERE sys.all_sql_modules.object_id=a.object_id \n FOR XML PATH(''), TYPE\n ) AS Statement_Text\n , a.object_id\n , o.modify_date \n\n FROM sys.all_sql_modules a \n LEFT JOIN sys.objects o ON a.object_id=o.object_id \n ORDER BY 4 desc\n\n--select * from sys.objects\n" }, { "answer_id": 894283, "author": "Sheki", "author_id": 107959, "author_profile": "https://Stackoverflow.com/users/107959", "pm_score": 4, "selected": false, "text": "DECLARE @nvcConcatonated nvarchar(max)\nSET @nvcConcatonated = ''\n\nSELECT @nvcConcatonated = @nvcConcatonated + C.CompanyName + ', '\nFROM tblCompany C\nWHERE C.CompanyID IN (1,2,3)\n\nSELECT @nvcConcatonated\n" }, { "answer_id": 894304, "author": "Sheki", "author_id": 107959, "author_profile": "https://Stackoverflow.com/users/107959", "pm_score": 0, "selected": false, "text": "DECLARE @nvcIDs nvarchar(max)\nSET @nvcIDs = '|1|2|3|'\n\nSELECT C.*\nFROM tblCompany C\nWHERE @nvcIDs LIKE '%|' + CAST(C.CompanyID as nvarchar) + '|%' \n" }, { "answer_id": 926216, "author": "Duncan Smart", "author_id": 1278, "author_profile": "https://Stackoverflow.com/users/1278", "pm_score": 1, "selected": false, "text": "INSERT INTO someTable EXEC sp_someproc\n" }, { "answer_id": 1063685, "author": "Jhonny D. Cano -Leftware-", "author_id": 76832, "author_profile": "https://Stackoverflow.com/users/76832", "pm_score": 0, "selected": false, "text": "CREATE procedure sp_who3\n @loginame sysname = NULL --or 'active' or 'lock'\nas\n\ndeclare @spidlow int,\n @spidhigh int,\n @spid int,\n @sid varbinary(85)\n\nselect @spidlow = 0\n ,@spidhigh = 32767\n\n\nif @loginame is not NULL begin\n if upper(@loginame) = 'ACTIVE' begin\n select spid, ecid, status\n , loginame=rtrim(loginame)\n , hostname=rtrim(hostname)\n , blk=convert(char(5),blocked)\n , dbname = case\n when dbid = 0 then null\n when dbid <> 0 then db_name(dbid)\n end\n ,cmd\n from master.dbo.sysprocesses\n where spid >= @spidlow and spid <= @spidhigh AND\n upper(cmd) <> 'AWAITING COMMAND'\n return (0)\n end\n if upper(@loginame) = 'LOCK' begin\n select spid , ecid, status\n , loginame=rtrim(loginame)\n , hostname=rtrim(hostname)\n , blk=convert(char(5),blocked)\n , dbname = case\n when dbid = 0 then null\n when dbid <> 0 then db_name(dbid)\n end\n ,cmd\n from master.dbo.sysprocesses\n where spid >= 0 and spid <= 32767 AND\n upper(cmd) <> 'AWAITING COMMAND'\n AND convert(char(5),blocked) > 0\n return (0)\n end\n\nend\n\nif (@loginame is not NULL\n AND upper(@loginame) <> 'ACTIVE'\n )\nbegin\n if (@loginame like '[0-9]%') -- is a spid.\n begin\n select @spid = convert(int, @loginame)\n select spid, ecid, status\n , loginame=rtrim(loginame)\n , hostname=rtrim(hostname)\n , blk=convert(char(5),blocked)\n , dbname = case\n when dbid = 0 then null\n when dbid <> 0 then db_name(dbid)\n end\n ,cmd\n from master.dbo.sysprocesses\n where spid = @spid\n end\n else\n begin\n select @sid = suser_sid(@loginame)\n if (@sid is null)\n begin\n raiserror(15007,-1,-1,@loginame)\n return (1)\n end\n select spid, ecid, status\n , loginame=rtrim(loginame)\n , hostname=rtrim(hostname)\n , blk=convert(char(5),blocked)\n , dbname = case\n when dbid = 0 then null\n when dbid <> 0 then db_name(dbid)\n end\n ,cmd\n from master.dbo.sysprocesses\n where sid = @sid\n end\n return (0)\nend\n\n\n/* loginame arg is null */\nselect spid,\n ecid,\n status\n , loginame=rtrim(loginame)\n , hostname=rtrim(hostname)\n , blk=convert(char(5),blocked)\n , dbname = case\n when dbid = 0 then null\n when dbid <> 0 then db_name(dbid)\n end\n ,cmd\nfrom master.dbo.sysprocesses\nwhere spid >= @spidlow and spid <= @spidhigh\n\n\nreturn (0) -- sp_who\n" }, { "answer_id": 1065869, "author": "penderi", "author_id": 32027, "author_profile": "https://Stackoverflow.com/users/32027", "pm_score": 2, "selected": false, "text": "Alt+F1" }, { "answer_id": 1243721, "author": "marc_s", "author_id": 13302, "author_profile": "https://Stackoverflow.com/users/13302", "pm_score": 6, "selected": false, "text": "inserted" }, { "answer_id": 1928481, "author": "Brian", "author_id": 18192, "author_profile": "https://Stackoverflow.com/users/18192", "pm_score": 2, "selected": false, "text": "DBCC DROPCLEANBUFFERS" }, { "answer_id": 1930277, "author": "Rob Boek", "author_id": 27179, "author_profile": "https://Stackoverflow.com/users/27179", "pm_score": 5, "selected": false, "text": "INSERT INTO Colors (id, Color)\nVALUES (1, 'Red'),\n (2, 'Blue'),\n (3, 'Green'),\n (4, 'Yellow')\n" }, { "answer_id": 3278967, "author": "Michhes", "author_id": 119073, "author_profile": "https://Stackoverflow.com/users/119073", "pm_score": 0, "selected": false, "text": "ALTER USER wacom_app WITH LOGIN = wacom_app\n" }, { "answer_id": 3291170, "author": "Sir Wobin", "author_id": 375187, "author_profile": "https://Stackoverflow.com/users/375187", "pm_score": 2, "selected": false, "text": "create table #deps\n( oType int,\n oObjName sysname,\n oOwner nvarchar(200),\n oSequence int\n)\n\ninsert into #deps \nexec sp_MSdependencies @tableName, null, 1315327\n\nexec sp_MSforeachtable @command1 = 'ALTER TABLE ? NOCHECK CONSTRAINT ALL',\n@whereand = ' and o.name in (select oObjName from #deps where oType = 8)'\n" }, { "answer_id": 3601926, "author": "Nathan Koop", "author_id": 18821, "author_profile": "https://Stackoverflow.com/users/18821", "pm_score": 3, "selected": false, "text": "SELECT OBJECT_NAME(OBJECT_ID) AS DatabaseName, last_user_update,*\nFROM sys.dm_db_index_usage_stats\nWHERE database_id = DB_ID( 'MyDatabase')\nAND OBJECT_ID=OBJECT_ID('MyTable')\n" }, { "answer_id": 3646602, "author": "Denis Valeev", "author_id": 124681, "author_profile": "https://Stackoverflow.com/users/124681", "pm_score": 3, "selected": false, "text": "select row_number() over (order by (select 1)), * from dbo.Table as t\n" }, { "answer_id": 6700081, "author": "MikeM", "author_id": 222714, "author_profile": "https://Stackoverflow.com/users/222714", "pm_score": 2, "selected": false, "text": "GETDATE()" }, { "answer_id": 8070773, "author": "Steve", "author_id": 634027, "author_profile": "https://Stackoverflow.com/users/634027", "pm_score": 0, "selected": false, "text": "SELECT \n Project.ProjectName,\n (SELECT\n SUBSTRING(\n (SELECT ', ' + Site.SiteName\n FROM Site\n WHERE Site.ProjectKey = Project.ProjectKey\n ORDER BY Project.ProjectName\n FOR XML PATH('')),2,200000)) AS CSV \nFROM Project\n" }, { "answer_id": 8216370, "author": "viniciushana", "author_id": 333687, "author_profile": "https://Stackoverflow.com/users/333687", "pm_score": 0, "selected": false, "text": "sp_who" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7028/" ]
121,253
<p>I'm having a strange problem in Visual Studio 2008 where my "Pending Checkins" window never updates. I open it up, and it says "Updating..." like usual, but I never see the "X remaining" message, and nothing happens. It just sits there doing nothing.</p> <p>Checked-out stuff still shows as checked out in Solution Explorer. SourceSafe 2005 still works like normal.</p> <p>Any ideas?</p>
[ { "answer_id": 192168, "author": "Ryan Lundy", "author_id": 5486, "author_profile": "https://Stackoverflow.com/users/5486", "pm_score": 4, "selected": true, "text": "GlobalSection(SourceCodeControl) = preSolution\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5486/" ]
121,266
<p>I'm currently looking for ways to create automated tests for a <a href="https://jsr311.dev.java.net/" rel="noreferrer">JAX-RS</a> (Java API for RESTful Web Services) based web service. </p> <p>I basically need a way to send it certain inputs and verify that I get the expected responses. I'd prefer to do this via JUnit, but I'm not sure how that can be achieved.</p> <p>What approach do you use to test your web-services?</p> <p><strong>Update:</strong> As entzik pointed out, decoupling the web service from the business logic allows me to unit test the business logic. However, I also want to test for the correct HTTP status codes etc.</p>
[ { "answer_id": 28726499, "author": "Fırat Küçük", "author_id": 159837, "author_profile": "https://Stackoverflow.com/users/159837", "pm_score": 4, "selected": false, "text": "mvn test" }, { "answer_id": 31744302, "author": "Alexandr", "author_id": 511804, "author_profile": "https://Stackoverflow.com/users/511804", "pm_score": 1, "selected": false, "text": "import javax.inject.Inject;\nimport javax.ws.rs.GET;\nimport javax.ws.rs.Path;\n\nimport com.brandmaker.skinning.service.SomeBean;\n\n/**\n* Created by alexandr on 31.07.15.\n*/\n@Path(\"/entities\")\npublic class RestBean\n{\n @Inject\n SomeBean bean;\n\n @GET\n public String getEntiry()\n {\n return bean.methodToBeMoked();\n }\n}\n\nimport java.util.Set;\n\nimport javax.ws.rs.ApplicationPath;\nimport javax.ws.rs.core.Application;\n\nimport com.google.common.collect.Sets;\n\n/**\n*/\n@ApplicationPath(\"res\")\npublic class JAXRSConfiguration extends Application\n{\n @Override\n public Set<Class<?>> getClasses()\n {\n return Sets.newHashSet(RestBean.class);\n }\n}\n\n\npublic class SomeBean\n{\n public String methodToBeMoked()\n {\n return \"Original\";\n }\n}\n\nimport javax.enterprise.inject.Specializes;\n\nimport com.brandmaker.skinning.service.SomeBean;\n\n/**\n*/\n@Specializes\npublic class SomeBeanMock extends SomeBean\n{\n @Override\n public String methodToBeMoked()\n {\n return \"Mocked\";\n }\n}\n\n@RunWith(Arquillian.class)\npublic class RestBeanTest\n{\n @Deployment\n public static WebArchive createDeployment() {\n WebArchive war = ShrinkWrap.create(WebArchive.class, \"test.war\")\n .addClasses(JAXRSConfiguration.class, RestBean.class, SomeBean.class, SomeBeanMock.class)\n .addAsWebInfResource(EmptyAsset.INSTANCE, \"beans.xml\");\n System.out.println(war.toString(true));\n return war;\n }\n\n @Test\n public void should_create_greeting() {\n Client client = ClientBuilder.newClient();\n WebTarget target = client.target(\"http://127.0.0.1:8181/test/res/entities\");\n //Building the request i.e a GET request to the RESTful Webservice defined\n //by the URI in the WebTarget instance.\n Invocation invocation = target.request().buildGet();\n //Invoking the request to the RESTful API and capturing the Response.\n Response response = invocation.invoke();\n //As we know that this RESTful Webserivce returns the XML data which can be unmarshalled\n //into the instance of Books by using JAXB.\n Assert.assertEquals(\"Mocked\", response.readEntity(String.class));\n }\n}\n" }, { "answer_id": 35056404, "author": "keyoxy", "author_id": 957280, "author_profile": "https://Stackoverflow.com/users/957280", "pm_score": 2, "selected": false, "text": " <dependency>\n <groupId>org.valid4j</groupId>\n <artifactId>http-matchers</artifactId>\n <version>1.0</version>\n </dependency>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121266", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2964/" ]
121,274
<p>How would I go about binding the following object, Car, to a gridview?</p> <pre> public class Car { long Id {get; set;} Manufacturer Maker {get; set;} } public class Manufacturer { long Id {get; set;} String Name {get; set;} } </pre> <p>The primitive types get bound easy but I have found no way of displaying anything for Maker. I would like for it to display the Manufacturer.Name. Is it even possible? </p> <p>What would be a way to do it? Would I have to store ManufacturerId in Car as well and then setup an lookupEditRepository with list of Manufacturers?</p>
[ { "answer_id": 121328, "author": "hollystyles", "author_id": 2083160, "author_profile": "https://Stackoverflow.com/users/2083160", "pm_score": 3, "selected": false, "text": " public class Manufacturer\n {\n long Id {get; set;}\n String Name {get; set;}\n\n public override string ToString()\n {\n return Name;\n }\n }\n" }, { "answer_id": 121359, "author": "Seb Nilsson", "author_id": 2429, "author_profile": "https://Stackoverflow.com/users/2429", "pm_score": 2, "selected": false, "text": "dataGrid.DataSource = carList;\ndataGrid.DataMember = \"Maker.Name\";\ndataGrid.DataKeyField = \"ID\";\ndataGrid.DataBind();\n" }, { "answer_id": 128909, "author": "ManiacZX", "author_id": 18148, "author_profile": "https://Stackoverflow.com/users/18148", "pm_score": 3, "selected": false, "text": "public class CarCell : System.Windows.Forms.DataGridViewTextBoxCell\n{\n protected override object GetValue(int rowIndex)\n {\n Car car = base.GetValue(rowIndex) as Car;\n if (car != null)\n {\n return car.Maker.Name;\n }\n else\n {\n return \"\";\n }\n }\n}\n" }, { "answer_id": 155861, "author": "Seth Petry-Johnson", "author_id": 23632, "author_profile": "https://Stackoverflow.com/users/23632", "pm_score": 2, "selected": false, "text": "public class ManufacturerField : BoundField\n{\n protected override string FormatDataValue(object dataValue, bool encode)\n {\n var mfr = dataValue as Manufacturer;\n\n if (mfr != null)\n {\n return mfr.Name + \" (ID \" + mfr.Id + \")\";\n }\n else\n {\n return base.FormatDataValue(dataValue, encode);\n }\n }\n}\n" }, { "answer_id": 940477, "author": "Ryan Spears", "author_id": 11948, "author_profile": "https://Stackoverflow.com/users/11948", "pm_score": 1, "selected": false, "text": "public class Car\n{\n public long Id {get; set;}\n public Manufacturer Maker {private get; set;}\n\n public string ManufacturerName\n {\n get { return Maker != null ? Maker.Name : \"\"; }\n }\n}\n\npublic class Manufacturer\n{\n long Id {get; set;}\n String Name {get; set;}\n}\n" }, { "answer_id": 5250423, "author": "n8wrl", "author_id": 37710, "author_profile": "https://Stackoverflow.com/users/37710", "pm_score": 2, "selected": false, "text": "<asp:TemplateColumn\n HeaderText=\"Maker\">\n <ItemTemplate>\n <%#Eval(\"Maker.Name\")%>\n </ItemTemplate>\n</asp:TemplateColumn>\n" }, { "answer_id": 10567944, "author": "Gad", "author_id": 25152, "author_profile": "https://Stackoverflow.com/users/25152", "pm_score": 5, "selected": false, "text": " private void Grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)\n {\n\n DataGridView grid = (DataGridView)sender;\n DataGridViewRow row = grid.Rows[e.RowIndex];\n DataGridViewColumn col = grid.Columns[e.ColumnIndex];\n if (row.DataBoundItem != null && col.DataPropertyName.Contains(\".\"))\n {\n string[] props = col.DataPropertyName.Split('.');\n PropertyInfo propInfo = row.DataBoundItem.GetType().GetProperty(props[0]);\n object val = propInfo.GetValue(row.DataBoundItem, null);\n for (int i = 1; i < props.Length; i++)\n {\n propInfo = val.GetType().GetProperty(props[i]);\n val = propInfo.GetValue(val, null);\n }\n e.Value = val;\n }\n }\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121274", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15771/" ]
121,280
<p>How do I detect what browser (IE, Firefox, Opera) the user is accessing my site with? Examples in Javascript, PHP, ASP, Python, JSP, and any others you can think of would be helpful. Is there a language agnostic way to get this information?</p>
[ { "answer_id": 121319, "author": "Midhat", "author_id": 9425, "author_profile": "https://Stackoverflow.com/users/9425", "pm_score": 2, "selected": false, "text": "private String getBrowserName(HttpServletRequest request) {\n // get the user Agent from request header\n String userAgent = request.getHeader(Constants.BROWSER_USER_AGENT);\n String BrowesrName = \"\";\n //check for Internet Explorer\n if (userAgent.indexOf(\"MSIE\") > -1) {\n BrowesrName = Constants.BROWSER_NAME_IE;\n } else if (userAgent.indexOf(Constants.BROWSER_NAME_FIREFOX) > -1) {\n BrowesrName = Constants.BROWSER_NAME_MOZILLA_FIREFOX;\n } else if (userAgent.indexOf(Constants.BROWSER_NAME_OPERA) > -1) {\n BrowesrName = Constants.BROWSER_NAME_OPERA;\n } else if (userAgent.indexOf(Constants.BROWSER_NAME_SAFARI) > -1) {\n BrowesrName = Constants.BROWSER_NAME_SAFARI;\n } else if (userAgent.indexOf(Constants.BROWSER_NAME_NETSCAPE) > -1) {\n BrowesrName = Constants.BROWSER_NAME_NETSCAPE;\n } else {\n BrowesrName = \"Undefined Browser\";\n }\n //return the browser name\n return BrowesrName;\n}\n" }, { "answer_id": 121334, "author": "Erikk Ross", "author_id": 18772, "author_profile": "https://Stackoverflow.com/users/18772", "pm_score": 1, "selected": false, "text": "private void Button1_Click(object sender, System.EventArgs e)\n{\n HttpBrowserCapabilities bc;\n string s;\n bc = Request.Browser;\n s= \"Browser Capabilities\" + \"\\n\";\n s += \"Type = \" + bc.Type + \"\\n\";\n s += \"Name = \" + bc.Browser + \"\\n\";\n s += \"Version = \" + bc.Version + \"\\n\";\n s += \"Major Version = \" + bc.MajorVersion + \"\\n\";\n s += \"Minor Version = \" + bc.MinorVersion + \"\\n\";\n s += \"Platform = \" + bc.Platform + \"\\n\";\n s += \"Is Beta = \" + bc.Beta + \"\\n\";\n s += \"Is Crawler = \" + bc.Crawler + \"\\n\";\n s += \"Is AOL = \" + bc.AOL + \"\\n\";\n s += \"Is Win16 = \" + bc.Win16 + \"\\n\";\n s += \"Is Win32 = \" + bc.Win32 + \"\\n\";\n s += \"Supports Frames = \" + bc.Frames + \"\\n\";\n s += \"Supports Tables = \" + bc.Tables + \"\\n\";\n s += \"Supports Cookies = \" + bc.Cookies + \"\\n\";\n s += \"Supports VB Script = \" + bc.VBScript + \"\\n\";\n s += \"Supports JavaScript = \" + bc.JavaScript + \"\\n\";\n s += \"Supports Java Applets = \" + bc.JavaApplets + \"\\n\";\n s += \"Supports ActiveX Controls = \" + bc.ActiveXControls + \"\\n\";\n TextBox1.Text = s;\n}\n" }, { "answer_id": 122743, "author": "Joshua Carmody", "author_id": 8409, "author_profile": "https://Stackoverflow.com/users/8409", "pm_score": 1, "selected": false, "text": "if (navigator.userAgent.indexOf(\"MSIE\") > -1) \n{\n alert(\"Internet Explorer!\");\n}\nelse if (navigator.userAgent.indexOf(\"Firefox\") > -1)\n{\n alert(\"Firefox!\");\n}\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121280", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1288/" ]
121,282
<p>If I do something like:</p> <pre><code>$ cat /bin/ls </code></pre> <p>into my terminal, I understand why I see a bunch of binary data, representing the ls executable. But afterwards, when I get my prompt back, my own keystrokes look crazy. I type "a" and I get a weird diagonal line. I type "b" and I get a degree symbol.</p> <p>Why does this happen?</p>
[ { "answer_id": 121299, "author": "Nick Johnson", "author_id": 12030, "author_profile": "https://Stackoverflow.com/users/12030", "pm_score": 5, "selected": false, "text": "reset\n" }, { "answer_id": 121374, "author": "Dan", "author_id": 17121, "author_profile": "https://Stackoverflow.com/users/17121", "pm_score": -1, "selected": false, "text": "less" }, { "answer_id": 121569, "author": "dsm", "author_id": 7780, "author_profile": "https://Stackoverflow.com/users/7780", "pm_score": 2, "selected": false, "text": "stty sane\n" }, { "answer_id": 370227, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 4, "selected": false, "text": "echo -e '\\017'\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121282", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7598/" ]
121,283
<p>I have a web application that is becoming rather large. I want to separate it into smaller more logical projects, but the smaller projects are still going to need to access some of the classes in the app_code of the main project. What are some good methods to accomplish this?</p>
[ { "answer_id": 121296, "author": "Paul van Brenk", "author_id": 1837197, "author_profile": "https://Stackoverflow.com/users/1837197", "pm_score": 3, "selected": false, "text": "/webapp1\n /default.aspx\n /....\n/webapp2\n /default.aspx\n /....\n/lib\n /Utils.cs\n" }, { "answer_id": 121303, "author": "Joseph Daigle", "author_id": 507, "author_profile": "https://Stackoverflow.com/users/507", "pm_score": 2, "selected": false, "text": "app_code" }, { "answer_id": 121347, "author": "mike", "author_id": 19217, "author_profile": "https://Stackoverflow.com/users/19217", "pm_score": 0, "selected": false, "text": "public_html" }, { "answer_id": 121804, "author": "Even Mien", "author_id": 73794, "author_profile": "https://Stackoverflow.com/users/73794", "pm_score": 3, "selected": true, "text": "app_code" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121283", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16820/" ]
121,309
<p>In an ASP.NET 2.0 website, I have a string representing some well-formed XML. I am currently creating an XmlDocument object with it and running an XSL transformation for display in a Web form. Everything was operating fine until the XML input started to contain namespaces.</p> <p>How can I read in this string and allow namespaces?</p> <p>I've included the current code below. The string source comes from an HTML encoded node in a WordPress RSS feed.</p> <pre><code>XPathNavigator myNav= myPost.CreateNavigator(); XmlNamespaceManager myManager = new XmlNamespaceManager(myNav.NameTable); myManager.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/"); string myPost = HttpUtility.HtmlDecode("&lt;post&gt;" + myNav.SelectSingleNode("//item[1]/content:encoded", myManager).InnerXml + "&lt;/post&gt;"); XmlDocument myDocument = new XmlDocument(); myDocument.LoadXml(myPost.ToString()); </code></pre> <p>The error is on the last line:</p> <p>"System.Xml.XmlException: 'w' is an undeclared namespace. Line 12, position 201. at System.Xml.XmlTextReaderImpl.Throw(Exception e) ..."</p>
[ { "answer_id": 121407, "author": "ckarras", "author_id": 5688, "author_profile": "https://Stackoverflow.com/users/5688", "pm_score": 1, "selected": false, "text": "<test xmlns:w=\"http://...\">\n <w:elementInWNamespace />\n</test>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121309", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19626/" ]
121,318
<p>I need to have a script read the files coming in and check information for verification.</p> <p>On the first line of the files to be read is a date but in numeric form. eg: 20080923 But before the date is other information, I need to read it from position 27. Meaning line 1 position 27, I need to get that number and see if it’s greater then another number.</p> <p>I use the grep command to check other information but I use special characters to search, in this case the information before the date is always different, so I can’t use a character to search on. It has to be done by line 1 position 27.</p>
[ { "answer_id": 121336, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 4, "selected": true, "text": "sed 1q $file | cut -c27-34\n" }, { "answer_id": 121344, "author": "DGentry", "author_id": 4761, "author_profile": "https://Stackoverflow.com/users/4761", "pm_score": 1, "selected": false, "text": "datestring=`head -1 $file | cut -c27-`\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121318", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21151/" ]
121,324
<p>I'm looking for a framework to generate Java source files.</p> <p>Something like the following API:</p> <pre><code>X clazz = Something.createClass("package name", "class name"); clazz.addSuperInterface("interface name"); clazz.addMethod("method name", returnType, argumentTypes, ...); File targetDir = ...; clazz.generate(targetDir); </code></pre> <p>Then, a java source file should be found in a sub-directory of the target directory.</p> <p>Does anyone know such a framework?</p> <hr> <p><strong>EDIT</strong>:</p> <ol> <li>I really need the source files.</li> <li>I also would like to fill out the code of the methods.</li> <li>I'm looking for a high-level abstraction, not direct bytecode manipulation/generation.</li> <li>I also need the "structure of the class" in a tree of objects.</li> <li>The problem domain is general: to generate a large amount of very different classes, without a "common structure".</li> </ol> <hr> <p><strong>SOLUTIONS</strong><br> I have posted 2 answers based in your answers... <a href="https://stackoverflow.com/questions/121324/a-java-api-to-generate-java-source-files#136010">with CodeModel</a> and <a href="https://stackoverflow.com/questions/121324/a-java-api-to-generate-java-source-files#136016">with Eclipse JDT</a>.</p> <p>I have used <a href="http://codemodel.java.net/" rel="noreferrer">CodeModel</a> in my solution, :-)</p>
[ { "answer_id": 136010, "author": "Daniel Fanjul", "author_id": 16135, "author_profile": "https://Stackoverflow.com/users/16135", "pm_score": 6, "selected": false, "text": "JCodeModel cm = new JCodeModel();\nJDefinedClass dc = cm._class(\"foo.Bar\");\nJMethod m = dc.method(0, int.class, \"foo\");\nm.body()._return(JExpr.lit(5));\n\nFile file = new File(\"./target/classes\");\nfile.mkdirs();\ncm.build(file);\n" }, { "answer_id": 136016, "author": "Daniel Fanjul", "author_id": 16135, "author_profile": "https://Stackoverflow.com/users/16135", "pm_score": 5, "selected": false, "text": "AST ast = AST.newAST(AST.JLS3);\nCompilationUnit cu = ast.newCompilationUnit();\n\nPackageDeclaration p1 = ast.newPackageDeclaration();\np1.setName(ast.newSimpleName(\"foo\"));\ncu.setPackage(p1);\n\nImportDeclaration id = ast.newImportDeclaration();\nid.setName(ast.newName(new String[] { \"java\", \"util\", \"Set\" }));\ncu.imports().add(id);\n\nTypeDeclaration td = ast.newTypeDeclaration();\ntd.setName(ast.newSimpleName(\"Foo\"));\nTypeParameter tp = ast.newTypeParameter();\ntp.setName(ast.newSimpleName(\"X\"));\ntd.typeParameters().add(tp);\ncu.types().add(td);\n\nMethodDeclaration md = ast.newMethodDeclaration();\ntd.bodyDeclarations().add(md);\n\nBlock block = ast.newBlock();\nmd.setBody(block);\n\nMethodInvocation mi = ast.newMethodInvocation();\nmi.setName(ast.newSimpleName(\"x\"));\n\nExpressionStatement e = ast.newExpressionStatement(mi);\nblock.statements().add(e);\n\nSystem.out.println(cu);\n" }, { "answer_id": 19263850, "author": "Stephen Haberman", "author_id": 355031, "author_profile": "https://Stackoverflow.com/users/355031", "pm_score": 2, "selected": false, "text": "@Test\npublic void testTwoMethods() {\n GClass gc = new GClass(\"foo.bar.Foo\");\n\n GMethod hello = gc.getMethod(\"hello\");\n hello.arguments(\"String foo\");\n hello.setBody(\"return 'Hi' + foo;\");\n\n GMethod goodbye = gc.getMethod(\"goodbye\");\n goodbye.arguments(\"String foo\");\n goodbye.setBody(\"return 'Bye' + foo;\");\n\n Assert.assertEquals(\n Join.lines(new Object[] {\n \"package foo.bar;\",\n \"\",\n \"public class Foo {\",\n \"\",\n \" public void hello(String foo) {\",\n \" return \\\"Hi\\\" + foo;\",\n \" }\",\n \"\",\n \" public void goodbye(String foo) {\",\n \" return \\\"Bye\\\" + foo;\",\n \" }\",\n \"\",\n \"}\",\n \"\" }),\n gc.toCode());\n}\n" }, { "answer_id": 22719691, "author": "user3207181", "author_id": 3207181, "author_profile": "https://Stackoverflow.com/users/3207181", "pm_score": 0, "selected": false, "text": "private JFieldVar generatedField;\n" }, { "answer_id": 23721770, "author": "Atmega", "author_id": 3649631, "author_profile": "https://Stackoverflow.com/users/3649631", "pm_score": 1, "selected": false, "text": "package ${cls.package.name};\n\npublic class ${cls.shortName}Builder {\n\n public static ${cls.name}Builder builder() {\n return new ${cls.name}Builder();\n }\n<% for(field in cls.fields) {%>\n private ${field.type.name} ${field.name};\n<% } %>\n<% for(field in cls.fields) {%>\n public ${cls.name}Builder ${field.name}(${field.type.name} ${field.name}) {\n this.${field.name} = ${field.name};\n return this;\n }\n<% } %>\n public ${cls.name} build() {\n final ${cls.name} data = new ${cls.name}();\n<% for(field in cls.fields) {%>\n data.${field.setter.name}(this.${field.name});\n<% } %>\n return data;\n }\n}\n" }, { "answer_id": 24681719, "author": "gastaldi", "author_id": 862119, "author_profile": "https://Stackoverflow.com/users/862119", "pm_score": 4, "selected": false, "text": "JavaClassSource source = Roaster.create(JavaClassSource.class);\nsource.setName(\"MyClass\").setPublic();\nsource.addMethod().setName(\"testMethod\").setPrivate().setBody(\"return null;\")\n .setReturnType(String.class).addAnnotation(MyAnnotation.class);\nSystem.out.println(source);\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16135/" ]
121,326
<p>What does it mean when it gives a backtrace with the following output?</p> <pre><code>#0 0x00000008009c991c in pthread_testcancel () from /lib/libpthread.so.2 #1 0x00000008009b8120 in sigaction () from /lib/libpthread.so.2 #2 0x00000008009c211a in pthread_mutexattr_init () from /lib/libpthread.so.2 #3 0x0000000000000000 in ?? () </code></pre> <p>The program has crashed with a standard signal 11, segmentation fault. My application is a multi-threaded FastCGI C++ program running on FreeBSD 6.3, using pthread as the threading library.</p> <p>It has been compiled with -g and all the symbol tables for my source are loaded, according to info sources.</p> <p>As is clear, none of my actual code appears in the trace but instead the error seems to originate from standard pthread libraries. In particular, what is ?? () ????</p> <p><b>EDIT</b>: eventually tracked the crash down to a standard invalid memory access in my main code. Doesn't explain why the stack trace was corrupted, but that's a question for another day :)</p>
[ { "answer_id": 327884, "author": "D.Shawley", "author_id": 41747, "author_profile": "https://Stackoverflow.com/users/41747", "pm_score": 2, "selected": false, "text": "NULL" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10264/" ]
121,350
<p>I have a large ADO.Net dataset and two database schemas (Oracle) with different constraints. The dataset will work with either schema, but I want to be able to tell the dataset which schema to use (via connection string) at runtime.</p> <p>Is that even possible?</p>
[ { "answer_id": 121500, "author": "David Basarab", "author_id": 2469, "author_profile": "https://Stackoverflow.com/users/2469", "pm_score": 1, "selected": false, "text": " DataSet ds = new DataSet();\n\n // Do some updateing here\n\n // Put your connection string here dyanmiclly\n System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand(\"Your Runtime Connection String\");\n\n // Create the data Adapter\n System.Data.OleDb.OleDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter(command);\n\n // Update the dataset\n dataAdapter.Update(ds);\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121350", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4219/" ]
121,373
<p>I am working on a WinForms application programmed in C# .NET 2.0 and VS2008. I am just about to start translating the app into several languages. Before I start, is it a good idea to use the VS2008 itself for all the localization? Or is it better to use some external tool right away? This is my first .NET app, so I rather ask before I start. What are others using?</p> <p>All strings used in my app are in resources, so I think the app is ready to be translated.</p> <p>Thank you, Petr</p>
[ { "answer_id": 670713, "author": "Germstorm", "author_id": 18631, "author_profile": "https://Stackoverflow.com/users/18631", "pm_score": 0, "selected": false, "text": "Default value | DE | ES\n-------------------------------\napple |apple | apple\n...\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20353/" ]
121,382
<p>Is there a way to comment out markup in an <code>.ASPX</code> page so that it isn't delivered to the client? I have tried the standard comments <code>&lt;!-- --&gt;</code> but this just gets delivered as a comment and doesn't prevent the control from rendering. </p>
[ { "answer_id": 121397, "author": "BigJump", "author_id": 8542, "author_profile": "https://Stackoverflow.com/users/8542", "pm_score": 3, "selected": false, "text": "<asp:panel runat=\"server\" visible=\"false\">\n html here\n</asp:panel>\n" }, { "answer_id": 121400, "author": "GEOCHET", "author_id": 5640, "author_profile": "https://Stackoverflow.com/users/5640", "pm_score": 9, "selected": true, "text": "<%--\n Commented out HTML/CODE/Markup. Anything with\n this block will not be parsed/handled by ASP.NET.\n\n <asp:Calendar runat=\"server\"></asp:Calendar> \n\n <%# Eval(“SomeProperty”) %> \n--%>\n" }, { "answer_id": 121406, "author": "Sklivvz", "author_id": 7028, "author_profile": "https://Stackoverflow.com/users/7028", "pm_score": 5, "selected": false, "text": "<%-- not rendered to browser --%>\n" }, { "answer_id": 121409, "author": "stefano m", "author_id": 19261, "author_profile": "https://Stackoverflow.com/users/19261", "pm_score": 4, "selected": false, "text": "<%-- Text not sent to client --%>\n" }, { "answer_id": 121411, "author": "Joel Martinez", "author_id": 5416, "author_profile": "https://Stackoverflow.com/users/5416", "pm_score": 4, "selected": false, "text": "<%-- your markup here --%>\n" }, { "answer_id": 26851082, "author": "ggb667", "author_id": 619895, "author_profile": "https://Stackoverflow.com/users/619895", "pm_score": 3, "selected": false, "text": "<%-- <%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"Default.aspx.cs\" Inherits=\"ht_tv1.Default\" %> --%>\n<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"Default.aspx.cs\" Inherits=\"Blank._Default\" %>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121382", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10676/" ]
121,385
<p>What makes a language strongly typed? I'm looking for the most important aspects of a strongly typed language.</p> <p>Yesterday I asked if PowerShell was strongly typed, but no one could agree on the definition of "strongly-typed", so I'm looking to clarify the definition.</p> <p>Feel free to link to wikipedia or other sources, but don't just cut and paste for your answer.</p>
[ { "answer_id": 121412, "author": "Hans Sjunnesson", "author_id": 8683, "author_profile": "https://Stackoverflow.com/users/8683", "pm_score": 1, "selected": false, "text": "int i = 4;\nchar s = i; // Type mismatch: cannot convert from int to char\n" }, { "answer_id": 121482, "author": "Mike Deck", "author_id": 1247, "author_profile": "https://Stackoverflow.com/users/1247", "pm_score": 3, "selected": false, "text": "x = \"5\"\n" }, { "answer_id": 122751, "author": "Jörg W Mittag", "author_id": 2988, "author_profile": "https://Stackoverflow.com/users/2988", "pm_score": 5, "selected": false, "text": "e1" }, { "answer_id": 48050808, "author": "SimpleGuy", "author_id": 3722884, "author_profile": "https://Stackoverflow.com/users/3722884", "pm_score": 1, "selected": false, "text": "int" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3289/" ]
121,387
<p>Table: </p> <pre><code>UserId, Value, Date. </code></pre> <p>I want to get the UserId, Value for the max(Date) for each UserId. That is, the Value for each UserId that has the latest date. Is there a way to do this simply in SQL? (Preferably Oracle)</p> <p><strong>Update:</strong> Apologies for any ambiguity: I need to get ALL the UserIds. But for each UserId, only that row where that user has the latest date.</p>
[ { "answer_id": 121416, "author": "jdmichal", "author_id": 12275, "author_profile": "https://Stackoverflow.com/users/12275", "pm_score": 2, "selected": false, "text": "SELECT UserId, Value\nFROM Users AS user\nWHERE Date = (\n SELECT MAX(Date)\n FROM Users AS maxtest\n WHERE maxtest.UserId = user.UserId\n)\n" }, { "answer_id": 121435, "author": "Steve K", "author_id": 739, "author_profile": "https://Stackoverflow.com/users/739", "pm_score": 6, "selected": false, "text": "SELECT userid, value\nFROM users u1\nWHERE date = (\n SELECT MAX(date)\n FROM users u2\n WHERE u1.userid = u2.userid\n)\n" }, { "answer_id": 121438, "author": "boes", "author_id": 17746, "author_profile": "https://Stackoverflow.com/users/17746", "pm_score": 1, "selected": false, "text": "create table users (userid int , value int , date datetime)\ninsert into users values (1, 1, '20010101')\ninsert into users values (1, 2, '20020101')\ninsert into users values (2, 1, '20010101')\ninsert into users values (2, 3, '20030101')\n\nselect T1.userid, T1.value, T1.date \n from users T1,\n (select max(date) as maxdate, userid from users group by userid) T2 \n where T1.userid= T2.userid and T1.date = T2.maxdate\n" }, { "answer_id": 121450, "author": "David Aldridge", "author_id": 6742, "author_profile": "https://Stackoverflow.com/users/6742", "pm_score": 10, "selected": true, "text": "select userid,\n my_date,\n ...\nfrom\n(\nselect userid,\n my_date,\n ...\n max(my_date) over (partition by userid) max_my_date\nfrom users\n)\nwhere my_date = max_my_date\n" }, { "answer_id": 121475, "author": "finnw", "author_id": 12048, "author_profile": "https://Stackoverflow.com/users/12048", "pm_score": -1, "selected": false, "text": "select TheTable.UserID, TheTable.Value\nfrom TheTable inner join (select UserID, max([Date]) MaxDate\n from TheTable\n group by UserID) UserMaxDate\n on TheTable.UserID = UserMaxDate.UserID\n TheTable.[Date] = UserMaxDate.MaxDate;\n" }, { "answer_id": 121492, "author": "stefano m", "author_id": 19261, "author_profile": "https://Stackoverflow.com/users/19261", "pm_score": 2, "selected": false, "text": "SELECT UserId, Value FROM Users U1 WHERE \nDate = ( SELECT MAX(Date) FROM Users where UserId = U1.UserId)\n" }, { "answer_id": 121506, "author": "marc", "author_id": 12260, "author_profile": "https://Stackoverflow.com/users/12260", "pm_score": 1, "selected": false, "text": "SELECT \n UserTest.UserID, UserTest.Value\nFROM UserTest\nINNER JOIN\n(\n SELECT UserID, MAX(Date) MaxDate\n FROM UserTest\n GROUP BY UserID\n) Dates\nON UserTest.UserID = Dates.UserID\nAND UserTest.Date = Dates.MaxDate \n" }, { "answer_id": 121519, "author": "Aheho", "author_id": 21155, "author_profile": "https://Stackoverflow.com/users/21155", "pm_score": 2, "selected": false, "text": "Select \n UserID, \n Value, \n Date \nFrom \n Table, \n ( \n Select \n UserID, \n Max(Date) as MDate \n From \n Table \n Group by \n UserID \n ) as subQuery \nWhere \n Table.UserID = subQuery.UserID and \n Table.Date = subQuery.mDate \n" }, { "answer_id": 121556, "author": "Zsolt Botykai", "author_id": 11621, "author_profile": "https://Stackoverflow.com/users/11621", "pm_score": 0, "selected": false, "text": "select userid, value, date\n from thetable t1 ,\n ( select t2.userid, max(t2.date) date2 \n from thetable t2 \n group by t2.userid ) t3\n where t3.userid t1.userid and\n t3.date2 = t1.date\n" }, { "answer_id": 121589, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 0, "selected": false, "text": "Select\nT1.UserId,\n(Select Top 1 T2.Value From Table T2 Where T2.UserId = T1.UserId Order By Date Desc) As 'Value'\nFrom\nTable T1\nGroup By\nT1.UserId\nOrder By\nT1.UserId\n" }, { "answer_id": 121622, "author": "Valerion", "author_id": 16156, "author_profile": "https://Stackoverflow.com/users/16156", "pm_score": 0, "selected": false, "text": "SELECT UserId, Value\nFROM Users u\nWHERE Date = (SELECT MAX(Date) FROM Users WHERE UserID = u.UserID)\n" }, { "answer_id": 121659, "author": "KyleLanser", "author_id": 12923, "author_profile": "https://Stackoverflow.com/users/12923", "pm_score": 0, "selected": false, "text": "CREATE TABLE table_name (id int, the_value varchar(2), the_date datetime);\n\nINSERT INTO table_name (id,the_value,the_date) VALUES(1 ,'a','1/1/2000');\nINSERT INTO table_name (id,the_value,the_date) VALUES(1 ,'b','2/2/2002');\nINSERT INTO table_name (id,the_value,the_date) VALUES(2 ,'c','1/1/2000');\nINSERT INTO table_name (id,the_value,the_date) VALUES(2 ,'d','3/3/2003');\nINSERT INTO table_name (id,the_value,the_date) VALUES(2 ,'e','3/3/2003');\n" }, { "answer_id": 121661, "author": "Dave Costa", "author_id": 6568, "author_profile": "https://Stackoverflow.com/users/6568", "pm_score": 7, "selected": false, "text": "SELECT userid, MAX(value) KEEP (DENSE_RANK FIRST ORDER BY date DESC)\n FROM table\n GROUP BY userid\n" }, { "answer_id": 121693, "author": "mancaus", "author_id": 13797, "author_profile": "https://Stackoverflow.com/users/13797", "pm_score": 4, "selected": false, "text": "\n-- Single Value\n;WITH ByDate\nAS (\nSELECT UserId, Value, ROW_NUMBER() OVER (PARTITION BY UserId ORDER BY Date DESC) RowNum\nFROM UserDates\n)\nSELECT UserId, Value\nFROM ByDate\nWHERE RowNum = 1\n\n-- Multiple values where dates match\n;WITH ByDate\nAS (\nSELECT UserId, Value, RANK() OVER (PARTITION BY UserId ORDER BY Date DESC) Rnk\nFROM UserDates\n)\nSELECT UserId, Value\nFROM ByDate\nWHERE Rnk = 1\n" }, { "answer_id": 121873, "author": "user11318", "author_id": 11318, "author_profile": "https://Stackoverflow.com/users/11318", "pm_score": 3, "selected": false, "text": "SELECT DISTINCT\n UserId\n , MaxValue\nFROM (\n SELECT UserId\n , FIRST (Value) Over (\n PARTITION BY UserId\n ORDER BY Date DESC\n ) MaxValue\n FROM SomeTable\n )\n" }, { "answer_id": 123481, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 9, "selected": false, "text": "SELECT t1.*\nFROM mytable t1\n LEFT OUTER JOIN mytable t2\n ON (t1.UserId = t2.UserId AND t1.\"Date\" < t2.\"Date\")\nWHERE t2.UserId IS NULL;\n" }, { "answer_id": 123511, "author": "Mike Woodhouse", "author_id": 1060, "author_profile": "https://Stackoverflow.com/users/1060", "pm_score": 6, "selected": false, "text": "SELECT * \nFROM MyTable\nWHERE (User, Date) IN\n ( SELECT User, MAX(Date) FROM MyTable GROUP BY User)\n" }, { "answer_id": 2327894, "author": "na43251", "author_id": 210716, "author_profile": "https://Stackoverflow.com/users/210716", "pm_score": 0, "selected": false, "text": "SELECT *\nFROM (\n SELECT u.*, FIRST_VALUE(u.rowid) OVER(PARTITION BY u.user_id ORDER BY u.date DESC) AS last_rowid\n FROM users u\n) u2\nWHERE u2.rowid = u2.last_rowid\n" }, { "answer_id": 2731582, "author": "Guus", "author_id": 328126, "author_profile": "https://Stackoverflow.com/users/328126", "pm_score": 1, "selected": false, "text": "SELECT FIRST, LAST, SUM(POINTS) AS TOTAL\nFROM STUDENTS S, RESULTS R\nWHERE S.SID = R.SID AND R.CAT = 'H'\nGROUP BY S.SID, FIRST, LAST\nHAVING SUM(POINTS) >= ALL (SELECT SUM (POINTS)\nFROM RESULTS\nWHERE CAT = 'H'\nGROUP BY SID)\n" }, { "answer_id": 2753881, "author": "Mauro", "author_id": 2208, "author_profile": "https://Stackoverflow.com/users/2208", "pm_score": 0, "selected": false, "text": "select ColumnNames, max(DateColumn) from log group by ColumnNames order by 1 desc\n" }, { "answer_id": 3141266, "author": "Truper", "author_id": 379052, "author_profile": "https://Stackoverflow.com/users/379052", "pm_score": 2, "selected": false, "text": "SELECT\n DISTINCT UserId,\n MAX(Date) OVER (PARTITION BY UserId ORDER BY Date DESC),\n MAX(Values) OVER (PARTITION BY UserId ORDER BY Date DESC)\nFROM\n(\n SELECT UserId, Date, SUM(Value) As Values\n FROM <<table_name>>\n GROUP BY UserId, Date\n)\n" }, { "answer_id": 7824518, "author": "wcw", "author_id": 1003601, "author_profile": "https://Stackoverflow.com/users/1003601", "pm_score": 3, "selected": false, "text": "select userid, my_date, ...\nfrom users\nqualify rank() over (partition by userid order by my_date desc) = 1\n" }, { "answer_id": 7967101, "author": "Cito", "author_id": 1008762, "author_profile": "https://Stackoverflow.com/users/1008762", "pm_score": 3, "selected": false, "text": "select user_id, user_value_1, user_value_2\n from (select user_id, user_value_1, user_value_2, row_number()\n over (partition by user_id order by user_date desc) \n from users) as r\n where r.row_number=1\n" }, { "answer_id": 8243260, "author": "nouky", "author_id": 623703, "author_profile": "https://Stackoverflow.com/users/623703", "pm_score": 2, "selected": false, "text": "select VALUE from TABLE1 where TIME = \n (select max(TIME) from TABLE1 where DATE= \n (select max(DATE) from TABLE1 where CRITERIA=CRITERIA))\n" }, { "answer_id": 16127407, "author": "王奕然", "author_id": 2245634, "author_profile": "https://Stackoverflow.com/users/2245634", "pm_score": -1, "selected": false, "text": "select UserId,max(Date) over (partition by UserId) value from users;\n" }, { "answer_id": 18539442, "author": "Ben Lin", "author_id": 1960137, "author_profile": "https://Stackoverflow.com/users/1960137", "pm_score": 1, "selected": false, "text": "select userid,\n my_date,\n ...\nfrom\n(\nselect @sno:= case when @pid<>userid then 0\n else @sno+1\n end as serialnumber, \n @pid:=userid,\n my_Date,\n ...\nfrom users order by userid, my_date\n) a\nwhere a.serialnumber=0\n" }, { "answer_id": 24860655, "author": "aLevelOfIndirection", "author_id": 913665, "author_profile": "https://Stackoverflow.com/users/913665", "pm_score": 2, "selected": false, "text": "select\n userid,\n to_number(substr(max(to_char(date,'yyyymmdd') || to_char(value)), 9)) as value,\n max(date) as date\nfrom \n users\ngroup by\n userid\n" }, { "answer_id": 26872328, "author": "Bruno Calza", "author_id": 822023, "author_profile": "https://Stackoverflow.com/users/822023", "pm_score": 2, "selected": false, "text": "array_agg" }, { "answer_id": 30888495, "author": "Smart003", "author_id": 3835573, "author_profile": "https://Stackoverflow.com/users/3835573", "pm_score": -1, "selected": false, "text": "select distinct sno,item_name,max(start_date) over(partition by sno),max(end_date) over(partition by sno),max(creation_date) over(partition by sno),\nmax(last_modified_date) over(partition by sno) \nfrom uniq_select_records\norder by sno,item_name asc;" }, { "answer_id": 43028479, "author": "Gurwinder Singh", "author_id": 6348498, "author_profile": "https://Stackoverflow.com/users/6348498", "pm_score": 3, "selected": false, "text": "Oracle 12c+" }, { "answer_id": 43913890, "author": "Natty ", "author_id": 7116494, "author_profile": "https://Stackoverflow.com/users/7116494", "pm_score": -1, "selected": false, "text": "select T.UserId,T.dt from (select UserId,max(dt) \nover (partition by UserId) as dt from t_users)T where T.dt=dt;\n" }, { "answer_id": 46113606, "author": "praveen", "author_id": 7856544, "author_profile": "https://Stackoverflow.com/users/7856544", "pm_score": -1, "selected": false, "text": "SELECT a.* \nFROM user a INNER JOIN (SELECT userid,Max(date) AS date12 FROM user1 GROUP BY userid) b \nON a.date=b.date12 AND a.userid=b.userid ORDER BY a.userid;\n" }, { "answer_id": 47036253, "author": "markusk", "author_id": 108326, "author_profile": "https://Stackoverflow.com/users/108326", "pm_score": 2, "selected": false, "text": "ROW_NUMBER()" }, { "answer_id": 52829751, "author": "praveen", "author_id": 7856544, "author_profile": "https://Stackoverflow.com/users/7856544", "pm_score": -1, "selected": false, "text": "SELECT a.userid,a.values1,b.mm \nFROM table_name a,(SELECT userid,Max(date1)AS mm FROM table_name GROUP BY userid) b\nWHERE a.userid=b.userid AND a.DATE1=b.mm;\n" }, { "answer_id": 61795657, "author": "kiruba", "author_id": 11781901, "author_profile": "https://Stackoverflow.com/users/11781901", "pm_score": -1, "selected": false, "text": "SELECT user_id, value, date , row_number() OVER (PARTITION BY user_id ORDER BY date desc) AS rn\nFROM table_name\nWHERE rn= 1\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21154/" ]
121,392
<p>I have a bunch (hundreds) of files that are supposed to have Unix line endings. I strongly suspect that some of them have Windows line endings, and I want to programmatically figure out which ones do.</p> <p>I know I can just run <pre>flip -u</pre> or something similar in a script to convert everything, but I want to be able to identify those files that need changing first.</p>
[ { "answer_id": 121447, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 6, "selected": false, "text": "file" }, { "answer_id": 121464, "author": "stimms", "author_id": 361, "author_profile": "https://Stackoverflow.com/users/361", "pm_score": 6, "selected": true, "text": "egrep -l $'\\r'\\$ *\n" }, { "answer_id": 2065154, "author": "joachim", "author_id": 187581, "author_profile": "https://Stackoverflow.com/users/187581", "pm_score": 4, "selected": false, "text": "perl -p -e 's[\\r\\n][WIN\\n]; s[(?<!WIN)\\n][UNIX\\n]; s[\\r][MAC\\n];' FILENAME\n" }, { "answer_id": 30138038, "author": "1ac0", "author_id": 1196670, "author_profile": "https://Stackoverflow.com/users/1196670", "pm_score": 0, "selected": false, "text": "0x0D 0x0A" }, { "answer_id": 37846265, "author": "Bryce Guinta", "author_id": 487464, "author_profile": "https://Stackoverflow.com/users/487464", "pm_score": 3, "selected": false, "text": "find . -type f -exec file {} \\; | grep \"CRLF\" | awk -F ':' '{ print $1 }'\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121392", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18177/" ]
121,396
<p>When you call the <code>object.__repr__()</code> method in Python you get something like this back: </p> <blockquote> <pre><code>&lt;__main__.Test object at 0x2aba1c0cf890&gt; </code></pre> </blockquote> <p>Is there any way to get a hold of the memory address if you overload <code>__repr__()</code>, other then calling <code>super(Class, obj).__repr__()</code> and regexing it out? </p>
[ { "answer_id": 121422, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 6, "selected": false, "text": "id(object)\n" }, { "answer_id": 121426, "author": "Thomas Wouters", "author_id": 17624, "author_profile": "https://Stackoverflow.com/users/17624", "pm_score": 2, "selected": false, "text": "id(self)\n" }, { "answer_id": 121452, "author": "Nick Johnson", "author_id": 12030, "author_profile": "https://Stackoverflow.com/users/12030", "pm_score": 9, "selected": true, "text": "id()" }, { "answer_id": 121508, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 6, "selected": false, "text": "def __repr__(self):\n return '<%s.%s object at %s>' % (\n self.__class__.__module__,\n self.__class__.__name__,\n hex(id(self))\n )\n" }, { "answer_id": 121572, "author": "Torsten Marek", "author_id": 9567, "author_profile": "https://Stackoverflow.com/users/9567", "pm_score": 2, "selected": false, "text": ">>> import ctypes\n>>> a = (1,2,3)\n>>> ctypes.addressof(a)\n3077760748L\n" }, { "answer_id": 122032, "author": "Dan Lenski", "author_id": 20789, "author_profile": "https://Stackoverflow.com/users/20789", "pm_score": 0, "selected": false, "text": "id(object)" }, { "answer_id": 4628230, "author": "Peter Le Bek", "author_id": 509631, "author_profile": "https://Stackoverflow.com/users/509631", "pm_score": 4, "selected": false, "text": "addressof()" }, { "answer_id": 26285749, "author": "abarnert", "author_id": 908494, "author_profile": "https://Stackoverflow.com/users/908494", "pm_score": 5, "selected": false, "text": "id" }, { "answer_id": 58107525, "author": "commanderbasher", "author_id": 12087395, "author_profile": "https://Stackoverflow.com/users/12087395", "pm_score": 2, "selected": false, "text": ">>> spam.upper\n<built-in method upper of str object at 0x1042e4830>\n>>> spam.upper()\n'YO I NEED HELP!'\n>>> id(spam)\n4365109296\n" }, { "answer_id": 68684928, "author": "Marco El-Korashy", "author_id": 15592529, "author_profile": "https://Stackoverflow.com/users/15592529", "pm_score": 1, "selected": false, "text": "str" }, { "answer_id": 69441298, "author": "Cloud Cho", "author_id": 5595995, "author_profile": "https://Stackoverflow.com/users/5595995", "pm_score": 0, "selected": false, "text": "__repr__" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121396", "https://Stackoverflow.com", "https://Stackoverflow.com/users/452521/" ]
121,408
<p>I need to store items with a calendar date (just the day, no time) in a sqlite database. What's the best way to represent the date in the column? Julian days and unix seconds come to mind as reasonable alternatives. If I go with a unit other than days at what clock time should it be?</p> <p>Update: I am aware of ISO8601 and actually used it to store the date as a string in YYYY-MM-DD format for the prototype. But for various arithmetic I have to convert it to some number internally, so I'd prefer to store a number and just convert to string for display. What units should this number be in, with what origin, and if the units is more precise than days what time of day should be used?</p>
[ { "answer_id": 124508, "author": "benzado", "author_id": 10947, "author_profile": "https://Stackoverflow.com/users/10947", "pm_score": 0, "selected": false, "text": "Date = (Month << 5) | Day\nMonth = Date >> 5\nDay = 0x1F & Date\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20626/" ]
121,439
<p>I'm running <code>Django 1.0</code> and I'm close to deploying my app. As such, I'll be changing the DEBUG setting to False.</p> <p>With that being said, I'd still like to include the stacktrace on my 500.html page when errors occur. By doing so, users can copy-and-paste the errors and easily email them to the developers.</p> <p>Any thoughts on how best to approach this issue?</p>
[ { "answer_id": 121474, "author": "Aaron Maenpaa", "author_id": 2603, "author_profile": "https://Stackoverflow.com/users/2603", "pm_score": 5, "selected": true, "text": "import traceback\nimport sys\n\ntry:\n raise Exception(\"Message\")\nexcept:\n type, value, tb = sys.exc_info()\n print >> sys.stderr, type.__name__, \":\", value\n print >> sys.stderr, '\\n'.join(traceback.format_tb(tb))\n" }, { "answer_id": 121487, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 1, "selected": false, "text": "sys.exc_info()" }, { "answer_id": 17483769, "author": "Avinash Garg", "author_id": 1900027, "author_profile": "https://Stackoverflow.com/users/1900027", "pm_score": 2, "selected": false, "text": "import sys,traceback\n\ndef custom_500(request):\n t = loader.get_template('500.html')\n\n print sys.exc_info()\n type, value, tb = sys.exc_info()\n return HttpResponseServerError(t.render(Context({\n 'exception_value': value,\n 'value':type,\n 'tb':traceback.format_exception(type, value, tb)\n },RequestContext(request))))\n" }, { "answer_id": 35889521, "author": "Joel Cross", "author_id": 1039538, "author_profile": "https://Stackoverflow.com/users/1039538", "pm_score": 0, "selected": false, "text": "pip install raven" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10040/" ]
121,453
<p>There is a way to know the flash player version installed on the computer that runs our SWF file with Action Script 3.0?</p>
[ { "answer_id": 149292, "author": "Martin", "author_id": 15840, "author_profile": "https://Stackoverflow.com/users/15840", "pm_score": 2, "selected": false, "text": "import flash.system.Capabilities;\n\n\nvar versionNumber:String = Capabilities.version;\ntrace(\"versionNumber: \"+versionNumber);\ntrace(\"-----\");\n\n// The version number is a list of items divided by \",\"\nvar versionArray:Array = versionNumber.split(\",\");\nvar length:Number = versionArray.length;\nfor(var i:Number = 0; i < length; i++) trace(\"versionArray[\"+i+\"]: \"+versionArray[i]);\ntrace(\"-----\");\n\n// The main version contains the OS type too so we split it in two\n// and we'll have the OS type and the major version number separately.\nvar platformAndVersion:Array = versionArray[0].split(\" \");\nfor(var j:Number = 0; j < 2; j++) trace(\"platformAndVersion[\"+j+\"]: \"+platformAndVersion[j]);\ntrace(\"-----\");\n\nvar majorVersion:Number = parseInt(platformAndVersion[1]);\nvar minorVersion:Number = parseInt(versionArray[1]);\nvar buildNumber:Number = parseInt(versionArray[2]);\n\ntrace(\"Platform: \"+platformAndVersion[0]);\ntrace(\"Major version: \"+majorVersion);\ntrace(\"Minor version: \"+minorVersion);\ntrace(\"Build number: \"+buildNumber);\ntrace(\"-----\");\n\nif (majorVersion < 9) trace(\"Your Flash Player version is older than the current version 9, please update.\");\nelse trace(\"You are using Flash Player 9 or later.\");\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20601/" ]
121,476
<p>What is the best way to access a running mono application via the command line (Linux/Unix)? </p> <p>Example: a mono server application is running and I want to send commands to it using the command line in the lightest/fastest way possible, causing the server to send back a response (e.g. to stdout).</p>
[ { "answer_id": 4331077, "author": "Gabriel Burt", "author_id": 223615, "author_profile": "https://Stackoverflow.com/users/223615", "pm_score": 1, "selected": false, "text": "gsharp" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121476", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17378/" ]
121,493
<p>I'm no crypto expert, but as I understand it, 3DES is a symmetric encryption algorithm, which means it doesnt use public/private keys.</p> <p>Nevertheless, I have been tasked with encrypting data using a public key, (specifically, a .CER file). If you ignore the whole symmetric/asymmetric thang, I should just be able to use the key data from the public key as the TripleDES key. However, I'm having difficulty extracting the key bytes from the .CER file. This is the code as it stands..</p> <pre><code>TripleDESCryptoServiceProvider cryptoProvider = new TripleDESCryptoServiceProvider(); X509Certificate2 cert = new X509Certificate2(@"c:\temp\whatever.cer"); cryptoProvider.Key = cert.PublicKey.Key. </code></pre> <p>The simplest method I can find to extract the raw key bytes from the certificate is ToXmlString(bool), and then doing some hacky substringing upon the returned string. However, this seems so hackish I feel I must be missing a simpler, more obvious way to do it.</p> <p>Am I missing a simpler way to use a .cer file to provide the key data to the C# 3DES crypto class, or is hacking it out of the certificate xml string really the best way to go about this?</p>
[ { "answer_id": 121527, "author": "Seb Nilsson", "author_id": 2429, "author_profile": "https://Stackoverflow.com/users/2429", "pm_score": 0, "selected": false, "text": "byte[] keyBytes = Convert.FromBase64String(sourceString);\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121493", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21002/" ]
121,499
<p>Suppose I attach an <code>blur</code> function to an HTML input box like this:</p> <pre><code>&lt;input id="myInput" onblur="function() { ... }"&gt;&lt;/input&gt; </code></pre> <p>Is there a way to get the ID of the element which caused the <code>blur</code> event to fire (the element which was clicked) inside the function? How?</p> <p>For example, suppose I have a span like this:</p> <pre><code>&lt;span id="mySpan"&gt;Hello World&lt;/span&gt; </code></pre> <p>If I click the span right after the input element has focus, the input element will lose its focus. How does the function know that it was <code>mySpan</code> that was clicked?</p> <p>PS: If the onclick event of the span would occur before the onblur event of the input element my problem would be solved, because I could set some status value indicating a specific element had been clicked.</p> <p>PPS: The background of this problem is that I want to trigger an AJAX autocompleter control externally (from a clickable element) to show its suggestions, without the suggestions disappearing immediately because of the <code>blur</code> event on the input element. So I want to check in the <code>blur</code> function if one specific element has been clicked, and if so, ignore the blur event. </p>
[ { "answer_id": 121517, "author": "brock.holum", "author_id": 15860, "author_profile": "https://Stackoverflow.com/users/15860", "pm_score": 0, "selected": false, "text": "<script type=\"text/javascript\">\n var lastFocusedElement;\n</script>\n<input id=\"myInput\" onFocus=\"lastFocusedElement=this;\" />\n" }, { "answer_id": 121522, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": -1, "selected": false, "text": "<script type=\"text/javascript\">\n function yourFunction(element) {\n alert(element);\n }\n</script>\n<input id=\"myinput\" onblur=\"yourFunction(this)\">\n" }, { "answer_id": 121576, "author": "stefano m", "author_id": 19261, "author_profile": "https://Stackoverflow.com/users/19261", "pm_score": 1, "selected": false, "text": "window.event.toElement" }, { "answer_id": 121708, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 8, "selected": true, "text": "explicitOriginalTarget" }, { "answer_id": 124560, "author": "bmb", "author_id": 5298, "author_profile": "https://Stackoverflow.com/users/5298", "pm_score": 2, "selected": false, "text": "<input id=\"myInput\" onblur=\"lastBlurred=this;\"></input>\n" }, { "answer_id": 128452, "author": "Michiel Borkent", "author_id": 6264, "author_profile": "https://Stackoverflow.com/users/6264", "pm_score": 4, "selected": false, "text": "<input id=\"myInput\" onblur=\"setTimeout(function() {alert(clickSrc);},200);\"></input>\n<span onclick=\"clickSrc='mySpan';\" id=\"mySpan\">Hello World</span>\n" }, { "answer_id": 177936, "author": "matte", "author_id": 25768, "author_profile": "https://Stackoverflow.com/users/25768", "pm_score": 2, "selected": false, "text": "Autocompleter.Base.prototype.onBlur = Autocompleter.Base.prototype.onBlur.wrap( \n function(origfunc, ev) {\n if ($(this.options.ignoreBlurEventElement)) {\n var newTargetElement = (ev.explicitOriginalTarget.nodeType == 3 ? ev.explicitOriginalTarget.parentNode : ev.explicitOriginalTarget);\n if (!newTargetElement.descendantOf($(this.options.ignoreBlurEventElement))) {\n return origfunc(ev);\n }\n }\n }\n );\n" }, { "answer_id": 947529, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<input id=\"btn1\" onblur=\"showBlur(event)\" value=\"text1\">\n<input id=\"btn2\" onblur=\"showBlur(event)\" value=\"text2\">\n<input id=\"btn3\" onblur=\"showBlur(event)\" value=\"text3\">\n" }, { "answer_id": 2572467, "author": "Evgeny Shmanev", "author_id": 308436, "author_profile": "https://Stackoverflow.com/users/308436", "pm_score": 4, "selected": false, "text": "$(document).mousedown(function(){\n if ($(event.target).attr(\"id\") == \"mySpan\") {\n // some process\n }\n});\n" }, { "answer_id": 6202863, "author": "EricDuWeb", "author_id": 779573, "author_profile": "https://Stackoverflow.com/users/779573", "pm_score": 0, "selected": false, "text": "$('#Form').keyup(function (e) {\n var ctrl = null;\n if (e.originalEvent.explicitOriginalTarget) { // FF\n ctrl = e.originalEvent.explicitOriginalTarget;\n }\n else if (e.originalEvent.srcElement) { // IE, Chrome and Opera\n ctrl = e.originalEvent.srcElement;\n }\n //...\n});\n" }, { "answer_id": 8853179, "author": "Vikas", "author_id": 1147999, "author_profile": "https://Stackoverflow.com/users/1147999", "pm_score": 1, "selected": false, "text": "var myVar = null;\n" }, { "answer_id": 9928738, "author": "Ronan Quillevere", "author_id": 1301197, "author_profile": "https://Stackoverflow.com/users/1301197", "pm_score": 0, "selected": false, "text": "<input id=\"myInput\" onblur=\"blured = this.id;\"></input>\n<span onfocus = \"sortOfCallback(this.id)\" id=\"mySpan\">Hello World</span>\n" }, { "answer_id": 12004741, "author": "Monika Sharma", "author_id": 1606730, "author_profile": "https://Stackoverflow.com/users/1606730", "pm_score": -1, "selected": false, "text": "<input type=\"text\" id=\"text1\" onblur=\"showMessageOnOnblur(this)\">\n\nfunction showMessageOnOnblur(field){\n alert($(field).attr(\"id\"));\n}\n" }, { "answer_id": 29704319, "author": "Shikekaka Yamiryuukido", "author_id": 4801908, "author_profile": "https://Stackoverflow.com/users/4801908", "pm_score": -1, "selected": false, "text": "<script type=\"text/javascript\">\nfunction myFunction(thisElement) \n{\n document.getElementByName(thisElement)[0];\n}\n</script>\n<input type=\"text\" name=\"txtInput1\" onBlur=\"myFunction(this.name)\"/>\n" }, { "answer_id": 33325953, "author": "Oriol", "author_id": 1529630, "author_profile": "https://Stackoverflow.com/users/1529630", "pm_score": 7, "selected": false, "text": "relatedTarget" }, { "answer_id": 38101004, "author": "Madbean", "author_id": 6528671, "author_profile": "https://Stackoverflow.com/users/6528671", "pm_score": 1, "selected": false, "text": " event.currentTarget.firstChild.ownerDocument.activeElement\n" }, { "answer_id": 40899101, "author": "Kevin", "author_id": 473792, "author_profile": "https://Stackoverflow.com/users/473792", "pm_score": 1, "selected": false, "text": "document.activeElement" }, { "answer_id": 40925160, "author": "rplaurindo", "author_id": 2730593, "author_profile": "https://Stackoverflow.com/users/2730593", "pm_score": 3, "selected": false, "text": "FocusEvent" }, { "answer_id": 43010274, "author": "Serhii Matrunchyk", "author_id": 1323496, "author_profile": "https://Stackoverflow.com/users/1323496", "pm_score": 0, "selected": false, "text": "contentEditable" }, { "answer_id": 45921048, "author": "Thomas J.", "author_id": 5470560, "author_profile": "https://Stackoverflow.com/users/5470560", "pm_score": -1, "selected": false, "text": "const focusedElement = document.activeElement\n" }, { "answer_id": 50340689, "author": "LuisEduardox", "author_id": 7452226, "author_profile": "https://Stackoverflow.com/users/7452226", "pm_score": 2, "selected": false, "text": "$(\"#YourElement\").blur(function(e){\n var InputTarget = $(e.relatedTarget).attr(\"id\"); // GET ID Element\n console.log(InputTarget);\n if(target == \"YourId\") { // If you want validate or make a action to specfic element\n ... // your code\n }\n});\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6264/" ]
121,511
<p>I have inherited a poorly written web application that seems to have errors when it tries to read in an xml document stored in the database that has an "&amp;" in it. For example there will be a tag with the contents: "Prepaid &amp; Charge". Is there some secret simple thing to do to have it not get an error parsing that character, or am I missing something obvious? </p> <p>EDIT: Are there any other characters that will cause this same type of parser error for not being well formed?</p>
[ { "answer_id": 121529, "author": "Steve g", "author_id": 12092, "author_profile": "https://Stackoverflow.com/users/12092", "pm_score": 2, "selected": false, "text": "&amp;" }, { "answer_id": 121537, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 6, "selected": true, "text": "Prepaid &amp; Charge" }, { "answer_id": 121544, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 2, "selected": false, "text": "&amp;" }, { "answer_id": 121555, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 2, "selected": false, "text": "<![CDATA[This is my wonderful & great user text]]>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13593/" ]
121,521
<p>I use the on-demand (hosted) version of FogBugz. I would like to start using Mercurial for source control. I would like to integrate FogBugz and a BitBucket repository. I gave it a bit of a try but things weren't going very well. </p> <p>FogBugz requires that you hook up your Mercurial client to a fogbugz.py python script. TortoiseHg doesn't seem to have the hgext directory that they refer to in instructions.</p> <p>So has anyone successfully done something similar?</p>
[ { "answer_id": 123314, "author": "Stefan Rusek", "author_id": 19704, "author_profile": "https://Stackoverflow.com/users/19704", "pm_score": 4, "selected": true, "text": "[fogbugz]\npath=C:\\Program Files\\TortoiseHg\\scripts\\fogbugz.py\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20498/" ]
121,579
<p>I don't know if anyone has seen this issue before but I'm just stumped. Here's the unhandled exception message that my error page is capturing. </p> <blockquote> <p>Error Message: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.</p> <p>Stack Trace: at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) at System.Web.UI.HiddenFieldPageStatePersister.Load() at System.Web.UI.Page.LoadPageStateFromPersistenceMedium() at System.Web.UI.Page.LoadAllState() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.generic_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)</p> <p>Source: System.Web</p> </blockquote> <p>Anybody have any ideas on how I could resolve this? Thanks.</p>
[ { "answer_id": 121583, "author": "Chris Driver", "author_id": 5217, "author_profile": "https://Stackoverflow.com/users/5217", "pm_score": 5, "selected": true, "text": "<input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"AEBnx7v.........tS\" />\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21165/" ]
121,581
<p>In SQL Server what is the simplest/cleanest way to make a datetime representing the first of the month based on another datetime? eg I have a variable or column with 3-Mar-2005 14:23 and I want to get 1-Mar-2005 00:00 (as a datetime, not as varchar)</p>
[ { "answer_id": 121596, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 3, "selected": false, "text": "SELECT DATEADD(mm, DATEDIFF(mm, 0, @date), 0)\n" }, { "answer_id": 121602, "author": "George Mastros", "author_id": 1408129, "author_profile": "https://Stackoverflow.com/users/1408129", "pm_score": 6, "selected": true, "text": "Select DateAdd(Month, DateDiff(Month, 0, GetDate()), 0)\n" }, { "answer_id": 121614, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 2, "selected": false, "text": "UPDATE YOUR_TABLE\nSET NewColumn = DATEADD(day, (DATEPART(day, OldColumn) -1)*-1, OldColumn)\n" }, { "answer_id": 27782399, "author": "sinan.petrus", "author_id": 4323416, "author_profile": "https://Stackoverflow.com/users/4323416", "pm_score": 0, "selected": false, "text": "DATEADD(DAY, 1-DAY(@date), @date)\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8479/" ]
121,585
<p>I'm specifically interested in Windows 2000/XP, but Vista/7 would be interesting too (if different).</p> <p>I was thinking along the lines of task scheduling a batch file or equivalent on a daily basis.</p> <p>EDIT: Sorry, I should have provided more info. The question pertains to 10 machines which I manually apply updates. I don't want to install the updates programatically, but just find out if there are updates ready to download/install (i.e. the update shield icon in the system tray is indicating this) using a batch or script. Thanks.</p>
[ { "answer_id": 857737, "author": "Alex", "author_id": 26564, "author_profile": "https://Stackoverflow.com/users/26564", "pm_score": 2, "selected": false, "text": "WUApiLib" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13967/" ]
121,599
<p>We're looking at CouchdDB for a CMS-ish application. What are some common patterns, best practices and workflow advice surrounding backing up our production database?</p> <p>I'm particularly interested in the process of cloning the database for use in development and testing.</p> <p>Is it sufficient to just copy the files on disk out from under a live running instance? Can you clone database data between two live running instances?</p> <p>Advice and description of the techniques you use will be greatly appreciated.</p>
[ { "answer_id": 126556, "author": "Jan Lehnardt", "author_id": 21269, "author_profile": "https://Stackoverflow.com/users/21269", "pm_score": 3, "selected": false, "text": "cp" }, { "answer_id": 28734252, "author": "coffeequant", "author_id": 2841309, "author_profile": "https://Stackoverflow.com/users/2841309", "pm_score": 1, "selected": false, "text": "." }, { "answer_id": 67741371, "author": "reduce_mighty", "author_id": 16061210, "author_profile": "https://Stackoverflow.com/users/16061210", "pm_score": 0, "selected": false, "text": "Export-CouchDBDatabase -Database test -Authorization \"admin:password\"\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19784/" ]
121,605
<p>What is the best way to reduce the size of the viewstate hidden field in JSF? I have noticed that my view state is approximately 40k this goes down to the client and back to the server on every request and response espically coming to the server this is a significant slowdown for the user. </p> <p>My Environment JSF 1.2, MyFaces, Tomcat, Tomahawk, RichFaces</p>
[ { "answer_id": 121624, "author": "David Waters", "author_id": 12148, "author_profile": "https://Stackoverflow.com/users/12148", "pm_score": 4, "selected": false, "text": "<context-param>\n <param-name>org.apache.myfaces.COMPRESS_STATE_IN_CLIENT</param-name>\n <param-value>true</param-value>\n</context-param> `\n" }, { "answer_id": 170877, "author": "Cristian Vat", "author_id": 20109, "author_profile": "https://Stackoverflow.com/users/20109", "pm_score": 5, "selected": true, "text": " <context-param>\n <param-name>javax.faces.STATE_SAVING_METHOD</param-name>\n <param-value>server</param-value>\n </context-param>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12148/" ]
121,606
<p>If I want to bind a collection to a some form of listing control in Silverlight. Is the only way to do it so make the underlying objects in the collection implement INotifyPropertyChanged and for the collection to be an Observablecollection?</p> <p>If I was using some sort of third party object, for example that returned by a web service, I would have to wrap it or map it to something that implements INotifyPropertyChanged ?</p>
[ { "answer_id": 598191, "author": "caryden", "author_id": 313, "author_profile": "https://Stackoverflow.com/users/313", "pm_score": 0, "selected": false, "text": "<UserControl>\n <UserControl.Resources>\n <local:FooToBindableFooConverter x:Key=\"BindableFooConverter\"/>\n </UserControl.Resources>\n <TextBlock Text=\"{Binding FooInstance, Converter={StaticResource BindableFooConverter}}\"/>\n\n</UserControl>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/230/" ]
121,615
<p>I'm in the process of adding custom buttons to my iPhone UI and want to make them have the glassy look from Apple's apps. I have a good default glass image, but I'd hate to have to have a separate image for each tint I want (red, green, blue, etc.). </p> <p>Is there a way to load a grayscale PNG and adjust it to the color I want? Better yet, is there a way to get Apple's glassy look without having to load custom images at all?</p>
[ { "answer_id": 4971371, "author": "Cyrille", "author_id": 526547, "author_profile": "https://Stackoverflow.com/users/526547", "pm_score": 3, "selected": false, "text": "UISegmentedControl" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1967/" ]
121,631
<p>Is there a difference in performance (in oracle) between</p> <pre><code>Select * from Table1 T1 Inner Join Table2 T2 On T1.ID = T2.ID </code></pre> <p>And</p> <pre><code>Select * from Table1 T1, Table2 T2 Where T1.ID = T2.ID </code></pre> <p>?</p>
[ { "answer_id": 122403, "author": "user21241", "author_id": 21241, "author_profile": "https://Stackoverflow.com/users/21241", "pm_score": 5, "selected": false, "text": "JOIN" }, { "answer_id": 354834, "author": "kiewic", "author_id": 27211, "author_profile": "https://Stackoverflow.com/users/27211", "pm_score": 9, "selected": true, "text": "CREATE TABLE table1 (\n id INT,\n name VARCHAR(20)\n);\n\nCREATE TABLE table2 (\n id INT,\n name VARCHAR(20)\n);\n" }, { "answer_id": 947481, "author": "cheduardo", "author_id": 113082, "author_profile": "https://Stackoverflow.com/users/113082", "pm_score": 3, "selected": false, "text": "select *\nfrom Table1 inner join Table2 using (ID);\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1782/" ]
121,638
<p>This may seem like a daft question, but i was wondering about how to use MVC frameworks on hosted servers.</p> <p>I am playing about (albeit slowly) at home with the RoR on Ubuntu and understand that if i want to do a live site then i need hosting with Rails and Ruby.</p> <p>However, what happens about the PHP frameworks. For example i have seen in the past all about the CakePHP but lately i have just come across the <a href="http://www.symfony-project.org/tutorial/1_1/my-first-project" rel="nofollow noreferrer">Symfony project</a> and was thinking that if i had a server stack set up i could develop at home, how would i go about deploying anything live. </p> <p>How do i use php command line on live servers, and how would i go about installing the framework on another server.</p> <p>This is all hyperthetical at the moment as i am just thinking about it, but it is a question that i have thought of in the past.</p> <p>Regards</p>
[ { "answer_id": 121681, "author": "dirtside", "author_id": 20903, "author_profile": "https://Stackoverflow.com/users/20903", "pm_score": 2, "selected": false, "text": "<?php\nrequire_once(\"/home/username/frameworks/Kohana_2.2/system/core/Bootstrap.php\");\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17415/" ]
121,656
<p>I have the following string and I would like to remove <code>&lt;bpt *&gt;*&lt;/bpt&gt;</code> and <code>&lt;ept *&gt;*&lt;/ept&gt;</code> (notice the additional tag content inside them that also needs to be removed) without using a XML parser (overhead too large for tiny strings).</p> <pre><code>The big &lt;bpt i="1" x="1" type="bold"&gt;&lt;b&gt;&lt;/bpt&gt;black&lt;ept i="1"&gt;&lt;/b&gt;&lt;/ept&gt; &lt;bpt i="2" x="2" type="ulined"&gt;&lt;u&gt;&lt;/bpt&gt;cat&lt;ept i="2"&gt;&lt;/u&gt;&lt;/ept&gt; sleeps. </code></pre> <p>Any regex in VB.NET or C# will do.</p>
[ { "answer_id": 121727, "author": "davenpcj", "author_id": 4777, "author_profile": "https://Stackoverflow.com/users/4777", "pm_score": 1, "selected": false, "text": "(<bpt .*?>.*?</bpt>)|(<ept .*?>.*?</ept>)\n" }, { "answer_id": 121833, "author": "Torsten Marek", "author_id": 9567, "author_profile": "https://Stackoverflow.com/users/9567", "pm_score": 0, "selected": false, "text": "(<([eb])pt[^>]+>((?!</\\2pt>).)+</\\2pt>)\n" }, { "answer_id": 121973, "author": "tyshock", "author_id": 16448, "author_profile": "https://Stackoverflow.com/users/16448", "pm_score": 4, "selected": true, "text": "try {\n yourstring = Regex.Replace(yourstring, \"(<[be]pt[^>]+>.+?</[be]pt>)\", \"\");\n} catch (ArgumentException ex) {\n // Syntax error in the regular expression\n}\n" }, { "answer_id": 396338, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": " str = CStr(str)\n If Len(str) > 0 Then\n str = Replace(str, \"&\", \"&amp;\")\n str = Replace(str, \"'\", \"&apos;\")\n str = Replace(str, \"\"\"\", \"&quot;\")\n arrLessThan = FindLocationOfChar(\"<\", str)\n arrGreaterThan = FindLocationOfChar(\">\", str)\n str = ChangeGreaterLess(arrLessThan, arrGreaterThan, str)\n str = Replace(str, Chr(13), \"chr(13)\")\n str = Replace(str, Chr(10), \"chr(10)\")\n End If\n Return str\nElse\n Return \"\"\nEnd If\n" }, { "answer_id": 3834084, "author": "Eamon Nerbonne", "author_id": 42921, "author_profile": "https://Stackoverflow.com/users/42921", "pm_score": 0, "selected": false, "text": "Regex" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1508/" ]
121,662
<p>Ok, so we have clients and those clients get to customize their web facing page. One option we are giving them is to be able to change the color of a graphic (it's like a framish-looking bar) using one of those hex wheels or whatever. </p> <p>So, I've thought about it, and I don't know where to start. I am sending comps out this week to my xhtml guy and I want to have the implementation done at least in my mind before I send things out. </p> <p>Something about System.Drawing sounds about right, but I've never worked with that before and it sounds hella complicated. Does anyone have an idea? </p> <p><strong>UPDATE:</strong> The color of an image will be changing. So if I want image 1 to be green, and image 2 to be blue, I go into my admin screen and enter those hex values (probably will give them an interface for it) and then when someone else looks at their page they will see the changes they made. Kind of like customizing a facebook or myspace page (OMFGz soooo Werb 2.0)</p>
[ { "answer_id": 122354, "author": "clweeks", "author_id": 13748, "author_profile": "https://Stackoverflow.com/users/13748", "pm_score": 2, "selected": true, "text": "Imports System.Drawing\n\nPrivate Function createImage(ByVal srcPath As String, ByVal fg As Color, ByVal bg As Color) As Bitmap\n Dim img As New Bitmap(srcPath)\n For x As Int16 = 0 To img.Width\n For y As Int16 = 0 To img.Height\n If img.GetPixel(x, y) = Color.Black Then\n img.SetPixel(x, y, fg)\n Else\n img.SetPixel(x, y, bg)\n End If\n Next\n Next\n Return img\nEnd Function\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4140/" ]
121,665
<p>How does one invoke a groovy method that prints to stdout, appending the output to a string?</p>
[ { "answer_id": 121776, "author": "Joe Skora", "author_id": 14057, "author_profile": "https://Stackoverflow.com/users/14057", "pm_score": 5, "selected": true, "text": "void doSomething() {\n println \"i did something\"\n}\n\nprintln \"normal call\\n---------------\"\ndoSomething()\nprintln \"\"\n\ndef buf = new ByteArrayOutputStream()\ndef newOut = new PrintStream(buf)\ndef saveOut = System.out\n\nprintln \"redirected call\\n---------------\"\nSystem.out = newOut\ndoSomething()\nSystem.out = saveOut\nprintln \"\"\n\nprintln \"results of call\\n---------------\"\nprintln buf.toString()\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
121,674
<p>The CPU architecture landscape has changed, multiple cores is a trend that will change how we have to develop software. I've done multi-threaded development in C, C++ and Java, I've done multi-process development using various IPC mechanisms. Traditional approaches of using threads doesn't seem to make it easy, for the developer, to utilize hardware that supports a high degree of concurrency.</p> <p>What languages, libraries and development techniques are you aware of that help alleviate the traditional challenges of creating concurrent applications? I'm obviously thinking of issues like deadlocks and race conditions. Design techniques, libraries, tools, etc. are also interesting that help actually take advantage of and ensure that the available resources are being utilized - just writing a safe, robust threaded application doesn't ensure that it's using all the available cores.</p> <p>What I've seen so far is:</p> <ul> <li><a href="http://www.erlang.org/" rel="nofollow noreferrer">Erlang</a>: process based, message passing IPC, the 'actor's model of concurrency</li> <li><a href="https://github.com/dramatis/dramatis" rel="nofollow noreferrer">Dramatis</a>: actors model library for Ruby and Python</li> <li><a href="http://www.scala-lang.org/" rel="nofollow noreferrer">Scala</a>: functional programming language for the JVM with some added concurrency support</li> <li><a href="http://clojure.org/" rel="nofollow noreferrer">Clojure</a>: functional programming language for the JVM with an actors library</li> <li><a href="http://code.google.com/p/termite/" rel="nofollow noreferrer">Termite</a>: a port of Erlang's process approach and message passing to Scheme</li> </ul> <p>What else do you know about, what has worked for you and what do you think is interesting to watch?</p>
[ { "answer_id": 121764, "author": "Torsten Marek", "author_id": 9567, "author_profile": "https://Stackoverflow.com/users/9567", "pm_score": 3, "selected": false, "text": "map/imap" }, { "answer_id": 219043, "author": "gbjbaanb", "author_id": 13744, "author_profile": "https://Stackoverflow.com/users/13744", "pm_score": 2, "selected": false, "text": "#pragma omp parallel for\nfor (int i=0; i < SIZE; i++) \n{\n// do something with an element\n}\n" }, { "answer_id": 222006, "author": "Anthony Williams", "author_id": 5597, "author_profile": "https://Stackoverflow.com/users/5597", "pm_score": 2, "selected": false, "text": "std::lock" }, { "answer_id": 10915777, "author": "Pierre Carbonnelle", "author_id": 474491, "author_profile": "https://Stackoverflow.com/users/474491", "pm_score": 0, "selected": false, "text": "multiprocessing" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121674", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19784/" ]
121,676
<p>Inside a .NET 3.5 web app running impersonation I am trying to execute a process via:</p> <pre><code>var process = new Process { StartInfo = { CreateNoWindow = true, FileName = "someFileName", Domain = "someDomain", Username = "someUserName", Password = securePassword, UseShellExecute = false } }; process.Start(); </code></pre> <p>-Changing the trust mode to full in web.config did not fix.</p> <p>-Note the var securePassword is a secureString set up earlier in the code.</p> <p>This throws an exception with 'Access is Denied' as its message. If I remove the username and password information, the exception goes away, but the process starts as aspnet_wp instead of the user I need it to.</p> <p>I've seen this issue in multiple forums and never seen a solution provided. Any ideas?</p>
[ { "answer_id": 121763, "author": "Mike L", "author_id": 12085, "author_profile": "https://Stackoverflow.com/users/12085", "pm_score": 2, "selected": false, "text": "Dim startInfo As New ProcessStartInfo(programName)\n With startInfo\n .Domain = \"test.local\"\n .WorkingDirectory = My.Application.Info.DirectoryPath\n .UserName = \"testuser\"\n Dim pwd As New Security.SecureString\n For Each c As Char In \"password\"\n pwd.AppendChar(c)\n Next\n .Password = pwd\n\n 'If you provide a value for the Password property, the UseShellExecute property must be false, or an InvalidOperationException will be thrown when the Process..::.Start(ProcessStartInfo) method is called. \n .UseShellExecute = False\n\n .WindowStyle = ProcessWindowStyle.Hidden\n End With\n" }, { "answer_id": 121846, "author": "Adrian Clark", "author_id": 148, "author_profile": "https://Stackoverflow.com/users/148", "pm_score": 0, "selected": false, "text": "Full Trust" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121676", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
121,680
<p>I am 90% sure I saw this answer on stackoverflow before, in fact I had never seen the "int?" syntax before seeing it here, but no matter how I search I can't find the previous post, and it's driving me crazy.</p> <p>It's possible that I've been eating the funny mushrooms by accident, but if I'm not, can someone please point out the previous post if they can find it or re-explain it? My stackoverflow search-fu is apparently too low....</p>
[ { "answer_id": 121686, "author": "Forgotten Semicolon", "author_id": 1960, "author_profile": "https://Stackoverflow.com/users/1960", "pm_score": 8, "selected": true, "text": "Nullable<int>" }, { "answer_id": 54249164, "author": "Taher Assad", "author_id": 7510214, "author_profile": "https://Stackoverflow.com/users/7510214", "pm_score": 0, "selected": false, "text": "x= (int)y;\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8151/" ]
121,700
<p>In an attempt to add some parameter validation and correct usage semantics to our application, we are trying to add correct exception handling to our .NET applications.</p> <p>My question is this: When throwing exceptions in ADO.NET if a particular query returns no data or the data could not be found, what type of exception should I use?</p> <p>Psuedocode: (read, don't scrutinize the semantics of the code, I know it won't compile)</p> <pre><code>public DataSet GetData(int identifier) { dataAdapter.Command.Text = "Select * from table1 Where ident = " + identifier.toString(); DataSet ds = dataAdapter.Fill(ds); if (ds.table1.Rows.Count == 0) throw new Exception("Data not found"); return ds; } </code></pre>
[ { "answer_id": 121746, "author": "Richard Yorkshire", "author_id": 21001, "author_profile": "https://Stackoverflow.com/users/21001", "pm_score": 2, "selected": false, "text": "public class myException : Exception\n{\n public myException(string s) : base() \n {\n this.MyReasonMessage = s;\n }\n}\n\npublic void GetData(int identifier)\n{\n dataAdapter.Command.Text = \"Select * from table1 Where ident = \" + identifier.toString();\n DataSet ds = dataAdapter.Fill(ds);\n if (ds.table1.Rows.Count == 0)\n throw new myException(\"Data not found\");\n}\n" }, { "answer_id": 121809, "author": "Johan Buret", "author_id": 15366, "author_profile": "https://Stackoverflow.com/users/15366", "pm_score": 2, "selected": false, "text": "try\n{\n int i;\n GetData(i);\n\n}\ncatch(Exception e) //will catch many many exceptions\n{\n //Handle gracefully the \"Data not Found\" case;\n //Whatever else happens will get caught and ignored\n}\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121700", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15766/" ]
121,707
<p>I don't currently use ajax.net though I would be open to it if it is the only solution. I have a auto-complete control on screen that I am using to populate a asp.net dropdownlist with values through javascript (jQuery). I have had to use EnableEventValidation="false" to allow this. After I add my options to the select and the form is posted back I would like to be able to get all the values for the option elements I have added to the asp.net dropdownlist through javascript.. Is there a good way to accomplish this?</p>
[ { "answer_id": 192082, "author": "Jason", "author_id": 26860, "author_profile": "https://Stackoverflow.com/users/26860", "pm_score": 1, "selected": false, "text": "string fooBar = Request.Form[SomeDropDown.UniqueID];\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121707", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18926/" ]
121,713
<p>My boss asked me to setup a <a href="http://en.wikipedia.org/wiki/Apache_Subversion" rel="nofollow noreferrer">Subversion</a> server for him to use so that he can share all his documents across different machines in sync and still be able to access them when there is no Internet connection.</p> <p>I have this up for him, but now he's requesting that the 'create date' file attribute be preserved. I explained that since he downloaded all the files that is their create date, but he insists I find a manner to preserve this as it is affecting the desktop search agent he uses. Is there any way to set this attribute to be preserved via Subversion, or do I have to write a script to get the date of each file and have him run 'touch' after each intial check out?</p> <p>Note that the set of documents that were added to the SVN repository span back several years, and he wants these dates preserved across all checkouts. So the date of the last change that Subversion has could potentially be off by years from what he wants.</p>
[ { "answer_id": 7366083, "author": "Bryce", "author_id": 311364, "author_profile": "https://Stackoverflow.com/users/311364", "pm_score": 2, "selected": false, "text": "svn propset svn:date --revprop -r HEAD \"2007-04-22\"\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121713", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9940/" ]
121,722
<pre><code>string percentage = e.Row.Cells[7].Text; </code></pre> <p>I am trying to do some dynamic stuff with my GridView, so I have wired up some code to the RowDataBound event. I am trying to get the value from a particular cell, which is a TemplateField. But the code above always seems to be returning an empty string. </p> <p>Any ideas?</p> <p>To clarify, here is a bit the offending cell:</p> <pre><code>&lt;asp:TemplateField HeaderText="# Percentage click throughs"&gt; &lt;ItemTemplate&gt; &lt;%# AddPercentClickThroughs((int)Eval("EmailSummary.pLinksClicked"), (int)Eval("NumberOfSends")) %&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre> <p>On a related note, does anyone know if there is a better way of selecting the cell in the row. It sucks putting in <code>cell[1]</code>. Couldn't I do <code>cell["mycellname"]</code>, so if I decide to change the order of my cells, bugs wont appear?</p>
[ { "answer_id": 121740, "author": "Orion Adrian", "author_id": 7756, "author_profile": "https://Stackoverflow.com/users/7756", "pm_score": 5, "selected": true, "text": "Label" }, { "answer_id": 121751, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 6, "selected": false, "text": "DataBinder.Eval(e.Row.DataItem, \"ColumnName\")\n" }, { "answer_id": 179832, "author": "Chris", "author_id": 13700, "author_profile": "https://Stackoverflow.com/users/13700", "pm_score": 5, "selected": false, "text": "string percentage = ((DataBoundLiteralControl)e.Row.Cells[7].Controls[0]).Text;\n" }, { "answer_id": 738051, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "protected void GridView1_DataBound(object sender, GridViewRowEventArgs e)\n{\n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n if (e.Row.Cells[0].Text.Contains(\"sometext\"))\n {\n e.Row.Cells[0].Font.Bold = true;\n }\n }\n}\n" }, { "answer_id": 5491397, "author": "Ahmad", "author_id": 684598, "author_profile": "https://Stackoverflow.com/users/684598", "pm_score": 3, "selected": false, "text": "for (int i = 0; i < GridView2.Rows.Count; i++)\n{\n string vr;\n vr = GridView2.Rows[i].Cells[4].Text; // here you go vr = the value of the cel\n if (vr == \"0\") // you can check for anything\n {\n GridView2.Rows[i].Cells[4].Text = \"Done\";\n // you can format this cell \n }\n}\n" }, { "answer_id": 5570440, "author": "SEO Service", "author_id": 695317, "author_profile": "https://Stackoverflow.com/users/695317", "pm_score": 2, "selected": false, "text": "RowDataBound" }, { "answer_id": 12091252, "author": "Vaibhav Saran", "author_id": 362310, "author_profile": "https://Stackoverflow.com/users/362310", "pm_score": 0, "selected": false, "text": "Label lblSecret = ((Label)e.Row.FindControl(\"lblSecret\"));\n" }, { "answer_id": 12626043, "author": "Mark Meuer", "author_id": 9117, "author_profile": "https://Stackoverflow.com/users/9117", "pm_score": 1, "selected": false, "text": "<asp:TemplateField ...>" }, { "answer_id": 26269264, "author": "user3679550", "author_id": 3679550, "author_profile": "https://Stackoverflow.com/users/3679550", "pm_score": 0, "selected": false, "text": "<asp:TemplateField HeaderText=\"# Percentage click throughs\">\n <ItemTemplate>\n <%# AddPercentClickThroughs(Convert.ToDecimal(DataBinder.Eval(Container.DataItem, \"EmailSummary.pLinksClicked\")), Convert.ToDecimal(DataBinder.Eval(Container.DataItem, \"NumberOfSends\")))%>\n </ItemTemplate>\n</asp:TemplateField>\n\n\npublic string AddPercentClickThroughs(decimal NumberOfSends, decimal EmailSummary.pLinksClicked)\n{\n decimal OccupancyPercentage = 0;\n if (TotalNoOfRooms != 0 && RoomsOccupied != 0)\n {\n OccupancyPercentage = (Convert.ToDecimal(NumberOfSends) / Convert.ToDecimal(EmailSummary.pLinksClicked) * 100);\n }\n return OccupancyPercentage.ToString(\"F\");\n}\n" }, { "answer_id": 29454155, "author": "ashiq", "author_id": 4750795, "author_profile": "https://Stackoverflow.com/users/4750795", "pm_score": -1, "selected": false, "text": "protected void gvbind_RowDataBound(object sender, GridViewRowEventArgs e)\n{\n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n e.Row.Attributes[\"onmouseover\"] = \"this.style.cursor='hand';\";\n e.Row.Attributes[\"onmouseout\"] = \"this.style.textDecoration='none';\";\n e.Row.Attributes[\"onclick\"] = ClientScript.GetPostBackClientHyperlink(this.gvbind, \"Select$\" + e.Row.RowIndex);\n }\n}\n" }, { "answer_id": 41738662, "author": "vemund", "author_id": 5200895, "author_profile": "https://Stackoverflow.com/users/5200895", "pm_score": 0, "selected": false, "text": "<asp:BoundField DataField=\"F1\" HeaderText=\"F1\" Visible=\"False\"/>\n" }, { "answer_id": 62479479, "author": "Niklas", "author_id": 3956100, "author_profile": "https://Stackoverflow.com/users/3956100", "pm_score": 0, "selected": false, "text": "API" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121722", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3193/" ]
121,743
<p>Server virtualization is a big thing these days, so I'm tasked at work to install some of our software on a virtualized server and see what happens. Long story short: a <code>rsync</code> transfer promptly brings the virtualized server to its knees. The virtualization host is a beefy machine with no other load; I don't think this should be happening. <code>Top</code> shows high load averages, and cpu iowait near 100%. There's a huge bottleneck somewhere.</p> <p>I'm more a programmer than a sysadmin, I lack the knowledge on how to go about fixing this outside of random Googling. I suspect I'm not alone in this. </p> <p>What I'd like to see here is general advice on virtualization, and pointers to good articles and other resources, which I and others could use to educate ourselves. </p> <ul> <li>What tools (even standard unix tools) can be used to pinpoint bottlenecks?</li> <li>What metrics should be followed to ensure things run smoothly?</li> <li>What kind of things can be efficiently virtualized? </li> <li>What kind of setups are doomed to fail?</li> </ul> <p>I apologize the broadness of the question. I just don't have the knowledge to ask useful specific questions about this.</p> <p>Edit: More on my specific problem:</p> <ul> <li>XAN paravirtualization, 3 x guest CentOS</li> <li>All guests on local SCSI disks, there is a fully hardware raid controller</li> <li>rsyncd running on 1 guest os, transfer initiated from a remote non virtualized server through 100mbps LAN</li> </ul> <p>Like I said before, I really can't provide a ton of useful data. I'm not really expecting to get a direct solution to this problem, I'd be happy with pointers on where to start building the skillset required to better understand these kinds of problems.</p>
[ { "answer_id": 121790, "author": "mlambie", "author_id": 17453, "author_profile": "https://Stackoverflow.com/users/17453", "pm_score": 2, "selected": false, "text": "iostat" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18037/" ]
121,757
<p>I doubt it can be done portably, but are there any solutions out there? I think it could be done by creating an alternate stack and reseting SP,BP, and IP on function entry, and having yield save IP and restore SP+BP. Destructors and exception safety seem tricky but solvable.</p> <p>Has it been done? Is it impossible?</p>
[ { "answer_id": 121773, "author": "Steve g", "author_id": 12092, "author_profile": "https://Stackoverflow.com/users/12092", "pm_score": 3, "selected": false, "text": "next()" }, { "answer_id": 10776153, "author": "jhasse", "author_id": 647898, "author_profile": "https://Stackoverflow.com/users/647898", "pm_score": -1, "selected": false, "text": "#include <iostream>\n#include <thread>\n\nclass InterruptedException : public std::exception {\n};\n\nclass AsyncThread {\npublic:\n AsyncThread() {\n std::unique_lock<std::mutex> lock(mutex);\n thread.reset(new std::thread(std::bind(&AsyncThread::run, this)));\n conditionVar.wait(lock); // wait for the thread to start\n }\n ~AsyncThread() {\n {\n std::lock_guard<std::mutex> _(mutex);\n quit = true;\n }\n conditionVar.notify_all();\n thread->join();\n }\n void run() {\n try {\n yield();\n for (int i = 0; i < 7; ++i) {\n std::cout << i << std::endl;\n yield();\n }\n } catch (InterruptedException& e) {\n return;\n }\n std::lock_guard<std::mutex> lock(mutex);\n quit = true;\n conditionVar.notify_all();\n }\n void yield() {\n std::unique_lock<std::mutex> lock(mutex);\n conditionVar.notify_all();\n conditionVar.wait(lock);\n if (quit) {\n throw InterruptedException();\n }\n }\n void step() {\n std::unique_lock<std::mutex> lock(mutex);\n if (!quit) {\n conditionVar.notify_all();\n conditionVar.wait(lock);\n }\n }\nprivate:\n std::unique_ptr<std::thread> thread;\n std::condition_variable conditionVar;\n std::mutex mutex;\n bool quit = false;\n};\n\nint main() {\n AsyncThread asyncThread;\n for (int i = 0; i < 3; ++i) {\n std::cout << \"main: \" << i << std::endl;\n asyncThread.step();\n }\n}\n" }, { "answer_id": 41480339, "author": "user1095108", "author_id": 1095108, "author_profile": "https://Stackoverflow.com/users/1095108", "pm_score": 1, "selected": false, "text": "setjmp/longjmp" }, { "answer_id": 58273371, "author": "acppcoder", "author_id": 1267264, "author_profile": "https://Stackoverflow.com/users/1267264", "pm_score": 1, "selected": false, "text": "// Coprocess.h\n#pragma once\n#include <vector>\n\nclass Coprocess {\n public:\n Coprocess() : line_(0) {}\n void start() { line_ = 0; run(); }\n void end() { line_ = -1; on_end(); }\n virtual void run() = 0;\n virtual void on_end() {}; \n protected:\n int line_;\n};\n\nclass Event {\n public:\n Event() : curr_(0) {}\n\n void wait(Coprocess* p) { waiters_[curr_].push_back(p); }\n\n void notify() {\n Waiters& old = waiters_[curr_];\n curr_ = 1 - curr_; // move to next ping/pong set of waiters\n waiters_[curr_].clear();\n for (Waiters::const_iterator I=old.begin(), E=old.end(); I != E; ++I)\n (*I)->run();\n } \n private:\n typedef std::vector<Coprocess*> Waiters;\n int curr_;\n Waiters waiters_[2];\n};\n\n#define corun() run() { switch(line_) { case 0:\n#define cowait(e) line_=__LINE__; e.wait(this); return; case __LINE__:\n#define coend default:; }} void on_end()\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19193/" ]
121,762
<p>I have two threads in an Android application, one is the view thread, and the other is the worker thread. What I want to do is, sleep the worker thread until the view thread terminates the handling of the onDraw method.</p> <p>How i can do this? is there any wait for the signal or something?</p>
[ { "answer_id": 121853, "author": "Paul Brinkley", "author_id": 18160, "author_profile": "https://Stackoverflow.com/users/18160", "pm_score": 6, "selected": true, "text": "stick.wait();\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7363/" ]
121,795
<p>My question is, which version-naming scheme should be used for what type of project.</p> <p>Very common is major.minor.fix, but even this can lead to 4 number (i.e. Firefox 2.0.0.16). Some have a model that odd numbers indicate developer-versions and even numbers stable releases. And all sorts of additions can enter the mix, like -dev3, -rc1, SP2 etc.</p> <p>Exists reasons to prefer one scheme over another and should different type of projects (i.e. Open Source vs. Closed Source) have different version naming schemes?</p>
[ { "answer_id": 121819, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 3, "selected": false, "text": "dev" }, { "answer_id": 305321, "author": "Ramesh Soni", "author_id": 191, "author_profile": "https://Stackoverflow.com/users/191", "pm_score": 1, "selected": false, "text": "Major.Minor.Revision.Build\n" }, { "answer_id": 882516, "author": "David", "author_id": 67468, "author_profile": "https://Stackoverflow.com/users/67468", "pm_score": 6, "selected": true, "text": "Major.Minor.Revision.Build" }, { "answer_id": 16386825, "author": "Emre Yazici", "author_id": 220726, "author_profile": "https://Stackoverflow.com/users/220726", "pm_score": 3, "selected": false, "text": "major" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21005/" ]
121,808
<p>I can use properties of an Excel Worksheet to tell if the worksheet is protected (Worksheet.Protection, Worksheet.ProtectContents etc).</p> <p>How can I tell using VBA if the entire workbook has been protected?</p>
[ { "answer_id": 121840, "author": "Guy Starbuck", "author_id": 2194, "author_profile": "https://Stackoverflow.com/users/2194", "pm_score": 2, "selected": false, "text": "Public Function wbAllSheetsProtected(wbTarget As Workbook) As Boolean \n\nDim ws As Worksheet \n\nwbAllSheetsProtected = True\n\nFor Each ws In wbTarget.Worksheets \n If ws.ProtectContents = False Then \n wbAllProtected = False\n Exit Function \n End If \nNext ws \n\nEnd Function\n" }, { "answer_id": 121913, "author": "Joe", "author_id": 13087, "author_profile": "https://Stackoverflow.com/users/13087", "pm_score": 4, "selected": true, "text": "Workbook.ProtectStructure" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121808", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13087/" ]
121,810
<p><strong>Is there any way that I can remove the Print item from the context menu when you right-click on an email with VBA?</strong></p> <p>I am forever right-clicking to reply to an email, only to accidentally click <code>Print</code> and have Outlook send it directly to the printer quicker than I can stop it.</p> <p><img src="https://farm4.static.flickr.com/3221/2882658372_496d6e7a11_o.jpg" alt="alt text"></p> <p><strong>NB:</strong> I am using Outlook 2007.</p>
[ { "answer_id": 582063, "author": "Will Rickards", "author_id": 290835, "author_profile": "https://Stackoverflow.com/users/290835", "pm_score": 4, "selected": true, "text": "Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Selection)\n\n Dim cmdTemp As Office.CommandBarControl\n\n If Selection.Count > 0 Then\n\n Select Case TypeName(Selection.Item(1))\n\n Case \"MailItem\"\n\n For Each cmdTemp In CommandBar.Controls\n\n If cmdTemp.Caption = \"&Print\" Then\n\n cmdTemp.Delete\n Exit For\n\n End If\n\n Next cmdTemp\n\n Case Else\n\n 'Debug.Print TypeName(Selection.Item(1))\n\n End Select\n\n End If\n\nEnd Sub\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
121,813
<p>We have redesigned the structure to a website which has several business units. Now I want to redirect (301) to the new page.</p> <p>IE: <br /> was www.example.com/abc <br /> now www.example.com/default.aspx?article=abc <br /></p> <p>I have tried to use Global.asax to do this, and it works properly when I debug through it.</p> <pre><code> if (Request.RawUrl.Contains("abc")) { Response.RedirectLocation = "/default.aspx?article=abc"; Response.StatusCode = 301; Response.StatusDescription = "Moved"; Response.End(); } </code></pre> <p>So <a href="http://localhost:1234/example/abc" rel="nofollow noreferrer">http://localhost:1234/example/abc</a> redirects properly, but (where 1234 is the port for the debugging server)<br/> <a href="http://localhost/example/abc" rel="nofollow noreferrer">http://localhost/example/abc</a> does not redirect, it gives me a 404.</p> <p>Any ideas?</p> <hr> <p>Additional info: If I go to <a href="http://localhost/example/abc/default.aspx" rel="nofollow noreferrer">http://localhost/example/abc/default.aspx</a> then it redirects properly.</p>
[ { "answer_id": 121893, "author": "Dave Anderson", "author_id": 371, "author_profile": "https://Stackoverflow.com/users/371", "pm_score": 2, "selected": false, "text": " *; www.example.com/*; www.example.com/default.aspx?article=$0\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18821/" ]
121,817
<p>I need to set the text within a DIV element dynamically. What is the best, browser safe approach? I have prototypejs and scriptaculous available.</p> <pre><code>&lt;div id="panel"&gt; &lt;div id="field_name"&gt;TEXT GOES HERE&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Here's what the function will look like:</p> <pre><code>function showPanel(fieldName) { var fieldNameElement = document.getElementById('field_name'); //Make replacement here } </code></pre>
[ { "answer_id": 121822, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 4, "selected": false, "text": "$('field_name').innerHTML = 'Your text.';\n" }, { "answer_id": 121824, "author": "17 of 26", "author_id": 2284, "author_profile": "https://Stackoverflow.com/users/2284", "pm_score": 8, "selected": false, "text": "fieldNameElement.innerHTML = \"My new text!\";\n" }, { "answer_id": 121825, "author": "Milan Babuškov", "author_id": 14690, "author_profile": "https://Stackoverflow.com/users/14690", "pm_score": 3, "selected": false, "text": "if (fieldNameElement)\n fieldNameElement.innerHTML = 'some HTML';\n" }, { "answer_id": 121859, "author": "John Topley", "author_id": 1450, "author_profile": "https://Stackoverflow.com/users/1450", "pm_score": 7, "selected": true, "text": "update" }, { "answer_id": 121874, "author": "hollystyles", "author_id": 2083160, "author_profile": "https://Stackoverflow.com/users/2083160", "pm_score": 0, "selected": false, "text": "function showPanel(fieldName) {\n var fieldNameElement = document.getElementById(field_name);\n\n fieldNameElement.removeChild(fieldNameElement.firstChild);\n var newText = document.createTextNode(\"New Text\");\n fieldNameElement.appendChild(newText);\n}\n" }, { "answer_id": 121877, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 4, "selected": false, "text": "document.getElementById(\"field_name\").innerText = newText;\n" }, { "answer_id": 121898, "author": "Daniel Papasian", "author_id": 7548, "author_profile": "https://Stackoverflow.com/users/7548", "pm_score": 6, "selected": false, "text": "\nfunction showPanel(fieldName) {\n var fieldNameElement = document.getElementById(\"field_name\");\n while(fieldNameElement.childNodes.length >= 1) {\n fieldNameElement.removeChild(fieldNameElement.firstChild);\n }\n fieldNameElement.appendChild(fieldNameElement.ownerDocument.createTextNode(fieldName));\n}\n" }, { "answer_id": 2326249, "author": "Cosmin", "author_id": 280352, "author_profile": "https://Stackoverflow.com/users/280352", "pm_score": 0, "selected": false, "text": "var el = $('#yourid .yourclass');\n\nel.html(el.html().replace(/Old Text/ig, \"New Text\"));\n" }, { "answer_id": 3339069, "author": "palswim", "author_id": 393280, "author_profile": "https://Stackoverflow.com/users/393280", "pm_score": 3, "selected": false, "text": "function showPanel(fieldName) {\n var fieldNameElement = document.getElementById(field_name);\n if(fieldNameElement.firstChild)\n fieldNameElement.firstChild.nodeValue = \"New Text\";\n}\n" }, { "answer_id": 8260506, "author": "Adrian Adkison", "author_id": 158095, "author_profile": "https://Stackoverflow.com/users/158095", "pm_score": 2, "selected": false, "text": "el.innerHTML='';\nel.appendChild(document.createTextNode(\"yo\"));\n" }, { "answer_id": 18723036, "author": "mikemaccana", "author_id": 123671, "author_profile": "https://Stackoverflow.com/users/123671", "pm_score": 8, "selected": false, "text": "fieldNameElement.textContent = \"New text\";\n" }, { "answer_id": 61691911, "author": "Trees", "author_id": 10350895, "author_profile": "https://Stackoverflow.com/users/10350895", "pm_score": 0, "selected": false, "text": "<div id=\"field_name\">TEXT GOES HERE</div>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4893/" ]
121,821
<p>I am creating an SQL view for a file that strips out the spaces in a particular field. My question is if there is a why to set a key on that new view so a person can still CHAIN the file. We are on V5R3.</p>
[ { "answer_id": 149414, "author": "Chris Smith", "author_id": 9073, "author_profile": "https://Stackoverflow.com/users/9073", "pm_score": 0, "selected": false, "text": "OPNQRYF" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2535/" ]
121,827
<p>I'm looking to implement an ESB and wanted to get thoughts related to "how" my web services might change (WCF) or -- how my client apps that consume these services might "need to be revised" (-- other than a new service ref to the ESB path --)</p> <p>The device I'm working with specifically is the "WebSphere DataPower XML Security Gateway XS40"</p>
[ { "answer_id": 149414, "author": "Chris Smith", "author_id": 9073, "author_profile": "https://Stackoverflow.com/users/9073", "pm_score": 0, "selected": false, "text": "OPNQRYF" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2701/" ]
121,828
<p>I'm stuck with the following problem. I'm trying to implement a basic GridView paged result set, which connects to an Oracle database. By itself, the GridView, and the paged results, work fine. The problem comes when I try to put it in page layout class that we have at work.</p> <p>We have ClassA, which inherits from Page, and is a corporate standard. Then I have ClassB, which inherits from ClassA and which includes application-specific code. The page that the GridView is on inherits from ClassB. This all seems to work fine in other pages, and I don't think it's the source of the problem, but I thought I'd mention it.</p> <p>What happens is that the first time the page with the GridView loads, everything looks normal. The query runs and the first 10 records are displayed, with the numbers for paging below. When I click on "2" or any of the other pages, I get the "yellow screen of death" with the following message: "Object reference not set to an instance of an object". The object being referred to in that error line is "Me", the Page object (ASP.pagename_aspx in the debugger). I don't believe that the exact line it fails on is that important, because I've switched the order of a few statements around and it just fails on the earliest one. </p> <p>I've traced through with the debugger and it looks normal, only that on Page 1 it works fine, and Page 2 it fails. </p> <p>I have implemented the PageIndexChanging event (again, it works by itself if I remove inheritance from ClassB. Also, if I try inheriting directly from ClassA (bypassing ClassB entirely), I still get the problem.</p> <p>Any ideas? Thanks.</p>
[ { "answer_id": 196035, "author": "Toran Billups", "author_id": 2701, "author_profile": "https://Stackoverflow.com/users/2701", "pm_score": 1, "selected": false, "text": "<asp:GridView ID=\"gridSuppliers\" EnableViewState=\"false\" runat=\"server\" OnPageIndexChanging=\"gridSuppliers_PageIndexChanging\" AutoGenerateColumns=\"false\" AllowPaging=\"true\" AllowSorting=\"true\" CssClass=\"datatable\" CellPadding=\"0\" CellSpacing=\"0\" BorderWidth=\"0\" GridLines=\"None\">...</asp:GridView>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121828", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
121,847
<p>I hear logarithms mentioned quite a lot in the programming context. They seem to be the solution to many problems and yet I can't seem to find a real-world way of making use of them. I've read the <a href="http://en.wikipedia.org/wiki/Logarithms" rel="noreferrer">Wikipedia entry</a> and that, quite frankly, leaves me none the wiser.</p> <p><strong>So, where can I learn about the real-world programming problems that logarithms solve?</strong> Has anyone got any examples of problems they faced that were solved by implementing a logarithm?</p>
[ { "answer_id": 125030, "author": "joel.neely", "author_id": 3525, "author_profile": "https://Stackoverflow.com/users/3525", "pm_score": 1, "selected": false, "text": "a = b + c\n" }, { "answer_id": 492040, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "p * (1 + r)^y = n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1944/" ]
121,849
<p>I'm not sure how I should express this, but I'll give it a try. <br /> I recently started coding my portfolio in object-oriented PHP and I'm wondering if it's according to best practices to use a single page where the content changes depending on SQL data and the $_GET variable?</p> <p>If so/not, why?</p> <p>Edit: Take a look at my next post, more in-depth details.</p>
[ { "answer_id": 121943, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 2, "selected": false, "text": "<?php\nrequire ('config.php')\nrequire ('start.php')\nrequire ('header.php')\n//custom page stuff\nrequire ('footer.php')\n?>\n" }, { "answer_id": 122333, "author": "K4emic", "author_id": 348430, "author_profile": "https://Stackoverflow.com/users/348430", "pm_score": 0, "selected": false, "text": "require_once 'config.php';\nrequire_once 'class_lib/template.php';\n\n$template = new template($config);\n$template->dataQuery();\n$template->pageCheck();\n$template->titleAssembly();\n$template->cssAssembly();\n$template->metaAssembly();\n$template->menuAssembly();\n$template->content();\necho $template->publish();\n" }, { "answer_id": 123588, "author": "Overbeeke", "author_id": 21238, "author_profile": "https://Stackoverflow.com/users/21238", "pm_score": 0, "selected": false, "text": "<Files site>\nForceType application/x-httpd-php \n</Files>\n" }, { "answer_id": 284471, "author": "Jason Moore", "author_id": 18158, "author_profile": "https://Stackoverflow.com/users/18158", "pm_score": 0, "selected": false, "text": "require('sitelib');\ndo_header('about', 'About Us');\n// content here\ndo_footer();\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/348430/" ]
121,864
<p>As compared to say:</p> <pre><code>REPLICATE(@padchar, @len - LEN(@str)) + @str </code></pre>
[ { "answer_id": 121890, "author": "AlexCuse", "author_id": 794, "author_profile": "https://Stackoverflow.com/users/794", "pm_score": 9, "selected": true, "text": "right('XXXXXXXXXXXX'+ rtrim(@str), @n)\n" }, { "answer_id": 121896, "author": "Tom H", "author_id": 5696608, "author_profile": "https://Stackoverflow.com/users/5696608", "pm_score": 3, "selected": false, "text": "DECLARE\n @pad_characters VARCHAR(10)\n\nSET @pad_characters = '0000000000'\n\nSELECT RIGHT(@pad_characters + @str, 10)\n" }, { "answer_id": 121901, "author": "Sklivvz", "author_id": 7028, "author_profile": "https://Stackoverflow.com/users/7028", "pm_score": 4, "selected": false, "text": "@padstr = REPLICATE(@padchar, @len) -- this can be cached, done only once\n\nSELECT RIGHT(@padstr + @str, @len)\n" }, { "answer_id": 121917, "author": "Gordon Bell", "author_id": 16473, "author_profile": "https://Stackoverflow.com/users/16473", "pm_score": 1, "selected": false, "text": "select right(replicate(@padchar, @len) + @str, @len)\n" }, { "answer_id": 121968, "author": "ila", "author_id": 1178, "author_profile": "https://Stackoverflow.com/users/1178", "pm_score": 2, "selected": false, "text": "CREATE FUNCTION [dbo].[f_pad_before](@string VARCHAR(255), @desired_length INTEGER, @pad_character CHAR(1))\nRETURNS VARCHAR(255) AS \nBEGIN\n\n-- Prefix the required number of spaces to bulk up the string and then replace the spaces with the desired character\n RETURN ltrim(rtrim(\n CASE\n WHEN LEN(@string) < @desired_length\n THEN REPLACE(SPACE(@desired_length - LEN(@string)), ' ', @pad_character) + @string\n ELSE @string\n END\n ))\nEND\n" }, { "answer_id": 140089, "author": "Kevin", "author_id": 19038, "author_profile": "https://Stackoverflow.com/users/19038", "pm_score": 5, "selected": false, "text": "right('XXXXXXXXXXXX'+ @str, @n)\n" }, { "answer_id": 678126, "author": "joshblair", "author_id": 79122, "author_profile": "https://Stackoverflow.com/users/79122", "pm_score": 1, "selected": false, "text": "replace((space(3 - len(MyField))\n" }, { "answer_id": 2982326, "author": "TonyP", "author_id": 225394, "author_profile": "https://Stackoverflow.com/users/225394", "pm_score": 3, "selected": false, "text": "ALTER Function [dbo].[fsPadLeft](@var varchar(200),@padChar char(1)='0',@len int)\nreturns varchar(300)\nas\nBegin\n\nreturn replicate(@PadChar,@len-Len(@var))+@var\n\nend\n" }, { "answer_id": 4389352, "author": "Ahmad", "author_id": 535212, "author_profile": "https://Stackoverflow.com/users/535212", "pm_score": 2, "selected": false, "text": "REPLACE(STR(FACT_HEAD.FACT_NO, x, 0), ' ', y)\n" }, { "answer_id": 6372730, "author": "vnRock", "author_id": 512327, "author_profile": "https://Stackoverflow.com/users/512327", "pm_score": 2, "selected": false, "text": "STUFF ( character_expression , start , length ,character_expression )\n\nselect stuff(@str, 1, 0, replicate('0', @n - len(@str)))\n" }, { "answer_id": 7499464, "author": "Deanos", "author_id": 685717, "author_profile": "https://Stackoverflow.com/users/685717", "pm_score": -1, "selected": false, "text": "WHILE Len(@String) < 8\nBEGIN\n SELECT @String = '0' + @String\nEND\n" }, { "answer_id": 7931179, "author": "Kevin", "author_id": 1018604, "author_profile": "https://Stackoverflow.com/users/1018604", "pm_score": 2, "selected": false, "text": "create function PadLeft(\n @String varchar(8000)\n ,@NumChars int\n ,@PadChar char(1) = ' ')\nreturns varchar(8000)\nas\nbegin\n return stuff(@String, 1, 0, replicate(@PadChar, @NumChars - len(@String)))\nend\n" }, { "answer_id": 9763742, "author": "mattpm", "author_id": 590021, "author_profile": "https://Stackoverflow.com/users/590021", "pm_score": -1, "selected": false, "text": "DECLARE @value = 20.1\nSET @value = ROUND(@value,2) * 100\nPRINT LEFT(CAST(@value AS VARCHAR(20)), LEN(@value)-2) + '.' + RIGHT(CAST(@value AS VARCHAR(20)),2)\n" }, { "answer_id": 16678606, "author": "Joseph Morgan", "author_id": 1440294, "author_profile": "https://Stackoverflow.com/users/1440294", "pm_score": 0, "selected": false, "text": "/*===============================================================\n Author : Joey Morgan\n Create date : November 1, 2012\n Description : Pads the string @MyStr with the character in \n : @PadChar so all results have the same length\n ================================================================*/\n CREATE FUNCTION [dbo].[svfn_AMS_PAD_STRING]\n (\n @MyStr VARCHAR(25),\n @LENGTH INT,\n @PadChar CHAR(1) = NULL\n )\nRETURNS VARCHAR(25)\n AS \n BEGIN\n SET @PadChar = ISNULL(@PadChar, '0');\n DECLARE @Result VARCHAR(25);\n SELECT\n @Result = RIGHT(SUBSTRING(REPLICATE('0', @LENGTH), 1,\n (@LENGTH + 1) - LEN(RTRIM(@MyStr)))\n + RTRIM(@MyStr), @LENGTH)\n\n RETURN @Result\n\n END\n" }, { "answer_id": 26107021, "author": "jediCouncilor", "author_id": 900953, "author_profile": "https://Stackoverflow.com/users/900953", "pm_score": 6, "selected": false, "text": "declare @n as int = 2\nselect FORMAT(@n, 'd10') as padWithZeros\n" }, { "answer_id": 44188657, "author": "Mass Dot Net", "author_id": 165494, "author_profile": "https://Stackoverflow.com/users/165494", "pm_score": 0, "selected": false, "text": " --[@charToPadStringWith] is the character you want to pad the string with.\ndeclare @charToPadStringWith char(1) = 'X';\n\n-- Generate a table of values to test with.\ndeclare @stringValues table (RowId int IDENTITY(1,1) NOT NULL PRIMARY KEY, StringValue varchar(max) NULL);\ninsert into @stringValues (StringValue) values (null), (''), ('_'), ('A'), ('ABCDE'), ('1234567890');\n\n-- Generate a table to store testing results in.\ndeclare @testingResults table (RowId int IDENTITY(1,1) NOT NULL PRIMARY KEY, StringValue varchar(max) NULL, PaddedStringValue varchar(max) NULL);\n\n-- Get the length of the longest string, then pad all strings based on that length.\ndeclare @maxLengthOfPaddedString int = (select MAX(LEN(StringValue)) from @stringValues);\ndeclare @longestStringValue varchar(max) = (select top(1) StringValue from @stringValues where LEN(StringValue) = @maxLengthOfPaddedString);\nselect [@longestStringValue]=@longestStringValue, [@maxLengthOfPaddedString]=@maxLengthOfPaddedString;\n\n-- Loop through each of the test string values, apply padding to it, and store the results in [@testingResults].\nwhile (1=1)\nbegin\n declare\n @stringValueRowId int,\n @stringValue varchar(max);\n\n -- Get the next row in the [@stringLengths] table.\n select top(1) @stringValueRowId = RowId, @stringValue = StringValue\n from @stringValues \n where RowId > isnull(@stringValueRowId, 0) \n order by RowId;\n\n if (@@ROWCOUNT = 0) \n break;\n\n -- Here is where the padding magic happens.\n declare @paddedStringValue varchar(max) = RIGHT(REPLICATE(@charToPadStringWith, @maxLengthOfPaddedString) + @stringValue, @maxLengthOfPaddedString);\n\n -- Added to the list of results.\n insert into @testingResults (StringValue, PaddedStringValue) values (@stringValue, @paddedStringValue);\nend\n\n-- Get all of the testing results.\nselect * from @testingResults;\n" }, { "answer_id": 55034858, "author": "blind Skwirl", "author_id": 5271220, "author_profile": "https://Stackoverflow.com/users/5271220", "pm_score": 0, "selected": false, "text": "CREATE FUNCTION PadStringTrim \n(\n @inputStr varchar(500), \n @finalLength int, \n @padChar varchar (1),\n @padSide varchar(1)\n)\nRETURNS VARCHAR(500)\n\nAS BEGIN\n -- the point of this function is to avoid using replicate which is extremely slow in SQL Server\n -- to get away from this though we now have a limitation of how much padding we can add, so I've settled on a hundred character pad \n DECLARE @padding VARCHAR (100) = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'\n SET @padding = REPLACE(@padding, 'X', @padChar)\n\n\n SET @inputStr = RTRIM(LTRIM(@inputStr))\n\n IF LEN(@inputStr) > @finalLength \n RETURN '!ERROR!' -- can search for ! in the returned text \n\n ELSE IF(@finalLength > LEN(@inputStr))\n IF @padSide = 'L'\n SET @inputStr = RIGHT(@padding + @inputStr, @finalLength)\n --SET @inputStr = REPLICATE(@padChar, @finalLength - LEN(@inputStr)) + @inputStr\n ELSE IF @padSide = 'R'\n SET @inputStr = LEFT(@inputStr + @padding, @finalLength)\n --SET @inputStr = @inputStr + REPLICATE(@padChar, @finalLength - LEN(@inputStr)) \n\n\n\n -- if LEN(@inputStr) = @finalLength we just return it \n RETURN @inputStr;\nEND\n\n-- SELECT dbo.PadStringTrim( tblAccounts.account, 20, '~' , 'R' ) from tblAccounts\n-- SELECT dbo.PadStringTrim( tblAccounts.account, 20, '~' , 'L' ) from tblAccounts\n" }, { "answer_id": 57532237, "author": "Pancho R", "author_id": 11938268, "author_profile": "https://Stackoverflow.com/users/11938268", "pm_score": 0, "selected": false, "text": "IF LEN(@string)=@length\nBEGIN\n IF CHARINDEX('.',@string)>0\n BEGIN\n SELECT @resp = CASE SIGN(@string)\n WHEN -1 THEN\n -- Nros negativos grandes con decimales\n concat('-',SUBSTRING(replicate(@pad,@length),1,@length-len(@string)),ltrim(str(abs(@string),@length,@dec)))\n ELSE\n -- Nros positivos grandes con decimales\n concat(SUBSTRING(replicate(@pad,@length),1,@length-len(@string)),ltrim(str(@string,@length,@dec))) \n END\n END\n ELSE\n BEGIN\n SELECT @resp = CASE SIGN(@string)\n WHEN -1 THEN\n --Nros negativo grande sin decimales\n concat('-',SUBSTRING(replicate(@pad,@length),1,(@length-3)-len(@string)),ltrim(str(abs(@string),@length,@dec)))\n ELSE\n -- Nros positivos grandes con decimales\n concat(SUBSTRING(replicate(@pad,@length),1,@length-len(@string)),ltrim(str(@string,@length,@dec))) \n END \n END\nEND\nELSE\n IF CHARINDEX('.',@string)>0\n BEGIN\n SELECT @resp =CASE SIGN(@string)\n WHEN -1 THEN\n -- Nros negativos con decimales\n concat('-',SUBSTRING(replicate(@pad,@length),1,@length-len(@string)),ltrim(str(abs(@string),@length,@dec)))\n ELSE\n --Ntos positivos con decimales\n concat(SUBSTRING(replicate(@pad,@length),1,@length-len(@string)),ltrim(str(abs(@string),@length,@dec))) \n END\n END\n ELSE\n BEGIN\n SELECT @resp = CASE SIGN(@string)\n WHEN -1 THEN\n -- Nros Negativos sin decimales\n concat('-',SUBSTRING(replicate(@pad,@length-3),1,(@length-3)-len(@string)),ltrim(str(abs(@string),@length,@dec)))\n ELSE\n -- Nros Positivos sin decimales\n concat(SUBSTRING(replicate(@pad,@length),1,(@length-3)-len(@string)),ltrim(str(abs(@string),@length,@dec)))\n END\n END\nRETURN @resp\n" }, { "answer_id": 64320371, "author": "DGM0522", "author_id": 14436698, "author_profile": "https://Stackoverflow.com/users/14436698", "pm_score": 0, "selected": false, "text": "CREATE OR ALTER FUNCTION code.fnConvert_PadLeft(\n @in_str nvarchar(1024),\n @pad_length int, \n @pad_char nchar(1) = ' ', \n @rtn_null NVARCHAR(1024) = '')\nRETURNS NVARCHAR(1024)\nAS\nBEGIN\n DECLARE @rtn NCHAR(1024) = ' '\n RETURN RIGHT(REPLACE(@rtn,' ',@pad_char)+ISNULL(@in_str,@rtn_null), @pad_length)\nEND\nGO\n\nCREATE OR ALTER FUNCTION code.fnConvert_PadRight(\n @in_str nvarchar(1024), \n @pad_length int, \n @pad_char nchar(1) = ' ', \n @rtn_null NVARCHAR(1024) = '')\nRETURNS NVARCHAR(1024)\nAS\nBEGIN\n DECLARE @rtn NCHAR(1024) = ' '\n RETURN LEFT(ISNULL(@in_str,@rtn_null)+REPLACE(@rtn,' ',@pad_char), @pad_length)\nEND\nGO \n\n-- Example\nSET STATISTICS time ON \nSELECT code.fnConvert_PadLeft('88',10,'0',''), \n code.fnConvert_PadLeft(null,10,'0',''), \n code.fnConvert_PadLeft(null,10,'0',null), \n code.fnConvert_PadRight('88',10,'0',''), \n code.fnConvert_PadRight(null,10,'0',''),\n code.fnConvert_PadRight(null,10,'0',NULL)\n\n\n0000000088 0000000000 NULL 8800000000 0000000000 NULL\n\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18255/" ]
121,866
<p>I'm preparing to deploy my Django app and I noticed that when I change the "DEBUG" setting to False, all references to static files (i.e., JavaScript, CSS, etc..) result in <code>HTTP 500</code> errors.</p> <p>Any idea what's causing that issue (and how to fix it)?</p>
[ { "answer_id": 122052, "author": "Peter Shinners", "author_id": 17209, "author_profile": "https://Stackoverflow.com/users/17209", "pm_score": 5, "selected": true, "text": "urls.py" }, { "answer_id": 38675118, "author": "wcyn", "author_id": 2878244, "author_profile": "https://Stackoverflow.com/users/2878244", "pm_score": 0, "selected": false, "text": "SECRET_KEY" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10040/" ]
121,922
<p>I am currently suffering a brain fart. I've done this before but I can't remember the exact syntax and I can't look at the code I wrote because I was working at another company at the time. I have this arrangement:</p> <pre><code>class P { // stuff }; class PW : public P { // more stuff }; class PR : public P { // more stuff }; class C { public: P GetP() const { return p; } private: P p; }; // ... P p = c.GetP( ); // valid PW p = c.GetP( ); // invalid PR p = c.GetP( ); // invalid // ... </code></pre> <p>Now I would like to make P interchangeable with PW and PR (and thus PW and PR can be interchanged). I could probably get away with casts but this code change has occurred quite a few times in this module alone. I am pretty sure it is a operator but for the life of me I can't remember what.</p> <p><strong>How do I make P interchangeable with PW and PR with minimal amount of code?</strong></p> <p><strong>Update:</strong> To give a bit more clarification. P stands for Project and the R and W stands for Reader and Writer respectively. All the Reader has is the code for loading - no variables, and the writer has code for simply Writing. It needs to be separate because the Reading and Writing sections has various manager classes and dialogs which is none of Projects real concern which is the manipulation of project files.</p> <p><strong>Update:</strong> I also need to be able to call the methods of P and PW. So if P has a method a() and PW as a method call b() then I could :</p> <pre><code>PW p = c.GetP(); p.a(); p.b(); </code></pre> <p>It's basically to make the conversion transparent.</p>
[ { "answer_id": 121944, "author": "Carl Seleborg", "author_id": 2095, "author_profile": "https://Stackoverflow.com/users/2095", "pm_score": 2, "selected": false, "text": "PW p = c.GetP()" }, { "answer_id": 121964, "author": "coppro", "author_id": 16855, "author_profile": "https://Stackoverflow.com/users/16855", "pm_score": -1, "selected": false, "text": "class C\n{\n public:\n P* GetP() const { return p; }\n private:\n P* p;\n};\n" }, { "answer_id": 122004, "author": "Harper Shelby", "author_id": 21196, "author_profile": "https://Stackoverflow.com/users/21196", "pm_score": 2, "selected": false, "text": "class C\n\n {\n public: \n P* GetP() const { return p; }\n private:\n P* p;\n }\n" }, { "answer_id": 122075, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 1, "selected": false, "text": "class C\n{\n public:\n C(std::auto_ptr<P> x):\n p(x)\n {\n if (p.get() == NULL) {throw BadInit;}\n }\n // Return a reference.\n P& GetP() const { return *p; } \n private:\n // I use auto_ptr just as an example\n // there are many different valid ways to do this.\n // Once the object is correctly initialized p is always valid.\n std::auto_ptr<P> p;\n};\n\n// ...\nP& p = c.GetP( ); // valid\nPW& p = dynamic_cast<PW>(c.GetP( )); // valid Throws exception if not PW\nPR& p = dynamic_cast<PR>(c.GetP( )); // valid Thorws exception if not PR\n// ...\n" }, { "answer_id": 122265, "author": "James Hopkin", "author_id": 11828, "author_profile": "https://Stackoverflow.com/users/11828", "pm_score": 1, "selected": false, "text": "class P\n{\npublic:\n template <typename T>\n operator T() const\n {\n T t;\n static_cast<T&>(t) = *this;\n return t;\n }\n};\n" }, { "answer_id": 122443, "author": "Greg Rogers", "author_id": 5963, "author_profile": "https://Stackoverflow.com/users/5963", "pm_score": 3, "selected": true, "text": "\n\n// ...\n P p = c.GetP( ); // valid\n PW p = c.GetP( ); // invalid\n PR p = c.GetP( ); // invalid\n// ...\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/342/" ]
121,946
<p>Ok, so I just ran into the following problem that raised an eyebrow.</p> <p>For various reasons I have a testing setup where Testing classes in a TestingAssembly.dll depend on the TestingBase class in a BaseTestingAssembly.dll. One of the things the TestBase does in the meantime is look for a certain embedded resource in its own and the calling assembly</p> <p>So my BaseTestingAssembly contained the following lines...</p> <pre><code>public class TestBase { private static Assembly _assembly; private static Assembly _calling_assembly; static TestBase() { _assembly = Assembly.GetExecutingAssembly(); _calling_assembly = Assembly.GetCallingAssembly(); } } </code></pre> <p>Static since I figured, these assemblies would be the same over the application's lifetime so why bother recalculating them on every single test.</p> <p>When running this however I noticed that both _assembly and _calling_assembly were being set to BaseTestingAssembly rather than BaseTestingAssembly and TestingAssembly respectively.</p> <p>Setting the variables to non-static and having them initialized in a regular constructor fixed this but I am confused why this happened to begin this. I thought static constructors run the first time a static member gets referenced. This could only have been from my TestingAssembly which should then have been the caller. Does anyone know what might have happened?</p>
[ { "answer_id": 122060, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 4, "selected": true, "text": "private static Assembly _assembly;\nprivate static Assembly Assembly {\n get {\n if (_assembly == null) _assembly = Assembly.GetExecutingAssembly();\n return _assembly;\n }\n}\n\nprivate static Assembly _calling_assembly;\nprivate static Assembly CallingAssembly {\n get {\n if (_calling_assembly == null) _calling_assembly = Assembly.GetCallingAssembly();\n return _calling_assembly;\n }\n}\n" }, { "answer_id": 341142, "author": "chilltemp", "author_id": 28736, "author_profile": "https://Stackoverflow.com/users/28736", "pm_score": 1, "selected": false, "text": "private static Assembly GetMyCallingAssembly()\n{\n Assembly me = Assembly.GetExecutingAssembly();\n\n StackTrace st = new StackTrace(false);\n foreach (StackFrame frame in st.GetFrames())\n {\n MethodBase m = frame.GetMethod();\n if (m != null && m.DeclaringType != null && m.DeclaringType.Assembly != me)\n return m.DeclaringType.Assembly;\n }\n\n return null;\n}\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121946", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
121,962
<p>How can I consistently get the absolute, fully-qualified root or base url of the site regardless of whether the site is in a virtual directory and regardless of where my code is in the directory structure? I've tried every variable and function I can think of and haven't found a good way.</p> <p>I want to be able to get the url of the current site, i.e. <a href="http://www.example.com" rel="nofollow noreferrer">http://www.example.com</a> or if it's a virtual directory, <a href="http://www.example.com/DNN/" rel="nofollow noreferrer">http://www.example.com/DNN/</a></p> <hr> <p>Here's some of the things I've tried and the result. The only one that includes the whole piece that I want (<a href="http://localhost:4471/DNN441" rel="nofollow noreferrer">http://localhost:4471/DNN441</a>) is Request.URI.AbsoluteURI:</p> <ul> <li>Request.PhysicalPath: C:\WebSites\DNN441\Default.aspx</li> <li>Request.ApplicationPath: /DNN441</li> <li>Request.PhysicalApplicationPath: C:\WebSites\DNN441\</li> <li>MapPath: C:\WebSites\DNN441\DesktopModules\Articles\Templates\Default.aspx</li> <li>RawURL: /DNN441/ModuleTesting/Articles/tabid/56/ctl/Details/mid/374/ItemID/1/Default.aspx</li> <li>Request.Url.AbsoluteUri: <a href="http://localhost:4471/DNN441/Default.aspx" rel="nofollow noreferrer">http://localhost:4471/DNN441/Default.aspx</a></li> <li>Request.Url.AbsolutePath: /DNN441/Default.aspx</li> <li>Request.Url.LocalPath: /DNN441/Default.aspx Request.Url.Host: localhost</li> <li>Request.Url.PathAndQuery: /DNN441/Default.aspx?TabId=56&amp;ctl=Details&amp;mid=374&amp;ItemID=1</li> </ul>
[ { "answer_id": 121997, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 0, "selected": false, "text": "<a href='/'>goes to root</a>" }, { "answer_id": 231475, "author": "EfficionDave", "author_id": 4318, "author_profile": "https://Stackoverflow.com/users/4318", "pm_score": 5, "selected": true, "text": "Public Shared Function GetFullyQualifiedURL(ByVal s as string) As String\n Dim Result as URI = New URI(HttpContext.Current.Request.Url, s)\n Return Result.ToString\nEnd Function\n" }, { "answer_id": 1588605, "author": "devio", "author_id": 21336, "author_profile": "https://Stackoverflow.com/users/21336", "pm_score": 2, "selected": false, "text": "string appPath = null;\n\nappPath = string.Format(\"{0}://{1}{2}{3}\",\n Request.Url.Scheme,\n Request.Url.Host,\n Request.Url.Port == 80 ? string.Empty : \":\" + Request.Url.Port,\n Request.ApplicationPath);\n" }, { "answer_id": 7112493, "author": "Scott Stafford", "author_id": 237091, "author_profile": "https://Stackoverflow.com/users/237091", "pm_score": 3, "selected": false, "text": "Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121962", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4318/" ]
121,979
<p>I want to detect users' screen size and pass this into a charting application (Chart Director by <a href="http://www.advsofteng.com" rel="nofollow noreferrer">http://www.advsofteng.com</a>) to control how big an image to display.</p> <p>I have to use ASP, but I can only think to use JavaScript to detect screen-size and then pass this into the server-side script. Is there an easier way?</p> <p>Thanks</p>
[ { "answer_id": 122135, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 0, "selected": false, "text": "src" }, { "answer_id": 32599305, "author": "pavurya", "author_id": 3975278, "author_profile": "https://Stackoverflow.com/users/3975278", "pm_score": 2, "selected": false, "text": "document.cookie = \"screen_w=\" + screen.availWidth ;\ndocument.cookie = \"screen_h=\" + screen.availHeight;\n" }, { "answer_id": 39077479, "author": "stu", "author_id": 4588272, "author_profile": "https://Stackoverflow.com/users/4588272", "pm_score": 0, "selected": false, "text": "<script type=\"text/javascript\" language=\"JavaScript\">\n\n document.cookie = \"screen_w=\" + screen.width;\n location.href = \"second_page.asp\"\n\n</script>\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/121979", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21203/" ]
122,033
<p>Yesterday, I asked <a href="https://stackoverflow.com/questions/119107/how-do-i-generate-a-list-of-n-unique-random-numbers-in-ruby">this</a> question and never really got an answer I was really happy with. I really would like to know how to generate a list of N unique random numbers using a functional language such as Ruby without having to be extremely imperative in style.</p> <p>Since I didn't see anything I really liked, I've written the solution I was looking for in LINQ:</p> <pre><code> static void Main(string[] args) { var temp = from q in GetRandomNumbers(100).Distinct().Take(5) select q; } private static IEnumerable GetRandomNumbers(int max) { Random r = new Random(); while (true) { yield return r.Next(max); } } </code></pre> <p>Can you translate my LINQ to Ruby? Python? Any other functional programming language?</p> <p><strong>Note:</strong> Please try not to use too many loops and conditionals - otherwise the solution is trivial. Also, I'd rather see a solution where you don't have to generate an array much bigger than N so you can then just remove the duplicates and trim it down to N.</p> <p>I know I'm being picky, but I'd really like to see some elegant solutions to this problem. Thanks!</p> <p><strong>Edit:</strong><br /> Why all the downvotes?</p> <p>Originally my code sample had the Distinct() after the Take() which, as many pointed out, could leave me with an empty list. I've changed the order in which those methods are called to reflect what I meant in the first place.</p> <p><strong>Apology:</strong><br /> I've been told this post came across as rather snobbish. I wasn't trying to imply that LINQ is better than Ruby/Python; or that my solution is much better than everyone else's. My intent is just to learn how to do this (with certain constraints) in Ruby. I'm sorry if I came across as a jerk.</p>
[ { "answer_id": 122047, "author": "Dan Lenski", "author_id": 20789, "author_profile": "https://Stackoverflow.com/users/20789", "pm_score": 0, "selected": false, "text": "from numpy import *\na = random.random_integers(0, 100, 5)\nb = unique(a)\n" }, { "answer_id": 122062, "author": "Thomas Wouters", "author_id": 17624, "author_profile": "https://Stackoverflow.com/users/17624", "pm_score": 2, "selected": false, "text": ">>> import random\n>>> \n>>> def getUniqueRandomNumbers(num, highest):\n... seen = set()\n... while len(seen) < num:\n... i = random.randrange(0, highest)\n... if i not in seen:\n... seen.add(i) \n... yield i\n... \n>>>\n" }, { "answer_id": 122064, "author": "Jeremy", "author_id": 1114, "author_profile": "https://Stackoverflow.com/users/1114", "pm_score": 4, "selected": false, "text": ">>> import random\n>>> print random.sample(xrange(100), 5)\n[61, 54, 91, 72, 85]\n" }, { "answer_id": 122085, "author": "hjdivad", "author_id": 7538, "author_profile": "https://Stackoverflow.com/users/7538", "pm_score": -1, "selected": false, "text": "def random(max)\n (rand * max).to_i\nend\n\n# Get 5 random numbers between 0 and 100\na = (1..5).inject([]){|acc,i| acc << random( 100)}\n# Remove Duplicates\na = a & a\n" }, { "answer_id": 122093, "author": "Will Boyce", "author_id": 5757, "author_profile": "https://Stackoverflow.com/users/5757", "pm_score": 2, "selected": false, "text": "s = set()\nwhile len(s) <= N: s.update((random.random(),))\n" }, { "answer_id": 122116, "author": "Michael Deardeuff", "author_id": 4931, "author_profile": "https://Stackoverflow.com/users/4931", "pm_score": 4, "selected": true, "text": "a = (0..100).entries.sort_by {rand}.slice! 0, 5\n" }, { "answer_id": 122121, "author": "David Mohundro", "author_id": 4570, "author_profile": "https://Stackoverflow.com/users/4570", "pm_score": 2, "selected": false, "text": "a = (1..5).collect { rand(100) }\na & a\n" }, { "answer_id": 122146, "author": "Joe Skora", "author_id": 14057, "author_profile": "https://Stackoverflow.com/users/14057", "pm_score": 0, "selected": false, "text": "import random\n\ndef makeRand(n):\n rand = random.Random()\n while 1:\n yield rand.randint(0,n)\n yield rand.randint(0,n) \n\ngen = makeRand(100) \nterms = [ gen.next() for n in range(5) ]\n\nprint \"raw list\"\nprint terms\nprint \"de-duped list\"\nprint list(set(terms))\n\n# produces output similar to this\n#\n# raw list\n# [22, 11, 35, 55, 1]\n# de-duped list\n# [35, 11, 1, 22, 55]\n" }, { "answer_id": 122159, "author": "apenwarr", "author_id": 42219, "author_profile": "https://Stackoverflow.com/users/42219", "pm_score": 0, "selected": false, "text": "from random import randrange\n\ndef Distinct(items):\n set = {}\n for i in items:\n if not set.has_key(i):\n yield i\n set[i] = 1\n\ndef Take(num, items):\n for i in items:\n if num > 0:\n yield i\n num = num - 1\n else:\n break\n\ndef ToArray(items):\n return [i for i in items]\n\ndef GetRandomNumbers(max):\n while 1:\n yield randrange(max)\n\nprint ToArray(Take(5, Distinct(GetRandomNumbers(100))))\n" }, { "answer_id": 122188, "author": "e-satis", "author_id": 9951, "author_profile": "https://Stackoverflow.com/users/9951", "pm_score": 2, "selected": false, "text": "def getRandomNumbers(max, size) :\n pool = set()\n return ((lambda x : pool.add(x) or x)(random.randrange(max)) for x in xrange(size) if len(a) < size)\n\nprint [x for x in gen(100, 5)]\n[0, 10, 19, 51, 18]\n" }, { "answer_id": 122212, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 0, "selected": false, "text": ">>> import random\n>>> def getRandomNumbers( max ):\n... while True:\n... yield random.randrange(0,max)\n" }, { "answer_id": 122285, "author": "user19087", "author_id": 19087, "author_profile": "https://Stackoverflow.com/users/19087", "pm_score": 0, "selected": false, "text": "from numpy import random,unique\n\ndef GetRandomNumbers(total=5):\n while True:\n yield unique(random.random(total*2))[:total]\n\nrandomGenerator = GetRandomNumbers()\n\nmyRandomNumbers = randomGenerator.next()\n" }, { "answer_id": 123258, "author": "Brian", "author_id": 9493, "author_profile": "https://Stackoverflow.com/users/9493", "pm_score": 0, "selected": false, "text": "import itertools, random\n\ndef distinct(seq):\n seen=set()\n for item in seq:\n if item not in seen:\n seen.add(item)\n yield item\n\ndef getRandomNumbers(max):\n while 1:\n yield random.randint(0,max)\n\nfor item in itertools.islice(distinct(getRandomNumbers(100)), 5):\n print item\n" }, { "answer_id": 3793197, "author": "horseyguy", "author_id": 66725, "author_profile": "https://Stackoverflow.com/users/66725", "pm_score": 1, "selected": false, "text": "Array(0..100).sample(5)\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/781/" ]
122,057
<p>At present it seems that VS2008 still isn't supported either in the 5.1.5 release or in the STLPort CVS repository. If someone has already done this work then it would be useful to share, if possible :)</p> <p>Likewise it would be useful to know about the changes required for a VS2005 or 2008 x64 build.</p>
[ { "answer_id": 156902, "author": "Len Holgate", "author_id": 7925, "author_profile": "https://Stackoverflow.com/users/7925", "pm_score": 2, "selected": false, "text": "\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\bin\\amd64\\vcvarsamd64.bat" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7925/" ]
122,067
<p>I have a site using a custom favicon.ico. The favicon displays as expected in all browsers except IE. When trying to display the favicon in IE, I get the big red x; when displaying the favicon in another browser, it displays just fine. The page source includes and it does work in other browsers. Thanks for your thoughts.</p> <p><strong>EDIT: SOLVED: The source of the issue was the file was a jpg renamed to ico. I created the file as an ico and it is working as expected. Thanks for your input.</strong></p>
[ { "answer_id": 122111, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 7, "selected": true, "text": "<link rel=\"icon\" href=\"http://www.example.com/favicon.ico\" type=\"image/x-icon\" />\n<link rel=\"shortcut icon\" href=\"http://www.example.com/favicon.ico\" type=\"image/x-icon\" />\n" }, { "answer_id": 122125, "author": "Jonathan Tran", "author_id": 12887, "author_profile": "https://Stackoverflow.com/users/12887", "pm_score": 2, "selected": false, "text": "/favicon.ico" }, { "answer_id": 11423240, "author": "germankiwi", "author_id": 1397352, "author_profile": "https://Stackoverflow.com/users/1397352", "pm_score": 2, "selected": false, "text": "link" }, { "answer_id": 12067017, "author": "Nivedita", "author_id": 1615999, "author_profile": "https://Stackoverflow.com/users/1615999", "pm_score": 4, "selected": false, "text": " <link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"FolderName/favicon.ico\" />\n" }, { "answer_id": 12373835, "author": "yoel halb", "author_id": 640195, "author_profile": "https://Stackoverflow.com/users/640195", "pm_score": 4, "selected": false, "text": "<location path=\"favicon.ico\">\n <system.web>\n <authorization>\n <allow users=\"*\" />\n </authorization>\n </system.web>\n</location> \n" }, { "answer_id": 16420318, "author": "RaghuRam Kattreddi", "author_id": 2358530, "author_profile": "https://Stackoverflow.com/users/2358530", "pm_score": 0, "selected": false, "text": "<link rel=\"shortcut icon\" href=\"/favicon.ico\" >\n<link rel=\"icon\" type=\"/image/ico\" href=\"/favicon.ico\" >\n" }, { "answer_id": 31747474, "author": "Lachlan Hunt", "author_id": 132537, "author_profile": "https://Stackoverflow.com/users/132537", "pm_score": 0, "selected": false, "text": "curl -I http://example.com/favicon.ico\n" }, { "answer_id": 36644995, "author": "Kappacake", "author_id": 4220401, "author_profile": "https://Stackoverflow.com/users/4220401", "pm_score": 1, "selected": false, "text": "<head>" }, { "answer_id": 55024503, "author": "Wilson Delgado", "author_id": 11160065, "author_profile": "https://Stackoverflow.com/users/11160065", "pm_score": 0, "selected": false, "text": "<link data-senna-track=\"temporary\" href=\"${favicon_url}\" rel=\"Shortcut Icon\" />\n<link rel=\"icon\" href=\"${favicon_url}\" type=\"image/x-icon\" />\n<link rel=\"shortcut icon\" href=\"${favicon_url}\" type=\"image/x-icon\" />\n" }, { "answer_id": 57505325, "author": "AllmanTool", "author_id": 5188689, "author_profile": "https://Stackoverflow.com/users/5188689", "pm_score": 0, "selected": false, "text": " <link id=\"shortcutIcon\" rel=\"shortcut icon\" type=\"image/x-icon\">\n <link id=\"icon\" rel=\"icon\" type=\"image/x-icon\">\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13465/" ]
122,088
<p>I have a table in a MSSQL database that looks like this:</p> <pre><code>Timestamp (datetime) Message (varchar(20)) </code></pre> <p>Once a day, a particular process inserts the current time and the message 'Started' when it starts. When it is finished it inserts the current time and the message 'Finished'.</p> <p>What is a good query or set of statements that, given a particular date, returns:</p> <ul> <li>0 if the process never started</li> <li>1 if the process started but did not finish</li> <li>2 if the process started and finished</li> </ul> <p>There are other messages in the table, but 'Started' and 'Finished' are unique to this one process.</p> <p>EDIT: For bonus karma, raise an error if the data is invalid, for example there are two 'Started' messages, or there is a 'Finished' without a 'Started'.</p>
[ { "answer_id": 122129, "author": "George Mastros", "author_id": 1408129, "author_profile": "https://Stackoverflow.com/users/1408129", "pm_score": 3, "selected": true, "text": "Select Count(Message) As Status\nFrom Process_monitor\nWhere TimeStamp >= '20080923'\n And TimeStamp < '20080924'\n And (Message = 'Started' or Message = 'Finished')\n" }, { "answer_id": 122150, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 0, "selected": false, "text": "DECLARE @TargetDate datetime\nSET @TargetDate = '2008-01-01'\n\nDECLARE @Messages varchar(max)\n\nSET @Messages = ''\n\nSELECT @Messages = @Messages + '|' + Message\nFROM process_monitor\nWHERE @TargetDate <= Timestamp and Timestamp < DateAdd(dd, 1, @TargetDate)\n and Message in ('Finished', 'Started')\nORDER BY Timestamp desc\n\nSELECT CASE\n WHEN @Messages = '|Finished|Started' THEN 2\n WHEN @Messages = '|Started' THEN 1\n WHEN @Messages = '' THEN 0\n ELSE -1\nEND\n" }, { "answer_id": 122151, "author": "Grant Johnson", "author_id": 12518, "author_profile": "https://Stackoverflow.com/users/12518", "pm_score": -1, "selected": false, "text": "select count(*) from process_monitor \nwhere timestamp > yesterday and timestamp < tomorrow.\n" }, { "answer_id": 122249, "author": "Aheho", "author_id": 21155, "author_profile": "https://Stackoverflow.com/users/21155", "pm_score": 0, "selected": false, "text": "select\n ProcessID,\n ProcessName,\n\n CASE\n WHEN \n (Select \n COUNT(*) \n from \n ProcessActivity \n where \n ProcessActivity.processid = Processes.processid \n and Message = 'STARTED') = 1 \n\n And\n (Select \n COUNT(*) \n from \n ProcessActivity \n where \n ProcessActivity.processid = Processes.processid \n and Message = 'FINISHED') = 0\n THEN 1\n\n WHEN\n (Select \n COUNT(*) \n from \n ProcessActivity \n where \n ProcessActivity.processid = Processes.processid \n and Message = 'STARTED') = 1 \n And\n (Select \n COUNT(*) \n from \n ProcessActivity \n where \n ProcessActivity.processid = Processes.processid \n and Message = 'FINISHED') = 1 \nTHEN 2\n ELSE 0\n\nEND as Status\n\nFrom\n Processes\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16881/" ]
122,089
<p>A brief search shows that all available (uUnix command line) tools that convert from xsd (XML Schema) to rng (RelaxNG) or rnc (compact RelaxNG) have problems of some sort.</p> <p>First, if I use rngconv:</p> <pre><code>$ wget https://msv.dev.java.net/files/documents/61/31333/rngconv.20060319.zip $ unzip rngconv.20060319.zip $ cd rngconv-20060319/ $ java -jar rngconv.jar my.xsd &gt; my.rng </code></pre> <p>It does not have a way to de-normalize elements so all end up being alternative start elements (it also seems to be a bit buggy).</p> <p>Trang is an alternative, but it doesn't support xsd files on the input only on the output (why?). It supports DTD, however. Converting to DTD first comes to mind, but a solid xsd2dtd is hard to find as well. The one below:</p> <pre><code> $ xsltproc http://crism.maden.org/consulting/pub/xsl/xsd2dtd.xsl in.xsd &gt; out.dtd </code></pre> <p>Seems to be buggy.</p> <p>All this is very surprising. For all these years of XML (ab)use, there no decent command line tools for these trivial basic tasks? Are people using only editors? Do those work? I much prefer command line, especially because I'd like to automate these tasks.</p> <p>Any enlightening comments on this?</p>
[ { "answer_id": 1095094, "author": "neozen", "author_id": 59412, "author_profile": "https://Stackoverflow.com/users/59412", "pm_score": 2, "selected": false, "text": "1.xml 2.xml 3.xml 4.xml 5.xml" }, { "answer_id": 2302117, "author": "antonj", "author_id": 183994, "author_profile": "https://Stackoverflow.com/users/183994", "pm_score": 2, "selected": false, "text": "http://relaxng.org/#conversion" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21205/" ]
122,097
<p>I am wondering what primers/guides/tutorials/etc. are out there for learning to rewrite URLs using Apache/.htaccess? Where is a good place to start?</p> <p>My primary interest is learning how to point certain directories to others, and how to use portions of a URL as parameters to a script (i.e. "/some/subdirs/like/this" => "script.php?a=some&amp;b=subdirs&amp;c=like&amp;d=this").</p>
[ { "answer_id": 122164, "author": "Kyle Burton", "author_id": 19784, "author_profile": "https://Stackoverflow.com/users/19784", "pm_score": 2, "selected": false, "text": "RewriteRule ^/games.* /usr/local/games/web\nRewriteRule ^/product/(.*)/view$ /var/web/productdb/$1\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122097", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5291/" ]
122,098
<p>I have a Google Web Toolkit (GWT) application and when I link to it, I want to pass some arguments/parameters that it can use to dynamically retrieve data. E.g. if it were a stock chart application, I would want my link to contain the symbol and then have the GWT app read that and make a request to some stock service. E.g. <a href="http://myapp/gwt/StockChart?symbol=GOOG" rel="noreferrer">http://myapp/gwt/StockChart?symbol=GOOG</a> would be the link to my StockChart GWT app and it would make a request to my stock info web service for the GOOG stock. </p> <p>So far, I've been using the server-side code to add Javascript variables to the page and then I've read those variables using JSNI (JavaScript Native Interface). </p> <p>For example:</p> <p>In the host HTML:</p> <pre><code>&lt;script type="text/javascript"&gt; var stockSymbol = '&lt;%= request.getParameter("symbol") %&gt;'; &lt;/script&gt; </code></pre> <p>In the GWT code:</p> <pre><code>public static native String getSymbol() /*-{ return $wnd.stockSymbol; }-*/; </code></pre> <p>(Although this code is based on real code that works, I've modified it for this question so I might have goofed somewhere)</p> <p>However, this doesn't always work well in hosted mode (especially with arrays) and since JSNI wasn't around in version 1.4 and previous, I'm guessing there's another/better way. </p>
[ { "answer_id": 122833, "author": "Drejc", "author_id": 6482, "author_profile": "https://Stackoverflow.com/users/6482", "pm_score": 4, "selected": true, "text": "// returns whole query string \npublic static String getQueryString() \n{\n return Window.Location.getQueryString();\n}\n\n// returns specific parameter\npublic static String getQueryString(String name)\n{ \n return Window.Location.getParameter(name);\n} \n" }, { "answer_id": 12100219, "author": "mxro", "author_id": 270662, "author_profile": "https://Stackoverflow.com/users/270662", "pm_score": 1, "selected": false, "text": " http://myapp/gwt/StockChart?symbol=GOOG\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122098", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9910/" ]
122,102
<p>What is the most efficient way to clone a JavaScript object? I've seen <code>obj = eval(uneval(o));</code> being used, but <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/uneval" rel="noreferrer">that's non-standard and only supported by Firefox</a>.<br/><br/> I've done things like <code>obj = JSON.parse(JSON.stringify(o));</code> but question the efficiency. <br/><br/> I've also seen recursive copying functions with various flaws. <br /> I'm surprised no canonical solution exists.</p>
[ { "answer_id": 122190, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 9, "selected": false, "text": "function clone(obj) {\n if (obj === null || typeof (obj) !== 'object' || 'isActiveClone' in obj)\n return obj;\n\n if (obj instanceof Date)\n var temp = new obj.constructor(); //or new Date(obj);\n else\n var temp = obj.constructor();\n\n for (var key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n obj['isActiveClone'] = null;\n temp[key] = clone(obj[key]);\n delete obj['isActiveClone'];\n }\n }\n return temp;\n}\n" }, { "answer_id": 122232, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 5, "selected": false, "text": "function clone(obj)\n { var clone = {};\n clone.prototype = obj.prototype;\n for (property in obj) clone[property] = obj[property];\n return clone;\n }\n" }, { "answer_id": 122704, "author": "John Resig", "author_id": 6524, "author_profile": "https://Stackoverflow.com/users/6524", "pm_score": 13, "selected": true, "text": "structuredClone(value)\n" }, { "answer_id": 1042676, "author": "Kamarey", "author_id": 86296, "author_profile": "https://Stackoverflow.com/users/86296", "pm_score": 7, "selected": false, "text": "// extends 'from' object with members from 'to'. If 'to' is null, a deep clone of 'from' is returned\nfunction extend(from, to)\n{\n if (from == null || typeof from != \"object\") return from;\n if (from.constructor != Object && from.constructor != Array) return from;\n if (from.constructor == Date || from.constructor == RegExp || from.constructor == Function ||\n from.constructor == String || from.constructor == Number || from.constructor == Boolean)\n return new from.constructor(from);\n\n to = to || new from.constructor();\n\n for (var name in from)\n {\n to[name] = typeof to[name] == \"undefined\" ? extend(from[name], null) : to[name];\n }\n\n return to;\n}\n" }, { "answer_id": 1891377, "author": "Alan", "author_id": 229955, "author_profile": "https://Stackoverflow.com/users/229955", "pm_score": 7, "selected": false, "text": "function cloneObject(obj) {\n var clone = {};\n for(var i in obj) {\n if(typeof(obj[i])==\"object\" && obj[i] != null)\n clone[i] = cloneObject(obj[i]);\n else\n clone[i] = obj[i];\n }\n return clone;\n}\n" }, { "answer_id": 1963559, "author": "Zibri", "author_id": 236062, "author_profile": "https://Stackoverflow.com/users/236062", "pm_score": 6, "selected": false, "text": "var clone = function() {\n var newObj = (this instanceof Array) ? [] : {};\n for (var i in this) {\n if (this[i] && typeof this[i] == \"object\") {\n newObj[i] = this[i].clone();\n }\n else\n {\n newObj[i] = this[i];\n }\n }\n return newObj;\n}; \n\nObject.defineProperty( Object.prototype, \"clone\", {value: clone, enumerable: false});\n" }, { "answer_id": 2728898, "author": "Dima", "author_id": 327790, "author_profile": "https://Stackoverflow.com/users/327790", "pm_score": 4, "selected": false, "text": "// obj target object, vals source object\nvar setVals = function (obj, vals) {\n if (obj && vals) {\n for (var x in vals) {\n if (vals.hasOwnProperty(x)) {\n if (obj[x] && typeof vals[x] === 'object') {\n obj[x] = setVals(obj[x], vals[x]);\n } else {\n obj[x] = vals[x];\n }\n }\n }\n }\n return obj;\n};\n" }, { "answer_id": 3873968, "author": "Chris Broski", "author_id": 468111, "author_profile": "https://Stackoverflow.com/users/468111", "pm_score": 5, "selected": false, "text": "function object(o) {\n function F() {}\n F.prototype = o;\n return new F();\n}\n\nvar newObject = object(oldObject);\n" }, { "answer_id": 3951975, "author": "Page Notes", "author_id": 478323, "author_profile": "https://Stackoverflow.com/users/478323", "pm_score": 4, "selected": false, "text": "function jQueryClone(obj) {\n return jQuery.extend(true, {}, obj)\n}\n\nfunction JSONClone(obj) {\n return JSON.parse(JSON.stringify(obj))\n}\n\nvar arrayLikeObj = [[1, \"a\", \"b\"], [2, \"b\", \"a\"]];\narrayLikeObj.names = [\"m\", \"n\", \"o\"];\nvar JSONCopy = JSONClone(arrayLikeObj);\nvar jQueryCopy = jQueryClone(arrayLikeObj);\n\nalert(\"Is arrayLikeObj an array instance?\" + (arrayLikeObj instanceof Array) +\n \"\\nIs the jQueryClone an array instance? \" + (jQueryCopy instanceof Array) +\n \"\\nWhat are the arrayLikeObj names? \" + arrayLikeObj.names +\n \"\\nAnd what are the JSONClone names? \" + JSONCopy.names)\n" }, { "answer_id": 4591639, "author": "Sultan Shakir", "author_id": 505062, "author_profile": "https://Stackoverflow.com/users/505062", "pm_score": 9, "selected": false, "text": "var newObject = JSON.parse(JSON.stringify(oldObject));\n" }, { "answer_id": 5344074, "author": "Corban Brook", "author_id": 69959, "author_profile": "https://Stackoverflow.com/users/69959", "pm_score": 11, "selected": false, "text": "JSON.parse(JSON.stringify(obj))\n" }, { "answer_id": 5452191, "author": "gion_13", "author_id": 491075, "author_profile": "https://Stackoverflow.com/users/491075", "pm_score": 2, "selected": false, "text": "function clone(obj){\n if(typeof(obj) == 'function')//it's a simple function\n return obj;\n //of it's not an object (but could be an array...even if in javascript arrays are objects)\n if(typeof(obj) != 'object' || obj.constructor.toString().indexOf('Array')!=-1)\n if(JSON != undefined)//if we have the JSON obj\n try{\n return JSON.parse(JSON.stringify(obj));\n }catch(err){\n return JSON.parse('\"'+JSON.stringify(obj)+'\"');\n }\n else\n try{\n return eval(uneval(obj));\n }catch(err){\n return eval('\"'+uneval(obj)+'\"');\n }\n // I used to rely on jQuery for this, but the \"extend\" function returns\n //an object similar to the one cloned,\n //but that was not an instance (instanceof) of the cloned class\n /*\n if(jQuery != undefined)//if we use the jQuery plugin\n return jQuery.extend(true,{},obj);\n else//we recursivley clone the object\n */\n return (function _clone(obj){\n if(obj == null || typeof(obj) != 'object')\n return obj;\n function temp () {};\n temp.prototype = obj;\n var F = new temp;\n for(var key in obj)\n F[key] = clone(obj[key]);\n return F;\n })(obj); \n}\n" }, { "answer_id": 5527124, "author": "neatonk", "author_id": 682672, "author_profile": "https://Stackoverflow.com/users/682672", "pm_score": 4, "selected": false, "text": "function clone(obj, clones) {\n // Makes a deep copy of 'obj'. Handles cyclic structures by\n // tracking cloned obj's in the 'clones' parameter. Functions \n // are included, but not cloned. Functions members are cloned.\n var new_obj,\n already_cloned,\n t = typeof obj,\n i = 0,\n l,\n pair; \n\n clones = clones || [];\n\n if (obj === null) {\n return obj;\n }\n\n if (t === \"object\" || t === \"function\") {\n\n // check to see if we've already cloned obj\n for (i = 0, l = clones.length; i < l; i++) {\n pair = clones[i];\n if (pair[0] === obj) {\n already_cloned = pair[1];\n break;\n }\n }\n\n if (already_cloned) {\n return already_cloned; \n } else {\n if (t === \"object\") { // create new object\n new_obj = new obj.constructor();\n } else { // Just use functions as is\n new_obj = obj;\n }\n\n clones.push([obj, new_obj]); // keep track of objects we've cloned\n\n for (key in obj) { // clone object members\n if (obj.hasOwnProperty(key)) {\n new_obj[key] = clone(obj[key], clones);\n }\n }\n }\n }\n return new_obj || obj;\n}\n" }, { "answer_id": 6466050, "author": "Steve Tomlin", "author_id": 813831, "author_profile": "https://Stackoverflow.com/users/813831", "pm_score": 3, "selected": false, "text": "if" }, { "answer_id": 7541349, "author": "Joe", "author_id": 962942, "author_profile": "https://Stackoverflow.com/users/962942", "pm_score": 6, "selected": false, "text": "var a = function(){\n return {\n father:'zacharias'\n };\n},\nb = a(),\nc = a();\nc.father = 'johndoe';\nalert(b.father);\n" }, { "answer_id": 8522874, "author": "itsadok", "author_id": 7581, "author_profile": "https://Stackoverflow.com/users/7581", "pm_score": 6, "selected": false, "text": "var newObject = _.clone(oldObject);\n" }, { "answer_id": 10916838, "author": "Jeremy", "author_id": 1114, "author_profile": "https://Stackoverflow.com/users/1114", "pm_score": 9, "selected": false, "text": "structuredClone" }, { "answer_id": 11335725, "author": "Maël Nison", "author_id": 880703, "author_profile": "https://Stackoverflow.com/users/880703", "pm_score": 4, "selected": false, "text": "var origin = { foo : {} };\nvar copy = Object.keys(origin).reduce(function(c,k){c[k]=origin[k];return c;},{});\n\nconsole.log(origin, copy);\nconsole.log(origin == copy); // false\nconsole.log(origin.foo == copy.foo); // true\n" }, { "answer_id": 11620938, "author": "user1547016", "author_id": 1547016, "author_profile": "https://Stackoverflow.com/users/1547016", "pm_score": 4, "selected": false, "text": "function clone(src, deep) {\n\n var toString = Object.prototype.toString;\n if (!src && typeof src != \"object\") {\n // Any non-object (Boolean, String, Number), null, undefined, NaN\n return src;\n }\n\n // Honor native/custom clone methods\n if (src.clone && toString.call(src.clone) == \"[object Function]\") {\n return src.clone(deep);\n }\n\n // DOM elements\n if (src.nodeType && toString.call(src.cloneNode) == \"[object Function]\") {\n return src.cloneNode(deep);\n }\n\n // Date\n if (toString.call(src) == \"[object Date]\") {\n return new Date(src.getTime());\n }\n\n // RegExp\n if (toString.call(src) == \"[object RegExp]\") {\n return new RegExp(src);\n }\n\n // Function\n if (toString.call(src) == \"[object Function]\") {\n\n //Wrap in another method to make sure == is not true;\n //Note: Huge performance issue due to closures, comment this :)\n return (function(){\n src.apply(this, arguments);\n });\n }\n\n var ret, index;\n //Array\n if (toString.call(src) == \"[object Array]\") {\n //[].slice(0) would soft clone\n ret = src.slice();\n if (deep) {\n index = ret.length;\n while (index--) {\n ret[index] = clone(ret[index], true);\n }\n }\n }\n //Object\n else {\n ret = src.constructor ? new src.constructor() : {};\n for (var prop in src) {\n ret[prop] = deep\n ? clone(src[prop], true)\n : src[prop];\n }\n }\n return ret;\n};\n" }, { "answer_id": 12941013, "author": "pvorb", "author_id": 432354, "author_profile": "https://Stackoverflow.com/users/432354", "pm_score": 6, "selected": false, "text": "npm install clone\n" }, { "answer_id": 13333781, "author": "Matt Browne", "author_id": 560114, "author_profile": "https://Stackoverflow.com/users/560114", "pm_score": 6, "selected": false, "text": "//If Object.create isn't already defined, we just do the simple shim,\n//without the second argument, since that's all we need here\nvar object_create = Object.create;\nif (typeof object_create !== 'function') {\n object_create = function(o) {\n function F() {}\n F.prototype = o;\n return new F();\n };\n}\n\nfunction deepCopy(obj) {\n if(obj == null || typeof(obj) !== 'object'){\n return obj;\n }\n //make sure the returned object has the same prototype as the original\n var ret = object_create(obj.constructor.prototype);\n for(var key in obj){\n ret[key] = deepCopy(obj[key]);\n }\n return ret;\n}\n" }, { "answer_id": 16406986, "author": "Michael Uzquiano", "author_id": 1489973, "author_profile": "https://Stackoverflow.com/users/1489973", "pm_score": 4, "selected": false, "text": "var clone = JSON.parse(JSON.stringify(obj));\n" }, { "answer_id": 17252104, "author": "opensas", "author_id": 47633, "author_profile": "https://Stackoverflow.com/users/47633", "pm_score": 5, "selected": false, "text": "var objects = [{ 'a': 1 }, { 'b': 2 }];\n\nvar deep = _.cloneDeep(objects);\nconsole.log(deep[0] === objects[0]);\n// => false\n" }, { "answer_id": 17915351, "author": "Daniel Lorenz", "author_id": 1245940, "author_profile": "https://Stackoverflow.com/users/1245940", "pm_score": 3, "selected": false, "text": "var newItem = jQuery.extend(true, {}, oldItem);\ncreateNewArrays(newItem);\n\n\nfunction createNewArrays(obj) {\n for (var prop in obj) {\n if ((kendo != null && obj[prop] instanceof kendo.data.ObservableArray) || obj[prop] instanceof Array) {\n var copy = [];\n $.each(obj[prop], function (i, item) {\n var newChild = $.extend(true, {}, item);\n createNewArrays(newChild);\n copy.push(newChild);\n });\n obj[prop] = copy;\n }\n }\n}\n" }, { "answer_id": 23277075, "author": "Cody", "author_id": 1153121, "author_profile": "https://Stackoverflow.com/users/1153121", "pm_score": 3, "selected": false, "text": "var newObj = JSON.parse( JSON.stringify(oldObje) );" }, { "answer_id": 24248152, "author": "weeger", "author_id": 2057976, "author_profile": "https://Stackoverflow.com/users/2057976", "pm_score": 2, "selected": false, "text": "extend(object_dest, object_source);" }, { "answer_id": 25476365, "author": "Robin Whittleton", "author_id": 453783, "author_profile": "https://Stackoverflow.com/users/453783", "pm_score": 3, "selected": false, "text": "var obj1 = { a: true, b: 1 };\nvar obj2 = Object.assign(obj1);\nconsole.log(obj2); // { a: true, b: 1 }\n" }, { "answer_id": 25921504, "author": "tim-montague", "author_id": 1404726, "author_profile": "https://Stackoverflow.com/users/1404726", "pm_score": 7, "selected": false, "text": "..." }, { "answer_id": 30929199, "author": "Steven Vachon", "author_id": 923745, "author_profile": "https://Stackoverflow.com/users/923745", "pm_score": 2, "selected": false, "text": "Object.create()" }, { "answer_id": 31817825, "author": "Tristian", "author_id": 3629804, "author_profile": "https://Stackoverflow.com/users/3629804", "pm_score": 2, "selected": false, "text": ".extend()" }, { "answer_id": 32144541, "author": "nathan rogers", "author_id": 4761444, "author_profile": "https://Stackoverflow.com/users/4761444", "pm_score": 5, "selected": false, "text": "var objToCreate = JSON.parse(JSON.stringify(cloneThis));\n" }, { "answer_id": 33273256, "author": "andrew", "author_id": 797230, "author_profile": "https://Stackoverflow.com/users/797230", "pm_score": 4, "selected": false, "text": "function clone(target, source){\n\n for(let key in source){\n\n // Use getOwnPropertyDescriptor instead of source[key] to prevent from trigering setter/getter.\n let descriptor = Object.getOwnPropertyDescriptor(source, key);\n if(descriptor.value instanceof String){\n target[key] = new String(descriptor.value);\n }\n else if(descriptor.value instanceof Array){\n target[key] = clone([], descriptor.value);\n }\n else if(descriptor.value instanceof Object){\n let prototype = Reflect.getPrototypeOf(descriptor.value);\n let cloneObject = clone({}, descriptor.value);\n Reflect.setPrototypeOf(cloneObject, prototype);\n target[key] = cloneObject;\n }\n else {\n Object.defineProperty(target, key, descriptor);\n }\n }\n let prototype = Reflect.getPrototypeOf(source);\n Reflect.setPrototypeOf(target, prototype);\n return target;\n}\n" }, { "answer_id": 33419329, "author": "Buzinas", "author_id": 3358027, "author_profile": "https://Stackoverflow.com/users/3358027", "pm_score": 4, "selected": false, "text": "JSON.parse(JSON.stringify(obj))" }, { "answer_id": 34283281, "author": "Eugene Tiurin", "author_id": 2676500, "author_profile": "https://Stackoverflow.com/users/2676500", "pm_score": 7, "selected": false, "text": "Object.assign" }, { "answer_id": 34555013, "author": "Bodhi Hu", "author_id": 2176133, "author_profile": "https://Stackoverflow.com/users/2176133", "pm_score": 3, "selected": false, "text": "/*\n * Trampoline to avoid recursion in JavaScript, see:\n * https://www.integralist.co.uk/posts/functional-recursive-javascript-programming/\n */\nfunction trampoline() {\n var func = arguments[0];\n var args = [];\n for (var i = 1; i < arguments.length; i++) {\n args[i - 1] = arguments[i];\n }\n\n var currentBatch = func.apply(this, args);\n var nextBatch = [];\n\n while (currentBatch && currentBatch.length > 0) {\n currentBatch.forEach(function(eachFunc) {\n var ret = eachFunc();\n if (ret && ret.length > 0) {\n nextBatch = nextBatch.concat(ret);\n }\n });\n\n currentBatch = nextBatch;\n nextBatch = [];\n }\n};\n\n/*\n * Deep clone an object using the trampoline technique.\n *\n * @param target {Object} Object to clone\n * @return {Object} Cloned object.\n */\nfunction clone(target) {\n if (typeof target !== 'object') {\n return target;\n }\n if (target == null || Object.keys(target).length == 0) {\n return target;\n }\n\n function _clone(b, a) {\n var nextBatch = [];\n for (var key in b) {\n if (typeof b[key] === 'object' && b[key] !== null) {\n if (b[key] instanceof Array) {\n a[key] = [];\n }\n else {\n a[key] = {};\n }\n nextBatch.push(_clone.bind(null, b[key], a[key]));\n }\n else {\n a[key] = b[key];\n }\n }\n return nextBatch;\n };\n\n var ret = target instanceof Array ? [] : {};\n (trampoline.bind(null, _clone))(target, ret);\n return ret;\n};\n" }, { "answer_id": 36177142, "author": "Barry Staes", "author_id": 2096041, "author_profile": "https://Stackoverflow.com/users/2096041", "pm_score": -1, "selected": false, "text": "var original = {a: 1};\n\n// Method 1: New object with original assigned.\nvar copy1 = Object.assign({}, original);\n\n// Method 2: New object with spread operator assignment.\nvar copy2 = {...original};\n" }, { "answer_id": 37220122, "author": "Dan Atkinson", "author_id": 31532, "author_profile": "https://Stackoverflow.com/users/31532", "pm_score": 4, "selected": false, "text": "angular.copy" }, { "answer_id": 38423812, "author": "Shishir Arora", "author_id": 3221274, "author_profile": "https://Stackoverflow.com/users/3221274", "pm_score": 3, "selected": false, "text": "const clone = (o) =>\n typeof o === 'object' && o !== null ? // only clone objects\n (Array.isArray(o) ? // if cloning an array\n o.map(e => clone(e)) : // clone each of its elements\n Object.keys(o).reduce( // otherwise reduce every key in the object\n (r, k) => (r[k] = clone(o[k]), r), {} // and save its cloned value into a new object\n )\n ) :\n o; // return non-objects as is\n\nvar x = {\n nested: {\n name: 'test'\n }\n};\n\nvar y = clone(x);\n\nconsole.log(x.nested !== y.nested);" }, { "answer_id": 38796058, "author": "user3071643", "author_id": 3071643, "author_profile": "https://Stackoverflow.com/users/3071643", "pm_score": 3, "selected": false, "text": "let a = clone(b)\n" }, { "answer_id": 39491721, "author": "azerafati", "author_id": 3160597, "author_profile": "https://Stackoverflow.com/users/3160597", "pm_score": 4, "selected": false, "text": "var newObject = angular.copy(oldObject);\n" }, { "answer_id": 40326630, "author": "SAlidadi", "author_id": 6249763, "author_profile": "https://Stackoverflow.com/users/6249763", "pm_score": 2, "selected": false, "text": "obj = {\n a: { b: { c: { d: ['1', '2'] } } },\n e: 'Saeid'\n}\nconst Clone = function (obj) {\n \n const container = Array.isArray(obj) ? [] : {}\n const keys = Object.keys(obj)\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]\n if(typeof obj[key] == 'object') {\n container[key] = Clone(obj[key])\n }\n else\n container[key] = obj[key].slice()\n }\n \n return container\n}\n console.log(Clone(obj))" }, { "answer_id": 40722084, "author": "Ashutosh Jha", "author_id": 3387029, "author_profile": "https://Stackoverflow.com/users/3387029", "pm_score": 2, "selected": false, "text": "_clone: function(obj){\n let newObj = {};\n for(let i in obj){\n if(typeof(obj[i]) === 'object' && Object.keys(obj[i]).length){\n newObj[i] = clone(obj[i]);\n } else{\n newObj[i] = obj[i];\n }\n }\n return Object.assign({},newObj);\n}\n" }, { "answer_id": 40784968, "author": "Ihor Pavlyk", "author_id": 3552556, "author_profile": "https://Stackoverflow.com/users/3552556", "pm_score": 2, "selected": false, "text": "class Handler {\n static deepCopy (obj) {\n if (Object.prototype.toString.call(obj) === '[object Array]') {\n const result = [];\n \n for (let i = 0, len = obj.length; i < len; i++) {\n result[i] = Handler.deepCopy(obj[i]);\n }\n return result;\n } else if (Object.prototype.toString.call(obj) === '[object Object]') {\n const result = {};\n for (let prop in obj) {\n result[prop] = Handler.deepCopy(obj[prop]);\n }\n return result;\n }\n return obj;\n }\n}" }, { "answer_id": 43188775, "author": "Alireza", "author_id": 5423108, "author_profile": "https://Stackoverflow.com/users/5423108", "pm_score": 6, "selected": false, "text": "var obj = {a:1, b:2, c:3, d:4};\n" }, { "answer_id": 43235072, "author": "Redu", "author_id": 4543207, "author_profile": "https://Stackoverflow.com/users/4543207", "pm_score": 2, "selected": false, "text": "function objectClone(o){\n var ot = Array.isArray(o);\n return o !== null && typeof o === \"object\" ? Object.keys(o)\n .reduce((r,k) => o[k] !== null && typeof o[k] === \"object\" ? (r[k] = objectClone(o[k]),r)\n : (r[k] = o[k],r), ot ? [] : {})\n : o;\n}\nvar obj = {a: 1, b: {c: 2, d: {e: 3, f: {g: 4, h: null}}}},\n arr = [1,2,[3,4,[5,6,[7]]]],\n nil = null,\n clobj = objectClone(obj),\n clarr = objectClone(arr),\n clnil = objectClone(nil);\nconsole.log(clobj, obj === clobj);\nconsole.log(clarr, arr === clarr);\nconsole.log(clnil, nil === clnil);\nclarr[2][2][2] = \"seven\";\nconsole.log(arr, clarr);" }, { "answer_id": 44358642, "author": "Daniel Barde", "author_id": 1134317, "author_profile": "https://Stackoverflow.com/users/1134317", "pm_score": 3, "selected": false, "text": "var foo = {a: 'a', b: {c:'d', e: {f: 'g'}}};\n\nvar bar = _.cloneDeep(foo);\n// bar = {a: 'a', b: {c:'d', e: {f: 'g'}}} \n" }, { "answer_id": 44612374, "author": "prograhammer", "author_id": 1110941, "author_profile": "https://Stackoverflow.com/users/1110941", "pm_score": 4, "selected": false, "text": "function cloneDeep (o) {\n let newO\n let i\n\n if (typeof o !== 'object') return o\n\n if (!o) return o\n\n if (Object.prototype.toString.apply(o) === '[object Array]') {\n newO = []\n for (i = 0; i < o.length; i += 1) {\n newO[i] = cloneDeep(o[i])\n }\n return newO\n }\n\n newO = {}\n for (i in o) {\n if (o.hasOwnProperty(i)) {\n newO[i] = cloneDeep(o[i])\n }\n }\n return newO\n}\n" }, { "answer_id": 45706299, "author": "JTeam", "author_id": 3714376, "author_profile": "https://Stackoverflow.com/users/3714376", "pm_score": 1, "selected": false, "text": "import esclone from \"esclone\";\n\nconst rockysGrandFather = {\n name: \"Rockys grand father\",\n father: \"Don't know :(\"\n};\nconst rockysFather = {\n name: \"Rockys Father\",\n father: rockysGrandFather\n};\n\nconst rocky = {\n name: \"Rocky\",\n father: rockysFather\n};\n\nconst rockyClone = esclone(rocky);\n" }, { "answer_id": 46132039, "author": "shobhit1", "author_id": 3711475, "author_profile": "https://Stackoverflow.com/users/3711475", "pm_score": 3, "selected": false, "text": "const cloneObject = (oldObject) => {\n let newObject = oldObject;\n if (oldObject && typeof oldObject === 'object') {\n if(Array.isArray(oldObject)) {\n newObject = [];\n } else if (Object.prototype.toString.call(oldObject) === '[object Date]' && !isNaN(oldObject)) {\n newObject = new Date(oldObject.getTime());\n } else {\n newObject = {};\n for (let i in oldObject) {\n newObject[i] = cloneObject(oldObject[i]);\n }\n }\n\n }\n return newObject;\n}\n" }, { "answer_id": 46692810, "author": "Mayur Agarwal", "author_id": 5838627, "author_profile": "https://Stackoverflow.com/users/5838627", "pm_score": 4, "selected": false, "text": "function cloneObject(obj) {\n if (obj === null || typeof(obj) !== 'object')\n return obj;\n var temp = obj.constructor(); // changed\n for (var key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n obj['isActiveClone'] = null;\n temp[key] = cloneObject(obj[key]);\n delete obj['isActiveClone'];\n }\n }\n return temp;\n}\n\nvar b = cloneObject({\"a\":1,\"b\":2}); // calling\n" }, { "answer_id": 46759423, "author": "Julez", "author_id": 1502014, "author_profile": "https://Stackoverflow.com/users/1502014", "pm_score": 2, "selected": false, "text": "ES2015" }, { "answer_id": 48360733, "author": "Константин Ван", "author_id": 4510033, "author_profile": "https://Stackoverflow.com/users/4510033", "pm_score": 2, "selected": false, "text": "Promise" }, { "answer_id": 49497485, "author": "codeMonkey", "author_id": 4009972, "author_profile": "https://Stackoverflow.com/users/4009972", "pm_score": 3, "selected": false, "text": "let objectToCopy = someObj;\nlet copyOfObject = {};\nObject.defineProperties(copyOfObject, Object.getOwnPropertyDescriptors(objectToCopy));\n// copyOfObject will now be the same as objectToCopy\n" }, { "answer_id": 50937561, "author": "Parabolord", "author_id": 9154756, "author_profile": "https://Stackoverflow.com/users/9154756", "pm_score": 3, "selected": false, "text": "JSON.parse(JSON.stringify(obj))" }, { "answer_id": 51013125, "author": "Vikram K", "author_id": 4960055, "author_profile": "https://Stackoverflow.com/users/4960055", "pm_score": 2, "selected": false, "text": "let obj = {a : \"foo\", b:\"bar\" , c:10 , d:true , e:[1,2,3] };\n\nlet objClone = { ...obj };\n" }, { "answer_id": 51357086, "author": "Jinu Joseph Daniel", "author_id": 822982, "author_profile": "https://Stackoverflow.com/users/822982", "pm_score": 2, "selected": false, "text": "function deepClone(obj) {\n /*\n * Duplicates an object \n */\n\n var ret = null;\n if (obj !== Object(obj)) { // primitive types\n return obj;\n }\n if (obj instanceof String || obj instanceof Number || obj instanceof Boolean) { // string objecs\n ret = obj; // for ex: obj = new String(\"Spidergap\")\n } else if (obj instanceof Date) { // date\n ret = new obj.constructor();\n } else\n ret = Object.create(obj.constructor.prototype);\n\n var prop = null;\n var allProps = Object.getOwnPropertyNames(obj); //gets non enumerables also\n\n\n var props = {};\n for (var i in allProps) {\n prop = allProps[i];\n props[prop] = false;\n }\n\n for (i in obj) {\n props[i] = i;\n }\n\n //now props contain both enums and non enums \n var propDescriptor = null;\n var newPropVal = null; // value of the property in new object\n for (i in props) {\n prop = obj[i];\n propDescriptor = Object.getOwnPropertyDescriptor(obj, i);\n\n if (Array.isArray(prop)) { //not backward compatible\n prop = prop.slice(); // to copy the array\n } else\n if (prop instanceof Date == true) {\n prop = new prop.constructor();\n } else\n if (prop instanceof Object == true) {\n if (prop instanceof Function == true) { // function\n if (!Function.prototype.clone) {\n Function.prototype.clone = function() {\n var that = this;\n var temp = function tmp() {\n return that.apply(this, arguments);\n };\n for (var ky in this) {\n temp[ky] = this[ky];\n }\n return temp;\n }\n }\n prop = prop.clone();\n\n } else // normal object \n {\n prop = deepClone(prop);\n }\n\n }\n\n newPropVal = {\n value: prop\n };\n if (propDescriptor) {\n /*\n * If property descriptors are there, they must be copied\n */\n newPropVal.enumerable = propDescriptor.enumerable;\n newPropVal.writable = propDescriptor.writable;\n\n }\n if (!ret.hasOwnProperty(i)) // when String or other predefined objects\n Object.defineProperty(ret, i, newPropVal); // non enumerable\n\n }\n return ret;\n}\n" }, { "answer_id": 51741812, "author": "Tính Ngô Quang", "author_id": 2949104, "author_profile": "https://Stackoverflow.com/users/2949104", "pm_score": 7, "selected": false, "text": "var obj = { \n a: 1,\n b: { \n c: 2\n }\n}\nvar newObj = JSON.parse(JSON.stringify(obj));\nobj.b.c = 20;\nconsole.log(obj); // { a: 1, b: { c: 20 } }\nconsole.log(newObj); // { a: 1, b: { c: 2 } } \n" }, { "answer_id": 51982744, "author": "Prasanth Jaya", "author_id": 2148827, "author_profile": "https://Stackoverflow.com/users/2148827", "pm_score": 2, "selected": false, "text": "JSON.parse(JSON.stringify(object))" }, { "answer_id": 52736806, "author": "shunryu111", "author_id": 2630316, "author_profile": "https://Stackoverflow.com/users/2630316", "pm_score": 2, "selected": false, "text": "const map1 = Immutable.fromJS( { a: 1, b: 2, c: { d: 3 } } );\nconst map2 = map1.setIn( [ 'c', 'd' ], 50 );\n\nconsole.log( `${ map1.getIn( [ 'c', 'd' ] ) } vs ${ map2.getIn( [ 'c', 'd' ] ) }` ); // \"3 vs 50\"\n" }, { "answer_id": 53151804, "author": "chandan gupta", "author_id": 8869104, "author_profile": "https://Stackoverflow.com/users/8869104", "pm_score": 4, "selected": false, "text": "deepCopy" }, { "answer_id": 54526566, "author": "Mystical", "author_id": 6368005, "author_profile": "https://Stackoverflow.com/users/6368005", "pm_score": 0, "selected": false, "text": "function deepClone(o) {\n var keys = Object.keys(o);\n var values = Object.values(o);\n\n var clone = {};\n\n keys.forEach(function(key, i) {\n clone[key] = typeof values[i] == 'object' ? Object.create(values[i]) : values[i];\n });\n\n return clone;\n}\n" }, { "answer_id": 54535859, "author": "shakthi nagaraj", "author_id": 7241090, "author_profile": "https://Stackoverflow.com/users/7241090", "pm_score": 1, "selected": false, "text": "function clone(obj) {\n var copy;\n\n // Handle the 3 simple types, and null or undefined\n if (null == obj || \"object\" != typeof obj) return obj;\n\n // Handle Date\n if (obj instanceof Date) {\n copy = new Date();\n copy.setTime(obj.getTime());\n return copy;\n }\n\n // Handle Array\n if (obj instanceof Array) {\n copy = [];\n for (var i = 0, len = obj.length; i < len; i++) {\n copy[i] = clone(obj[i]);\n }\n return copy;\n }\n\n // Handle Object\n if (obj instanceof Object) {\n copy = {};\n for (var attr in obj) {\n if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);\n }\n return copy;\n }\n\n throw new Error(\"Unable to copy obj! Its type isn't supported.\");\n}\n" }, { "answer_id": 55701165, "author": "Shidersz", "author_id": 10366495, "author_profile": "https://Stackoverflow.com/users/10366495", "pm_score": 2, "selected": false, "text": "const obj = {\n key1: {key11: \"key11\", key12: \"key12\", key13: {key131: 22}},\n key2: {key21: \"key21\", key22: \"key22\"},\n key3: \"key3\",\n key4: [1,2,3, {key: \"value\"}]\n}\n\nconst cloneObj = (obj) =>\n{\n if (Object(obj) !== obj)\n return obj;\n else if (Array.isArray(obj))\n return obj.map(cloneObj);\n\n return Object.fromEntries(Object.entries(obj).map(\n ([k,v]) => ([k, cloneObj(v)])\n ));\n}\n\n// Clone the original object.\nlet newObj = cloneObj(obj);\n\n// Make changes on the original object.\nobj.key1.key11 = \"TEST\";\nobj.key3 = \"TEST\";\nobj.key1.key13.key131 = \"TEST\";\nobj.key4[1] = \"TEST\";\nobj.key4[3].key = \"TEST\";\n\n// Display both objects on the console.\nconsole.log(\"Original object: \", obj);\nconsole.log(\"Cloned object: \", newObj);" }, { "answer_id": 56207766, "author": "Kamyar", "author_id": 3281955, "author_profile": "https://Stackoverflow.com/users/3281955", "pm_score": 2, "selected": false, "text": "Object.assign()" }, { "answer_id": 56336059, "author": "KRIPA SHANKAR JHA", "author_id": 9249953, "author_profile": "https://Stackoverflow.com/users/9249953", "pm_score": 3, "selected": false, "text": "Object.assign({},sourceObj)" }, { "answer_id": 57340254, "author": "Ankur Kedia", "author_id": 6419016, "author_profile": "https://Stackoverflow.com/users/6419016", "pm_score": 2, "selected": false, "text": "function deepClone(obj) {\n if (typeof obj !== \"object\") {\n return obj;\n } else {\n let newObj =\n typeof obj === \"object\" && obj.length !== undefined ? [] : {};\n for (let key in obj) {\n if (key) {\n newObj[key] = deepClone(obj[key]);\n }\n }\n return newObj;\n }\n}\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122102", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12694/" ]
122,104
<p>Say I have a page that display search results. I search for stackoverflow and it returns 5000 results, 10 per page. Now I find myself doing this when building links on that page:</p> <pre><code>&lt;%=Html.ActionLink("Page 1", "Search", new { query=ViewData["query"], page etc..%&gt; &lt;%=Html.ActionLink("Page 2", "Search", new { query=ViewData["query"], page etc..%&gt; &lt;%=Html.ActionLink("Page 3", "Search", new { query=ViewData["query"], page etc..%&gt; &lt;%=Html.ActionLink("Next", "Search", new { query=ViewData["query"], page etc..%&gt; </code></pre> <p>I dont like this, I have to build my links with careful consideration to what was posted previously etc.. </p> <p>What I'd like to do is</p> <pre><code>&lt;%=Html.BuildActionLinkUsingCurrentActionPostData ("Next", "Search", new { Page = 1}); </code></pre> <p>where the anonymous dictionary overrides anything currently set by previous action. </p> <p>Essentially I care about what the previous action parameters were, because I want to reuse, it sounds simple, but start adding sort and loads of advance search options and it starts getting messy.</p> <p>Im probably missing something obvious</p>
[ { "answer_id": 123454, "author": "Switters", "author_id": 1860358, "author_profile": "https://Stackoverflow.com/users/1860358", "pm_score": 1, "selected": false, "text": "<div id=\"product_list\">\n <% foreach (TestMVC.Product product in ViewData.Model)\n { %>\n <% Html.RenderPartial(\"ProductEntry\", product); %>\n <% } %>\n</div>\n" }, { "answer_id": 1228074, "author": "Daniel Chambers", "author_id": 107512, "author_profile": "https://Stackoverflow.com/users/107512", "pm_score": 4, "selected": false, "text": "private static RouteValueDictionary CreateRouteToCurrentPage(HtmlHelper html)\n{\n RouteValueDictionary routeValues \n = new RouteValueDictionary(html.ViewContext.RouteData.Values);\n\n NameValueCollection queryString \n = html.ViewContext.HttpContext.Request.QueryString;\n\n foreach (string key in queryString.Cast<string>())\n {\n routeValues[key] = queryString[key];\n }\n\n return routeValues;\n}\n" }, { "answer_id": 1582050, "author": "Jalal El-Shaer", "author_id": 95380, "author_profile": "https://Stackoverflow.com/users/95380", "pm_score": 1, "selected": false, "text": " public static string EnhancedActionLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, bool keepQueryStrings)\n {\n ViewContext context = helper.ViewContext;\n IDictionary<string, object> htmlAttributes = null;\n RouteValueDictionary routeValues = null;\n string actionLink = string.Empty;\n if (keepQueryStrings && context.RequestContext.HttpContext.Request.QueryString.Keys.Count > 0)\n {\n routeValues = new RouteValueDictionary(context.RouteData.Values);\n foreach (string key in context.RequestContext.HttpContext.Request.QueryString.Keys)\n {\n routeValues[key] = context.RequestContext.HttpContext.Request.QueryString[key];\n }\n } \n actionLink = helper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes);\n return actionLink;\n }\n" }, { "answer_id": 11305841, "author": "h3n", "author_id": 182332, "author_profile": "https://Stackoverflow.com/users/182332", "pm_score": 0, "selected": false, "text": "\n public static class ActionLinkExtension\n {\n public static MvcHtmlString ActionLinkWithQueryString(this HtmlHelper helper, string linkText, string action, string controller, object routeValues)\n {\n var context = helper.ViewContext;\n\n var currentRouteValues = new RouteValueDictionary(context.RouteData.Values);\n foreach (string key in context.HttpContext.Request.QueryString.Keys)\n {\n currentRouteValues[key] = context.HttpContext.Request.QueryString[key];\n }\n\n var newRouteValues = new RouteValueDictionary(routeValues);\n\n foreach (var route in newRouteValues)\n {\n if (!currentRouteValues.ContainsKey(route.Key))\n {\n currentRouteValues.Add(route.Key, route.Value);\n }\n else\n {\n currentRouteValues[route.Key] = route.Value;\n }\n }\n\n return helper.ActionLink(linkText, action, controller, currentRouteValues, null);\n }\n\n }\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122104", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
122,105
<p>I want to filter a <code>java.util.Collection</code> based on a predicate.</p>
[ { "answer_id": 122204, "author": "jon", "author_id": 12215, "author_profile": "https://Stackoverflow.com/users/12215", "pm_score": 3, "selected": false, "text": "public interface Predicate<T> {\n public boolean filter(T t);\n}\n\nvoid filterCollection(Collection<T> col, Predicate<T> predicate) {\n for (Iterator i = col.iterator(); i.hasNext();) {\n T obj = i.next();\n if (predicate.filter(obj)) {\n i.remove();\n }\n }\n}\n" }, { "answer_id": 122206, "author": "Vladimir Dyuzhev", "author_id": 1163802, "author_profile": "https://Stackoverflow.com/users/1163802", "pm_score": 6, "selected": false, "text": "Iterator<Foo> it = col.iterator();\nwhile( it.hasNext() ) {\n Foo foo = it.next();\n if( !condition(foo) ) it.remove();\n}\n" }, { "answer_id": 122207, "author": "Alan", "author_id": 17205, "author_profile": "https://Stackoverflow.com/users/17205", "pm_score": 8, "selected": false, "text": "public interface IPredicate<T> { boolean apply(T type); }\n" }, { "answer_id": 337135, "author": "akuhn", "author_id": 24468, "author_profile": "https://Stackoverflow.com/users/24468", "pm_score": 3, "selected": false, "text": "import static ch.akuhn.util.query.Query.select;\nimport static ch.akuhn.util.query.Query.$result;\nimport ch.akuhn.util.query.Select;\n\nCollection<String> collection = ...\n\nfor (Select<String> each : select(collection)) {\n each.yield = each.value.length() > 3;\n}\n\nCollection<String> result = $result();\n" }, { "answer_id": 1385698, "author": "Mario Fusco", "author_id": 112779, "author_profile": "https://Stackoverflow.com/users/112779", "pm_score": 11, "selected": true, "text": "List<Person> beerDrinkers = persons.stream()\n .filter(p -> p.getAge() > 16).collect(Collectors.toList());\n" }, { "answer_id": 2106948, "author": "jdc0589", "author_id": 113173, "author_profile": "https://Stackoverflow.com/users/113173", "pm_score": 2, "selected": false, "text": "LinkedList<Person> list = ......\nLinkedList<Person> filtered = \n Query.from(list).where(Condition.ensure(\"age\", Op.GTE, 21));\n" }, { "answer_id": 2578408, "author": "Vincent Robert", "author_id": 268, "author_profile": "https://Stackoverflow.com/users/268", "pm_score": 2, "selected": false, "text": "List<Integer> myList = new ArrayList<Integer>(){ 1, 2, 3, 4, 5 }\n\nIterable<Integer> filtered = Iterable.wrap(myList).select(new Predicate1<Integer>()\n{\n public Boolean call(Integer n) throws FunctionalException\n {\n return n % 2 == 0;\n }\n})\n\nfor( int n : filtered )\n{\n System.out.println(n);\n}\n" }, { "answer_id": 12573823, "author": "Donald Raab", "author_id": 1570415, "author_profile": "https://Stackoverflow.com/users/1570415", "pm_score": 3, "selected": false, "text": "List<Integer> jdkList = Arrays.asList(1, 2, 3, 4, 5);\nMutableList<Integer> ecList = Lists.mutable.with(1, 2, 3, 4, 5);\n" }, { "answer_id": 18508956, "author": "gavenkoa", "author_id": 173149, "author_profile": "https://Stackoverflow.com/users/173149", "pm_score": 5, "selected": false, "text": "List<Person> olderThan30 = \n //Create a Stream from the personList\n personList.stream().\n //filter the element to select only those with age >= 30\n filter(p -> p.age >= 30).\n //put those filtered elements into a new List.\n collect(Collectors.toList());\n" }, { "answer_id": 19623934, "author": "Josh M", "author_id": 1255746, "author_profile": "https://Stackoverflow.com/users/1255746", "pm_score": 4, "selected": false, "text": "Collection<T> collection = ...;\nStream<T> stream = collection.stream().filter(...);\n" }, { "answer_id": 23601384, "author": "Nestor Hernandez Loli", "author_id": 1434175, "author_profile": "https://Stackoverflow.com/users/1434175", "pm_score": 3, "selected": false, "text": " List<Customer> list ...;\n List<Customer> newList = new ArrayList<>();\n for (Customer c : list){\n if (c.getName().equals(\"dd\")) newList.add(c);\n }\n" }, { "answer_id": 24561326, "author": "Andrew McKnight", "author_id": 581986, "author_profile": "https://Stackoverflow.com/users/581986", "pm_score": 1, "selected": false, "text": "ArrayList<Item> filtered = new ArrayList<Item>(); \nfor (Item item : items) if (condition(item)) filtered.add(item);\n" }, { "answer_id": 24924039, "author": "anon", "author_id": 577062, "author_profile": "https://Stackoverflow.com/users/577062", "pm_score": 4, "selected": false, "text": "Observable.from(Arrays.asList(1, 2, 3, 4, 5))\n .filter(new Func1<Integer, Boolean>() {\n public Boolean call(Integer i) {\n return i % 2 != 0;\n }\n })\n .subscribe(new Action1<Integer>() {\n public void call(Integer i) {\n System.out.println(i);\n }\n });\n" }, { "answer_id": 25645013, "author": "Low Flying Pelican", "author_id": 847853, "author_profile": "https://Stackoverflow.com/users/847853", "pm_score": 1, "selected": false, "text": "Collection<Dto> testList = new ArrayList<>();\n" }, { "answer_id": 27818083, "author": "Lawrence", "author_id": 1435079, "author_profile": "https://Stackoverflow.com/users/1435079", "pm_score": 2, "selected": false, "text": "public abstract class AbstractFilter<T> {\n\n /**\n * Method that returns whether an item is to be included or not.\n * @param item an item from the given collection.\n * @return true if this item is to be included in the collection, false in case it has to be removed.\n */\n protected abstract boolean excludeItem(T item);\n\n public void filter(Collection<T> collection) {\n if (CollectionUtils.isNotEmpty(collection)) {\n Iterator<T> iterator = collection.iterator();\n while (iterator.hasNext()) {\n if (excludeItem(iterator.next())) {\n iterator.remove();\n }\n }\n }\n }\n}\n" }, { "answer_id": 29795865, "author": "vikingsteve", "author_id": 1993366, "author_profile": "https://Stackoverflow.com/users/1993366", "pm_score": 1, "selected": false, "text": "CollectionUtils" }, { "answer_id": 34245383, "author": "hd84335", "author_id": 1387113, "author_profile": "https://Stackoverflow.com/users/1387113", "pm_score": 2, "selected": false, "text": "java 8" }, { "answer_id": 41160462, "author": "ZhekaKozlov", "author_id": 706317, "author_profile": "https://Stackoverflow.com/users/706317", "pm_score": 0, "selected": false, "text": "Collection<Integer> collection = Lists.newArrayList(1, 2, 3, 4, 5);\n\nIterators.removeIf(collection.iterator(), new Predicate<Integer>() {\n @Override\n public boolean apply(Integer i) {\n return i % 2 == 0;\n }\n});\n\nSystem.out.println(collection); // Prints 1, 3, 5\n" }, { "answer_id": 44570130, "author": "Fredrik Metcalf", "author_id": 1200563, "author_profile": "https://Stackoverflow.com/users/1200563", "pm_score": 1, "selected": false, "text": "public class Filter {\n public static <T> void List(List<T> list, Chooser<T> chooser) {\n List<Integer> toBeRemoved = new ArrayList<>();\n leftloop:\n for (int right = 1; right < list.size(); ++right) {\n for (int left = 0; left < right; ++left) {\n if (toBeRemoved.contains(left)) {\n continue;\n }\n Keep keep = chooser.choose(list.get(left), list.get(right));\n switch (keep) {\n case LEFT:\n toBeRemoved.add(right);\n continue leftloop;\n case RIGHT:\n toBeRemoved.add(left);\n break;\n case NONE:\n toBeRemoved.add(left);\n toBeRemoved.add(right);\n continue leftloop;\n }\n }\n }\n\n Collections.sort(toBeRemoved, new Comparator<Integer>() {\n @Override\n public int compare(Integer o1, Integer o2) {\n return o2 - o1;\n }\n });\n\n for (int i : toBeRemoved) {\n if (i >= 0 && i < list.size()) {\n list.remove(i);\n }\n }\n }\n\n public static <T> void List(List<T> list, Keeper<T> keeper) {\n Iterator<T> iterator = list.iterator();\n while (iterator.hasNext()) {\n if (!keeper.keep(iterator.next())) {\n iterator.remove();\n }\n }\n }\n\n public interface Keeper<E> {\n boolean keep(E obj);\n }\n\n public interface Chooser<E> {\n Keep choose(E left, E right);\n }\n\n public enum Keep {\n LEFT, RIGHT, BOTH, NONE;\n }\n}\n" }, { "answer_id": 50511268, "author": "yanefedor", "author_id": 4545552, "author_profile": "https://Stackoverflow.com/users/4545552", "pm_score": 3, "selected": false, "text": "Collectors.filtering" }, { "answer_id": 52875398, "author": "pramod_m", "author_id": 4312010, "author_profile": "https://Stackoverflow.com/users/4312010", "pm_score": 2, "selected": false, "text": " List<String> lines = Arrays.asList(\"java\", \"pramod\", \"example\");\n\n List<String> result = lines.stream() \n .filter(line -> !\"pramod\".equals(line)) \n .collect(Collectors.toList()); \n\n result.forEach(System.out::println); \n" }, { "answer_id": 68547203, "author": "Muhammad Hamed K", "author_id": 7988380, "author_profile": "https://Stackoverflow.com/users/7988380", "pm_score": 1, "selected": false, "text": "List<Person> personsList = persons.stream()\n.filter(p -> p.getAdrress() != null).collect(Collectors.toList());\n" }, { "answer_id": 69423954, "author": "Kevin Lano", "author_id": 14192015, "author_profile": "https://Stackoverflow.com/users/14192015", "pm_score": 0, "selected": false, "text": "ArrayList<Word> sel = Ocl.selectSequence(words, \n w -> w.pos.equals(\"NN\")); \nint total = Ocl.sumint(Ocl.collectSequence(sel,\n w -> w.text.length())); \n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122105", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4792/" ]
122,107
<p><strong>"It is not possible to check out a single file. The finest level of checkouts you can do is at the directory level."</strong></p> <p>How do I get around this issue when using Subversion?</p> <p>We have this folder in Subversion where we keep all our images. I just want to check out one file (image) from that. This folder is really big and has ton of other stuff which I don't need now.</p>
[ { "answer_id": 122126, "author": "Milan Babuškov", "author_id": 14690, "author_profile": "https://Stackoverflow.com/users/14690", "pm_score": 6, "selected": false, "text": "svn cat" }, { "answer_id": 122134, "author": "Mnementh", "author_id": 21005, "author_profile": "https://Stackoverflow.com/users/21005", "pm_score": 7, "selected": false, "text": "svn export" }, { "answer_id": 122149, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 2, "selected": false, "text": "svn import" }, { "answer_id": 122156, "author": "Ted", "author_id": 8965, "author_profile": "https://Stackoverflow.com/users/8965", "pm_score": 2, "selected": false, "text": "svn export <URL>\n" }, { "answer_id": 122291, "author": "Steve Jessop", "author_id": 13005, "author_profile": "https://Stackoverflow.com/users/13005", "pm_score": 10, "selected": true, "text": "svn export" }, { "answer_id": 369681, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "cd C:\\path\\dir\nsvn checkout https://server/path/to/trunk/dir/dir/parent_dir--depth empty\ncd C:\\path\\dir\\parent_dir\nsvn update filename.log\n" }, { "answer_id": 3591876, "author": "Vass", "author_id": 410975, "author_profile": "https://Stackoverflow.com/users/410975", "pm_score": 2, "selected": false, "text": " svn co --depth files <source> <local dest>\n" }, { "answer_id": 3974032, "author": "blanne", "author_id": 400068, "author_profile": "https://Stackoverflow.com/users/400068", "pm_score": 3, "selected": false, "text": "svn propedit svn:externals .\n" }, { "answer_id": 9144620, "author": "hendergassler", "author_id": 1189892, "author_profile": "https://Stackoverflow.com/users/1189892", "pm_score": 2, "selected": false, "text": "svn co http://subversion.repository.server/repository/module/directory/myfile /**directoryb**\n" }, { "answer_id": 10313106, "author": "Manish Singh", "author_id": 1307864, "author_profile": "https://Stackoverflow.com/users/1307864", "pm_score": 2, "selected": false, "text": "mkdir <your directory>/repos/test\n\nsvn cat http://svn.red-bean.com/repos/test/readme.txt > <your directory>/repos/test/readme.txt\n" }, { "answer_id": 19690880, "author": "Arthur Niu", "author_id": 2920375, "author_profile": "https://Stackoverflow.com/users/2920375", "pm_score": 4, "selected": false, "text": "$ cd /tmp\n\n$ svn co --depth empty http://svn.your.company.ca/training/trunk/sql\n" }, { "answer_id": 41439465, "author": "LachoTomov", "author_id": 931409, "author_profile": "https://Stackoverflow.com/users/931409", "pm_score": 2, "selected": false, "text": "$ cd /yourfolder\nsvn co https://path-to-folder-which-has-your-files/ --depth files\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122107", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1175964/" ]
122,108
<p>I have implemented the WMD control that Stack Overflow uses into a project of mine, it <strong>almost</strong> works like a charm, but when I save the changes to the database it is saving the HTML version and not the Markdown version.</p> <p>So where I have this in my text box:</p> <pre><code>**boldtext** </code></pre> <p>It is really saving this:</p> <pre><code>&lt;b&gt;boldtext&lt;/b&gt; </code></pre> <p>How do I make it save the Markdown version?</p>
[ { "answer_id": 122572, "author": "Clinton Dreisbach", "author_id": 6262, "author_profile": "https://Stackoverflow.com/users/6262", "pm_score": 4, "selected": true, "text": "wmd.js" }, { "answer_id": 5369774, "author": "Ryan Yonzon", "author_id": 668358, "author_profile": "https://Stackoverflow.com/users/668358", "pm_score": 1, "selected": false, "text": "wmd.wmd_env.output = 'markdown';\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1768/" ]
122,110
<p>I'm a big fan of the Jadclipse plugin and I'd really like to upgrade to Eclipse 3.4 but the plugin currently does not work. Are there any other programs out there that let you use jad to view source of code you navigate to from Eclipse? (Very useful when delving into ambiguous code in stack traces).</p>
[ { "answer_id": 442887, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "java.lang.IncompatibleClassChangeError\n at net.sf.jadclipse.JadclipseClassFileEditor.doOpenBuffer(JadclipseClassFileEditor.java:101)\n at net.sf.jadclipse.JadclipseClassFileEditor.doSetInput(JadclipseClassFileEditor.java:45)\n at net.sf.jadclipse.JadclipseActionBarContributor.setActiveEditor(JadclipseActionBarContributor.java:87)\n at org.eclipse.ui.internal.EditorActionBars.partChanged(EditorActionBars.java:335)\n at org.eclipse.ui.internal.WorkbenchPage$3.run(WorkbenchPage.java:628)\n.....(i don't think the rest of the stack trace is important)\n" }, { "answer_id": 1811496, "author": "Laex", "author_id": 220333, "author_profile": "https://Stackoverflow.com/users/220333", "pm_score": 1, "selected": false, "text": "Cannot complete the request. See the details.\nUnsatisfied dependency: [org.codehaus.groovy.eclipse.feature.feature.group 2.0.0.20090814-1100-e34-N] requiredCapability: org.eclipse.equinox.p2.iu/org.codehaus.groovy.eclipse.core.help/[2.0.0.20090814-1100-e34-N,2.0.0.20090814-1100-e34-N]\nUnsatisfied dependency: [org.codehaus.groovy.eclipse.feature.feature.group 2.0.0.20090814-1100-e34-N] requiredCapability: org.eclipse.equinox.p2.iu/org.codehaus.groovy.jdt.patch.feature.group/[2.0.0.20090814-1100-e34-N,2.0.0.20090814-1100-e34-N]\nUnsatisfied dependency: [org.codehaus.groovy.jdt.patch.feature.group 2.0.0.20090814-1100-e34-N] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.jdt.feature.group/[3.4.2.r342_v20081217-7o7tEAoEEDWEm5HTrKn-svO4BbDI,3.4.2.r342_v20081217-7o7tEAoEEDWEm5HTrKn-svO4BbDI]\nUnsatisfied dependency: [org.codehaus.groovy.eclipse.core.help 2.0.0.20090814-1100-e34-N] requiredCapability: osgi.bundle/org.eclipse.help/3.3.102\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5885/" ]
122,115
<p>Ruby's standard popen3 module does not work on Windows. Is there a maintained replacement that allows for separating stdin, stdout, and stderr?</p>
[ { "answer_id": 122222, "author": "Max Caceres", "author_id": 4842, "author_profile": "https://Stackoverflow.com/users/4842", "pm_score": 4, "selected": true, "text": "require 'rubygems'\nrequire 'popen4'\n\nstatus =\n POpen4::popen4(\"cmd\") do |stdout, stderr, stdin, pid|\n stdin.puts \"echo hello world!\"\n stdin.puts \"echo ERROR! 1>&2\"\n stdin.puts \"exit\"\n stdin.close\n\n puts \"pid : #{ pid }\"\n puts \"stdout : #{ stdout.read.strip }\"\n puts \"stderr : #{ stderr.read.strip }\"\n end\n\nputs \"status : #{ status.inspect }\"\nputs \"exitstatus : #{ status.exitstatus }\"\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122115", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4842/" ]
122,127
<p>In order to create the proper queries I need to be able to run a query against the same datasource that the report is using. How do I get that information <strong>programatically</strong>? Preferably the connection string or pieces of data used to build the connection string.</p>
[ { "answer_id": 122423, "author": "Orion Adrian", "author_id": 7756, "author_profile": "https://Stackoverflow.com/users/7756", "pm_score": 2, "selected": true, "text": "DataSourceDefinition dataSourceDefinition \n = reportingService.GetDataSourceContents(\"DataSourceName\");\n\nstring connectionString = dataSourceDefinition.ConnectString;\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7756/" ]
122,144
<p>Im calling a locally hosted wcf service from silverlight and I get the exception below.</p> <p>Iv created a clientaccesspolicy.xml, which is situated in the route of my host.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;access-policy&gt; &lt;cross-domain-access&gt; &lt;policy&gt; &lt;allow-from http-request-headers="*"&gt; &lt;domain uri="*"/&gt; &lt;/allow-from&gt; &lt;grant-to&gt; &lt;resource path="/" include-subpaths="true"/&gt; &lt;/grant-to&gt; &lt;/policy&gt; &lt;/cross-domain-access&gt; &lt;/access-policy&gt; </code></pre> <blockquote> <p>An error occurred while trying to make a request to URI '<a href="http://localhost:8005/Service1.svc" rel="nofollow noreferrer">http://localhost:8005/Service1.svc</a>'. This could be due to a cross domain configuration error. Please see the inner exception for more details. ---></p> <p>{System.Security.SecurityException ---> System.Security.SecurityException: Security error. at MS.Internal.InternalWebRequest.Send() at System.Net.BrowserHttpWebRequest.BeginGetResponseImplementation() at System.Net.BrowserHttpWebRequest.InternalBeginGetResponse(AsyncCallback callback, Object state) at System.Net.AsyncHelper.&lt;>c__DisplayClass4.b__3(Object sendState) --- End of inner exception stack trace --- at System.Net.AsyncHelper.BeginOnUI(BeginMethod beginMethod, AsyncCallback callback, Object state) at System.Net.BrowserHttpWebRequest.BeginGetResponse(AsyncCallback callback, Object state) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteSend(IAsyncResult result) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnSend(IAsyncResult result)}</p> </blockquote> <p>Any ideas on how to progress?</p>
[ { "answer_id": 123432, "author": "Dan", "author_id": 230, "author_profile": "https://Stackoverflow.com/users/230", "pm_score": 2, "selected": false, "text": "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">\n<cross-domain-policy>\n <allow-http-request-headers-from domain=\"*\" headers=\"*\"/>\n</cross-domain-policy>\n" }, { "answer_id": 600027, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "Bad:\n <allow-access-from domain=\"\"*\"\" headers=\"*\" />\n\nGood:\n <allow-access-from domain=\"\"*\"\" />\n <allow-http-request-headers-from domain=\"\"*\"\" headers=\"\"*\"\" />\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122144", "https://Stackoverflow.com", "https://Stackoverflow.com/users/230/" ]
122,154
<p>I'm using Team Foundation Build but we aren't yet using TFS for problem tracking, so I would like to disable the work item creation on a failed build. Is there any way to do this? I tried commenting out the work item info in the TFSBuild.proj file for the build type but that didn't do the trick.</p>
[ { "answer_id": 122660, "author": "Tim Booker", "author_id": 10046, "author_profile": "https://Stackoverflow.com/users/10046", "pm_score": 6, "selected": true, "text": "<SkipWorkItemCreation>true</SkipWorkItemCreation>\n" }, { "answer_id": 51420939, "author": "Beingnin", "author_id": 7441056, "author_profile": "https://Stackoverflow.com/users/7441056", "pm_score": 0, "selected": false, "text": "Create Work Item on failure" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/327/" ]
122,160
<p>I'm a big fan of the way Visual Studio will give you the comment documentation / parameter names when completing code that you have written and ALSO code that you are referencing (various libraries/assemblies).</p> <p>Is there an easy way to get inline javadoc/parameter names in Eclipse when doing code complete or hovering over methods? Via plugin? Via some setting? It's extremely annoying to use a lot of libraries (as happens often in Java) and then have to go to the website or local javadoc location to lookup information when you have it in the source jars right there!</p>
[ { "answer_id": 122182, "author": "Henry B", "author_id": 6414, "author_profile": "https://Stackoverflow.com/users/6414", "pm_score": 7, "selected": false, "text": "Source Attachment: (none)\nJavadoc location: (none)\nNative library location: (none)\nAccess rules: (No restrictions)\n" }, { "answer_id": 26747235, "author": "Joshua Richardson", "author_id": 973402, "author_profile": "https://Stackoverflow.com/users/973402", "pm_score": 1, "selected": false, "text": "jar {\n from sourceSets.main.allSource\n}\n" } ]
2008/09/23
[ "https://Stackoverflow.com/questions/122160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5885/" ]