qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
60,680
<p>I'm writing a small web server in Python, using BaseHTTPServer and a custom subclass of BaseHTTPServer.BaseHTTPRequestHandler. Is it possible to make this listen on more than one port?</p> <p>What I'm doing now:</p> <pre><code>class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def doGET [...] class ThreadingHTTPServer(ThreadingMixIn, HTTPServer): pass server = ThreadingHTTPServer(('localhost', 80), MyRequestHandler) server.serve_forever() </code></pre>
[ { "answer_id": 60753, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 6, "selected": true, "text": "from threading import Thread\nfrom SocketServer import ThreadingMixIn\nfrom BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler\n\nclass Handler(BaseHTTPRequestHandler):\n def do_GET(self):\n self.send_response(200)\n self.send_header(\"Content-type\", \"text/plain\")\n self.end_headers()\n self.wfile.write(\"Hello World!\")\n\nclass ThreadingHTTPServer(ThreadingMixIn, HTTPServer):\n daemon_threads = True\n\ndef serve_on_port(port):\n server = ThreadingHTTPServer((\"localhost\",port), Handler)\n server.serve_forever()\n\nThread(target=serve_on_port, args=[1111]).start()\nserve_on_port(2222)\n" }, { "answer_id": 60754, "author": "Douglas Leeder", "author_id": 3978, "author_profile": "https://Stackoverflow.com/users/3978", "pm_score": 3, "selected": false, "text": "def serve_forever(self, poll_interval=0.5):\n \"\"\"Handle one request at a time until shutdown.\n\n Polls for shutdown every poll_interval seconds. Ignores\n self.timeout. If you need to do periodic tasks, do them in\n another thread.\n \"\"\"\n self.__serving = True\n self.__is_shut_down.clear()\n while self.__serving:\n # XXX: Consider using another file descriptor or\n # connecting to the socket to wake this up instead of\n # polling. Polling reduces our responsiveness to a\n # shutdown request and wastes cpu at all other times.\n r, w, e = select.select([self], [], [], poll_interval)\n if r:\n self._handle_request_noblock()\n self.__is_shut_down.set()\n" }, { "answer_id": 61322, "author": "Thomas Vander Stichele", "author_id": 2900, "author_profile": "https://Stackoverflow.com/users/2900", "pm_score": 3, "selected": false, "text": "from twisted.internet import reactor\nfrom twisted.web import resource, server\n\nclass MyResource(resource.Resource):\n isLeaf = True\n def render_GET(self, request):\n return 'gotten'\n\nsite = server.Site(MyResource())\n\nreactor.listenTCP(8000, site)\nreactor.listenTCP(8001, site)\nreactor.run()\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4321/" ]
60,683
<p>Can you have a multicolumn listview control where one of the columns is a checkbox? Example code or links would be greatly appreciated.</p> <p>I am using visual studio 2005</p>
[ { "answer_id": 60695, "author": "Winter", "author_id": 6227, "author_profile": "https://Stackoverflow.com/users/6227", "pm_score": 4, "selected": true, "text": "\n GlacialList mylist = new GlacialList();\n\nmylist.Columns.Add( \"Column1\", 100 ); // this can also be added \n\n // through the design time support \n\nmylist.Columns.Add( \"Column2\", 100 ); \nmylist.Columns.Add( \"Column3\", 100 ); \nmylist.Columns.Add( \"Column4\", 100 ); \n\nGLItem item;\n\nitem = this.glacialList1.Items.Add( \"Atlanta Braves\" );\nitem.SubItems[1].Text = \"8v\";\nitem.SubItems[2].Text = \"Live\";\nitem.SubItems[2].BackColor = Color.Bisque;\nitem.SubItems[3].Text = \"MLB.TV\"; \n\nitem = this.glacialList1.Items.Add( \"Florida Marlins\" );\nitem.SubItems[1].Text = \"\";\nitem.SubItems[2].Text = \"Delayed\";\nitem.SubItems[2].BackColor = Color.LightCoral;\nitem.SubItems[3].Text = \"Audio\";\n\n\nitem.SubItems[1].BackColor = Color.Aqua; // set the background \n\n // of this particular subitem ONLY\n\nitem.UserObject = myownuserobjecttype; // set a private user object\n\nitem.Selected = true; // set this item to selected state\n\nitem.SubItems[1].Span = 2; // set this sub item to span 2 spaces\n\n\nArrayList selectedItems = mylist.SelectedItems; \n // get list of selected items\n" }, { "answer_id": 83882, "author": "Makis Arvanitis", "author_id": 66654, "author_profile": "https://Stackoverflow.com/users/66654", "pm_score": 5, "selected": false, "text": "this.listView1.CheckBoxes = true;\n" }, { "answer_id": 5534056, "author": "CharithJ", "author_id": 591656, "author_profile": "https://Stackoverflow.com/users/591656", "pm_score": 3, "selected": false, "text": "myListView.CheckBoxes = true;\nmyListView.Columns.Add(text, width, alignment);\n" }, { "answer_id": 30975220, "author": "Sohaib Afzal", "author_id": 4228223, "author_profile": "https://Stackoverflow.com/users/4228223", "pm_score": 2, "selected": false, "text": "CheckBoxes" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60683", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
60,684
<p><strong><em>Edit:</em></strong> This question had been tagged "Tolstoy" in appreciation of the quality and length of my writing:) Just reading the first and the last paragraph should be enough:) If you tend to select and move code with the mouse, the stuff in middle could be interesting to you.</p> <p>This question is about how you use text editors in general. I’m looking for the best way to <em>delete</em> a plurality of lines of code (no intent to patent it:) This extends to <em>transposing</em> lines, i.e. deleting and adding them somewhere else. Most importantly, I don’t want to be creating any blank lines that I have to delete separately. Sort of like Visual Studio's SHIFT+DELETE feature, but working for multiple lines at once.</p> <p>Say you want to delete line 3 from following code (tabs and newlines visualized as well). The naïve way would be to select the text between angle brackets:</p> <pre> if (true) {\n \t int i = 1;\n \t &lt;i *= 2;&gt;\n \t i += 3;\n }\n </pre> <p>Then hit backspace. This creates a blank line. Hit backspace twice more to delete \t and \n. </p> <p>You end up with:</p> <pre> if (true) {\n \t int i = 1;\n \t i += 3;\n }\n </pre> <p>When you try to select a whole line, Visual Studio doesn't let you select the trailing newline character. For example, placing the cursor on a line and hitting SHIFT+END will not select the newline at the end. Neither will you select the newline if you use your mouse, i.e. clicking in the middle of a line and dragging the cursor all the way to the right. You only select the trailing newline characters if you make a selection that spans at least two lines. Most editors I use do it this way; Microsoft WordPad and Word are counter-examples (and I frequently get newlines wrong when deleting text there; at least Word has a way to display end-of-line and end-of-paragraph characters explicitly).</p> <p>When using Visual Studio and other editors in general, here’s the solution that currently works best for me:</p> <p>Using the mouse, I select the characters that I put between angle brackets:</p> <pre> if (true) {\n \t int i = 1;&lt;\n \t i *= 2;&gt;\n \t i += 3;\n }\n </pre> <p>Hitting backspace now, you delete the line in one go without having to delete any other characters. This works for several contiguous lines at once. Additionally, it can be used for transposing lines. You could drag the selection between the angle brackets to the point marked with a caret:</p> <pre> if (true) {\n \t int i = 1;&lt;\n \t i *= 2;&gt;\n \t i += 3;^\n }\n </pre> <p>This leaves you with:</p> <pre> if (true) {\n \t int i = 1;\n \t i += 3;&lt;\n \t i *= 2;&gt;\n }\n </pre> <p>where lines 3 and 4 have switched place.</p> <p>There are variations on this theme. When you want to delete line 3, you could also select the following characters:</p> <pre> if (true) {\n \t int i = 1;\n &lt;\t i *= 2;\n &gt;\t i += 3;\n }\n </pre> <p>In fact, this is what Visual Studio does if you tell it to select a complete line. You do this by clicking in the margin between your code and the column where the red circles go which indicate breakpoints. The mouse pointer is mirrored in that area to distinguish it a little better, but I think it's too narrow and physically too far removed from the code I want to select.</p> <p>Maybe this method is useful to other people as well, even if it only serves to make them aware of how newlines are handled when selecting/deleting text:) It works nicely for most non-specialized text editors. However, given the vast amount of features and plugins for Visual Studio (which I use most), I'm sure there is better way to use it to delete and move lines of code. Getting the indentation right automatically when moving code between different blocks would be nice (i.e. without hitting "Format Document/Selection"). I'm looking forward to suggestions; no rants on micro-optimization, please:)</p> <hr> <p><strong><em>Summary of Answers</em></strong></p> <p>With respect to Visual Studio: Navigating well with the cursor keys.</p> <p>The solution that would best suit my style of going over and editing code is the <em>Eclipse</em> way:</p> <p>You can select several consecutive lines of code, where the first and the last selected line may be selected only partially. Pressing ALT+{up,down} moves the complete lines (not just the selection) up and down, fixing indentation as you go. Hitting CTRL+D deletes the lines completely (not just the selection) without leaving any unwanted blank lines. I would love to see this in Visual Studio!</p>
[ { "answer_id": 60697, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 2, "selected": false, "text": "kill-whole-line" }, { "answer_id": 60709, "author": "Nathan Fellman", "author_id": 1084, "author_profile": "https://Stackoverflow.com/users/1084", "pm_score": 2, "selected": false, "text": "dd" }, { "answer_id": 20648989, "author": "Drew", "author_id": 729907, "author_profile": "https://Stackoverflow.com/users/729907", "pm_score": 0, "selected": false, "text": "C-k" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6103/" ]
60,685
<p>What follows is a regular expression I have written to match multi-line pre-processor macros in C / C++ code. I'm by no means a regular expressions guru, so I'd welcome any advice on how I can make this better.</p> <p>Here's the regex:</p> <pre><code>\s*#define(.*\\\n)+[\S]+(?!\\) </code></pre> <p>It should match all of this:</p> <pre><code>#define foo(x) if(x) \ doSomething(x) </code></pre> <p>But only some of this (shouldn't match the next line of code:</p> <pre><code>#define foo(x) if(x) \ doSomething(x) normalCode(); </code></pre> <p>And also shouldn't match single-line preprocessor macros.</p> <p>I'm pretty sure that the regex above works - but as I said, there probably a better way of doing it, and I imagine that there are ways of breaking it. Can anyone suggest any?</p>
[ { "answer_id": 60723, "author": "Douglas Leeder", "author_id": 3978, "author_profile": "https://Stackoverflow.com/users/3978", "pm_score": 4, "selected": true, "text": "#!/usr/bin/env python\n\nTEST1=\"\"\"\n#include \"Foo.h\"\n#define bar foo\\\\\n x\n#include \"Bar.h\"\n\"\"\"\n\nTEST2=\"\"\"\n#define bar foo\n#define x 1 \\\\\n 12 \\\\\n 2 \\\\\\\\ 3\nFoobar\n\"\"\"\n\nTEST3=\"\"\"\n#define foo(x) if(x) \\\\\ndoSomething(x)\n\"\"\"\n\nTEST4=\"\"\"\n#define foo(x) if(x) \\\\\ndoSomething(x)\nnormalCode();\n\"\"\"\n\nimport re\nmatcher = re.compile(r\"^[ \\t]*#define(.*\\\\\\n)+.*$\",re.MULTILINE)\n\ndef extractDefines(s):\n mo = matcher.search(s)\n if not mo:\n print mo\n return\n print mo.group(0)\n\nextractDefines(TEST1)\nextractDefines(TEST2)\nextractDefines(TEST3)\nextractDefines(TEST4)\n" }, { "answer_id": 60729, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 2, "selected": false, "text": "start = r\"^\\s*#define\\s+\"\ncontinuation = r\"(?:.*\\\\\\n)+\"\nlastline = r\".*$\"\n\nre_multiline_macros = re.compile(start + continuation + lastline, \n re.MULTILINE)\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1304/" ]
60,720
<p>What is the best way for me to determine a controller variable's value during execution?</p> <p>For example, is there a way I can insert a break in the code, and cause the value of the variable to be output to the screen (or the log)?</p>
[ { "answer_id": 60731, "author": "Jordi Bunster", "author_id": 4272, "author_profile": "https://Stackoverflow.com/users/4272", "pm_score": 5, "selected": true, "text": "raise @foo.to_s" }, { "answer_id": 60732, "author": "John Topley", "author_id": 1450, "author_profile": "https://Stackoverflow.com/users/1450", "pm_score": 3, "selected": false, "text": "@foo" }, { "answer_id": 60737, "author": "Jaryl", "author_id": 6291, "author_profile": "https://Stackoverflow.com/users/6291", "pm_score": 3, "selected": false, "text": "raise @foo.inspect\n" }, { "answer_id": 63453, "author": "squadette", "author_id": 7754, "author_profile": "https://Stackoverflow.com/users/7754", "pm_score": 2, "selected": false, "text": "raise @foo.inspect\n" }, { "answer_id": 50114810, "author": "Daniel Garmoshka", "author_id": 1751321, "author_profile": "https://Stackoverflow.com/users/1751321", "pm_score": 0, "selected": false, "text": "gem 'pry-moves'" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3764/" ]
60,736
<p>I have a laptop running Ubuntu that I would like to act as a Subversion server. Both for myself to commit to locally, and for others remotely. What are the steps required to get this working? Please include steps to:</p> <ul> <li>Get and configure Apache, and necessary modules (I know there are other ways to create a SVN server, but I would like it Apache-specific)</li> <li>Configure a secure way of accessing the server (SSH/HTTPS)</li> <li>Configure a set of authorised users (as in, they must authorised to commit, but are free to browse)</li> <li>Validate the setup with an initial commit (a "Hello world" of sorts)</li> </ul> <p>These steps can involve any mixture of command line or GUI application instructions. If you can, please note where instructions are specific to a particular distribution or version, and where a users' choice of a particular tool can be used instead (say, <a href="https://en.wikipedia.org/wiki/GNU_nano" rel="noreferrer">nano</a> instead of <a href="http://en.wikipedia.org/wiki/Vi" rel="noreferrer">vi</a>).</p>
[ { "answer_id": 60741, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": -1, "selected": false, "text": "sudo apt-get -yq install apache2\n" }, { "answer_id": 60792, "author": "Grundlefleck", "author_id": 4120, "author_profile": "https://Stackoverflow.com/users/4120", "pm_score": 8, "selected": true, "text": "sudo apt-get install libapache2-svn apache2\n" }, { "answer_id": 26987985, "author": "Ashish Saini", "author_id": 834799, "author_profile": "https://Stackoverflow.com/users/834799", "pm_score": -1, "selected": false, "text": "$sudo apt-get install subversion\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4120/" ]
60,740
<p>Is there an IE6/PNG fix that is officially developed by the jQuery team?</p> <p>If not which of the available plugins should I use?</p>
[ { "answer_id": 2163740, "author": "Guilherme Santos", "author_id": 262002, "author_profile": "https://Stackoverflow.com/users/262002", "pm_score": 1, "selected": false, "text": "// this line\njQuery(this).find(\"img[src$=.png]:visible\").each(function() { \n// this line\njQuery(this).find(\":visible\").each(function(){\n// and this line\njQuery(this).find(\"input[src$=.png]:visible\").each(function() {\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60740", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747/" ]
60,751
<p>Currently my app uses just Direct3D9 for graphics, however in the future I' m planning to extend this to D3D10 and possibly OpenGL. The question is how can I do this in a tidy way?</p> <p>At present there are various Render methods in my code</p> <pre><code>void Render(boost::function&lt;void()&gt; &amp;Call) { D3dDevice-&gt;BeginScene(); Call(); D3dDevice-&gt;EndScene(); D3dDevice-&gt;Present(0,0,0,0); } </code></pre> <p>The function passed then depends on the exact state, eg MainMenu->Render, Loading->Render, etc. These will then oftern call the methods of other objects.</p> <pre><code>void RenderGame() { for(entity::iterator it = entity::instances.begin();it != entity::instance.end(); ++it) (*it)-&gt;Render(); UI-&gt;Render(); } </code></pre> <p>And a sample class derived from entity::Base</p> <pre><code>class Sprite: public Base { IDirect3DTexture9 *Tex; Point2 Pos; Size2 Size; public: Sprite(IDirect3DTexture9 *Tex, const Point2 &amp;Pos, const Size2 &amp;Size); virtual void Render(); }; </code></pre> <p>Each method then takes care of how best to render given the more detailed settings (eg are pixel shaders supported or not).</p> <p>The problem is I'm really not sure how to extend this to be able to use one of, what may be somewhat different (D3D v OpenGL) render modes...</p>
[ { "answer_id": 60790, "author": "Tobi", "author_id": 5422, "author_profile": "https://Stackoverflow.com/users/5422", "pm_score": 4, "selected": true, "text": "class IRenderer {\n public:\n virtual ~IRenderer() {}\n virtual void RenderModel(CModel* model) = 0;\n virtual void DrawScreenQuad(int x1, int y1, int x2, int y2) = 0;\n // ...etc...\n};\n\nclass COpenGLRenderer : public IRenderer {\n public:\n virtual void RenderModel(CModel* model) {\n // render model using OpenGL\n }\n virtual void DrawScreenQuad(int x1, int y1, int x2, int y2) {\n // draw screen aligned quad using OpenGL\n }\n};\n\nclass CDirect3DRenderer : public IRenderer {\n // similar, but render using Direct3D\n};\n" }, { "answer_id": 69100, "author": "Baxissimo", "author_id": 9631, "author_profile": "https://Stackoverflow.com/users/9631", "pm_score": 1, "selected": false, "text": "Ogre3D" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6266/" ]
60,757
<p>What is the best way to handle user account management in a system, without having your employees who have access to a database, to have access to the accounts.</p> <p>Examples:</p> <ol> <li><p>Storing username/password in the database. This is a bad idea because anyone that has access to a database can see the username and password. And hence use it.</p></li> <li><p>Storing username/password hash. This is a better method, but the account can be accessed by replacing the password hash in the database with the hash of another account that you know the auth info for. Then after access is granted reverting it back in the database. </p></li> </ol> <p>How does windows/*nix handle this?</p>
[ { "answer_id": 60864, "author": "Mr Shark", "author_id": 6093, "author_profile": "https://Stackoverflow.com/users/6093", "pm_score": 2, "selected": false, "text": "SetPassword(user, password)\n salt = RandomString()\n hash = Hashfunction(salt+password)\n StoreInDatabase(user, salt, hash)\n\nCheckPassword(user, password)\n (salt, hash) = GetFromDatabase(user)\n if Hashfunction(salt+password) == hash\n return \"Success\"\n else\n return \"Login Failed\"\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
60,764
<p>Why is it so hard to do this in Java? If you want to have any kind of module system you need to be able to load JAR files dynamically. I'm told there's a way of doing it by writing your own <code>ClassLoader</code>, but that's a lot of work for something that should (in my mind at least) be as easy as calling a method with a JAR file as its argument.</p> <p>Any suggestions for simple code that does this?</p>
[ { "answer_id": 60766, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 7, "selected": false, "text": "File file = ...\nURL url = file.toURI().toURL();\n\nURLClassLoader classLoader = (URLClassLoader)ClassLoader.getSystemClassLoader();\nMethod method = URLClassLoader.class.getDeclaredMethod(\"addURL\", URL.class);\nmethod.setAccessible(true);\nmethod.invoke(classLoader, url);\n" }, { "answer_id": 60775, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 9, "selected": true, "text": "URLClassLoader child = new URLClassLoader(\n new URL[] {myJar.toURI().toURL()},\n this.getClass().getClassLoader()\n);\nClass classToLoad = Class.forName(\"com.MyClass\", true, child);\nMethod method = classToLoad.getDeclaredMethod(\"myMethod\");\nObject instance = classToLoad.newInstance();\nObject result = method.invoke(instance);\n" }, { "answer_id": 63892, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "public void initialize(String libDir) throws Exception {\n File dependencyDirectory = new File(libDir);\n File[] files = dependencyDirectory.listFiles();\n ArrayList<URL> urls = new ArrayList<URL>();\n for (int i = 0; i < files.length; i++) {\n if (files[i].getName().endsWith(\".jar\")) {\n urls.add(files[i].toURL());\n //urls.add(files[i].toURI().toURL());\n }\n }\n classLoader = new JarFileClassLoader(\"Scheduler CL\" + System.currentTimeMillis(), \n urls.toArray(new URL[urls.size()]), \n GFClassLoader.class.getClassLoader());\n}\n" }, { "answer_id": 1450837, "author": "Chris", "author_id": 92813, "author_profile": "https://Stackoverflow.com/users/92813", "pm_score": 5, "selected": false, "text": "JarClassLoader jcl = new JarClassLoader();\njcl.add(\"myjar.jar\"); // Load jar file \njcl.add(new URL(\"http://myserver.com/myjar.jar\")); // Load jar from a URL\njcl.add(new FileInputStream(\"myotherjar.jar\")); // Load jar file from stream\njcl.add(\"myclassfolder/\"); // Load class folder \njcl.add(\"myjarlib/\"); // Recursively load all jar files in the folder/sub-folder(s)\n\nJclObjectFactory factory = JclObjectFactory.getInstance();\n// Create object of loaded class \nObject obj = factory.create(jcl, \"mypackage.MyClass\");\n" }, { "answer_id": 2593771, "author": "Jonathan Nadeau", "author_id": 311140, "author_profile": "https://Stackoverflow.com/users/311140", "pm_score": 4, "selected": false, "text": "/**************************************************************************************************\n * Copyright (c) 2004, Federal University of So Carlos *\n * *\n * All rights reserved. *\n * *\n * Redistribution and use in source and binary forms, with or without modification, are permitted *\n * provided that the following conditions are met: *\n * *\n * * Redistributions of source code must retain the above copyright notice, this list of *\n * conditions and the following disclaimer. *\n * * Redistributions in binary form must reproduce the above copyright notice, this list of *\n * * conditions and the following disclaimer in the documentation and/or other materials *\n * * provided with the distribution. *\n * * Neither the name of the Federal University of So Carlos nor the names of its *\n * * contributors may be used to endorse or promote products derived from this software *\n * * without specific prior written permission. *\n * *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *\n * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *\n * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *\n * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *\n * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *\n * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *\n * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *\n **************************************************************************************************/\n/*\n * Created on Oct 6, 2004\n */\npackage tools;\n\nimport java.io.File;\nimport java.io.IOException;\nimport java.lang.reflect.Constructor;\nimport java.lang.reflect.InvocationTargetException;\nimport java.lang.reflect.Method;\nimport java.net.URL;\nimport java.net.URLClassLoader;\n\n/**\n * Useful class for dynamically changing the classpath, adding classes during runtime. \n */\npublic class ClasspathHacker {\n /**\n * Parameters of the method to add an URL to the System classes. \n */\n private static final Class<?>[] parameters = new Class[]{URL.class};\n\n /**\n * Adds a file to the classpath.\n * @param s a String pointing to the file\n * @throws IOException\n */\n public static void addFile(String s) throws IOException {\n File f = new File(s);\n addFile(f);\n }\n\n /**\n * Adds a file to the classpath\n * @param f the file to be added\n * @throws IOException\n */\n public static void addFile(File f) throws IOException {\n addURL(f.toURI().toURL());\n }\n\n /**\n * Adds the content pointed by the URL to the classpath.\n * @param u the URL pointing to the content to be added\n * @throws IOException\n */\n public static void addURL(URL u) throws IOException {\n URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();\n Class<?> sysclass = URLClassLoader.class;\n try {\n Method method = sysclass.getDeclaredMethod(\"addURL\",parameters);\n method.setAccessible(true);\n method.invoke(sysloader,new Object[]{ u }); \n } catch (Throwable t) {\n t.printStackTrace();\n throw new IOException(\"Error, could not add URL to system classloader\");\n } \n }\n\n public static void main(String args[]) throws IOException, SecurityException, ClassNotFoundException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{\n addFile(\"C:\\\\dynamicloading.jar\");\n Constructor<?> cs = ClassLoader.getSystemClassLoader().loadClass(\"test.DymamicLoadingTest\").getConstructor(String.class);\n DymamicLoadingTest instance = (DymamicLoadingTest)cs.newInstance();\n instance.test();\n }\n}\n" }, { "answer_id": 18253109, "author": "Caner", "author_id": 448625, "author_profile": "https://Stackoverflow.com/users/448625", "pm_score": 3, "selected": false, "text": "String jarFile = \"path/to/jarfile.jar\";\nDexClassLoader classLoader = new DexClassLoader(jarFile, \"/data/data/\" + context.getPackageName() + \"/\", null, getClass().getClassLoader());\nClass<?> myClass = classLoader.loadClass(\"MyClass\");\n" }, { "answer_id": 31624177, "author": "venergiac", "author_id": 1645339, "author_profile": "https://Stackoverflow.com/users/1645339", "pm_score": 2, "selected": false, "text": "Thread.currentThread().setContextClassLoader(classLoader);\n" }, { "answer_id": 46457506, "author": "fgb", "author_id": 298029, "author_profile": "https://Stackoverflow.com/users/298029", "pm_score": 4, "selected": false, "text": "URLClassLoader" }, { "answer_id": 50521611, "author": "Aleksey", "author_id": 1433446, "author_profile": "https://Stackoverflow.com/users/1433446", "pm_score": 2, "selected": false, "text": " File libDir = new File(\"path/to/jar\");\n\n ProxyCallerInterface caller = ObjectBuilder.builder()\n .setClassName(\"net.proxy.lib.test.LibClass\")\n .setArtifact(DirArtifact.builder()\n .withClazz(ObjectBuilderTest.class)\n .withVersionInfo(newVersionInfo(libDir))\n .build())\n .build();\n String version = caller.call(\"getLibVersion\").asString();\n" }, { "answer_id": 52616924, "author": "czdepski", "author_id": 10448469, "author_profile": "https://Stackoverflow.com/users/10448469", "pm_score": 2, "selected": false, "text": "File file = ...\nURL url = file.toURI().toURL();\nURLClassLoader sysLoader = new URLClassLoader(new URL[0]);\n\nMethod sysMethod = URLClassLoader.class.getDeclaredMethod(\"addURL\", new Class[]{URL.class});\nsysMethod.setAccessible(true);\nsysMethod.invoke(sysLoader, new Object[]{url});\n" }, { "answer_id": 52741647, "author": "czdepski", "author_id": 10448469, "author_profile": "https://Stackoverflow.com/users/10448469", "pm_score": 3, "selected": false, "text": "package agent;\n\nimport java.io.IOException;\nimport java.lang.instrument.Instrumentation;\nimport java.util.jar.JarFile;\n\npublic class Agent {\n public static Instrumentation instrumentation;\n\n public static void premain(String args, Instrumentation instrumentation) {\n Agent.instrumentation = instrumentation;\n }\n\n public static void agentmain(String args, Instrumentation instrumentation) {\n Agent.instrumentation = instrumentation;\n }\n\n public static void appendJarFile(JarFile file) throws IOException {\n if (instrumentation != null) {\n instrumentation.appendToSystemClassLoaderSearch(file);\n }\n }\n}\n" }, { "answer_id": 52911129, "author": "steve212", "author_id": 10534683, "author_profile": "https://Stackoverflow.com/users/10534683", "pm_score": 2, "selected": false, "text": "import jhplot.Web;\nWeb.load(\"http://central.maven.org/maven2/it/unimi/dsi/fastutil/8.2.2/fastutil-8.2.2.jar\"); // now you can start using this library\n" }, { "answer_id": 53111471, "author": "Anton Tananaev", "author_id": 2548565, "author_profile": "https://Stackoverflow.com/users/2548565", "pm_score": 4, "selected": false, "text": "ClassLoader classLoader = ClassLoader.getSystemClassLoader();\ntry {\n Method method = classLoader.getClass().getDeclaredMethod(\"addURL\", URL.class);\n method.setAccessible(true);\n method.invoke(classLoader, new File(jarPath).toURI().toURL());\n} catch (NoSuchMethodException e) {\n Method method = classLoader.getClass()\n .getDeclaredMethod(\"appendToClassPathForInstrumentation\", String.class);\n method.setAccessible(true);\n method.invoke(classLoader, jarPath);\n}\n" }, { "answer_id": 59743937, "author": "Mordechai", "author_id": 1751640, "author_profile": "https://Stackoverflow.com/users/1751640", "pm_score": 6, "selected": false, "text": "java -Djava.system.class.loader=com.example.MyCustomClassLoader\n" }, { "answer_id": 60281394, "author": "Bằng Rikimaru", "author_id": 2028440, "author_profile": "https://Stackoverflow.com/users/2028440", "pm_score": 1, "selected": false, "text": "public static synchronized void loadLibrary(java.io.File jar) {\n try { \n java.net.URL url = jar.toURI().toURL();\n java.lang.reflect.Method method = java.net.URLClassLoader.class.getDeclaredMethod(\"addURL\", new Class[]{java.net.URL.class});\n method.setAccessible(true); /*promote the method to public access*/\n method.invoke(Thread.currentThread().getContextClassLoader(), new Object[]{url});\n } catch (Exception ex) {\n throw new RuntimeException(\"Cannot load library from jar file '\" + jar.getAbsolutePath() + \"'. Reason: \" + ex.getMessage());\n }\n}\n" }, { "answer_id": 60662896, "author": "ZGorlock", "author_id": 7427882, "author_profile": "https://Stackoverflow.com/users/7427882", "pm_score": 2, "selected": false, "text": "File object = new File(pack.getObjectFile()).getAbsoluteFile();\nObject packObject;\ntry {\n URLClassLoader classloader;\n\n List<URL> classpath = new ArrayList<>();\n classpath.add(new File(pack.getObjectRootPath()).toURI().toURL());\n for (File jar : FileUtils.listFiles(new File(pack.getLibPath()), new String[] {\"jar\"}, true)) {\n classpath.add(jar.toURI().toURL());\n }\n classloader = new URLClassLoader(classpath.toArray(new URL[] {}));\n\n Class<?> clazz = classloader.loadClass(object.getName());\n packObject = clazz.getDeclaredConstructor().newInstance();\n\n} catch (Exception e) {\n e.printStackTrace();\n throw e;\n}\nreturn packObject;\n" }, { "answer_id": 63094644, "author": "Sergio Santiago", "author_id": 1563297, "author_profile": "https://Stackoverflow.com/users/1563297", "pm_score": 3, "selected": false, "text": "public interface Greeting extends ExtensionPoint {\n\n String getGreeting();\n\n}\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2443/" ]
60,768
<p>I am trying to dynamicaly compile code using CodeDom. I can load other assemblies, but I cannot load System.Data.Linq.dll. I get an error:</p> <p>Metadata file 'System.Data.Linq.dll' could not be found</p> <p>My code looks like:</p> <pre><code>CompilerParameters compilerParams = new CompilerParameters(); compilerParams.CompilerOptions = "/target:library /optimize"; compilerParams.GenerateExecutable = false; compilerParams.GenerateInMemory = true; compilerParams.IncludeDebugInformation = false; compilerParams.ReferencedAssemblies.Add("mscorlib.dll"); compilerParams.ReferencedAssemblies.Add("System.dll"); compilerParams.ReferencedAssemblies.Add("System.Data.Linq.dll"); </code></pre> <p>Any ideas? </p>
[ { "answer_id": 60781, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 3, "selected": true, "text": "compilerParams.ReferencedAssemblies.Add(typeof(DataContext).Assembly.Location);\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5189/" ]
60,779
<p>Trying to do this sort of thing...</p> <pre><code>WHERE username LIKE '%$str%' </code></pre> <p>...but using bound parameters to prepared statements in PDO. e.g.:</p> <pre><code>$query = $db-&gt;prepare("select * from comments where comment like :search"); $query-&gt;bindParam(':search', $str); $query-&gt;execute(); </code></pre> <p>I've tried numerous permutations of single quotes and % signs and it's just getting cross with me.</p> <p>I seem to remember wrestling with this at some point before but I can't find any references. Does anyone know how (if?) you can do this nicely in PDO with named parameters?</p>
[ { "answer_id": 60782, "author": "Polsonby", "author_id": 137, "author_profile": "https://Stackoverflow.com/users/137", "pm_score": 5, "selected": true, "text": "$str = \"%$str%\";\n$query = $db->prepare(\"select * from comments where comment like :search\");\n$query->bindParam(':search', $str);\n$query->execute();\n" }, { "answer_id": 15377644, "author": "Dominic P", "author_id": 931860, "author_profile": "https://Stackoverflow.com/users/931860", "pm_score": 2, "selected": false, "text": "$query = $db->prepare(\"select * FROM table WHERE field LIKE CONCAT('%',:search,'%')\");\n$query->bindParam(':search', $str);\n$query->execute();\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/137/" ]
60,785
<p>How can I show a grey transparent overlay in C#?<br> It should overlay other process which are not owned by the application doing the overlay.</p>
[ { "answer_id": 60782, "author": "Polsonby", "author_id": 137, "author_profile": "https://Stackoverflow.com/users/137", "pm_score": 5, "selected": true, "text": "$str = \"%$str%\";\n$query = $db->prepare(\"select * from comments where comment like :search\");\n$query->bindParam(':search', $str);\n$query->execute();\n" }, { "answer_id": 15377644, "author": "Dominic P", "author_id": 931860, "author_profile": "https://Stackoverflow.com/users/931860", "pm_score": 2, "selected": false, "text": "$query = $db->prepare(\"select * FROM table WHERE field LIKE CONCAT('%',:search,'%')\");\n$query->bindParam(':search', $str);\n$query->execute();\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44972/" ]
60,802
<p>I'm having trouble ordering by more than one field in my Linq to NHibernate query. Does anyone either know what might be wrong or if there is a work around?</p> <p>Code:</p> <pre><code>IQueryable&lt;AgendaItem&gt; items = _agendaRepository.GetAgendaItems(location) .Where(item =&gt; item.Minutes.Contains(query) || item.Description.Contains(query)); int total = items.Count(); var results = items .OrderBy(item =&gt; item.Agenda.Date) .ThenBy(item =&gt; item.OutcomeType) .ThenBy(item =&gt; item.OutcomeNumber) .Skip((page - 1)*pageSize) .Take(pageSize) .ToArray(); return new SearchResult(query, total, results); </code></pre> <p>I've tried replacing ThenBy with multiple OrderBy calls. Same result. The method works great if I comment out the two ThenBy calls.</p> <p>Error I'm receiving:</p> <pre> [SqlException (0x80131904): Invalid column name '__hibernate_sort_expr_0____hibernate_sort_expr_1__'. Invalid column name '__hibernate_sort_expr_0____hibernate_sort_expr_1__'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1948826 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392 [ADOException: could not execute query [ SELECT this_.Id as Id5_2_, this_.AgendaId as AgendaId5_2_, this_.Description as Descript3_5_2_, this_.OutcomeType as OutcomeT4_5_2_, this_.OutcomeNumber as OutcomeN5_5_2_, this_.Minutes as Minutes5_2_, agenda1_.Id as Id2_0_, agenda1_.LocationId as LocationId2_0_, agenda1_.Date as Date2_0_, location2_.Id as Id7_1_, location2_.Name as Name7_1_ FROM AgendaItem this_ left outer join Agenda agenda1_ on this_.AgendaId=agenda1_.Id left outer join Location location2_ on agenda1_.LocationId=location2_.Id WHERE location2_.Id = ? and (this_.Minutes like ? or this_.Description like ?) ORDER BY agenda1_.Date asc, this_.OutcomeType asc, this_.OutcomeNumber asc ] Positional parameters: #0>1 #0>%Core% #0>%Core% [SQL: SELECT this_.Id as Id5_2_, this_.AgendaId as AgendaId5_2_, this_.Description as Descript3_5_2_, this_.OutcomeType as OutcomeT4_5_2_, this_.OutcomeNumber as OutcomeN5_5_2_, this_.Minutes as Minutes5_2_, agenda1_.Id as Id2_0_, agenda1_.LocationId as LocationId2_0_, agenda1_.Date as Date2_0_, location2_.Id as Id7_1_, location2_.Name as Name7_1_ FROM AgendaItem this_ left outer join Agenda agenda1_ on this_.AgendaId=agenda1_.Id left outer join Location location2_ on agenda1_.LocationId=location2_.Id WHERE location2_.Id = ? and (this_.Minutes like ? or this_.Description like ?) ORDER BY agenda1_.Date asc, this_.OutcomeType asc, this_.OutcomeNumber asc]] NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +258 NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +18 NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) +87 NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) +342 NHibernate.Impl.CriteriaImpl.List(IList results) +41 NHibernate.Impl.CriteriaImpl.List() +35 NHibernate.Linq.CriteriaResultReader`1.List() in C:\home\dev\tools\NHibernate\NHibernateContribSrc\src\NHibernate.Linq\src\NHibernate.Linq\CriteriaResultReader.cs:22 NHibernate.Linq.d__0.MoveNext() in C:\home\dev\tools\NHibernate\NHibernateContribSrc\src\NHibernate.Linq\src\NHibernate.Linq\CriteriaResultReader.cs:27 </pre>
[ { "answer_id": 86686, "author": "dcstraw", "author_id": 10391, "author_profile": "https://Stackoverflow.com/users/10391", "pm_score": 4, "selected": true, "text": "var results = items\n .ToArray()\n .OrderBy(item => item.Agenda.Date)\n .ThenBy(item => item.OutcomeType)\n .ThenBy(item => item.OutcomeNumber)\n .Skip((page - 1)*pageSize)\n .Take(pageSize)\n" }, { "answer_id": 51985649, "author": "Alexander Levinson", "author_id": 4715783, "author_profile": "https://Stackoverflow.com/users/4715783", "pm_score": 0, "selected": false, "text": "var results = items\n .OrderBy(item => item.Agenda.Date).Asc\n .ThenBy(item => item.OutcomeType).Asc\n .ThenBy(item => item.OutcomeNumber).Asc\n .Skip((page - 1)*pageSize)\n .Take(pageSize)\n .ToArray();\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2595/" ]
60,805
<p>How do I select one or more random rows from a table using SQLAlchemy? </p>
[ { "answer_id": 60811, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": -1, "selected": false, "text": "SELECT colum FROM table\nORDER BY RAND()\nLIMIT 1\n" }, { "answer_id": 60815, "author": "Łukasz", "author_id": 4999, "author_profile": "https://Stackoverflow.com/users/4999", "pm_score": 8, "selected": true, "text": "from sqlalchemy.sql.expression import func, select\n\nselect.order_by(func.random()) # for PostgreSQL, SQLite\n\nselect.order_by(func.rand()) # for MySQL\n\nselect.order_by('dbms_random.value') # For Oracle\n" }, { "answer_id": 390676, "author": "David Raznick", "author_id": 20842, "author_profile": "https://Stackoverflow.com/users/20842", "pm_score": 5, "selected": false, "text": "import random\nrand = random.randrange(0, session.query(Table).count()) \nrow = session.query(Table)[rand]\n" }, { "answer_id": 14906244, "author": "GuySoft", "author_id": 311268, "author_profile": "https://Stackoverflow.com/users/311268", "pm_score": 5, "selected": false, "text": "import random\nquery = DBSession.query(Table)\nrowCount = int(query.count())\nrandomRow = query.offset(int(rowCount*random.random())).first()\n" }, { "answer_id": 21242325, "author": "med116", "author_id": 1784279, "author_profile": "https://Stackoverflow.com/users/1784279", "pm_score": -1, "selected": false, "text": "import random\nmax_model_id = YourModel.query.order_by(YourModel.id.desc())[0].id\nrandom_id = random.randrange(0,max_model_id)\nrandom_row = YourModel.query.get(random_id)\nprint random_row\n" }, { "answer_id": 33583008, "author": "Jeff Widman", "author_id": 770425, "author_profile": "https://Stackoverflow.com/users/770425", "pm_score": 5, "selected": false, "text": "timeit" }, { "answer_id": 42780139, "author": "ChickenFeet", "author_id": 5387193, "author_profile": "https://Stackoverflow.com/users/5387193", "pm_score": 0, "selected": false, "text": "from random import randint\n\nrows_query = session.query(Table) # get all rows\nif rows_query.count() > 0: # make sure there's at least 1 row\n rand_index = randint(0,rows_query.count()-1) # get random index to rows \n rand_row = rows_query.all()[rand_index] # use random index to get random row\n" }, { "answer_id": 50345203, "author": "Charles Wang", "author_id": 3155630, "author_profile": "https://Stackoverflow.com/users/3155630", "pm_score": 2, "selected": false, "text": "from sqlalchemy.sql.expression import func\n\ndef random_find_rows(sample_num):\n if not sample_num:\n return []\n\n session = DBSession()\n return session.query(Table).order_by(func.random()).limit(sample_num).all()\n" }, { "answer_id": 52692368, "author": "Ilja Everilä", "author_id": 2681632, "author_profile": "https://Stackoverflow.com/users/2681632", "pm_score": 3, "selected": false, "text": "TABLESAMPLE" }, { "answer_id": 62321734, "author": "Anas", "author_id": 12861001, "author_profile": "https://Stackoverflow.com/users/12861001", "pm_score": -1, "selected": false, "text": "#first import the random module\nimport random\n\n#then choose what ever Model you want inside random.choise() method\nget_questions = random.choice(Question.query.all())\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1448/" ]
60,825
<p>I am working on a web application, where I transfer data from the server to the browser in XML.</p> <p>Since I'm danish, I quickly run into problems with the characters <code>æøå</code>.</p> <p>I know that in html, I use the <code>"&amp;amp;aelig;&amp;amp;oslash;&amp;amp;aring;"</code> for <code>æøå</code>.</p> <p>however, as soon as the chars pass through JavaScript, I get black boxes with <code>"?"</code> in them when using <code>æøå</code>, and <code>"&amp;aelig;&amp;oslash;&amp;aring;"</code> is printed as is.</p> <p>I've made sure to set it to utf-8, but that isn't helping much.</p> <p>Ideally, I want it to work with any special characters (naturally).</p> <p>The example that isn't working is included below:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;script type="text/javascript" charset="utf-8"&gt; alert("&amp;aelig;&amp;oslash;&amp;aring;"); alert("æøå"); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>What am I doing wrong?</p> <hr> <p>Ok, thanks to Grapefrukts answer, I got it working.</p> <p>I actually needed it for data coming from an MySQL server. Since the saving of the files in UTF-8 encoding only solves the problem for static content, I figure I'd include the solution for strings from a MySQL server, pulled out using PHP:</p> <p><code>utf8_encode($MyStringHere)</code></p>
[ { "answer_id": 60832, "author": "chryss", "author_id": 5169, "author_profile": "https://Stackoverflow.com/users/5169", "pm_score": 0, "selected": false, "text": "alert(\"&aelig;&oslash;&aring;\");\n" }, { "answer_id": 67289, "author": "enricopulatzo", "author_id": 9883, "author_profile": "https://Stackoverflow.com/users/9883", "pm_score": 3, "selected": false, "text": "String.fromCharCode()" }, { "answer_id": 144878, "author": "Kevin Hakanson", "author_id": 22514, "author_profile": "https://Stackoverflow.com/users/22514", "pm_score": 5, "selected": false, "text": "\\u" }, { "answer_id": 17870496, "author": "Kayun Chantarasathaporn", "author_id": 2620771, "author_profile": "https://Stackoverflow.com/users/2620771", "pm_score": 1, "selected": false, "text": "$message" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1090/" ]
60,830
<p>While it would be very convenient to use inline functions at some situations,</p> <p>Are there any drawbacks with inline functions?</p> <p><strong>Conclusion</strong>:</p> <p>Apparently, There is nothing wrong with using inline functions.</p> <p>But it is worth noting the following points!</p> <ul> <li><p>Overuse of inlining can actually make programs slower. Depending on a function's size, inlining it can cause the code size to increase or decrease. Inlining a very small accessor function will usually decrease code size while inlining a very large function can dramatically increase code size. On modern processors smaller code usually runs faster due to better use of the instruction cache. <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Inline_Functions" rel="noreferrer">- Google Guidelines</a></p></li> <li><p>The speed benefits of inline functions tend to diminish as the function grows in size. At some point the overhead of the function call becomes small compared to the execution of the function body, and the benefit is lost <a href="http://www-rocq.inria.fr/who/Marc.Thiriet/Langages/tic0324.html" rel="noreferrer">- Source</a></p></li> <li><p>There are few situations where an inline function may not work:</p> <ul> <li>For a function returning values; if a return statement exists.</li> <li>For a function not returning any values; if a loop, switch or goto statement exists. </li> <li>If a function is recursive. <a href="http://www-rocq.inria.fr/who/Marc.Thiriet/Langages/tic0324.html" rel="noreferrer">-Source</a></li> </ul></li> <li><p>The <code>__inline</code> keyword causes a function to be inlined only if you specify the optimize option. If optimize is specified, whether or not <code>__inline</code> is honored depends on the setting of the inline optimizer option. By default, the inline option is in effect whenever the optimizer is run. If you specify optimize , you must also specify the noinline option if you want the <code>__inline</code> keyword to be ignored. <a href="http://support.sas.com/documentation/onlinedoc/sasc/doc750/html/clug/zcoptinl.htm" rel="noreferrer">-Source</a></p></li> </ul>
[ { "answer_id": 60854, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 1, "selected": false, "text": "__forceinline" }, { "answer_id": 60941, "author": "maccullt", "author_id": 4945, "author_profile": "https://Stackoverflow.com/users/4945", "pm_score": 2, "selected": false, "text": "class OtherObject;\n\nclass Object {\npublic:\n void someFunc(OtherObject& otherObj) {\n otherObj.doIt(); // Yikes requires OtherObj declaration!\n }\n};\n" }, { "answer_id": 38563033, "author": "Tom Tanner", "author_id": 1182921, "author_profile": "https://Stackoverflow.com/users/1182921", "pm_score": 0, "selected": false, "text": "#include" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123/" ]
60,848
<p>Is it possible to retrieve items from a Python dictionary in the order that they were inserted?</p>
[ { "answer_id": 60862, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 7, "selected": true, "text": "dict" }, { "answer_id": 61031, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 4, "selected": false, "text": "class ordered_dict(dict):\n def __init__(self, *args, **kwargs):\n dict.__init__(self, *args, **kwargs)\n self._order = self.keys()\n\n def __setitem__(self, key, value):\n dict.__setitem__(self, key, value)\n if key in self._order:\n self._order.remove(key)\n self._order.append(key)\n\n def __delitem__(self, key):\n dict.__delitem__(self, key)\n self._order.remove(key)\n\n def order(self):\n return self._order[:]\n\n def ordered_items(self):\n return [(key,self[key]) for key in self._order]\n\n\nod = ordered_dict()\nod[\"hello\"] = \"world\"\nod[\"goodbye\"] = \"cruel world\"\nprint od.order() # prints ['hello', 'goodbye']\n\ndel od[\"hello\"]\nod[\"monty\"] = \"python\"\nprint od.order() # prints ['goodbye', 'monty']\n\nod[\"hello\"] = \"kitty\"\nprint od.order() # prints ['goodbye', 'monty', 'hello']\n\nprint od.ordered_items()\n# prints [('goodbye','cruel world'), ('monty','python'), ('hello','kitty')]\n" }, { "answer_id": 659817, "author": "Davide", "author_id": 25891, "author_profile": "https://Stackoverflow.com/users/25891", "pm_score": 1, "selected": false, "text": "my_dict={}\nmy_dict[\"foo\"]=\"bar\"\n" }, { "answer_id": 24028185, "author": "A.J. Uppal", "author_id": 3113477, "author_profile": "https://Stackoverflow.com/users/3113477", "pm_score": -1, "selected": false, "text": "sorted()" }, { "answer_id": 26637218, "author": "rewgoes", "author_id": 2848021, "author_profile": "https://Stackoverflow.com/users/2848021", "pm_score": 4, "selected": false, "text": "from collections import OrderedDict\na = {}\nb = OrderedDict()\nc = OrderedDict()\n\na['key1'] = 'value1'\na['key2'] = 'value2'\n\nb['key1'] = 'value1'\nb['key2'] = 'value2'\n\nc['key2'] = 'value2'\nc['key1'] = 'value1'\n\nprint a == b # True\nprint a == c # True\nprint b == c # False\n" }, { "answer_id": 51777540, "author": "Brian McCutchon", "author_id": 2093695, "author_profile": "https://Stackoverflow.com/users/2093695", "pm_score": 4, "selected": false, "text": "popitem()" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
60,874
<p>I know a few advanced ways, to change directories. <code>pushd</code> and <code>popd</code> (directory stack) or <code>cd -</code> (change to last directory).</p> <p>But I am looking for quick way to achieve the following:</p> <p>Say, I am in a rather deep dir:</p> <pre><code>/this/is/a/very/deep/directory/structure/with\ lot\ of\ nasty/names </code></pre> <p>and I want to switch to </p> <pre><code>/this/is/another/very/deep/directory/structure/with\ lot\ of\ nasty/names </code></pre> <p>Is there a cool/quick/geeky way to do it (without the mouse)?</p>
[ { "answer_id": 60887, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 4, "selected": true, "text": "cd ${PWD/a/another}\n" }, { "answer_id": 60936, "author": "Rob Wells", "author_id": 2974, "author_profile": "https://Stackoverflow.com/users/2974", "pm_score": 2, "selected": false, "text": "CDPATH" }, { "answer_id": 66331, "author": "slipset", "author_id": 9422, "author_profile": "https://Stackoverflow.com/users/9422", "pm_score": 1, "selected": false, "text": "cd ^/a/^/another/\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1870/" ]
60,877
<p>I have a query where I wish to retrieve the oldest X records. At present my query is something like the following:</p> <pre><code>SELECT Id, Title, Comments, CreatedDate FROM MyTable WHERE CreatedDate &gt; @OlderThanDate ORDER BY CreatedDate DESC </code></pre> <p>I know that normally I would remove the 'DESC' keyword to switch the order of the records, however in this instance I still want to get records ordered with the newest item first.</p> <p>So I want to know if there is any means of performing this query such that I get the oldest X items sorted such that the newest item is first. I should also add that my database exists on SQL Server 2005.</p>
[ { "answer_id": 60882, "author": "Jason Punyon", "author_id": 6212, "author_profile": "https://Stackoverflow.com/users/6212", "pm_score": 6, "selected": true, "text": "SELECT T1.* \nFROM\n(SELECT TOP X Id, Title, Comments, CreatedDate\nFROM MyTable\nWHERE CreatedDate > @OlderThanDate\nORDER BY CreatedDate) T1\nORDER BY CreatedDate DESC\n" }, { "answer_id": 60883, "author": "Unsliced", "author_id": 2902, "author_profile": "https://Stackoverflow.com/users/2902", "pm_score": 1, "selected": false, "text": "select * \nfrom \n(\n SELECT top X Id, Title, Comments, CreatedDate\n FROM MyTable\n WHERE CreatedDate > @OlderThanDate\n ORDER BY CreatedDate \n) a\norder by createddate desc \n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5086/" ]
60,904
<p>How can I open a cmd window in a specific location without having to navigate all the way to the directory I want?</p>
[ { "answer_id": 60907, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 9, "selected": false, "text": "cmd /K \"cd C:\\Windows\\\"\n" }, { "answer_id": 215534, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "system32" }, { "answer_id": 215558, "author": "raven", "author_id": 4228, "author_profile": "https://Stackoverflow.com/users/4228", "pm_score": 3, "selected": false, "text": "Windows Registry Editor Version 5.00\n\n[HKEY_CLASSES_ROOT\\Folder\\shell\\Command_Prompt_Here...]\n@=\"Command Prompt Here...\"\n\n[HKEY_CLASSES_ROOT\\Folder\\shell\\Command_Prompt_Here...\\command]\n@=\"cmd.exe \\\"%1\\\"\"\n" }, { "answer_id": 1220972, "author": "crowdy", "author_id": 123706, "author_profile": "https://Stackoverflow.com/users/123706", "pm_score": 2, "selected": false, "text": "[HKEY_CLASSES_ROOT\\Directory\\shell\\cmd]\n@=\"command prompt here\"\n[HKEY_CLASSES_ROOT\\Directory\\shell\\cmd\\command]\n@=\"cmd.exe /c start \\\"%1\\\" cmd.exe /k cd /d %1\"\n[HKEY_CLASSES_ROOT\\Drive\\shell\\cmd]\n@=\"command prompt here\"\n[HKEY_CLASSES_ROOT\\Drive\\shell\\cmd\\command]\n@=\"cmd.exe /c start \\\"%1\\\" cmd.exe /k cd /d %1\"\n" }, { "answer_id": 5342262, "author": "Codism", "author_id": 155253, "author_profile": "https://Stackoverflow.com/users/155253", "pm_score": 4, "selected": false, "text": "; Get working folder\nGetWorkingFolder() {\n if WinActive(\"ahk_class ExploreWClass\") or WinActive(\"ahk_class CabinetWClass\") {\n ControlGetText, path, Edit1\n return %path%\n } else if WinActive(\"FreeCommander\") {\n Send, {CTRLDOWN}{ALTDOWN}{INS}{ALTUP}{CTRLUP}\n Sleep, 100\n return clipboard\n } else {\n return \"C:\\\"\n }\n}\n\n#IfWinActive,\n\n#c::\n path := GetWorkingFolder()\n Run, %ComSpec%, %path%\n return\n\n; PowerShell\n#+C::\n path := GetWorkingFolder()\n Run, %SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe, %path%\n return\n\n#^c::\n Run, %ComSpec%, %temp%\n return\n\n#!c::\n path := GetWorkingFolder()\n Run, %comspec% /k \"%VS90COMNTOOLS%vsvars32.bat\", %path%\n return\n\n; irb\n#!b::\n path := GetWorkingFolder()\n Run, c:\\cygwin\\bin\\ruby /usr/bin/irb, %path%\n return\n\n; Bash\n#b::\n path := GetWorkingFolder()\n Run, bash --login, %path%\n return\n\n; Paste in console\n+INS::\n if WinActive(\"ahk_class ConsoleWindowClass\") {\n WinGetPos, x, y, w, h, A\n MouseGetPos, mx, my\n ;MsgBox x=%x% y=%y% w=%w% h=%h% mx=%mx% my=%my%\n if (mx < 10)\n mx = 10\n else if (mx > w - 30)\n mx := w - 30\n\n if (my < 40)\n my = 40\n else if (my > h)\n my := h - 10\n\n MouseClick, right, mx, my\n }\n return\n" }, { "answer_id": 28795485, "author": "TiagoLr", "author_id": 4052701, "author_profile": "https://Stackoverflow.com/users/4052701", "pm_score": 4, "selected": false, "text": "Alt + D" }, { "answer_id": 33021825, "author": "Edward Gavilán", "author_id": 5420048, "author_profile": "https://Stackoverflow.com/users/5420048", "pm_score": 2, "selected": false, "text": "START cd C:\\Users\n" }, { "answer_id": 34534874, "author": "Forest Jackdaw", "author_id": 5731710, "author_profile": "https://Stackoverflow.com/users/5731710", "pm_score": 2, "selected": false, "text": "cmd.exe" }, { "answer_id": 35293994, "author": "ofir_aghai", "author_id": 2591785, "author_profile": "https://Stackoverflow.com/users/2591785", "pm_score": 3, "selected": false, "text": "Shift" }, { "answer_id": 37605054, "author": "Syed. A", "author_id": 1913743, "author_profile": "https://Stackoverflow.com/users/1913743", "pm_score": 4, "selected": false, "text": "cmd" }, { "answer_id": 41578578, "author": "Guillermo", "author_id": 686777, "author_profile": "https://Stackoverflow.com/users/686777", "pm_score": 5, "selected": false, "text": "cmd" }, { "answer_id": 43426901, "author": "cagcak", "author_id": 2153187, "author_profile": "https://Stackoverflow.com/users/2153187", "pm_score": 0, "selected": false, "text": "path_of_the_cmder" }, { "answer_id": 44212019, "author": "Niraj Shakya", "author_id": 5383415, "author_profile": "https://Stackoverflow.com/users/5383415", "pm_score": 1, "selected": false, "text": "\"shift + mouse right click \"" }, { "answer_id": 45469822, "author": "FocusedWolf", "author_id": 490748, "author_profile": "https://Stackoverflow.com/users/490748", "pm_score": 3, "selected": false, "text": "Right-click a folder icon (or the empty background area inside an already open folder)\nand click either \"Open in Terminal\" or \"Open in Terminal (Admin)\".\n\nYou can also right click files to execute them with a command window.\nWhen the file is done running you are left with a command window that is navigated to the files directory.\n" }, { "answer_id": 45563746, "author": "Mendi Barel", "author_id": 2840531, "author_profile": "https://Stackoverflow.com/users/2840531", "pm_score": 3, "selected": false, "text": "cmd /k \"pushd D:\\Music\"\n" }, { "answer_id": 50422879, "author": "curiousBoy", "author_id": 2166856, "author_profile": "https://Stackoverflow.com/users/2166856", "pm_score": 2, "selected": false, "text": "@ECHO OFF \ncd C:\\YourProjectPath\\FolderPath\\" }, { "answer_id": 52266173, "author": "Alex T", "author_id": 2658643, "author_profile": "https://Stackoverflow.com/users/2658643", "pm_score": 2, "selected": false, "text": " start cd c:\\MyTargetFolder\n" }, { "answer_id": 56254760, "author": "Gerold Broser", "author_id": 1744774, "author_profile": "https://Stackoverflow.com/users/1744774", "pm_score": 2, "selected": false, "text": "HKCR\\Directory\\shell" }, { "answer_id": 56489448, "author": "U.A", "author_id": 11000016, "author_profile": "https://Stackoverflow.com/users/11000016", "pm_score": 1, "selected": false, "text": "start .\n" }, { "answer_id": 68227863, "author": "Julien Jm", "author_id": 12814623, "author_profile": "https://Stackoverflow.com/users/12814623", "pm_score": 3, "selected": false, "text": "Alt" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44972/" ]
60,910
<p>I've recently had a need to do a bit of lisp editing and I found the nifty Ready Lisp package for OS X, which is great, except Aquamacs automatically uses a proportional font (which is idiotic, IMHO) and I want to change it to a monospace font. However, I'm not really much of an EMACS user, and the preferences menu in Aquamacs is less than clear on where and how one might make such a change. </p>
[ { "answer_id": 60948, "author": "Natalie Weizenbaum", "author_id": 2518, "author_profile": "https://Stackoverflow.com/users/2518", "pm_score": 4, "selected": true, "text": "(set-default-font \"-apple-bitstream vera sans mono-medium-r-normal--0-0-0-0-m-0-mac-roman\")\n" }, { "answer_id": 2424197, "author": "fikovnik", "author_id": 219584, "author_profile": "https://Stackoverflow.com/users/219584", "pm_score": 2, "selected": false, "text": " -apple-DejaVu_Sans_Mono-medium-normal-normal-*-12-*-*-*-m-0-iso10646-1\n" }, { "answer_id": 58135994, "author": "chrisinmtown", "author_id": 1630244, "author_profile": "https://Stackoverflow.com/users/1630244", "pm_score": 1, "selected": false, "text": "(when window-system\n (setq initial-frame-alist nil) ;; Undo Aquamacs forced defaults\n (setq default-frame-alist nil) ;; Undo Aquamacs forced defaults\n (aquamacs-autoface-mode -1) ;; Use one face (font) everywhere\n (set-frame-font \"Menlo-12\") ;; Set the default font to Menlo size 12\n ;;(set-default-font \"Menlo-12\") ;; This would do the same.\n)\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60910", "https://Stackoverflow.com", "https://Stackoverflow.com/users/85/" ]
60,918
<p>I'm trying to do 'Attach to Process' for debugging in Visual Studio 2008 and I can't figure out what process to attach to. Help.</p>
[ { "answer_id": 6362634, "author": "Robin Minto", "author_id": 1456, "author_profile": "https://Stackoverflow.com/users/1456", "pm_score": 4, "selected": false, "text": "cscript iisapp.vbs" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4541/" ]
60,919
<p>Can I use this approach efficiently?</p> <pre><code>using(SqlCommand cmd = new SqlCommand("GetSomething", new SqlConnection(Config.ConnectionString)) { cmd.Connection.Open(); // set up parameters and CommandType to StoredProcedure etc. etc. cmd.ExecuteNonQuery(); } </code></pre> <p>My concern is : Will the Dispose method of the SqlCommand (which is called when exiting the using block) close the underlying SqlConnection object or not?</p>
[ { "answer_id": 60934, "author": "Ryan Farley", "author_id": 1627, "author_profile": "https://Stackoverflow.com/users/1627", "pm_score": 8, "selected": true, "text": "SqlCommand" }, { "answer_id": 5654064, "author": "Chuck Bevitt", "author_id": 704658, "author_profile": "https://Stackoverflow.com/users/704658", "pm_score": -1, "selected": false, "text": "private void DisposeCommand(SqlCommand cmd)\n{\n try\n {\n if (cmd != null)\n {\n if (cmd.Connection != null)\n {\n cmd.Connection.Close();\n cmd.Connection.Dispose();\n }\n cmd.Dispose();\n }\n }\n catch { } //don't blow up\n}\n" }, { "answer_id": 59635946, "author": "Keith Patrick", "author_id": 12670837, "author_profile": "https://Stackoverflow.com/users/12670837", "pm_score": 1, "selected": false, "text": "var provider = DbProviderFactories.GetFactory(\"System.Data.SqlClient\");// Or MS.Data.SqlClient\nusing (var connection = provider.CreateConnection())\n{\n connection.ConnectionString = \"...\";\n using (var command = connection.CreateCommand())\n {\n command.CommandText = \"...\";\n connection.Open();\n\n using (var reader = command.ExecuteReader())\n {\n...\n }\n }\n}\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1796/" ]
60,942
<p>I'd like to redirect the stdout of process proc1 to two processes proc2 and proc3:</p> <pre><code> proc2 -&gt; stdout / proc1 \ proc3 -&gt; stdout </code></pre> <p>I tried</p> <pre><code> proc1 | (proc2 &amp; proc3) </code></pre> <p>but it doesn't seem to work, i.e.</p> <pre><code> echo 123 | (tr 1 a &amp; tr 1 b) </code></pre> <p>writes</p> <pre><code> b23 </code></pre> <p>to stdout instead of </p> <pre><code> a23 b23 </code></pre>
[ { "answer_id": 60955, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 8, "selected": true, "text": ">(…)" }, { "answer_id": 61716, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 3, "selected": false, "text": "PS > \"123\" | % { \n $_.Replace( \"1\", \"a\"), \n $_.Replace( \"2\", \"b\" ) \n}\n\na23\n1b3\n" }, { "answer_id": 190777, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 5, "selected": false, "text": "bash" }, { "answer_id": 16541914, "author": "munish", "author_id": 730858, "author_profile": "https://Stackoverflow.com/users/730858", "pm_score": -1, "selected": false, "text": " eval `echo '&& echo 123 |'{'tr 1 a','tr 1 b'} | sed -n 's/^&&//gp'`\n" }, { "answer_id": 43906764, "author": "mklement0", "author_id": 45375, "author_profile": "https://Stackoverflow.com/users/45375", "pm_score": 4, "selected": false, "text": "bash" }, { "answer_id": 62188317, "author": "exic", "author_id": 332451, "author_profile": "https://Stackoverflow.com/users/332451", "pm_score": 1, "selected": false, "text": "out=$(proc1); echo \"$out\" | proc2; echo \"$out\" | proc3\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60942", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4085/" ]
60,950
<p>I find working on the command line in Windows frustrating, primarily because the console window is wretched to use compared to terminal applications on linux and OS X such as "rxvt", "xterm", or "Terminal". Major complaints:</p> <ol> <li><p>No standard copy/paste. You have to turn on "mark" mode and it's only available from a multi-level popup triggered by the (small) left hand corner button. Then copy and paste need to be invoked from the same menu</p></li> <li><p>You can't arbitrarily resize the window by dragging, you need to set a preference (back to the multi-level popup) each time you want to resize a window</p></li> <li><p>You can only make the window so big before horizontal scroll bars enter the picture. Horizontal scroll bars suck.</p></li> <li><p>With the cmd.exe shell, you can't navigate to folders with \\netpath notation (UNC?), you need to map a network drive. This sucks when working on multiple machines that are going to have different drives mapped</p></li> </ol> <p>Are there any tricks or applications, (paid or otherwise), that address these issue?</p>
[ { "answer_id": 60956, "author": "Apocalisp", "author_id": 3434, "author_profile": "https://Stackoverflow.com/users/3434", "pm_score": 5, "selected": false, "text": "xterm" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4668/" ]
60,977
<p>Sometimes I have to work on code that moves the computer clock forward. In this case some .cpp or .h files get their latest modification date set to the future time.</p> <p>Later on, when my clock is fixed, and I compile my sources, system rebuilds most of the project because some of the latest modification dates are in the future. Each subsequent recompile has the same problem.</p> <p>Solution that I know are:</p> <p>a) Find the file that has the future time and re-save it. This method is not ideal because the project is very big and it takes time even for windows advanced search to find the files that are changed.</p> <p>b) Delete the whole project and re-check it out from svn.</p> <p>Does anyone know how I can get around this problem?</p> <p>Is there perhaps a setting in visual studio that will allow me to tell the compiler to use the archive bit instead of the last modification date to detect source file changes?</p> <p>Or perhaps there is a recursive modification date reset tool that can be used in this situation?</p>
[ { "answer_id": 61015, "author": "Nathan Jones", "author_id": 5848, "author_profile": "https://Stackoverflow.com/users/5848", "pm_score": 1, "selected": false, "text": "touch temp\nfind . -newer temp -exec touch {} ;\nrm temp\n" }, { "answer_id": 61105, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 2, "selected": true, "text": "Get-ChildItem -r . | \n ? { $_.LastWriteTime -gt ([DateTime]::Now) } | \n Set-ItemProperty -Name \"LastWriteTime\" -Value ([DateTime]::Now)\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
61,000
<p>I am wondering what directory structure are commonly used in development projects. I mean with the idea of facilitating builds, deploys release, and etc.</p> <p>I recently used a <a href="http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html" rel="nofollow noreferrer">Maven structure</a> for a java project, but I am not sure it's the best structure for a non-maven driven project.</p> <p>So, I have two questions: When you guys start new projects, what structure you use? And: What if you need to integrate two different languages, like for example java classes into a PHP application; PHP files are source files, web files, you you use a /src, /classes, webapps/php ? What are your choices in such scenarios. </p> <p>As a note: I am wondering also what are you choices for directories names. I like the 3-letters names (src, lib, bin, web, img, css, xml, cfg) but what are your opinions about descriptive names like libraris, sources or htdocs/public_html ?</p>
[ { "answer_id": 4540307, "author": "Fernando Barrocal", "author_id": 2274, "author_profile": "https://Stackoverflow.com/users/2274", "pm_score": 4, "selected": true, "text": "/project_name (everything goes here)\n /web (htdocs)\n /img\n /css\n /app (usually some framework or sensitive code)\n /lib (externa libs)\n /vendor_1\n /vendor_2\n /tmp\n /cache\n /sql (sql scripts usually with maybe diagrams)\n /scripts\n /doc (usually an empty directory)\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2274/" ]
61,002
<p>I'd like to script, preferably in rake, the following actions into a single command:</p> <ol> <li>Get the version of my local git repository.</li> <li>Git pull the latest code.</li> <li>Git diff from the version I extracted in step #1 to what is now in my local repository.</li> </ol> <p>In other words, I want to get the latest code form the central repository and immediately generate a diff of what's changed since the last time I pulled.</p>
[ { "answer_id": 61004, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "git fetch\ngit diff ...origin\n" }, { "answer_id": 61477, "author": "Greg", "author_id": 108, "author_profile": "https://Stackoverflow.com/users/108", "pm_score": 4, "selected": false, "text": "git config remote.origin.url <url>\n" }, { "answer_id": 62303, "author": "Lily Ballard", "author_id": 582, "author_profile": "https://Stackoverflow.com/users/582", "pm_score": 8, "selected": true, "text": "git pull origin\ngit diff @{1}..\n" }, { "answer_id": 2831146, "author": "Clintm", "author_id": 3384609, "author_profile": "https://Stackoverflow.com/users/3384609", "pm_score": 2, "selected": false, "text": "function parse_git_branch {\n git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/'\n}\nfunction gd2 { \n echo branch \\($1\\) has these commits and \\($2\\) does not \n git log $2..$1 --no-merges --format='%h | Author:%an | Date:%ad | %s' --date=local\n}\nfunction grin {\n git fetch origin master\n gd2 FETCH_HEAD $(parse_git_branch)\n}\nfunction grout {\n git fetch origin master\n gd2 $(parse_git_branch) FETCH_HEAD\n}\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4061/" ]
61,005
<p>What are the best file permission settings for PHP scripts? Any suggestions on ways to figure out the minimum required permissions?</p>
[ { "answer_id": 61004, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "git fetch\ngit diff ...origin\n" }, { "answer_id": 61477, "author": "Greg", "author_id": 108, "author_profile": "https://Stackoverflow.com/users/108", "pm_score": 4, "selected": false, "text": "git config remote.origin.url <url>\n" }, { "answer_id": 62303, "author": "Lily Ballard", "author_id": 582, "author_profile": "https://Stackoverflow.com/users/582", "pm_score": 8, "selected": true, "text": "git pull origin\ngit diff @{1}..\n" }, { "answer_id": 2831146, "author": "Clintm", "author_id": 3384609, "author_profile": "https://Stackoverflow.com/users/3384609", "pm_score": 2, "selected": false, "text": "function parse_git_branch {\n git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/'\n}\nfunction gd2 { \n echo branch \\($1\\) has these commits and \\($2\\) does not \n git log $2..$1 --no-merges --format='%h | Author:%an | Date:%ad | %s' --date=local\n}\nfunction grin {\n git fetch origin master\n gd2 FETCH_HEAD $(parse_git_branch)\n}\nfunction grout {\n git fetch origin master\n gd2 $(parse_git_branch) FETCH_HEAD\n}\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/814/" ]
61,033
<p>I've got a table of URLs and I don't want any duplicate URLs. How do I check to see if a given URL is already in the table using PHP/MySQL?</p>
[ { "answer_id": 61035, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": -1, "selected": false, "text": "SELECT url FROM urls WHERE url = 'http://asdf.com' LIMIT 1\n" }, { "answer_id": 61036, "author": "roman m", "author_id": 3661, "author_profile": "https://Stackoverflow.com/users/3661", "pm_score": 2, "selected": false, "text": "IF NOT EXISTS (SELECT 1 FROM YOURTABLE WHERE URL = 'URL')\nINSERT INTO YOURTABLE (...) VALUES (...)\n" }, { "answer_id": 61045, "author": "Joe Mahoney", "author_id": 575, "author_profile": "https://Stackoverflow.com/users/575", "pm_score": 4, "selected": false, "text": "alter table urls add constraint unique_url unique (url);\n" }, { "answer_id": 62307, "author": "Jean Paul Galea", "author_id": 6618, "author_profile": "https://Stackoverflow.com/users/6618", "pm_score": 1, "selected": false, "text": "urls" }, { "answer_id": 7085163, "author": "Pedro Lobito", "author_id": 797495, "author_profile": "https://Stackoverflow.com/users/797495", "pm_score": 0, "selected": false, "text": "$url = \"http://www.scroogle.com\";\n\n$query = \"SELECT `id` FROM `urls` WHERE `url` = '$url' \";\n$resultdb = mysql_query($query) or die(mysql_error()); \nlist($idtemp) = mysql_fetch_array($resultdb) ;\n\nif(empty($idtemp)) // if $idtemp is empty the url doesn't exist and we go ahead and insert it into the db.\n{ \n mysql_query(\"INSERT INTO urls (`url` ) VALUES('$url') \") or die (mysql_error());\n}else{\n //do something else if the url already exists in the DB\n}\n" }, { "answer_id": 7087626, "author": "Steve Buzonas", "author_id": 816584, "author_profile": "https://Stackoverflow.com/users/816584", "pm_score": 3, "selected": false, "text": "SELECT COUNT(*) AS UrlResults FROM websites WHERE url='http://www.domain.com'\n" }, { "answer_id": 7093198, "author": "Mike Sherrill 'Cat Recall'", "author_id": 562459, "author_profile": "https://Stackoverflow.com/users/562459", "pm_score": 4, "selected": false, "text": "UNIQUE (url, resource_locator)" }, { "answer_id": 7122583, "author": "Matt", "author_id": 61256, "author_profile": "https://Stackoverflow.com/users/61256", "pm_score": 0, "selected": false, "text": "primary key" }, { "answer_id": 7128282, "author": "Mez", "author_id": 20010, "author_profile": "https://Stackoverflow.com/users/20010", "pm_score": 5, "selected": false, "text": "http://www.example.com/" }, { "answer_id": 7128408, "author": "Matthew", "author_id": 369775, "author_profile": "https://Stackoverflow.com/users/369775", "pm_score": 0, "selected": false, "text": "SELECT\n *\nFROM\n yourTable a\nJOIN\n yourTable b -- Join the same table\n ON b.[URL] = a.[URL] -- where the URL's match\n AND b.[PK] <> b.[PK] -- but the PK's are different\n" }, { "answer_id": 7128781, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 1, "selected": false, "text": "CREATE TABLE MyURLTable(\nID INTEGER NOT NULL AUTO_INCREMENT\n,URL VARCHAR(512)\n,PRIMARY KEY(ID)\n,UNIQUE INDEX IDX_URL(URL)\n);\n" }, { "answer_id": 7138051, "author": "Daniel Trebbien", "author_id": 196844, "author_profile": "https://Stackoverflow.com/users/196844", "pm_score": 2, "selected": false, "text": "%C3%84" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6305/" ]
61,051
<p>You can use more than one css class in an HTML tag in current web browsers, e.g.:</p> <pre><code>&lt;div class="style1 style2 style3"&gt;foo bar&lt;/div&gt; </code></pre> <p>This hasn't always worked; with which versions did the major browsers begin correctly supporting this feature?</p>
[ { "answer_id": 61414, "author": "Bryan M.", "author_id": 4636, "author_profile": "https://Stackoverflow.com/users/4636", "pm_score": 4, "selected": true, "text": "<div class=\"bold italic\">content</div>\n\n.bold {\n font-weight: 800;\n}\n\n.italic {\n font-style: italic;\n{\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3283/" ]
61,052
<p>I need to know the application's ProductCode in the Installer.OnCommitted callback. There doesn't seem to be an obvious way of determining this.</p>
[ { "answer_id": 61298, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "string productCode = (string)Context.Parameters[\"productcode\"];\n" }, { "answer_id": 67385558, "author": "aolszowka", "author_id": 433069, "author_profile": "https://Stackoverflow.com/users/433069", "pm_score": 0, "selected": false, "text": " public static string GetProductCode(string fileName)\n {\n IntPtr hInstall = IntPtr.Zero;\n try\n {\n uint num = MsiOpenPackage(fileName, ref hInstall);\n if ((ulong)num != 0)\n {\n throw new Exception(\"Cannot open database: \" + num);\n }\n\n int pcchValueBuf = 255;\n StringBuilder szValueBuf = new StringBuilder(pcchValueBuf);\n num = MsiGetProperty(hInstall, \"ProductCode\", szValueBuf, ref pcchValueBuf);\n if ((ulong)num != 0)\n {\n throw new Exception(\"Failed to Get Property ProductCode: \" + num);\n }\n return szValueBuf.ToString();\n }\n finally\n {\n if (hInstall != IntPtr.Zero)\n {\n MsiCloseHandle(hInstall);\n }\n }\n }\n\n [DllImport(\"msi.dll\", CharSet = CharSet.Unicode, EntryPoint = \"MsiGetPropertyW\", ExactSpelling = true, SetLastError = true)]\n private static extern uint MsiGetProperty(IntPtr hInstall, string szName, [Out] StringBuilder szValueBuf, ref int pchValueBuf);\n [DllImport(\"msi.dll\", CharSet = CharSet.Unicode, EntryPoint = \"MsiOpenPackageW\", ExactSpelling = true, SetLastError = true)]\n private static extern uint MsiOpenPackage(string szDatabasePath, ref IntPtr hProduct);\n [DllImport(\"msi.dll\", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]\n private static extern int MsiCloseHandle(IntPtr hAny);\n\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
61,084
<p>I'm trying to create a sitemap using Linq to Xml, but am getting an empty namespace attribute, which I would like to get rid of. e.g.</p> <pre><code>XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "true"), new XElement(ns + "urlset", new XElement("url", new XElement("loc", "http://www.example.com/page"), new XElement("lastmod", "2008-09-14")))); </code></pre> <p>The result is ...</p> <pre><code>&lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt; &lt;url xmlns=""&gt; &lt;loc&gt;http://www.example.com/page&lt;/loc&gt; &lt;lastmod&gt;2008-09-14&lt;/lastmod&gt; &lt;/url&gt; &lt;/urlset&gt; </code></pre> <p>I would rather not have the xmlns="" on the url element. I can strip it out using Replace on the final xdoc.ToString(), but is there a more correct way?</p>
[ { "answer_id": 61141, "author": "Micah", "author_id": 6209, "author_profile": "https://Stackoverflow.com/users/6209", "pm_score": 6, "selected": true, "text": "XDocument xdoc = new XDocument(new XDeclaration(\"1.0\", \"utf-8\", \"true\"),\nnew XElement(ns + \"urlset\",\nnew XElement(ns + \"url\",\n new XElement(ns + \"loc\", \"http://www.example.com/page\"),\n new XElement(ns + \"lastmod\", \"2008-09-14\"))));\n" }, { "answer_id": 777327, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "Imports <xmlns:ns=\"x-schema:tsSchema.xml\">\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4449/" ]
61,085
<p>I've been trying to use SQLite with the PDO wrapper in PHP with mixed success. I can read from the database fine, but none of my updates are being committed to the database when I view the page in the browser. Curiously, running the script from my shell does update the database. I suspected file permissions as the culprit, but even with the database providing full access (chmod 777) the problem persists. Should I try changing the file owner? If so, what to?</p> <p>By the way, my machine is the standard Mac OS X Leopard install with PHP activated.</p> <p>@Tom Martin</p> <p>Thank you for your reply. I just ran your code and it looks like PHP runs as user _www. I then tried chowning the database to be owned by _www, but that didn't work either.</p> <p>I should also note that PDO's errorInfo function doesn't indicate an error took place. Could this be a setting with PDO somehow opening the database for read-only? I've heard that SQLite performs write locks on the entire file. Is it possible that the database is locked by something else preventing the write?</p> <p>I've decided to include the code in question. This is going to be more or less a port of <a href="https://stackoverflow.com/questions/6936/using-what-ive-learned-from-stackoverflow-html-scraper">Grant's script</a> to PHP. So far it's just the Questions section:</p> <pre><code>&lt;?php $db = new PDO('sqlite:test.db'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://stackoverflow.com/users/658/kyle"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIE, "shhsecret=1293706652"); $page = curl_exec($ch); preg_match('/summarycount"&gt;.*?([,\d]+)&lt;\/div&gt;.*?Reputation/s', $page, $rep); $rep = preg_replace("/,/", "", $rep[1]); preg_match('/iv class="summarycount".{10,60} (\d+)&lt;\/d.{10,140}Badges/s', $page, $badge); $badge = $badge[1]; $qreg = '/question-summary narrow.*?vote-count-post"&gt;&lt;strong.*?&gt;(-?\d*).*?\/questions\/(\d*).*?&gt;(.*?)&lt;\/a&gt;/s'; preg_match_all($qreg, $page, $questions, PREG_SET_ORDER); $areg = '/(answer-summary"&gt;&lt;a href="\/questions\/(\d*).*?votes.*?&gt;(-?\d+).*?href.*?&gt;(.*?)&lt;.a)/s'; preg_match_all($areg, $page, $answers, PREG_SET_ORDER); echo "&lt;h3&gt;Questions:&lt;/h3&gt;\n"; echo "&lt;table cellpadding=\"3\"&gt;\n"; foreach ($questions as $q) { $query = 'SELECT count(id), votes FROM Questions WHERE id = '.$q[2].' AND type=0;'; $dbitem = $db-&gt;query($query)-&gt;fetch(PDO::FETCH_ASSOC); if ($dbitem['count(id)'] &gt; 0) { $lastQ = $q[1] - $dbitem['votes']; if ($lastQ == 0) { $lastQ = ""; } $query = "UPDATE Questions SET votes = '$q[1]' WHERE id = '$q[2]'"; $db-&gt;exec($query); } else { $query = "INSERT INTO Questions VALUES('$q[3]', '$q[1]', 0, '$q[2]')"; echo "$query\n"; $db-&gt;exec($query); $lastQ = "(NEW)"; } echo "&lt;tr&gt;&lt;td&gt;$lastQ&lt;/td&gt;&lt;td align=\"right\"&gt;$q[1]&lt;/td&gt;&lt;td&gt;$q[3]&lt;/td&gt;&lt;/tr&gt;\n"; } echo "&lt;/table&gt;"; ?&gt; </code></pre>
[ { "answer_id": 61102, "author": "Tom Martin", "author_id": 5303, "author_profile": "https://Stackoverflow.com/users/5303", "pm_score": 1, "selected": false, "text": "echo exec('whoami');" }, { "answer_id": 3470364, "author": "paolo_O", "author_id": 418707, "author_profile": "https://Stackoverflow.com/users/418707", "pm_score": 0, "selected": false, "text": "try...catch" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61085", "https://Stackoverflow.com", "https://Stackoverflow.com/users/658/" ]
61,088
<p><strong>What "Hidden Features" of JavaScript do you think every programmer should know?</strong></p> <p>After having seen the excellent quality of the answers to the following questions I thought it was time to ask it for JavaScript.</p> <ul> <li><a href="https://stackoverflow.com/questions/954327/">Hidden Features of HTML</a></li> <li><a href="https://stackoverflow.com/questions/628407">Hidden Features of CSS</a></li> <li><a href="https://stackoverflow.com/questions/61401/">Hidden Features of PHP</a></li> <li><a href="https://stackoverflow.com/questions/54929/">Hidden Features of ASP.NET</a></li> <li><a href="https://stackoverflow.com/questions/9033/">Hidden Features of C#</a></li> <li><a href="https://stackoverflow.com/questions/15496/">Hidden Features of Java</a></li> <li><a href="https://stackoverflow.com/questions/101268/">Hidden Features of Python</a></li> </ul> <p>Even though JavaScript is arguably the most important Client Side language right now (just ask Google) it's surprising how little most web developers appreciate how powerful it really is.</p>
[ { "answer_id": 61094, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 8, "selected": false, "text": "var passFunAndApply = function (fn,x,y,z) { return fn(x,y,z); };\n\nvar sum = function(x,y,z) {\n return x+y+z;\n};\n\nalert( passFunAndApply(sum,3,4,5) ); // 12\n" }, { "answer_id": 61097, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 7, "selected": false, "text": "function Person(firstName, lastName) {\n this.firstName = firstName;\n this.lastName = lastName;\n\n // A private method only visible from within this constructor\n function calcFullName() {\n return firstName + \" \" + lastName; \n }\n\n // A public method available to everyone\n this.sayHello = function () {\n alert(calcFullName());\n }\n}\n\n//Usage:\nvar person1 = new Person(\"Bob\", \"Loblaw\");\nperson1.sayHello();\n\n// This fails since the method is not visible from this scope\nalert(person1.calcFullName());\n" }, { "answer_id": 61118, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 6, "selected": false, "text": "with" }, { "answer_id": 61125, "author": "Patrick", "author_id": 429, "author_profile": "https://Stackoverflow.com/users/429", "pm_score": 7, "selected": false, "text": "[]" }, { "answer_id": 61129, "author": "Eric Schoonover", "author_id": 3957, "author_profile": "https://Stackoverflow.com/users/3957", "pm_score": 6, "selected": false, "text": "Array.prototype.contains = function(value) { \n for (var i = 0; i < this.length; i++) { \n if (this[i] == value) return true; \n } \n return false; \n}\n" }, { "answer_id": 61158, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 7, "selected": false, "text": "||" }, { "answer_id": 61173, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 7, "selected": false, "text": "var x = 1;\n{\n var x = 2;\n}\nalert(x); // outputs 2\n" }, { "answer_id": 61193, "author": "Tyler", "author_id": 5642, "author_profile": "https://Stackoverflow.com/users/5642", "pm_score": 5, "selected": false, "text": "//Takes a function that filters numbers and calls the function on \n//it to build up a list of numbers that satisfy the function.\nfunction filter(filterFunction, numbers)\n{\n var filteredNumbers = [];\n\n for (var index = 0; index < numbers.length; index++)\n {\n if (filterFunction(numbers[index]) == true)\n {\n filteredNumbers.push(numbers[index]);\n }\n }\n return filteredNumbers;\n}\n\n//Creates a function (closure) that will remember the value \"lowerBound\" \n//that gets passed in and keep a copy of it.\nfunction buildGreaterThanFunction(lowerBound)\n{\n return function (numberToCheck) {\n return (numberToCheck > lowerBound) ? true : false;\n };\n}\n\nvar numbers = [1, 15, 20, 4, 11, 9, 77, 102, 6];\n\nvar greaterThan7 = buildGreaterThanFunction(7);\nvar greaterThan15 = buildGreaterThanFunction(15);\n\nnumbers = filter(greaterThan7, numbers);\nalert('Greater Than 7: ' + numbers);\n\nnumbers = filter(greaterThan15, numbers);\nalert('Greater Than 15: ' + numbers);\n" }, { "answer_id": 61196, "author": "Tyler", "author_id": 5642, "author_profile": "https://Stackoverflow.com/users/5642", "pm_score": 5, "selected": false, "text": "// Defines a Pet class constructor \nfunction Pet(name) \n{\n this.getName = function() { return name; };\n this.setName = function(newName) { name = newName; };\n}\n\n// Adds the Pet.toString() function for all Pet objects\nPet.prototype.toString = function() \n{\n return 'This pets name is: ' + this.getName();\n};\n// end of class Pet\n\n// Define Dog class constructor (Dog : Pet) \nfunction Dog(name, breed) \n{\n // think Dog : base(name) \n Pet.call(this, name);\n this.getBreed = function() { return breed; };\n}\n\n// this makes Dog.prototype inherit from Pet.prototype\nDog.prototype = new Pet();\n\n// Currently Pet.prototype.constructor\n// points to Pet. We want our Dog instances'\n// constructor to point to Dog.\nDog.prototype.constructor = Dog;\n\n// Now we override Pet.prototype.toString\nDog.prototype.toString = function() \n{\n return 'This dogs name is: ' + this.getName() + \n ', and its breed is: ' + this.getBreed();\n};\n// end of class Dog\n\nvar parrotty = new Pet('Parrotty the Parrot');\nvar dog = new Dog('Buddy', 'Great Dane');\n// test the new toString()\nalert(parrotty);\nalert(dog);\n\n// Testing instanceof (similar to the `is` operator)\nalert('Is dog instance of Dog? ' + (dog instanceof Dog)); //true\nalert('Is dog instance of Pet? ' + (dog instanceof Pet)); //true\nalert('Is dog instance of Object? ' + (dog instanceof Object)); //true\n" }, { "answer_id": 61545, "author": "Martin Clarke", "author_id": 2422, "author_profile": "https://Stackoverflow.com/users/2422", "pm_score": 8, "selected": false, "text": "===" }, { "answer_id": 61584, "author": "Marius", "author_id": 1585, "author_profile": "https://Stackoverflow.com/users/1585", "pm_score": 3, "selected": false, "text": "function someFunction(){\n var Static = arguments.callee;\n Static.someStaticVariable = (Static.someStaticVariable || 0) + 1;\n alert(Static.someStaticVariable);\n}\nsomeFunction() //Alerts 1\nsomeFunction() //Alerts 2\nsomeFunction() //Alerts 3\n" }, { "answer_id": 64404, "author": "JW.", "author_id": 4321, "author_profile": "https://Stackoverflow.com/users/4321", "pm_score": 3, "selected": false, "text": "undefined" }, { "answer_id": 64912, "author": "Vitaly Sharovatov", "author_id": 6647, "author_profile": "https://Stackoverflow.com/users/6647", "pm_score": 2, "selected": false, "text": "var singleton = function(){ \n\n if (typeof arguments.callee.__instance__ == 'undefined') { \n\n arguments.callee.__instance__ = new function(){\n\n //this creates a random private variable.\n //this could be a complicated calculation or DOM traversing that takes long\n //or anything that needs to be \"cached\"\n var rnd = Math.random();\n\n //just a \"public\" function showing the private variable value\n this.smth = function(){ alert('it is an object with a rand num=' + rnd); };\n\n };\n\n }\n\n return arguments.callee.__instance__;\n\n};\n\n\nvar a = new singleton;\nvar b = new singleton;\n\na.smth(); \nb.smth();\n" }, { "answer_id": 64950, "author": "Thevs", "author_id": 8559, "author_profile": "https://Stackoverflow.com/users/8559", "pm_score": 4, "selected": false, "text": "function isLeapYear(year) {\n return (new Date(year, 1, 29, 0, 0).getMonth() != 2);\n}\n" }, { "answer_id": 65002, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 3, "selected": false, "text": "//e.g., createAddFunction(\"a\",\"b\") returns function(a,b) { return a+b; }\nfunction createAddFunction(paramName1, paramName2)\n { return new Function( paramName1, paramName2\n ,\"return \"+ paramName1 +\" + \"+ paramName2 +\";\");\n }\n" }, { "answer_id": 65028, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 9, "selected": false, "text": "arguments" }, { "answer_id": 65064, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 4, "selected": false, "text": "var x = {a: 0};\nx[\"a\"]; //returns 0\n\nx[\"b\"] = 1;\nx.b; //returns 1\n\nfor (p in x) document.write(p+\";\"); //writes \"a;b;\"\n" }, { "answer_id": 65124, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 7, "selected": false, "text": "var x = 1;\nvar y = 3;\nvar list = {0:0, 1:0, 2:0};\nx in list; //true\ny in list; //false\n1 in list; //true\ny in {3:0, 4:0, 5:0}; //true\n" }, { "answer_id": 65415, "author": "Sebastian Rittau", "author_id": 7779, "author_profile": "https://Stackoverflow.com/users/7779", "pm_score": 4, "selected": false, "text": "var x = { intValue: 5, strValue: \"foo\" };\n" }, { "answer_id": 68961, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "function getObjectType( obj ) { \n return obj.constructor.name; \n} \n\nwindow.onload = function() { \n alert( getObjectType( \"Hello World!\" ) ); \n function Cat() { \n // some code here... \n } \n alert( getObjectType( new Cat() ) ); \n}\n" }, { "answer_id": 75844, "author": "noah", "author_id": 12034, "author_profile": "https://Stackoverflow.com/users/12034", "pm_score": 3, "selected": false, "text": "var o1 = { foo: 1, bar: 'abc' };\nfunction f() {}\nf.prototype = o1;\no2 = new f();\nassert( o2.foo === 1 );\nassert( o2.bar === 'abc' );\no2.foo = 2;\no2.baz = true;\nassert( o2.foo === 2 );\n// o1 is unchanged by assignment to o2\nassert( o1.foo === 1 );\nassert( o2.baz );\n" }, { "answer_id": 78155, "author": "user14079", "author_id": 14079, "author_profile": "https://Stackoverflow.com/users/14079", "pm_score": 4, "selected": false, "text": "// Usual Way\nvar d = new Date();\ntimestamp = d.getTime();\n\n// Shorter Way\ntimestamp = (new Date()).getTime();\n\n// Shortest Way\ntimestamp = +new Date();\n" }, { "answer_id": 78290, "author": "Jimmy", "author_id": 4435, "author_profile": "https://Stackoverflow.com/users/4435", "pm_score": 3, "selected": false, "text": "function x() {\n alert(\"Hello World\");\n}\neval (\"x = \" + (x + \"\").replace(\n 'Hello World',\n 'STACK OVERFLOW BWAHAHA\"); x(\"'));\nx();\n" }, { "answer_id": 104424, "author": "Chris MacDonald", "author_id": 18146, "author_profile": "https://Stackoverflow.com/users/18146", "pm_score": 5, "selected": false, "text": "var test = function () {\n //private members\n var x = 1;\n var y = function () {\n return x * 2;\n };\n //public interface\n return {\n setx : function (newx) {\n x = newx;\n },\n gety : function () {\n return y();\n }\n }\n}();\n\nassert(undefined == test.x);\nassert(undefined == test.y);\nassert(2 == test.gety());\ntest.setx(5);\nassert(10 == test.gety());\n" }, { "answer_id": 105603, "author": "Vincent Robert", "author_id": 268, "author_profile": "https://Stackoverflow.com/users/268", "pm_score": 6, "selected": false, "text": "var listNodes = document.getElementsByTagName('a');\nlistNodes.sort(function(a, b){ ... });\n" }, { "answer_id": 109360, "author": "Zach", "author_id": 9128, "author_profile": "https://Stackoverflow.com/users/9128", "pm_score": 5, "selected": false, "text": "// convert to base 2\n(5).toString(2) // returns \"101\"\n\n// provide built in iteration\nNumber.prototype.times = function(funct){\n if(typeof funct === 'function') {\n for(var i = 0;i < Math.floor(this);i++) {\n funct(i);\n }\n }\n return this;\n}\n\n\n(5).times(function(i){\n string += i+\" \";\n});\n// string now equals \"0 1 2 3 4 \"\n\nvar x = 1000;\n\nx.times(function(i){\n document.body.innerHTML += '<p>paragraph #'+i+'</p>';\n});\n// adds 1000 parapraphs to the document\n" }, { "answer_id": 110337, "author": "user19745", "author_id": 19745, "author_profile": "https://Stackoverflow.com/users/19745", "pm_score": 3, "selected": false, "text": "var z = ( x = \"can you do crazy things with parenthesis\", ( y = x.split(\" \"), [ y[1], y[0] ].concat( y.slice(2) ) ).join(\" \") )\n\nalert(x + \"\\n\" + y + \"\\n\" + z)\n" }, { "answer_id": 114695, "author": "Dan", "author_id": 17121, "author_profile": "https://Stackoverflow.com/users/17121", "pm_score": 3, "selected": false, "text": "function(){\n arguments.push('foo') // This errors, arguments is not a proper array and has no push method\n Array.prototype.push.apply(arguments, ['foo']) // Works!\n}\n" }, { "answer_id": 115587, "author": "jrockway", "author_id": 8457, "author_profile": "https://Stackoverflow.com/users/8457", "pm_score": 2, "selected": false, "text": "// Create a class called Point\nClass(\"Point\", {\n has: {\n x: {\n is: \"rw\",\n init: 0\n },\n y: {\n is: \"rw\",\n init: 0\n }\n },\n methods: {\n clear: function () {\n this.setX(0);\n this.setY(0);\n }\n }\n})\n\n// Use the class\nvar point = new Point();\npoint.setX(10)\npoint.setY(20);\npoint.clear();\n" }, { "answer_id": 116790, "author": "Andrey Fedorov", "author_id": 10728, "author_profile": "https://Stackoverflow.com/users/10728", "pm_score": 5, "selected": false, "text": "aWizz = wizz || \"default\";\n// same as: if (wizz) { aWizz = wizz; } else { aWizz = \"default\"; }\n" }, { "answer_id": 117022, "author": "Leo", "author_id": 20689, "author_profile": "https://Stackoverflow.com/users/20689", "pm_score": 5, "selected": false, "text": "var recurse = function() {\n if (condition) arguments.callee(); //calls recurse() again\n}\n" }, { "answer_id": 117922, "author": "treat your mods well", "author_id": 20772, "author_profile": "https://Stackoverflow.com/users/20772", "pm_score": 1, "selected": false, "text": "Array" }, { "answer_id": 117951, "author": "David Leonard", "author_id": 19502, "author_profile": "https://Stackoverflow.com/users/19502", "pm_score": 6, "selected": false, "text": "NaN" }, { "answer_id": 118150, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "parseInt()" }, { "answer_id": 118556, "author": "Chris Noe", "author_id": 14749, "author_profile": "https://Stackoverflow.com/users/14749", "pm_score": 4, "selected": false, "text": "for (i in a)" }, { "answer_id": 123136, "author": "travis", "author_id": 1414, "author_profile": "https://Stackoverflow.com/users/1414", "pm_score": 4, "selected": false, "text": "var a = []; // equivalent to new Array()\nvar o = {}; // equivalent to new Object()\n" }, { "answer_id": 128867, "author": "ScottKoon", "author_id": 1538, "author_profile": "https://Stackoverflow.com/users/1538", "pm_score": 7, "selected": false, "text": "(function() { alert(\"hi there\");})();\n" }, { "answer_id": 143666, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": ">>> 1 == true\ntrue\n>>> 0 == false\ntrue\n>>> 2 == true\nfalse\n" }, { "answer_id": 152545, "author": "Rob", "author_id": 11715, "author_profile": "https://Stackoverflow.com/users/11715", "pm_score": 4, "selected": false, "text": "function log(message) {\n (console || { log: function(s) { alert(s); }).log(message);\n}\n" }, { "answer_id": 155730, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 3, "selected": false, "text": "let" }, { "answer_id": 155761, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 3, "selected": false, "text": "function fib() {\n var i = 0, j = 1;\n while (true) {\n yield i;\n var t = i;\n i = j;\n j += t;\n }\n}\n\nvar g = fib();\nfor (var i = 0; i < 10; i++) {\n document.write(g.next() + \"<br>\\n\");\n}\n" }, { "answer_id": 155805, "author": "Ates Goral", "author_id": 23501, "author_profile": "https://Stackoverflow.com/users/23501", "pm_score": 6, "selected": false, "text": "var obj = { prop1: 42, prop2: 43 };\n\nobj.prop2 = undefined;\n\nfor (var key in obj) {\n ...\n" }, { "answer_id": 158462, "author": "Ates Goral", "author_id": 23501, "author_profile": "https://Stackoverflow.com/users/23501", "pm_score": 3, "selected": false, "text": "eval()" }, { "answer_id": 179154, "author": "Ates Goral", "author_id": 23501, "author_profile": "https://Stackoverflow.com/users/23501", "pm_score": 2, "selected": false, "text": "3.14 >> 0" }, { "answer_id": 182493, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": 2, "selected": false, "text": "var $links = $(\"a\");\n\n$links.hide();\n" }, { "answer_id": 224227, "author": "Justin Love", "author_id": 30203, "author_profile": "https://Stackoverflow.com/users/30203", "pm_score": 3, "selected": false, "text": "function blarg(a) {return a;} // statement\nbleep = function(b) {return b;} //expression\n" }, { "answer_id": 238770, "author": "Már Örlygsson", "author_id": 16271, "author_profile": "https://Stackoverflow.com/users/16271", "pm_score": 5, "selected": false, "text": "Object.beget = (function(Function){\n return function(Object){\n Function.prototype = Object;\n return new Function;\n }\n})(function(){});\n" }, { "answer_id": 302545, "author": "bbrown", "author_id": 20595, "author_profile": "https://Stackoverflow.com/users/20595", "pm_score": 3, "selected": false, "text": "window.name" }, { "answer_id": 347540, "author": "Andreas Grech", "author_id": 44084, "author_profile": "https://Stackoverflow.com/users/44084", "pm_score": 5, "selected": false, "text": "for (p in anObject) {\n if (anObject.hasOwnProperty(p)) {\n //Do stuff with p here\n }\n}\n" }, { "answer_id": 347552, "author": "Andreas Grech", "author_id": 44084, "author_profile": "https://Stackoverflow.com/users/44084", "pm_score": 4, "selected": false, "text": "var numbers = [1,2,3,4,5];\ndelete numbers[3];\n//numbers is now [1,2,3,undefined,5]\n" }, { "answer_id": 414508, "author": "Binoj Antony", "author_id": 33015, "author_profile": "https://Stackoverflow.com/users/33015", "pm_score": 3, "selected": false, "text": "AJAXCall('http://www.abcd.com/')\n\nfunction AJAXCall(url) {\n var client = new XMLHttpRequest();\n client.onreadystatechange = handlerFunc;\n client.open(\"GET\", url);\n client.send();\n}\n\nfunction handlerFunc() {\n if(this.readyState == 4 && this.status == 200) {\n if(this.responseXML != null)\n document.write(this.responseXML)\n }\n}\n" }, { "answer_id": 460884, "author": "Remy Sharp", "author_id": 22617, "author_profile": "https://Stackoverflow.com/users/22617", "pm_score": 2, "selected": false, "text": "while" }, { "answer_id": 476923, "author": "Paweł Witkowski Photography", "author_id": 58260, "author_profile": "https://Stackoverflow.com/users/58260", "pm_score": 2, "selected": false, "text": "var a;\na=alert(5),7;\nalert(a); // alerts undefined\na=7,alert(5);\nalert(a); // alerts 7\n\na=(3,6);\nalert(a); // alerts 6\n" }, { "answer_id": 490143, "author": "Breton", "author_id": 51101, "author_profile": "https://Stackoverflow.com/users/51101", "pm_score": 5, "selected": false, "text": "function getInnerText(o){\n return o === null? null : {\n string: o,\n array: o.map(getInnerText).join(\"\"),\n object:getInnerText(o[\"childNodes\"])\n }[typeis(o)];\n}\n" }, { "answer_id": 490169, "author": "Ionuț G. Stan", "author_id": 58808, "author_profile": "https://Stackoverflow.com/users/58808", "pm_score": 5, "selected": false, "text": "try {\n myroutine(); // may throw three exceptions\n} catch (e if e instanceof TypeError) {\n // statements to handle TypeError exceptions\n} catch (e if e instanceof RangeError) {\n // statements to handle RangeError exceptions\n} catch (e if e instanceof EvalError) {\n // statements to handle EvalError exceptions\n} catch (e) {\n // statements to handle any unspecified exceptions\n logMyErrors(e); // pass exception object to error handler\n}\n" }, { "answer_id": 490546, "author": "Breton", "author_id": 51101, "author_profile": "https://Stackoverflow.com/users/51101", "pm_score": 3, "selected": false, "text": "Array.prototype.slice.call({\"0\":\"foo\", \"1\":\"bar\", 2:\"baz\", \"length\":3 }) \n" }, { "answer_id": 625580, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": 2, "selected": false, "text": "var i;\n\nfor (i = 0; i < 10; i++) (function ()\n{\n // do something with i\n}());\n" }, { "answer_id": 628728, "author": "Ates Goral", "author_id": 23501, "author_profile": "https://Stackoverflow.com/users/23501", "pm_score": 2, "selected": false, "text": "arguments[-2]" }, { "answer_id": 645331, "author": "nickytonline", "author_id": 77814, "author_profile": "https://Stackoverflow.com/users/77814", "pm_score": 2, "selected": false, "text": "var a = [0, 1, 2];\n\n// code that might clear the array.\n\nif (a.length > 0) {\n // do something\n}\n" }, { "answer_id": 692380, "author": "Lucent", "author_id": 6385, "author_profile": "https://Stackoverflow.com/users/6385", "pm_score": 4, "selected": false, "text": "eval()" }, { "answer_id": 731342, "author": "e-satis", "author_id": 9951, "author_profile": "https://Stackoverflow.com/users/9951", "pm_score": 2, "selected": false, "text": "// creating an object (the short way, to use it like a hashmap)\nvar diner = {\n\"fruit\":\"apple\"\n\"veggetable\"=\"bean\"\n}\n\n// looping over its properties\nfor (meal_name in diner ) {\n document.write(meal_name+\"<br \\n>\");\n}\n" }, { "answer_id": 731411, "author": "David", "author_id": 21909, "author_profile": "https://Stackoverflow.com/users/21909", "pm_score": 3, "selected": false, "text": "function Animal () {\n\n}\n\nvar animal = new Animal();\nvar animal = new Animal;\n" }, { "answer_id": 841201, "author": "username", "author_id": 4939, "author_profile": "https://Stackoverflow.com/users/4939", "pm_score": 4, "selected": false, "text": "function fn(){\n var cat = \"meow\";\n var dog = \"woof\";\n return [cat,dog];\n};\n\nvar [cat,dog] = fn(); // Handy!\n\nalert(cat);\nalert(dog);\n" }, { "answer_id": 865753, "author": "Sebastian Schuth", "author_id": 107339, "author_profile": "https://Stackoverflow.com/users/107339", "pm_score": 2, "selected": false, "text": "function called(){\n alert(\"Go called by:\\n\"+arguments.callee.caller.toString());\n}\n\nfunction iDoTheCall(){\n called();\n}\n\niDoTheCall();\n" }, { "answer_id": 955784, "author": "pawelsto", "author_id": 109208, "author_profile": "https://Stackoverflow.com/users/109208", "pm_score": 1, "selected": false, "text": "<div id=\"jsTest\">Klick Me</div>\n<script type=\"text/javascript\">\n var someVariable = 'I was klicked';\n var divElement = document.getElementById('jsTest');\n // binding function/object or anything as attribute\n divElement.controller = function() { someVariable += '*'; alert('You can change instance data:\\n' + someVariable ); };\n var onclickFunct = new Function( 'this.controller();' ); // Works in Firefox and Internet Explorer.\n divElement.onclick = onclickFunct;\n</script>\n" }, { "answer_id": 1024826, "author": "Metal", "author_id": 75025, "author_profile": "https://Stackoverflow.com/users/75025", "pm_score": 3, "selected": false, "text": "o.constructor.constructor(\"alert('hi')\")()" }, { "answer_id": 1025127, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "var names = new Array(1024), i = names.length;\nwhile(i--)\n names[i] = \"John\" + i;\n" }, { "answer_id": 1025990, "author": "Justin Johnson", "author_id": 126562, "author_profile": "https://Stackoverflow.com/users/126562", "pm_score": 1, "selected": false, "text": "a || b || c || \"default\";" }, { "answer_id": 1043658, "author": "Blixt", "author_id": 119081, "author_profile": "https://Stackoverflow.com/users/119081", "pm_score": 1, "selected": false, "text": "prototype" }, { "answer_id": 1131595, "author": "RaYell", "author_id": 137467, "author_profile": "https://Stackoverflow.com/users/137467", "pm_score": 2, "selected": false, "text": "typeof" }, { "answer_id": 1162208, "author": "gotch4", "author_id": 138606, "author_profile": "https://Stackoverflow.com/users/138606", "pm_score": 1, "selected": false, "text": "function myClass(){\n this.fun = function(){\n do something;\n };\n}\n" }, { "answer_id": 1176498, "author": "outis", "author_id": 90527, "author_profile": "https://Stackoverflow.com/users/90527", "pm_score": 1, "selected": false, "text": "function Circle(r) {\n this.setR(r);\n}\n\nCircle.prototype = {\n recalcArea: function() {\n this.area=function() {\n area = this.r * this.r * Math.PI;\n this.area = function() {return area;}\n return area;\n }\n },\n setR: function (r) {\n this.r = r;\n this.invalidateR();\n },\n invalidateR: function() {\n this.recalcArea();\n }\n}\n" }, { "answer_id": 1211874, "author": "Fabian Jakobs", "author_id": 129322, "author_profile": "https://Stackoverflow.com/users/129322", "pm_score": 3, "selected": false, "text": "<script type=\"text/javascript\">\n(function() {\n\nfunction init() {\n // ...\n}\n\nwindow.onload = init;\n})();\n</script>\n" }, { "answer_id": 1211921, "author": "Fabian Jakobs", "author_id": 129322, "author_profile": "https://Stackoverflow.com/users/129322", "pm_score": 3, "selected": false, "text": "ns" }, { "answer_id": 1318068, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "\n function DriveIn()\n {\n this.car = 'Honda';\n alert(this.food); //'food' is the attribute of a future object \n //and DriveIn does not define it.\n }\n\n var A = {food:'chili', q:DriveIn}; //create object A whose q attribute \n //is the function DriveIn;\n\n alert(A.car); //displays 'undefined' \n A.q(); //displays 'chili' but also defines this.car.\n alert(A.car); //displays 'Honda' \n\n" }, { "answer_id": 1365822, "author": "pramodc84", "author_id": 40614, "author_profile": "https://Stackoverflow.com/users/40614", "pm_score": 6, "selected": false, "text": "function add_nums(num1, num2, num3 ){\n return num1 + num2 + num3;\n}\nadd_nums.length // 3 is the number of parameters expected.\n" }, { "answer_id": 1394655, "author": "vsync", "author_id": 104380, "author_profile": "https://Stackoverflow.com/users/104380", "pm_score": -1, "selected": false, "text": "alert(prompt('',something.innerHTML ));\n" }, { "answer_id": 1416391, "author": "Kris Kowal", "author_id": 42586, "author_profile": "https://Stackoverflow.com/users/42586", "pm_score": 2, "selected": false, "text": "+anything\nNumber(anything)\n" }, { "answer_id": 1462261, "author": "Seth", "author_id": 65295, "author_profile": "https://Stackoverflow.com/users/65295", "pm_score": 4, "selected": false, "text": "apply" }, { "answer_id": 1682820, "author": "Lyubomyr Shaydariv", "author_id": 166589, "author_profile": "https://Stackoverflow.com/users/166589", "pm_score": 2, "selected": false, "text": "// forget the debug alerts\nvar alertToFirebugConsole = function() {\n if ( window.console && window.console.log ) {\n window.alert = console.log;\n }\n}\n" }, { "answer_id": 1712004, "author": "Kenneth J", "author_id": 195456, "author_profile": "https://Stackoverflow.com/users/195456", "pm_score": 1, "selected": false, "text": "var fn = (function() {\n var ready = true;\n function fnX() {\n ready = false;\n // AJAX return function\n function Success() {\n ready = true;\n }\n Success();\n return \"this is a test\";\n }\n\n fnX.IsReady = function() {\n return ready;\n }\n return fnX;\n })();\n\n if (fn.IsReady()) {\n fn();\n }\n" }, { "answer_id": 2042069, "author": "Anil Namde", "author_id": 237743, "author_profile": "https://Stackoverflow.com/users/237743", "pm_score": 2, "selected": false, "text": "\nfunction divPopup(str)\n{\n //code to show the divPopup\n}\nwindow.alert = divPopup;\n" }, { "answer_id": 2047391, "author": "slebetman", "author_id": 167735, "author_profile": "https://Stackoverflow.com/users/167735", "pm_score": 4, "selected": false, "text": "// Say you want three functions to share a single variable:\n\n// Use a self-calling function to create scope:\n(function(){\n\n var counter = 0; // this is the variable we want to share;\n\n // Declare global functions using function expressions:\n increment = function(){\n return ++counter;\n }\n decrement = function(){\n return --counter;\n }\n value = function(){\n return counter;\n }\n})()\n" }, { "answer_id": 2243631, "author": "Andy E", "author_id": 94197, "author_profile": "https://Stackoverflow.com/users/94197", "pm_score": 6, "selected": false, "text": "+" }, { "answer_id": 2303653, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": 2, "selected": false, "text": "window.alert" }, { "answer_id": 2479026, "author": "adamJLev", "author_id": 26192, "author_profile": "https://Stackoverflow.com/users/26192", "pm_score": 1, "selected": false, "text": "function isRunningLocally(){\n var runningLocally = ....; // Might be an expensive check, check whatever needs to be checked.\n\n return (isRunningLocally = function(){\n return runningLocally;\n })();\n},\n" }, { "answer_id": 2709783, "author": "Harmen", "author_id": 176603, "author_profile": "https://Stackoverflow.com/users/176603", "pm_score": 4, "selected": false, "text": "function showSomething(a){\n alert(a);\n return arguments.callee;\n}\n\n// Alerts: 'a', 'b', 'c'\nshowSomething('a')('b')('c');\n\n// Or what about this:\n(function (a){\n alert(a);\n return arguments.callee;\n}​)('a')('b')('c');​​​​\n" }, { "answer_id": 2920211, "author": "wnrph", "author_id": 345520, "author_profile": "https://Stackoverflow.com/users/345520", "pm_score": 1, "selected": false, "text": "function f() { \n var a; \n function closureGet(){ return a; }\n function closureSet(val){ a=val;}\n return [closureGet,closureSet];\n}\n\n[closureGet,closureSet]=f(); \nclosureSet(5);\nalert(closureGet()); // gives 5\n\nclosureSet(15);\nalert(closureGet()); // gives 15\n" }, { "answer_id": 2921079, "author": "Tgr", "author_id": 323407, "author_profile": "https://Stackoverflow.com/users/323407", "pm_score": 3, "selected": false, "text": ":something" }, { "answer_id": 3110886, "author": "Edgar Klerks", "author_id": 375367, "author_profile": "https://Stackoverflow.com/users/375367", "pm_score": 1, "selected": false, "text": "callback: function(){\n stuff(arg1,arg2);\n}\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2443/" ]
61,092
<p>Having read the threads <a href="https://stackoverflow.com/questions/60919/is-sqlcommanddispose-enough">Is SqlCommand.Dispose enough?</a> and <a href="https://stackoverflow.com/questions/23867/closing-and-disposing-a-wcf-service">Closing and Disposing a WCF Service</a> I am wondering for classes such as SqlConnection or one of the several classes inheriting from the Stream class does it matter if I close Dispose rather than Close?</p>
[ { "answer_id": 61096, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 4, "selected": false, "text": "SqlConnection" }, { "answer_id": 61131, "author": "Brannon", "author_id": 5745, "author_profile": "https://Stackoverflow.com/users/5745", "pm_score": 5, "selected": false, "text": "IDisposable" }, { "answer_id": 61133, "author": "André Chalella", "author_id": 4850, "author_profile": "https://Stackoverflow.com/users/4850", "pm_score": 3, "selected": false, "text": "Dispose()" }, { "answer_id": 61171, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 9, "selected": true, "text": "Close" }, { "answer_id": 44633468, "author": "Deep Jadia", "author_id": 7437225, "author_profile": "https://Stackoverflow.com/users/7437225", "pm_score": 1, "selected": false, "text": "private void CloseConnection(Client client)\n {\n if (client != null && client.State == CommunicationState.Opened)\n {\n client.Close();\n }\n else\n {\n client.Abort();\n }\n }\n" }, { "answer_id": 73442564, "author": "Alexander Kozachenko", "author_id": 3423333, "author_profile": "https://Stackoverflow.com/users/3423333", "pm_score": 0, "selected": false, "text": "TransactionScope" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5086/" ]
61,109
<p>I have been learning C++ for a while now, I find it very powerful. But, the problem is the the level of abstraction is not much and I have to do memory management myself. What are the languages that I can use which uses a higher level of abstraction.</p>
[ { "answer_id": 12147944, "author": "mikera", "author_id": 214010, "author_profile": "https://Stackoverflow.com/users/214010", "pm_score": 1, "selected": false, "text": ";; treat a vector as a sequence and reverse it\n(reverse [1 2 3 4 5])\n=> (5 4 3 2 1)\n\n;; Take 10 items from a infinite sequence\n(take 10 (range))\n=> (0 1 2 3 4 5 6 7 8 9)\n\n;; Treat a String as a sequence of characters, calculate the frequencies\n(frequencies \"abracadabra\")\n=> {\\a 5, \\b 2, \\r 2, \\c 1, \\d 1}\n\n;; Define an infinite lazy sequence of fibonacci numbers, take the first 10\n(def fibs (concat [0 1] (lazy-seq (map + fibs (rest fibs)))))\n(take 10 fibs)\n=> (0 1 1 2 3 5 8 13 21 34)\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6323/" ]
61,110
<p>I need advice on how to have my C# console application display text to the user through the standard output while still being able access it later on. The actual feature I would like to implement is to dump the entire output buffer to a text file at the end of program execution.</p> <p>The workaround I use while I don't find a cleaner approach is to subclass <code>TextWriter</code> overriding the writing methods so they would both write to a file and call the original stdout writer. Something like this:</p> <pre><code>public class DirtyWorkaround { private class DirtyWriter : TextWriter { private TextWriter stdoutWriter; private StreamWriter fileWriter; public DirtyWriter(string path, TextWriter stdoutWriter) { this.stdoutWriter = stdoutWriter; this.fileWriter = new StreamWriter(path); } override public void Write(string s) { stdoutWriter.Write(s); fileWriter.Write(s); fileWriter.Flush(); } // Same as above for WriteLine() and WriteLine(string), // plus whatever methods I need to override to inherit // from TextWriter (Encoding.Get I guess). } public static void Main(string[] args) { using (DirtyWriter dw = new DirtyWriter("path", Console.Out)) { Console.SetOut(dw); // Teh codez } } } </code></pre> <p>See that it writes to and flushes the file all the time. I'd love to do it only at the end of the execution, but I couldn't find any way to access to the output buffer.</p> <p>Also, excuse inaccuracies with the above code (had to write it <em>ad hoc</em>, sorry ;).</p>
[ { "answer_id": 61119, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 3, "selected": false, "text": "MultiWriter" }, { "answer_id": 61123, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 1, "selected": false, "text": "tee" }, { "answer_id": 61164, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 0, "selected": false, "text": "Console.WriteLine" }, { "answer_id": 369254, "author": "Rob Parker", "author_id": 181460, "author_profile": "https://Stackoverflow.com/users/181460", "pm_score": 0, "selected": false, "text": "stdoutWriter" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4850/" ]
61,143
<p>Can someone show me how to implement a recursive lambda expression to traverse a tree structure in C#. </p>
[ { "answer_id": 61149, "author": "DevelopingChris", "author_id": 1220, "author_profile": "https://Stackoverflow.com/users/1220", "pm_score": 1, "selected": false, "text": " public void HandleTreeItems(Action<TreeItem> item, TreeItem parent)\n {\n if (parent.Children.Count > 0)\n {\n foreach (TreeItem ti in parent.Children)\n {\n HandleTreeItems(item, ti);\n }\n }\n\n item(parent);\n }\n" }, { "answer_id": 61206, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 5, "selected": false, "text": "Func<int, int> fact = null;\nfact = x => (x == 0) ? 1 : x * fact(x - 1);\n" }, { "answer_id": 61244, "author": "Tom Lokhorst", "author_id": 2597, "author_profile": "https://Stackoverflow.com/users/2597", "pm_score": 4, "selected": false, "text": "Func<int, int> fact = null;\nfact = x => (x == 0) ? 1 : x * fact(x - 1);\n" }, { "answer_id": 61257, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 7, "selected": true, "text": "class TreeNode\n{\n public string Value { get; set;}\n public List<TreeNode> Nodes { get; set;}\n\n\n public TreeNode()\n {\n Nodes = new List<TreeNode>();\n }\n}\n\nAction<TreeNode> traverse = null;\n\ntraverse = (n) => { Console.WriteLine(n.Value); n.Nodes.ForEach(traverse);};\n\nvar root = new TreeNode { Value = \"Root\" };\nroot.Nodes.Add(new TreeNode { Value = \"ChildA\"} );\nroot.Nodes[0].Nodes.Add(new TreeNode { Value = \"ChildA1\" });\nroot.Nodes[0].Nodes.Add(new TreeNode { Value = \"ChildA2\" });\nroot.Nodes.Add(new TreeNode { Value = \"ChildB\"} );\nroot.Nodes[1].Nodes.Add(new TreeNode { Value = \"ChildB1\" });\nroot.Nodes[1].Nodes.Add(new TreeNode { Value = \"ChildB2\" });\n\ntraverse(root);\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61143", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5360/" ]
61,150
<p>My motto for Java is "just because Java has static blocks, it doesn't mean that you should be using them." Jokes aside, there are a lot of tricks in Java that make testing a nightmare. Two of the most I hate are Anonymous Classes and Static Blocks. We have a lot of legacy code that make use of Static Blocks and these are one of the annoying points in our push in writing unit tests. Our goal is to be able to write unit tests for classes that depend on this static initialization with minimal code changes. </p> <p>So far my suggestion to my colleagues is to move the body of the static block into a private static method and call it <code>staticInit</code>. This method can then be called from within the static block. For unit testing another class that depends on this class could easily mock <code>staticInit</code> with <a href="https://jmockit.github.io/" rel="noreferrer">JMockit</a> to not do anything. Let's see this in example.</p> <pre><code>public class ClassWithStaticInit { static { System.out.println("static initializer."); } } </code></pre> <p>Will be changed to</p> <pre><code>public class ClassWithStaticInit { static { staticInit(); } private static void staticInit() { System.out.println("static initialized."); } } </code></pre> <p>So that we can do the following in a <a href="https://junit.org/junit5/" rel="noreferrer">JUnit</a>.</p> <pre><code>public class DependentClassTest { public static class MockClassWithStaticInit { public static void staticInit() { } } @BeforeClass public static void setUpBeforeClass() { Mockit.redefineMethods(ClassWithStaticInit.class, MockClassWithStaticInit.class); } } </code></pre> <p>However this solution also comes with its own problems. You can't run <code>DependentClassTest</code> and <code>ClassWithStaticInitTest</code> on the same JVM since you actually want the static block to run for <code>ClassWithStaticInitTest</code>.</p> <p>What would be your way of accomplishing this task? Or any better, non-JMockit based solutions that you think would work cleaner?</p>
[ { "answer_id": 61153, "author": "Justin Standard", "author_id": 92, "author_profile": "https://Stackoverflow.com/users/92", "pm_score": 3, "selected": false, "text": "staticInit()" }, { "answer_id": 61190, "author": "marcospereira", "author_id": 4600, "author_profile": "https://Stackoverflow.com/users/4600", "pm_score": 2, "selected": false, "text": "Math.metaClass.'static'.max = { int a, int b -> \n a + b\n}\n\nMath.max 1, 2\n" }, { "answer_id": 61389, "author": "martinatime", "author_id": 1353, "author_profile": "https://Stackoverflow.com/users/1353", "pm_score": 1, "selected": false, "text": "public static class MockClassWithEmptyStaticInit {\n public static void staticInit() {\n }\n}\n" }, { "answer_id": 144876, "author": "Cem Catikkas", "author_id": 3087, "author_profile": "https://Stackoverflow.com/users/3087", "pm_score": 4, "selected": false, "text": "public void $clinit()" }, { "answer_id": 489018, "author": "Jan Kronquist", "author_id": 43935, "author_profile": "https://Stackoverflow.com/users/43935", "pm_score": 6, "selected": false, "text": "@RunWith(PowerMockRunner.class)\n@SuppressStaticInitializationFor(\"some.package.ClassWithStaticInit\")\n" }, { "answer_id": 7242341, "author": "matsev", "author_id": 303598, "author_profile": "https://Stackoverflow.com/users/303598", "pm_score": 4, "selected": false, "text": "@SuppressStaticInitializationFor" }, { "answer_id": 33737521, "author": "KidCrippler", "author_id": 223365, "author_profile": "https://Stackoverflow.com/users/223365", "pm_score": 0, "selected": false, "text": "Mockit.redefineMethods" }, { "answer_id": 64216523, "author": "Sebastian Luna", "author_id": 7845889, "author_profile": "https://Stackoverflow.com/users/7845889", "pm_score": 0, "selected": false, "text": "ClassWithStaticInit staticInitClass = new ClassWithStaticInit()\nWhitebox.invokeMethod(staticInitClass, \"staticInit\");\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3087/" ]
61,151
<p>If you're writing a library, or an app, where do the unit test files go? </p> <p>It's nice to separate the test files from the main app code, but it's awkward to put them into a "tests" subdirectory inside of the app root directory, because it makes it harder to import the modules that you'll be testing. </p> <p>Is there a best practice here?</p>
[ { "answer_id": 61169, "author": "Cristian", "author_id": 680, "author_profile": "https://Stackoverflow.com/users/680", "pm_score": 6, "selected": false, "text": "parent_dir/\n foo.py\n tests/\n" }, { "answer_id": 61531, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 4, "selected": false, "text": "tests/" }, { "answer_id": 61820, "author": "George V. Reilly", "author_id": 6364, "author_profile": "https://Stackoverflow.com/users/6364", "pm_score": 1, "selected": false, "text": "if __name__ == \"__main__\"" }, { "answer_id": 62527, "author": "user6868", "author_id": 6868, "author_profile": "https://Stackoverflow.com/users/6868", "pm_score": 8, "selected": false, "text": "module.py" }, { "answer_id": 77145, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": ">>> import module\n>>> module.method('test')\n'testresult'\n" }, { "answer_id": 103610, "author": "Thomas Andrews", "author_id": 7061, "author_profile": "https://Stackoverflow.com/users/7061", "pm_score": 5, "selected": false, "text": "if __name__ == '__main__':\n do tests...\n" }, { "answer_id": 128616, "author": "André", "author_id": 9683, "author_profile": "https://Stackoverflow.com/users/9683", "pm_score": 2, "selected": false, "text": "app/src/code.py\napp/testing/code_test.py \napp/docs/..\n" }, { "answer_id": 382596, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "test_suite='tests.runalltests.suite'" }, { "answer_id": 2363162, "author": "Dale Reidy", "author_id": 50746, "author_profile": "https://Stackoverflow.com/users/50746", "pm_score": 3, "selected": false, "text": "project/\n src/\n code.py\n tests/\n setup.py\n" }, { "answer_id": 22704148, "author": "Rahul Biswas", "author_id": 2726038, "author_profile": "https://Stackoverflow.com/users/2726038", "pm_score": 4, "selected": false, "text": " <Main Package>\n / \\\n / \\\n lib tests\n / \\\n [module1.py, module2.py, [ut_module1.py, ut_module2.py,\n module3.py module4.py, ut_module3.py, ut_module.py]\n __init__.py]\n" }, { "answer_id": 23386287, "author": "Steely Wing", "author_id": 1877620, "author_profile": "https://Stackoverflow.com/users/1877620", "pm_score": 7, "selected": false, "text": "module/\n lib/\n __init__.py\n module.py\n test.py\n" }, { "answer_id": 37122327, "author": "Arash", "author_id": 832304, "author_profile": "https://Stackoverflow.com/users/832304", "pm_score": 4, "selected": false, "text": "myPackage/\n myapp/\n moduleA/\n __init__.py\n module_A.py\n moduleB/\n __init__.py\n module_B.py\nsetup.py\n" }, { "answer_id": 39740835, "author": "Janusz Skonieczny", "author_id": 260480, "author_profile": "https://Stackoverflow.com/users/260480", "pm_score": 5, "selected": false, "text": "find_packages(\"src\", exclude=[\"*.tests\", \"*.tests.*\", \"tests.*\", \"tests\"]) \n" }, { "answer_id": 53740627, "author": "cjs", "author_id": 107294, "author_profile": "https://Stackoverflow.com/users/107294", "pm_score": 2, "selected": false, "text": "foo.py" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
61,155
<p>I'm trying to place this menu on the left hand side of the page:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="left-menu" style="left: 123px; top: 355px"&gt; &lt;ul&gt; &lt;li&gt; Categories &lt;/li&gt; &lt;li&gt; Weapons &lt;/li&gt; &lt;li&gt; Armor &lt;/li&gt; &lt;li&gt; Manuals &lt;/li&gt; &lt;li&gt; Sustenance &lt;/li&gt; &lt;li&gt; Test &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>The problem is that if I use absolute or fixed values, different screen sizes will render the navigation bar differently. I also have a second <code>div</code> that contains all the main content which also needs to be moved to the right, so far I'm using relative values which seems to work no matter the screen size.</p>
[ { "answer_id": 61200, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": true, "text": "float" }, { "answer_id": 61438, "author": "Bryan M.", "author_id": 4636, "author_profile": "https://Stackoverflow.com/users/4636", "pm_score": 2, "selected": false, "text": "<div>" }, { "answer_id": 15769430, "author": "Eng Maisa", "author_id": 2214827, "author_profile": "https://Stackoverflow.com/users/2214827", "pm_score": 0, "selected": false, "text": "<div class=\"left-menu\">\n<ul>\n<li> Categories </li>\n<li> Weapons </li>\n<li> Armor </li>\n<li> Manuals </li>\n<li> Sustenance </li>\n<li> Test </li>\n</ul>\n</div>\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4298/" ]
61,176
<p>I want to access messages in Gmail from a Java application using <a href="http://www.ing.iac.es/~docs/external/java/javamail/javadocs/index.html" rel="nofollow noreferrer">JavaMail</a> and <a href="https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol" rel="nofollow noreferrer">IMAP</a>. Why am I getting a <em><a href="https://docs.oracle.com/javase/7/docs/api/java/net/SocketTimeoutException.html" rel="nofollow noreferrer">SocketTimeoutException</a></em> ?</p> <p>Here is my code:</p> <pre><code>Properties props = System.getProperties(); props.setProperty("mail.imap.host", "imap.gmail.com"); props.setProperty("mail.imap.port", "993"); props.setProperty("mail.imap.connectiontimeout", "5000"); props.setProperty("mail.imap.timeout", "5000"); try { Session session = Session.getDefaultInstance(props, new MyAuthenticator()); URLName urlName = new URLName("imap://MYUSERNAME@gmail.com:MYPASSWORD@imap.gmail.com"); Store store = session.getStore(urlName); if (!store.isConnected()) { store.connect(); } } catch (NoSuchProviderException e) { e.printStackTrace(); System.exit(1); } catch (MessagingException e) { e.printStackTrace(); System.exit(2); } </code></pre> <p>I have set the timeout values so that it wouldn't take "forever" to timeout. Also, <em>MyAuthenticator</em> also has the username and password, which seems redundant with the URL. Is there another way to specify the protocol? (I didn't see it in the JavaDoc for <a href="https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol" rel="nofollow noreferrer">IMAP</a>.)</p>
[ { "answer_id": 61185, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 3, "selected": false, "text": "imaps" }, { "answer_id": 61469, "author": "Dave", "author_id": 2512222, "author_profile": "https://Stackoverflow.com/users/2512222", "pm_score": 6, "selected": false, "text": "Properties props = System.getProperties();\nprops.setProperty(\"mail.store.protocol\", \"imaps\");\ntry {\n Session session = Session.getDefaultInstance(props, null);\n Store store = session.getStore(\"imaps\");\n store.connect(\"imap.gmail.com\", \"<username>@gmail.com\", \"<password>\");\n ...\n} catch (NoSuchProviderException e) {\n e.printStackTrace();\n System.exit(1);\n} catch (MessagingException e) {\n e.printStackTrace();\n System.exit(2);\n}\n" }, { "answer_id": 260650, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "URLName server = new URLName(\"imaps://<gmail-user-name>:<gmail-pass>@imap.gmail.com/INBOX\");\n" }, { "answer_id": 2385657, "author": "Fu Cheng", "author_id": 221847, "author_profile": "https://Stackoverflow.com/users/221847", "pm_score": 1, "selected": false, "text": "\"mail.imaps.host\" : \"imap.gmail.com\" \n\"mail.store.protocol\" : \"imaps\" \n\"mail.imaps.port\" : \"993\"\n" }, { "answer_id": 9888150, "author": "WhyNotHugo", "author_id": 107510, "author_profile": "https://Stackoverflow.com/users/107510", "pm_score": 3, "selected": false, "text": "props.setProperty(\"mail.imaps.host\", \"imap.gmail.com\");\nprops.setProperty(\"mail.imaps.port\", \"993\");\nprops.setProperty(\"mail.imaps.connectiontimeout\", \"5000\");\nprops.setProperty(\"mail.imaps.timeout\", \"5000\");\n" }, { "answer_id": 31214560, "author": "lboix", "author_id": 2920131, "author_profile": "https://Stackoverflow.com/users/2920131", "pm_score": 2, "selected": false, "text": " final Properties properties = new Properties();\n properties.put(\"mail.imap.ssl.enable\", \"true\");\n\n imapSession = Session.getInstance(properties, null);\n imapSession.setDebug(false);\n imapStore = imapSession.getStore(\"imap\");\n\n imapStore.connect(\"imap.gmail.com\", USERNAME, \"password\");\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2512222/" ]
61,212
<p>How do I delete untracked local files from the current working tree?</p>
[ { "answer_id": 61214, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 9, "selected": false, "text": "git-clean" }, { "answer_id": 64966, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 14, "selected": true, "text": "git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>…​\n" }, { "answer_id": 912737, "author": "robert.berger", "author_id": 108743, "author_profile": "https://Stackoverflow.com/users/108743", "pm_score": 10, "selected": false, "text": "git clean -f -d" }, { "answer_id": 14521765, "author": "Michał Szajbe", "author_id": 369894, "author_profile": "https://Stackoverflow.com/users/369894", "pm_score": 8, "selected": false, "text": "-f" }, { "answer_id": 18974433, "author": "Vijay C", "author_id": 255721, "author_profile": "https://Stackoverflow.com/users/255721", "pm_score": 7, "selected": false, "text": "git clean -f {dir_path}\n" }, { "answer_id": 20195320, "author": "Oscar Fraxedas", "author_id": 1074245, "author_profile": "https://Stackoverflow.com/users/1074245", "pm_score": 7, "selected": false, "text": "git clean -fdx\n" }, { "answer_id": 20846779, "author": "SystematicFrank", "author_id": 253098, "author_profile": "https://Stackoverflow.com/users/253098", "pm_score": 9, "selected": false, "text": "git clean -i\n" }, { "answer_id": 21057032, "author": "hiroshi", "author_id": 338986, "author_profile": "https://Stackoverflow.com/users/338986", "pm_score": 7, "selected": false, "text": "git stash push -u" }, { "answer_id": 28082580, "author": "Pooja", "author_id": 3446107, "author_profile": "https://Stackoverflow.com/users/3446107", "pm_score": 6, "selected": false, "text": "git clean -fd" }, { "answer_id": 29667299, "author": "Chhabilal", "author_id": 2554162, "author_profile": "https://Stackoverflow.com/users/2554162", "pm_score": 5, "selected": false, "text": "git clean -d -x -f\n" }, { "answer_id": 34049725, "author": "Nikita Leonov", "author_id": 723050, "author_profile": "https://Stackoverflow.com/users/723050", "pm_score": 5, "selected": false, "text": "git clean -f -d -x $(git rev-parse --show-cdup)" }, { "answer_id": 35427633, "author": "Omar Mowafi", "author_id": 1350159, "author_profile": "https://Stackoverflow.com/users/1350159", "pm_score": 4, "selected": false, "text": "git clean -d -n" }, { "answer_id": 35539401, "author": "thybzi", "author_id": 3027390, "author_profile": "https://Stackoverflow.com/users/3027390", "pm_score": 5, "selected": false, "text": "git add .\ngit reset --hard HEAD\n" }, { "answer_id": 35737150, "author": "JD Brennan", "author_id": 304712, "author_profile": "https://Stackoverflow.com/users/304712", "pm_score": 4, "selected": false, "text": "git stash save -u\ngit stash drop \"stash@{0}\"\n" }, { "answer_id": 37614185, "author": "Thanga", "author_id": 5678086, "author_profile": "https://Stackoverflow.com/users/5678086", "pm_score": 9, "selected": false, "text": "git add --all\ngit reset --hard HEAD\n" }, { "answer_id": 38978877, "author": "rahul286", "author_id": 156336, "author_profile": "https://Stackoverflow.com/users/156336", "pm_score": 5, "selected": false, "text": "git clean -ffdx\n" }, { "answer_id": 39968630, "author": "kujiy", "author_id": 5815086, "author_profile": "https://Stackoverflow.com/users/5815086", "pm_score": 4, "selected": false, "text": "git clean" }, { "answer_id": 40235858, "author": "Gaurav", "author_id": 3809978, "author_profile": "https://Stackoverflow.com/users/3809978", "pm_score": 4, "selected": false, "text": "git clean -fdn\n" }, { "answer_id": 41187216, "author": "Gnanasekar S", "author_id": 6859356, "author_profile": "https://Stackoverflow.com/users/6859356", "pm_score": 2, "selected": false, "text": "-i" }, { "answer_id": 42185640, "author": "Shital Shah", "author_id": 207661, "author_profile": "https://Stackoverflow.com/users/207661", "pm_score": 7, "selected": false, "text": "git clean -ffdx\n" }, { "answer_id": 42269293, "author": "Vaisakh VM", "author_id": 1905008, "author_profile": "https://Stackoverflow.com/users/1905008", "pm_score": 4, "selected": false, "text": "git clean -f to remove untracked files from working directory." }, { "answer_id": 42564993, "author": "bit_cracker007", "author_id": 1098479, "author_profile": "https://Stackoverflow.com/users/1098479", "pm_score": 5, "selected": false, "text": "git clean -i -fd\n\nRemove .classpath [y/N]? N\nRemove .gitignore [y/N]? N\nRemove .project [y/N]? N\nRemove .settings/ [y/N]? N\nRemove src/com/arsdumpgenerator/inspector/ [y/N]? y\nRemove src/com/arsdumpgenerator/manifest/ [y/N]? y\nRemove src/com/arsdumpgenerator/s3/ [y/N]? y\nRemove tst/com/arsdumpgenerator/manifest/ [y/N]? y\nRemove tst/com/arsdumpgenerator/s3/ [y/N]? y\n" }, { "answer_id": 45220636, "author": "Alireza", "author_id": 5423108, "author_profile": "https://Stackoverflow.com/users/5423108", "pm_score": 6, "selected": false, "text": "git" }, { "answer_id": 45558196, "author": "Vivek", "author_id": 4199462, "author_profile": "https://Stackoverflow.com/users/4199462", "pm_score": 0, "selected": false, "text": "git reset HEAD <file>" }, { "answer_id": 45994347, "author": "Mohideen bin Mohammed", "author_id": 4453737, "author_profile": "https://Stackoverflow.com/users/4453737", "pm_score": 4, "selected": false, "text": "git clean -i" }, { "answer_id": 46409906, "author": "Sergey", "author_id": 739731, "author_profile": "https://Stackoverflow.com/users/739731", "pm_score": 3, "selected": false, "text": "(git clean -d -x -f && git submodule foreach --recursive git clean -d -x -f)\n" }, { "answer_id": 46868431, "author": "DevWL", "author_id": 2179965, "author_profile": "https://Stackoverflow.com/users/2179965", "pm_score": 7, "selected": false, "text": "-n" }, { "answer_id": 47070614, "author": "Jämes", "author_id": 2780334, "author_profile": "https://Stackoverflow.com/users/2780334", "pm_score": 3, "selected": false, "text": "gclean='git clean -fd'" }, { "answer_id": 47627685, "author": "Elangovan", "author_id": 2614459, "author_profile": "https://Stackoverflow.com/users/2614459", "pm_score": 3, "selected": false, "text": "git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]\n" }, { "answer_id": 50404741, "author": "Sudhir Vishwakarma", "author_id": 493356, "author_profile": "https://Stackoverflow.com/users/493356", "pm_score": 3, "selected": false, "text": "git clean -f\n" }, { "answer_id": 53244015, "author": "Zia", "author_id": 2931121, "author_profile": "https://Stackoverflow.com/users/2931121", "pm_score": 2, "selected": false, "text": "git stash" }, { "answer_id": 55831043, "author": "victorm1710", "author_id": 680032, "author_profile": "https://Stackoverflow.com/users/680032", "pm_score": 1, "selected": false, "text": "git add -A && git commit -m temp && git reset --hard HEAD^" }, { "answer_id": 56520858, "author": "Thirdy", "author_id": 5118429, "author_profile": "https://Stackoverflow.com/users/5118429", "pm_score": -1, "selected": false, "text": "git status" }, { "answer_id": 59435746, "author": "ideasman42", "author_id": 432509, "author_profile": "https://Stackoverflow.com/users/432509", "pm_score": 0, "selected": false, "text": "#!/bin/bash\nreadarray -t -d '' FILES < <(git ls-files -z --other --directory)\nif [ \"$FILES\" = \"\" ]; then\n echo \"Nothing to clean!\"\n exit 0\nfi\necho -e \"Dirty files:\\n\"\nprintf ' %s\\n' \"${FILES[@]}\"\nDO_REMOVE=0\nwhile true; do\n echo \"\"\n read -p \"Remove ${#FILES[@]} files? [y/n]: \" choice\n case \"$choice\" in\n y|Y )\n DO_REMOVE=1\n break ;;\n n|N )\n echo \"Exiting!\"\n break ;;\n * ) echo \"Invalid input, expected [Y/y/N/n]\"\n continue ;;\n esac\ndone\n\nif [ \"$DO_REMOVE\" -eq 1 ];then\n echo \"Removing!\"\n for f in \"${FILES[@]}\"; do\n rm -rfv -- \"$f\"\n done\nfi\n" }, { "answer_id": 61917678, "author": "Rajeev Shetty", "author_id": 3932147, "author_profile": "https://Stackoverflow.com/users/3932147", "pm_score": 5, "selected": false, "text": "git add .\ngit reset --hard HEAD\n" }, { "answer_id": 63590924, "author": "Samir Kape", "author_id": 8312897, "author_profile": "https://Stackoverflow.com/users/8312897", "pm_score": 1, "selected": false, "text": "-q, --quiet do not print names of files removed\n-n, --dry-run dry run\n-f, --force force\n-i, --interactive interactive cleaning\n-d remove whole directories\n-e, --exclude <pattern>\n add <pattern> to ignore rules\n-x remove ignored files, too\n-X remove only ignored files\n" }, { "answer_id": 64769771, "author": "KARTHIKEYAN.A", "author_id": 4652706, "author_profile": "https://Stackoverflow.com/users/4652706", "pm_score": 3, "selected": false, "text": "$ git clean -f -d\nRemoving client/app/helpers/base64.js\nRemoving files/\nRemoving package.json.bak\n\nwhere \n-f is force \n-d is a directory \n" }, { "answer_id": 67098568, "author": "jenny", "author_id": 6409591, "author_profile": "https://Stackoverflow.com/users/6409591", "pm_score": 4, "selected": false, "text": "git add --all" }, { "answer_id": 68547440, "author": "Ahmet Emrebas", "author_id": 12603032, "author_profile": "https://Stackoverflow.com/users/12603032", "pm_score": 3, "selected": false, "text": "git add .\ngit stash \n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61212", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
61,217
<p>This question is a follow up to my <a href="https://stackoverflow.com/questions/56279/export-aspx-to-html">previous question</a> about getting the HTML from an ASPX page. I decided to try using the webclient object, but the problem is that I get the login page's HTML because login is required. I tried "logging in" using the webclient object:</p> <pre><code>WebClient ww = new WebClient(); ww.DownloadString("Login.aspx?UserName=&amp;Password="); string html = ww.DownloadString("Internal.aspx"); </code></pre> <p>But I still get the login page all the time. I know that the username info is not stored in a cookie. I must be doing something wrong or leaving out an important part. Does anyone know what it could be?</p>
[ { "answer_id": 61231, "author": "NakedBrunch", "author_id": 3742, "author_profile": "https://Stackoverflow.com/users/3742", "pm_score": 2, "selected": false, "text": "WebClient ww = new WebClient();\nww.Credentials = CredentialCache.DefaultCredentials;\nww.DownloadString(\"Login.aspx?UserName=&Password=\");\nstring html = ww.DownloadString(\"Internal.aspx\");\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278/" ]
61,219
<p>I've just started skimming 'Debugging MS .Net 2.0 Applications' by John Robbins, and have become confused by his evangelism for Debug.Assert(...).</p> <p>He points out that well-implemented Asserts store the state, somewhat, of an error condition, e.g.:</p> <pre><code>Debug.Assert(i &gt; 3, "i &gt; 3", "This means I got a bad parameter"); </code></pre> <p>Now, personally, it seems crazy to me that he so loves restating his test without an actual sensible 'business logic' comment, perhaps "i &lt;= 3 must never happen because of the flobittyjam widgitification process".</p> <p>So, I think I get Asserts as a kind-of low-level "Let's protect my assumptions" kind of thing... assuming that one feels this is a test one only needs to do in debug - i.e. you are protecting yourself against colleague and future programmers, and hoping that they actually test things.</p> <p>But what I don't get is, he then goes on to say that you should use assertions in addition to normal error handling; now what I envisage is something like this:</p> <pre><code>Debug.Assert(i &gt; 3, "i must be greater than 3 because of the flibbity widgit status"); if (i &lt;= 3) { throw new ArgumentOutOfRangeException("i", "i must be &gt; 3 because... i=" + i.ToString()); } </code></pre> <p>What have I gained by the Debug.Assert repetition of the error condition test? I think I'd get it if we were talking about debug-only double-checking of a very important calculation...</p> <pre><code>double interestAmount = loan.GetInterest(); Debug.Assert(debugInterestDoubleCheck(loan) == interestAmount, "Mismatch on interest calc"); </code></pre> <p>...but I don't get it for parameter tests which are surely worth checking (in both DEBUG and Release builds)... or not. What am I missing?</p>
[ { "answer_id": 61225, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 7, "selected": true, "text": "ArgumentOutOfRangeException" }, { "answer_id": 61266, "author": "hwiechers", "author_id": 5883, "author_profile": "https://Stackoverflow.com/users/5883", "pm_score": 4, "selected": false, "text": "public string ToString()\n{\n Debug.Assert(Name != null);\n return Name;\n}\n" }, { "answer_id": 5964259, "author": "Tim Abell", "author_id": 10245, "author_profile": "https://Stackoverflow.com/users/10245", "pm_score": 1, "selected": false, "text": "Debug.Assert(flibbles.count() < 1000000, \"too many flibbles\"); // indicate something is awry\nlog.warning(\"flibble count reached \" + flibbles.count()); // log in production as early warning\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6004/" ]
61,227
<p>If I have: </p> <pre><code>signed char * p; </code></pre> <p>and I do a comparison:</p> <pre><code>if ( *p == 0xFF ) break; </code></pre> <p>it will never catch 0XFF, but if I replace it with -1 it will:</p> <pre><code>if ( *p == (signed char)0xFF ) break; </code></pre> <p>How can this happen? Is it something with the sign flag? I though that <code>0xFF == -1 == 255</code>.</p>
[ { "answer_id": 61229, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 6, "selected": true, "text": "0xFF" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61227", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2566/" ]
61,233
<p>What is the best way to shred XML data into various database columns? So far I have mainly been using the nodes and value functions like so:</p> <pre><code>INSERT INTO some_table (column1, column2, column3) SELECT Rows.n.value('(@column1)[1]', 'varchar(20)'), Rows.n.value('(@column2)[1]', 'nvarchar(100)'), Rows.n.value('(@column3)[1]', 'int'), FROM @xml.nodes('//Rows') Rows(n) </code></pre> <p>However I find that this is getting very slow for even moderate size xml data.</p>
[ { "answer_id": 61246, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "INSERT INTO Test\nSELECT Id, Data \nFROM OPENXML (@XmlDocument, '/Root/blah',2)\nWITH (Id int '@ID',\n Data varchar(10) '@DATA')\n" }, { "answer_id": 631578, "author": "DannykPowell", "author_id": 67617, "author_profile": "https://Stackoverflow.com/users/67617", "pm_score": 1, "selected": false, "text": "INSERT INTO some_table (column1, column2, column3)\nSELECT\nRows.n.value('(@column1)[1]', 'varchar(20)'),\nRows.n.value('(@column2)[1]', 'nvarchar(100)'),\nRows.n.value('(@column3)[1]', 'int'),\nFROM @xml.nodes('//Rows') Rows(n)\n" }, { "answer_id": 4671129, "author": "Dan", "author_id": 572994, "author_profile": "https://Stackoverflow.com/users/572994", "pm_score": 7, "selected": true, "text": "IF EXISTS ( SELECT * FROM sys.xml_schema_collections where [name] = 'MyXmlSchema')\nDROP XML SCHEMA COLLECTION [MyXmlSchema]\nGO\n\nDECLARE @MySchema XML\nSET @MySchema = \n(\n SELECT * FROM OPENROWSET\n (\n BULK 'C:\\Path\\To\\Schema\\MySchema.xsd', SINGLE_CLOB \n ) AS xmlData\n)\n\nCREATE XML SCHEMA COLLECTION [MyXmlSchema] AS @MySchema \nGO\n" }, { "answer_id": 9794641, "author": "edhubbell", "author_id": 1054938, "author_profile": "https://Stackoverflow.com/users/1054938", "pm_score": 2, "selected": false, "text": "INSERT INTO some_table (column1, column2, column3)\n SELECT \n Rows.n.value(N'(@column1/text())[1]', 'varchar(20)'), \n Rows.n.value(N'(@column2/text())[1]', 'nvarchar(100)'), \n Rows.n.value(N'(@column3/text())[1]', 'int')\n FROM @xml.nodes('//Rows') Rows(n) \n" }, { "answer_id": 18264248, "author": "jccprj", "author_id": 2687849, "author_profile": "https://Stackoverflow.com/users/2687849", "pm_score": 3, "selected": false, "text": "INSERT INTO @tbl (Tbl_ID, Name, Value, ParamData)\nSELECT 1,\n tbl.cols.value('name[1]', 'nvarchar(255)'),\n tbl.cols.value('value[1]', 'nvarchar(255)'),\n tbl.cols.query('./paramdata[1]')\nFROM @xml.nodes('//root') as tbl(cols) OPTION ( OPTIMIZE FOR ( @xml = NULL ) )\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5769/" ]
61,262
<p>Here's the problem, you include multiple assemblies and add 'using namespaceX' at the top of your code file.<br> Now you want to create a class or use a symbol which is defined in multiple namespaces, e.g. <code>System.Windows.Controls.Image</code> &amp; <code>System.Drawing.Image</code></p> <p>Now unless you use the fully qualified name, there will be a crib/build error due to ambiguity inspite of the right 'using' declarations at the top. What is the way out here?</p> <p><em>(Another knowledge base post.. I found the answer after about 10 minutes of searching because I didn't know the right keyword to search for)</em></p>
[ { "answer_id": 61264, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 6, "selected": true, "text": "using System.Windows.Controls;\nusing Drawing = System.Drawing;\n\n...\n\nImage img = ... //System.Windows.Controls.Image\nDrawing.Image img2 = ... //System.Drawing.Image\n" }, { "answer_id": 61265, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 3, "selected": false, "text": "using ControlImage = System.Windows.Controls.Image;\nusing System.Drawing.Image;\n\nControlImage.Image myImage = new ControlImage.Image();\nmyImage.Width = 200;\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1695/" ]
61,278
<p>What method do you use when you want to get performance data about specific code paths?</p>
[ { "answer_id": 61279, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 5, "selected": true, "text": "#pragma once\n#include <tchar.h>\n#include <windows.h>\n#include <sstream>\n#include <boost/noncopyable.hpp>\n\nnamespace scope_timer {\n class time_collector : boost::noncopyable {\n __int64 total;\n LARGE_INTEGER start;\n size_t times;\n const TCHAR* name;\n\n double cpu_frequency()\n { // cache the CPU frequency, which doesn't change.\n static double ret = 0; // store as double so devision later on is floating point and not truncating\n if (ret == 0) {\n LARGE_INTEGER freq;\n QueryPerformanceFrequency(&freq);\n ret = static_cast<double>(freq.QuadPart);\n }\n return ret;\n }\n bool in_use;\n\n public:\n time_collector(const TCHAR* n)\n : times(0)\n , name(n)\n , total(0)\n , start(LARGE_INTEGER())\n , in_use(false)\n {\n }\n\n ~time_collector()\n {\n std::basic_ostringstream<TCHAR> msg;\n msg << _T(\"scope_timer> \") << name << _T(\" called: \");\n\n double seconds = total / cpu_frequency();\n double average = seconds / times;\n\n msg << times << _T(\" times total time: \") << seconds << _T(\" seconds \")\n << _T(\" (avg \") << average <<_T(\")\\n\");\n OutputDebugString(msg.str().c_str());\n }\n\n void add_time(__int64 ticks)\n {\n total += ticks;\n ++times;\n in_use = false;\n }\n\n bool aquire()\n {\n if (in_use)\n return false;\n in_use = true;\n return true;\n }\n };\n\n class one_time : boost::noncopyable {\n LARGE_INTEGER start;\n time_collector* collector;\n public:\n one_time(time_collector& tc)\n {\n if (tc.aquire()) {\n collector = &tc;\n QueryPerformanceCounter(&start);\n }\n else\n collector = 0;\n }\n\n ~one_time()\n {\n if (collector) {\n LARGE_INTEGER end;\n QueryPerformanceCounter(&end);\n collector->add_time(end.QuadPart - start.QuadPart);\n }\n }\n };\n}\n\n// Usage TIME_THIS_SCOPE(XX); where XX is a C variable name (can begin with a number)\n#define TIME_THIS_SCOPE(name) \\\n static scope_timer::time_collector st_time_collector_##name(_T(#name)); \\\n scope_timer::one_time st_one_time_##name(st_time_collector_##name)\n" }, { "answer_id": 61281, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "Timer timer = new Timer\ntimer.Start\n" }, { "answer_id": 61303, "author": "MrValdez", "author_id": 1599, "author_profile": "https://Stackoverflow.com/users/1599", "pm_score": 2, "selected": false, "text": "cProfile" }, { "answer_id": 231590, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "dumpResults()" }, { "answer_id": 231614, "author": "John Dibling", "author_id": 241536, "author_profile": "https://Stackoverflow.com/users/241536", "pm_score": 2, "selected": false, "text": "int CInsertBuffer::Read(char* pBuf)\n{\n // TIMER NOTES: Avg Execution Time = ~1 ms\n Timer timer(\"BufferRead\");\n : :\n return -1;\n}\n" }, { "answer_id": 44489926, "author": "metamorphosis", "author_id": 3454889, "author_profile": "https://Stackoverflow.com/users/3454889", "pm_score": 0, "selected": false, "text": "plf::timer t;\ntimer.start();\n\n// stuff\n\ndouble elapsed = t.get_elapsed_ns(); // Get nanoseconds\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61278", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3848/" ]
61,307
<p>I have a VB.net test application that clicks a link that opens the Microsoft Word application window and displays the document. How do I locate the Word application window so that I can grab some text from it?</p>
[ { "answer_id": 61279, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 5, "selected": true, "text": "#pragma once\n#include <tchar.h>\n#include <windows.h>\n#include <sstream>\n#include <boost/noncopyable.hpp>\n\nnamespace scope_timer {\n class time_collector : boost::noncopyable {\n __int64 total;\n LARGE_INTEGER start;\n size_t times;\n const TCHAR* name;\n\n double cpu_frequency()\n { // cache the CPU frequency, which doesn't change.\n static double ret = 0; // store as double so devision later on is floating point and not truncating\n if (ret == 0) {\n LARGE_INTEGER freq;\n QueryPerformanceFrequency(&freq);\n ret = static_cast<double>(freq.QuadPart);\n }\n return ret;\n }\n bool in_use;\n\n public:\n time_collector(const TCHAR* n)\n : times(0)\n , name(n)\n , total(0)\n , start(LARGE_INTEGER())\n , in_use(false)\n {\n }\n\n ~time_collector()\n {\n std::basic_ostringstream<TCHAR> msg;\n msg << _T(\"scope_timer> \") << name << _T(\" called: \");\n\n double seconds = total / cpu_frequency();\n double average = seconds / times;\n\n msg << times << _T(\" times total time: \") << seconds << _T(\" seconds \")\n << _T(\" (avg \") << average <<_T(\")\\n\");\n OutputDebugString(msg.str().c_str());\n }\n\n void add_time(__int64 ticks)\n {\n total += ticks;\n ++times;\n in_use = false;\n }\n\n bool aquire()\n {\n if (in_use)\n return false;\n in_use = true;\n return true;\n }\n };\n\n class one_time : boost::noncopyable {\n LARGE_INTEGER start;\n time_collector* collector;\n public:\n one_time(time_collector& tc)\n {\n if (tc.aquire()) {\n collector = &tc;\n QueryPerformanceCounter(&start);\n }\n else\n collector = 0;\n }\n\n ~one_time()\n {\n if (collector) {\n LARGE_INTEGER end;\n QueryPerformanceCounter(&end);\n collector->add_time(end.QuadPart - start.QuadPart);\n }\n }\n };\n}\n\n// Usage TIME_THIS_SCOPE(XX); where XX is a C variable name (can begin with a number)\n#define TIME_THIS_SCOPE(name) \\\n static scope_timer::time_collector st_time_collector_##name(_T(#name)); \\\n scope_timer::one_time st_one_time_##name(st_time_collector_##name)\n" }, { "answer_id": 61281, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "Timer timer = new Timer\ntimer.Start\n" }, { "answer_id": 61303, "author": "MrValdez", "author_id": 1599, "author_profile": "https://Stackoverflow.com/users/1599", "pm_score": 2, "selected": false, "text": "cProfile" }, { "answer_id": 231590, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "dumpResults()" }, { "answer_id": 231614, "author": "John Dibling", "author_id": 241536, "author_profile": "https://Stackoverflow.com/users/241536", "pm_score": 2, "selected": false, "text": "int CInsertBuffer::Read(char* pBuf)\n{\n // TIMER NOTES: Avg Execution Time = ~1 ms\n Timer timer(\"BufferRead\");\n : :\n return -1;\n}\n" }, { "answer_id": 44489926, "author": "metamorphosis", "author_id": 3454889, "author_profile": "https://Stackoverflow.com/users/3454889", "pm_score": 0, "selected": false, "text": "plf::timer t;\ntimer.start();\n\n// stuff\n\ndouble elapsed = t.get_elapsed_ns(); // Get nanoseconds\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2665/" ]
61,320
<p>SVN in Eclipse is spread into two camps. The SVN people have developed a plugin called <a href="http://subclipse.tigris.org/" rel="noreferrer">Subclipse</a>. The Eclipse people have a plugin called <a href="http://www.eclipse.org/subversive/" rel="noreferrer">Subversive</a>. Broadly speaking they both do the same things. What are the advantages and disadvantages of each?</p>
[ { "answer_id": 4215210, "author": "Rahel Lüthy", "author_id": 57448, "author_profile": "https://Stackoverflow.com/users/57448", "pm_score": 2, "selected": false, "text": "bugtraq" }, { "answer_id": 8433757, "author": "Yinch", "author_id": 1088090, "author_profile": "https://Stackoverflow.com/users/1088090", "pm_score": 2, "selected": false, "text": "Subversive" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3408/" ]
61,339
<p>I am trying to retrieve a user on Sharepoint's user photo through the WSS 3.0 object model. I have been browsing the web for solutions, but so far I've been unable to find a way to do it. Is it possible, and if so how?</p>
[ { "answer_id": 61452, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "public override void ItemAdded(SPItemEventProperties properties)\n{\n // Get list item on which the event occurred.\n SPListItem item = properties.ListItem;\n\n // Set the Author Image field to the user's PictureURL if it exists.\n using (SPWeb web = properties.OpenWeb())\n {\n // Author: {C32DB804-FF2D-4656-A38A-B0394BA5C931}\n SPFieldUserValue authorValue = new SPFieldUserValue(properties.OpenWeb(), item[new Guid(\"{C32DB804-FF2D-4656-A38A-B0394BA5C931}\")].ToString());\n\n UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(web.Site));\n UserProfile profile = profileManager.GetUserProfile(authorValue.LookupId);\n UserProfileValueCollection values = profile[PropertyConstants.PictureUrl];\n\n if (values.Count > 0)\n {\n // Author Image: {37A5CA4C-7621-44d7-BF3B-583F742CE52F}\n SPFieldUrlValue urlValue = new SPFieldUrlValue(values.Value.ToString());\n item[new Guid(\"{37A5CA4C-7621-44d7-BF3B-583F742CE52F}\")] = urlValue.Url;\n }\n }\n\n item.Update();\n\n // News Text: {7F55A8F0-4555-46BC-B24C-222240B862AF}\n //\n\n // Author Image: {37A5CA4C-7621-44d7-BF3B-583F742CE52F}\n // \n\n // Publish Date: {45E84B8B-E161-46C6-AD51-27A42E4992B5}\n //\n}\n" }, { "answer_id": 61468, "author": "Eric Schoonover", "author_id": 3957, "author_profile": "https://Stackoverflow.com/users/3957", "pm_score": 4, "selected": true, "text": " //get current profile manager\n UserProfileManager objUserProfileManager = new UserProfileManager(PortalContext.Current);\n //get current users profile\n UserProfile profile = objUserProfileManager.GetUserProfile(true);\n //get user image URL\n string imageUrl = (string)profile[PropertyConstants.PictureUrl];\n\n //do something here with imageUrl\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
61,341
<p>I remember back in the day with the old borland DOS compiler you could do something like this:</p> <pre><code>asm { mov ax,ex etc etc... } </code></pre> <p>Is there a semi-platform independent way to do this now? I have a need to make a BIOS call, so if there was a way to do this without asm code, that would be equally useful to me.</p>
[ { "answer_id": 61344, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 3, "selected": false, "text": "#include <stdio.h>\n\n\nint main() {\n /* Add 10 and 20 and store result into register %eax */\n __asm__ ( \"movl $10, %eax;\"\n \"movl $20, %ebx;\"\n \"addl %ebx, %eax;\"\n );\n\n /* Subtract 20 from 10 and store result into register %eax */\n __asm__ ( \"movl $10, %eax;\"\n \"movl $20, %ebx;\"\n \"subl %ebx, %eax;\"\n );\n\n /* Multiply 10 and 20 and store result into register %eax */\n __asm__ ( \"movl $10, %eax;\"\n \"movl $20, %ebx;\"\n \"imull %ebx, %eax;\"\n );\n\n return 0 ;\n}\n" }, { "answer_id": 61350, "author": "Niall", "author_id": 6049, "author_profile": "https://Stackoverflow.com/users/6049", "pm_score": 7, "selected": true, "text": "__asm__(\"movl %edx, %eax\\n\\t\"\n \"addl $2, %eax\\n\\t\");\n" }, { "answer_id": 61745, "author": "Martin Del Vecchio", "author_id": 5397, "author_profile": "https://Stackoverflow.com/users/5397", "pm_score": 4, "selected": false, "text": " asm (\"lock; xaddl %0,%2\" : \"=r\" (result) : \"0\" (1), \"m\" (*atom) : \"memory\");\n" }, { "answer_id": 66843327, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "asm" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6062/" ]
61,354
<p>I was just working on fixing up exception handling in a .NET 2.0 app, and I stumbled onto some weird issue with <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx" rel="nofollow noreferrer">Application.ThreadException</a>.</p> <p>What I want is to be able to catch all exceptions from events behind GUI elements (e.g. button_Click, etc.). I then want to filter these exceptions on 'fatality', e.g. with some types of Exceptions the application should keep running and with others it should exit.</p> <p>In another .NET 2.0 app I learned that, by default, only in debug mode the exceptions actually leave an Application.Run or Application.DoEvents call. In release mode this does not happen, and the exceptions have to be 'caught' using the Application.ThreadException event.</p> <p>Now, however, I noticed that <strong>the exception object passed in the ThreadExceptionEventArgs of the Application.ThreadException event is always the innermost exception in the exception chain</strong>. For logging/debugging/design purposes I really want the entire chain of exceptions though. It isn't easy to determine what external system failed for example when you just get to handle a SocketException: when it's wrapped as e.g. a NpgsqlException, then at least you know it's a database problem.</p> <p><strong>So, how to get to the entire chain of exceptions from this event?</strong> Is it even possible or do I need to design my excepion handling in another way?</p> <p>Note that I do -sort of- have a <a href="https://stackoverflow.com/questions/61366/rolling-your-own-message-loop-any-pitfalls">workaround</a> using <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setunhandledexceptionmode.aspx" rel="nofollow noreferrer">Application.SetUnhandledExceptionMode</a>, but this is far from ideal because I'd have to roll my own message loop.</p> <p>EDIT: to prevent more mistakes, <strong>the GetBaseException() method does NOT do what I want</strong>: it just returns the innermost exception, while the only thing I already have is the innermost exception. I want to get at the outermost exception!</p>
[ { "answer_id": 61647, "author": "Leo Moore", "author_id": 6336, "author_profile": "https://Stackoverflow.com/users/6336", "pm_score": -1, "selected": false, "text": " Public Overridable Function GetBaseException() As Exception\n Dim innerException As Exception = Me.InnerException\n Dim exception2 As Exception = Me\n Do While (Not innerException Is Nothing)\n exception2 = innerException\n innerException = innerException.InnerException\n Loop\n Return exception2\n End Function\n" }, { "answer_id": 308388, "author": "Vincent Van Den Berghe", "author_id": 39259, "author_profile": "https://Stackoverflow.com/users/39259", "pm_score": 1, "selected": false, "text": " Private Shared Sub Test1()\n Try\n Test2()\n Catch ex As Exception\n Application.OnThreadException(New ApplicationException(\"test1\", ex))\n End Try\n End Sub\n\n Private Shared Sub Test2()\n Try\n Test3()\n Catch ex As Exception\n Throw New ApplicationException(\"test2\", ex)\n End Try\n End Sub\n\n Private Shared Sub Test3()\n Throw New ApplicationException(\"blabla\")\n End Sub\n\nPrivate Shared Sub HandleAppException(ByVal sender As Object, ByVal e As ThreadExceptionEventArgs)\n...\nEnd Sub\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61354", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5422/" ]
61,357
<p>Should I still be using tables anyway?</p> <p>The table code I'd be replacing is:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt; &lt;/tr&gt; ... &lt;/table&gt; </code></pre> <p>From what I've been reading I should have something like</p> <pre><code>&lt;label class="name"&gt;Name&lt;/label&gt;&lt;label class="value"&gt;Value&lt;/value&gt;&lt;br /&gt; ... </code></pre> <p>Ideas and links to online samples greatly appreciated. I'm a developer way out of my design depth.</p> <p>EDIT: My need is to be able to both to display the data to a user and edit the values in a separate (but near identical) form.</p>
[ { "answer_id": 61360, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 3, "selected": false, "text": "<dl> and <dt>" }, { "answer_id": 61362, "author": "macbirdie", "author_id": 5049, "author_profile": "https://Stackoverflow.com/users/5049", "pm_score": 7, "selected": true, "text": "<dl>\n <dt>Name</dt>\n <dd>Value</dd>\n</dl>\n" }, { "answer_id": 61364, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": -1, "selected": false, "text": ".left {\n float:left;\n padding-right:20px\n}\n" }, { "answer_id": 61381, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 2, "selected": false, "text": "<form ... class=\"editing\">\n <div class=\"field\">\n <label>Label</label>\n <span class=\"edit\"><input type=\"text\" value=\"Value\" ... /></span>\n <span class=\"view\">Value</span>\n </div>\n ...\n</form>\n" }, { "answer_id": 39487947, "author": "Dónal", "author_id": 2648, "author_profile": "https://Stackoverflow.com/users/2648", "pm_score": 3, "selected": false, "text": "<dl class=\"dl-horizontal\">\n <dt>ID</dt>\n <dd>25</dd>\n <dt>Username</dt>\n <dd>Bob</dd>\n</dl>\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1122/" ]
61,366
<p>This question is slightly related to <a href="https://stackoverflow.com/questions/61354/how-to-get-entire-chain-of-exceptions-in-applicationthreadexception-event-handl">this question about exception handling</a>. The workaround I found there consists of rolling my own message loop.</p> <p>So my Main method now looks basically like this:</p> <pre><code>[STAThread] static void Main() { // this is needed so there'll actually an exception be thrown by // Application.Run/Application.DoEvents, instead of the ThreadException // event being raised. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form form = new MainForm(); form.Show(); // the loop is here to keep app running if non-fatal exception is caught. do { try { Application.DoEvents(); Thread.Sleep(100); } catch (Exception ex) { ExceptionHandler.ConsumeException(ex); } } while (!form.IsDisposed); } </code></pre> <p>What I'm wondering though, <strong>is this a safe/decent way to replace the more typical 'Application.Run(new MainForm());'</strong>, whether it's used for exception handling or for whatever else, or should I always stick to using Application.Run?</p> <p>On another app that's in testing now a similar approach is used for both loading (splashscreen) and exception handling, and I don't think it has caused any troubles (yet :-))</p>
[ { "answer_id": 61393, "author": "ima", "author_id": 5733, "author_profile": "https://Stackoverflow.com/users/5733", "pm_score": 2, "selected": false, "text": "Thread.Sleep(100);\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5422/" ]
61,372
<p>I want to write an <code>onClick</code> event which submits a form several times, iterating through selected items in a multi-select field, submitting once for each. </p> <p><strong>How do I code the loop?</strong></p> <p>I'm working in Ruby on Rails and using <code>remote_function()</code> to generate the JavaScript for the ajax call.</p>
[ { "answer_id": 61651, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 2, "selected": false, "text": "<%= javascript_include_tag 'prototype' %>\n\n<form id=\"my-form\">\n <input type=\"text\" name=\"username\" />\n\n <select multiple=\"true\" id=\"select-box\">\n <option value=\"1\">First</option>\n <option value=\"2\">Second</option>\n <option value=\"3\">Third</option>\n <option value=\"4\">Fourth</option>\n </select>\n</form>\n\n<script type=\"text/javascript\" language=\"javascript\">\nsubmitFormMultipleTimes = function() {\n $F('select-box').each(function(selectedItemValue){\n new Ajax.Request('/somewhere?val='+selectedItemValue, \n {method: 'POST', postBody: Form.serialize('my-form')});\n });\n}\n</script>\n\n<a href=\"#\" onclick=\"submitFormMultipleTimes(); return false;\">Clicky Clicky</a>\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3764/" ]
61,383
<p>My current project is in Rails. Coming from a Symfony (PHP) and Django (Python) background, they both have excellent admin generators. Seems like this is missing in Rails.</p> <p>For those who aren't familiar with Symfony or Django, they both allow you to specify some metadata around your models to automatically (dynamically) generate an admin interface to do the common CRUD operations. You can create an entire Intranet with only a few commands or lines of code. They have a good appearance and are extensible enough for 99% of your admin needs.</p> <p>I've looked for something similar for Rails, but all of the projects either have no activity or they died long ago. Is there anything to generate an intranet/admin site for a rails app other than scaffolding?</p>
[ { "answer_id": 62410, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "./script/generate scaffold_resource MyModel property:type property2:type2\n" }, { "answer_id": 17062194, "author": "Rajarshi Das", "author_id": 2463570, "author_profile": "https://Stackoverflow.com/users/2463570", "pm_score": 0, "selected": false, "text": "active_admin" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2884/" ]
61,400
<p>I'm sure most of you are writing lots of automated tests and that you also have run into some common pitfalls when unit testing. </p> <p>My question is do you follow any rules of conduct for writing tests in order to avoid problems in the future? To be more specific: What are the <strong>properties of good unit tests</strong> or how do you write your tests?</p> <p>Language agnostic suggestions are encouraged.</p>
[ { "answer_id": 61441, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 3, "selected": false, "text": "[TestFixture]\npublic class StackTests\n{\n [TestFixture]\n public class EmptyTests\n {\n Stack<int> _stack;\n\n [TestSetup]\n public void TestSetup()\n {\n _stack = new Stack<int>();\n }\n\n [TestMethod]\n [ExpectedException (typeof(Exception))]\n public void PopFails()\n {\n _stack.Pop();\n }\n\n [TestMethod]\n public void IsEmpty()\n {\n Assert(_stack.IsEmpty());\n }\n }\n\n [TestFixture]\n public class PushedOneTests\n {\n Stack<int> _stack;\n\n [TestSetup]\n public void TestSetup()\n {\n _stack = new Stack<int>();\n _stack.Push(7);\n }\n\n // Tests for one item on the stack...\n }\n}\n" }, { "answer_id": 831542, "author": "womp", "author_id": 63756, "author_profile": "https://Stackoverflow.com/users/63756", "pm_score": 5, "selected": false, "text": " - Map_DefaultConstructorShouldCreateEmptyGisMap()\n - ShouldAlwaysDelegateXMLCorrectlyToTheCustomHandlers()\n - Dog_Object_Should_Eat_Homework_Object_When_Hungry()\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3713/" ]
61,401
<p>I know this sounds like a point-whoring question but let me explain where I'm coming from.</p> <p>Out of college I got a job at a PHP shop. I worked there for a year and a half and thought that I had learned all there was to learn about programming.</p> <p>Then I got a job as a one-man internal development shop at a sizable corporation where all the work was in C#. In my commitment to the position I started reading a ton of blogs and books and quickly realized how wrong I was to think I knew everything. I learned about unit testing, dependency injection and decorator patterns, the design principle of loose coupling, the composition over inheritance debate, and so on and on and on - I am still very much absorbing it all. Needless to say my programming style has changed entirely in the last year.</p> <p>Now I find myself picking up a php project doing some coding for a friend's start-up and I feel completely constrained as opposed to programming in C#. It really bothers me that all variables at a class scope have to be referred to by appending '$this->' . It annoys me that none of the IDEs that I've tried have very good intellisense and that my SimpleTest unit tests methods have to start with the word 'test'. It drives me crazy that dynamic typing keeps me from specifying implicitly which parameter type a method expects, and that you have to write a switch statement to do method overloads. I can't stand that you can't have nested namespaces and have to use the :: operator to call the base class's constructor.</p> <p>Now I have no intention of starting a PHP vs C# debate, rather what I mean to say is that I'm sure there are some PHP features that I either don't know about or know about yet fail to use properly. I am set in my C# universe and having trouble seeing outside the glass bowl.</p> <p>So I'm asking, what are your favorite features of PHP? What are things you can do in it that you can't or are more difficult in the .Net languages?</p>
[ { "answer_id": 61403, "author": "George Mauer", "author_id": 5056, "author_profile": "https://Stackoverflow.com/users/5056", "pm_score": 4, "selected": false, "text": "function MyMethod($VarICareAbout, $VarIDontCareAbout = 'yippie') { }\n" }, { "answer_id": 61482, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 7, "selected": false, "text": "interface AllMagicMethods {\n // accessing undefined or invisible (e.g. private) properties\n public function __get($fieldName);\n public function __set($fieldName, $value);\n public function __isset($fieldName);\n public function __unset($fieldName);\n\n // calling undefined or invisible (e.g. private) methods\n public function __call($funcName, $args);\n public static function __callStatic($funcName, $args); // as of PHP 5.3\n\n // on serialize() / unserialize()\n public function __sleep();\n public function __wakeup();\n\n // conversion to string (e.g. with (string) $obj, echo $obj, strlen($obj), ...)\n public function __toString();\n\n // calling the object like a function (e.g. $obj($arg, $arg2))\n public function __invoke($arguments, $...);\n\n // called on var_export()\n public static function __set_state($array);\n}\n" }, { "answer_id": 61489, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 7, "selected": false, "text": "$fp = fopen(\"xlsfile://tmp/test.xls\", \"wb\");\nif (!is_resource($fp)) { \n die(\"Cannot open excel file\");\n}\n\n$data= array(\n array(\"Name\" => \"Bob Loblaw\", \"Age\" => 50), \n array(\"Name\" => \"Popo Jijo\", \"Age\" => 75), \n array(\"Name\" => \"Tiny Tim\", \"Age\" => 90)\n); \n\nfwrite($fp, serialize($data));\nfclose($fp);\n" }, { "answer_id": 61574, "author": "Jan Gorman", "author_id": 3196, "author_profile": "https://Stackoverflow.com/users/3196", "pm_score": 4, "selected": false, "text": "function foo ( array $param0, stdClass $param1 );\n" }, { "answer_id": 62525, "author": "Jrgns", "author_id": 6681, "author_profile": "https://Stackoverflow.com/users/6681", "pm_score": 6, "selected": false, "text": "$foo = 'bar';\n$bar = 'foobar';\necho $$foo; //This outputs foobar\n\nfunction bar() {\n echo 'Hello world!';\n}\n\nfunction foobar() {\n echo 'What a wonderful world!';\n}\n$foo(); //This outputs Hello world!\n$$foo(); //This outputs What a wonderful world!\n" }, { "answer_id": 62645, "author": "pilsetnieks", "author_id": 6615, "author_profile": "https://Stackoverflow.com/users/6615", "pm_score": 2, "selected": false, "text": "class Bar\n{\n public function __construct(array $Parameters, Bar $AnotherBar){}\n}\n" }, { "answer_id": 114001, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 6, "selected": false, "text": "extract()" }, { "answer_id": 163857, "author": "Willem", "author_id": 15447, "author_profile": "https://Stackoverflow.com/users/15447", "pm_score": 6, "selected": false, "text": "__autoload()" }, { "answer_id": 173907, "author": "e-satis", "author_id": 9951, "author_profile": "https://Stackoverflow.com/users/9951", "pm_score": 5, "selected": false, "text": "<?php $flag and print \"Blah\" ?>\n" }, { "answer_id": 255623, "author": "Dean Rather", "author_id": 14966, "author_profile": "https://Stackoverflow.com/users/14966", "pm_score": 7, "selected": false, "text": "$person = array();\n$person['name'] = 'bob';\n$person['age'] = 5;\n" }, { "answer_id": 526917, "author": "Michał Tatarynowicz", "author_id": 49564, "author_profile": "https://Stackoverflow.com/users/49564", "pm_score": 6, "selected": false, "text": "or" }, { "answer_id": 551988, "author": "Bob Fanger", "author_id": 19165, "author_profile": "https://Stackoverflow.com/users/19165", "pm_score": 4, "selected": false, "text": "if (preg_match(\"/cat/\",\"one cat\")) {\n // do something\n}\n" }, { "answer_id": 665660, "author": "Jamol", "author_id": 66611, "author_profile": "https://Stackoverflow.com/users/66611", "pm_score": 5, "selected": false, "text": "function myFunc($param1, $param2 = MY_CONST)\n{\n//code...\n}\n" }, { "answer_id": 794461, "author": "Luc M", "author_id": 14673, "author_profile": "https://Stackoverflow.com/users/14673", "pm_score": 3, "selected": false, "text": "$my_array = array();\n$my_array[] = 'first element';\n$my_array[] = 'second element';\n" }, { "answer_id": 810635, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "class style\n{\n ....\n function set_bg_colour($c)\n {\n $this->{'background-color'} = $c;\n }\n}\n" }, { "answer_id": 886384, "author": "zombat", "author_id": 81205, "author_profile": "https://Stackoverflow.com/users/81205", "pm_score": 6, "selected": false, "text": "$fp = fopen('http://example.com');\n" }, { "answer_id": 1023029, "author": "Sam152", "author_id": 59730, "author_profile": "https://Stackoverflow.com/users/59730", "pm_score": 5, "selected": false, "text": "/*\n die('You shall not pass!');\n//*/\n\n\n//*\n die('You shall not pass!');\n//*/\n" }, { "answer_id": 1024891, "author": "dcousineau", "author_id": 20265, "author_profile": "https://Stackoverflow.com/users/20265", "pm_score": 5, "selected": false, "text": "static" }, { "answer_id": 1024914, "author": "MSpreij", "author_id": 126584, "author_profile": "https://Stackoverflow.com/users/126584", "pm_score": 5, "selected": false, "text": "// swap values. any number of vars works, obviously \nlist($a, $b) = array($b, $a);\n\n// nested list() calls \"fill\" variables from multidim arrays: \n$arr = array( \n array('aaaa', 'bbb'), \n array('cc', 'd') \n); \nlist(list($a, $b), list($c, $d)) = $arr; \necho \"$a $b $c $d\"; // -> aaaa bbb cc d \n\n// list() values to arrays \nwhile (list($arr1[], $arr2[], $arr3[]) = mysql_fetch_row($res)) { .. } \n// or get columns from a matrix \nforeach($data as $row) list($col_1[], $col_2[], $col_3[]) = $row;\n\n// abusing the ternary operator to set other variables as a side effect: \n$foo = $condition ? 'Yes' . (($bar = 'right') && false) : 'No' . (($bar = 'left') && false); \n// boolean False cast to string for concatenation becomes an empty string ''. \n// you can also use list() but that's so boring ;-) \nlist($foo, $bar) = $condition ? array('Yes', 'right') : array('No', 'left');\n" }, { "answer_id": 1025143, "author": "staticsan", "author_id": 28832, "author_profile": "https://Stackoverflow.com/users/28832", "pm_score": 5, "selected": false, "text": "array_merge()" }, { "answer_id": 1025183, "author": "noripcord", "author_id": 84824, "author_profile": "https://Stackoverflow.com/users/84824", "pm_score": 0, "selected": false, "text": "//file page_specific_funcs.inc\n\nfunction doOtherThing(){\n\n}\n\nclass MyClass{\n\n}\n\n//end file\n\n//file.php\n\nfunction doSomething(){\n include(\"page_specific_funcs.inc\");\n\n $var = new MyClass(); \n\n}\n//end of file.php\n" }, { "answer_id": 1025634, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "$var = ($_POST['my_checkbox']=='checked') ? TRUE : FALSE;\n" }, { "answer_id": 1026758, "author": "Darren Newton", "author_id": 12799, "author_profile": "https://Stackoverflow.com/users/12799", "pm_score": 6, "selected": false, "text": "for ($i=0; $i < $x; $i++) { \n // code...\n}\n" }, { "answer_id": 1027553, "author": "aviv", "author_id": 112601, "author_profile": "https://Stackoverflow.com/users/112601", "pm_score": -1, "selected": false, "text": "function getInt(int $v)\n{\n echo $v;\n}\n\ngetInt(5); // will work\ngetInt('hello'); // will fail\n" }, { "answer_id": 1027577, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "Class Connection {\n private $dsn;\n private $connection;\n ...\n public __wakeup() {\n $this->connection = ADONewConnection();\n }\n}\n" }, { "answer_id": 1027828, "author": "Eric", "author_id": 119301, "author_profile": "https://Stackoverflow.com/users/119301", "pm_score": 4, "selected": false, "text": "serialize" }, { "answer_id": 1029100, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "echo <<<EOM\n <div id=\"someblock\">\n <img src=\"{$file}\" />\n </div>\nEOM;\n" }, { "answer_id": 1029114, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "$foo = 'Bob';\necho 'My name is {$foo}'; // Doesn't swap the variable\necho \"My name is {$foo}\"; // Swaps the variable\n" }, { "answer_id": 1029599, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "$obj = new ArrayObject(array(\"name\"=>\"bob\", \"email\"=>\"bob@example.com\"),2);\n$obj->fullname = \"Bob Example\";\necho $obj[\"fullname\"];\n$obj[\"fullname\"]=\"Bobby Example\";\necho $obj->fullname;\n" }, { "answer_id": 1061640, "author": "Shane H", "author_id": 60247, "author_profile": "https://Stackoverflow.com/users/60247", "pm_score": 4, "selected": false, "text": "function twiterize($text) {\n // Replace @somename with the full twitter handle\n return preg_replace(\"(\\s+)@(\\w)+(\\s+)\", \"http://www.twitter.com/${2}\", $text);\n}\n\nob_start(twiterize);\n" }, { "answer_id": 1092743, "author": "Daan", "author_id": 7922, "author_profile": "https://Stackoverflow.com/users/7922", "pm_score": 2, "selected": false, "text": "if" }, { "answer_id": 1103508, "author": "TheBrain", "author_id": 130341, "author_profile": "https://Stackoverflow.com/users/130341", "pm_score": 6, "selected": false, "text": "func_get_args()" }, { "answer_id": 1141481, "author": "RaYell", "author_id": 137467, "author_profile": "https://Stackoverflow.com/users/137467", "pm_score": 3, "selected": false, "text": "$newVar = $ar['foo']['bar'];\necho \"Array value is $newVar\";\n\n$newVar = $obj->foo->bar;\necho \"Object value is $newVar\";\n" }, { "answer_id": 1173586, "author": "dburke", "author_id": 72656, "author_profile": "https://Stackoverflow.com/users/72656", "pm_score": 2, "selected": false, "text": "php -a" }, { "answer_id": 1241052, "author": "Philippe Gerber", "author_id": 117260, "author_profile": "https://Stackoverflow.com/users/117260", "pm_score": 7, "selected": false, "text": "// config.php\nreturn array(\n 'db' => array(\n 'host' => 'example.org',\n 'user' => 'usr',\n // ...\n ),\n // ...\n);\n\n// index.php\n$config = include 'config.php';\necho $config['db']['host']; // example.org\n" }, { "answer_id": 1416447, "author": "Kzqai", "author_id": 69993, "author_profile": "https://Stackoverflow.com/users/69993", "pm_score": 1, "selected": false, "text": "function render_title($title){\n return \"<title>$title</title\";\n}\n" }, { "answer_id": 1548737, "author": "Alex L", "author_id": 114446, "author_profile": "https://Stackoverflow.com/users/114446", "pm_score": 3, "selected": false, "text": "$classInfo = new ReflectionClass ('MyClass');\nif ($classInfo->hasMethod($methodName)) \n{\n $cm = $classInfo->getMethod($name); \n $methodResult = $cm->invoke(null);\n}\n" }, { "answer_id": 1697712, "author": "Frank Koehl", "author_id": 38358, "author_profile": "https://Stackoverflow.com/users/38358", "pm_score": 3, "selected": false, "text": "#!/usr/bin/php5\n<?php\n// start coding here\n" }, { "answer_id": 2032550, "author": "Axel Gneiting", "author_id": 5876, "author_profile": "https://Stackoverflow.com/users/5876", "pm_score": 2, "selected": false, "text": "ArrayAccess" }, { "answer_id": 2161431, "author": "Talvi Watia", "author_id": 215170, "author_profile": "https://Stackoverflow.com/users/215170", "pm_score": 1, "selected": false, "text": "<?\n// file unit1.php\n$this_code='does something.';\n?>\n\n<?\n// file unit2.php\n$this_code='does something else. it could be a PHP class object!';\n?>\n\n<?\n// file unit3.php\n$this_code='does something else. it could be your master include file';\nrequire_once('unit2.php');\ninclude('unit1.php');\n?>\n\n<?\n// file main.php\ninclude('unit1.php');\nrequire_once('unit2.php');\nrequire_once('unit3.php');\n?>\n" }, { "answer_id": 3089775, "author": "bob-the-destroyer", "author_id": 352583, "author_profile": "https://Stackoverflow.com/users/352583", "pm_score": 3, "selected": false, "text": "included" }, { "answer_id": 3111088, "author": "manixrock", "author_id": 93691, "author_profile": "https://Stackoverflow.com/users/93691", "pm_score": 4, "selected": false, "text": "break N;" }, { "answer_id": 3135918, "author": "fixo2020 ", "author_id": 347194, "author_profile": "https://Stackoverflow.com/users/347194", "pm_score": -1, "selected": false, "text": "$check = \"HELLO\";\n\nswitch ($check) {\n case (eregi('HI', $check)):\n echo \"Write HI!\";\n case (eregi('HELLO', $check)):\n echo \"Write HELLO!\";\n case (eregi('OTHER', $check)):\n echo \"Write OTHER!\";\n}\n" }, { "answer_id": 3136088, "author": "Codler", "author_id": 304894, "author_profile": "https://Stackoverflow.com/users/304894", "pm_score": 2, "selected": false, "text": "function sort_by_field($field, & $data) {\n $sort_func = create_function('$a,$b', 'if ($a[\"' . $field . '\"] == $b[\"' . $field . '\"]) {return 0;} \n return ($a[\"' . $field . '\"] < $b[\"' . $field . '\"]) ? -1 : 1;');\n\n uasort($data, $sort_func);\n}\n" }, { "answer_id": 3136831, "author": "Xeoncross", "author_id": 99923, "author_profile": "https://Stackoverflow.com/users/99923", "pm_score": 3, "selected": false, "text": "<?php\n\nTRUE AND print 'Hello';\nFALSE OR print 'World';\n\n// Prints \"Hello World\";\n\n// Complex example...\nUser::logged_in() or die('Not allowed');\nUser::is_admin() AND print 'Admin Area';\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
61,405
<p>I'm about to start on a large Qt application, which is made up of smaller components (groups of classes that work together). For example, there might be a dialog that is used in the project, but should be developed on its own before being integrated into the project. Instead of working on it in another folder somewhere and then copying it into the main project folder, can I create a sub-folder which is dedicated to that dialog, and then somehow incorporate it into the main project?</p>
[ { "answer_id": 62009, "author": "Jérôme", "author_id": 2796, "author_profile": "https://Stackoverflow.com/users/2796", "pm_score": 6, "selected": true, "text": "/MyWholeApp\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1585/" ]
61,418
<p>I have a function that gives me the following warning:</p> <blockquote> <p>[DCC Warning] filename.pas(6939): W1035 Return value of function 'function' might be undefined</p> </blockquote> <p>The function, however, is clean, small, and does have a known, expected, return value. The first statement in the function is:</p> <pre><code>Result := ''; </code></pre> <p>and there is no local variable or parameter called <code>Result</code> either.</p> <p>Is there any kind of pragma-like directive I can surround this method with to remove this warning? This is Delphi 2007.</p> <p>Unfortunately, the help system on this Delphi installation is not working, therefore i can't pop up the help for that warning right now.</p> <p>Anyone know off the top of their head what i can do?</p>
[ { "answer_id": 61426, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 4, "selected": true, "text": "{$WARN NO_RETVAL OFF}\nfunction func(...): string;\nbegin\n ...\nend;\n{$WARN NO_RETVAL ON}\n" }, { "answer_id": 2906623, "author": "Abelevich", "author_id": 11391, "author_profile": "https://Stackoverflow.com/users/11391", "pm_score": 1, "selected": false, "text": "program TestCompilerProblems;\n\nprocedure Proc;\nvar\n a01, a02, a03, a04, a05, a06, a07, a08, a09, a10,\n a11, a12, a13, a14, a15, a16, a17, a18, a19, a20,\n a21, a22, a23, a24, a25, a26, a27, a28, a29, a30,\n a31, a32, a33, a34, a35, a36, a37, a38, a39, a40: Integer;\nbegin\nend;\n\nbegin\n Proc;\nend.\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/267/" ]
61,421
<p>I'm making an example for someone who hasn't yet realized that controls like <code>ListBox</code> don't have to contain strings; he had been storing formatted strings and jumping through complicated parsing hoops to get the data back out of the <code>ListBox</code> and I'd like to show him there's a better way.</p> <p>I noticed that if I have an object stored in the <code>ListBox</code> then update a value that affects <code>ToString</code>, the <code>ListBox</code> does not update itself. I've tried calling <code>Refresh</code> and <code>Update</code> on the control, but neither works. Here's the code of the example I'm using, it requires you to drag a listbox and a button onto the form:</p> <pre><code>Public Class Form1 Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) For i As Integer = 1 To 3 Dim tempInfo As New NumberInfo() tempInfo.Count = i tempInfo.Number = i * 100 ListBox1.Items.Add(tempInfo) Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each objItem As Object In ListBox1.Items Dim info As NumberInfo = DirectCast(objItem, NumberInfo) info.Count += 1 Next End Sub End Class Public Class NumberInfo Public Count As Integer Public Number As Integer Public Overrides Function ToString() As String Return String.Format("{0}, {1}", Count, Number) End Function End Class</code></pre> <p>I thought that perhaps the problem was using fields and tried implementing <em>INotifyPropertyChanged</em>, but this had no effect. (The reason I'm using fields is because it's an example and I don't feel like adding a few dozen lines that have nothing to do with the topic I'm demonstrating.)</p> <p>Honestly I've never tried updating items in place like this before; in the past I've always been adding/removing items, not editing them. So I've never noticed that I don't know how to make this work.</p> <p>So what am I missing?</p>
[ { "answer_id": 61425, "author": "Quibblesome", "author_id": 1143, "author_profile": "https://Stackoverflow.com/users/1143", "pm_score": 3, "selected": false, "text": "Public Class Form1\n\n Private datasource As New List(Of NumberInfo)\n Private bindingSource As New BindingSource\n\n Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)\n MyBase.OnLoad(e)\n\n For i As Integer = 1 To 3\n Dim tempInfo As New NumberInfo()\n tempInfo.Count = i\n tempInfo.Number = i * 100\n datasource.Add(tempInfo)\n Next\n bindingSource.DataSource = datasource\n ListBox1.DataSource = bindingSource\n End Sub\n\n Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\n For Each objItem As Object In datasource\n Dim info As NumberInfo = DirectCast(objItem, NumberInfo)\n info.Count += 1\n Next\n bindingSource.ResetBindings(False)\n End Sub\nEnd Class\n\nPublic Class NumberInfo\n\n Public Count As Integer\n Public Number As Integer\n\n Public Overrides Function ToString() As String\n Return String.Format(\"{0}, {1}\", Count, Number)\n End Function\nEnd Class\n" }, { "answer_id": 61463, "author": "zeemz", "author_id": 6351, "author_profile": "https://Stackoverflow.com/users/6351", "pm_score": -1, "selected": false, "text": "listbox.bind()" }, { "answer_id": 61711, "author": "Ant", "author_id": 3709, "author_profile": "https://Stackoverflow.com/users/3709", "pm_score": 2, "selected": false, "text": "public class ListBox2 : ListBox {\n public void RefreshItem2(int index) {\n RefreshItem(index);\n }\n}\n" }, { "answer_id": 61719, "author": "Brad Bruce", "author_id": 5008, "author_profile": "https://Stackoverflow.com/users/5008", "pm_score": 5, "selected": false, "text": "public class RefreshingListBox : ListBox\n{\n public new void RefreshItem(int index)\n {\n base.RefreshItem(index);\n }\n\n public new void RefreshItems()\n {\n base.RefreshItems();\n }\n}\n" }, { "answer_id": 930356, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "if (objLstTypes.SelectedItem != null)\n{\n PublisherTypeDescriptor objType = (PublisherTypeDescriptor)objLstTypes.SelectedItem;\n objLstTypes.Items.Remove(objType);\n objLstTypes.Items.Add(objType);\n objLstTypes.SelectedItem = objType;\n}\n" }, { "answer_id": 2135255, "author": "geno", "author_id": 258739, "author_profile": "https://Stackoverflow.com/users/258739", "pm_score": 6, "selected": true, "text": "using System;\nusing System.ComponentModel;\nusing System.Windows.Forms;\n\nnamespace TestBindingList\n{\n public class Employee\n {\n public string Name { get; set; }\n public int Id { get; set; }\n }\n\n public partial class Form1 : Form\n {\n private BindingList<Employee> _employees;\n\n private ListBox lstEmployees;\n private TextBox txtId;\n private TextBox txtName;\n private Button btnRemove;\n\n public Form1()\n {\n InitializeComponent();\n\n FlowLayoutPanel layout = new FlowLayoutPanel();\n layout.Dock = DockStyle.Fill;\n Controls.Add(layout);\n\n lstEmployees = new ListBox();\n layout.Controls.Add(lstEmployees);\n\n txtId = new TextBox();\n layout.Controls.Add(txtId);\n\n txtName = new TextBox();\n layout.Controls.Add(txtName);\n\n btnRemove = new Button();\n btnRemove.Click += btnRemove_Click;\n btnRemove.Text = \"Remove\";\n layout.Controls.Add(btnRemove);\n\n Load+=new EventHandler(Form1_Load);\n }\n\n private void Form1_Load(object sender, EventArgs e)\n {\n _employees = new BindingList<Employee>();\n for (int i = 0; i < 10; i++)\n {\n _employees.Add(new Employee() { Id = i, Name = \"Employee \" + i.ToString() }); \n }\n\n lstEmployees.DisplayMember = \"Name\";\n lstEmployees.DataSource = _employees;\n\n txtId.DataBindings.Add(\"Text\", _employees, \"Id\");\n txtName.DataBindings.Add(\"Text\", _employees, \"Name\");\n }\n\n private void btnRemove_Click(object sender, EventArgs e)\n {\n Employee selectedEmployee = (Employee)lstEmployees.SelectedItem;\n if (selectedEmployee != null)\n {\n _employees.Remove(selectedEmployee);\n }\n }\n }\n}\n" }, { "answer_id": 4285934, "author": "Elton M", "author_id": 521450, "author_profile": "https://Stackoverflow.com/users/521450", "pm_score": 5, "selected": false, "text": "lstBox.Items[lstBox.SelectedIndex] = lstBox.SelectedItem;\n" }, { "answer_id": 4631419, "author": "Jon", "author_id": 567625, "author_profile": "https://Stackoverflow.com/users/567625", "pm_score": 4, "selected": false, "text": "typeof(ListBox).InvokeMember(\"RefreshItems\", \n BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,\n null, myListBox, new object[] { });\n" }, { "answer_id": 29008084, "author": "JTIM", "author_id": 2076775, "author_profile": "https://Stackoverflow.com/users/2076775", "pm_score": 0, "selected": false, "text": "private void listBox1_DrawItem(object sender, DrawItemEventArgs e)\n{\n e.DrawBackground();\n e.DrawFocusRectangle();\n\n Sensor toBeDrawn = (listBox1.Items[e.Index] as Sensor);\n e.Graphics.FillRectangle(new SolidBrush(toBeDrawn.ItemColor), e.Bounds);\n e.Graphics.DrawString(toBeDrawn.sensorName, new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold), new SolidBrush(Color.White),e.Bounds);\n}\n" }, { "answer_id": 71672910, "author": "Daniel Lidström", "author_id": 286406, "author_profile": "https://Stackoverflow.com/users/286406", "pm_score": 0, "selected": false, "text": "private void CheckBox_Click(object sender, EventArgs e)\n{\n // some kind of hack to make the ListBox refresh\n int currentPosition = bindingSource.Position;\n bindingSource.Position += 1;\n bindingSource.Position -= 1;\n bindingSource.Position = currentPosition;\n}\n" }, { "answer_id": 71919054, "author": "John G", "author_id": 12492467, "author_profile": "https://Stackoverflow.com/users/12492467", "pm_score": 0, "selected": false, "text": "Dim i = LstBox.SelectedIndex\nLstBox.Items(i) = anObject\nLstBox.Sorted = True\n" }, { "answer_id": 72072608, "author": "purple_2022", "author_id": 13008103, "author_profile": "https://Stackoverflow.com/users/13008103", "pm_score": 0, "selected": false, "text": "Public Class Form1\n\nDim tempInfo As New NumberInfo()\n\nPrivate Sub Form1_Load() Handles Me.Load\n For i As Integer = 1 To 3\n tempInfo.Count = i\n tempInfo.Number = i * 100\n ListBox1.Items.Add(tempInfo)\n Next\nEnd Sub\n\nPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\n Dim info As NumberInfo = tempInfo\n Dim obj As New Object\n info.Count += 1\n info.Number = info.Count * 100\n obj = info\n ListBox1.Items.Add(obj)\n ListBox1.Items.RemoveAt(0)\nEnd Sub\nEnd Class\n\nPublic Class NumberInfo\nPublic Count As Integer\nPublic Number As Integer\n Public Overrides Function ToString() As String\n Return String.Format(\"{0}, {1}\", Count, Number)\n End Function\nEnd Class\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2547/" ]
61,443
<p>I have a counter in hardware that I can observe for timing considerations. It counts miliseconds and is stored in a 16 bit unsigned value. How do I safely check if a timer value has passed a certain time and safely handle the inevitable rollover:</p> <pre><code>//this is a bit contrived, but it illustrates what I'm trying to do const uint16_t print_interval = 5000; // milliseconds static uint16_t last_print_time; if(ms_timer() - last_print_time &gt; print_interval) { printf("Fault!\n"); last_print_time = ms_timer(); } </code></pre> <p>This code will fail when ms_timer overflows to 0.</p>
[ { "answer_id": 61461, "author": "ReaperUnreal", "author_id": 4218, "author_profile": "https://Stackoverflow.com/users/4218", "pm_score": 1, "selected": false, "text": "const int32 print_interval = 5000;\nstatic int32 last_print_time; // I'm assuming this gets initialized elsewhere\n\nint32 delta = ((int32)ms_timer()) - last_print_time; //allow a negative interval\nwhile(delta < 0) delta += 65536; // move the difference back into range\nif(delta < print_interval)\n{\n printf(\"Fault!\\n\");\n last_print_time = ms_timer();\n}\n" }, { "answer_id": 61466, "author": "JeffV", "author_id": 445087, "author_profile": "https://Stackoverflow.com/users/445087", "pm_score": 1, "selected": false, "text": "const uint16_t print_interval = 5000; // milliseconds\nstatic uint16_t last_print_time; \n\nint next_print_time = (last_print_time + print_interval);\n\nif((int16_t) (x - next_print_time) >= 0)\n{\n printf(\"Fault!\\n\");\n last_print_time = x;\n}\n" }, { "answer_id": 61572, "author": "smh", "author_id": 1077, "author_profile": "https://Stackoverflow.com/users/1077", "pm_score": 4, "selected": false, "text": "ms_timer()" }, { "answer_id": 164182, "author": "Steve Karg", "author_id": 9016, "author_profile": "https://Stackoverflow.com/users/9016", "pm_score": 0, "selected": false, "text": "void timer_milliseconds_reset(unsigned index);\nbool timer_milliseconds_elapsed(unsigned index, unsigned long value);\n" }, { "answer_id": 2976575, "author": "bobc", "author_id": 358705, "author_profile": "https://Stackoverflow.com/users/358705", "pm_score": 2, "selected": false, "text": "/* ========================================================================== */\n/* timers.c */\n/* */\n/* Description: Demonstrate unsigned vs signed timers */\n/* ========================================================================== */\n\n#include <stdio.h>\n#include <limits.h>\n\nint timer;\n\nint HW_DIGCTL_MICROSECONDS_RD()\n{\n printf (\"timer %x\\n\", timer);\n return timer++;\n}\n\n// delay up to UINT_MAX\n// this fails when start near UINT_MAX\nvoid delay_us (unsigned int us)\n{\n unsigned int start = HW_DIGCTL_MICROSECONDS_RD();\n\n while (start + us > HW_DIGCTL_MICROSECONDS_RD()) \n ;\n}\n\n// works correctly for delay from 0 to INT_MAX\nvoid sdelay_us (int us)\n{\n int start = HW_DIGCTL_MICROSECONDS_RD();\n\n while (HW_DIGCTL_MICROSECONDS_RD() - start < us) \n ;\n}\n\nint main()\n{\n printf (\"UINT_MAX = %x\\n\", UINT_MAX);\n printf (\"INT_MAX = %x\\n\\n\", INT_MAX);\n\n printf (\"unsigned, no wrap\\n\\n\");\n timer = 0;\n delay_us (10);\n\n printf (\"\\nunsigned, wrap\\n\\n\");\n timer = UINT_MAX - 8;\n delay_us (10);\n\n printf (\"\\nsigned, no wrap\\n\\n\");\n timer = 0;\n sdelay_us (10);\n\n printf (\"\\nsigned, wrap\\n\\n\");\n timer = INT_MAX - 8;\n sdelay_us (10);\n\n}\n" }, { "answer_id": 11911902, "author": "Jeff", "author_id": 877375, "author_profile": "https://Stackoverflow.com/users/877375", "pm_score": -1, "selected": false, "text": "#define LIMIT 10 // Any value less then ULONG_MAX\nulong t1 = tick of last event;\nulong t2 = current tick;\n\n// This code needs to execute every tick\nif ( t1 > t2 ){\n if ((ULONG_MAX-t1+t2+1)>=LIMIT){\n do something\n }\n} else {\nif ( t2 - t1 >= LIMT ){\n do something\n}\n" }, { "answer_id": 45852411, "author": "Hill", "author_id": 3239341, "author_profile": "https://Stackoverflow.com/users/3239341", "pm_score": 2, "selected": false, "text": "uint32_t" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445087/" ]
61,446
<p>Particularly, what is the best snippets package out there?</p> <p>Features:</p> <ul> <li>easy to define new snippets (plain text, custom input with defaults)</li> <li>simple navigation between predefined positions in the snippet</li> <li>multiple insertion of the same custom input</li> <li>accepts currently selected text as a custom input</li> <li><em>cross-platform</em> (Windows, Linux)</li> <li>dynamically evaluated expressions (embedded code) written in a concise programming language (Perl, Python, Ruby are preferred)</li> <li>nicely coexists with others packages in Emacs</li> </ul> <p>Example of code template, a simple <code>for</code> loop in C:</p> <pre><code>for (int i = 0; i &lt; %N%; ++i) { _ } </code></pre> <p>It is a lot of typing for such common code. I want to invoke a code template or snippet which inserts that boilerplate code for me. Additionally it stops (on TAB or other keystroke) at <code>%N%</code> (my input replaces it) and final position of the cursor is <code>_</code>. </p>
[ { "answer_id": 61447, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 6, "selected": true, "text": "hippie-expand" }, { "answer_id": 18829042, "author": "gavenkoa", "author_id": 173149, "author_profile": "https://Stackoverflow.com/users/173149", "pm_score": 2, "selected": false, "text": "Semantic" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61446", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4279/" ]
61,449
<p>I've just created a new Windows XP VM on my Mac using VMware Fusion. The VM is using NAT to share the host's internet connection.</p> <p>How do I access a Rails application, which is accessible on the Mac itself using <code>http://localhost:3000</code>?</p>
[ { "answer_id": 61455, "author": "JW.", "author_id": 4321, "author_profile": "https://Stackoverflow.com/users/4321", "pm_score": 8, "selected": true, "text": "ipconfig" }, { "answer_id": 191707, "author": "Richard Poirier", "author_id": 26842, "author_profile": "https://Stackoverflow.com/users/26842", "pm_score": 3, "selected": false, "text": "<gateway-ip" }, { "answer_id": 2094910, "author": "J. Perkins", "author_id": 93921, "author_profile": "https://Stackoverflow.com/users/93921", "pm_score": 4, "selected": false, "text": "192.168.78.1 myrubyapp\n" }, { "answer_id": 6688618, "author": "Jess Telford", "author_id": 473961, "author_profile": "https://Stackoverflow.com/users/473961", "pm_score": 3, "selected": false, "text": "[default-gateway-IP] www.example.com\n[default-gateway-IP] example.com\n" }, { "answer_id": 9828343, "author": "Dennis Plucinik", "author_id": 184302, "author_profile": "https://Stackoverflow.com/users/184302", "pm_score": 3, "selected": false, "text": "<gateway-ip> yourserver.local" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1450/" ]
61,451
<p>Does Django have any template tags to generate common HTML markup? For example, I know that I can get a url using</p> <pre><code>{% url mapper.views.foo %} </code></pre> <p>But that only gives me the URL and not the HTML code to create the link. Does Django have anything similar to Rails' link_to helper? I found <a href="http://code.google.com/p/django-helpers/" rel="noreferrer">django-helpers</a> but since this is a common thing I thought Django would have something built-in.</p>
[ { "answer_id": 71598, "author": "Ali", "author_id": 11895, "author_profile": "https://Stackoverflow.com/users/11895", "pm_score": -1, "selected": false, "text": "<a href=\"{% url mapper.views.foo %}\">foo</a>" }, { "answer_id": 82175, "author": "zgoda", "author_id": 12138, "author_profile": "https://Stackoverflow.com/users/12138", "pm_score": 0, "selected": false, "text": "p" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/796/" ]
61,456
<p>After trying to avoid JavaScript for years, Iv started using Query for <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow noreferrer">validation</a> in MVC asp.net, as there does not seem to be an official way of doing validation, Iv been surprised how good jQuery is. </p> <p>Firstly is there a way to get intellisense working for jQuery and its validation plugin, so that i don have to learn the api?</p> <p>Secondly how do I create a validation summary for this, it currently appends the error to the right of the text box.:</p> <pre><code>&lt;script type="text/javascript"&gt; $().ready(function() { $("#CreateLog").validate({ rules: { UserName: { required: true, minLength: 2, } }, messages: { UserName: { required: "Please enter a username", minLength: "Your username must consist of at least 2 characters", } } }); }); &lt;/script&gt; &lt;form id="CreateLog" action="Create" method="post" /&gt; &lt;label&gt;UserName&lt;/label&gt;&lt;br /&gt; &lt;%=Html.TextBox("UserName")%&gt; &lt;br /&gt; &lt;div class="error"&gt; &lt;/div&gt; &lt;input type=submit value=Save /&gt; &lt;/form&gt; </code></pre> <p>I tried adding this to the script:</p> <pre><code> errorLabelContainer: $("#CreateLog div.error") </code></pre> <p>and this to the html:</p> <pre><code> &lt;div class="error"&gt; &lt;/div&gt; </code></pre> <p>But this didn't work.</p>
[ { "answer_id": 66527, "author": "Dane O'Connor", "author_id": 1946, "author_profile": "https://Stackoverflow.com/users/1946", "pm_score": 5, "selected": true, "text": "display:none;" }, { "answer_id": 298664, "author": "Tomas Aschan", "author_id": 38055, "author_profile": "https://Stackoverflow.com/users/38055", "pm_score": 1, "selected": false, "text": "/// <reference path=\"[insert path to script file here]\" />\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/230/" ]
61,480
<p>In the past we declared properties like this:</p> <pre><code>public class MyClass { private int _age; public int Age { get{ return _age; } set{ _age = value; } } } </code></pre> <p>Now we can do:</p> <pre><code>public class MyClass { public int Age {get; set;} } </code></pre> <p>My question is, how can I access the private variable that is created automatically using this notation? </p> <p>I would rather access the private variable and not the public accessor 'Age'. Is there a default notation to access the private variable, or it is just not possible?</p>
[ { "answer_id": 61493, "author": "Scott Dorman", "author_id": 1559, "author_profile": "https://Stackoverflow.com/users/1559", "pm_score": 4, "selected": false, "text": "[CompilerGenerated]\nprivate int <Age>k_BackingField;\n\npublic int Age\n{\n [CompilerGenerated]\n get\n {\n return this.<Age>k_BackingField;\n }\n [CompilerGenerated]\n set\n {\n this.<Age>k_BackingField = value;\n }\n" }, { "answer_id": 61494, "author": "chakrit", "author_id": 3055, "author_profile": "https://Stackoverflow.com/users/3055", "pm_score": 5, "selected": false, "text": "private int _age" }, { "answer_id": 61503, "author": "Wilka", "author_id": 1367, "author_profile": "https://Stackoverflow.com/users/1367", "pm_score": 7, "selected": false, "text": "public class MyClass\n{\n public int Age {get; private set;} \n}" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1368/" ]
61,486
<p>I need to figure out what div is visible out of four possible divs using jQuery. Only one of those div's will be visible at any given time.</p> <p>This is what I have that works so far:</p> <pre><code>$("#FeatureImage1:visible, #FeatureImage2:visible, #FeatureImage3:visible, #FeatureImage4:visible").attr("id"); </code></pre> <p>Is there a way to refactor this? Is there an easier way to figure this out?</p>
[ { "answer_id": 61500, "author": "Gilean", "author_id": 6305, "author_profile": "https://Stackoverflow.com/users/6305", "pm_score": 5, "selected": true, "text": "$(\"div.myClass:visible\").attr(\"id\");\n" }, { "answer_id": 64390, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 1, "selected": false, "text": "<div>" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/648/" ]
61,517
<p>Do you know if there is a built-in function to build a dictionary from an arbitrary object? I'd like to do something like this:</p> <pre><code>&gt;&gt;&gt; class Foo: ... bar = 'hello' ... baz = 'world' ... &gt;&gt;&gt; f = Foo() &gt;&gt;&gt; props(f) { 'bar' : 'hello', 'baz' : 'world' } </code></pre> <p><strong>NOTE:</strong> It should not include methods. Only fields.</p>
[ { "answer_id": 61522, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 6, "selected": false, "text": "dir" }, { "answer_id": 61551, "author": "Julio César", "author_id": 2148, "author_profile": "https://Stackoverflow.com/users/2148", "pm_score": 5, "selected": false, "text": "dict((key, value) for key, value in f.__dict__.iteritems() \n if not callable(value) and not key.startswith('__'))\n" }, { "answer_id": 62680, "author": "user6868", "author_id": 6868, "author_profile": "https://Stackoverflow.com/users/6868", "pm_score": 10, "selected": true, "text": "class Foo(object):\n ...\n" }, { "answer_id": 63635, "author": "indentation", "author_id": 7706, "author_profile": "https://Stackoverflow.com/users/7706", "pm_score": 4, "selected": false, "text": "__dict__" }, { "answer_id": 17470565, "author": "Score_Under", "author_id": 1091693, "author_profile": "https://Stackoverflow.com/users/1091693", "pm_score": 3, "selected": false, "text": "def props(x):\n return dict((key, getattr(x, key)) for key in dir(x) if key not in dir(x.__class__))\n" }, { "answer_id": 23937693, "author": "radtek", "author_id": 2023392, "author_profile": "https://Stackoverflow.com/users/2023392", "pm_score": 3, "selected": false, "text": "class A(object):\n def __init__(self):\n self.b = 1\n self.c = 2\n def __getitem__(self, item):\n return self.__dict__[item]\n\n# Usage: \na = A()\na.__getitem__('b') # Outputs 1\na.__dict__ # Outputs {'c': 2, 'b': 1}\nvars(a) # Outputs {'c': 2, 'b': 1}\n" }, { "answer_id": 29333136, "author": "Seaux", "author_id": 263175, "author_profile": "https://Stackoverflow.com/users/263175", "pm_score": 5, "selected": false, "text": "dict(obj)" }, { "answer_id": 31770231, "author": "Berislav Lopac", "author_id": 122033, "author_profile": "https://Stackoverflow.com/users/122033", "pm_score": 8, "selected": false, "text": "x.__dict__" }, { "answer_id": 34662287, "author": "coanor", "author_id": 342348, "author_profile": "https://Stackoverflow.com/users/342348", "pm_score": 1, "selected": false, "text": "__dict__" }, { "answer_id": 48696573, "author": "spattanaik75", "author_id": 3094089, "author_profile": "https://Stackoverflow.com/users/3094089", "pm_score": 0, "selected": false, "text": "class DateTimeDecoder(json.JSONDecoder):\n\n def __init__(self, *args, **kargs):\n JSONDecoder.__init__(self, object_hook=self.dict_to_object,\n *args, **kargs)\n\n def dict_to_object(self, d):\n if '__type__' not in d:\n return d\n\n type = d.pop('__type__')\n try:\n dateobj = datetime(**d)\n return dateobj\n except:\n d['__type__'] = type\n return d\n\ndef json_default_format(value):\n try:\n if isinstance(value, datetime):\n return {\n '__type__': 'datetime',\n 'year': value.year,\n 'month': value.month,\n 'day': value.day,\n 'hour': value.hour,\n 'minute': value.minute,\n 'second': value.second,\n 'microsecond': value.microsecond,\n }\n if isinstance(value, decimal.Decimal):\n return float(value)\n if isinstance(value, Enum):\n return value.name\n else:\n return vars(value)\n except Exception as e:\n raise ValueError\n" }, { "answer_id": 53823839, "author": "R H", "author_id": 2169290, "author_profile": "https://Stackoverflow.com/users/2169290", "pm_score": 4, "selected": false, "text": "__dict__" }, { "answer_id": 61531302, "author": "Ricky Levi", "author_id": 281965, "author_profile": "https://Stackoverflow.com/users/281965", "pm_score": 3, "selected": false, "text": "vars()" }, { "answer_id": 65469063, "author": "Anakhand", "author_id": 6117426, "author_profile": "https://Stackoverflow.com/users/6117426", "pm_score": 2, "selected": false, "text": "vars" }, { "answer_id": 66727687, "author": "Reed Sandberg", "author_id": 1287091, "author_profile": "https://Stackoverflow.com/users/1287091", "pm_score": 3, "selected": false, "text": ">>> class Foo(BaseModel):\n... count: int\n... size: float = None\n... \n>>> \n>>> class Bar(BaseModel):\n... apple = 'x'\n... banana = 'y'\n... \n>>> \n>>> class Spam(BaseModel):\n... foo: Foo\n... bars: List[Bar]\n... \n>>> \n>>> m = Spam(foo={'count': 4}, bars=[{'apple': 'x1'}, {'apple': 'x2'}])\n" }, { "answer_id": 68982164, "author": "thetaprime", "author_id": 1968839, "author_profile": "https://Stackoverflow.com/users/1968839", "pm_score": 0, "selected": false, "text": "from pprint import pformat\na_dict = eval(pformat(an_obj))\n" }, { "answer_id": 69088860, "author": "hizbul25", "author_id": 1534638, "author_profile": "https://Stackoverflow.com/users/1534638", "pm_score": 3, "selected": false, "text": "return dict((key, value) for key, value in f.__dict__.items() if not callable(value) and not key.startswith('__'))\n" }, { "answer_id": 73388990, "author": "Surya Teja", "author_id": 5692181, "author_profile": "https://Stackoverflow.com/users/5692181", "pm_score": 2, "selected": false, "text": "@dataclass\nclass Point:\n x: int\n y: int\n\np = Point(10, 20)\nasdict(p) # it returns {'x': 10, 'y': 20}\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2148/" ]
61,535
<p>I get a URL from a user. I need to know:<br/> a) is the URL a valid RSS feed?<br/> b) if not is there a valid feed associated with that URL</p> <p>using PHP/Javascript or something similar</p> <p>(Ex. <a href="http://techcrunch.com" rel="nofollow noreferrer">http://techcrunch.com</a> fails a), but b) would return their RSS feed)</p>
[ { "answer_id": 61537, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 3, "selected": false, "text": "text/html" }, { "answer_id": 61538, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 3, "selected": false, "text": "<link rel=\"alternate\" title=\"RSS Feed\" \n href=\"http://www.example.com/rss-feed.xml\" type=\"application/rss+xml\" />\n" }, { "answer_id": 61539, "author": "Bobby Jack", "author_id": 5058, "author_profile": "https://Stackoverflow.com/users/5058", "pm_score": 2, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" }, { "answer_id": 62237, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "$feedArray = Zend_Feed::findFeeds('http://www.example.com/news.html');\n" }, { "answer_id": 71816, "author": "Corion", "author_id": 11253, "author_profile": "https://Stackoverflow.com/users/11253", "pm_score": 2, "selected": false, "text": "use Feed::Find;\nmy @feeds = Feed::Find->find('http://example.com/');\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61535", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6305/" ]
61,552
<p><a href="http://www.stackoverflow.com/questions/61088/hidden-features-of-javascript#61118">Alan Storm's comments</a> in response to my answer regarding the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with" rel="noreferrer"><code>with</code> statement</a> got me thinking. I've seldom found a reason to use this particular language feature, and had never given much thought to how it might cause trouble. Now, I'm curious as to how I might make effective use of <code>with</code>, while avoiding its pitfalls.</p> <p>Where have you found the <code>with</code> statement useful?</p>
[ { "answer_id": 61566, "author": "Sören Kuklau", "author_id": 1600, "author_profile": "https://Stackoverflow.com/users/1600", "pm_score": 4, "selected": false, "text": "With" }, { "answer_id": 61577, "author": "Sarien", "author_id": 1994377, "author_profile": "https://Stackoverflow.com/users/1994377", "pm_score": 3, "selected": false, "text": "(with-slots (foo bar) objectname\n \"some code that accesses foo and bar\"\n" }, { "answer_id": 61586, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 5, "selected": false, "text": "with" }, { "answer_id": 61676, "author": "Alan Storm", "author_id": 4668, "author_profile": "https://Stackoverflow.com/users/4668", "pm_score": 6, "selected": false, "text": "with" }, { "answer_id": 61737, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 5, "selected": false, "text": "var o = incrediblyLongObjectNameThatNoOneWouldUse;\no.name = \"Bob\";\no.age = \"50\";\n" }, { "answer_id": 176406, "author": "Tom", "author_id": 20, "author_profile": "https://Stackoverflow.com/users/20", "pm_score": 2, "selected": false, "text": "with" }, { "answer_id": 185283, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 9, "selected": false, "text": "var name = \"Joe\";\nif ( true )\n{\n var name = \"Jack\";\n}\n// name now contains \"Jack\"\n" }, { "answer_id": 1028684, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "with (document.getElementById(\"blah\").style) {\n background = \"black\";\n color = \"blue\";\n border = \"1px solid green\";\n}\n" }, { "answer_id": 1462102, "author": "airportyh", "author_id": 5304, "author_profile": "https://Stackoverflow.com/users/5304", "pm_score": 7, "selected": false, "text": "markupbuilder.div(\n markupbuilder.p('Hi! I am a paragraph!',\n markupbuilder.span('I am a span inside a paragraph')\n )\n)\n" }, { "answer_id": 1463937, "author": "kangax", "author_id": 130652, "author_profile": "https://Stackoverflow.com/users/130652", "pm_score": 4, "selected": false, "text": "with" }, { "answer_id": 2207355, "author": "alex", "author_id": 267082, "author_profile": "https://Stackoverflow.com/users/267082", "pm_score": 2, "selected": false, "text": "// demo class framework\nvar Class= function(name, o) {\n var c=function(){};\n if( o.hasOwnProperty(\"constructor\") ) {\n c= o.constructor;\n }\n delete o[\"constructor\"];\n delete o[\"prototype\"];\n c.prototype= {};\n for( var k in o ) c.prototype[k]= o[k];\n c.scope= Class.scope;\n c.scope.Class= c;\n c.Name= name;\n return c;\n}\nClass.newScope= function() {\n Class.scope= {};\n Class.scope.Scope= Class.scope;\n return Class.scope;\n}\n\n// create a new class\nwith( Class.newScope() ) {\n window.Foo= Class(\"Foo\",{\n test: function() {\n alert( Class.Name );\n }\n });\n}\n(new Foo()).test();\n" }, { "answer_id": 2602245, "author": "Fire Crow", "author_id": 80479, "author_profile": "https://Stackoverflow.com/users/80479", "pm_score": 2, "selected": false, "text": "for(var i = nodes.length; i--;)\n{\n // info is namespaced in a closure the click handler can access!\n (function(info)\n { \n nodes[i].onclick = function(){ showStuff(info) };\n })(data[i]);\n}\n" }, { "answer_id": 3122593, "author": "Jonah", "author_id": 376785, "author_profile": "https://Stackoverflow.com/users/376785", "pm_score": 3, "selected": false, "text": "var photo = document.getElementById('photo');\nphoto.style.position = 'absolute';\nphoto.style.left = '10px';\nphoto.style.top = '10px';\n" }, { "answer_id": 3471239, "author": "palswim", "author_id": 393280, "author_profile": "https://Stackoverflow.com/users/393280", "pm_score": 2, "selected": false, "text": "with" }, { "answer_id": 3637640, "author": "Jordão", "author_id": 31158, "author_profile": "https://Stackoverflow.com/users/31158", "pm_score": 3, "selected": false, "text": "with" }, { "answer_id": 3666255, "author": "Elvis Salaris", "author_id": 442248, "author_profile": "https://Stackoverflow.com/users/442248", "pm_score": 1, "selected": false, "text": "function validate_required(field)\n{\nwith (field)\n {\n if (value==null||value==\"\")\n {\n alert('All fields are mandtory');return false;\n }\n else\n {\n return true;\n }\n }\n}\n\nfunction validate_form(thisform)\n{\nwith (thisform)\n {\n for(fiie in elements){\n if (validate_required(elements[fiie])==false){\n elements[fiie].focus();\n elements[fiie].style.border='1px solid red';\n return false;\n } else {elements[fiie].style.border='1px solid #7F9DB9';}\n }\n\n }\n return false;\n}\n" }, { "answer_id": 3976785, "author": "Andy E", "author_id": 94197, "author_profile": "https://Stackoverflow.com/users/94197", "pm_score": 6, "selected": false, "text": "with" }, { "answer_id": 6360857, "author": "Trevor Burnham", "author_id": 66226, "author_profile": "https://Stackoverflow.com/users/66226", "pm_score": 1, "selected": false, "text": "with" }, { "answer_id": 10077345, "author": "rplantiko", "author_id": 1092785, "author_profile": "https://Stackoverflow.com/users/1092785", "pm_score": 2, "selected": false, "text": "sin" }, { "answer_id": 14428133, "author": "avanderveen", "author_id": 1472460, "author_profile": "https://Stackoverflow.com/users/1472460", "pm_score": 0, "selected": false, "text": "with" }, { "answer_id": 19012662, "author": "Dexygen", "author_id": 34806, "author_profile": "https://Stackoverflow.com/users/34806", "pm_score": 0, "selected": false, "text": "with" }, { "answer_id": 23285657, "author": "Jackson", "author_id": 1468130, "author_profile": "https://Stackoverflow.com/users/1468130", "pm_score": 0, "selected": false, "text": "with" }, { "answer_id": 26707742, "author": "kevin.groat", "author_id": 2939688, "author_profile": "https://Stackoverflow.com/users/2939688", "pm_score": 0, "selected": false, "text": "with" }, { "answer_id": 29690322, "author": "user2782001", "author_id": 2782001, "author_profile": "https://Stackoverflow.com/users/2782001", "pm_score": -1, "selected": false, "text": " //utility function\n function _with(context){\n var ctx=context;\n this.set=function(obj){\n for(x in obj){\n //should add hasOwnProperty(x) here\n ctx[x]=obj[x];\n }\n } \n\n return this.set; \n }\n\n //how calling it would look in code...\n\n _with(Hemisphere.Continent.Nation.Language.Dialect.Alphabet)({\n\n a:\"letter a\",\n b:\"letter b\",\n c:\"letter c\",\n d:\"letter a\",\n e:\"letter b\",\n f:\"letter c\",\n // continue through whole alphabet...\n\n });//look how readable I am!!!!\n" }, { "answer_id": 37640530, "author": "Little Alien", "author_id": 6267925, "author_profile": "https://Stackoverflow.com/users/6267925", "pm_score": 1, "selected": false, "text": "switch(e.type) {\n case gapi.drive.realtime.ErrorType.TOKEN_REFRESH_REQUIRED: blah\n case gapi.drive.realtime.ErrorType.CLIENT_ERROR: blah\n case gapi.drive.realtime.ErrorType.NOT_FOUND: blah\n}\n" }, { "answer_id": 65077825, "author": "shabaany", "author_id": 12220097, "author_profile": "https://Stackoverflow.com/users/12220097", "pm_score": 1, "selected": false, "text": "module" }, { "answer_id": 73360501, "author": "nzn", "author_id": 932256, "author_profile": "https://Stackoverflow.com/users/932256", "pm_score": 0, "selected": false, "text": "with" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/811/" ]
61,604
<p>Do you often see in API documentation (as in 'javadoc of public functions' for example) the description of "value limits" as well as the classic documentation ?</p> <p><strong>Note:</strong> I am not talking about <a href="https://stackoverflow.com/questions/20922/do-you-comment-your-code">comments within the code</a></p> <p>By "value limits", I mean:</p> <ul> <li>does a parameter can support a null value (or an empty String, or...) ?</li> <li>does a 'return value' can be null or is guaranteed to never be null (or can be "empty", or...) ?</li> </ul> <p><strong>Sample:</strong></p> <p>What I often see (without having access to source code) is:</p> <pre><code>/** * Get all readers name for this current Report. &lt;br /&gt; * &lt;b&gt;Warning&lt;/b&gt;The Report must have been published first. * @param aReaderNameRegexp filter in order to return only reader matching the regexp * @return array of reader names */ String[] getReaderNames(final String aReaderNameRegexp); </code></pre> <p>What I <em>like to see</em> would be:</p> <pre><code>/** * Get all readers name for this current Report. &lt;br /&gt; * &lt;b&gt;Warning&lt;/b&gt;The Report must have been published first. * @param aReaderNameRegexp filter in order to return only reader matching the regexp * (can be null or empty) * @return array of reader names * (null if Report has not yet been published, * empty array if no reader match criteria, * reader names array matching regexp, or all readers if regexp is null or empty) */ String[] getReaderNames(final String aReaderNameRegexp); </code></pre> <p><strong>My point is:</strong></p> <p>When I use a library with a getReaderNames() function in it, I often do not even need to read the API documentation to guess what it does. But I need to be sure <em>how to use it</em>.</p> <p>My only concern when I want to use this function is: what should I expect in term of parameters and return values ? That is all I need to know to safely setup my parameters and safely test the return value, yet I almost never see that kind of information in API documentation...</p> <p><strong>Edit:</strong> </p> <p>This can influence the usage or not for <em><a href="https://stackoverflow.com/questions/27578#73355">checked or unchecked exceptions</a></em>.</p> <p>What do you think ? value limits and API, do they belong together or not ?</p>
[ { "answer_id": 61608, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 1, "selected": false, "text": "//File:\n// Should be a path to the teexture file to load, if it is not a full path (eg \"c:\\example.png\") it will attempt to find the file usign the paths provided by the DataSearchPath list\n//Return: The pointer to a Texture instance is returned, in the event of an error, an exception is thrown. When you are finished with the texture you chould call the Free() method.\n//Exceptions:\n//except::FileNotFound\n//except::InvalidFile\n//except::InvalidParams\n//except::CreationFailed\nTexture *GetTexture(const std::string &File);\n" }, { "answer_id": 24224149, "author": "taringamberini", "author_id": 1972317, "author_profile": "https://Stackoverflow.com/users/1972317", "pm_score": 2, "selected": false, "text": "RuntimeException" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6309/" ]
61,605
<p>In python, you can have a function return multiple values. Here's a contrived example:</p> <pre><code>def divide(x, y): quotient = x/y remainder = x % y return quotient, remainder (q, r) = divide(22, 7) </code></pre> <p>This seems very useful, but it looks like it can also be abused ("Well..function X already computes what we need as an intermediate value. Let's have X return that value also").</p> <p>When should you draw the line and define a different method? </p>
[ { "answer_id": 61629, "author": "Jason Etheridge", "author_id": 2193, "author_profile": "https://Stackoverflow.com/users/2193", "pm_score": 5, "selected": false, "text": "q, r = divide(22, 7)\n" }, { "answer_id": 61636, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 8, "selected": true, "text": "divmod()" }, { "answer_id": 61637, "author": "Nathan Jones", "author_id": 5848, "author_profile": "https://Stackoverflow.com/users/5848", "pm_score": 4, "selected": false, "text": "divmod" }, { "answer_id": 63528, "author": "Will Harris", "author_id": 4702, "author_profile": "https://Stackoverflow.com/users/4702", "pm_score": 0, "selected": false, "text": "divmod" }, { "answer_id": 64110, "author": "zweiterlinde", "author_id": 6592, "author_profile": "https://Stackoverflow.com/users/6592", "pm_score": 2, "selected": false, "text": "// C++\nvoid test(int& arg)\n{\n arg = 1;\n}\n\nint foo = 0;\ntest(foo); // foo is now 1!\n" }, { "answer_id": 66967, "author": "Fred Larson", "author_id": 10077, "author_profile": "https://Stackoverflow.com/users/10077", "pm_score": 0, "selected": false, "text": "def divide(x, y):\n return {'quotient': x/y, 'remainder':x%y }\n\nanswer = divide(22, 7)\nprint answer['quotient']\nprint answer['remainder']\n" }, { "answer_id": 640632, "author": "NevilleDNZ", "author_id": 77431, "author_profile": "https://Stackoverflow.com/users/77431", "pm_score": 1, "selected": false, "text": "INT quotient:=355, remainder;\nremainder := (quotient /:= 113);\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
61,615
<p>C# and Java allow almost any character in class names, method names, local variables, etc.. Is it bad practice to use non-ASCII characters, testing the boundaries of poor editors and analysis tools and making it difficult for some people to read, or is American arrogance the only argument against?</p>
[ { "answer_id": 61619, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 2, "selected": false, "text": "if" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4926/" ]
61,634
<p>I'm trying to create a dialog box using C++ and the windows API, but I don't want the dialog defined in a resource file. I can't find anything good on this on the web, and none of the examples I've read seem to define the dialog programmatically.</p> <p>How can I do this?</p> <p>A simple example is fine. I'm not doing anything complicated with it yet.</p>
[ { "answer_id": 48009861, "author": "jrh", "author_id": 4975230, "author_profile": "https://Stackoverflow.com/users/4975230", "pm_score": 3, "selected": false, "text": "CreateWindow" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1467/" ]
61,669
<p>How do I use the profiler in Visual Studio 2008?</p> <p>I know theres a build option in Config Properties -> Linker -> Advanced -> Profile (/PROFILE), however I can't find anything about actauly using it, only articles I was able to find appear to only apply to older versions of Visual Studio (eg most say to goto Build->Profile to bring up the profile dialog box, yet in 2008 there is no such menu item).</p> <p>Is this because Visual Studio 2008 does not include a profiler, and if it does where is it and where is the documentation for it?</p>
[ { "answer_id": 11205196, "author": "Michelle", "author_id": 1482301, "author_profile": "https://Stackoverflow.com/users/1482301", "pm_score": 0, "selected": false, "text": ".vsp" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6266/" ]
61,675
<p>I'm reading lines of input on a TCP socket, similar to this:</p> <pre><code>class Bla def getcmd @sock.gets unless @sock.closed? end def start srv = TCPServer.new(5000) @sock = srv.accept while ! @sock.closed? ans = getcmd end end end </code></pre> <p>If the endpoint terminates the connection while getline() is running then gets() hangs. </p> <p>How can I work around this? Is it necessary to do non-blocking or timed I/O?</p>
[ { "answer_id": 61732, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": -1, "selected": false, "text": "gets" }, { "answer_id": 64313, "author": "manveru", "author_id": 8367, "author_profile": "https://Stackoverflow.com/users/8367", "pm_score": 3, "selected": false, "text": "require 'socket'\n\nhost, port = 'localhost', 7000\n\nTCPServer.open(host, port) do |server|\n while client = server.accept\n readfds = true\n got = nil\n begin\n readfds, writefds, exceptfds = select([client], nil, nil, 0.1)\n p :r => readfds, :w => writefds, :e => exceptfds\n\n if readfds\n got = client.gets \n p got\n end\n end while got\n end\nend\n" }, { "answer_id": 6005803, "author": "Ben Flynn", "author_id": 449161, "author_profile": "https://Stackoverflow.com/users/449161", "pm_score": 0, "selected": false, "text": "while true\n sockets_ready = select(@sockets, nil, nil, nil)\n if sockets_ready != nil\n sockets_ready[0].each do |socket|\n begin\n if (socket == @server_socket)\n # puts \"Connection accepted!\"\n @sockets << @server_socket.accept\n else\n # Received something on a client socket\n if socket.eof?\n # puts \"Disconnect!\"\n socket.close\n @sockets.delete(socket)\n else\n data = \"\"\n recv_length = 256\n while (tmp = socket.readpartial(recv_length))\n data += tmp\n break if (!socket.ready?)\n end\n listen socket, data\n end\n end\n rescue Exception => exception\n case exception\n when Errno::ECONNRESET,Errno::ECONNABORTED,Errno::ETIMEDOUT\n # puts \"Socket: #{exception.class}\"\n @sockets.delete(socket)\n else\n raise exception\n end\n end\n end\n end\n end\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61675", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3796/" ]
61,677
<p>Suppose I have a COM object which users can access via a call such as:</p> <pre><code>Set s = CreateObject("Server") </code></pre> <p>What I'd like to be able to do is allow the user to specify an event handler for the object, like so:</p> <pre><code>Function ServerEvent MsgBox "Event handled" End Function s.OnDoSomething = ServerEvent </code></pre> <p>Is this possible and, if so, how do I expose this in my type library in C++ (specifically BCB 2007)?</p>
[ { "answer_id": 61723, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 2, "selected": false, "text": "IProvideClassInfo" }, { "answer_id": 61762, "author": "Jeff Hillman", "author_id": 3950, "author_profile": "https://Stackoverflow.com/users/3950", "pm_score": 3, "selected": false, "text": "[\n object,\n uuid(6EDA5438-0915-4183-841D-D3F0AEDFA466),\n nonextensible,\n oleautomation,\n pointer_default(unique)\n]\ninterface IServerEvents : IDispatch\n{\n [id(1)]\n HRESULT OnServerEvent();\n}\n\n//...\n\n[\n uuid(FA8F24B3-1751-4D44-8258-D649B6529494),\n]\ncoclass ServerEvents\n{\n [default] interface IServerEvents;\n [default, source] dispinterface IServerEvents;\n};\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61677", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5449/" ]
61,680
<p>I need to create a 2D int array of size 800x800. But doing so creates a stack overflow (ha ha).</p> <p>I'm new to C++, so should I do something like a vector of vectors? And just encapsulate the 2d array into a class?</p> <p>Specifically, this array is my zbuffer in a graphics program. I need to store a z value for every pixel on the screen (hence the large size of 800x800).</p> <p>Thanks!</p>
[ { "answer_id": 61684, "author": "Adam Mitz", "author_id": 2574, "author_profile": "https://Stackoverflow.com/users/2574", "pm_score": 5, "selected": true, "text": "int *array = new int[800*800];\n" }, { "answer_id": 61685, "author": "Niall", "author_id": 6049, "author_profile": "https://Stackoverflow.com/users/6049", "pm_score": 2, "selected": false, "text": "const int width = 800;\nconst int height = 800;\nunsigned int* z_buffer = new unsigned int[width*height];\n" }, { "answer_id": 61689, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 2, "selected": false, "text": "int *ary=new int[800*800];\n" }, { "answer_id": 61690, "author": "Free Wildebeest", "author_id": 1849, "author_profile": "https://Stackoverflow.com/users/1849", "pm_score": 1, "selected": false, "text": "const int xwidth = 800;\nconst int ywidth = 800;\nint* array = (int*) new int[xwidth * ywidth];\n// Check array is not NULL here and handle the allocation error if it is\n// Then do stuff with the array, such as zero initialize it\nfor(int x = 0; x < xwidth; ++x)\n{\n for(int y = 0; y < ywidth; ++y)\n {\n array[y * xwidth + x] = 0;\n }\n}\n// Just use array[y * xwidth + x] when you want to access your class.\n\n// When you're done with it, free the memory you allocated with\ndelete[] array;\n" }, { "answer_id": 61693, "author": "ReaperUnreal", "author_id": 4218, "author_profile": "https://Stackoverflow.com/users/4218", "pm_score": -1, "selected": false, "text": "800 = 512 + 256 + 32 = 2^5 + 2^8 + 2^9\n" }, { "answer_id": 61936, "author": "Kevin", "author_id": 6386, "author_profile": "https://Stackoverflow.com/users/6386", "pm_score": 3, "selected": false, "text": "template <class T, size_t W, size_t H>\nclass Array2D\n{\npublic:\n const int width = W;\n const int height = H;\n typedef typename T type;\n\n Array2D()\n : buffer(width*height)\n {\n }\n\n inline type& at(unsigned int x, unsigned int y)\n {\n return buffer[y*width + x];\n }\n\n inline const type& at(unsigned int x, unsigned int y) const\n {\n return buffer[y*width + x];\n }\n\nprivate:\n std::vector<T> buffer;\n};\n" }, { "answer_id": 61946, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 1, "selected": false, "text": "vector" }, { "answer_id": 61960, "author": "Andreas Magnusson", "author_id": 5811, "author_profile": "https://Stackoverflow.com/users/5811", "pm_score": 2, "selected": false, "text": "std::vector<T> buffer[width * height];\n" }, { "answer_id": 61980, "author": "Ryan Fox", "author_id": 55, "author_profile": "https://Stackoverflow.com/users/55", "pm_score": 1, "selected": false, "text": "boost::shared_array<int> zbuffer(new int[width*height]);\n" }, { "answer_id": 62611, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "static" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/396/" ]
61,688
<p>My current project is to write a web application that is an equivalent of an existing desktop application. </p> <p>In the desktop app at certain points in the workflow the user might click on a button and then be shown a form to fill in. Even if it takes a little time for the app to display the form, expert users know what the form will be and will start typing, knowing that the app will "catch up with them".</p> <p>In a web application this doesn't happen: when the user clicks a link their keystrokes are then lost until the form on the following page is dispayed. Does anyone have any tricks for preventing this? Do I have to move away from using separate pages and use AJAX to embed the form in the page using something like <a href="http://code.google.com/webtoolkit/" rel="nofollow noreferrer">GWT</a>, or will that still have the problem of lost keystrokes?</p>
[ { "answer_id": 61708, "author": "Leo Moore", "author_id": 6336, "author_profile": "https://Stackoverflow.com/users/6336", "pm_score": 0, "selected": false, "text": "<html><head>\n<script language=javascript>\nIE=document.all;\nNN=document.layers;\nkys=\"\";\nif (NN){document.captureEvents(Event.KEYPRESS)}\ndocument.onkeypress=katch\nfunction katch(e){\nif (NN){kys+=e.which}\nif (IE){kys+=event.keyCode}\ndocument.forms[0].elements[0].value=kys\n}\n</script>\n</head>\n<body>\n<form><input></form>\n</body>\n</html>\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2649/" ]
61,691
<p>The .NET Setup project seems to have a lot of options, but I don't see an "Uninstall" option. </p> <p>I'd prefer if people could "uninstall" from the standard "start menu" folder rather than send them to the control panel to uninstall my app, so can someone please tell me how to do this?</p> <p>Also, I am aware of non Microsoft installers that have this feature, but if possible I'd like to stay with the Microsoft toolkit.</p>
[ { "answer_id": 61697, "author": "Mladen Janković", "author_id": 6300, "author_profile": "https://Stackoverflow.com/users/6300", "pm_score": 4, "selected": true, "text": "msiexec /uninstall [path to msi or product code]\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4050/" ]
61,692
<p>I have a Java application which I want to shutdown 'nicely' when the user selects Start->Shutdown. I've tried using JVM shutdown listeners via Runtime.addShutdownHook(...) but this doesn't work as I can't use any UI elements from it.</p> <p>I've also tried using the exit handler on my main application UI window but it has no way to pause or halt shutdown as far as I can tell. How can I handle shutdown nicely?</p>
[ { "answer_id": 61697, "author": "Mladen Janković", "author_id": 6300, "author_profile": "https://Stackoverflow.com/users/6300", "pm_score": 4, "selected": true, "text": "msiexec /uninstall [path to msi or product code]\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1849/" ]
61,699
<p>Until recently we were using Inno Setup for our installations, something I would like to continue doing, unless we can get an <a href="https://stackoverflow.com/questions/61691/how-to-add-uninstall-option-in-net-setup-project">uninstall option in the start menu</a> (thanks Giovanni Galbo), however we now need to GAC some external libraries, something I suspect is only doable (or at least only supported) though the .NET Setup Project.</p> <p>Is it possible to call a GAC'ing library from another setup application?</p>
[ { "answer_id": 1476781, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 4, "selected": true, "text": "* Added new [Files] section flag: gacinstall.\n* Added new [Files] section parameter: StrongAssemblyName.\n* Added new constants: {regasmexe}, {regasmexe32}, {regasmexe64}.\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5302/" ]
61,718
<p>When you are doing integration tests with either just your data access layer or the majority of the application stack. What is the best way prevent multiple tests from clashing with each other if they are run on the same database?</p>
[ { "answer_id": 61721, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 4, "selected": true, "text": "Load all fixture data.\n\nFor each test:\n\n BEGIN TRANSACTION\n\n # Yield control to user code\n\n ROLLBACK TRANSACTION\n\nEnd for each\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6369/" ]
61,733
<p>Which of the following is better code in c# and why?</p> <pre><code>((DateTime)g[0]["MyUntypedDateField"]).ToShortDateString() </code></pre> <p>or</p> <pre><code>DateTime.Parse(g[0]["MyUntypedDateField"].ToString()).ToShortDateString() </code></pre> <p>Ultimately, is it better to cast or to parse?</p>
[ { "answer_id": 62619, "author": "Steve Cooper", "author_id": 6722, "author_profile": "https://Stackoverflow.com/users/6722", "pm_score": 1, "selected": false, "text": "DateTime.TryParse()" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4246/" ]
61,735
<p>What is the best method for including a CSS or Javascript file for a specific node in Drupal 6.</p> <p>I want to create a page on my site that has a little javascript application running, so the CSS and javascript is specific to that page and would not want to be included in other page loads at all.</p>
[ { "answer_id": 61798, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 2, "selected": false, "text": "function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {\n // the node ID of the node you want to modify\n $node_to_modify = 6;\n\n // do it!\n if($op == 'view' && $node->nid == $node_to_modify) {\n drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js');\n drupal_add_css(drupal_get_path('module', 'mymodule') . '/mymodule.css');\n }\n}\n" }, { "answer_id": 67901, "author": "Inferis", "author_id": 6251, "author_profile": "https://Stackoverflow.com/users/6251", "pm_score": 4, "selected": false, "text": "hook_nodeapi" }, { "answer_id": 628706, "author": "canen", "author_id": 43785, "author_profile": "https://Stackoverflow.com/users/43785", "pm_score": 3, "selected": false, "text": "$variables['styles']" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6277/" ]
61,739
<p>I'm drawing old school (unthemed - themed radios are a whole other problem) radio buttons myself using DrawFrameControl:</p> <pre><code>DrawFrameControl(dc, &amp;rectRadio, DFC_BUTTON, isChecked() ? DFCS_BUTTONRADIO | DFCS_CHECKED : DFCS_BUTTONRADIO); </code></pre> <p>I've never been able to figure out a sure fire way to figure out what to pass for the RECT. I've been using a 12x12 rectangle but I'de like Windows to tell me the size of a radio button.</p> <p>DrawFrameControl seems to scale the radio button to fit the rect I pass so I have to be close to the "right" size of the radio looks off from other (non-owner drawn) radios on the screen.</p> <p>Anyone know how to do this? </p>
[ { "answer_id": 124770, "author": "Brannon", "author_id": 5745, "author_profile": "https://Stackoverflow.com/users/5745", "pm_score": 2, "selected": false, "text": "GetSystemMetrics" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3655/" ]
61,747
<p>How can I get PDO to work on my mac (os x 10.5)? I'm using the built in php and php in Zend/Eclipse. Can't seem to find useful drivers for it at all.</p>
[ { "answer_id": 1286153, "author": "hbw", "author_id": 90155, "author_profile": "https://Stackoverflow.com/users/90155", "pm_score": 6, "selected": true, "text": "$ pecl download pdo_pgsql\n$ tar xzf PDO_PGSQL-1.0.2.tgz\n" }, { "answer_id": 35874398, "author": "Mark Horgan", "author_id": 628709, "author_profile": "https://Stackoverflow.com/users/628709", "pm_score": 0, "selected": false, "text": "brew install php55-pdo-pgsql\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6371/" ]
61,750
<p>Task: implement paging of database records suitable for different RDBMS. Method should work for mainstream engines - MSSQL2000+, Oracle, MySql, etc.</p> <p>Please don't post RDBMS specific solutions, I know how to implement this for most of the modern database engines. I'm looking for the universal solution. Only temporary tables based solutions come to my mind at the moment.</p> <p><strong>EDIT:</strong><br> I'm looking for SQL solution, not 3rd party library.</p>
[ { "answer_id": 61757, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 0, "selected": false, "text": "Query q = ...;\nq.setFirstResult (0);\nq.setMaxResults (10);\n" }, { "answer_id": 61985, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 0, "selected": false, "text": "N - upper bound\nM - lower bound\n\ncreate #temp (Id int identity, originalId int)\n\ninsert into #temp(originalId)\nselect top N KeyColumn from MyTable\nwhere ...\n\nselect MyTable.* from MyTable\njoin #temp t on t.originalId = MyTable.KeyColumn\nwhere Id between M and M\norder by Id asc\n\ndrop #temp\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61750", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1196/" ]
61,805
<p>I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a Preview 2 solution) that uses an untyped ViewMasterPage like so:</p> <pre><code>public partial class Home : ViewMasterPage </code></pre> <p>On Home.Master there is a display statement like this:</p> <pre><code>&lt;%= ((GenericViewData)ViewData["Generic"]).Skin %&gt; </code></pre> <p>However, a developer on the team just changed the assembly references to Preview 4.</p> <p>Following this, the code will no longer populate ViewData with indexed values like the above.</p> <p>Instead, ViewData["Generic"] is null.</p> <p>As per <a href="https://stackoverflow.com/questions/18787/aspnet-mvc-user-control-viewdata">this question</a>, ViewData.Eval("Generic") works, and ViewData.Model is also populated correctly.</p> <p>However, the reason this solution isn't using typed pages etc. is because it is kind of a legacy solution. As such, it is impractical to go through this fairly large solution and update all .aspx pages (especially as the compiler doesn't detect this sort of stuff).</p> <p>I have tried reverting the assemblies by removing the reference and then adding a reference to the Preview 3 assembly in the 'bin' folder of the project. This did not change anything. I have even tried reverting the Project file to an earlier version and that still did not seem to fix the problem.</p> <p>I have other solutions using the same technique that continue to work.</p> <p>Is there anything you can suggest as to why this has suddenly stopped working and how I might go about fixing it (any hint in the right direction would be appreciated)?</p>
[ { "answer_id": 61835, "author": "Ricky", "author_id": 653, "author_profile": "https://Stackoverflow.com/users/653", "pm_score": 0, "selected": false, "text": "ViewData[\"CategoryName\"] = a.Name;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
61,817
<p>I am wondering what the best way to obtain the current domain is in ASP.NET?</p> <p>For instance:</p> <p><a href="http://www.domainname.com/subdir/" rel="noreferrer">http://www.domainname.com/subdir/</a> should yield <a href="http://www.domainname.com" rel="noreferrer">http://www.domainname.com</a> <a href="http://www.sub.domainname.com/subdir/" rel="noreferrer">http://www.sub.domainname.com/subdir/</a> should yield <a href="http://sub.domainname.com" rel="noreferrer">http://sub.domainname.com</a></p> <p>As a guide, I should be able to add a url like "/Folder/Content/filename.html" (say as generated by Url.RouteUrl() in ASP.NET MVC) straight onto the URL and it should work.</p>
[ { "answer_id": 61819, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 5, "selected": false, "text": "Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host \n" }, { "answer_id": 61822, "author": "jwalkerjr", "author_id": 689, "author_profile": "https://Stackoverflow.com/users/689", "pm_score": -1, "selected": false, "text": "String domain = \"http://\" + Request.Url.Host\n" }, { "answer_id": 64045, "author": "derek lawless", "author_id": 400464, "author_profile": "https://Stackoverflow.com/users/400464", "pm_score": 1, "selected": false, "text": "NameValueCollection vars = HttpContext.Current.Request.ServerVariables;\nstring protocol = vars[\"SERVER_PORT_SECURE\"] == \"1\" ? \"https://\" : \"http://\";\nstring domain = vars[\"SERVER_NAME\"];\nstring port = vars[\"SERVER_PORT\"];\n" }, { "answer_id": 2326934, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "\nstring domain;\nUri url = HttpContext.Current.Request.Url;\ndomain= url.AbsoluteUri.Replace(url.PathAndQuery, string.Empty);\n" }, { "answer_id": 2878350, "author": "Carlos Muñoz", "author_id": 186133, "author_profile": "https://Stackoverflow.com/users/186133", "pm_score": 9, "selected": true, "text": "Request.Url.Authority" }, { "answer_id": 6727511, "author": "Korayem", "author_id": 80434, "author_profile": "https://Stackoverflow.com/users/80434", "pm_score": 4, "selected": false, "text": "Request.Url.Authority" }, { "answer_id": 8686506, "author": "izlence", "author_id": 1123996, "author_profile": "https://Stackoverflow.com/users/1123996", "pm_score": 5, "selected": false, "text": "Request.Url.GetLeftPart(UriPartial.Authority)\n" }, { "answer_id": 29385136, "author": "Darren", "author_id": 329367, "author_profile": "https://Stackoverflow.com/users/329367", "pm_score": 0, "selected": false, "text": " var relativePath = \"\"; // or whatever-path-you-want\n var uriBuilder = new UriBuilder\n {\n Host = Request.Url.Host,\n Path = relativePath,\n Scheme = Request.Url.Scheme\n };\n\n if (!Request.Url.IsDefaultPort)\n uriBuilder.Port = Request.Url.Port;\n\n var fullPathToUse = uriBuilder.ToString();\n" }, { "answer_id": 45777954, "author": "Ramin Bateni", "author_id": 1474613, "author_profile": "https://Stackoverflow.com/users/1474613", "pm_score": 2, "selected": false, "text": "Request.GetFullDomain()" }, { "answer_id": 63976140, "author": "Dastan Alybaev", "author_id": 10049738, "author_profile": "https://Stackoverflow.com/users/10049738", "pm_score": 1, "selected": false, "text": "private readonly IHttpContextAccessor _contextAccessor;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
61,838
<p>If I have something like a UILabel linked to a xib file, do I need to release it on dealloc of my view? The reason I ask is because I don't alloc it, which makes me think I don't need to release it either? eg (in the header):</p> <pre><code>IBOutlet UILabel *lblExample; </code></pre> <p>in the implementation:</p> <pre><code>.... [lblExample setText:@"whatever"]; .... -(void)dealloc{ [lblExample release];//????????? } </code></pre>
[ { "answer_id": 61867, "author": "Kendall Helmstetter Gelner", "author_id": 6330, "author_profile": "https://Stackoverflow.com/users/6330", "pm_score": 0, "selected": false, "text": "@property (nonatomic, retain) UILabel *lblExample;\n" }, { "answer_id": 191935, "author": "mmalc", "author_id": 23233, "author_profile": "https://Stackoverflow.com/users/23233", "pm_score": 6, "selected": true, "text": "@interface MyController : MySuperclass {\n Control *uiElement;\n}\n@property (nonatomic, retain) IBOutlet Control *uiElement;\n@end\n\n\n@implementation MyController\n\n@synthesize uiElement;\n\n- (void)dealloc {\n [uiElement release];\n [super dealloc];\n}\n@end\n" }, { "answer_id": 567962, "author": "Wil Shipley", "author_id": 30602, "author_profile": "https://Stackoverflow.com/users/30602", "pm_score": 2, "selected": false, "text": "[anOutlet release], anOutlet = nil;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6044/" ]
61,861
<p>I would like to make my web control more readable in design mode, basically I want the tag declaration to look like:</p> <pre><code>&lt;cc1:Ctrl ID="Value1" runat="server"&gt; &lt;Values&gt;string value 1&lt;/Value&gt; &lt;Values&gt;string value 2&lt;/Value&gt; &lt;/cc1:Ctrl&gt; </code></pre> <p>Lets say I have a private variable in the code behind:</p> <pre><code>List&lt;string&gt; values = new List&lt;string&gt;(); </code></pre> <p>So how can I make my user control fill out the private variable with the values that are declared in the markup?</p> <hr> <p>Sorry I should have been more explicit. Basically I like the functionality that the ITemplate provides (<a href="http://msdn.microsoft.com/en-us/library/aa719834.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa719834.aspx</a>)</p> <p>But in this case you need to know at runtime how many templates can be instansitated, i.e.</p> <pre><code>void Page_Init() { if (messageTemplate != null) { for (int i=0; i&lt;5; i++) { MessageContainer container = new MessageContainer(i); messageTemplate.InstantiateIn(container); msgholder.Controls.Add(container); } } </code></pre> <p>}</p> <p>In the given example the markup looks like:</p> <pre><code>&lt;acme:test runat=server&gt; &lt;MessageTemplate&gt; Hello #&lt;%# Container.Index %&gt;.&lt;br&gt; &lt;/MessageTemplate&gt; &lt;/acme:test&gt; </code></pre> <p>Which is nice and clean, it does not have any tag prefixes etc. I really want the nice clean tags.</p> <p>I'm probably being silly in wanting the markup to be clean, I'm just wondering if there is something simple that I'm missing.</p>
[ { "answer_id": 61925, "author": "Matt", "author_id": 4154, "author_profile": "https://Stackoverflow.com/users/4154", "pm_score": 0, "selected": false, "text": " <asp:ListBox ID=\"ListBox1\" runat=\"server\">\n <asp:ListItem>String 1</asp:ListItem>\n <asp:ListItem>String 2</asp:ListItem>\n <asp:ListItem>String 3</asp:ListItem>\n </asp:ListBox><br />\n" }, { "answer_id": 62589, "author": "Luca Molteni", "author_id": 4206, "author_profile": "https://Stackoverflow.com/users/4206", "pm_score": 3, "selected": true, "text": "[PersistenceMode(PersistenceMode.InnerProperty)]\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2758/" ]
61,872
<p>We are rewriting our legacy <a href="https://en.wikipedia.org/wiki/Accounting_information_system" rel="nofollow noreferrer">accounting system</a> in VB.NET and SQL Server. We brought in a new team of .NET/ SQL Programmers to do the rewrite. Most of the system is already completed with the dollar amounts using floats. The legacy system language, I programmed in, did not have a float, so I probably would have used a decimal.</p> <p>What is your recommendation?</p> <p>Should the float or decimal data type be used for dollar amounts?</p> <p>What are some of the pros and cons for either?</p> <p>One <em>con</em> mentioned in our <a href="https://en.wikipedia.org/wiki/Scrum_%28software_development%29#Daily_scrum" rel="nofollow noreferrer">daily scrum</a> was you have to be careful when you calculate an amount that returns a result that is over two decimal positions. It sounds like you will have to round the amount to two decimal positions.</p> <p>Another <em>con</em> is all displays and printed amounts have to have a <em>format statement</em> that shows two decimal positions. I noticed a few times where this was not done and the amounts did not look correct. (i.e. 10.2 or 10.2546)</p> <p>A <em>pro</em> is the float-only approach takes up eight bytes on disk where the decimal would take up nine bytes (decimal 12,2).</p>
[ { "answer_id": 62071, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 3, "selected": false, "text": "money" }, { "answer_id": 62493, "author": "David T. Macknet", "author_id": 6850, "author_profile": "https://Stackoverflow.com/users/6850", "pm_score": 0, "selected": false, "text": "FORMAT()" }, { "answer_id": 66678, "author": "TSK", "author_id": 9959, "author_profile": "https://Stackoverflow.com/users/9959", "pm_score": 8, "selected": true, "text": "m/2^n" }, { "answer_id": 70868, "author": "Peter Stuifzand", "author_id": 1633, "author_profile": "https://Stackoverflow.com/users/1633", "pm_score": 2, "selected": false, "text": "100" }, { "answer_id": 3991553, "author": "Lars Bohl", "author_id": 438960, "author_profile": "https://Stackoverflow.com/users/438960", "pm_score": 2, "selected": false, "text": "#include <stdio.h>\n\nint main()\n{\n printf(\"Mapping 100 numbers between 0 and 1 \");\n printf(\"to their hexadecimal exponential form (HEF).\\n\");\n printf(\"Most of them do not equal their HEFs. That means \");\n printf(\"that their representations as floats \");\n printf(\"differ from their actual values.\\n\");\n double f = 0.01;\n int i;\n for (i = 0; i < 100; i++) {\n printf(\"%1.2f -> %a\\n\",f*i,f*i);\n }\n printf(\"Printing 128 'float-compatible' numbers \");\n printf(\"together with their HEFs for comparison.\\n\");\n f = 0x1p-7; // ==0.0071825\n for (i = 0; i < 0x80; i++) {\n printf(\"%1.7f -> %a\\n\",f*i,f*i);\n }\n return 0;\n}\n" }, { "answer_id": 4002088, "author": "BrokeMyLegBiking", "author_id": 97686, "author_profile": "https://Stackoverflow.com/users/97686", "pm_score": 0, "selected": false, "text": " DECLARE @Float1 float, @Float2 float, @Float3 float, @Float4 float; \n SET @Float1 = 54; \n SET @Float2 = 3.1; \n SET @Float3 = 0 + @Float1 + @Float2; \n SELECT @Float3 - @Float1 - @Float2 AS \"Should be 0\";\n\nShould be 0 \n---------------------- \n1.13797860024079E-15\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4964/" ]
61,882
<p>In a typical handheld/portable embedded system device Battery life is a major concern in design of H/W, S/W and the features the device can support. From the Software programming perspective, one is aware of MIPS, Memory(Data and Program) optimized code. I am aware of the H/W Deep sleep mode, Standby mode that are used to clock the hardware at lower Cycles or turn of the clock entirel to some unused circutis to save power, but i am looking for some ideas from that point of view:</p> <p>Wherein my code is running and it needs to keep executing, given this how can I write the code "power" efficiently so as to consume minimum watts?</p> <p>Are there any special programming constructs, data structures, control structures which i should look at to achieve minimum power consumption for a given functionality.</p> <p>Are there any s/w high level design considerations which one should keep in mind at time of code structure design, or during low level design to make the code as power efficient(Least power consuming) as possible? </p>
[ { "answer_id": 61912, "author": "macbirdie", "author_id": 5049, "author_profile": "https://Stackoverflow.com/users/5049", "pm_score": 5, "selected": false, "text": "1800 INFORMATION" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61882", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2759376/" ]
61,888
<p>Is it possible to use <a href="http://subversion.apache.org/" rel="noreferrer">Apache Subversion</a> (SVN) as general purpose backup tool? (As a kind of <a href="http://en.wikipedia.org/wiki/Rsync" rel="noreferrer">rsync</a> alternative.)</p>
[ { "answer_id": 15548768, "author": "user2195264", "author_id": 2195264, "author_profile": "https://Stackoverflow.com/users/2195264", "pm_score": 1, "selected": false, "text": "cd" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61888", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1897/" ]