qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
184,272
<p>What exactly does the word patch mean when referring to 'submitting a patch'?</p> <p>I've seen this used a lot, especially in the open source world. What what does it mean and what exactly is involved in submitting a patch?</p>
[ { "answer_id": 184277, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 5, "selected": true, "text": "<?php\n $foo = 0;\n?>\n <?php\n $bar = 0;\n?>\n Index: test.php\n===================================================================\n--- test.php (revision 40)\n+++ test.php (working copy)\n@@ -3,7 +3,7 @@\n <?php\n- $foo = 0;\n+ $bar= 0;\n ?>\n" }, { "answer_id": 184284, "author": "Jim Puls", "author_id": 6010, "author_profile": "https://Stackoverflow.com/users/6010", "pm_score": 1, "selected": false, "text": "diff svn diff git format-patch" }, { "answer_id": 184298, "author": "Kluge", "author_id": 8752, "author_profile": "https://Stackoverflow.com/users/8752", "pm_score": 1, "selected": false, "text": " 1. n. A temporary addition to a piece of code, usually as a quick-and-dirty\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184272", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13227/" ]
184,292
<p>I am wondering what the correct mechanism to enable communication between controls in WPF is. My goal is to not use conventional events and have to manually wire them up. The default behavior of routed commands (tunneling, bubbling) seems to be along the right lines but I guess I'm missing something.</p> <blockquote> <p>Routed events are a new infrastructure provided by WPF which allows events to tunnel down the visual tree to the target element, or bubble up to the root element. When an event is raised, it “travels” up or down the visual tree invoking handlers for that event on any element subscribed to that event it encounters en route. <strong>Note that this tree traversal does not cover the entire visual tree, only the ancestral element</strong> </p> </blockquote> <p>That is from this <a href="http://joshsmithonwpf.wordpress.com/2007/06/22/overview-of-routed-events-in-wpf/" rel="nofollow noreferrer">WPF Article</a></p> <p>Using the image in the article, I want "Immediate Element #1" to initiate (raise) an event and then have "Immediate Element #2" handle that event. I'd like to achieve this without having to put any code in the "Root Element".</p> <p>Basically fire an event (save, status updated, selection changed, etc..) from any where in my app, then have it be handled somewhere else with out the 2 parties knowing anything about each other. Is this possible?</p> <p>I dont believe data bainding is the answer. I'd like to use Routed Events / Commands as they were designed just across the entire tree, not just within the source control's branch. Maybe it can't be done using routed events / commands, and data binding is the answer. I just dont know...</p> <p>Any ideas?</p>
[ { "answer_id": 184314, "author": "David Schmitt", "author_id": 4918, "author_profile": "https://Stackoverflow.com/users/4918", "pm_score": 1, "selected": false, "text": "Binding Style DataTriggers" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184292", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
184,309
<p>I know there are <a href="https://stackoverflow.com/questions/11737/net-library-to-unzip-zip-and-rar-files">libraries out there for working with ZIP files</a>. And, you can alternatively <a href="https://stackoverflow.com/questions/30211/windows-built-in-zip-compression-script-able">use the functionality built into Windows for working ZIP files</a>.</p> <p>But, I'm wondering if anyone has worked out how to use the tools built into the System.IO.Compression namespace within .NET for reading/writing ZIP files? Or, is it not possible using only this namespace?</p> <p>UPDATED: I've seem someone comment that the System.IO.Packaging namespace might be usefull with this also. Does anyone know exactly how to do it?</p>
[ { "answer_id": 184529, "author": "Sean Hanley", "author_id": 7290, "author_profile": "https://Stackoverflow.com/users/7290", "pm_score": 0, "selected": false, "text": "myDataSet.WriteXML() if (CompressData)\n{\n // Write to memory\n mStream = new MemoryStream();\n Save(mStream);\n mStream.Seek(0, SeekOrigin.Begin);\n\n // Filter that through a GZipStream and then to file\n fStream = new FileStream(Path.Combine(CacheFilePath, FileName + \".gz\"),\n FileMode.OpenOrCreate);\n zipStream = new GZipStream(fStream, CompressionMode.Compress, true);\n\n Pump(mStream, zipStream);\n}\nelse\n{\n // Write straight to file\n fStream = new FileStream(Path.Combine(CacheFilePath, FileName),\n FileMode.OpenOrCreate);\n Save(fStream);\n}\n Save() Pump() private void Pump(Stream input, Stream output)\n{\n int n;\n byte[] bytes = new byte[4096]; // 4KiB at a time\n\n while ((n = input.Read(bytes, 0, bytes.Length)) != 0)\n {\n output.Write(bytes, 0, n);\n }\n}\n\npublic void Save(Stream stream)\n{\n AcceptChanges();\n\n WriteXml(stream, XmlWriteMode.WriteSchema);\n}\n" }, { "answer_id": 410397, "author": "Cheeso", "author_id": 48082, "author_profile": "https://Stackoverflow.com/users/48082", "pm_score": 3, "selected": false, "text": " try\n {\n using (ZipFile zip = new ZipFile())\n {\n zip.AddDirectory(DirectoryToZip); // recurses subdirs\n zip.Save(Filename);\n }\n }\n catch (System.Exception ex1)\n {\n System.Console.Error.WriteLine(\"exception: \" + ex1);\n }\n" }, { "answer_id": 16728995, "author": "muhammedkasva", "author_id": 814100, "author_profile": "https://Stackoverflow.com/users/814100", "pm_score": 0, "selected": false, "text": " public static void zIpDatabseFile(string srcPath, string destPath)\n {//This is for Zip a File\n using (var source = new FileStream(srcPath, FileMode.Open, FileAccess.Read, FileShare.Read))\n using (var dest = new FileStream(destPath, FileMode.OpenOrCreate, FileAccess.Write))\n using (var zip = new GZipStream(dest, CompressionMode.Compress))\n {\n source.CopyTo(zip);\n }\n }\n public static void uNzIpDatabaseFile(string SrcPath, string DestPath)\n {// This is for unzip a files.\n using (var source = new FileStream(SrcPath, FileMode.Open, FileAccess.Read, FileShare.Read))\n using (var dest = new FileStream(DestPath, FileMode.OpenOrCreate, FileAccess.Write))\n using (var zip = new GZipStream(source, CompressionMode.Decompress))\n {\n zip.CopyTo(dest);\n }\n }\n" }, { "answer_id": 20006189, "author": "Christopher Currens", "author_id": 721276, "author_profile": "https://Stackoverflow.com/users/721276", "pm_score": 3, "selected": false, "text": "System.IO.Compression GZipStream Deflate ZipArchive ZipArchive" }, { "answer_id": 72510112, "author": "hatem87", "author_id": 3182650, "author_profile": "https://Stackoverflow.com/users/3182650", "pm_score": 0, "selected": false, "text": "System.IO.Compression.ZipFile.ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName);\nSystem.IO.Compression.ZipFile.CreateFromDirectory(directoryToArchivePath, archiveDestinationPath);\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184309", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7831/" ]
184,312
<p>I am building Java web applications, and I hate the traditional "code-compile-deploy-test" cycle. I want to type in one tiny change, then see the result INSTANTLY, without having to compile and deploy.</p> <p>Fortunately, <a href="http://www.mortbay.org/jetty/" rel="noreferrer">Jetty</a> is great for this. It is a pure-java web server. It comes with a really nice <a href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin" rel="noreferrer">maven plugin</a> which lets you launch Jetty reading directly from your build tree -- no need to package a war file or deploy. It even has a scanInterval setting: put this to a non-zero value and it will watch your java files and various config files for changes and automatically re-deploy a few seconds after you make a change.</p> <p>There's just one thing keeping me from nirvana. I have javascript and css files in my src/main/webapp directory which just get served up by Jetty. I would like to be able to edit <em>these</em> and have the changes show up when I refresh the page in the browser. Unfortunately, Jetty holds these files open so I can't (on Windows) modify them while it is running.</p> <p>Does anyone know how to make Jetty let go of these files so I can edit them, then serve up the edited files for subsequent requests?</p>
[ { "answer_id": 185675, "author": "Athena", "author_id": 17846, "author_profile": "https://Stackoverflow.com/users/17846", "pm_score": 5, "selected": true, "text": "useFileMappedBuffer DefaultServlet false" }, { "answer_id": 4985717, "author": "kybernetikos", "author_id": 412335, "author_profile": "https://Stackoverflow.com/users/412335", "pm_score": 4, "selected": false, "text": "// Startup stuff\nfinal Server server = new Server(port);\nServletContextHandler handler = new ServletContextHandler();\nhandler.setResourceBase(path);\n\nSessionManager sm = new HashSessionManager();\nSessionHandler sh = new SessionHandler(sm);\nhandler.setSessionHandler(sh);\n\nDefaultServlet defaultServlet = new DefaultServlet();\nServletHolder holder = new ServletHolder(defaultServlet);\nholder.setInitParameter(\"useFileMappedBuffer\", \"false\");\nhandler.addServlet(holder, \"/\");\n\nserver.setHandler(handler);\nserver.start();\nserver.join();\n" }, { "answer_id": 11004449, "author": "FUD", "author_id": 552525, "author_profile": "https://Stackoverflow.com/users/552525", "pm_score": 3, "selected": false, "text": " <plugin>\n <groupId>org.mortbay.jetty</groupId>\n <artifactId>jetty-maven-plugin</artifactId>\n <configuration>\n <connectors>\n <connector implementation=\"org.eclipse.jetty.server.bio.SocketConnector\">\n <port>8080</port>\n </connector>\n </connectors>\n </configuration>\n </plugin>\n" }, { "answer_id": 16235377, "author": "David Roussel", "author_id": 191084, "author_profile": "https://Stackoverflow.com/users/191084", "pm_score": 0, "selected": false, "text": "DefaultServlet SelectChannelConnector org.mortbay.jetty.bio.SocketConnector import org.eclipse.jetty.io.Buffers.Type;\nimport org.eclipse.jetty.server.nio.SelectChannelConnector;\n\n/**\n * A Connector that has the advantages NIO, but doesn't lock files in Windows by\n * avoiding memory mapped buffers.\n * <p> \n * It used to be that you could avoid this problem by setting \"useFileMappedBuffer\" as described in \n * http://stackoverflow.com/questions/184312/how-to-make-jetty-dynamically-load-static-pages\n * However that approach doesn't seem to work in newer versions of jetty.\n * \n * @author David Roussel\n * \n */\npublic class SelectChannelConnectorNonLocking extends SelectChannelConnector {\n\n public SelectChannelConnectorNonLocking() {\n super();\n\n // Override AbstractNIOConnector and use all indirect buffers\n _buffers.setRequestBufferType(Type.INDIRECT);\n _buffers.setRequestHeaderType(Type.INDIRECT);\n _buffers.setResponseBufferType(Type.INDIRECT);\n _buffers.setResponseHeaderType(Type.INDIRECT);\n }\n}\n" }, { "answer_id": 25608829, "author": "Johannes Brodwall", "author_id": 27658, "author_profile": "https://Stackoverflow.com/users/27658", "pm_score": 2, "selected": false, "text": "// Startup stuff\nfinal Server server = new Server(port);\nWebAppContext webAppContext = new WebAppContext(path, \"/\")\nwebAppContext.setInitParam(\n \"org.eclipse.jetty.servlet.Default.useFileMappedBuffer\", \"false\");\n\nserver.setHandler(webAppContext);\nserver.start();\nserver.join();\n" }, { "answer_id": 30384006, "author": "Julien Kronegg", "author_id": 698168, "author_profile": "https://Stackoverflow.com/users/698168", "pm_score": 3, "selected": false, "text": "ResourceHandler // Create a basic Jetty server object that will listen on port 8080. Note that if you set this to port 0\n// then a randomly available port will be assigned that you can either look in the logs for the port,\n// or programmatically obtain it for use in test cases.\nServer server = new Server(8080);\n\n// Create the ResourceHandler. It is the object that will actually handle the request for a given file. It is\n// a Jetty Handler object so it is suitable for chaining with other handlers as you will see in other examples.\nResourceHandler resource_handler = new ResourceHandler();\n// Configure the ResourceHandler. Setting the resource base indicates where the files should be served out of.\n// In this example it is the current directory but it can be configured to anything that the jvm has access to.\nresource_handler.setDirectoriesListed(true);\nresource_handler.setWelcomeFiles(new String[]{ \"index.html\" });\nresource_handler.setResourceBase(\".\");\n\n// Add the ResourceHandler to the server.\nHandlerList handlers = new HandlerList();\nhandlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });\nserver.setHandler(handlers);\n\n// Start things up! By using the server.join() the server thread will join with the current thread.\n// See \"http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()\" for more details.\nserver.start();\nserver.join();\n resource_handler.setMinMemoryMappedContentLength(-1);\n the minimum size in bytes of a file resource that will be served using a memory mapped buffer, or -1 for no memory mapped buffers Integer.MAX_VALUE" }, { "answer_id": 35863046, "author": "Yurii Bondarenko", "author_id": 1690578, "author_profile": "https://Stackoverflow.com/users/1690578", "pm_score": 3, "selected": false, "text": "my-web-app/jetty/jetty-config.xml <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Configure class=\"org.eclipse.jetty.webapp.WebAppContext\">\n <Call name=\"setInitParameter\">\n <Arg>org.eclipse.jetty.servlet.Default.useFileMappedBuffer</Arg>\n <Arg>false</Arg>\n </Call>\n</Configure>\n <plugin>\n <groupId>org.eclipse.jetty</groupId>\n <artifactId>jetty-maven-plugin</artifactId>\n <configuration>\n <httpConnector>\n <host>localhost</host>\n <port>8801</port>\n </httpConnector>\n <webApp>\n <contextPath>/${project.artifactId}</contextPath>\n </webApp>\n <contextXml>${project.basedir}/jetty/jetty-config.xml</contextXml>\n </configuration>\n</plugin>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14570/" ]
184,313
<p>I have this .NET regex:</p> <pre><code>^(?&lt;prefix&gt;("[^"]*"))\s(?&lt;attrgroup&gt;(\([^\)]*\)))\s(?&lt;suffix&gt;("[^"]*"))$ </code></pre> <p>It properly matches the following strings:</p> <pre><code>"some prefix" ("attribute 1" "value 1") "some suffix" "some prefix" ("attribute 1" "value 1" "attribute 2" "value 2") "some suffix" </code></pre> <p>It fails on...</p> <pre><code>"some prefix" ("attribute 1" "value (fail) 1") "some suffix" </code></pre> <p>...due to the right paren after "fail".</p> <p>How can I modify my regex so that the <code>attrgroup</code> match group will end up containing "<code>("attribute 1" "value (fail) 1")</code>"? I've been looking at it for too long and need some fresh eyes. Thanks!</p> <p><strong>Edit:</strong> <code>attrgroup</code> won't ever contain anything other than pairs of double-quoted strings.</p>
[ { "answer_id": 184392, "author": "hometoast", "author_id": 2009, "author_profile": "https://Stackoverflow.com/users/2009", "pm_score": 1, "selected": false, "text": "^(?<prefix>\"[^\"]*\")\\s+(?<attrgroup>\\(.*\\))\\s+(?<suffix>\"[^\"]*\")$\n" }, { "answer_id": 184451, "author": "Patrick Huizinga", "author_id": 15200, "author_profile": "https://Stackoverflow.com/users/15200", "pm_score": 3, "selected": true, "text": "^(?<prefix>(\"[^\"]*\"))\\s(?<attrgroup>(\\((\"[^\"]*\")(\\s(\"[^\"]*\")*)**\\)))\\s(?<suffix>(\"[^\"]*\"))$\n [^\\)]*\n (\"[^\"]*\")(\\s(\"[^\"]*\")*)*\n" }, { "answer_id": 187148, "author": "Tetha", "author_id": 17663, "author_profile": "https://Stackoverflow.com/users/17663", "pm_score": 0, "selected": false, "text": "def parse_String(string):\n index = skip_spaces(string, 0)\n index, prefix = read_prefix(string, index)\n index = skip_spaces(string, index)\n index, attrgroup = read_attrgroup(string, index)\n index = skip_spaces(string, index)\n index, suffix = read_suffix(string, index)\n return prefix, attrgroup, suffix\n\ndef read_prefix(string, start_index):\n return read_quoted_string(string, start_index) \n\ndef read_attrgroup(string, start_index):\n end_index, content = read_paren(string, start_index)\n\n index = skip_spaces(content, 0)\n index, first_entry = read_quoted_string(content, index)\n index = skip_spaces(content, index)\n index, second_entry = read_quoted_string(content, index)\n return end_index, (first_entry, second_entry)\n\n\ndef read_suffix(string, start_index):\n return read_quoted_string(string, start_index)\n\ndef read_paren(string, start_index):\n return read_delimited_string(string, start_index, '(', ')')\n\ndef read_quoted_string(string, start_index):\n return read_delimited_string(string, start_index, '\"', '\"')\n\ndef read_delimited_string(string, starting_index, start_limiter, end_limiter):\n assert string[starting_index] == start_limiter, (start_limiter \n +\"!=\" \n +string[starting_index])\n current_index = starting_index+1\n content = \"\"\n while(string[current_index] != end_limiter):\n content += string[current_index]\n current_index += 1\n\n assert string[current_index] == end_limiter\n return current_index+1, content\n\ndef skip_spaces(string, index):\n while string[index] == \" \":\n index += 1\n return index\n def parse_string(string):\n prefix = read_prefix()\n attrgroup = read_attr_group()\n suffix = read_suffix()\n return prefix, attrgroup, suffix.\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3447/" ]
184,340
<p>I have an application that manages patient demographic information. Along with this data a user can scan a picture of a patient and assign that picture to a patient. When the user clicks the scan button a separate application is opened as a dialog in order to scan the image. When running this on XP everything worked fine. The imaging application loaded up fine and gained focus. On Vista however occasionally the imaging application will not gain focus and will popup behind the main application. When running full screen or through 2008 Application Server you cannot see the application, you only get a locked screen and it appears nothing has happened. Is there any way to change the window focus management on Vista to work the way XP did? I'm looking for a way to solve this without making changes to the actual application if possible.</p>
[ { "answer_id": 184422, "author": "Bradley Grainger", "author_id": 23633, "author_profile": "https://Stackoverflow.com/users/23633", "pm_score": 1, "selected": false, "text": "ShellExecute CreateProcess SHELLEXECUTEINFO.hProcess ShellExecute PROCESS_INFORMATION.hProcess CreateProcess AllowSetForegroundWindow(GetProcessId(hProcess));\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25511/" ]
184,409
<p>The documentation for <code>+[NSThread detachNewThreadSelector:toTarget:withObject:]</code> says:</p> <blockquote> <p>For non garbage-collected applications, the method <code>aSelector</code> is responsible for setting up an autorelease pool for the newly detached thread and freeing that pool before it exits.</p> </blockquote> <p>My question is, do I need to create my own <code>NSAutoreleasePool</code> in my override of the <code>-[NSOperation main]</code> method, or is the creation of the <code>NSAutoreleasePool</code> handled by <code>NSOperation</code>?</p>
[ { "answer_id": 185954, "author": "Barry Wark", "author_id": 2140, "author_profile": "https://Stackoverflow.com/users/2140", "pm_score": 2, "selected": false, "text": "NSAutoreleasePool [NSOperation main] NSOperation [NSOperation start] NSAutoreleasePool NSOperation" }, { "answer_id": 1606179, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "- (void) main\n{\n NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init];\n //your code here\n //more code\n [thePool release];\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23028/" ]
184,414
<p>I have one action I want to perform when a TSpeedButton is pressed and another I want to perform when the same button is "unpressed". I know there's no onunpress event, but is there any easy way for me to get an action to execute when a different button is pressed? </p> <pre><code>procedure ActionName.ActionNameExecute(Sender: TObject); begin PreviousActionName.execute(Sender); // end; </code></pre> <p>Seems too clunky.</p>
[ { "answer_id": 185954, "author": "Barry Wark", "author_id": 2140, "author_profile": "https://Stackoverflow.com/users/2140", "pm_score": 2, "selected": false, "text": "NSAutoreleasePool [NSOperation main] NSOperation [NSOperation start] NSAutoreleasePool NSOperation" }, { "answer_id": 1606179, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "- (void) main\n{\n NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init];\n //your code here\n //more code\n [thePool release];\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1765/" ]
184,431
<p>I'm trying to convert an XML file into the markup used by dokuwiki, using XSLT. This actually works to some degree, but the indentation in the XSL file is getting inserted into the results. At the moment, I have two choices: abandon this XSLT thing entirely, and find another way to convert from XML to dokuwiki markup, or delete about 95% of the whitespace from the XSL file, making it nigh-unreadable and a maintenance nightmare.</p> <p>Is there some way to keep the indentation in the XSL file without passing all that whitespace on to the final document?</p> <p>Background: I'm migrating an autodoc tool from static HTML pages over to dokuwiki, so the API developed by the server team can be further documented by the applications team whenever the apps team runs into poorly-documented code. The logic is to have a section of each page set aside for the autodoc tool, and to allow comments anywhere outside this block. I'm using XSLT because we already have the XSL file to convert from XML to XHTML, and I'm assuming it will be faster to rewrite the XSL than to roll my own solution from scratch.</p> <p><i>Edit: Ah, right, foolish me, I neglected the indent attribute. (Other background note: I am new to XSLT.) On the other hand, I still have to deal with newlines. Dokuwiki uses pipes to differentiate between table columns, which means that all of the data in a table line must be on one line. Is there a way to suppress newlines being outputted (just occasionally), so I can do some fairly complex logic for each table cell in a somewhat readable fasion?</i></p>
[ { "answer_id": 184449, "author": "Lindsay", "author_id": 23520, "author_profile": "https://Stackoverflow.com/users/23520", "pm_score": 2, "selected": false, "text": "<xsl:output method=\"text\" indent=\"no\" />\n" }, { "answer_id": 184931, "author": "Odilon Redo", "author_id": 21166, "author_profile": "https://Stackoverflow.com/users/21166", "pm_score": 0, "selected": false, "text": "<xsl:template name=\"replace.string.section\">\n <xsl:param name=\"in.string\"/>\n <xsl:param name=\"in.characters\"/>\n <xsl:param name=\"out.characters\"/>\n <xsl:choose>\n <xsl:when test=\"contains($in.string,$in.characters)\">\n <xsl:value-of select=\"concat(substring-before($in.string,$in.characters),$out.characters)\"/>\n <xsl:call-template name=\"replace.string.section\">\n <xsl:with-param name=\"in.string\" select=\"substring-after($in.string,$in.characters)\"/>\n <xsl:with-param name=\"in.characters\" select=\"$in.characters\"/>\n <xsl:with-param name=\"out.characters\" select=\"$out.characters\"/>\n </xsl:call-template>\n </xsl:when>\n <xsl:otherwise>\n <xsl:value-of select=\"$in.string\"/>\n </xsl:otherwise>\n </xsl:choose>\n</xsl:template> \n <xsl:call-template name=\"replace.string.section\">\n <xsl:with-param name=\"in.string\" select=\"$some.string\"/>\n <xsl:with-param name=\"in.characters\" select=\"'&#xA;'\"/>\n <xsl:with-param name=\"out.characters\" select=\"' '\"/>\n </xsl:call-template>\n" }, { "answer_id": 185048, "author": "JeniT", "author_id": 6739, "author_profile": "https://Stackoverflow.com/users/6739", "pm_score": 7, "selected": true, "text": "<xsl:strip-space> <xsl:preserve-space> <ul>\n <li>This is an <strong>important</strong> <em>point</em></li>\n</ul>\n <ul> <li> </li> </ul> <strong> <em> <xsl:strip-space elements=\"*\" />\n<xsl:preserve-space elements=\"li\" />\n elements <xsl:preserve-space> <xsl:strip-space> normalize-space() <dt>\n a definition\n</dt>\n <dt> <xsl:template match=\"dt\">\n ...\n <xsl:value-of select=\"normalize-space(.)\" />\n ...\n</xsl:template>\n <dt> \"a definition\" <xsl:template match=\"name\">\n Name:\n <xsl:value-of select=\".\" />\n</xsl:template>\n <xsl:template> match <xsl:value-of> select <xsl:value-of> <xsl:template> <xsl:text> <xsl:template match=\"name\">\n <xsl:text>Name: </xsl:text>\n <xsl:value-of select=\".\" />\n</xsl:template>\n <xsl:text>" }, { "answer_id": 4703908, "author": "Dan", "author_id": 95559, "author_profile": "https://Stackoverflow.com/users/95559", "pm_score": 2, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE xsl:transform [\n <!ENTITY s \"<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> </xsl:text>\" >\n <!ENTITY s2 \"<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> </xsl:text>\" >\n <!ENTITY s4 \"<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> </xsl:text>\" >\n <!ENTITY s6 \"<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> </xsl:text>\" >\n <!ENTITY e \"<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform'></xsl:text>\" >\n <!ENTITY n \"<xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n</xsl:text>\" >\n]>\n\n<xsl:transform version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n<xsl:output method=\"text\"/>\n<xsl:template match=\"/\">\n &e;Flush left, despite the indentation.&n;\n &e; This line will be output indented two spaces.&n;\n\n <!-- the blank lines above/below won't be output -->\n\n <xsl:for-each select=\"//foo\">\n &e; Starts with two blanks: <xsl:value-of select=\"@bar\"/>.&n;\n &e; <xsl:value-of select=\"@baz\"/> The 'e' trick won't work here.&n;\n &s2;<xsl:value-of select=\"@baz\"/> Use s2 instead.&n;\n &s2; <xsl:value-of select=\"@abc\"/> <xsl:value-of select=\"@xyz\"/>&n;\n &s2; <xsl:value-of select=\"@abc\"/>&s;<xsl:value-of select=\"@xyz\"/>&n;\n </xsl:for-each>\n</xsl:template>\n</xsl:transform>\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo bar=\"bar\" baz=\"baz\" abc=\"abc\" xyz=\"xyz\"></foo>\n Flush left, despite the indentation.\n This line will be output indented two spaces.\n Starts with two blanks: bar.\nbaz The 'e' trick won't work here.\n baz Use s2 instead.\n abcxyz\n abc xyz\n <xsl:template match=\"/\">\n <xsl:text></xsl:text>Flush left, despite the indentation.<xsl:text>\n</xsl:text>\n \" This line will be output indented two spaces.\" <xsl:template match=\"/\">\n <xsl:text>Flush left, despite the indentation.</xsl:text>\n <xsl:text> This line will be output indented two spaces.</xsl:text>\n <xsl:for-each select=\"//foo\">\n <xsl:text> Starts with two blanks: </xsl:text><xsl:value-of select=\"@bar\"/>.<xsl:text>\n</xsl:text>\n <xsl:text> </xsl:text><xsl:value-of select=\"@abc\"/><xsl:text> </xsl:text><xsl:value-of select=\"@xyz\"/><xsl:text>\n</xsl:text>\n </xsl:for-each>\n</xsl:template>\n </xsl:text>" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26257/" ]
184,436
<p>I'm working with an old Access database (yes, it's very ugly and I hate it). I need to modify some of the columns from a VB app that I'm creating. I have most the modifications setup correctly, but I'm fighting with the fact that modifying a column to text has it default to "Allow Zero Length" to false.</p> <p>SO ALTER TABLE [Applicant Table] ALTER COLUMN [Applicant ID] Text(255)</p> <p>I need that alter to have "Allow Zero Length" set to true.</p> <p>I have tried ALTER TABLE [Applicant Table] ALTER COLUMN [Applicant ID] Text(255) NULL</p> <p>but that doesn't seem to work either. I've looked all over for the solution, but can't seem to find a straight answer.</p> <p>Any ideas?</p> <p>Thanks, Ryan.</p> <hr> <p>Thanks for the info. I'm glad that it's Access and not me.</p> <p>I guess I'm just going to hack my way through this application since the entire data model is trash anyway.</p>
[ { "answer_id": 184575, "author": "Chris OC", "author_id": 11041, "author_profile": "https://Stackoverflow.com/users/11041", "pm_score": 3, "selected": true, "text": "Public Function setAllowZeroLenStr() \n On Error GoTo Proc_Err\n\n Dim db As Database\n Dim tbl As TableDef\n Dim fld As DAO.Field\n\n Set db = CurrentDb\n Set tbl = db.TableDefs![Applicant Table]\n Set fld = tbl.Fields![Applicant ID]\n fld.AllowZeroLength = True\n\nProc_Exit: \n Set fld = Nothing\n Set tbl = Nothing\n Set db = Nothing\n\n Exit Function\n\nProc_Err: \n MsgBox Err.Number & vbCrLf & Err.Description\n Err.Clear\n Resume Proc_Exit \nEnd Function\n" }, { "answer_id": 184774, "author": "onedaywhen", "author_id": 15354, "author_profile": "https://Stackoverflow.com/users/15354", "pm_score": 2, "selected": false, "text": "ALTER TABLE [Applicant Table] ADD\n CONSTRAINT Applicant_ID__not_zero_length \n CHECK (LEN([Applicant ID]) > 0);\n DROP" }, { "answer_id": 12194088, "author": "andy", "author_id": 1547591, "author_profile": "https://Stackoverflow.com/users/1547591", "pm_score": 0, "selected": false, "text": " DBLib dbLib = new DBLib();\n dbLib.ConnectionString = ConnectionString;\n dbLib.Initialize(); \n dbLib.ModifyTextFieledSetAllowZeroLength(ref TableName, ref FiledName);\n" }, { "answer_id": 66270762, "author": "John Argus", "author_id": 8613038, "author_profile": "https://Stackoverflow.com/users/8613038", "pm_score": 0, "selected": false, "text": "Sub SetUpTempDbExample()\n' Set up a temp database for running report data into.\n' Temp DB is killed and re-created on demand (saves having to compact and repair in primary DB).\n' Temp table can be relinked to primary DB for further querying\nDim dbTemp As Database\nDim tblTemp As TableDef\nDim idxTemp As Index, idxTemp2 As Index\nConst cTempPath = \"C:\\temp\\\"\nConst cTempDB = \"TempReportData\"\n\n ' Delete old temp database (if db is in use, Kill will fail. Resume gracefully.)\n On Error Resume Next\n If Dir(cTempPath & cTempDB) <> \"\" Then Kill (cTempPath & cTempDB)\n\n On Error GoTo ErrHandler\n \n ' Create a new temp DB.\n Set dbTemp = CreateDatabase(cTempPath & cTempDB, dbLangGeneral)\n\n Set tblTemp = dbTemp.CreateTableDef(\"TEMP_SAMPLES\")\n \n With tblTemp\n .Fields.Append .CreateField(\"SAMPLE_ID\", dbDouble)\n .Fields.Append .CreateField(\"SITE_ID\", dbText, 38)\n .Fields.Append .CreateField(\"SAMPLE_DATE_TIME\", dbDate)\n .Fields.Append .CreateField(\"METHOD\", dbText, 20)\n .Fields.Append .CreateField(\"MATRIX\", dbText, 20)\n .Fields.Append .CreateField(\"COMMENT\", dbText, 255)\n .Fields![COMMENT].AllowZeroLength = True\n Set idxTemp = .CreateIndex(\"SAMPLE_ID\")\n idxTemp.Fields.Append .CreateField(\"SAMPLE_ID\")\n idxTemp.Primary = True\n Set idxTemp2 = .CreateIndex(\"SITE_ID\")\n idxTemp2.Fields.Append .CreateField(\"SITE_ID\")\n End With\n dbTemp.TableDefs.Append tblTemp\n tblTemp.Indexes.Append idxTemp\n tblTemp.Indexes.Append idxTemp2\n\n Set tblTemp = Nothing\n Set idxTemp = Nothing\n Set dbTemp = Nothing\n\nExitSub:\n Exit Sub\n\nErrHandler:\n MsgBox Err.Description & \" (\" & Err.Number & \")\"\n Resume ExitSub\nEnd Sub\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10420/" ]
184,448
<p>I maintain an application that uses the win32 EnumPorts() function to help determine the set of serial ports installed on the computer. I have seen cases on some computers where the call to get this information fails with a GetLastError() code of 1722 (RPC server is unavailable). I assume that this has something to do with either registry settings or a required service being disabled but my search so far has been rather fruitless. Has anyonw else encountered this issue?</p> <p>In answer to Euro Micelli's comments. I am specifically attempting to fill a pick list that will allow the user to choose an available picklist. To begin with, I relied exclusively on EnumPorts() to provide me a list of potential serial port names. It has proven to be unreliable, however in several senses: It has not always provided the complete set of port names and, as I have recently seen, it can fail to function altogether when the "RPC service is unavailable". Why RPC is needed to find out what ports are available on the local machine is completely beyond me but there it is. This latter problem was the final straw. So far as relying completely on the list of names provided, i filter these names using the GetDefaultCommConfig() function to determine the exact nature of each of the names that I came up with.</p> <p>In my experience, the list of names provided by the previously mentioned registry key has been the most reliable method for getting port names. As a matter of fact, I can see the key get updated as I disable port drivers in the device device manager. Under normal experiences, I would agree with the assessment that relying upon a particular key is fraught with peril. In this case, however, M$ has never provided a decent mechanism to evaluate the names of available ports.</p> <p>I should point out that I have already replaced the call to EnumPorts() with an algorithm that scans the registry key: HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM for serial port names. This should resolve the issue once my software is released. What I am after is pointers that can be given to customers who are using the released package at the present.</p>
[ { "answer_id": 25234746, "author": "Valdar Moridin", "author_id": 2499546, "author_profile": "https://Stackoverflow.com/users/2499546", "pm_score": 0, "selected": false, "text": "RPC Server is unavailable" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184448", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19674/" ]
184,456
<p>Converting a couple stored procedures from MySQL to Microsoft SQL server. Everything is going well, except one procedure used the MySQL <code>SHA1()</code> function. I cannot seem to find an equivalent to this in MS-SQL.</p> <p>Does anyone know a valid equivalent for <code>SHA1()</code> on MS-SQL?</p>
[ { "answer_id": 12207895, "author": "Peter", "author_id": 460053, "author_profile": "https://Stackoverflow.com/users/460053", "pm_score": 5, "selected": false, "text": "SELECT sys.fn_varbintohexsubstring(0, HashBytes('SHA1', 'password'), 1, 0)\n" }, { "answer_id": 65934009, "author": "mr R", "author_id": 1831734, "author_profile": "https://Stackoverflow.com/users/1831734", "pm_score": 2, "selected": false, "text": "HASHBYTES('SHA1', CAST('abcd@#' as nvarchar(max)))\nCONVERT(VARCHAR(MAX), HASHBYTES('SHA1', CAST('abcd@#' as nvarchar(max))) , 2)\n\n/* result */\n0x77DD873DBAB2D81786AB9AE6EA91B1F59980E48C \n77DD873DBAB2D81786AB9AE6EA91B1F59980E48C\n using (SHA1Managed sha1 = new SHA1Managed())\n{\n string input = \"abcd@#\";\n var hash = sha1.ComputeHash(Encoding.Unicode.GetBytes(input));\n var sb = new StringBuilder(hash.Length * 2);\n \n foreach (byte b in hash)\n {\n sb.Append(b.ToString(\"X2\")); // can be \"x2\" if you want lowercase\n }\n return sb.ToString();\n}\n//result \"77DD873DBAB2D81786AB9AE6EA91B1F59980E48C\"\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5640/" ]
184,471
<p>Replaces Question: <a href="https://stackoverflow.com/questions/184096/update-multiple-rows-into-sql-table">Update multiple rows into SQL table</a></p> <p>Here's a Code Snippet to update an exam results set. DB structure is as given, but I can submit Stored Procedures for inclusion (Which are a pain to modify, so I save that until the end.)</p> <p>The question: Is there a better way using SQL server v 2005.,net 2.0 ?</p> <pre><code>string update = @"UPDATE dbo.STUDENTAnswers SET ANSWER=@answer WHERE StudentID =@ID and QuestionNum =@qnum"; SqlCommand updateCommand = new SqlCommand( update, conn ); conn.Open(); string uid = Session["uid"].ToString(); for (int i= tempStart; i &lt;= tempEnd; i++) { updateCommand.Parameters.Clear(); updateCommand.Parameters.AddWithValue("@ID",uid); updateCommand.Parameters.AddWithValue("@qnum",i); updateCommand.Parameters.AddWithValue("@answer", Request.Form[i.ToString()]); try { updateCommand.ExecuteNonQuery(); } catch { } } </code></pre>
[ { "answer_id": 184503, "author": "Hafthor", "author_id": 4489, "author_profile": "https://Stackoverflow.com/users/4489", "pm_score": -1, "selected": false, "text": "UPDATE s SET ANSWER=a FROM dbo.STUDENTAnswers s JOIN (\n SELECT 1 as q, 'answer1' as a\n UNION ALL SELECT 2, 'answer2' -- etc...\n) x ON s.QuestionNum=x.q AND StudentID=@ID\n using(SqlCommand updateCommand = new SqlCommand()) {\n updateCommand.CommandType = CommandType.Text;\n updateCommand.Connection = conn;\n if (cn.State != ConnectionState.Open) conn.Open();\n\n StringBuilder sb = new StringBuilder(\"UPDATE s SET ANSWER=a FROM dbo.STUDENTAnswers s JOIN (\");\n string fmt = \"SELECT {0} as q, @A{0} as a\";\n for(int i=tempStart; i<tempEnd; i++) {\n sb.AppendFormat(fmt, i);\n fmt=\" UNION ALL SELECT {0},@A{0}\";\n updateCommand.Parameters.AddWithValue(\"@A\"+i.ToString(), Request.Form[i.ToString()]);\n }\n sb.Append(\") x ON s.QuestionNum=x.q AND StudentID=@ID\");\n updateCommand.CommandText = sb.ToString();\n updateCommand.Parameters.AddWithValue(\"@ID\", uid);\n updateCommand.ExecuteNonQuery();\n}\n" }, { "answer_id": 184657, "author": "mancaus", "author_id": 13797, "author_profile": "https://Stackoverflow.com/users/13797", "pm_score": 2, "selected": false, "text": "updateCommand SqlBulkCopy" }, { "answer_id": 184659, "author": "Joe", "author_id": 13087, "author_profile": "https://Stackoverflow.com/users/13087", "pm_score": 3, "selected": true, "text": "using (SqlConnection conn = new SqlConnection(connectionString))\n{\n conn.Open();\n using (SqlCommand updateCommand = new SqlCommand(update, conn))\n {\n string uid = Session[\"uid\"].ToString();\n updateCommand.Parameters.AddWithValue(\"@ID\", uid);\n updateCommand.Parameters.AddWithValue(\"@qnum\", i);\n updateCommand.Parameters.Add(\"@answer\", System.Data.SqlDbType.VarChar);\n for (int i = tempStart; i <= tempEnd; i++)\n {\n updateCommand.Parameters[\"@answer\"] = Request.Form[i.ToString()];\n updateCommand.ExecuteNonQuery();\n }\n }\n}\n using (SqlConnection conn = new SqlConnection(connectionString))\n{\n conn.Open();\n using (SqlTransaction transaction = conn.BeginTransaction())\n {\n using (SqlCommand updateCommand = new SqlCommand(update, conn, transaction))\n {\n string uid = Session[\"uid\"].ToString();\n updateCommand.Parameters.AddWithValue(\"@ID\", uid);\n updateCommand.Parameters.AddWithValue(\"@qnum\", i);\n updateCommand.Parameters.Add(\"@answer\", System.Data.SqlDbType.VarChar);\n for (int i = tempStart; i <= tempEnd; i++)\n {\n updateCommand.Parameters[\"@answer\"] = Request.Form[i.ToString()];\n updateCommand.ExecuteNonQuery();\n }\n transaction.Commit();\n }\n } // Transaction will be disposed and rolled back here if an exception is thrown\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18907/" ]
184,476
<p>I have been pushing into the .NET framework in PowerShell, and I have hit something that I don't understand. This works fine:</p> <pre><code>$foo = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]" $foo.Add("FOO", "BAR") $foo Key Value --- ----- FOO BAR </code></pre> <p>This however does not:</p> <pre><code>$bar = New-Object "System.Collections.Generic.SortedDictionary``2[System.String,System.String]" New-Object : Cannot find type [System.Collections.Generic.SortedDictionary`2[System.String,System.String]]: make sure t he assembly containing this type is loaded. At line:1 char:18 + $bar = New-Object &lt;&lt;&lt;&lt; "System.Collections.Generic.SortedDictionary``2[System.String,System.String]" </code></pre> <p>They are both in the same assembly, so what am I missing?</p> <p>As was pointed out in the answers, this is pretty much only an issue with PowerShell v1.</p>
[ { "answer_id": 185885, "author": "tomasr", "author_id": 10292, "author_profile": "https://Stackoverflow.com/users/10292", "pm_score": 5, "selected": true, "text": "$bar = new-object \"System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]\"\n" }, { "answer_id": 2202519, "author": "ShanePowser", "author_id": 266497, "author_profile": "https://Stackoverflow.com/users/266497", "pm_score": 6, "selected": false, "text": "Dictionary $object = New-Object 'system.collections.generic.dictionary[string,int]'\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184476", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1358/" ]
184,482
<p>I display data into an html table, w/ a drop down box with a list of venues. Each volunteer will be assigned a venue. I envision being able to go down thru the html table and assigning each volunteer a venue. The drop down box contains all the possible venues that they can be assigned to.</p> <pre><code>&lt;select&gt; &lt;option value="1"&gt;Setup&lt;/option&gt; &lt;option value="2"&gt;Check in&lt;/option&gt; etc... &lt;/select&gt; </code></pre> <p>Then once I am done assigning each volunteer, I want to hit submit and it will assign the appropriate value for each volunteer.</p> <p>How would I go about doing that, I know how to do that, but only one at a time.</p>
[ { "answer_id": 184517, "author": "Darryl Hein", "author_id": 5441, "author_profile": "https://Stackoverflow.com/users/5441", "pm_score": 0, "selected": false, "text": "UPDATE volunteer SET venue = 1 WHERE id = 2;\nUPDATE volunteer SET venue = 2 WHERE id = 3;\n...\n" }, { "answer_id": 184518, "author": "Tomasz Tybulewicz", "author_id": 17405, "author_profile": "https://Stackoverflow.com/users/17405", "pm_score": 3, "selected": true, "text": "<select name=\"venues[1]\">\n<option value=\"1\">Setup</option>\netc...\n</select>\n\n<select name=\"venues[2]\">\n<option value=\"1\">Setup</option>\netc...\n</select>\n\n<select name=\"venues[3]\">\n<option value=\"1\">Setup</option>\netc...\n</select>\n $_POST['venues'] foreach ($_POST['venues'] as $volunteer_id => $venue) {\n save_venue_for_volunteer($volunteer_id, $venue);\n}\n" }, { "answer_id": 184569, "author": "Peter Bailey", "author_id": 8815, "author_profile": "https://Stackoverflow.com/users/8815", "pm_score": 1, "selected": false, "text": "<?php\n\nif ( isset( $_POST['venuChoice'] ) )\n{\n // Create a transaction\n mysql_query( 'BEGIN' );\n\n $failure = false;\n\n // Loop over the selections\n foreach ( $_POST['venuChoice'] as $employeeId => $venueId )\n {\n $sql = sprintf(\n 'UPDATE table SET columns=%d WHERE id=%d'\n , intval( mysql_real_escape_string( $venueId ) )\n , intval( mysql_real_escape_string( $employeeId ) )\n );\n if ( ! @mysql_query( $sql ) )\n {\n $failure = true;\n break;\n }\n }\n\n // Close out the transaction\n if ( $failure )\n {\n mysql_query( 'ROLLBACK' );\n // Display and error or something\n } else {\n mysql_query( 'COMMIT' );\n // Success!\n }\n}\n\n?>\n\n<form>\n <select name=\"venueChoice[1]\">\n <option value=\"1\">Setup</option>\n <option value=\"2\">Check in</option>\n </select>\n <select name=\"venueChoice[2]\">\n <option value=\"1\">Setup</option>\n <option value=\"2\">Check in</option>\n </select>\n <select name=\"venueChoice[3]\">\n <option value=\"1\">Setup</option>\n <option value=\"2\">Check in</option>\n </select>\n\n</form>\n" }, { "answer_id": 245601, "author": "Brad", "author_id": 26130, "author_profile": "https://Stackoverflow.com/users/26130", "pm_score": 0, "selected": false, "text": "foreach ($_POST['venues'] as $volunteer_id => $venue) {\n save_venue_for_volunteer($volunteer_id, $venue);\n}\n\nfunction save_venue_for_volunteer($volunteer_id, $venue) {\n $result = mysql_query(\"UPDATE volunteers_2009 SET venue_id='$venue' WHERE id='$volunteer_id'\") \n or die(mysql_error());\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26130/" ]
184,489
<p>I am trying to retrieve an image stored in an oracle blob and place it in a new System.Drawing.Image instance. I know I can write the stream to a temp.bmp file on the disk and read it from there but thats just not l33t enough for me. How do I convert the blob object directly to an image?</p>
[ { "answer_id": 184577, "author": "osp70", "author_id": 2357, "author_profile": "https://Stackoverflow.com/users/2357", "pm_score": 0, "selected": false, "text": "Dim cn As SqlConnection = Nothing\n Dim cmd As SqlCommand = Nothing\n Dim da As SqlDataAdapter = Nothing\n Dim ms As MemoryStream = Nothing\n Dim dsImage As Data.DataSet = Nothing\n Dim myBytes() As Byte = Nothing\n Dim imgJPG As System.Drawing.Image = Nothing\n Dim msOut As MemoryStream = Nothing\n\n Try\n cn = New SqlConnection(ConnectionStrings(\"conImageDB\").ToString)\n cmd = New SqlCommand(AppSettings(\"sprocGetImage\").ToString, cn)\n cmd.CommandType = Data.CommandType.StoredProcedure\n\n cmd.Parameters.AddWithValue(\"@dmhiRowno\", irowno)\n\n da = New SqlDataAdapter(cmd)\n\n dsImage = New Data.DataSet\n da.Fill(dsImage, \"image\")\n\n If dsImage.Tables(0).Rows.Count = 0 Then\n Throw New Exception(\"No results returned for rowno\")\n End If\n myBytes = dsImage.Tables(0).Rows(0)(\"Frontimage\")\n\n ms = New MemoryStream\n ms.Write(myBytes, 0, myBytes.Length)\n\n imgJPG = System.Drawing.Image.FromStream(ms)\n\n 'Export to JPG Stream\n msOut = New MemoryStream\n imgJPG.Save(msOut, System.Drawing.Imaging.ImageFormat.Jpeg)\n imgJPG.Dispose()\n imgJPG = Nothing\n ms.Close()\n sFrontImage = Convert.ToBase64String(msOut.ToArray())\n\n dsImage = New Data.DataSet\n da.Fill(dsImage, \"image\")\n myBytes = dsImage.Tables(0).Rows(0)(\"Backimage\")\n\n ms = New MemoryStream\n ms.Write(myBytes, 0, myBytes.Length)\n\n imgJPG = System.Drawing.Image.FromStream(ms)\n sBackImage = Convert.ToBase64String(ms.ToArray)\n\n Catch ex As System.IO.IOException ' : An I/O error occurs.\n Throw ex\n Catch ex As System.ArgumentNullException ': buffer is null.\n Throw ex\n Catch ex As System.NotSupportedException ': The stream does not support writing. For additional information see System.IO.Stream.CanWrite.-or- The current position is closer than count bytes to the end of the stream, and the capacity cannot be modified.\n Throw ex\n Catch ex As System.ArgumentOutOfRangeException ': offset or count are negative.\n Throw ex\n Catch ex As System.ObjectDisposedException ' : The current stream instance is closed.\n Throw ex\n Catch ex As System.ArgumentException\n Throw ex\n Catch ex As System.Runtime.InteropServices.ExternalException ': The image was saved with the wrong image format\n Throw ex\n Catch ex As Exception\n Throw ex\n Finally\n If cn IsNot Nothing Then\n cn.Close()\n cn.Dispose()\n cn = Nothing\n End If\n\n If cmd IsNot Nothing Then\n cmd.Dispose()\n cmd = Nothing\n End If\n\n If da IsNot Nothing Then\n da.Dispose()\n da = Nothing\n End If\n\n If ms IsNot Nothing Then\n ms.Dispose()\n ms = Nothing\n End If\n\n If msOut IsNot Nothing Then\n msOut.Close()\n msOut.Dispose()\n msOut = Nothing\n End If\n\n If dsImage IsNot Nothing Then\n dsImage.Dispose()\n dsImage = Nothing\n End If\n\n If myBytes IsNot Nothing Then\n myBytes = Nothing\n End If\n\n If imgJPG IsNot Nothing Then\n imgJPG.Dispose()\n imgJPG = Nothing\n End If\n\n End Try\n" }, { "answer_id": 1443596, "author": "Mac", "author_id": 8696, "author_profile": "https://Stackoverflow.com/users/8696", "pm_score": 2, "selected": true, "text": "System.Data.OracleClient OracleConnection connection OracleCommand command SELECT my_blob FROM my_table WHERE id=xx using (OracleDataReader odr=command.ExecuteReader())\n{\n reader.Read();\n\n if (!dr.IsDBNull(0))\n using (Stream s=(Stream)dr.GetOracleValue(0))\n using (Image image=Image.FromStream(s))\n return Copy(image);\n}\n public static Image Copy(Image original)\n{\n Image ret=new Bitmap(original.Width, original.Height);\n using (Graphics g=Graphics.FromImage(ret))\n {\n g.DrawImageUnscaled(original, 0, 0);\n g.Save();\n }\n\n return ret;\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184489", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
184,491
<p>We have a Java Applet built using AWT. This applet lets you select pictures from your hard drive and upload them to a server. The applet includes a scrollable list of pictures, which works fine in Windows, Linux and Mac OS X 10.5. We launch this applet via Java Web Start or within a web page. </p> <p>Our applet does not behave properly in Mac OS X 10.4, regardless of the version of Java (1.4 or 1.5). You can find a screenshot of the incorrect behaviour, when scrolling, here:</p> <p><a href="http://www.lavablast.com/tmp/ui_error.png" rel="nofollow noreferrer">http://www.lavablast.com/tmp/ui_error.png</a></p> <p>Simply put, sometimes when scrolling the pictures end up overlapping the header or footer of the application. This behaviour does not occur on other platforms. On Mac OS X 10.4, it shows the pictures in the incorrect location when scrolling, which would not be so bad if it refreshed the screen after painting the image at that location. However, it does not appear that the application knows it painted it incorrectly and thus does not refresh.</p> <p>If the window is minimized, resized or even moved, the application is refreshed and the incorrectly positioned elements vanish and the application resumes normally. I spent quite some time trying to force a refresh of the background image unsuccessfully. (the repaint the image directly, repaint all children of a few panels, etc. ) Thus, I am looking for any tips that would help me resolve this problem under Mac OS X 10.4 or, in the worst case, simply simulate a full applet refresh. </p> <p>Until recently, everything was compatible with Java 1.1 but this has changed in a few locations which now require 1.4. I don't feel these changes created the issue, I am just providing this as extra information. If you are interested in implementation details of the scroll panel, I will investigate, but I am assuming this is a common platform bug for which workarounds must be known.</p> <p>To replicate the problem, open the following Java Web Start application: <a href="http://www.lavablast.com/tmp/opal-webstart.php.jnlp" rel="nofollow noreferrer">http://www.lavablast.com/tmp/opal-webstart.php.jnlp</a></p> <p>Select a folder containing lots of images and play with the scrollbar. At some point (fairly quickly), you should get the refresh problem. </p> <p>Edit: I followed the first suggestion here and replaced all my controls that feature background images with a Swing equivalent and the issue is still there. (Plus, there are numerous other fixes I would need to do to do a complete change). Any other ideas? A simple one line of code that forces a full refresh would be great :)</p> <p>Edit2: The main thread creates the panels and launches X threads. Using an observer/notifier pattern, the threads complete and notify the main control, which adds a panel to the page. This is done via an EventQueue.invokeLater which, unless I am mistaken, should run on the right thread. The issue is at its most severe when scrolling even if no extra threads are running (as during the loading). </p>
[ { "answer_id": 184577, "author": "osp70", "author_id": 2357, "author_profile": "https://Stackoverflow.com/users/2357", "pm_score": 0, "selected": false, "text": "Dim cn As SqlConnection = Nothing\n Dim cmd As SqlCommand = Nothing\n Dim da As SqlDataAdapter = Nothing\n Dim ms As MemoryStream = Nothing\n Dim dsImage As Data.DataSet = Nothing\n Dim myBytes() As Byte = Nothing\n Dim imgJPG As System.Drawing.Image = Nothing\n Dim msOut As MemoryStream = Nothing\n\n Try\n cn = New SqlConnection(ConnectionStrings(\"conImageDB\").ToString)\n cmd = New SqlCommand(AppSettings(\"sprocGetImage\").ToString, cn)\n cmd.CommandType = Data.CommandType.StoredProcedure\n\n cmd.Parameters.AddWithValue(\"@dmhiRowno\", irowno)\n\n da = New SqlDataAdapter(cmd)\n\n dsImage = New Data.DataSet\n da.Fill(dsImage, \"image\")\n\n If dsImage.Tables(0).Rows.Count = 0 Then\n Throw New Exception(\"No results returned for rowno\")\n End If\n myBytes = dsImage.Tables(0).Rows(0)(\"Frontimage\")\n\n ms = New MemoryStream\n ms.Write(myBytes, 0, myBytes.Length)\n\n imgJPG = System.Drawing.Image.FromStream(ms)\n\n 'Export to JPG Stream\n msOut = New MemoryStream\n imgJPG.Save(msOut, System.Drawing.Imaging.ImageFormat.Jpeg)\n imgJPG.Dispose()\n imgJPG = Nothing\n ms.Close()\n sFrontImage = Convert.ToBase64String(msOut.ToArray())\n\n dsImage = New Data.DataSet\n da.Fill(dsImage, \"image\")\n myBytes = dsImage.Tables(0).Rows(0)(\"Backimage\")\n\n ms = New MemoryStream\n ms.Write(myBytes, 0, myBytes.Length)\n\n imgJPG = System.Drawing.Image.FromStream(ms)\n sBackImage = Convert.ToBase64String(ms.ToArray)\n\n Catch ex As System.IO.IOException ' : An I/O error occurs.\n Throw ex\n Catch ex As System.ArgumentNullException ': buffer is null.\n Throw ex\n Catch ex As System.NotSupportedException ': The stream does not support writing. For additional information see System.IO.Stream.CanWrite.-or- The current position is closer than count bytes to the end of the stream, and the capacity cannot be modified.\n Throw ex\n Catch ex As System.ArgumentOutOfRangeException ': offset or count are negative.\n Throw ex\n Catch ex As System.ObjectDisposedException ' : The current stream instance is closed.\n Throw ex\n Catch ex As System.ArgumentException\n Throw ex\n Catch ex As System.Runtime.InteropServices.ExternalException ': The image was saved with the wrong image format\n Throw ex\n Catch ex As Exception\n Throw ex\n Finally\n If cn IsNot Nothing Then\n cn.Close()\n cn.Dispose()\n cn = Nothing\n End If\n\n If cmd IsNot Nothing Then\n cmd.Dispose()\n cmd = Nothing\n End If\n\n If da IsNot Nothing Then\n da.Dispose()\n da = Nothing\n End If\n\n If ms IsNot Nothing Then\n ms.Dispose()\n ms = Nothing\n End If\n\n If msOut IsNot Nothing Then\n msOut.Close()\n msOut.Dispose()\n msOut = Nothing\n End If\n\n If dsImage IsNot Nothing Then\n dsImage.Dispose()\n dsImage = Nothing\n End If\n\n If myBytes IsNot Nothing Then\n myBytes = Nothing\n End If\n\n If imgJPG IsNot Nothing Then\n imgJPG.Dispose()\n imgJPG = Nothing\n End If\n\n End Try\n" }, { "answer_id": 1443596, "author": "Mac", "author_id": 8696, "author_profile": "https://Stackoverflow.com/users/8696", "pm_score": 2, "selected": true, "text": "System.Data.OracleClient OracleConnection connection OracleCommand command SELECT my_blob FROM my_table WHERE id=xx using (OracleDataReader odr=command.ExecuteReader())\n{\n reader.Read();\n\n if (!dr.IsDBNull(0))\n using (Stream s=(Stream)dr.GetOracleValue(0))\n using (Image image=Image.FromStream(s))\n return Copy(image);\n}\n public static Image Copy(Image original)\n{\n Image ret=new Bitmap(original.Width, original.Height);\n using (Graphics g=Graphics.FromImage(ret))\n {\n g.DrawImageUnscaled(original, 0, 0);\n g.Save();\n }\n\n return ret;\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20893/" ]
184,502
<p>In this particular case I'm trying to discover if a mylib.a file is 32 or 64 bit compatible. I'm familiar with ldd for shared objects (mylib.so) but how do I inspect a regular .a archive? </p>
[ { "answer_id": 184602, "author": "ephemient", "author_id": 20713, "author_profile": "https://Stackoverflow.com/users/20713", "pm_score": 3, "selected": false, "text": "binutils" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26261/" ]
184,511
<p>How would you implement a GUI similar to the "My Computer" view in Windows Explorer?</p> <p>In particular the "Icons" view mode. Including the grouping of different item types (as Files Stored on This Computer/Hard Disk Drives/Devices with Removable Storage groups in Windows Explorer)</p> <p>In WinForms I would use a ListView for this thing but in WPF the only thing that has even come close is a listbox with a custom ControlTemplate but it seems like too much effort!</p>
[ { "answer_id": 650714, "author": "Nir", "author_id": 3509, "author_profile": "https://Stackoverflow.com/users/3509", "pm_score": 1, "selected": false, "text": "public class Item\n{\n public string Type { get; set; }\n public string Name { get; set; }\n public ImageSource Icon { get; set; }\n}\n <Window x:Class=\"ListViewTest.Window1\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Title=\"Window1\" Height=\"300\" Width=\"300\" Name=\"W\">\n <Window.Resources>\n <CollectionViewSource x:Key=\"Items\" Source=\"{Binding}\">\n <CollectionViewSource.GroupDescriptions>\n <PropertyGroupDescription PropertyName=\"Type\"/>\n </CollectionViewSource.GroupDescriptions>\n </CollectionViewSource>\n <DataTemplate x:Key=\"ItemTemplate\">\n <Grid Width=\"128\">\n <Grid.RowDefinitions>\n <RowDefinition Height=\"40\"/>\n <RowDefinition Height=\"12\"/>\n </Grid.RowDefinitions>\n <Image Source=\"{Binding Icon}\"/>\n <TextBlock Text=\"{Binding Name}\" Grid.Row=\"1\"/>\n </Grid>\n </DataTemplate>\n <ItemsPanelTemplate x:Key=\"ItemPanel\">\n <WrapPanel Orientation=\"Horizontal\" Width=\"{Binding ElementName=W, Path=ActualWidth}\"/>\n </ItemsPanelTemplate>\n <DataTemplate x:Key=\"HeaderTemplate\">\n <StackPanel Margin=\"0 15\">\n <TextBlock Text=\"{Binding Name}\"/>\n <Rectangle Height=\"1\" Fill=\"Blue\"/>\n </StackPanel>\n </DataTemplate>\n <Style x:Key=\"ContainerStyle\" TargetType=\"{x:Type GroupItem}\">\n <Setter Property=\"Template\">\n <Setter.Value>\n <ControlTemplate>\n <Expander Header=\"{Binding Name}\" IsExpanded=\"True\">\n <ItemsPresenter/>\n </Expander>\n </ControlTemplate>\n </Setter.Value>\n </Setter>\n </Style>\n </Window.Resources>\n\n <Grid>\n <ListBox \n ItemsSource=\"{Binding Source={StaticResource Items}}\"\n ItemTemplate=\"{StaticResource ItemTemplate}\"\n ItemsPanel=\"{StaticResource ItemPanel}\">\n <ListBox.GroupStyle>\n <GroupStyle \n HeaderTemplate=\"{StaticResource HeaderTemplate}\"\n ContainerStyle=\"{StaticResource ContainerStyle}\"/>\n </ListBox.GroupStyle>\n </ListBox>\n </Grid>\n</Window>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5776/" ]
184,522
<p>I have a ListBox that when in focus, and when I have an item selected returns a valid SelectedIndex. If I have a valid SelectedIndex and I click on a TextBox on the same Forum, the SelectedIndex now becomes -1. However I want it to keep its SelectedIndex from changing. How would I go about doing this?</p>
[ { "answer_id": 20203641, "author": "Danny S", "author_id": 1452485, "author_profile": "https://Stackoverflow.com/users/1452485", "pm_score": 2, "selected": false, "text": "<Style d:IsControlPart=\"True\" TargetType=\"{x:Type ListBoxItem}\">\n....\n<Style.Triggers>\n <Trigger Property=\"Selector.IsSelected\" Value=\"True\">\n <Setter Property=\"Foreground\">\n <Setter.Value>\n <SolidColorBrush po:Freeze=\"True\" Color=\"{DynamicResource BlackColor}\" />\n </Setter.Value>\n </Setter>\n </Trigger>\n <Trigger Property=\"IsKeyboardFocusWithin\" Value=\"true\">\n <Setter Property=\"IsSelected\" Value=\"true\" />\n </Trigger>\n </Style.Triggers>\n</Style>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184522", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41/" ]
184,537
<p>I see in C++ there are multiple ways to allocate and free data and I understand that when you call <code>malloc</code> you should call <code>free</code> and when you use the <code>new</code> operator you should pair with <code>delete</code> and it is a mistake to mix the two (e.g. Calling <code>free()</code> on something that was created with the <code>new</code> operator), but I'm not clear on when I should use <code>malloc</code>/ <code>free</code> and when I should use <code>new</code>/ <code>delete</code> in my real world programs.</p> <p>If you're a C++ expert, please let me know any rules of thumb or conventions you follow in this regard.</p>
[ { "answer_id": 184540, "author": "Brian R. Bondy", "author_id": 3153, "author_profile": "https://Stackoverflow.com/users/3153", "pm_score": 9, "selected": false, "text": "malloc new char *pBuffer = new char[1024];\n //This is incorrect - may delete only one element, may corrupt the heap, or worse...\ndelete pBuffer;\n //This deletes all items in the array\ndelete[] pBuffer;\n new new malloc malloc new realloc realloc new free malloc delete int* p_scalar = new int(5); // Does not create 5 elements, but initializes to 5\nint* p_array = new int[5]; // Creates 5 elements\n" }, { "answer_id": 184548, "author": "dmckee --- ex-moderator kitten", "author_id": 2509, "author_profile": "https://Stackoverflow.com/users/2509", "pm_score": 5, "selected": false, "text": "malloc free new delete []" }, { "answer_id": 184568, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 6, "selected": false, "text": "void *p = operator new(size);\n ...\noperator delete(p);\n" }, { "answer_id": 184798, "author": "selwyn", "author_id": 16314, "author_profile": "https://Stackoverflow.com/users/16314", "pm_score": 0, "selected": false, "text": "new delete malloc free new/delete" }, { "answer_id": 7970036, "author": "Flexo", "author_id": 168175, "author_profile": "https://Stackoverflow.com/users/168175", "pm_score": 7, "selected": false, "text": "malloc malloc new malloc void* #include <stdlib.h>\n\nstruct foo {\n double d[5];\n}; \n\nint main() {\n foo *f1 = malloc(1); // error, no cast\n foo *f2 = static_cast<foo*>(malloc(sizeof(foo)));\n foo *f3 = static_cast<foo*>(malloc(1)); // No error, bad\n}\n malloc f2 foo struct foo {\n double d[5];\n virtual ~foo() { }\n};\n malloc f2 is_pod #include <type_traits>\n#include <stdlib.h>\n\nfoo *safe_foo_malloc() {\n static_assert(std::is_pod<foo>::value, \"foo must be POD\");\n return static_cast<foo*>(malloc(sizeof(foo)));\n}\n malloc NULL new std::bad_alloc NULL malloc NULL safe_foo_malloc #include <type_traits>\n#include <stdlib.h>\n\nvoid my_malloc_failed_handler();\n\nfoo *safe_foo_malloc() {\n static_assert(std::is_pod<foo>::value, \"foo must be POD\");\n foo *mem = static_cast<foo*>(malloc(sizeof(foo)));\n if (!mem) {\n my_malloc_failed_handler();\n // or throw ...\n }\n return mem;\n}\n malloc new malloc safe_foo_malloc new #include <stdlib.h>\n#include <new>\n\nvoid my_malloc_failed_handler();\n\nfoo *safe_foo_malloc() {\n void *mem = malloc(sizeof(foo));\n if (!mem) {\n my_malloc_failed_handler();\n // or throw ...\n }\n return new (mem)foo();\n}\n safe_foo_malloc foo #include <functional>\n#include <new>\n#include <stdlib.h>\n\nvoid my_malloc_failed_handler();\n\ntemplate <typename T>\nstruct alloc {\n template <typename ...Args>\n static T *safe_malloc(Args&&... args) {\n void *mem = malloc(sizeof(T));\n if (!mem) {\n my_malloc_failed_handler();\n // or throw ...\n }\n return new (mem)T(std::forward(args)...);\n }\n};\n new malloc new new" }, { "answer_id": 7971041, "author": "R. Martinho Fernandes", "author_id": 46642, "author_profile": "https://Stackoverflow.com/users/46642", "pm_score": 4, "selected": false, "text": "malloc new malloc new non_pod_type* p = (non_pod_type*) malloc(sizeof *p);\n new non_pod_type* p = new non_pod_type();\n new pod_type* p = (pod_type*) malloc(sizeof *p);\nstd::cout << p->foo;\n malloc new pod_type* p = new pod_type();\nstd::cout << p->foo; // prints 0\n new malloc new new malloc new new std::unique_ptr<T> p = std::unique_ptr<T>(new T()); // this won't leak\n" }, { "answer_id": 11998474, "author": "Barry", "author_id": 1605648, "author_profile": "https://Stackoverflow.com/users/1605648", "pm_score": 2, "selected": false, "text": "class B {\nprivate:\n B *ptr;\n int x;\npublic:\n B(int n) {\n cout<<\"B: ctr\"<<endl;\n //ptr = new B; //keep calling ctr, result is segmentation fault\n ptr = (B *)malloc(sizeof(B));\n x = n;\n ptr->x = n + 10;\n }\n ~B() {\n //delete ptr;\n free(ptr);\n cout<<\"B: dtr\"<<endl;\n }\n};\n" }, { "answer_id": 21140469, "author": "herohuyongtao", "author_id": 2589776, "author_profile": "https://Stackoverflow.com/users/2589776", "pm_score": 3, "selected": false, "text": "new malloc new new malloc new malloc" }, { "answer_id": 33935717, "author": "Yogeesh H T", "author_id": 3725702, "author_profile": "https://Stackoverflow.com/users/3725702", "pm_score": 6, "selected": false, "text": "new malloc() new malloc() new malloc() new malloc() new malloc()" }, { "answer_id": 41146664, "author": "kungfooman", "author_id": 1952626, "author_profile": "https://Stackoverflow.com/users/1952626", "pm_score": 2, "selected": false, "text": "new struct test_s {\n int some_strange_name = 1;\n int &easy = some_strange_name;\n}\n new struct test_s" }, { "answer_id": 45386558, "author": "The Quantum Physicist", "author_id": 1317944, "author_profile": "https://Stackoverflow.com/users/1317944", "pm_score": 5, "selected": false, "text": "malloc new malloc new free delete delete" }, { "answer_id": 53898150, "author": "JVApen", "author_id": 2466431, "author_profile": "https://Stackoverflow.com/users/2466431", "pm_score": 4, "selected": false, "text": " std::vector<int> *createVector(); // Bad\n std::vector<int> createVector(); // Good\n\n auto v = new std::vector<int>(); // Bad\n auto result = calculate(/*optional output = */ v);\n auto v = std::vector<int>(); // Good\n auto result = calculate(/*optional output = */ &v);\n std::unique_ptr std::shared_ptr auto instance = std::make_unique<Class>(/*args*/); // C++14\nauto instance = std::unique_ptr<Class>(new Class(/*args*/)); // C++11\nauto instance = std::make_unique<Class[]>(42); // C++14\nauto instance = std::unique_ptr<Class[]>(new Class[](42)); // C++11\n std::optional auto optInstance = std::optional<Class>{};\nif (condition)\n optInstance = Class{};\n auto vector = std::vector<std::unique_ptr<Interface>>{};\n auto instance = std::make_unique<Class>();\n vector.push_back(std::move(instance)); // std::move -> transfer (most of the time)\n new std::make_unique auto instance = std::make_unique<Class>();\n legacyFunction(instance.release()); // Ownership being transferred\n\n auto instance = std::unique_ptr<Class>{legacyFunction()}; // Ownership being captured in unique_ptr\n auto instance = new Class(); // Allocate memory\n delete instance; // Deallocate\n auto instances = new Class[42](); // Allocate memory\n delete[] instances; // Deallocate\n auto instanceBlob = std::malloc(sizeof(Class)); // Allocate memory\n auto instance = new(instanceBlob)Class{}; // Initialize via constructor\n instance.~Class(); // Destroy via destructor\n std::free(instanceBlob); // Deallocate the memory\n std::vector C" }, { "answer_id": 73317006, "author": "Adrian", "author_id": 19705775, "author_profile": "https://Stackoverflow.com/users/19705775", "pm_score": 1, "selected": false, "text": "char* pWord = new char[5]; // allocation of char array of fixed size \n int size = 5; \nchar* pWord = (char*)malloc(size); \n memset((void*)pWord, 0, sizeof(pWord) / sizeof(char)); \n pWord = &pWord[0]; // or *pWord = pWord[0]; \n delete[] pWord; \n free((void*)pWord); \n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184537", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
184,538
<p>PNG images appear "fuzzy" in flash CS3. They are very blocky and appear unanti-aliased (if that is a word) Does anyone have a fix for this? Is there some setting I'm missing? </p>
[ { "answer_id": 184808, "author": "defmeta", "author_id": 10875, "author_profile": "https://Stackoverflow.com/users/10875", "pm_score": 2, "selected": false, "text": "myBitmap.smoothing = true;\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25280/" ]
184,541
<p>I've been fooling around with the Google App Engine for a few days and I have a little hobby application that I want to write and deploy.</p> <p>However I'd like to set it up so that users are <strong>not</strong> directly accessing the app via appspot.com.</p> <p>Is hosting it through Google Apps and then pointing it at my own domain the only way to go? I looked at that a little bit and it seemed like a pain to implement but maybe I'm just missing something.</p> <p>My other thought was to write the app-engine piece as a more generic web-service. </p> <p>Then I could have the user-facing piece be hosted anywhere, written in any language, and have it query the appspot.com url.</p> <p>Anyone have any luck with the web-service approach?</p>
[ { "answer_id": 5695742, "author": "Sangan", "author_id": 712420, "author_profile": "https://Stackoverflow.com/users/712420", "pm_score": 1, "selected": false, "text": "request.getRequestURI() resp.sendRedirect(\"<your domain>\")\n request.getRequestDispatcher(\"<error-page>\").forward(request, response);\n" }, { "answer_id": 48001832, "author": "I. J. Kennedy", "author_id": 8677, "author_profile": "https://Stackoverflow.com/users/8677", "pm_score": 2, "selected": true, "text": "Add custom domain" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
184,560
<p>I downloaded a VM image of a web application that uses MySQL.</p> <p>How can I monitor its space consumption and know when additional space must be added?</p>
[ { "answer_id": 4055942, "author": "RolandoMySQLDBA", "author_id": 491757, "author_profile": "https://Stackoverflow.com/users/491757", "pm_score": 6, "selected": true, "text": "SELECT IFNULL(B.engine,'Total') \"Storage Engine\",\nCONCAT(LPAD(REPLACE(FORMAT(B.DSize/POWER(1024,pw),3),',',''),17,' '),' ',\nSUBSTR(' KMGTP',pw+1,1),'B') \"Data Size\", CONCAT(LPAD(REPLACE(\nFORMAT(B.ISize/POWER(1024,pw),3),',',''),17,' '),' ',\nSUBSTR(' KMGTP',pw+1,1),'B') \"Index Size\", CONCAT(LPAD(REPLACE(\nFORMAT(B.TSize/POWER(1024,pw),3),',',''),17,' '),' ',\nSUBSTR(' KMGTP',pw+1,1),'B') \"Table Size\" FROM\n(SELECT engine,SUM(data_length) DSize,SUM(index_length) ISize,\nSUM(data_length+index_length) TSize FROM\ninformation_schema.tables WHERE table_schema NOT IN\n('mysql','information_schema','performance_schema') AND\nengine IS NOT NULL GROUP BY engine WITH ROLLUP) B,\n(SELECT 3 pw) A ORDER BY TSize;\n SELECT DBName,CONCAT(LPAD(FORMAT(SDSize/POWER(1024,pw),3),17,' '),' ',\nSUBSTR(' KMGTP',pw+1,1),'B') \"Data Size\",CONCAT(LPAD(\nFORMAT(SXSize/POWER(1024,pw),3),17,' '),' ',SUBSTR(' KMGTP',pw+1,1),'B') \"Index Size\",\nCONCAT(LPAD(FORMAT(STSize/POWER(1024,pw),3),17,' '),' ',\nSUBSTR(' KMGTP',pw+1,1),'B') \"Total Size\" FROM\n(SELECT IFNULL(DB,'All Databases') DBName,SUM(DSize) SDSize,SUM(XSize) SXSize,\nSUM(TSize) STSize FROM (SELECT table_schema DB,data_length DSize,\nindex_length XSize,data_length+index_length TSize FROM information_schema.tables\nWHERE table_schema NOT IN ('mysql','information_schema','performance_schema')) AAA\nGROUP BY DB WITH ROLLUP) AA,(SELECT 3 pw) BB ORDER BY (SDSize+SXSize);\n SELECT Statistic,DataSize \"Data Size\",IndexSize \"Index Size\",TableSize \"Table Size\"\nFROM (SELECT IF(ISNULL(table_schema)=1,10,0) schema_score,\nIF(ISNULL(engine)=1,10,0) engine_score,\nIF(ISNULL(table_schema)=1,'ZZZZZZZZZZZZZZZZ',table_schema) schemaname,\nIF(ISNULL(B.table_schema)+ISNULL(B.engine)=2,\"Storage for All Databases\",\nIF(ISNULL(B.table_schema)+ISNULL(B.engine)=1,\nCONCAT(\"Storage for \",B.table_schema),\nCONCAT(B.engine,\" Tables for \",B.table_schema))) Statistic,\nCONCAT(LPAD(REPLACE(FORMAT(B.DSize/POWER(1024,pw),3),',',''),17,' '),' ',\nSUBSTR(' KMGTP',pw+1,1),'B') DataSize,CONCAT(LPAD(REPLACE(\nFORMAT(B.ISize/POWER(1024,pw),3),',',''),17,' '),' ',\nSUBSTR(' KMGTP',pw+1,1),'B') IndexSize,\nCONCAT(LPAD(REPLACE(FORMAT(B.TSize/POWER(1024,pw),3),',',''),17,' '),' ',\nSUBSTR(' KMGTP',pw+1,1),'B') TableSize FROM (SELECT table_schema,engine,\nSUM(data_length) DSize,SUM(index_length) ISize,\nSUM(data_length+index_length) TSize FROM information_schema.tables\nWHERE table_schema NOT IN ('mysql','information_schema','performance_schema')\nAND engine IS NOT NULL GROUP BY table_schema,engine WITH ROLLUP) B,\n(SELECT 3 pw) A) AA ORDER BY schemaname,schema_score,engine_score;\n (SELECT 3 pw) (SELECT 0 pw) (SELECT 1 pw) (SELECT 2 pw) (SELECT 3 pw) (SELECT 4 pw) (SELECT 5 pw) SELECT IFNULL(db,'Total') \"Database\",\ndatsum / power(1024,pw) \"Data Size\",\nndxsum / power(1024,pw) \"Index Size\",\ntotsum / power(1024,pw) \"Total\"\nFROM (SELECT db,SUM(dat) datsum,SUM(ndx) ndxsum,SUM(dat+ndx) totsum\nFROM (SELECT table_schema db,data_length dat,index_length ndx\nFROM information_schema.tables WHERE engine IS NOT NULL\nAND table_schema NOT IN ('information_schema','mysql')) AA\nGROUP BY db WITH ROLLUP) A,(SELECT 1 pw) B;\n pw SELECT\n IFNULL(ENGINE,'Total') \"Storage Engine\",\n LPAD(CONCAT(FORMAT(DAT/POWER(1024,pw1),2),' ',\n SUBSTR(units,pw1*2+1,2)),17,' ') \"Data Size\",\n LPAD(CONCAT(FORMAT(NDX/POWER(1024,pw2),2),' ',\n SUBSTR(units,pw2*2+1,2)),17,' ') \"Index Size\",\n LPAD(CONCAT(FORMAT(TBL/POWER(1024,pw3),2),' ',\n SUBSTR(units,pw3*2+1,2)),17,' ') \"Total Size\"\nFROM\n(\n SELECT ENGINE,DAT,NDX,TBL,\n IF(px>4,4,px) pw1,IF(py>4,4,py) pw2,IF(pz>4,4,pz) pw3\n FROM \n (SELECT *,\n FLOOR(LOG(IF(DAT=0,1,DAT))/LOG(1024)) px,\n FLOOR(LOG(IF(NDX=0,1,NDX))/LOG(1024)) py,\n FLOOR(LOG(IF(TBL=0,1,TBL))/LOG(1024)) pz\n FROM\n (SELECT\n ENGINE,\n SUM(data_length) DAT,\n SUM(index_length) NDX,\n SUM(data_length+index_length) TBL\n FROM\n (\n SELECT engine,data_length,index_length FROM\n information_schema.tables WHERE table_schema NOT IN\n ('information_schema','performance_schema','mysql')\n AND ENGINE IS NOT NULL\n ) AAA GROUP BY ENGINE WITH ROLLUP\n) AAA ) AA) A,(SELECT ' BKBMBGBTB' units) B;\n SELECT\n IFNULL(DB,'Total') \"Database\",\n LPAD(CONCAT(FORMAT(DAT/POWER(1024,pw1),2),' ',\n SUBSTR(units,pw1*2+1,2)),17,' ') \"Data Size\",\n LPAD(CONCAT(FORMAT(NDX/POWER(1024,pw2),2),' ',\n SUBSTR(units,pw2*2+1,2)),17,' ') \"Index Size\",\n LPAD(CONCAT(FORMAT(TBL/POWER(1024,pw3),2),' ',\n SUBSTR(units,pw3*2+1,2)),17,' ') \"Total Size\"\nFROM\n(\n SELECT DB,DAT,NDX,TBL,\n IF(px>4,4,px) pw1,IF(py>4,4,py) pw2,IF(pz>4,4,pz) pw3\n FROM \n (SELECT *,\n FLOOR(LOG(IF(DAT=0,1,DAT))/LOG(1024)) px,\n FLOOR(LOG(IF(NDX=0,1,NDX))/LOG(1024)) py,\n FLOOR(LOG(IF(TBL=0,1,TBL))/LOG(1024)) pz\n FROM\n (SELECT\n DB,\n SUM(data_length) DAT,\n SUM(index_length) NDX,\n SUM(data_length+index_length) TBL\n FROM\n (\n SELECT table_schema DB,data_length,index_length FROM\n information_schema.tables WHERE table_schema NOT IN\n ('information_schema','performance_schema','mysql')\n AND ENGINE IS NOT NULL\n ) AAA GROUP BY DB WITH ROLLUP\n) AAA) AA) A,(SELECT ' BKBMBGBTB' units) B;\n SELECT\n IF(ISNULL(DB)+ISNULL(ENGINE)=2,'Database Total',\n CONCAT(DB,' ',IFNULL(ENGINE,'Total'))) \"Reported Statistic\",\n LPAD(CONCAT(FORMAT(DAT/POWER(1024,pw1),2),' ',\n SUBSTR(units,pw1*2+1,2)),17,' ') \"Data Size\",\n LPAD(CONCAT(FORMAT(NDX/POWER(1024,pw2),2),' ',\n SUBSTR(units,pw2*2+1,2)),17,' ') \"Index Size\",\n LPAD(CONCAT(FORMAT(TBL/POWER(1024,pw3),2),' ',\n SUBSTR(units,pw3*2+1,2)),17,' ') \"Total Size\"\nFROM\n(\n SELECT DB,ENGINE,DAT,NDX,TBL,\n IF(px>4,4,px) pw1,IF(py>4,4,py) pw2,IF(pz>4,4,pz) pw3\n FROM \n (SELECT *,\n FLOOR(LOG(IF(DAT=0,1,DAT))/LOG(1024)) px,\n FLOOR(LOG(IF(NDX=0,1,NDX))/LOG(1024)) py,\n FLOOR(LOG(IF(TBL=0,1,TBL))/LOG(1024)) pz\n FROM\n (SELECT\n DB,ENGINE,\n SUM(data_length) DAT,\n SUM(index_length) NDX,\n SUM(data_length+index_length) TBL\n FROM\n (\n SELECT table_schema DB,ENGINE,data_length,index_length FROM\n information_schema.tables WHERE table_schema NOT IN\n ('information_schema','performance_schema','mysql')\n AND ENGINE IS NOT NULL\n ) AAA GROUP BY DB,ENGINE WITH ROLLUP\n) AAA) AA) A,(SELECT ' BKBMBGBTB' units) B;\n" }, { "answer_id": 4229061, "author": "Vadim", "author_id": 338477, "author_profile": "https://Stackoverflow.com/users/338477", "pm_score": 0, "selected": false, "text": "/var/lib/mysql" }, { "answer_id": 33592145, "author": "wpdevramki", "author_id": 4467277, "author_profile": "https://Stackoverflow.com/users/4467277", "pm_score": 0, "selected": false, "text": "du -s /var/lib/mysql/* | sort -nr\n 34128 /var/lib/mysql/db_name1\n33720 /var/lib/mysql/db_name2\n29744 /var/lib/mysql/db_name3\n26624 /var/lib/mysql/db_name4\n16516 /var/lib/mysql/db_name5\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15884/" ]
184,563
<p>We are introducing static analysis tools into the build system for our Java product. We are using Maven2 so <a href="http://checkstyle.sourceforge.net/" rel="noreferrer">Checkstyle</a> and <a href="http://pmd.sourceforge.net/" rel="noreferrer">PMD</a> integration come for free. However it looks like there is a large overlap in functionality between these two tools, in terms of enforcing basic style rules.</p> <p>Is there a benefit from utilizing both of these? I don't want to maintain 2 tools if one will work. If we choose one, which one should we use and why?</p> <p>We are also planning on using FindBugs. Are there other static analysis tools we should look at?</p> <p><strong>Update:</strong> Consensus seems to be that PMD is preferred over CheckStyle. I don't see a solid reason to use both, and I don't want to maintain 2 sets of rule files, so we will probably aim for PMD exclusively. We'll also be bringing in FindBugs, and perhaps, eventually, Macker to enforce architectural rules.</p>
[ { "answer_id": 13035733, "author": "yegor256", "author_id": 187141, "author_profile": "https://Stackoverflow.com/users/187141", "pm_score": 2, "selected": false, "text": "<plugin>\n <groupId>com.qulice</groupId>\n <artifactId>qulice-maven-plugin</artifactId>\n <version>0.15</version>\n <executions>\n <execution>\n <goals>\n <goal>check</goal>\n </goals>\n </execution>\n </executions>\n</plugin>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5874/" ]
184,574
<p>If I have two variables containing binary values, how do I append them together as one binary value? For example, if I used WMI to read the registry of two REG_BINARY value, I then want to be able to concatenate the values.</p> <p>VBScript complains of a type mismatch when you try to join with the '&amp;' operator.</p>
[ { "answer_id": 185045, "author": "aphoria", "author_id": 2441, "author_profile": "https://Stackoverflow.com/users/2441", "pm_score": 0, "selected": false, "text": "result = CStr(val1) & CStr(val2)\n" }, { "answer_id": 186339, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 2, "selected": false, "text": "Function ConcatByteArrays(ra, rb)\n Dim oStream : Set oStream = CreateObject(\"ADODB.Stream\")\n oStream.Open\n oStream.Type = 1 'Binary'\n oStream.Write ra\n oStream.Write rb\n\n oStream.Position = 0\n\n ConcatByteArrays = oStream.Read(LenB(ra) + LenB(rb))\n oStream.Close\n\nEnd Function\n Class ByteArrayBuilder\n Private moStream\n\n Sub Class_Initialize()\n Set moStream = CreateObject(\"ADODB.Stream\")\n moStream.Open\n moStream.Type = 1\n End Sub\n\n Public Sub Append(rabyt)\n moStream.Write rabyt\n End Sub\n\n Public Property Get Length\n Length = moStream.Size\n End Property\n\n Public Function GetArray()\n moStream.Position = 0\n GetArray = moStream.Read(moStream.Size)\n End Function\n\n Sub Class_Terminate()\n moStream.Close\n End Sub\n\nEnd Class\n" }, { "answer_id": 213730, "author": "spoulson", "author_id": 3347, "author_profile": "https://Stackoverflow.com/users/3347", "pm_score": 2, "selected": true, "text": "REG_BINARY SetBinaryValue WshShell REG_BINARY" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184574", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3347/" ]
184,590
<p>Is there a way to do this in one line?</p> <pre><code>$x =~ s/^\s+//; $x =~ s/\s+$//; </code></pre> <p>In other words, remove all leading and trailing whitespace from a string.</p>
[ { "answer_id": 184610, "author": "moritz", "author_id": 14132, "author_profile": "https://Stackoverflow.com/users/14132", "pm_score": 2, "selected": false, "text": "$x =~ s/\\A\\s*(.*?)\\s*\\z/$1/;\n" }, { "answer_id": 184613, "author": "Lev", "author_id": 7224, "author_profile": "https://Stackoverflow.com/users/7224", "pm_score": -1, "selected": false, "text": "$x =~ s/^\\s*(.*?)\\s*$/$1/;\n" }, { "answer_id": 184615, "author": "ephemient", "author_id": 20713, "author_profile": "https://Stackoverflow.com/users/20713", "pm_score": 0, "selected": false, "text": "s/\\A\\s*|\\s*\\Z//g" }, { "answer_id": 184620, "author": "Zsolt Botykai", "author_id": 11621, "author_profile": "https://Stackoverflow.com/users/11621", "pm_score": 0, "selected": false, "text": "s/^\\s*(\\S*\\S)\\s*$/$1/\n" }, { "answer_id": 184622, "author": "runrig", "author_id": 10415, "author_profile": "https://Stackoverflow.com/users/10415", "pm_score": 6, "selected": true, "text": "$x =~ s/^\\s+|\\s+$//g;\n s/^\\s+//, s/\\s+$// for $x;\n" }, { "answer_id": 184829, "author": "Tanktalus", "author_id": 23512, "author_profile": "https://Stackoverflow.com/users/23512", "pm_score": 5, "selected": false, "text": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nuse Benchmark qw(:all);\n\nmy $a = 'a' x 1_000;\n\nmy @x = (\n \" $a \",\n \"$a \",\n $a,\n \" $a\"\n );\n\ncmpthese(-5,\n {\n single => sub {\n for my $s (@x)\n {\n my $x = $s;\n $x =~ s/^\\s+|\\s+$//g;\n }\n },\n double => sub {\n for my $s (@x)\n {\n my $x = $s;\n $x =~ s/^\\s+//;\n $x =~ s/\\s+$//;\n }\n },\n trick => sub {\n for my $s (@x)\n {\n my $x = $s;\n s/^\\s+//, s/\\s+$// for $x;\n }\n },\n capture => sub {\n for my $s (@x)\n {\n my $x = $s;\n $x =~ s/\\A\\s*(.*?)\\s*\\z/$1/\n }\n },\n kramercap => sub {\n for my $s (@x)\n {\n my $x = $s;\n ($x) = $x =~ /^\\s*(.*?)\\s*$/\n }\n },\n }\n );\n" }, { "answer_id": 184953, "author": "Logan", "author_id": 1127433, "author_profile": "https://Stackoverflow.com/users/1127433", "pm_score": 3, "selected": false, "text": "$string =~ s/^\\s+//;\n$string =~ s/\\s+$//;\n" }, { "answer_id": 185125, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 3, "selected": false, "text": "my $a = 'a' x 1_000_000;\n\nmy @x = (\n \" $a \",\n \"$a \",\n $a,\n \" $a\"\n );\n Rate single capture trick double\nsingle 2.09/s -- -12% -98% -98%\ncapture 2.37/s 13% -- -98% -98%\ntrick 96.0/s 4491% 3948% -- -0%\ndouble 96.4/s 4512% 3967% 0% --\n" }, { "answer_id": 185272, "author": "jkramer", "author_id": 12523, "author_profile": "https://Stackoverflow.com/users/12523", "pm_score": 1, "selected": false, "text": "($foo) = $foo =~ /^\\s*(.*?)\\s*$/;\n" }, { "answer_id": 1710629, "author": "Shashidhar Vajramatti", "author_id": 208101, "author_profile": "https://Stackoverflow.com/users/208101", "pm_score": -1, "selected": false, "text": "$var1 =~ s/(^\\s*)(.*?)(\\s*$)+/$2/;\n" }, { "answer_id": 63265988, "author": "HappyFace", "author_id": 1410221, "author_profile": "https://Stackoverflow.com/users/1410221", "pm_score": 0, "selected": false, "text": "function trim() {\n local out=\"$*\"\n [[ \"$out\" =~ '^\\s*(.*\\S)\\s*$' ]] && out=\"$match[1]\" || out=''\n print -nr -- \"$out\"\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184590", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7598/" ]
184,592
<p>I have topics(id*) and tags(id*,name) and a linking table topic_tags(topicFk*,tagFk*).</p> <p>Now I want to select every single topic, that has all of the good tags (a,b,c) but none of the bad tags (d,e,f).</p> <p>How do I do that?</p>
[ { "answer_id": 184614, "author": "Tom Ritter", "author_id": 8435, "author_profile": "https://Stackoverflow.com/users/8435", "pm_score": 2, "selected": false, "text": "SELECT *\nFROM topics\nWHERE topic_id IN\n (SELECT topic_id\n FROM topic_tags a\n INNER JOIN topic_tags b\n on a.topic_id=b.topic_id\n and b.tag = 'b'\n INNER JOIN topic_tags c\n on b.topic_id=c.topic_d\n and c.tag = 'c'\n WHERE a.tag = 'a')\nAND topic_id NOT IN\n (SELECT topic_id\n FROM topic_tags\n WHERE tag = 'd' or tag = 'e' or tag = 'f')\n" }, { "answer_id": 184655, "author": "ysth", "author_id": 17389, "author_profile": "https://Stackoverflow.com/users/17389", "pm_score": 0, "selected": false, "text": "select id from topic\n inner join topic_tags tta on topic.id=tta.topicFk and tta.tagFk=a\n inner join topic_tags ttb on topic.id=ttb.topicFk and ttb.tagFk=b\n inner join topic_tags ttc on topic.id=ttc.topicFk and ttc.tagFk=c\n left join topic_tags tt on topic.id=tt.topicFk and tt.tagFk in (d,e,f)\n where tt.topicFk is null;\n select id from topic\n left join topic_tags tt on topic.id=tt.topicFk and tt.tagFk in (d,e,f)\n where tt.topicFk is null and\n 3=(select count(*) from topic_tags where topicFk=topic.id and tagFk in (a,b,c));\n select id from topic\n left join topic_tags tt on topic.id=tt.topicFk\n inner join tags on tt.tagFk=tags.id and tags.name in (d,e,f)\n where tt.topicFk is null and\n 3=(select count(*) from tags inner join topic_tags on tags.id=topic_tags.tagFk and topic_tags.topicFk=topic.id where tags.name in (a,b,c));\n" }, { "answer_id": 184674, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 1, "selected": false, "text": "select distinct topics.id from topics \ninner join topic_tags as t1 \n on (t1.topicFK=topics.id)\ninner join tags as goodtags \n on(goodtags.id=t1.tagFK and goodtags.name in ('a', 'b', 'c'))\nleft join topic_tags as t2 \n on (t2.topicFK=topics.id)\nleft join tags as badtags \n on(badtags .id=t2.tagFK and batags.name in ('d', 'e', 'f'))\nwhere badtags.name is null;\n" }, { "answer_id": 184705, "author": "Pablo Venturino", "author_id": 16732, "author_profile": "https://Stackoverflow.com/users/16732", "pm_score": 0, "selected": false, "text": "minus -- All topics with desired tags.\nselect distinct T.*\nfrom Topics T inner join Topics_Tags R on T.id = R.topicFK\n inner join Tags U on U.id = R.topic=FK\nwhere U.name in ('a', 'b', 'c')\n\nminus\n\n-- All topics with undesired tags. These are filtered out.\nselect distinct T.*\nfrom Topics T inner join Topics_Tags R on T.id = R.topicFK\n inner join Tags U on U.id = R.topic=FK\nwhere U.name in ('d', 'e', 'f')\n" }, { "answer_id": 184887, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 3, "selected": false, "text": "SELECT\n TopicId\nFROM Topic_Tags\nJOIN Tags ON\n Topic_Tags.TagId = Tags.TagId\nWHERE\n Tags.Name IN ('A', 'B', 'C', 'D', 'E', 'F')\nGROUP BY\n TopicId\nHAVING\n COUNT(*) = 3 \n AND MAX(Tags.Name) = 'C'\n SELECT \n * \nFROM (\n SELECT\n TopicId\n FROM Topic_Tags\n JOIN Tags ON\n Topic_Tags.TagId = Tags.TagId\n WHERE\n Tags.Name IN ('A', 'B', 'C')\n GROUP BY\n TopicId\n HAVING\n COUNT(*) = 3 \n) as GoodTags\nLEFT JOIN (\n SELECT\n TopicId\n FROM Topic_Tags\n JOIN Tags ON\n Topic_Tags.TagId = Tags.TagId\n WHERE\n Tags.Name = 'D'\n OR Tags.Name = 'E'\n OR Tags.Name = 'F'\n) as BadTags ON\n GoodTags.TopicId = BadTags.TopicId\nWHERE\n BadTags.TopicId IS NULL\n" }, { "answer_id": 184943, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "SELECT t.*, \n SUM(CASE WHEN g.name IN ('a', 'b', 'c') THEN 1 ELSE 0 END) AS num_good_tags,\n SUM(CASE WHEN g.name IN ('d', 'e', 'f') THEN 1 ELSE 0 END) AS num_bad_tags\nFROM topics AS t\n JOIN topic_tags AS tg ON (t.id = tg.topicFk)\n JOIN tags AS g ON (g.id = tg.tagFk)\nGROUP BY t.id\nHAVING num_good_tags = 3 AND num_bad_tags = 0;\n" }, { "answer_id": 185514, "author": "defnull", "author_id": 407880, "author_profile": "https://Stackoverflow.com/users/407880", "pm_score": 1, "selected": true, "text": "SELECT topics.id\nFROM topics\n INNER JOIN topic_tags topic_ptags\n ON topics.id = topic_ptags.topicFk\n INNER JOIN tags ptags\n ON topic_ptags.tagFk = ptags.id\n AND ptags.name IN ('a','b','c')\n LEFT JOIN topic_tags topic_ntags\n ON topics.id = topic_ntags.topicFk\n LEFT JOIN tags ntags\n ON topic_ntags.tagFk = ntags.id\n AND ntags.name IN ('d','e','f')\nGROUP BY topics.id\nHAVING count(DISTINCT ptags.id) = 3\n AND count(ntags.id) = 0\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/407880/" ]
184,600
<p>I have a situation where I have two models, companies and permissions, where companies is in a separate database from my permissions database. This is a has and belongs to many relationship because each company can have many permissions and each permission can belong to many companies.</p> <p>The reason the two databases are split is because the company database runs a high demand production application and the permissions database controls the permissions for another application.</p> <p>With rails, it looks for the join table in the same database as the primary table. For instance, if I do company.permissions, it looks in the company database for company_permissions. If I do permission.companies it looks in the permissions database.</p> <p>What is the best solution to using a has and belongs to many relationship with multiple databases?</p>
[ { "answer_id": 186310, "author": "JasonOng", "author_id": 6048, "author_profile": "https://Stackoverflow.com/users/6048", "pm_score": 3, "selected": false, "text": "permissions:\n adapter: mysql\n database: permissions\n username: root\n password: \n socket: /tmp/mysql.sock\n class Permission < ActiveRecord::Base\n\n establish_connection :permissions\n\nend \n class PermissionReference < ActiveRecord::Base\n\n belongs_to :permission\n has_and_belongs_to_many :companies,\n :join_table => 'companies_permissions',\n :foreign_key => 'permission_id'\n\nend\n class Company < ActiveRecord::Base\n\n has_and_belongs_to_many :permissions, \n :class_name => 'PermissionReference', \n :join_table => 'companies_permissions', \n :association_foreign_key => 'permission_id'\n\nend\n class External < ActiveRecord::Base\n\n self.abstract_class = true\n establish_connection :permissions\n\nend\n\nclass Permission < External\nend\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21872/" ]
184,609
<p>Consider the following two ways of writing a loop in Java to see if a list contains a given value:</p> <h3>Style 1</h3> <pre><code>boolean found = false; for(int i = 0; i &lt; list.length &amp;&amp; !found; i++) { if(list[i] == testVal) found = true; } </code></pre> <h3>Style 2</h3> <pre><code>boolean found = false; for(int i = 0; i &lt; list.length &amp;&amp; !found; i++) { found = (list[i] == testVal); } </code></pre> <p>The two are equivalent, but I always use style 1 because 1) I find it more readable, and 2) I am assuming that reassigning <code>found</code> to <code>false</code> hundreds of times feels like it would take more time. I am wondering: is this second assumption true?</p> <h3>Nitpicker's corner</h3> <ul> <li>I am well aware that this is a case of premature optimization. That doesn't mean that it isn't something that is useful to know.</li> <li>I don't care which style you think is more readable. I am only interested in whether one has a performance penalty compared to the other.</li> <li>I know that style 1 has the advantage of allowing you to also put a <code>break;</code> statement in the <code>if</code> block, but I don't care. Again, this question is about performance, not style.</li> </ul>
[ { "answer_id": 184632, "author": "warren", "author_id": 4418, "author_profile": "https://Stackoverflow.com/users/4418", "pm_score": 1, "selected": false, "text": "for(i=0; i<list.length && list[i]!=testval; i++);\nboolean found = (i!=list.length);\n" }, { "answer_id": 184776, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 1, "selected": false, "text": "start:\n CMP i, list.length\n JE end\n CMP list[i], testval\n JE equal\n JMP start\nequal:\n MOV true, found\nend:\n start:\n CMP i, list.length\n JE end\n CMP true, found\n JE end\n CMP list[i], testval\n JE equal\n JNE notequal\nequal:\n MOV true, found\n JMP start\nnotequal:\n MOV false, found\n JMP start\nend:\n" }, { "answer_id": 185064, "author": "anjanb", "author_id": 11142, "author_profile": "https://Stackoverflow.com/users/11142", "pm_score": 0, "selected": false, "text": "boolean found = false;\nfor(int i = 0; i < list.length && !found; i++)\n{\n if(list[i] == testVal)\n found = true;\n}\n" }, { "answer_id": 185071, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "boolean notFound = true;\n for(int i = 0; notFound && i < list.length; i++)\n {\n if(list[i] == testVal)\n notFound = false;\n }\n" }, { "answer_id": 208139, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "for(int i = 0; i < list.length; i++)\n{\n if(list[i] == testVal)\n return true;\n}\n\nreturn false;\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184609", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18511/" ]
184,618
<p>What is the best comment in source code you have ever encountered?</p>
[ { "answer_id": 184629, "author": "Diodeus - James MacFarlane", "author_id": 12579, "author_profile": "https://Stackoverflow.com/users/12579", "pm_score": 5, "selected": false, "text": "//ALL YOUR BASE ARE BELONG TO US\n" }, { "answer_id": 184633, "author": "Walter Mitty", "author_id": 19937, "author_profile": "https://Stackoverflow.com/users/19937", "pm_score": 2, "selected": false, "text": "Get This hack!\n" }, { "answer_id": 184635, "author": "Eduardo Campañó", "author_id": 12091, "author_profile": "https://Stackoverflow.com/users/12091", "pm_score": 3, "selected": false, "text": "I'm not sure what I did\n" }, { "answer_id": 184637, "author": "antik", "author_id": 1625, "author_profile": "https://Stackoverflow.com/users/1625", "pm_score": 3, "selected": false, "text": "// TODO: Implement this function!\n" }, { "answer_id": 184638, "author": "StubbornMule", "author_id": 13341, "author_profile": "https://Stackoverflow.com/users/13341", "pm_score": 8, "selected": false, "text": "//I am not sure why this works but it fixes the problem. \n" }, { "answer_id": 184639, "author": "Alejo", "author_id": 23084, "author_profile": "https://Stackoverflow.com/users/23084", "pm_score": 4, "selected": false, "text": "\"This code makes baby Jesus very sad!\". \n String blankSpaces=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"+ //100 whitespaces\n \"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \"+ //200 Whitespaces\n ...\n \" \" //100 whitespaces\n" }, { "answer_id": 184649, "author": "daniels", "author_id": 9789, "author_profile": "https://Stackoverflow.com/users/9789", "pm_score": 8, "selected": false, "text": "/* Please work */\n" }, { "answer_id": 184656, "author": "Tim Farley", "author_id": 4425, "author_profile": "https://Stackoverflow.com/users/4425", "pm_score": 7, "selected": false, "text": "// This only exists because Scott doesn't know how to use const correctly\n" }, { "answer_id": 184670, "author": "Dave Verwer", "author_id": 4496, "author_profile": "https://Stackoverflow.com/users/4496", "pm_score": 8, "selected": false, "text": "/* I did this the other way */\n" }, { "answer_id": 184672, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 8, "selected": false, "text": "/* You are not meant to understand this */ \n" }, { "answer_id": 184673, "author": "Tom Ritter", "author_id": 8435, "author_profile": "https://Stackoverflow.com/users/8435", "pm_score": 10, "selected": false, "text": "//Code sanitized to protect the foolish.\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Reflection;\nusing System.Web.UI;\n\nnamespace Mobile.Web.Control\n{\n /// <summary>\n /// Class used to work around Richard being a fucking idiot\n /// </summary>\n /// <remarks>\n /// The point of this is to work around his poor design so that paging will \n /// work on a mobile control. The main problem is the BindCompany() method, \n /// which he hoped would be able to do everything. I hope he dies.\n /// </remarks>\n public abstract class RichardIsAFuckingIdiotControl : MobileBaseControl, ICompanyProfileControl\n {\n protected abstract Pager Pager { get; }\n\n public void BindCompany(int companyId) { }\n\n public RichardIsAFuckingIdiotControl()\n {\n MakeSureNobodyAccidentallyGetsBittenByRichardsStupidity();\n }\n\n private void MakeSureNobodyAccidentallyGetsBittenByRichardsStupidity()\n {\n // Make sure nobody is actually using that fucking bindcompany method\n MethodInfo m = this.GetType().GetMethod(\"BindCompany\", BindingFlags.DeclaredOnly | \n BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);\n if (m != null)\n {\n throw new RichardIsAFuckingIdiotException(\"No!! Don't use the fucking BindCompany method!!!\");\n }\n // P.S. this method is a joke ... the rest of the class is fucking serious\n }\n\n /// <summary>\n /// This returns true if this control is supposed to be doing anything\n /// at all for this request. Richard thought it was a good idea to load\n /// the entire website during every request and have things turn themselves\n /// off. He also thought bandanas and aviator sunglasses were \"fuckin' \n /// gnarly, dude.\"\n /// </summary>\n protected bool IsThisTheRightPageImNotSureBecauseRichardIsDumb()\n {\n return Request.QueryString[\"Section\"] == this.MenuItemKey;\n }\n\n protected override void OnLoad(EventArgs e)\n {\n if (IsThisTheRightPageImNotSureBecauseRichardIsDumb())\n {\n Page.LoadComplete += new EventHandler(Page_LoadComplete);\n Pager.RowCount = GetRowCountBecauseRichardIsDumb();\n }\n base.OnLoad(e);\n }\n\n protected abstract int GetRowCountBecauseRichardIsDumb();\n protected abstract void BindDataBecauseRichardIsDumb();\n\n void Page_LoadComplete(object sender, EventArgs e)\n {\n BindDataBecauseRichardIsDumb();\n }\n\n // the rest of his reduh-ndant interface members\n public abstract string MenuItemName { get; set; }\n public abstract string MenuItemKey { get; set; }\n public abstract bool IsCapable(CapabilityCheck checker, int companyId);\n public abstract bool ShowInMenu { get; }\n public virtual Control CreateHeaderControl()\n {\n return null;\n }\n }\n}\n" }, { "answer_id": 184682, "author": "Randyaa", "author_id": 9518, "author_profile": "https://Stackoverflow.com/users/9518", "pm_score": 9, "selected": false, "text": "Catch (Exception e) {\n //who cares?\n} \n" }, { "answer_id": 184696, "author": "Kip", "author_id": 18511, "author_profile": "https://Stackoverflow.com/users/18511", "pm_score": 5, "selected": false, "text": "//this formula is right, work out the math yourself if you don't believe me\n" }, { "answer_id": 184701, "author": "Greg D", "author_id": 6932, "author_profile": "https://Stackoverflow.com/users/6932", "pm_score": 9, "selected": false, "text": "// I'm sorry.\n" }, { "answer_id": 184720, "author": "Kristopher Johnson", "author_id": 1175, "author_profile": "https://Stackoverflow.com/users/1175", "pm_score": 6, "selected": false, "text": "/* Project : XYZ (Please somebody shoot me!)\n *\n * File : $Id: defs.h,v 1.1 $\n *\n * Purpose : Create havoc rather than peace among many nations\n *\n * History : Back-ported changes that were not in CVS. Please somebody,\n * shoot us and put us all out of our misery.\n */\n" }, { "answer_id": 184734, "author": "Kristopher Johnson", "author_id": 1175, "author_profile": "https://Stackoverflow.com/users/1175", "pm_score": 3, "selected": false, "text": "// This code sucks.\n" }, { "answer_id": 184746, "author": "JosephStyons", "author_id": 672, "author_profile": "https://Stackoverflow.com/users/672", "pm_score": 3, "selected": false, "text": "{\nThis is a gathering place for all unit tests.\nCreate a TUnitTestWrapper, then call \"RunAllUnitTests\".\n\nThis class will create an instance of each thing to be tested, and call each of\ntheir unit tests.\n\nIt does not really do any testing on it's own; it just gives a common place from\nwhich to call everyone else's tests.\n\nThis way, one day, we can automate our testing with each build. [Cue laughter]\n}\n" }, { "answer_id": 184755, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "int Q13Factor = 8125; // 2^13 for Q13 \n" }, { "answer_id": 184795, "author": "Milner", "author_id": 16575, "author_profile": "https://Stackoverflow.com/users/16575", "pm_score": 5, "selected": false, "text": "-- Comment this later\n" }, { "answer_id": 184807, "author": "Robert S.", "author_id": 7565, "author_profile": "https://Stackoverflow.com/users/7565", "pm_score": 4, "selected": false, "text": "'Avert your eyes, it may take on other forms!\n" }, { "answer_id": 184835, "author": "Andreas Petersson", "author_id": 16542, "author_profile": "https://Stackoverflow.com/users/16542", "pm_score": 5, "selected": false, "text": "//You are not expected to understand this" }, { "answer_id": 184854, "author": "Steve B.", "author_id": 19479, "author_profile": "https://Stackoverflow.com/users/19479", "pm_score": 8, "selected": false, "text": "{ \n { \n while (.. ){ \n if (..){\n }\n for (.. ){ \n }\n .... (just putting in the control flow here, imagine another few hundred ifs)\n if(..) {\n if(..) {\n if(..) {\n ...\n (another few hundred brackets)\n }\n }\n } //endif\n {{{{}}{}{}{}{}}{{}{{}{}{}{}{}{}{{}{}}{}{}{{}{}{}{}{}{}{}{}{}{}{}{{}}}{{}{{}}{{{}}}{{}{}{}{}{}{}{}{{}}{}{{{}}{}{{}{}}{{{}}{}{}{}{}}{{}}}{}{{}{}{}{{}{{}}{}}{{}}}{{}}{{}}{{}}{}{{}}{{}}{{}}{{}{}{}}{}{}{{{}}{{}}}{}{}{}{}}{{{}{{}{}{}{{}{}{}{}{}{}}{}}{{}}{{}{}}}{{}}{{}}}{{}}{{}}{}{}{}{}{{}}{{}{}{}{}}}}{}{}}{{}{{{}{}{}{}}}}{{}{{{}}}}{{}{{{}{{}}{}{{}}{}{{}{}}{{}}{}{{}}}{{}}}}{{}{}{}{}{}{{{} {{{{}}{}{}{}{}}{{}{{}{}{}{}{}{}{{}{}}{}{}{{}{}{}{}{}{}{}{}{}{}{}{{}}}{{}{{}}{{{}}}{{}{}{}{}{}{}{}{{}}{}{{{}}{}{{}{}}{{{}}{}{}{}{}}{{}}}{}{{}{}{}{{}{{}}{}}{{}}}{{}}{{}}{{}}{}{{}}{{}}{{}}{{}{}{}}{}{}{{{}}{{}}}{}{}{}{}}{{{}{{}{}{}{{}{}{}{}{}{}}{}}{{}}{{}{}}}{{}}{{}}}{{}}{{}}{}{}{}{}{{}}{{}{}{}{}}}}{}{}}{{}{{{}{}{}{}}}}{{}{{{}}}}{{}{{{}{{}}{}{{}}{}{{}{}}{{}}{}{{}}}{{}}}}{{}{}{}{}{}{{{}{}{{}}{}}}{}}{{}}{{}{}}{{}{{}{{}}}}{{{}{{{}}}}}{{{{{}}}}}{}{}{}{{{{}}}{}{}}{{}{{}}}}{}{{}}{}}}{}}{{}}{{}{}}{{}{{}{{}}}}{{{}{{{}}}}}{{{{{}}}}}{}{}{}{{{{}}}{}{}}{{}{{}}}}\n" }, { "answer_id": 184885, "author": "Scott Dillman", "author_id": 10111, "author_profile": "https://Stackoverflow.com/users/10111", "pm_score": 5, "selected": false, "text": "// yikes\n" }, { "answer_id": 184924, "author": "rshimoda", "author_id": 23297, "author_profile": "https://Stackoverflow.com/users/23297", "pm_score": 4, "selected": false, "text": "// Abandon all hope you who needs to debug this\n" }, { "answer_id": 184949, "author": "CobolGuy", "author_id": 2038447, "author_profile": "https://Stackoverflow.com/users/2038447", "pm_score": 3, "selected": false, "text": "THIS PROGRAM HAS CODE THAT DOES NOT MEET STANDARDS \n" }, { "answer_id": 184971, "author": "catfood", "author_id": 12802, "author_profile": "https://Stackoverflow.com/users/12802", "pm_score": 2, "selected": false, "text": "StupidMark" }, { "answer_id": 184986, "author": "John Chuckran", "author_id": 25511, "author_profile": "https://Stackoverflow.com/users/25511", "pm_score": 8, "selected": false, "text": "// If this comment is removed the program will blow up \n" }, { "answer_id": 185016, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "If you have reached this part in the code, then this program sucks.\n" }, { "answer_id": 185031, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "using namespace std; // So sue me\n" }, { "answer_id": 185053, "author": "Simon Howard", "author_id": 24806, "author_profile": "https://Stackoverflow.com/users/24806", "pm_score": 7, "selected": false, "text": "// UNUSED\n// Separate into p_slidoor.c?\n\n#if 0 // ABANDONED TO THE MISTS OF TIME!!!\n//\n// EV_SlidingDoor : slide a door horizontally\n// (animate midtexture, then set noblocking line)\n//\n" }, { "answer_id": 185062, "author": "Darryl Hein", "author_id": 5441, "author_profile": "https://Stackoverflow.com/users/5441", "pm_score": 2, "selected": false, "text": "// but the \"real\" solution is much more complicated\n" }, { "answer_id": 185070, "author": "Darryl Hein", "author_id": 5441, "author_profile": "https://Stackoverflow.com/users/5441", "pm_score": 2, "selected": false, "text": "// this is really complicated\n" }, { "answer_id": 185106, "author": "Jason Sundram", "author_id": 2683, "author_profile": "https://Stackoverflow.com/users/2683", "pm_score": 9, "selected": false, "text": "// Magic. Do not touch.\n" }, { "answer_id": 185115, "author": "Milen A. Radev", "author_id": 15785, "author_profile": "https://Stackoverflow.com/users/15785", "pm_score": 4, "selected": false, "text": "// Okay, let's do the loop, yeah come on baby let's do the loop\n// and it goes like this ...\n" }, { "answer_id": 185156, "author": "Goran", "author_id": 23164, "author_profile": "https://Stackoverflow.com/users/23164", "pm_score": 9, "selected": false, "text": "<!-- Here be dragons -->\n" }, { "answer_id": 185165, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 2, "selected": false, "text": "/* logic */\n#ifndef TRUE\n# define TRUE 1\n#endif /* TRUE */\n#ifndef FALSE\n# define FALSE 0\n#endif /* FALSE */\n#define EOF_OK TRUE\n#define EOF_NOT_OK FALSE\n" }, { "answer_id": 185169, "author": "Bobby Jack", "author_id": 5058, "author_profile": "https://Stackoverflow.com/users/5058", "pm_score": 7, "selected": false, "text": "/* These magic numbers are fucking stupid. */\n\n/* Dear free software world, do you NOW see we are fucking\n things up?! This is insane! */\n\n/* We will NOT put a fucking timestamp in the header here. Every\n time you put it back, I will come in and take it out again. */\n\n# However, this only works if there are MULTIPLE checkboxes!\n# The fucking JS DOM *changes* based on one or multiple boxes!?!?!\n# Damn damn damn I hate the JavaScript DOM so damn much!!!!!!\n\n/* TODO: this is obviously not right ... this whole fucking module\n sucks anyway */\n\n/* FIXME: please god, when will the hurting stop? Thus function is so\n fucking broken it's not even funny. */\n # code below replaces code above - any problems?\n # yeah, it doesn't fucking work.\n" }, { "answer_id": 185181, "author": "Daniel Papasian", "author_id": 7548, "author_profile": "https://Stackoverflow.com/users/7548", "pm_score": 10, "selected": false, "text": "// drunk, fix later\n" }, { "answer_id": 185196, "author": "Rulas", "author_id": 22145, "author_profile": "https://Stackoverflow.com/users/22145", "pm_score": 7, "selected": false, "text": "// I have to find a better job\n" }, { "answer_id": 185201, "author": "Michael Easter", "author_id": 12704, "author_profile": "https://Stackoverflow.com/users/12704", "pm_score": 1, "selected": false, "text": "// Father, forgive me, for I am sinning\n\n// heaven help me\n\n// horse string-length into correctitude \n(from a textbook)\n\n// what, me worry?\n" }, { "answer_id": 185246, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "(A bunch of code that's really weird looking) //Kludge.\n" }, { "answer_id": 185308, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 9, "selected": false, "text": "return 1; # returns 1\n" }, { "answer_id": 185550, "author": "KevDog", "author_id": 13139, "author_profile": "https://Stackoverflow.com/users/13139", "pm_score": 8, "selected": false, "text": "//This code sucks, you know it and I know it. \n//Move on and call me an idiot later.\n" }, { "answer_id": 185576, "author": "Draemon", "author_id": 26334, "author_profile": "https://Stackoverflow.com/users/26334", "pm_score": 9, "selected": false, "text": "/* This is O(scary), but seems quick enough in practice. */ \n" }, { "answer_id": 185603, "author": "Ted", "author_id": 8965, "author_profile": "https://Stackoverflow.com/users/8965", "pm_score": 3, "selected": false, "text": "// Bad Christian, No cookie\n" }, { "answer_id": 185712, "author": "Mike", "author_id": 1743, "author_profile": "https://Stackoverflow.com/users/1743", "pm_score": 9, "selected": false, "text": "const int TEN=10; // As if the value of 10 will fluctuate... \n" }, { "answer_id": 185720, "author": "mattlant", "author_id": 14642, "author_profile": "https://Stackoverflow.com/users/14642", "pm_score": 4, "selected": false, "text": "//The following code is commented out\n//(a load of commented out code followed)\n" }, { "answer_id": 185789, "author": "Aidos", "author_id": 12040, "author_profile": "https://Stackoverflow.com/users/12040", "pm_score": 8, "selected": false, "text": "// This shouldn't happen. The only way this can happen is if the\n// <code>JFileChooser</code> has returned a <code>File</code> that doesn't exist\n// on the system. If this happens we can't recover, and there is more than likely\n// a rip in the space time continuum that the user is too distracted by to notice\n// anything else.\n /**\n * This method leverages collective synergy to drive \"outside of the box\"\n * thinking and formulate key objectives into a win-win game plan with a\n * quality-driven approach that focuses on empowering key players to drive-up\n * their core competencies and increase expectations with an all-around\n * initiative to drive down the bottom-line. I really wanted to work the word\n * \"mandrolic\" in there, but that word always makes me want to punch myself in\n * the face.\n */\nprivate void updateFileCountLabel() {\n" }, { "answer_id": 185803, "author": "Sergey Kornilov", "author_id": 10969, "author_profile": "https://Stackoverflow.com/users/10969", "pm_score": 10, "selected": false, "text": "// sometimes I believe compiler ignores all my comments\n" }, { "answer_id": 185846, "author": "Brad Achorn", "author_id": 2909, "author_profile": "https://Stackoverflow.com/users/2909", "pm_score": 3, "selected": false, "text": "# absolutely foul heuristic code.\n# ..it's dirty, but you want it.\n # VERY USEFUL DEBUGGING AID, for when the above all goes pearshaped:\n" }, { "answer_id": 185853, "author": "moswald", "author_id": 8368, "author_profile": "https://Stackoverflow.com/users/8368", "pm_score": 3, "selected": false, "text": "// this function doesn't actually calculated the profit, like it says --it really signals the mothership orbiting saturn that the planet is ripe for takeover\n\n[later]\n\n// I don't think anyone is going to read this\n\n[various permutations on that last one]\n" }, { "answer_id": 185877, "author": "Samat Jain", "author_id": 14878, "author_profile": "https://Stackoverflow.com/users/14878", "pm_score": 7, "selected": false, "text": "/* Halley's comment */\n" }, { "answer_id": 185971, "author": "TM.", "author_id": 12983, "author_profile": "https://Stackoverflow.com/users/12983", "pm_score": 4, "selected": false, "text": "//This was clearly written under duress\n" }, { "answer_id": 185979, "author": "Mark Glorie", "author_id": 952, "author_profile": "https://Stackoverflow.com/users/952", "pm_score": 5, "selected": false, "text": "'Is it worth it, let me work it'\n'I put my thing down, flip it and reverse it'\n'Ti esrever dna ti pilf, nwod gniht ym tup I'\n\nNextIP = StrReverse(UserRecordset.Fields.Item(0))\n" }, { "answer_id": 185989, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "try\n{ \n // Some database logic\n}\ncatch (Exception $ex)\n{\n // sure, it looks silly and I honestly cant remember what code used to go here... but i swear i will\n // find a use for this code.... eventually....\n throw $ex;\n}\n" }, { "answer_id": 185990, "author": "Matias Nino", "author_id": 17235, "author_profile": "https://Stackoverflow.com/users/17235", "pm_score": 5, "selected": false, "text": "'NO COMMENT\n" }, { "answer_id": 186286, "author": "Enrico Campidoglio", "author_id": 26396, "author_profile": "https://Stackoverflow.com/users/26396", "pm_score": 3, "selected": false, "text": "/**\n * ...as the moon sets over the early morning Merlin, Oregon\n * mountains, our intrepid adventurers type...\n */\npublic Test createTest(Class theClass, String name) {\n ...\n}\n" }, { "answer_id": 186309, "author": "Tuoski", "author_id": 1703, "author_profile": "https://Stackoverflow.com/users/1703", "pm_score": 10, "selected": false, "text": "stop(); // Hammertime!\n" }, { "answer_id": 186395, "author": "ThatBloke", "author_id": 7050, "author_profile": "https://Stackoverflow.com/users/7050", "pm_score": 3, "selected": false, "text": "offset=1;\nfor (i=0;i<=len;i++)\n {\n if ((i!=0)&&(i<len)) //-3\n {\n switch(mess[i])\n {\n case ETX:\n case ETB:\n case DLE:\n buf[offset]=DLE;\n offset++;\n break;\n }\n }\n buf[offset]=mess[i];\n offset++;\n }\n for (n=0;n<offset;n++)\n{\n Sleep(TR); //Modif A\n Sleep(T);//\n FWriteFile(hCom,buf+n,1,&dwMot,NULL);\n if (ECHO)\n FReadFile(hCom,tab,1,&dwMot,NULL);\n}\n if (GetFileSize(hSlotFile,NULL)==3600) //5*720\n" }, { "answer_id": 186434, "author": "Simon Peverett", "author_id": 6063, "author_profile": "https://Stackoverflow.com/users/6063", "pm_score": 3, "selected": false, "text": "/* Perkele ISO Puukko! */ -> Fucking Big Hack!\n" }, { "answer_id": 186457, "author": "belugabob", "author_id": 13397, "author_profile": "https://Stackoverflow.com/users/13397", "pm_score": 3, "selected": false, "text": "// He's dead, Jim!\n" }, { "answer_id": 186579, "author": "trshiv", "author_id": 21647, "author_profile": "https://Stackoverflow.com/users/21647", "pm_score": 3, "selected": false, "text": "/* My lawyer told me not to reveal */\n" }, { "answer_id": 186967, "author": "sharkin", "author_id": 7891, "author_profile": "https://Stackoverflow.com/users/7891", "pm_score": 10, "selected": false, "text": "// I dedicate all this code, all my work, to my wife, Darlene, who will \n// have to support me and our three children and the dog once it gets \n// released into the public.\n" }, { "answer_id": 186988, "author": "Razor", "author_id": 17211, "author_profile": "https://Stackoverflow.com/users/17211", "pm_score": 6, "selected": false, "text": "//Abandon all hope ye who enter beyond this point\n" }, { "answer_id": 187163, "author": "Richard Turner", "author_id": 12559, "author_profile": "https://Stackoverflow.com/users/12559", "pm_score": 3, "selected": false, "text": "// TODO - Comment this function\n" }, { "answer_id": 187183, "author": "Martin Brown", "author_id": 20553, "author_profile": "https://Stackoverflow.com/users/20553", "pm_score": 6, "selected": false, "text": "public class Contact\n{\n //... \n\n /// <summary>\n /// Gets or sets the name of the first.\n /// </summary>\n /// <value>The name of the first.</value>\n public string FirstName\n {\n get { return _firstName; }\n set { _firstName = value; }\n }\n}\n" }, { "answer_id": 187215, "author": "Larry", "author_id": 24472, "author_profile": "https://Stackoverflow.com/users/24472", "pm_score": 6, "selected": false, "text": "Repeat\n ...\nUntil (JesusChristsReturn) ' Not sure\n" }, { "answer_id": 187223, "author": "Retne", "author_id": 26489, "author_profile": "https://Stackoverflow.com/users/26489", "pm_score": 3, "selected": false, "text": "-- Change Log: Not needed. The code is perfect 'cause I wrote it.\n-- If you change it, it will break.\n" }, { "answer_id": 187405, "author": "Sean", "author_id": 26095, "author_profile": "https://Stackoverflow.com/users/26095", "pm_score": 9, "selected": false, "text": "long john; // silver\n" }, { "answer_id": 187549, "author": "ForCripeSake", "author_id": 14833, "author_profile": "https://Stackoverflow.com/users/14833", "pm_score": 6, "selected": false, "text": "//There can Only Be one HIGHLAN....err..Singleton\npublic class SomeSingleton\n{\n...\n}\n" }, { "answer_id": 187565, "author": "kjensen", "author_id": 22177, "author_profile": "https://Stackoverflow.com/users/22177", "pm_score": 7, "selected": false, "text": "virgin = 0; /* you're not a virgin anymore, sweety */\n" }, { "answer_id": 187599, "author": "Guido", "author_id": 12388, "author_profile": "https://Stackoverflow.com/users/12388", "pm_score": 4, "selected": false, "text": "i++; // increment variable i\n" }, { "answer_id": 188042, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "'RH 5/24/06 burn me if this dosn't work.. :)\n" }, { "answer_id": 188063, "author": "Collin Estes", "author_id": 20748, "author_profile": "https://Stackoverflow.com/users/20748", "pm_score": 5, "selected": false, "text": "//open lid\n\n\n//take sh!t\n\n\n//close lid\n" }, { "answer_id": 188100, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "# <magic type=\"voodoo\">\n\n...\n\n# </magic>\n" }, { "answer_id": 188413, "author": "itsmatt", "author_id": 7862, "author_profile": "https://Stackoverflow.com/users/7862", "pm_score": 6, "selected": false, "text": "// Catching exceptions is for communists\n" }, { "answer_id": 189279, "author": "André", "author_id": 9683, "author_profile": "https://Stackoverflow.com/users/9683", "pm_score": 4, "selected": false, "text": "DON'T TOUCH THIS SCRIPT -> XSLT is like arcane, black magic\n" }, { "answer_id": 189302, "author": "MattC", "author_id": 21126, "author_profile": "https://Stackoverflow.com/users/21126", "pm_score": 4, "selected": false, "text": "// Hard to explain\n" }, { "answer_id": 189312, "author": "Vincent", "author_id": 25658, "author_profile": "https://Stackoverflow.com/users/25658", "pm_score": 4, "selected": false, "text": "return null; //Not really null\n" }, { "answer_id": 189503, "author": "DGentry", "author_id": 4761, "author_profile": "https://Stackoverflow.com/users/4761", "pm_score": 7, "selected": false, "text": " * ...and don't just declare it volatile and think you've solved\n * the problem. You young punks think you know what volatile\n * means... why in my day we had to cast it volatile uphill\n * both ways, and the code still didn't work! Whippersnappers...\n" }, { "answer_id": 189713, "author": "moffdub", "author_id": 10759, "author_profile": "https://Stackoverflow.com/users/10759", "pm_score": 3, "selected": false, "text": "// zzzzZZZZzzzz....\n" }, { "answer_id": 189732, "author": "Mike Two", "author_id": 23659, "author_profile": "https://Stackoverflow.com/users/23659", "pm_score": 6, "selected": false, "text": "// human madable inconvenient. Way too sucks.\n" }, { "answer_id": 189740, "author": "Mark Bessey", "author_id": 17826, "author_profile": "https://Stackoverflow.com/users/17826", "pm_score": 7, "selected": false, "text": "// I know the line below is wrong, but it came that way from our IP vendor, and \n// the driver won't work if you \"fix\" it. I've had to revert this change 4 times\n// now. Leave it alone, or I will hunt you down and hurt you\nif (r = 0) {\n /* bunch of code here */\n}\nelse\n{\n /* even more code here */\n}\n" }, { "answer_id": 189859, "author": "PoppaVein", "author_id": 14889, "author_profile": "https://Stackoverflow.com/users/14889", "pm_score": 9, "selected": false, "text": "/*\n * You may think you know what the following code does.\n * But you dont. Trust me.\n * Fiddle with it, and youll spend many a sleepless\n * night cursing the moment you thought youd be clever\n * enough to \"optimize\" the code below.\n * Now close this file and go play with something else.\n */ \n" }, { "answer_id": 189938, "author": "Parappa", "author_id": 9974, "author_profile": "https://Stackoverflow.com/users/9974", "pm_score": 3, "selected": false, "text": "assert(0); // should never shit this point" }, { "answer_id": 190046, "author": "abarax", "author_id": 24390, "author_profile": "https://Stackoverflow.com/users/24390", "pm_score": 8, "selected": false, "text": "// I am not sure if we need this, but too scared to delete. \n" }, { "answer_id": 190139, "author": "NeilDurant", "author_id": 26718, "author_profile": "https://Stackoverflow.com/users/26718", "pm_score": 7, "selected": false, "text": "if(m_measures =/*=*/ --index)\n{\n ....\n" }, { "answer_id": 190535, "author": "Christoph Schiessl", "author_id": 20467, "author_profile": "https://Stackoverflow.com/users/20467", "pm_score": 3, "selected": false, "text": "Person p = new Person(\"John\", \"Doe\", \"male\");\nCollection women = new ArrayList();\nwomen.insert(p.getTail());\n" }, { "answer_id": 190866, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/*************************** Drag And Drop Section - Start (you should be me to mess with this section)*********************************************/\n" }, { "answer_id": 190869, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "if(count<0) count=0; //don't get me wrong but this has to be done :p\n" }, { "answer_id": 191005, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "[ThereBeDragons]\n //What is this?\npublic bool IsReusable\n{\n get{return false;}\n}\n" }, { "answer_id": 191049, "author": "Powerlord", "author_id": 15880, "author_profile": "https://Stackoverflow.com/users/15880", "pm_score": 1, "selected": false, "text": "try {\n dataSource.close();\n}\ncatch (SQLException ex) {\n // Do nothing, since we're going to trash this anyway\n}\n" }, { "answer_id": 191918, "author": "Dr. Bob", "author_id": 12182, "author_profile": "https://Stackoverflow.com/users/12182", "pm_score": 3, "selected": false, "text": "// Whoever put this here is an idiot...this doesn't work at all !" }, { "answer_id": 192010, "author": "hmcclungiii", "author_id": 24333, "author_profile": "https://Stackoverflow.com/users/24333", "pm_score": 1, "selected": false, "text": "''' <summary>\n''' Represents an exception that was logged. Since System.Exception implements IDictionary, it can't be\n''' serialized, so I had to write this. Pretty fucking stupid thing to have to do, System.Exception should\n''' be serializable right out of the box, IMHO.\n''' </summary>\n''' <remarks></remarks>\nPublic Class LogException\n" }, { "answer_id": 192040, "author": "JB King", "author_id": 8745, "author_profile": "https://Stackoverflow.com/users/8745", "pm_score": 5, "selected": false, "text": "catch (Ex as Exception)\n{\n // oh crap, we should do something.\n}\n" }, { "answer_id": 192098, "author": "Martin Brown", "author_id": 20553, "author_profile": "https://Stackoverflow.com/users/20553", "pm_score": 5, "selected": false, "text": "/// <summary>\n/// The possible outcomes of an update operation (save or delete)\n/// </summary>\npublic enum UpdateResult\n{\n\n /// <summary>\n /// Updated successfully\n /// </summary>\n Success = 0,\n\n /// <summary>\n /// Updated successfully\n /// </summary>\n Failed = 1\n}\n" }, { "answer_id": 192155, "author": "Kasper", "author_id": 18671, "author_profile": "https://Stackoverflow.com/users/18671", "pm_score": 1, "selected": false, "text": "// not brilliant solution, but fair enough heh.\n" }, { "answer_id": 192823, "author": "gedevan", "author_id": 20225, "author_profile": "https://Stackoverflow.com/users/20225", "pm_score": 9, "selected": false, "text": "try {\n\n} finally { // should never happen \n\n}\n" }, { "answer_id": 193577, "author": "Dano", "author_id": 26938, "author_profile": "https://Stackoverflow.com/users/26938", "pm_score": 4, "selected": false, "text": "Catch (Exception e) {\n //eat it\n}\n" }, { "answer_id": 193705, "author": "Knobloch", "author_id": 2878, "author_profile": "https://Stackoverflow.com/users/2878", "pm_score": 7, "selected": false, "text": "/* Emits a 7-Hz tone for 10 seconds.\n True story: 7 Hz is the resonant frequency of a\n chicken's skull cavity. This was determined\n empirically in Australia, where a new factory\n generating 7-Hz tones was located too close to a\n chicken ranch: When the factory started up, all the\n chickens died.\n Your PC may not be able to emit a 7-Hz tone. */\n\nmain()\n{\n sound(7);\n delay(10000);\n nosound();\n}\n" }, { "answer_id": 194065, "author": "John Nilsson", "author_id": 24243, "author_profile": "https://Stackoverflow.com/users/24243", "pm_score": 0, "selected": false, "text": "[onload_1;block=begin;when 1=0]\n\nSome of the techinques in this template are rather obscure, just trust me, they need to be there.\nOTOH a better sollution would be to create a few seperate templates and pick one in the php-script...\n\n[onload_1;block=end]\n" }, { "answer_id": 194269, "author": "Chris Jefferson", "author_id": 27074, "author_profile": "https://Stackoverflow.com/users/27074", "pm_score": 8, "selected": false, "text": "// I don't know why I need this, but it stops the people being upside-down\n\nx = -x;\n" }, { "answer_id": 194372, "author": "HTTP 410", "author_id": 13118, "author_profile": "https://Stackoverflow.com/users/13118", "pm_score": 6, "selected": false, "text": "// This procedure is really good for your dorsolateral prefrontal cortex." }, { "answer_id": 194393, "author": "HTTP 410", "author_id": 13118, "author_profile": "https://Stackoverflow.com/users/13118", "pm_score": 6, "selected": false, "text": "// Any maintenance developer who can't quote entire Monty Python\n// movies from memory has no business being a developer. \nconst string LancelotsFavoriteColor = \"$0204FB\"" }, { "answer_id": 194433, "author": "MrBoJangles", "author_id": 13578, "author_profile": "https://Stackoverflow.com/users/13578", "pm_score": 3, "selected": false, "text": "Case 1:\n ...\n break;\n ...\n//I don't want do do this but [my coworker] says it's part of the code standard\ndefault:\n break;\n" }, { "answer_id": 194475, "author": "Josh Segall", "author_id": 2659, "author_profile": "https://Stackoverflow.com/users/2659", "pm_score": 8, "selected": false, "text": "doRun.run(); // ... \"a doo run run\".\n" }, { "answer_id": 194506, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "DvLog::Log(\"This silly log message fixes a PSCRIPT5.DLL gpf when printing to Adobe.\");\n" }, { "answer_id": 194720, "author": "Joshua", "author_id": 14768, "author_profile": "https://Stackoverflow.com/users/14768", "pm_score": 3, "selected": false, "text": "'Do not optimize these next two lines. Compiler bugs lurk.\n" }, { "answer_id": 194743, "author": "interstar", "author_id": 8482, "author_profile": "https://Stackoverflow.com/users/8482", "pm_score": 4, "selected": false, "text": "; Rechnen ja ; have faith in yes\n" }, { "answer_id": 195155, "author": "smaclell", "author_id": 22914, "author_profile": "https://Stackoverflow.com/users/22914", "pm_score": 3, "selected": false, "text": "/// I intend to do this as shittily as possible because there are many better products that will totally blow this out of the water\n/// and we don't have them so whatever\n /// sidestep a bug in WCF (that we can't send types across)\n/// or, depending on how you look at, this issue is a Feature\n if( where == null)//be nice\n" }, { "answer_id": 195187, "author": "sbeskur", "author_id": 10446, "author_profile": "https://Stackoverflow.com/users/10446", "pm_score": 5, "selected": false, "text": "/*\n\n* @author Andrew Asta\n*/\npublic class AstaClass{\n\n private String astaVar1; \n private String astaVar2; \n private String astaVar3; \n private String astaVar4; \n private String astaVar5; \n private String astaVar6; \n private String astaVar7; \n private String astaVar8; \n private String astaVar9; \n private String astaVar10; \n\n public void AstaSaysGetData(){\n //JDBC statement to populate astavars 1 through 10\n //...\n String astaSqlStatment = \"Select astaCol1, astaCol2, astaCol3... From AstaTable Where...\";\n //..\n //...\n }\n\n //Perform data manipulation on astavars...\n public void AstaSaysGaaGaa(){\n [removed for sake of brevity]\n }\n\n\n //Perform more data manipulation on astavars...\n public void AstaSaysGooGoO(){\n [removed for sake of brevity]\n }\n\n public void AstaSaysPersist(){ \n //JDBC statement to save astavars to DB \n String astaSqlStatment = \"Update AstaTable set astaCol1 = @astaVar1\n , set astaCol2 = @astaVar2\n , set astaCol3 = astaCol3... \n Where...\";\n }\n}\n" }, { "answer_id": 195196, "author": "Rick", "author_id": 14138, "author_profile": "https://Stackoverflow.com/users/14138", "pm_score": 2, "selected": false, "text": "-- This line negates the @inverseqty, which is the\n-- negative of the @insertedquantity. This works through the\n-- magic of the trigger. In fact, this code is a lot like\n-- the bermuda triangle!\n@negquantity = -1 * @inverseqty\n" }, { "answer_id": 195198, "author": "Hafthor", "author_id": 4489, "author_profile": "https://Stackoverflow.com/users/4489", "pm_score": 7, "selected": false, "text": " mov si, pCard ; captain?\n" }, { "answer_id": 195199, "author": "kender", "author_id": 4172, "author_profile": "https://Stackoverflow.com/users/4172", "pm_score": 5, "selected": false, "text": "// and there is where the dragon lives\n" }, { "answer_id": 195418, "author": "stuartcw", "author_id": 27065, "author_profile": "https://Stackoverflow.com/users/27065", "pm_score": 4, "selected": false, "text": "/* This comment was just added in order to check-in a file that was last \nchecked in by [Insert Programmer FirstName] \"Back-to-the-Future\" [Insert \nProgrammer LastName]. While testing for year 2000 problems, he accidentally \nchecked-in this file while his machine clock was set forward to the year 2000. \nThis meant that the source code was always newer than the object file and \ncompiled every time the code was built. I'm checking this file in again to \nfix that. */\n" }, { "answer_id": 195432, "author": "Rob Wells", "author_id": 2974, "author_profile": "https://Stackoverflow.com/users/2974", "pm_score": 1, "selected": false, "text": "/* core dumps around here but this is hardly ever called */\n /* don't know why this works but it seeems to be ok */\n" }, { "answer_id": 196132, "author": "Nat", "author_id": 13813, "author_profile": "https://Stackoverflow.com/users/13813", "pm_score": 2, "selected": false, "text": "' Oh man I'm pissed. I think I better go home.\n" }, { "answer_id": 196782, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "//Not a bug, parameter position can change..., if you think this is wrong, you are in fact wrong.\n" }, { "answer_id": 196886, "author": "noocyte", "author_id": 11220, "author_profile": "https://Stackoverflow.com/users/11220", "pm_score": 2, "selected": false, "text": "// Jay knows what's going on here, but will he remember in a year? Not very likely, this code sucks, but it works so do not change it.\n" }, { "answer_id": 196934, "author": "Andreas Magnusson", "author_id": 5811, "author_profile": "https://Stackoverflow.com/users/5811", "pm_score": 3, "selected": false, "text": "// THE LOOP THAT DO EVERYTHING!!!!!!!\n" }, { "answer_id": 197847, "author": "jpinto3912", "author_id": 11567, "author_profile": "https://Stackoverflow.com/users/11567", "pm_score": 3, "selected": false, "text": "> // And now, for something completely\n> // different:\n" }, { "answer_id": 197874, "author": "Paul Lalonde", "author_id": 5782, "author_profile": "https://Stackoverflow.com/users/5782", "pm_score": 5, "selected": false, "text": "/* HP-UX sucks wet farts from dead pigeons' asses */\n" }, { "answer_id": 197879, "author": "Dan", "author_id": 8040, "author_profile": "https://Stackoverflow.com/users/8040", "pm_score": 1, "selected": false, "text": "//Forward declarations:\n\nclass X {}; // TODO: Remove {} ! When we get X defined....\n" }, { "answer_id": 199806, "author": "Thiago Figueiro", "author_id": 27693, "author_profile": "https://Stackoverflow.com/users/27693", "pm_score": 6, "selected": false, "text": "/*\n * 'schedule()' is the scheduler function. It's a very simple and nice\n * scheduler: it's not perfect, but certainly works for most things.\n * The one thing you might take a look at is the signal-handler code here.\n *\n * NOTE!! Task 0 is the 'idle' task, which gets called when no other\n * tasks can run. It can not be killed, and it cannot sleep. The 'state'\n * information in task[0] is never used.\n *\n * The \"confuse_gcc\" goto is used only to get better assembly code..\n * Dijkstra probably hates me.\n */\nasmlinkage void schedule(void)\n" }, { "answer_id": 200024, "author": "Matt", "author_id": 27718, "author_profile": "https://Stackoverflow.com/users/27718", "pm_score": 4, "selected": false, "text": "// Houston, we have a problem" }, { "answer_id": 200038, "author": "Pat", "author_id": 36, "author_profile": "https://Stackoverflow.com/users/36", "pm_score": 2, "selected": false, "text": "// No women, no children... What movie???\n" }, { "answer_id": 200154, "author": "Miserable Variable", "author_id": 18573, "author_profile": "https://Stackoverflow.com/users/18573", "pm_score": 0, "selected": false, "text": "C=\"Lint says \"argument Manual isn't used.\" What's that\nmean?\";\n" }, { "answer_id": 203901, "author": "blindauer", "author_id": 22403, "author_profile": "https://Stackoverflow.com/users/22403", "pm_score": 5, "selected": false, "text": "// TODO make this work\n" }, { "answer_id": 204187, "author": "Joshi Spawnbrood", "author_id": 15392, "author_profile": "https://Stackoverflow.com/users/15392", "pm_score": 5, "selected": false, "text": "// Remove this if you wanna be fired\n" }, { "answer_id": 204235, "author": "Anonymous", "author_id": 15073, "author_profile": "https://Stackoverflow.com/users/15073", "pm_score": 5, "selected": false, "text": "/*\n\n** The author disclaims copyright to this source code. In place of \n** a legal notice, here is a blessing: \n** \n** May you do good and not evil. \n** May you find forgiveness for yourself and forgive others. \n** May you share freely, never taking more than you give.\n\n*/\n" }, { "answer_id": 208240, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": " // WARNING!!!\n // Very perversive code ahead!\n\n... about a 20 lines of \"very perversive\" code ...\n\n// Now you can call your grandmother back. ;)\n" }, { "answer_id": 210422, "author": "TJ L", "author_id": 12605, "author_profile": "https://Stackoverflow.com/users/12605", "pm_score": 6, "selected": false, "text": "if (/*you*/ $_GET['action']) { //celebrate\n" }, { "answer_id": 215166, "author": "Russell Bryant", "author_id": 23224, "author_profile": "https://Stackoverflow.com/users/23224", "pm_score": 6, "selected": false, "text": " /* Mark: If there's one thing you learn from this code, it is this...\n Never, ever fly Air France. Their customer service is absolutely\n the worst. I've never heard the words \"That's not my problem\" as \n many times as I have from their staff -- It should, without doubt\n be their corporate motto if it isn't already. Don't bother giving \n them business because you're just a pain in their side and they\n will be sure to let you know the first time you speak to them.\n\n If you ever want to make me happy just tell me that you, too, will\n never fly Air France again either (in spite of their excellent\n cuisine). \n\n Update by oej: The merger with KLM has transferred this\n behaviour to KLM as well. \n Don't bother giving them business either...\n\n Only if you want to travel randomly without luggage, you\n might pick either of them.\n */\n" }, { "answer_id": 216127, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "Fix problem where Nulls don't work properly. Stupid Microsoft!\n" }, { "answer_id": 216139, "author": "blank", "author_id": 1348, "author_profile": "https://Stackoverflow.com/users/1348", "pm_score": 3, "selected": false, "text": "// fix for groupid > 9 \n// if groupid ever gets to 100 everything will break (again)\n\nif (groupid < 10) {\ngroupid = \"0\" + groupid;\n}\n" }, { "answer_id": 216159, "author": "edomaur", "author_id": 14262, "author_profile": "https://Stackoverflow.com/users/14262", "pm_score": 4, "selected": false, "text": "// Added because boss changed his mind : 20020111,20020501,20020820, ...\n// Commented out because boss changed his mind : 20020201,20020614,20020908, ...\n" }, { "answer_id": 216744, "author": "paercebal", "author_id": 14089, "author_profile": "https://Stackoverflow.com/users/14089", "pm_score": 8, "selected": false, "text": "// I am not responsible of this code.\n// They made me write it, against my will.\n" }, { "answer_id": 216943, "author": "Brian R. Bondy", "author_id": 3153, "author_profile": "https://Stackoverflow.com/users/3153", "pm_score": 5, "selected": false, "text": "//If you're reading this, then my program is probably a success\n" }, { "answer_id": 216948, "author": "Gabriël", "author_id": 2104, "author_profile": "https://Stackoverflow.com/users/2104", "pm_score": 1, "selected": false, "text": "// GK Experimental\n" }, { "answer_id": 217681, "author": "Nat", "author_id": 13813, "author_profile": "https://Stackoverflow.com/users/13813", "pm_score": 3, "selected": false, "text": "Without a crash \n\nOr mighty bang \n\nThe sync disk \n\nDid it's process hang\n" }, { "answer_id": 222164, "author": "Matthew Scouten", "author_id": 8508, "author_profile": "https://Stackoverflow.com/users/8508", "pm_score": 3, "selected": false, "text": "struct core_unlocker\n{\n core_unlocker(lock)\n {\n m_lock = lock\n unlock(lock) //Abandon All Locks, Ye Who Enter Core!\n }\n ~core_unlocker()\n {\n lock(m_lock)\n } \n private:\n Corelock m_lock;\n}\n" }, { "answer_id": 222193, "author": "George Mauer", "author_id": 5056, "author_profile": "https://Stackoverflow.com/users/5056", "pm_score": 2, "selected": false, "text": "// this part is more difficult\n" }, { "answer_id": 225428, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "else\n{\n // wobbly wilson said this would *never* happen!!\n}\n" }, { "answer_id": 235510, "author": "coppro", "author_id": 16855, "author_profile": "https://Stackoverflow.com/users/16855", "pm_score": 3, "selected": false, "text": "// These were orginally up and down. When it was clear the names were\n// inapplicable, they were renamed to retain the joke.\n// Sorry if you were hoping for useful variable names.\nquantum strange, charm;\n" }, { "answer_id": 236424, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "aComment = 'this is not aComment' # this is aComment\nclass T(object):\n def f(this):\n this is not aComment\n" }, { "answer_id": 237886, "author": "alex", "author_id": 26787, "author_profile": "https://Stackoverflow.com/users/26787", "pm_score": 2, "selected": false, "text": "// this code was written after a version trying to do {this} failed because of {reason},\n// previously we were doing {this} which failed because of {reason}. This is \n// now written {this} way so that {lots of reasons here}. If you want to touch\n// this code, please make sure that it produces the right answers when tested with:\n//\n// {some sort of unit test}\n" }, { "answer_id": 240292, "author": "Joshi Spawnbrood", "author_id": 15392, "author_profile": "https://Stackoverflow.com/users/15392", "pm_score": 1, "selected": false, "text": "// this control (Resistance) is FUTILE! \n" }, { "answer_id": 240381, "author": "Pramod", "author_id": 1386292, "author_profile": "https://Stackoverflow.com/users/1386292", "pm_score": 4, "selected": false, "text": "return 0; // Happy ending\n int32_t Interpolate1DSignal(\n Array1D<float64>::Handle hfInputSamples, // samples to be interpolated\n Array1D<float64>::Handle hfInterpolationFilter, // polyphase filter coefficients,\n int32_t iFilterInterpolationFactor, // # of \"rows\" in polyphase filter\n int32_t iFilterLength, // Length of each row in filter\n float64 fInterpolationFactor, // Factor to interpolate the\n // signal by\n float64 fTimingOffset, // Offset into the signal (units \n // of samples)\n Array1D<float64>::Handle hfOutputSamples // left as an exercise for the reader\n);\n" }, { "answer_id": 250413, "author": "Chris Kloberdanz", "author_id": 28714, "author_profile": "https://Stackoverflow.com/users/28714", "pm_score": 2, "selected": false, "text": "# This is convoluted and evil, sorry.\n" }, { "answer_id": 271471, "author": "Jason Sundram", "author_id": 2683, "author_profile": "https://Stackoverflow.com/users/2683", "pm_score": 2, "selected": false, "text": "#define MSGTAG_B33R 0x723 /* RIPLVB */\n" }, { "answer_id": 309983, "author": "AdamBT", "author_id": 22426, "author_profile": "https://Stackoverflow.com/users/22426", "pm_score": 3, "selected": false, "text": "// Hardcoded this for time sake ... will make andrew fix later :)\n" }, { "answer_id": 310251, "author": "Jared Knipp", "author_id": 39803, "author_profile": "https://Stackoverflow.com/users/39803", "pm_score": 2, "selected": false, "text": "'\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n'\n' NOTE: DON'T SCREW WITH THIS CODE UNLESS YOU REALLY UNDERSTAND IT!\n'\n'\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n" }, { "answer_id": 311113, "author": "Overflown", "author_id": 37840, "author_profile": "https://Stackoverflow.com/users/37840", "pm_score": 4, "selected": false, "text": "\nif (case1) { // trivial\n...\n}\nelse { // we are screwed\n /* fill in later */\n}\n" }, { "answer_id": 312203, "author": "Chris Lloyd", "author_id": 42413, "author_profile": "https://Stackoverflow.com/users/42413", "pm_score": 8, "selected": false, "text": "# To understand recursion, see the bottom of this file \n # To understand recursion, see the top of this file\n" }, { "answer_id": 315112, "author": "Joseph Ferris", "author_id": 15906, "author_profile": "https://Stackoverflow.com/users/15906", "pm_score": 3, "selected": false, "text": "/// <summary>I pity the \"foo\".</summary>\n Remove() /// <summary>A \"foo\" and his money are soon parted.</summary>\n" }, { "answer_id": 316042, "author": "Steve T", "author_id": 415, "author_profile": "https://Stackoverflow.com/users/415", "pm_score": 3, "selected": false, "text": "<!-- THIS IS THE MAIN CONFIGURATION FILE FOR THE ENTIRE BLOODY DIRECTORY -->\n<!-- WHATEVER YOU DO, DO NOT EDIT THIS FILE WITHOUT TALKING TO ME FIRST -->\n<!-- I'M SERIOUS -->\n<!-- (scroll down) -->\n" }, { "answer_id": 316112, "author": "bikesandcode", "author_id": 40112, "author_profile": "https://Stackoverflow.com/users/40112", "pm_score": 7, "selected": false, "text": "float Q_rsqrt( float number )\n{\n long i;\n float x2, y;\n const float threehalfs = 1.5F;\n\n x2 = number * 0.5F;\n y = number;\n i = * ( long * ) &y; // evil floating point bit level hacking\n i = 0x5f3759df - ( i >> 1 ); // what the fuck?\n y = * ( float * ) &i;\n y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration\n // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed\n\n #ifndef Q3_VM\n #ifdef __linux__\n assert( !isnan(y) ); // bk010122 - FPE?\n #endif\n #endif\n return y;\n}\n" }, { "answer_id": 316233, "author": "johnc", "author_id": 5302, "author_profile": "https://Stackoverflow.com/users/5302", "pm_score": 10, "selected": false, "text": "//When I wrote this, only God and I understood what I was doing\n//Now, God only knows\n" }, { "answer_id": 331424, "author": "jumpinjackie", "author_id": 18731, "author_profile": "https://Stackoverflow.com/users/18731", "pm_score": 7, "selected": false, "text": "options.BatchSize = 300; //Madness? THIS IS SPARTA!\n" }, { "answer_id": 334450, "author": "Paul Mitchell", "author_id": 38966, "author_profile": "https://Stackoverflow.com/users/38966", "pm_score": 2, "selected": false, "text": " C I don't know what this next bit does so I'll jump around it\n GOTO DONE.\n" }, { "answer_id": 334499, "author": "Nikola Stjelja", "author_id": 32582, "author_profile": "https://Stackoverflow.com/users/32582", "pm_score": 3, "selected": false, "text": "\n//Iterate by one\n$i++;\n" }, { "answer_id": 334507, "author": "CLaRGe", "author_id": 20507, "author_profile": "https://Stackoverflow.com/users/20507", "pm_score": 2, "selected": false, "text": "// good luck!\n" }, { "answer_id": 334568, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "//Mr. Compiler, please do not read this.\n" }, { "answer_id": 335114, "author": "Rob Prouse", "author_id": 30827, "author_profile": "https://Stackoverflow.com/users/30827", "pm_score": 3, "selected": false, "text": "#region Hack - Shield Eyes Before Expanding\n\n/// <summary>\n/// A single uint with all of the bits set to represent the different tracing\n/// </summary>\n/// <remarks>\n/// Ugly I know, so if you can think of a better way, feel free to rewrite.\n/// </remarks>\n[Browsable(false)]\npublic uint TraceBitfield\n{\n // Snip\n}\n\n#endregion\n" }, { "answer_id": 339377, "author": "Sumptin", "author_id": 43061, "author_profile": "https://Stackoverflow.com/users/43061", "pm_score": 3, "selected": false, "text": "//Attempt Handshake: Hello? This is London calling. Are we reaching you?\n\n\n//Handshake Failed: I don't understand...he just hung up.\n" }, { "answer_id": 344863, "author": "NotDan", "author_id": 3291, "author_profile": "https://Stackoverflow.com/users/3291", "pm_score": 5, "selected": false, "text": "//Visual Studio Bug Workaround:\n//http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101677\n\n//To fix 'CJumpToHelper::GetInstance()' : undeclared identifier compiler errors, change the number lines below\n//until the file compiles correctly. (This needs to be done anytime a change is made to this file)\n\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n //////////////////////////////////////: There should be 1-10 of these lines\n" }, { "answer_id": 344907, "author": "Jeremiah", "author_id": 34183, "author_profile": "https://Stackoverflow.com/users/34183", "pm_score": 7, "selected": false, "text": "int MyFunction()\n{\n // There once was a man named Dave\n int Result = 0;\n\n // Whose code just wouldn't behave\n MyObject *Ptr = new MyObject();\n\n // He left to go to a meetin'\n Result = Ptr->DoSomething();\n\n // And left his memory a leakin'\n return Result;\n}\n" }, { "answer_id": 348483, "author": "vdhant", "author_id": 30572, "author_profile": "https://Stackoverflow.com/users/30572", "pm_score": 2, "selected": false, "text": "//select is a royal pain in the ass where \n//the parameter passed to CreateQuery isn't actually the one that goes in the call\n//requiring this workaround. Not sure how straight Linq to Objects does it.\n //expressions have to be compiled in order to work with the method call on \n//straight Enumerable somehow, LINQ to objects itself magically does this. \n//Reflector shows a mess, so I (Aaron) invented my own way. God love unit tests!\n //ok, this is a hairy, dirty, and nasty piece of code\n //the alternatives are substantially worse than this though\n //i.e. when you do your own provider, LINQ assumes that\n //you are going to implement your own expression tree visitor and\n //do it all yourself. Frankly, I still have xmas shopping to do\n //and I really don't want us to be foobared when we get\n //even more extension methods added to LINQ\n //therefore, we are pulling execute based on taking the calling the \n //standard execute on enumerable, but using our own class\n //\n //optimization can occur from here on an as needed basis, that is\n //check for the value of mex.Method.Name, and write a handler for\n //that method\n //\n //also, it may not be a bad idea to rather than do this reflection \n //each and every time somehow cache the reflected methodinfos and do \n //lookups that way that said, we need a complete red/green/refactor \n //cycle here before I am touching that one\n //Compile that mutherf-ker, invoke it, and get the resulting hash\n" }, { "answer_id": 350893, "author": "theschmitzer", "author_id": 2167252, "author_profile": "https://Stackoverflow.com/users/2167252", "pm_score": 4, "selected": false, "text": "// Jesus told me to skip to the end of the message here\n" }, { "answer_id": 354692, "author": "Jim McKeeth", "author_id": 255, "author_profile": "https://Stackoverflow.com/users/255", "pm_score": 1, "selected": false, "text": "// Oh what a tangled web we weave\n// When first we practice to deceive\n// ASTA\n" }, { "answer_id": 360696, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "/* Sun, you just can't beat me, you just can't. Stop trying,\n* give up. I'm serious, I am going to kick the living shit\n* out of you, game over, lights out.\n*/\n /* 2,191 lines of complete and utter shit coming up... */\n #if 0 /* XXX No fucking way dude... */\n" }, { "answer_id": 368692, "author": "Lucas Gabriel Sánchez", "author_id": 20601, "author_profile": "https://Stackoverflow.com/users/20601", "pm_score": 4, "selected": false, "text": "# Limit length of buffer to try to send, because some OSes are too\n# stupid to do so themselves (ahem windows)\nreturn self.socket.send(buffer(data, 0, self.SEND_LIMIT))\n" }, { "answer_id": 368709, "author": "cLFlaVA", "author_id": 45109, "author_profile": "https://Stackoverflow.com/users/45109", "pm_score": 3, "selected": false, "text": "// The code below needs to be changed immediately.\n// I wish I was a little bit taller\n// I wish I was a baller\n// I wish I had a girl who looked good, I would call her.\n" }, { "answer_id": 375554, "author": "George", "author_id": 8803, "author_profile": "https://Stackoverflow.com/users/8803", "pm_score": 3, "selected": false, "text": "catch (Domain.ConcurrencyException)\n{\n // somebody changed it between the time we loaded it and now.\n // weird, huh?\n}\n" }, { "answer_id": 377591, "author": "alepuzio", "author_id": 45745, "author_profile": "https://Stackoverflow.com/users/45745", "pm_score": 3, "selected": false, "text": "/**\n*@return the value \n*@param key: the id of the list of instruments\n*@PS this function is a violation of all the laws of the \n*software engineering, \n*commons sense, highway code \n*and ONU decision about the coding.\nThat sh*t...\n*/\n" }, { "answer_id": 377894, "author": "Keltia", "author_id": 16143, "author_profile": "https://Stackoverflow.com/users/16143", "pm_score": 3, "selected": false, "text": "/*\n * A virgin directory (no blushing please).\n */\n" }, { "answer_id": 378918, "author": "FreeMemory", "author_id": 2132, "author_profile": "https://Stackoverflow.com/users/2132", "pm_score": 3, "selected": false, "text": "/*\n* Dear Richard Stallman,\n*\n* This one's for you.\n*\n* Sincerely,\n* Me\n*\n*/\nMODULE_LICENSE( \"GPL\" );\n" }, { "answer_id": 378932, "author": "John Channing", "author_id": 3305, "author_profile": "https://Stackoverflow.com/users/3305", "pm_score": 1, "selected": false, "text": "/* Hammer Time! */\n" }, { "answer_id": 378987, "author": "llimllib", "author_id": 42559, "author_profile": "https://Stackoverflow.com/users/42559", "pm_score": 7, "selected": false, "text": "/*\nMajor subtleties ahead: Most hash schemes depend on having a \"good\" hash\nfunction, in the sense of simulating randomness. Python doesn't: its most\nimportant hash functions (for strings and ints) are very regular in common\ncases:\n\n>>> map(hash, (0, 1, 2, 3))\n[0, 1, 2, 3]\n>>> map(hash, (\"namea\", \"nameb\", \"namec\", \"named\"))\n[-1658398457, -1658398460, -1658398459, -1658398462]\n>>>\n\nThis isn't necessarily bad! To the contrary, in a table of size 2**i, taking\nthe low-order i bits as the initial table index is extremely fast, and there\nare no collisions at all for dicts indexed by a contiguous range of ints.\nThe same is approximately true when keys are \"consecutive\" strings. So this\ngives better-than-random behavior in common cases, and that's very desirable.\n\nOTOH, when collisions occur, the tendency to fill contiguous slices of the\nhash table makes a good collision resolution strategy crucial. Taking only\nthe last i bits of the hash code is also vulnerable: for example, consider\n[i << 16 for i in range(20000)] as a set of keys. Since ints are their own\nhash codes, and this fits in a dict of size 2**15, the last 15 bits of every\nhash code are all 0: they *all* map to the same table index.\n\nBut catering to unusual cases should not slow the usual ones, so we just take\nthe last i bits anyway. It's up to collision resolution to do the rest. If\nwe *usually* find the key we're looking for on the first try (and, it turns\nout, we usually do -- the table load factor is kept under 2/3, so the odds\nare solidly in our favor), then it makes best sense to keep the initial index\ncomputation dirt cheap.\n\nThe first half of collision resolution is to visit table indices via this\nrecurrence:\n\n j = ((5*j) + 1) mod 2**i\n\nFor any initial j in range(2**i), repeating that 2**i times generates each\nint in range(2**i) exactly once (see any text on random-number generation for\nproof). By itself, this doesn't help much: like linear probing (setting\nj += 1, or j -= 1, on each loop trip), it scans the table entries in a fixed\norder. This would be bad, except that's not the only thing we do, and it's\nactually *good* in the common cases where hash keys are consecutive. In an\nexample that's really too small to make this entirely clear, for a table of\nsize 2**3 the order of indices is:\n\n 0 -> 1 -> 6 -> 7 -> 4 -> 5 -> 2 -> 3 -> 0 [and here it's repeating]\n\nIf two things come in at index 5, the first place we look after is index 2,\nnot 6, so if another comes in at index 6 the collision at 5 didn't hurt it.\nLinear probing is deadly in this case because there the fixed probe order\nis the *same* as the order consecutive keys are likely to arrive. But it's\nextremely unlikely hash codes will follow a 5*j+1 recurrence by accident,\nand certain that consecutive hash codes do not.\n\nThe other half of the strategy is to get the other bits of the hash code\ninto play. This is done by initializing a (unsigned) vrbl \"perturb\" to the\nfull hash code, and changing the recurrence to:\n\n j = (5*j) + 1 + perturb;\n perturb >>= PERTURB_SHIFT;\n use j % 2**i as the next table index;\n\nNow the probe sequence depends (eventually) on every bit in the hash code,\nand the pseudo-scrambling property of recurring on 5*j+1 is more valuable,\nbecause it quickly magnifies small differences in the bits that didn't affect\nthe initial index. Note that because perturb is unsigned, if the recurrence\nis executed often enough perturb eventually becomes and remains 0. At that\npoint (very rarely reached) the recurrence is on (just) 5*j+1 again, and\nthat's certain to find an empty slot eventually (since it generates every int\nin range(2**i), and we make sure there's always at least one empty slot).\n\nSelecting a good value for PERTURB_SHIFT is a balancing act. You want it\nsmall so that the high bits of the hash code continue to affect the probe\nsequence across iterations; but you want it large so that in really bad cases\nthe high-order hash bits have an effect on early iterations. 5 was \"the\nbest\" in minimizing total collisions across experiments Tim Peters ran (on\nboth normal and pathological cases), but 4 and 6 weren't significantly worse.\n\nHistorical: Reimer Behrends contributed the idea of using a polynomial-based\napproach, using repeated multiplication by x in GF(2**n) where an irreducible\npolynomial for each table size was chosen such that x was a primitive root.\nChristian Tismer later extended that to use division by x instead, as an\nefficient way to get the high bits of the hash code into play. This scheme\nalso gave excellent collision statistics, but was more expensive: two\nif-tests were required inside the loop; computing \"the next\" index took about\nthe same number of operations but without as much potential parallelism\n(e.g., computing 5*j can go on at the same time as computing 1+perturb in the\nabove, and then shifting perturb can be done while the table index is being\nmasked); and the dictobject struct required a member to hold the table's\npolynomial. In Tim's experiments the current scheme ran faster, produced\nequally good collision statistics, needed less code & used less memory.\n\nTheoretical Python 2.5 headache: hash codes are only C \"long\", but\nsizeof(Py_ssize_t) > sizeof(long) may be possible. In that case, and if a\ndict is genuinely huge, then only the slots directly reachable via indexing\nby a C long can be the first slot in a probe sequence. The probe sequence\nwill still eventually reach every slot in the table, but the collision rate\non initial probes may be much higher than this scheme was designed for.\nGetting a hash code as fat as Py_ssize_t is the only real cure. But in\npractice, this probably won't make a lick of difference for many years (at\nwhich point everyone will have terabytes of RAM on 64-bit boxes).\n*/\n" }, { "answer_id": 379021, "author": "llimllib", "author_id": 42559, "author_profile": "https://Stackoverflow.com/users/42559", "pm_score": 4, "selected": false, "text": "//the XML returned from this request is *mind-bogglingly* bad. Terrifyingly bad.\n//a completed batch looks like this:\n//<Batch>batchid=363777811 status=Done dateandtime=09/18/2007 09:53:10 PDT activateditems=335 numberofwarnings=0 itemsnotacivated=17 </Batch>\n//and an incomplete batch like:\n//<Batch>batchid=363778361 status=In Progress </Batch>\n//so we'll just parse each item as a regex. Thanks Amazon.\n" }, { "answer_id": 379627, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "/* Honest this works */\n" }, { "answer_id": 379687, "author": "Mark Beckwith", "author_id": 45799, "author_profile": "https://Stackoverflow.com/users/45799", "pm_score": 4, "selected": false, "text": "// This code was written by a genius so don't try to understand it with\n// your tiny little brain.\n" }, { "answer_id": 381386, "author": "Richard Ev", "author_id": 39709, "author_profile": "https://Stackoverflow.com/users/39709", "pm_score": 2, "selected": false, "text": "// echt halmaal gek - no way!\n" }, { "answer_id": 381392, "author": "Richard Ev", "author_id": 39709, "author_profile": "https://Stackoverflow.com/users/39709", "pm_score": 4, "selected": false, "text": "&h723 ' RIP LVB\n" }, { "answer_id": 381499, "author": "Nicolas", "author_id": 18800, "author_profile": "https://Stackoverflow.com/users/18800", "pm_score": 1, "selected": false, "text": "// Description : !!! TODO" }, { "answer_id": 381523, "author": "Michael Bobick", "author_id": 3425, "author_profile": "https://Stackoverflow.com/users/3425", "pm_score": 1, "selected": false, "text": "Abandon hope all ye who enter here" }, { "answer_id": 381524, "author": "chaos", "author_id": 47529, "author_profile": "https://Stackoverflow.com/users/47529", "pm_score": 6, "selected": false, "text": "// The ratio of a circle's circumference to its diameter. Remember to change\n// this to 3.0 if you move to a site in Indiana.\n\n#define Pi 3.1415927\n" }, { "answer_id": 381599, "author": "Brian Rudolph", "author_id": 33114, "author_profile": "https://Stackoverflow.com/users/33114", "pm_score": 7, "selected": false, "text": "ICantBelieveImUsingAGoto:\n" }, { "answer_id": 383547, "author": "Andy Webb", "author_id": 10931, "author_profile": "https://Stackoverflow.com/users/10931", "pm_score": 0, "selected": false, "text": "REM Don't delete this print statement ****** will die\n" }, { "answer_id": 385765, "author": "barfoon", "author_id": 1390354, "author_profile": "https://Stackoverflow.com/users/1390354", "pm_score": 1, "selected": false, "text": "// fudge the group stuff\n" }, { "answer_id": 385771, "author": "barfoon", "author_id": 1390354, "author_profile": "https://Stackoverflow.com/users/1390354", "pm_score": 2, "selected": false, "text": "// this is daggy??\n" }, { "answer_id": 386201, "author": "pi.", "author_id": 15274, "author_profile": "https://Stackoverflow.com/users/15274", "pm_score": 2, "selected": false, "text": "# let's pretend we are free, for a while\n" }, { "answer_id": 389723, "author": "martinus", "author_id": 48181, "author_profile": "https://Stackoverflow.com/users/48181", "pm_score": 9, "selected": false, "text": "/**\n * Always returns true.\n */\npublic boolean isAvailable() {\n return false;\n}\n" }, { "answer_id": 400187, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 3, "selected": false, "text": "#region quis custodiet ipsos custodes?\n\n[Fact]\npublic void TestPositive()\n{\n Assert.Equal(4, 2 + 2);\n}\n\n[Fact]\npublic void TestNegative()\n{\n Assert.Equal(5, 2 + 2);\n}\n\n#endregion\n" }, { "answer_id": 400211, "author": "Yuval", "author_id": 2819, "author_profile": "https://Stackoverflow.com/users/2819", "pm_score": 7, "selected": false, "text": "// This comment is self explanatory.\n" }, { "answer_id": 400230, "author": "Perry Neal", "author_id": 44633, "author_profile": "https://Stackoverflow.com/users/44633", "pm_score": 4, "selected": false, "text": "// This is crap code but it's 3 a.m. and I need to get this working.\n" }, { "answer_id": 417196, "author": "user24985", "author_id": 24985, "author_profile": "https://Stackoverflow.com/users/24985", "pm_score": 3, "selected": false, "text": "// I love the smell of dirty XML in the morning\nxml = xml.Replace(\"xmlns=\\\"urn:bsd.orion/inventory\\\"\", \"\");\n" }, { "answer_id": 431717, "author": "Brian Clapper", "author_id": 53495, "author_profile": "https://Stackoverflow.com/users/53495", "pm_score": 7, "selected": false, "text": "last = first; /* Biblical reference */\n" }, { "answer_id": 431722, "author": "Evan Fosmark", "author_id": 49701, "author_profile": "https://Stackoverflow.com/users/49701", "pm_score": 6, "selected": false, "text": "// If you're reading this, that means you have been put in charge of my previous project.\n// I am so, so sorry for you. God speed.\n" }, { "answer_id": 431726, "author": "kal", "author_id": 43756, "author_profile": "https://Stackoverflow.com/users/43756", "pm_score": 3, "selected": false, "text": "i++; //increment i\n" }, { "answer_id": 449493, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "./arch/sparc/kernel/ptrace.c\n/* Fuck me gently with a chainsaw... */\n\n./drivers/scsi/qlogicpti.h\n/* Am I fucking pedantic or what? */\n" }, { "answer_id": 482129, "author": "Jens Roland", "author_id": 57068, "author_profile": "https://Stackoverflow.com/users/57068", "pm_score": 11, "selected": false, "text": "/**\n* For the brave souls who get this far: You are the chosen ones,\n* the valiant knights of programming who toil away, without rest,\n* fixing our most awful code. To you, true saviors, kings of men,\n* I say this: never gonna give you up, never gonna let you down,\n* never gonna run around and desert you. Never gonna make you cry,\n* never gonna say goodbye. Never gonna tell a lie and hurt you.\n*/\n // \n// Dear maintainer:\n// \n// Once you are done trying to 'optimize' this routine,\n// and have realized what a terrible mistake that was,\n// please increment the following counter as a warning\n// to the next guy:\n// \n// total_hours_wasted_here = 42\n// \n" }, { "answer_id": 482177, "author": "Rob", "author_id": 18505, "author_profile": "https://Stackoverflow.com/users/18505", "pm_score": 2, "selected": false, "text": "/// <STERNLY-WORDED-WARNING>\n/// Pay attention to this or I will hunt you down.\n/// ...\n/// </STERNLY-WORDED-WARNING>\n" }, { "answer_id": 482189, "author": "GBegen", "author_id": 10223, "author_profile": "https://Stackoverflow.com/users/10223", "pm_score": 4, "selected": false, "text": "// Hey, your shoe's untied!\n // Keep looking! I think it was the other shoe!\n // How strange -- I must be seeing things. Anyhow, I'm going to go take a shower, now...\n" }, { "answer_id": 488642, "author": "Chris Kloberdanz", "author_id": 28714, "author_profile": "https://Stackoverflow.com/users/28714", "pm_score": 3, "selected": false, "text": "// Choose! Choose the form of the Destructor!\n// The choice is made! The Traveler has come!\n" }, { "answer_id": 488651, "author": "JuanDeLosMuertos", "author_id": 39339, "author_profile": "https://Stackoverflow.com/users/39339", "pm_score": 7, "selected": false, "text": "// hack for ie browser (assuming that ie is a browser)\n" }, { "answer_id": 496175, "author": "Sam Schutte", "author_id": 146, "author_profile": "https://Stackoverflow.com/users/146", "pm_score": 1, "selected": false, "text": "//Determine if the database has been \"Grizzlified\"\n" }, { "answer_id": 499983, "author": "Nosredna", "author_id": 61027, "author_profile": "https://Stackoverflow.com/users/61027", "pm_score": 2, "selected": false, "text": "//this used to be a comment\n" }, { "answer_id": 502932, "author": "Neil Aitken", "author_id": 13803, "author_profile": "https://Stackoverflow.com/users/13803", "pm_score": 3, "selected": false, "text": "$s=2; // chicken and bacon wrap for lunch\n" }, { "answer_id": 502985, "author": "Oskar Duveborn", "author_id": 49293, "author_profile": "https://Stackoverflow.com/users/49293", "pm_score": 2, "selected": false, "text": "-- Beyond this point, there'll be dragons\n" }, { "answer_id": 502993, "author": "devdimi", "author_id": 54983, "author_profile": "https://Stackoverflow.com/users/54983", "pm_score": 0, "selected": false, "text": "// long live COM'n'Roll\npublic enum StatusCode\n{\n //success codes\n S_OK = 1,\n S_NONE = 2,\n S_SQL_OPERATIONS_LISTS_EMPTY = 3,\n\n //error codes\n E_NO_MATCHING_END_FOUND = -1,\n E_SEQUENCE_NUMBER_NOT_FOUND_AT_BEGINNING = -2,\n E_SEQUENCE_NUMBER_NOT_FOUND_AT_END = -3,\n E_FORWARD_AND_BACKWARD_OPS_COUNT_DO_NOT_MATCH = -4,\n E_FORWARD_AND_BACKWARD_IDS_DO_NOT_MATCH = -5,\n E_IDS_DO_NOT_MATCH = -6\n}\n" }, { "answer_id": 503002, "author": "MatthieuP", "author_id": 41469, "author_profile": "https://Stackoverflow.com/users/41469", "pm_score": 2, "selected": false, "text": "// HACK ! COPY/PASTE this and look for another job\n" }, { "answer_id": 503012, "author": "aldrinleal", "author_id": 39261, "author_profile": "https://Stackoverflow.com/users/39261", "pm_score": 5, "selected": false, "text": "// Caveat implementor\n" }, { "answer_id": 503186, "author": "Sindri Traustason", "author_id": 1113, "author_profile": "https://Stackoverflow.com/users/1113", "pm_score": 4, "selected": false, "text": "/**\n * As Gregor Samsa awoke one morning from uneasy dreams he found himself\n * transformed in his bed into a gigantic insect. He was lying on his hard,\n * as it were armour plated, back, and if he lifted his head a little he\n * could see his big, brown belly divided into stiff, arched segments, on\n * top of which the bed quilt could hardly keep in position and was about\n * to slide off completely. His numerous legs, which were pitifully thin\n * compared to the rest of his bulk, waved helplessly before his eyes.\n * \"What has happened to me?\", he thought. It was no dream....\n */\nprotected static String DEFAULT_TRANSLET_NAME = \"GregorSamsa\";\n" }, { "answer_id": 503215, "author": "BlackWasp", "author_id": 21862, "author_profile": "https://Stackoverflow.com/users/21862", "pm_score": 2, "selected": false, "text": "'This code was written by **************.\n'I haven't a clue what it does. He hasn't a clue what it does.\n'Nobody else has a clue what it does or how it does it.\n'It is something to do with data but **** knows what.\n'The ******* still works so please do not change this code,\n'even though it is a complete pile of ****.\n" }, { "answer_id": 504832, "author": "unclerojelio", "author_id": 54757, "author_profile": "https://Stackoverflow.com/users/54757", "pm_score": 5, "selected": false, "text": "//Woulda\nif(x) {}\n//Shoulda\nelse if(y) {}\n//Coulda\nelse {}\n" }, { "answer_id": 505122, "author": "John Baughman", "author_id": 26923, "author_profile": "https://Stackoverflow.com/users/26923", "pm_score": 4, "selected": false, "text": "Squashed some IPR mod bugs. The were big and juicy ones, too.\n Squashed some more mod bugs. Those are some nasty bugs, them mod bugs...\n Squashed some more mod bugs. They are like cockroaches: they'll live through a nuclear war.\n Squashed some more John bugs. They too are like cockroaches: they appear anywhere John goes. Wait. That doesn't sound right.\n Same John bug. It didn't die, just played 'possum.\n" }, { "answer_id": 505344, "author": "Jeremy Ricketts", "author_id": 36758, "author_profile": "https://Stackoverflow.com/users/36758", "pm_score": 5, "selected": false, "text": ".class {border:1px solid gold;} /* I pitty the fool */" }, { "answer_id": 508563, "author": "Andreas", "author_id": 54710, "author_profile": "https://Stackoverflow.com/users/54710", "pm_score": 1, "selected": false, "text": "// StupidCompilerDontInline(SCDI), in the test project where\n// allcode was in a single cpp the compiler had inlined nearly\n// everything which lead to nice stackoverflow.\n// To prevent this the metods are made virtual\n#define SCDI virtual\n" }, { "answer_id": 508818, "author": "Pete H.", "author_id": 52966, "author_profile": "https://Stackoverflow.com/users/52966", "pm_score": 6, "selected": false, "text": "//MailBody builders for two outgoing messages\nStringBuilder hanz = new StringBuilder();\nStringBuilder franz = new StringBuilder();\n" }, { "answer_id": 515402, "author": "User", "author_id": 62830, "author_profile": "https://Stackoverflow.com/users/62830", "pm_score": 1, "selected": false, "text": "// Instance of excel\nExcel excel = this.CreateExcelInstance();\nexcel.Open(stream); // how to close it?!\n" }, { "answer_id": 515419, "author": "Polo", "author_id": 60561, "author_profile": "https://Stackoverflow.com/users/60561", "pm_score": 3, "selected": false, "text": "//Haleluya i can go home!\n" }, { "answer_id": 515593, "author": "xan", "author_id": 15667, "author_profile": "https://Stackoverflow.com/users/15667", "pm_score": 5, "selected": false, "text": "# This job would be great if it wasn't for the fucking customers.\n" }, { "answer_id": 515605, "author": "Lukas Šalkauskas", "author_id": 5369, "author_profile": "https://Stackoverflow.com/users/5369", "pm_score": 2, "selected": false, "text": "// I wish (boss name) could do this by him self.\n" }, { "answer_id": 519734, "author": "BoD", "author_id": 15695, "author_profile": "https://Stackoverflow.com/users/15695", "pm_score": 4, "selected": false, "text": "// HERE\n" }, { "answer_id": 522655, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": false, "text": "/* You'll never believe all this is necessary to handle relocations\n for function calls. Having to compute and pack the argument\n relocation bits is the real nightmare.\n\n If you're interested in how this works, just forget it. You really\n do not want to know about this braindamage. */\n /* Don't ask about these magic sequences. I took them straight\n from gas-1.36 which took them from the a.out man page. */\n /* Keep track of exactly where we are within a particular\n space. This is necessary as the braindamaged HPUX\n loader will create holes between subspaces *and*\n subspace alignments are *NOT* preserved. What a crock. */\n /* We will NOT put a fucking timestamp in the header here. Every\n time you put it back, I will come in and take it out again. ... */\n /* Yes this is ugly (storing the broken_word pointer\n in the symbol slot). Still, this whole chunk of\n code is ugly, and I don't feel like doing anything\n about it. Think of it as stubbornness in action. */\n" }, { "answer_id": 538091, "author": "Jane Sales", "author_id": 63994, "author_profile": "https://Stackoverflow.com/users/63994", "pm_score": 3, "selected": false, "text": "\"we_are_not_in_kansas_any_more_toto\"" }, { "answer_id": 538175, "author": "Tim Post", "author_id": 50049, "author_profile": "https://Stackoverflow.com/users/50049", "pm_score": 4, "selected": false, "text": "/*\n * Don't OOM me, bro!\n */\n /*\n * Don't swap me, bro!\n */\n" }, { "answer_id": 544238, "author": "Bennett McElwee", "author_id": 61754, "author_profile": "https://Stackoverflow.com/users/61754", "pm_score": 3, "selected": false, "text": "try {\n doSomething();\n} catch(err) {\n // Die quietly\n alert(err);\n}\n" }, { "answer_id": 549611, "author": "スーパーファミコン", "author_id": 53189, "author_profile": "https://Stackoverflow.com/users/53189", "pm_score": 10, "selected": false, "text": "Exception up = new Exception(\"Something is really wrong.\");\nthrow up; //ha ha\n" }, { "answer_id": 549644, "author": "James Jones", "author_id": 84088, "author_profile": "https://Stackoverflow.com/users/84088", "pm_score": 1, "selected": false, "text": "'this next if statement - just how it is. don't try to understand it because you won't. :)\n" }, { "answer_id": 577663, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// barcore.cpp - MFC\n\n//.....\nHBRUSH CControlBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)\n{\n LRESULT lResult;\n if (pWnd->SendChildNotifyLastMsg(&lResult))\n return (HBRUSH)lResult; // eat it\n\n//......\n\n// Eat it - just like eat this.\n" }, { "answer_id": 614031, "author": "Viachaslau Tysianchuk", "author_id": 74144, "author_profile": "https://Stackoverflow.com/users/74144", "pm_score": 2, "selected": false, "text": "// Iced odnako\nbool Iced{get;set;}\n" }, { "answer_id": 614792, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 8, "selected": false, "text": "/////////////////////////////////////// this is a well commented line\n" }, { "answer_id": 615022, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "// It may be a hack, but it works.\n" }, { "answer_id": 615028, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "* All comments pertain to the lines which follow.\n" }, { "answer_id": 615049, "author": "Ed Marty", "author_id": 36007, "author_profile": "https://Stackoverflow.com/users/36007", "pm_score": 4, "selected": false, "text": "stepOff(); //bitch\n" }, { "answer_id": 615795, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// The root of all evil ... umm classes\n" }, { "answer_id": 615845, "author": "Juliano", "author_id": 55078, "author_profile": "https://Stackoverflow.com/users/55078", "pm_score": 8, "selected": false, "text": "long long ago; /* in a galaxy far far away */ \n" }, { "answer_id": 615872, "author": "Chris Doggett", "author_id": 64203, "author_profile": "https://Stackoverflow.com/users/64203", "pm_score": 3, "selected": false, "text": " /************************************************************\n * *\n * .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. *\n * | ______ | *\n * | .-\" \"-. | *\n * | / \\ | *\n * | _ | | _ | *\n * | ( \\ |, .-. .-. ,| / ) | *\n * | > \"=._ | )(__/ \\__)( | _.=\" < | *\n * | (_/\"=._\"=._ |/ /\\ \\| _.=\"_.=\"\\_) | *\n * | \"=._\"(_ ^^ _)\"_.=\" | *\n * | \"=\\__|IIIIII|__/=\" | *\n * | _.=\"| \\IIIIII/ |\"=._ | *\n * | _ _.=\"_.=\"\\ /\"=._\"=._ _ | *\n * | ( \\_.=\"_.=\" `--------` \"=._\"=._/ ) | *\n * | > _.=\" \"=._ < | *\n * | (_/ \\_) | *\n * | | *\n * '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' *\n * *\n * LASCIATE OGNI SPERANZA, VOI CH'ENTRATE *\n *************************************************************/\n" }, { "answer_id": 615887, "author": "David", "author_id": 9908, "author_profile": "https://Stackoverflow.com/users/9908", "pm_score": 2, "selected": false, "text": "/**\n* Do not use, ever - left in place for testing purposes\n*/\nfunction I_David_WillHuntYouDownAndHurtYou_Badly_IfIFindThisUsedAnyWhereInTheAppLibrary(){\n...\n}\n" }, { "answer_id": 615901, "author": "shsteimer", "author_id": 292, "author_profile": "https://Stackoverflow.com/users/292", "pm_score": 6, "selected": false, "text": "//I wonder if she actually reads these.\n" }, { "answer_id": 615910, "author": "shampoopy", "author_id": 37812, "author_profile": "https://Stackoverflow.com/users/37812", "pm_score": 0, "selected": false, "text": "// Oh crap, i think i'm gonna yack\n // TODO: end this lunacy\n" }, { "answer_id": 615989, "author": "Rad", "author_id": 1349, "author_profile": "https://Stackoverflow.com/users/1349", "pm_score": 7, "selected": false, "text": "class Act //That's me!!!\n{\n\n}\n" }, { "answer_id": 616013, "author": "Rad", "author_id": 1349, "author_profile": "https://Stackoverflow.com/users/1349", "pm_score": 7, "selected": false, "text": "try {\n\n}\ncatch (SQLException ex) {\n // Basically, without saying too much, you're screwed. Royally and totally.\n}\ncatch(Exception ex)\n{\n //If you thought you were screwed before, boy have I news for you!!!\n}\n" }, { "answer_id": 616053, "author": "TheHolyTerrah", "author_id": 32532, "author_profile": "https://Stackoverflow.com/users/32532", "pm_score": 4, "selected": false, "text": "// Yes...I know this is repulsive and stupid.\n// But <%CompanyOwnerOrManagerToken%>, not knowing a thing about code,\n// demanded I do it anyways. SO, go crap on their desk, not mine.\n// K THX BYE \n" }, { "answer_id": 616122, "author": "Gambrinus", "author_id": 42386, "author_profile": "https://Stackoverflow.com/users/42386", "pm_score": 2, "selected": false, "text": "try\n{\n...\n}\ncatch(Exception ex)\n{\n//if this happens the world is going to end...\n}\n" }, { "answer_id": 616281, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "// If you delete the credits, I will fucking kill you.\n" }, { "answer_id": 616523, "author": "danio", "author_id": 12663, "author_profile": "https://Stackoverflow.com/users/12663", "pm_score": 3, "selected": false, "text": " // Some wanker in ISO got rid of ifstream(int), ofstream(int), and\n // fstream(int). Twit.\n" }, { "answer_id": 616551, "author": "user16208", "author_id": 16208, "author_profile": "https://Stackoverflow.com/users/16208", "pm_score": 5, "selected": false, "text": "...\n\n// get the units from the form \nint numUnits = Integer.parseInt(request.getParameter(\"num_pieces\")); // this break at random times\n\n//price \nfloat price = Float.parseFloat(request.getParameter(\"price\")); // same as above\n\n// Under certain conditions the following code blows up. I don't know those conditions.\nfloat pricePerUnit = price / (float)numUnits;\n\n...\n" }, { "answer_id": 618828, "author": "Pratik Deoghare", "author_id": 58737, "author_profile": "https://Stackoverflow.com/users/58737", "pm_score": 4, "selected": false, "text": "/**---------START-----------**/\n\n // IMPLEMENTATION GOES HERE\n\n/**---------END-----------**/\n" }, { "answer_id": 618976, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "// John! If you'll svn remove this once more,\n// I'll shut you, for God's sake!\n// That piece of code is not “something strange”!\n// That is THE AUTH VALIDATION.\n" }, { "answer_id": 621591, "author": "hasen", "author_id": 35364, "author_profile": "https://Stackoverflow.com/users/35364", "pm_score": 2, "selected": false, "text": "if( year < 100 ): year += 2000 #lol, Y2K\n" }, { "answer_id": 626983, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "$this->getSelect()->where ('main_table.product_id = -1'); // Mom, Dad... sorry\n" }, { "answer_id": 628776, "author": "Flow", "author_id": 75937, "author_profile": "https://Stackoverflow.com/users/75937", "pm_score": 3, "selected": false, "text": "// insert comment here\n" }, { "answer_id": 638670, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "} catch (PartInitException pie) {\n // Mmm... pie\n" }, { "answer_id": 645024, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": " /*\n * OK; before you read the following code know what I am trying to do.\n * I needed to get the list of child catagories from the root node so that\n * the root node didn't appear in the selection box. But for some stupid\n * fucking reason the stupid fucking DBA wont let me access the items using\n * indicies and I instead have to use their stupid fucking Iterator\n * implementation. So there.\n */\n $firstList = $this->getRootNode()->getChildren();\n foreach ($firstList as $node)\n {\n $nodes = $node->getChildren();\n break; // wtf?\n }\n" }, { "answer_id": 647713, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "if (scroll and noScroll) # or tea and no tea\n" }, { "answer_id": 648822, "author": "neoneye", "author_id": 78336, "author_profile": "https://Stackoverflow.com/users/78336", "pm_score": 3, "selected": false, "text": "// nobody read comments!\n" }, { "answer_id": 648866, "author": "Neil N", "author_id": 55164, "author_profile": "https://Stackoverflow.com/users/55164", "pm_score": 6, "selected": false, "text": "// TODO: Fix this. Fix what?\n" }, { "answer_id": 649920, "author": "Simon Lieschke", "author_id": 2766, "author_profile": "https://Stackoverflow.com/users/2766", "pm_score": 3, "selected": false, "text": "<!-- Hopfully we can do this otherwise the nav is going to be pretty plain and Hong will go postal. -->\n" }, { "answer_id": 649924, "author": "Telemachus", "author_id": 26702, "author_profile": "https://Stackoverflow.com/users/26702", "pm_score": 2, "selected": false, "text": "// The hackiest hack that ever did hack\n" }, { "answer_id": 657831, "author": "Jeeva Subburaj", "author_id": 79442, "author_profile": "https://Stackoverflow.com/users/79442", "pm_score": 2, "selected": false, "text": "//If the Current Record is Getting End Dated, We should not create New History Entry. \n//We Just need to Update the Previous History Entry\n//If the History is already End Dated and the New Record is now removing End Date, Then \n//We should not update the Previous History End Date. \n//We Just need to Create the New History Record Only.\n//Alright.. \n//Alright.... \n//Enough Comments. Code it. :-)\n" }, { "answer_id": 657879, "author": "Tony", "author_id": 68536, "author_profile": "https://Stackoverflow.com/users/68536", "pm_score": 2, "selected": false, "text": "#define SHIT_HAPPENED (BASE + 1) /* generic shit happened */\n" }, { "answer_id": 657888, "author": "Esko Luontola", "author_id": 62130, "author_profile": "https://Stackoverflow.com/users/62130", "pm_score": 1, "selected": false, "text": "uint16 CPreferences::GetMaxDownload(){\n//dont be a Lam3r :)\n uint16 maxup=(GetMaxUpload()==UNLIMITED)?GetMaxGraphUploadRate():GetMaxUpload();\n if( maxup < 4 )\n return (( (maxup < 10) && (maxup*3 < prefs->maxdownload) )? maxup*3 : prefs->maxdownload);\n return (( (maxup < 10) && (maxup*4 < prefs->maxdownload) )? maxup*4 : prefs->maxdownload);\n}\n" }, { "answer_id": 675779, "author": "Jorn", "author_id": 8681, "author_profile": "https://Stackoverflow.com/users/8681", "pm_score": 4, "selected": false, "text": "/* FIXME This must absolutely be removed before 4.0.7 release\n * TODO really remove this */\n" }, { "answer_id": 676374, "author": "Stephen Curial", "author_id": 1399919, "author_profile": "https://Stackoverflow.com/users/1399919", "pm_score": 0, "selected": false, "text": "int StupidJava = -1;\n" }, { "answer_id": 686583, "author": "Fraser", "author_id": 74861, "author_profile": "https://Stackoverflow.com/users/74861", "pm_score": 2, "selected": false, "text": "/*\n* spaghetty code in this module.\n* hardcoded variables for load paths for the content window.\n* Needs (vast) improvement.\n*/\n" }, { "answer_id": 686915, "author": "itsmatt", "author_id": 7862, "author_profile": "https://Stackoverflow.com/users/7862", "pm_score": 4, "selected": false, "text": "// A Gorgon class - For the love of Zeus don't look directly at it!\n" }, { "answer_id": 687811, "author": "Martin Lazar", "author_id": 82569, "author_profile": "https://Stackoverflow.com/users/82569", "pm_score": 6, "selected": false, "text": "// I can't divide with zero, so I have to divide with something very similar\nresult = number / 0.00000000000001;\n" }, { "answer_id": 687856, "author": "Brian Campbell", "author_id": 69755, "author_profile": "https://Stackoverflow.com/users/69755", "pm_score": 3, "selected": false, "text": "/*\n** The author disclaims copyright to this source code. In place of\n** a legal notice, here is a blessing:\n**\n** May you do good and not evil.\n** May you find forgiveness for yourself and forgive others.\n** May you share freely, never taking more than you give.\n*/\n" }, { "answer_id": 687969, "author": "i_am_jorf", "author_id": 74815, "author_profile": "https://Stackoverflow.com/users/74815", "pm_score": 3, "selected": false, "text": "// TODO: Drive an ashen stake through the foul heart of this function.\n" }, { "answer_id": 688017, "author": "user63503", "author_id": 63503, "author_profile": "https://Stackoverflow.com/users/63503", "pm_score": 4, "selected": false, "text": "// this error could never happen\n" }, { "answer_id": 688088, "author": "eglasius", "author_id": 66372, "author_profile": "https://Stackoverflow.com/users/66372", "pm_score": 2, "selected": false, "text": "//why the f*** we have to move this here to make it work\n" }, { "answer_id": 694615, "author": "Amr Elgarhy", "author_id": 20126, "author_profile": "https://Stackoverflow.com/users/20126", "pm_score": 1, "selected": false, "text": "// Sorry dirty code\n" }, { "answer_id": 694644, "author": "Mia Clarke", "author_id": 83075, "author_profile": "https://Stackoverflow.com/users/83075", "pm_score": 8, "selected": false, "text": "//Dear future me. Please forgive me. \n//I can't even begin to express how sorry I am. \n //private instance variable for storing age\npublic static int age;\n" }, { "answer_id": 694652, "author": "Zifre", "author_id": 83871, "author_profile": "https://Stackoverflow.com/users/83871", "pm_score": 6, "selected": false, "text": "/* Welcome to Sun Microsystems, can I take your order please? */\nif(!hp->happy_flags & HFLAG_FENABLE)\n return happy_meal_bb_write(hp, tregs, reg, value);\n\n/* Would you like fries with that? */\nhme_write32(hp, &tregs->frame,\n (FRAME_WRITE | (hp->paddr << 23) |\n ((reg & 0xff) << 18) | (value & 0xffff)));\nwhile(!(hme_read32(hp, &tregs->frame) & 0x10000) && --tries)\n udelay(20);\n\n/* Anything else? */\nif(!tries)\n printk(KERN_ERR \"happy meal: Aieee, transceiver MIF write bolixed\\n\");\n\n/* Fifty-two cents is your change, have a nice day. */\n" }, { "answer_id": 706648, "author": "euphoria83", "author_id": 78351, "author_profile": "https://Stackoverflow.com/users/78351", "pm_score": 2, "selected": false, "text": "// Empty constructor to satisfy the stupid compiler\n Public ServletHandlerClass () { } \n" }, { "answer_id": 713861, "author": "BobC", "author_id": 31167, "author_profile": "https://Stackoverflow.com/users/31167", "pm_score": 3, "selected": false, "text": "catch (Exception ex)\n{ \n // just die already.\n}\n" }, { "answer_id": 713871, "author": "AaronLS", "author_id": 84206, "author_profile": "https://Stackoverflow.com/users/84206", "pm_score": 1, "selected": false, "text": "I have no idea what this stuff does below here.\n" }, { "answer_id": 713872, "author": "JeffO", "author_id": 61339, "author_profile": "https://Stackoverflow.com/users/61339", "pm_score": 2, "selected": false, "text": "'On Error Goto Hell.\n" }, { "answer_id": 714566, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/*\n * Chaos reigns within.\n * Reflect, repent, and reboot.\n * Order shall return.\n */\nreturn (DB_RUNRECOVERY);\n" }, { "answer_id": 717461, "author": "martinus", "author_id": 48181, "author_profile": "https://Stackoverflow.com/users/48181", "pm_score": 4, "selected": false, "text": " /**\n * Returns cookies according to the filters specified.\n * \n * @return array Cookies! Nom nom nom nom nom.\n */\n public function data_getCookies($uid, $name) {\n" }, { "answer_id": 717501, "author": "MissT", "author_id": 81523, "author_profile": "https://Stackoverflow.com/users/81523", "pm_score": 2, "selected": false, "text": "/*\n//You can tell I was bored\n//I wanted to do this for a long time\nchar* ConvertToRoman(int number, int base)\n{\n... whole code here\n}\n*/\n" }, { "answer_id": 720857, "author": "Paul Suart", "author_id": 68432, "author_profile": "https://Stackoverflow.com/users/68432", "pm_score": 0, "selected": false, "text": "// Hack-er-ama\n" }, { "answer_id": 720865, "author": "Eskat0n", "author_id": 78316, "author_profile": "https://Stackoverflow.com/users/78316", "pm_score": 3, "selected": false, "text": "# Don use this. Never!\n" }, { "answer_id": 720902, "author": "Elroy", "author_id": 56097, "author_profile": "https://Stackoverflow.com/users/56097", "pm_score": 1, "selected": false, "text": "else\n{\n //error situation\n}\n" }, { "answer_id": 720905, "author": "fog", "author_id": 57334, "author_profile": "https://Stackoverflow.com/users/57334", "pm_score": 5, "selected": false, "text": "/* Ah ah ah! You'll never understand why this one works. */\n" }, { "answer_id": 720983, "author": "Elroy", "author_id": 56097, "author_profile": "https://Stackoverflow.com/users/56097", "pm_score": 1, "selected": false, "text": "#pragma region Crap that is kept for temporary reasons\n\n // Huge chunk of commented code\n\n#pragma endregion\n" }, { "answer_id": 721029, "author": "lfx", "author_id": 43164, "author_profile": "https://Stackoverflow.com/users/43164", "pm_score": 4, "selected": false, "text": "// If I from the future read this I'll back in time and kill myself. \n" }, { "answer_id": 721065, "author": "pomarc", "author_id": 85738, "author_profile": "https://Stackoverflow.com/users/85738", "pm_score": 2, "selected": false, "text": "//marco 2007.1.23\n//I didn't do it\n" }, { "answer_id": 721091, "author": "Benjol", "author_id": 11410, "author_profile": "https://Stackoverflow.com/users/11410", "pm_score": 3, "selected": false, "text": "//#region Code for weird cases - do you really want to know?\n ' Commented out following code, don't delete for when [CustomerName] changes his mind\n" }, { "answer_id": 721797, "author": "Colin Cassidy", "author_id": 6515, "author_profile": "https://Stackoverflow.com/users/6515", "pm_score": 3, "selected": false, "text": "for (bo_thans = 0 ; bo_thans < MAX ; bo_thans++)\n{\n if(rs == thing[bo_thans])\n {\n found = true;\n }\n}\n\nif(!found)\n{\n /* Failed to find rs with bo_thans */\n ...\n}\n" }, { "answer_id": 721922, "author": "Brian Postow", "author_id": 53491, "author_profile": "https://Stackoverflow.com/users/53491", "pm_score": 1, "selected": false, "text": "// Wilted celery?\n" }, { "answer_id": 726186, "author": "TalkingCode", "author_id": 70414, "author_profile": "https://Stackoverflow.com/users/70414", "pm_score": 2, "selected": false, "text": "// Keep prozac ready if things get ugly!\n" }, { "answer_id": 735896, "author": "ninegrid", "author_id": 13661, "author_profile": "https://Stackoverflow.com/users/13661", "pm_score": 0, "selected": false, "text": "// now swap like a <explicative removed>\n" }, { "answer_id": 735928, "author": "Lucas Jones", "author_id": 41981, "author_profile": "https://Stackoverflow.com/users/41981", "pm_score": 2, "selected": false, "text": "// haack, phil haack\n /* hack, hack, hack, hack, hack hack, hack, hack\n * hackity hack, oh wonderful hacks\n * wonderful hacks, oh wonderful hack, hack, hack\n * hack hack hack... and spam \n */\n // yikes, we need to:\n/*\n * o\n * -|- < US CROSSING PLATFORM\n * |\\ \n ************************************************\n * | ^ PLATFORM |\n * | T |\n * | TROLL^ |\n */\n// right now:\n/*\n * o ./_ | \n * -|-[]\\ | (_'_) () (\\) | ) \\|/ (S) < WALL\n * |\\ | ^ FRIENDLY MESSAGE FROM YOUR FRIENDS AT MICROSOFT\n * ***********************************************\n * | ^PLATFORM |\n * ^ SPRAY CAN (IN HAND)\n */\npublic static class DefaultFonts\n{\n public static string SansSerifPath\n {\n get { return @\"C:\\Windows\\Fonts\\arial.ttf\"; }\n }\n public static string SerifPath\n {\n get { return @\"C:\\Windows\\Fonts\\times.ttf\"; }\n }\n public static string MonospacePath\n {\n get { return @\"C:\\Windows\\Fonts\\courier.ttf\"; }\n }\n}\n" }, { "answer_id": 736035, "author": "Will Charczuk", "author_id": 73309, "author_profile": "https://Stackoverflow.com/users/73309", "pm_score": 1, "selected": false, "text": "map(TimeZoneId.Romance, \"Romance Standard Time\"); //LULZ.\n" }, { "answer_id": 736044, "author": "samoz", "author_id": 39036, "author_profile": "https://Stackoverflow.com/users/39036", "pm_score": 7, "selected": false, "text": "/*\nThis isn't the right way to deal with this, but today is my last day, Ron\njust spilled coffee on my desk, and I'm hungry, so this will have to do...\n*/\n\nreturn 12; // 12 is my lucky number\n" }, { "answer_id": 736049, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "// This interface defines method signatures<br>\ninterface IWhatever { ... }\n" }, { "answer_id": 736113, "author": "Pool", "author_id": 2352432, "author_profile": "https://Stackoverflow.com/users/2352432", "pm_score": 3, "selected": false, "text": "// i don't know how this works but it does so i'll leave it here anyway\n" }, { "answer_id": 736167, "author": "mseery", "author_id": 39153, "author_profile": "https://Stackoverflow.com/users/39153", "pm_score": 4, "selected": false, "text": "// This is a walkaround for bug #7812\n" }, { "answer_id": 740552, "author": "womp", "author_id": 63756, "author_profile": "https://Stackoverflow.com/users/63756", "pm_score": 3, "selected": false, "text": "<!-- Here it is -->\n" }, { "answer_id": 740603, "author": "Ash", "author_id": 43192, "author_profile": "https://Stackoverflow.com/users/43192", "pm_score": 10, "selected": false, "text": "// Autogenerated, do not edit. All changes will be undone.\n" }, { "answer_id": 750386, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "//If defined, will include all the Windows-specific code.\n#define LOSE\n\n#ifdef LOSE\n#include <windows.h> //WIN32. Duh.\n#endif\n\n\n---------------------------------------------------\n\n\n//Stolen from other_project_name.cpp\n\n\n---------------------------------------------------\n\n\n/*\n * These comments have been lifted from propagate() and, though they no longer apply to the code, they may still be of value somewhere. Original tabbing and structural elements have been preserved.\n */\n //CAUTION: This has a major Bobby Tables risk. Even if a rulebuilder is used, there's still the risk of something getting corrupted in the database itself.\n //Reading text from anywhere and simply slotting it into an SQL statement is a major security risk. (With thanks to xkcd for the name \"Bobby Tables\".)\n //Requirement: Eliminate one Bobby Tables by changing [redacted] to be not just straight SQL.\n[lots more comments that are not as funny]\n/*\n * End of lifted comments. There should not be any executable code between these markers.\n */\n\n\n---------------------------------------------------\n\n\n /*\n Okay. It's unrecognized. Why is this a fatal error? It's actually very closely akin to the miswart of botched #includes being a fatal. When writing a C/C++\n program, you need your headers, and if you don't have one, chances are there'll be a million cascaded errors; so by making \"unable to open asdf.h\" a fatal,\n the compiler suppresses all those errors about undefined symbols and potentially misspelled type names.\n */\n\n\n---------------------------------------------------\n\n\n //If someone tries to import 'id' as a field name, it won't work. (We already have our own id.) But I think the probability is so low that I can afford to be funny.\n if (!stricmp(ptr,\"id\")) {warn(0,\"Import\",\"\",\"'id' is a reserved word and cannot be used as a column name. (Try 'ego' or 'superego'.)\"); return;}\n\n\n---------------------------------------------------\n\n\n//Need a place to squirrel away SQL statements somewhere\nchar *uts[1024]; //Unified Temporary Storage. (Why? Because I said so.)\nint nuts=0; //What is it that squirrels keep? Ha!\nint utsid[sizeof uts/sizeof *uts];\n\n\n---------------------------------------------------\n\n\n /**************************************\\\n * NOTE: This sets tilde.action. If a *\n * tilde header does not exist in the *\n * import file (not the _content_, if *\n * the entire column isn't there), it *\n * will duplicate down through all of *\n * the rows. This is fine for ~id, as *\n * that will never be changed; and if *\n * ~Quantity is blank, that throws an *\n * error in 'Add'. With ~Action, I am *\n * not so certain. I THINK it'd be OK *\n * to dup-down most of the time... if *\n * the user only ever imports Adds or *\n * Revises, but never both at once in *\n * a single import. So for safety, to *\n * allow a blank ~Action to revise OR *\n * add, I'm breaking the check out to *\n * a new variable - the curaction. In *\n * most cases, it won't be needed, so *\n * it's a waste; but it isn't like it *\n * has to copy the entire tilde.*, so *\n * it's only a small waste. So it can *\n * waste a register... big deal. OK ! *\n \\**************************************/\n\n\n---------------------------------------------------\n\n\n //if (!response) // we're going to crash\n //if (!items) // we're going to crash\n //TODO: Don't crash\n\n\n---------------------------------------------------\n" }, { "answer_id": 750440, "author": "digijock", "author_id": 86345, "author_profile": "https://Stackoverflow.com/users/86345", "pm_score": 5, "selected": false, "text": "// (c) 2000 Applied Magic, Inc.\n// Unauthorized use punishable by torture, mutilation, and vivisection.\n" }, { "answer_id": 750454, "author": "Ciryon", "author_id": 22012, "author_profile": "https://Stackoverflow.com/users/22012", "pm_score": 5, "selected": false, "text": "/**\n * If you don't understand this code, you should be flipping burgers instead.\n */\n" }, { "answer_id": 750707, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "// Cabbage fart?\n" }, { "answer_id": 753350, "author": "Lily", "author_id": 85812, "author_profile": "https://Stackoverflow.com/users/85812", "pm_score": 3, "selected": false, "text": "public int hashCode() {\n//sucks, but what're you gonna do\n\n/*\nint hash = 7;\nfor (int i = 0; i < array.length; i++)\n hash = hash * 31 * (null == array[i] ? 0 : array[i].hashCode());\nreturn hash;\n*/\n\nreturn 0;\n}\n" }, { "answer_id": 753413, "author": "Bob Cross", "author_id": 5812, "author_profile": "https://Stackoverflow.com/users/5812", "pm_score": 1, "selected": false, "text": "/* Look not upon this file lest your eyes be burnt from your head. */\n" }, { "answer_id": 753637, "author": "munificent", "author_id": 9457, "author_profile": "https://Stackoverflow.com/users/9457", "pm_score": 6, "selected": false, "text": "// error codes\n#define ERROR_SUCESS 0\n#define ERROR_SUCCESS_IS_MISSPELLED 1\n" }, { "answer_id": 756621, "author": "madcolor", "author_id": 13954, "author_profile": "https://Stackoverflow.com/users/13954", "pm_score": 0, "selected": false, "text": "'CANNOT JUST QUIT!\n" }, { "answer_id": 764798, "author": "The Disintegrator", "author_id": 92462, "author_profile": "https://Stackoverflow.com/users/92462", "pm_score": 3, "selected": false, "text": "// This condition can't happen. Call the police or something.\n" }, { "answer_id": 765147, "author": "Chris Morley", "author_id": 80090, "author_profile": "https://Stackoverflow.com/users/80090", "pm_score": 5, "selected": false, "text": "//The following 1056 lines of code in this next method \n//is a line by line port from VB.NET to C#.\n//I ported this code but did not write the original code.\n//It remains to me a mystery as to what\n//the business logic is trying to accomplish here other than to serve as\n//some sort of a compensation shell game invented by a den of thieves.\n//Oh well, everyone wants this stuff to work the same as before.\n//I guess the devil you know is better than the devil you don't.\n" }, { "answer_id": 765149, "author": "mmmm", "author_id": 85592, "author_profile": "https://Stackoverflow.com/users/85592", "pm_score": 2, "selected": false, "text": "/* \n There is no accounting for pointers \n*/\n" }, { "answer_id": 765216, "author": "Stewart Robinson", "author_id": 47424, "author_profile": "https://Stackoverflow.com/users/47424", "pm_score": 0, "selected": false, "text": "<cftry>\n...code...\n<cfcatch>\n <!--- Gobble --->\n</cfcatch>\n<cftry>\n" }, { "answer_id": 765375, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "On error resume next 'because nothing will ever go wrong!\n" }, { "answer_id": 765387, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "var arbitraryNumber = 10;\n//I don't know why. Just move on.\n" }, { "answer_id": 765935, "author": "penger", "author_id": 92831, "author_profile": "https://Stackoverflow.com/users/92831", "pm_score": 2, "selected": false, "text": "def leppard\n# what, i cant have my own convention?\nend\n" }, { "answer_id": 765942, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "/*\n * subtle. orig_eax is used by the signal code to distinct between\n * system calls and interrupted 'random user-space'. Thus we have\n * to put a negative value into orig_eax here. (the problem is that\n * both system calls and IRQs want to have small integer numbers in\n * orig_eax, and the syscall code has won the optimization conflict ;)\n *\n * Subtle as a pigs ear. VY\n */\n" }, { "answer_id": 765965, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "double t = 0.0; /* that's generally my opinion of the diner, too. */\n" }, { "answer_id": 765967, "author": "Casbah", "author_id": 91210, "author_profile": "https://Stackoverflow.com/users/91210", "pm_score": 2, "selected": false, "text": "private static final Logger lager = new Logger();\n" }, { "answer_id": 766018, "author": "ealf", "author_id": 85699, "author_profile": "https://Stackoverflow.com/users/85699", "pm_score": 7, "selected": false, "text": "__inline BOOL\nSearchOneDirectory(\n IN LPSTR Directory,\n IN LPSTR FileToFind,\n IN LPSTR SourceFullName,\n IN LPSTR SourceFilePart,\n OUT PBOOL FoundInTree\n )\n{\n //\n // This was way too slow. Just say we didn't find the file.\n //\n *FoundInTree = FALSE;\n return(TRUE);\n}\n" }, { "answer_id": 766037, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/*\n* Wirzenius wrote this portably, Torvalds fucked it up :-)\n*/\n" }, { "answer_id": 766044, "author": "vobject", "author_id": 53911, "author_profile": "https://Stackoverflow.com/users/53911", "pm_score": 6, "selected": false, "text": "// If this code works, it was written by Paul DiLascia. If not, I don't know\n// who wrote it\n" }, { "answer_id": 766097, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "$dnstime = time() + 60 * 60 * 24 * 7 * 2; //how long are you staying for vacation on mars? twooo weeeeeks. give dees people air\n" }, { "answer_id": 766105, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "/**\n * Not even your mum thinks you're special if you call this method\n */ \nonlyYourMumThinksYoureSpecialIfYouCallThisMethod() {...}\n" }, { "answer_id": 766133, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "switch(value)\n{\n [...]\ndefault:\n ASSERT(**true**); // if this is triggered, something really bad is happening.\n}\n" }, { "answer_id": 766208, "author": "dustins", "author_id": 91731, "author_profile": "https://Stackoverflow.com/users/91731", "pm_score": 5, "selected": false, "text": "// .==. .==. \n// //`^\\\\ //^`\\\\ \n// // ^ ^\\(\\__/)/^ ^^\\\\ \n// //^ ^^ ^/6 6\\ ^^ ^ \\\\ \n// //^ ^^ ^/( .. )\\^ ^ ^ \\\\ \n// // ^^ ^/\\| v\"\"v |/\\^ ^ ^\\\\ \n// // ^^/\\/ / `~~` \\ \\/\\^ ^\\\\ \n// -----------------------------\n/// HERE BE DRAGONS\n" }, { "answer_id": 766217, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "//FIXME: fix this before the 1.0 release\n" }, { "answer_id": 766270, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "What do you think you're doing, Dave?\n" }, { "answer_id": 766324, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "def format_ticket_content(text, recursive = true)\n if text.is_a?(TicketNote)\n note = text\n text = note.content\n else\n note = nil\n end\n\n ## Safety pig has arrived!\n text = h(text)\n ## _\n ## _._ _..._ .-', _.._(`))\n ## '-. ` ' /-._.-' ',/\n ## ) \\ '.\n ## / _ _ | \\\n ## | a a / |\n ## \\ .-. ; \n ## '-('' ).-' ,' ;\n ## '-; | .'\n ## \\ \\ /\n ## | 7 .__ _.-\\ \\\n ## | | | ``/ /` /\n ## /,_| | /,_/ /\n ## /,_/ '`-'\n ## \n" }, { "answer_id": 766328, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "/* You are not expected to understand this. */\n" }, { "answer_id": 766333, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "when :orientation\n## Avoid matching gay people with straight people - they hate it, they do, they really do.\nquery_parameter = \"(users.orientation = 'Bi' OR (users.orientation = 'Straight' AND users.gender IN ('#{user.opposite_genders.join('\\',\\'')}')) OR (users.orientation = 'Gay' AND users.gender IN ('#{user.same_genders.join('\\',\\'')}')))\"\n" }, { "answer_id": 766363, "author": "Lance Kidwell", "author_id": 29683, "author_profile": "https://Stackoverflow.com/users/29683", "pm_score": 9, "selected": false, "text": "// Replaces with spaces the braces in cases where braces in places cause stasis \n $str = str_replace(array(\"\\{\",\"\\}\"),\" \",$str);\n" }, { "answer_id": 766537, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "/* Here I sit, Joe broken hearted, came to do some sh*t, but only just started. */\n" }, { "answer_id": 766552, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": " // Constructs a tuple with 2 elements (fucking idiot, use std::pair instead!)\n template <typename T0,typename T1>\n inline tuple <T0,T1> make_tuple (const T0& t0,\n const T1& t1) {\n tuple <T0,T1> t;\n t.get<0>() = t0;\n t.get<1>() = t1;\n return t;\n }\n" }, { "answer_id": 766553, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "'TODO: Matt Damon\n" }, { "answer_id": 766554, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// Thats the end of the While loop\n// Clean up last row. I really must program better than this.\n\n// Note: You can't immediately tell if the line below works.\n\n// Rounding - blech. It's assumed that all .5s are rounded up.\n\n// Sort out predictions first. Seems like the right place for a prediction, 'first'.\n\n// Let's interpret!\n" }, { "answer_id": 766602, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "If bFound Then\n 'I love it when I write kick ass code like this\nElse\n .\n .\n" }, { "answer_id": 766630, "author": "David Pope", "author_id": 92789, "author_profile": "https://Stackoverflow.com/users/92789", "pm_score": 3, "selected": false, "text": "#ifdef TRACE\n#undef TRACE /* All your trace are belong to us. */\n#endif\n#define TRACE ....\n" }, { "answer_id": 766631, "author": "Jason", "author_id": 90053, "author_profile": "https://Stackoverflow.com/users/90053", "pm_score": 3, "selected": false, "text": "// Fuck.\n // This code worked before, but my cat decided to take a trip across my keyboard...\n" }, { "answer_id": 766668, "author": "Lance Richardson", "author_id": 18310, "author_profile": "https://Stackoverflow.com/users/18310", "pm_score": 6, "selected": false, "text": "long time; /* know C */\n /* Be a real daemon: fork myself and kill my parent */\n" }, { "answer_id": 766696, "author": "joshk0", "author_id": 92631, "author_profile": "https://Stackoverflow.com/users/92631", "pm_score": 3, "selected": false, "text": "static void happy_meal_tcvr_write(struct happy_meal *hp,\n void __iomem *tregs, int reg,\n unsigned short value)\n{\n int tries = TCVR_WRITE_TRIES;\n\n ASD((\"happy_meal_tcvr_write: reg=0x%02x value=%04x\\n\", reg, value));\n\n /* Welcome to Sun Microsystems, can I take your order please? */\n if (!(hp->happy_flags & HFLAG_FENABLE)) {\n happy_meal_bb_write(hp, tregs, reg, value);\n return;\n }\n\n /* Would you like fries with that? */\n hme_write32(hp, tregs + TCVR_FRAME,\n (FRAME_WRITE | (hp->paddr << 23) |\n ((reg & 0xff) << 18) | (value & 0xffff)));\n while (!(hme_read32(hp, tregs + TCVR_FRAME) & 0x10000) && --tries)\n udelay(20);\n\n /* Anything else? */\n if (!tries)\n printk(KERN_ERR \"happy meal: Aieee, transceiver MIF write bolixed\\n\");\n\n /* Fifty-two cents is your change, have a nice day. */\n" }, { "answer_id": 766708, "author": "tlrobinson", "author_id": 113, "author_profile": "https://Stackoverflow.com/users/113", "pm_score": 3, "selected": false, "text": "// This is confusing, I KNOW, so let me explain it to you." }, { "answer_id": 766766, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "// For the sins I am about to commit, may James Gosling forgive me\n" }, { "answer_id": 766843, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/* Jeez, this is an ugly mess */\n\n...comment from the X11R6 internals source code circa 1991.\n" }, { "answer_id": 766895, "author": "sandro", "author_id": 81192, "author_profile": "https://Stackoverflow.com/users/81192", "pm_score": 2, "selected": false, "text": "private int mousycounter = 0; //Not really a counter\n" }, { "answer_id": 766920, "author": "Tony Arnold", "author_id": 63580, "author_profile": "https://Stackoverflow.com/users/63580", "pm_score": 1, "selected": false, "text": "# I would be _very_ brain farting if I said this code didn't need reviewing.\n# It will make babies cry, and hair grow on your back, so please don't use it\n" }, { "answer_id": 766930, "author": "Draxillion", "author_id": 53034, "author_profile": "https://Stackoverflow.com/users/53034", "pm_score": 1, "selected": false, "text": "- (void)smartInsertForString:(NSString *)pasteString replacingRange:(NSRange)charRangeToReplace beforeString:(NSString **)beforeString afterString:(NSString **)afterString;\n- (NSString *)smartInsertBeforeStringForString:(NSString *)pasteString replacingRange:(NSRange)charRangeToReplace;\n- (NSString *)smartInsertAfterStringForString:(NSString *)pasteString replacingRange:(NSRange)charRangeToReplace;\n\n/* Java note: The second and third methods are the primitives and are the \nmethods exposed in Java. The first method calls the other two. All \nObjective-C code calls the first method. In either Objective-C or Java any \noverriding should be done for the second and third methods, not the first \nmethod. This will all work out correctly with the exception of existing code \nthat overrides the first method. Existing subclasses that do this will not \nhave their implementations available to Java developers. Isn't Java wonderful? */\n" }, { "answer_id": 766933, "author": "Tola", "author_id": 74069, "author_profile": "https://Stackoverflow.com/users/74069", "pm_score": 2, "selected": false, "text": "//Please comment on your source code\n" }, { "answer_id": 766949, "author": "cliff.meyers", "author_id": 41754, "author_profile": "https://Stackoverflow.com/users/41754", "pm_score": 3, "selected": false, "text": "// TODO: not this\n" }, { "answer_id": 767004, "author": "MRFerocius", "author_id": 72547, "author_profile": "https://Stackoverflow.com/users/72547", "pm_score": 2, "selected": false, "text": "//Do not continue reading if you dont want to die.\n" }, { "answer_id": 767282, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/*\n FIXME: why the fuck did anyone ever think this kind of expensive iteration\n was a good idea?\n" }, { "answer_id": 767341, "author": "efdee", "author_id": 50145, "author_profile": "https://Stackoverflow.com/users/50145", "pm_score": 6, "selected": false, "text": "// if i ever see this again i'm going to start bringing guns to work\n" }, { "answer_id": 767642, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "//If only humans could leave things be.\n\n//Please do not edit this code, \n//if you do you wont go to jail, you wont go directly to jail, \n//you wont pass go, you wont collect 200 dollars\n" }, { "answer_id": 767750, "author": "DragonFax", "author_id": 92694, "author_profile": "https://Stackoverflow.com/users/92694", "pm_score": 2, "selected": false, "text": "# insert this handy debugging line wherever you have problems\n#R$* $:$>99$1\n" }, { "answer_id": 767937, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "int main(void)\n/* Program starts here */\n" }, { "answer_id": 768021, "author": "w4ymo", "author_id": 80229, "author_profile": "https://Stackoverflow.com/users/80229", "pm_score": 2, "selected": false, "text": "//Write Code Here\n" }, { "answer_id": 768023, "author": "Steve Pomeroy", "author_id": 90934, "author_profile": "https://Stackoverflow.com/users/90934", "pm_score": 4, "selected": false, "text": "// If you are reading this, please place a checkmark here [ ]\n" }, { "answer_id": 768096, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "#!/usr/bin/perl\n# perl script disguised as a bash script\n" }, { "answer_id": 768097, "author": "JJacobsson", "author_id": 93150, "author_profile": "https://Stackoverflow.com/users/93150", "pm_score": 2, "selected": false, "text": "// The freshest corpse at the back please.\nm_DeadCharacters.push_back( std::make_pair(character, 0.0f) );\n// Get rid of the rotting surplus\nwhile( m_DeadCharacters.size() > 3 )\n m_DeadCharacters.pop_front();\n" }, { "answer_id": 768172, "author": "TJ Eastmond", "author_id": 76754, "author_profile": "https://Stackoverflow.com/users/76754", "pm_score": 2, "selected": false, "text": "//ha, you thought I was lazy didnt ya?!\n" }, { "answer_id": 768386, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "// this comment included for the benefit of anyone grepping for swearwords: shit.\n" }, { "answer_id": 768393, "author": "orj", "author_id": 20480, "author_profile": "https://Stackoverflow.com/users/20480", "pm_score": 4, "selected": false, "text": "// BEGIN HACK\n...\n// END HACK: I feel dirty.\n" }, { "answer_id": 768440, "author": "Jan-Willem Hoekman", "author_id": 93117, "author_profile": "https://Stackoverflow.com/users/93117", "pm_score": 3, "selected": false, "text": "/*\n* TODO: Remove this function\n\nfunction remove($customer_id)\n {\n $this->Customer->remove($id);\n }\n\n*/\n" }, { "answer_id": 768624, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "/*\n\n ____________________\n/ \\\n| Jean-Michel Bechet |\n| 2002-2009 |\n\\___ _______________/\n |/\n (o_\n //\\\n V_/_\n\n\n*/\n" }, { "answer_id": 768714, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/*\n* After 36 hours, 2 holes in my wall and writing my code right beside the API\n* this still doesn't work.\n* function getMap():void takes in an event object @param: evt:mouseEvent\n* I will now retire for the day with a bottle of rum and 2 hours of crying\n*/\n" }, { "answer_id": 768732, "author": "Chris Walton", "author_id": 93236, "author_profile": "https://Stackoverflow.com/users/93236", "pm_score": 2, "selected": false, "text": "if(FAILED(hr))\n{\n char fuck[256];\n sprintf(fuck, \"GetBuffer() fucking fucked the fuck: %d\", hr);\n MessageBoxA(0, fuck, fuck, MB_OK | MB_ICONERROR);\n return;\n}\n\n\n// This is for Chris, since he gets all hot and horny over \"uint\" instead of \"unsigned int\"\n// ... or maybe he's just a lazy fuck. Who knows!?\nusing Ogre::uint; \n// movable texts, fucktory\nMovableObjectTextFactory* m_pMovableObjectTextFactory;\n\n\n// diarrhea... shitting CR from the string. complete run...\n // unlock shit (duh, this comment is useless)\npixelBuffer->unlock();\n\n\n// :HACK: remove me after demo is shipped\nOf course, it's still in there ;)\n\n\n// it's 4am and I can't think of a decent error message.\n// my lead just fell asleep at his desk, so I can't ask him.\n// [name] went home because he didn't want to get divorced.\n// and so it's little ol' me, sitting here, comin up with an\n// error message for something that should never ever happen.\nASSERT0(in_len == max_in, \"http://www.youtube.com/watch?v=oHg5SJYRHA0\"); \n\n\n// you want hungarian, you GET hungarian!\nfor(int fcknglpidxcntvrI = 0; fcknglpidxcntvrI &lt; len; fcknglpidxcntvrI++)\n\n\nbool bKillSomethingAlive = false; // beating the dead horse instead\n // HACKOMATIC \n// HMM... HACKXOR?\n// HACK'O'ROONY\n// AR; yeah I know it's HACKsoup\n// HACK SHOT! DOMINATING!\n// HACK'KIDO\n// HACKku. sepukku. harakiri. kamikaze. ninja.\n// HACK'o'NEIL\n// HACKsaw\n" }, { "answer_id": 769046, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "#define FUCK_VS6_CANT_COMPILE_TEMPLATES_WITHOUT_HANDHOLDING ((float*)0)\n\n... \n\nSetPinsFromChannels`<float`>(&pinbuf, streambuf, &inmapper, FUCK_VS6_CANT_COMPILE_TEMPLATES_WITHOUT_HANDHOLDING);\n" }, { "answer_id": 769077, "author": "Martin", "author_id": 15840, "author_profile": "https://Stackoverflow.com/users/15840", "pm_score": 5, "selected": false, "text": "/* The License:\nYou (from this point on referred to as The You) are hereby \ngranted by me (from this point on referred to as The Me) \nlicense to knock yourself silly with this template. \nBy using this template The You implicitly accepts this \nlicense and pledges solemnly to never claim creative \nownership of any graphics, code, concepts, eggs, bacon, ideas, \ncolors, shapes, hypertext-transfer protocols or other conduits \nof the visual splendor thatis this template. \n\nThe Me, in turn, pledges equally solemnly to be far too \nlazy to ever check up on you, so if you do manage to pull \nsome chicks The Me won't have a cow. \nHowever The Me would be sorely disappointed if The You \nwere to try and sell or distribute this work without \nacknowledging The Me. Seriously. The Me will come down on \nThe You like a large quantitiy of hard and heavy objects \nthat in large quantities may be harmful and possibly even \nlethal to The You; So don't even think about it, The Buster.\n*/\n" }, { "answer_id": 769083, "author": "Kuroki Kaze", "author_id": 79078, "author_profile": "https://Stackoverflow.com/users/79078", "pm_score": 4, "selected": false, "text": "// This will save us ~0.5 sec for every user and please the machine spirits." }, { "answer_id": 769201, "author": "George Mauer", "author_id": 5056, "author_profile": "https://Stackoverflow.com/users/5056", "pm_score": 3, "selected": false, "text": "// This part is more difficult\n" }, { "answer_id": 769278, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "\n// The magnitude of this hack compares favorably with that of the national debt.\n" }, { "answer_id": 769428, "author": "Glyph", "author_id": 13564, "author_profile": "https://Stackoverflow.com/users/13564", "pm_score": 3, "selected": false, "text": " Subclassing made Zope and TR\n much harder to work with by far.\n So before you inherit,\n be sure to declare it\n Adapter, not PyObject*\n twisted.reality twisted.reality" }, { "answer_id": 769443, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 9, "selected": false, "text": "// At this point, I'd like to take a moment to speak to you about the Adobe PSD\n// format. PSD is not a good format. PSD is not even a bad format. Calling it\n// such would be an insult to other bad formats, such as PCX or JPEG. No, PSD\n// is an abysmal format. Having worked on this code for several weeks now, my\n// hate for PSD has grown to a raging fire that burns with the fierce passion\n// of a million suns.\n//\n// If there are two different ways of doing something, PSD will do both, in\n// different places. It will then make up three more ways no sane human would\n// think of, and do those too. PSD makes inconsistency an art form. Why, for\n// instance, did it suddenly decide that *these* particular chunks should be\n// aligned to four bytes, and that this alignement should *not* be included in\n// the size? Other chunks in other places are either unaligned, or aligned with\n// the alignment included in the size. Here, though, it is not included. Either\n// one of these three behaviours would be fine. A sane format would pick one.\n// PSD, of course, uses all three, and more.\n//\n// Trying to get data out of a PSD file is like trying to find something in the\n// attic of your eccentric old uncle who died in a freak freshwater shark\n// attack on his 58th birthday. That last detail may not be important for the\n// purposes of the simile, but at this point I am spending a lot of time\n// imagining amusing fates for the people responsible for this Rube Goldberg of\n// a file format.\n//\n// Earlier, I tried to get a hold of the latest specs for the PSD file format.\n// To do this, I had to apply to them for permission to apply to them to have\n// them consider sending me this sacred tome. This would have involved faxing\n// them a copy of some document or other, probably signed in blood. I can only\n// imagine that they make this process so difficult because they are intensely\n// ashamed of having created this abomination. I was naturally not gullible\n// enough to go through with this procedure, but if I had done so, I would have\n// printed out every single page of the spec, and set them all on fire. Were it\n// within my power, I would gather every single copy of those specs, and launch\n// them on a spaceship directly into the sun.\n//\n// PSD is not my favourite file format.\n" }, { "answer_id": 769447, "author": "Nordes", "author_id": 80527, "author_profile": "https://Stackoverflow.com/users/80527", "pm_score": 3, "selected": false, "text": "// Notice: I feel so dirty doing this, but it's the only way to make it cross browser.\n Every line of code you write that you feel gross about will ultimately come back to haunt you. Therefore, avoid writing code that makes you feel dirty.\n" }, { "answer_id": 769590, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "/**\n * This run through all the guipublisherbuyRecord , the records those have\n * diff. is buytotal and prior to buy isRecommendedBillingClickedWarning flag\n * is set if priously RB ran and this time not.\n * \n * --What?\n * \n * @return\n * @throws AppException\n */\n" }, { "answer_id": 769805, "author": "Daniel Dickison", "author_id": 69749, "author_profile": "https://Stackoverflow.com/users/69749", "pm_score": 0, "selected": false, "text": " (let ((varianta (format nil \"~aa\" problem))\n (variantb (format nil \"~ab\" problem))\n (variantc (format nil \"~ac\" problem)))\n ;;if the A and B variants exist, create a group file\n ;;(why not just check for a? I don't know, this just feels right)\n (when (and (probe-file varianta)\n (probe-file variantb))\n ...)))\n" }, { "answer_id": 769869, "author": "Alexander Temerev", "author_id": 74275, "author_profile": "https://Stackoverflow.com/users/74275", "pm_score": 6, "selected": false, "text": "// I put on my robe and wizard hat..." }, { "answer_id": 769893, "author": "ben", "author_id": 4607, "author_profile": "https://Stackoverflow.com/users/4607", "pm_score": 1, "selected": false, "text": "/* Yow! DEMONS are flying through my NOSE! */\n" }, { "answer_id": 769949, "author": "Macke", "author_id": 72312, "author_profile": "https://Stackoverflow.com/users/72312", "pm_score": 8, "selected": false, "text": "double penetration; // ouch\n" }, { "answer_id": 770022, "author": "proudgeekdad", "author_id": 702, "author_profile": "https://Stackoverflow.com/users/702", "pm_score": 7, "selected": false, "text": "/* IF DOLPHINS ARE SO SMART, HOW COME THEY LIVE IN IGLOOS? */\n" }, { "answer_id": 770351, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": " // no comment " }, { "answer_id": 770788, "author": "HeretoLearn", "author_id": 1984928, "author_profile": "https://Stackoverflow.com/users/1984928", "pm_score": 0, "selected": false, "text": " integer *4 one,two,three;\n\nc asssign one to 100 before entering the loop\n one=100;\n" }, { "answer_id": 770924, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "// This should fix something that should never happen\n" }, { "answer_id": 771666, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "// repopulate, slight hax (or strong assumptions :P) below\n" }, { "answer_id": 771803, "author": "Craig McGuff", "author_id": 92759, "author_profile": "https://Stackoverflow.com/users/92759", "pm_score": 5, "selected": false, "text": "/* NOT FIT FOR HUMAN CONSUMPTION */\n" }, { "answer_id": 771804, "author": "Sindri Traustason", "author_id": 1113, "author_profile": "https://Stackoverflow.com/users/1113", "pm_score": 3, "selected": false, "text": "/**\n * As Gregor Samsa awoke one morning from uneasy dreams he found himself\n * transformed in his bed into a gigantic insect. He was lying on his hard,\n * as it were armour plated, back, and if he lifted his head a little he\n * could see his big, brown belly divided into stiff, arched segments, on\n * top of which the bed quilt could hardly keep in position and was about\n * to slide off completely. His numerous legs, which were pitifully thin\n * compared to the rest of his bulk, waved helplessly before his eyes.\n * \"What has happened to me?\", he thought. It was no dream....\n */\nprotected static String DEFAULT_TRANSLET_NAME = \"GregorSamsa\";\n" }, { "answer_id": 771828, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "catch\n{ \n // you’re fucked\n // write out the file somewhere and start screaming “Connection down! Connection down!”\n}\n" }, { "answer_id": 771851, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "//this is a crap way to do this but I ran out of patience\n\nDelButton.click(); \n" }, { "answer_id": 771927, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "DataRow[] foundrows = FilterCalendarEntriesBecauseDotNETIsFuckedUp(tbtemp,CalDate);\n" }, { "answer_id": 771974, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 9, "selected": false, "text": "\n #define TRUE FALSE\n //Happy debugging suckers\n" }, { "answer_id": 772078, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "XRA A ;MT\n LDA 0\n XRA A\n" }, { "answer_id": 772132, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "public function get state( /* of Palestine back */ ):Boolean\n" }, { "answer_id": 772430, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "/**\n * Hexadecimal digit\n */\nprotected $version = -1;\n" }, { "answer_id": 772445, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "else\n{\n // rien, c'est parfait.\n}\n" }, { "answer_id": 776351, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// This is a kind of magic...\n" }, { "answer_id": 776364, "author": "Juergen Gutsch", "author_id": 94229, "author_profile": "https://Stackoverflow.com/users/94229", "pm_score": 2, "selected": false, "text": "// fix it!\n" }, { "answer_id": 776445, "author": "Juergen Gutsch", "author_id": 94229, "author_profile": "https://Stackoverflow.com/users/94229", "pm_score": 2, "selected": false, "text": "// TODO: Delete\n" }, { "answer_id": 776486, "author": "slf", "author_id": 13263, "author_profile": "https://Stackoverflow.com/users/13263", "pm_score": 3, "selected": false, "text": "// *** drunk -- fix later ***\n" }, { "answer_id": 776518, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// This shouldn't happen, if it does, then the bits that automagically \n// worked when I wrote it have stopped working\n" }, { "answer_id": 776595, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// for 8 or 12 threads this does not affect much.\n// Strange are the situations if not understood properly.\n// Yoda strikes again\n" }, { "answer_id": 776698, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// simply copied from another code\n" }, { "answer_id": 776715, "author": "ohnoes", "author_id": 53330, "author_profile": "https://Stackoverflow.com/users/53330", "pm_score": 4, "selected": false, "text": "raise InvalidChild() # e.g. no legs\n" }, { "answer_id": 776808, "author": "Martin Marconcini", "author_id": 2684, "author_profile": "https://Stackoverflow.com/users/2684", "pm_score": 3, "selected": false, "text": "// Since today's CPUs are really fast, this is dedicated to those who said:\n// \" You can't use Moore's Law as an excuse to write bad software. \"\n" }, { "answer_id": 776957, "author": "Ivo", "author_id": 76031, "author_profile": "https://Stackoverflow.com/users/76031", "pm_score": 2, "selected": false, "text": "'Major changes: Everthing! - Removed all Cornoud's code !\n" }, { "answer_id": 776959, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "public GetRandomNumber()\n{\n // Chosen by a fairly rolen dice\n return 12;\n}\n" }, { "answer_id": 777244, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "// Holy moses! I've never seen anything so ridiculous in all my life. \n\n// Why do we need to query the AlarmIDs table twice.\n\n// Please tell me sir; I would really like to know. \n\n// This like all the other services have been mangled\n\n// to the point where they are nearly impossible to determine what kind of side affects might occur.\n\n// I am making the smallest changes I can to this code. \n\n// The GetAlarmId method gets the alarm id from the AlarmIDs table.\n\n// Novel idea, why didn't we query for the values be get below all in the same place.\n\n// This should be changed, but right now it will have to remain as is due to time constraints.\n\n// This like all other services really don't do anything fantastically hard, but after the original coders got\n\n// done with them; they are difficult to work with and have an acceptable comfort level.\n" }, { "answer_id": 777655, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// if the resultMap size is less than or equal to zero\n// then the product is added\nif (resultMap.size() <= 0)\n" }, { "answer_id": 777805, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "v.bpc := v.pc; -- Remember to jump back\nv.baccu := accu; -- Yo dawg, heard you like runing instructions\n -- so I took backup of your accu so you can run\n -- instructions while you run instructions.\nv.flags.i := false; -- No more interupts\n" }, { "answer_id": 778161, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "#!/usr/bin/sh\n# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T\n# All Rights Reserved\n\n# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T\n# The copyright notice above does not evidence any\n# actual or intended publication of such source code.\n\n#ident \"@(#)false.sh 1.6 93/01/11 SMI\" /* SVr4.0 1.3 */\nexit 255\n" }, { "answer_id": 778254, "author": "Peter Turner", "author_id": 1765, "author_profile": "https://Stackoverflow.com/users/1765", "pm_score": 2, "selected": false, "text": "var something TBoolean; //Pickins\n" }, { "answer_id": 778275, "author": "Rohit", "author_id": 16071, "author_profile": "https://Stackoverflow.com/users/16071", "pm_score": 10, "selected": false, "text": "// somedev1 - 6/7/02 Adding temporary tracking of Login screen\n// somedev2 - 5/22/07 Temporary my ass\n" }, { "answer_id": 778286, "author": "bosky101", "author_id": 94486, "author_profile": "https://Stackoverflow.com/users/94486", "pm_score": 2, "selected": false, "text": "%%return_median\nhit_the_sweet_spot(Arg)->\n.\n.\n" }, { "answer_id": 778615, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "/*General note to all who tread in the <ObjectName>() code...\n * The SetOriginals() method from the BaseEntity class should be called (and only called) right after the Get() method\n * call as seen above. Calling the SetOriginals method elsewhere will result in bugs and all kinds of other nasty suprises.\n */\n //Attempt to explain this confusing mess of code:\n//First time you save an actual absence this is what happens:\n//0. The first save saves to the <TableName> table (among other things). (Fig. A)\n//1. The <CalculationMethod> method is called next which inserts to the <OtherTableName> table. \n//(This is the table that keeps track of credits to the case.) (Fig. B)\n//2. So then you have to call <UpdateCalculations> to move the <TableName> records to the <ThirdTableName> table. (Fig. C)\n//3. Then you go back and run calculations since you have the debits table (<ThirdTableName>) populated. (Fig D.)\n//4. Then a final save to save the calculations back to the case. (Fig. E)\n//Yeah, I know what you're thinking: this sucks. 10/01/07 XXX\n" }, { "answer_id": 778722, "author": "Samutz", "author_id": 94561, "author_profile": "https://Stackoverflow.com/users/94561", "pm_score": 6, "selected": false, "text": "/*\nafter hours of consulting the tome of google\ni have discovered that by the will of unknown forces\nwithout the below line, IE7 believes that 6px = 12px\n*/\nfont-size: 0px;\n" }, { "answer_id": 778975, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "//Dave chapelle reports errors.\nfunction reporterror() {\n davechapelle.trace(\"FUCK!\");\n}\n" }, { "answer_id": 779128, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// All this code is yours, except gedit()...attempt no modifications there.\n" }, { "answer_id": 779317, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": " cardDeck.push_back(*(new card((rank)r, (suit)s))); // Push each card onto the deck\n // Temp. objects are overrated\n" }, { "answer_id": 779681, "author": "STW", "author_id": 60724, "author_profile": "https://Stackoverflow.com/users/60724", "pm_score": 5, "selected": false, "text": "' ROFL:ROFL:LOL:ROFL:ROFL\n' ______/|\\____\n' L / [] \\\n' LOL===_ ROFL \\_\n' L \\_______________]\n' I I\n' /---------------/\n\n'TODO: REMOVE MY INFO AND REPLACE WITH USER CREDENTIALS\n'Private TEST_LoginName As String = \"DurgshA@Exmaple.org\"\n'Private TEST_Password As String = \"Humsal892\"\n'Private TEST_Server As String = \"imap.secureserver.net\"\n" }, { "answer_id": 779818, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "# There is a bug in the next line. $searchParameters != {} will always return true, because {} is creating\n# a new hash reference on the fly, and the inequality operater is comparing the memory location of it\n# to the memory location of $searchParameters, and they will always be different. \n# This means that the following code will always get executed as long as $nodes is defined.\n# I'm leaving it there because it has always been there, and although I'm sure it was originally meant to\n# mean %$searchParameters (essentially \"is this hash not empty\"), I'm afraid to change it.\nif ( $nodes && $searchParameters != {} )\n{\n" }, { "answer_id": 779856, "author": "SPWorley", "author_id": 74222, "author_profile": "https://Stackoverflow.com/users/74222", "pm_score": 4, "selected": false, "text": " // At this point, I'd like to take a moment to speak to you about the Adobe PSD format.\n // PSD is not a good format. PSD is not even a bad format. Calling it such would be an\n // insult to other bad formats, such as PCX or JPEG. No, PSD is an abysmal format. Having\n // worked on this code for several weeks now, my hate for PSD has grown to a raging fire\n // that burns with the fierce passion of a million suns.\n // If there are two different ways of doing something, PSD will do both, in different\n // places. It will then make up three more ways no sane human would think of, and do those\n // too. PSD makes inconsistency an art form. Why, for instance, did it suddenly decide\n // that *these* particular chunks should be aligned to four bytes, and that this alignement\n // should *not* be included in the size? Other chunks in other places are either unaligned,\n // or aligned with the alignment included in the size. Here, though, it is not included.\n // Either one of these three behaviours would be fine. A sane format would pick one. PSD,\n // of course, uses all three, and more.\n // Trying to get data out of a PSD file is like trying to find something in the attic of\n // your eccentric old uncle who died in a freak freshwater shark attack on his 58th\n // birthday. That last detail may not be important for the purposes of the simile, but\n // at this point I am spending a lot of time imagining amusing fates for the people\n // responsible for this Rube Goldberg of a file format.\n // Earlier, I tried to get a hold of the latest specs for the PSD file format. To do this,\n // I had to apply to them for permission to apply to them to have them consider sending\n // me this sacred tome. This would have involved faxing them a copy of some document or\n // other, probably signed in blood. I can only imagine that they make this process so\n // difficult because they are intensely ashamed of having created this abomination. I\n // was naturally not gullible enough to go through with this procedure, but if I had done\n // so, I would have printed out every single page of the spec, and set them all on fire.\n // Were it within my power, I would gather every single copy of those specs, and launch\n // them on a spaceship directly into the sun.\n //\n // PSD is not my favourite file format.\n" }, { "answer_id": 779874, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/* I don't know how you can ever get here so I'll have to fix it later */\n" }, { "answer_id": 779899, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "# as you can see: I comment the code!" }, { "answer_id": 779948, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "// The world is a happy place.\n" }, { "answer_id": 779987, "author": "Paul", "author_id": 68968, "author_profile": "https://Stackoverflow.com/users/68968", "pm_score": 5, "selected": false, "text": "long time; /* just seems that way */\n" }, { "answer_id": 779993, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": " rescue\n # silently, we fail\n # many validations fade\n # like tear drops in rain\n end\n" }, { "answer_id": 779999, "author": "justin.m.chase", "author_id": 12958, "author_profile": "https://Stackoverflow.com/users/12958", "pm_score": 3, "selected": false, "text": "\"\"\".........................:~+?7$$$ZZZZZZZ$$$7I+=:,............................\n........................~+7ZZZZZOZZOOZOZZOZOZOOZZZZZ7?~:........................\n......................,~7$ZZOOOOOZOZOZOZZOOZZOZOOOOOZ$$I,.......................\n...................,=I$OOZOZOZZOOOZZOZOOOOZOZZZOOZZZOZZOZI=:....................\n.................:?$ZZOOZZOZOZZOOOZZZOOZOZOZZZZZZZOZZOZOOOZ$I~..................\n................IZOOOZOOOZZZOZZZZOZZOZOOOOZOZZZOOZZZZOOZOZZZOZ7=................\n...............~ZZOZZOZOOZOOZOZOZZOZOZOZZZZZOZOZZOZOOZOZZOOOOZZ7................\n.............:IZOOZOZZZZOZOZZOZOOZOZOZOZZOZOOZOOOOZOZZZZZOZOZZOOI~..............\n...........,+$ZOOZZOZOZOZOZOZZOZOZOOZZOZZOZZOZOOOOZOZZOZZOOZOOOOO$?:............\n..........:IZZOOOZOZZZZOOZOOZOZOZZOZOZZZZOZOOZOZZOZOZOZOOOOOOOZZZOZ7~...........\n..........+$OOZZZOZZOOZOOZZZZOZZOZOZZOZOOOZOZOZZOZOZOZOOOOOZ$$77I77$+:..........\n........,?$OOZZZZZZZOZOOOZOZZOZZZOOZOZOOOOZOZZZOOZOOZOOO7?~:,.......,...........\n........+ZOOZZZZZOZOOZOOZZZZOZZOOOZZZOZOZOOZZOZOZZZOOO$?........................\n........$ZOZZZOZZZZOZOOZZZOZOZZOOOOOOOOOOOZOZOZZOZOO$?,.........................\n.......:ZOOZOZOZZOOZZOZOZOZOOOZOOOOOOOOOOOOOOOZOZOOZI:..........................\n.......+OOOZOOZOZOZOZZZOOZOOZOOO$I+=~:::~+I$OOOOOOZ?:........,:=,...............\n......:7ZOOZOZZOOOZOZOZOOZOOZ$I=............:?$OOZ7:.......:IZOOZ?,.............\n......=$OZOZOOZOOOOOZOZZOOZ7=,................:?O$+.......~7OOOOOZ+,............\n.....,?$OOOOOZZZZOOOOOOZOZ?,....................ZZ=.......=$OOZOOZ+,............\n.....:IZOZZ$777I7$ZOOOOOZ7~.....................$Z=.......~7OOOOO7=.............\n.....:+?~:,.......,~IZOO7~........~+II?=........?$?,.......:I$ZZ?:..............\n.....................+ZO=,......:IOOOOOZ:.......=7$~............................\n.....................:IO~.......=OOZOZOO=,......~7O7~...........................\n...........:~:.......:IO~.......+OOOOZOO=.......~78Z?,.................,:.......\n..........:IZ7~......+ZO~.......:7OOOOO$,.......+$OOZ7=,.............:?$=.......\n...........,,.....,=7ZOO+,.......,=II?=:........7OOOOOOZ=:,.....,:=I$ZOO=.......\n....................,:+$7=.....................~OOOZZZOOOZZ$$7$$ZOOOOOOZ=.......\n......................:?Z?,...................:?OZOOZOOZOOOOOOOOOOZOZOZO=.......\n............,::,.......,OO7:................,+$OOZOZOOZOZZOZOZZOOZOZOZOO=.......\n...........~$8OI........$OOZI~,.........,:=IZOOZOZOZOZOOOZOZOZOOOZZZOZOO=.......\n...........:??=:.......:OOOOOZZ7+=~~==+?$ZOOOOZOOOZOZOZOOZOZOZZOZZOZOZZO=.......\n............::,.......,+OOZOOOOO$7777$$ZOOOOOZOZZZZOZOZZZOOZOZZOOOZOOZOO=.......\n.....................=7OOZOOZOOZOOOOOOOOOZZZOZOZZOZOZOZOOOZOZOZZOZOOZOOO=.......\n................,:=I$OOOZZOOOZOOOOOZOZOZZZZZOOZZZOZOZZZOOZOOZOZOZOZOZOOZ=.......\n...........:~+?7ZOOOOOOZZZOZOOZOZOOZOZOZZOZZOZOZZZZOZOZZOZOZOZZOZOOZOOOZ=.......\n........$$ZOOOOOOOOZOZOZZZZOZOZOOOZZZOZZZOZOOZOZZZZZZZZOOOZOOZZZOZOOZOOZ=.......\n.......~OOZOOZZOOZZZZZZOOZOZOZOZZOOZOOZZZOZZOZOZZOZZZOZOOOOOZOZOZOOZOOOZ=.......\n.......~OOZOOZZOZZOZOZZOZZOZOOZOZOOZOZOZZOZOOZOZZOZOZOZOZOOZOZOOOZOOZOZO=.......\n.......~OOZZZOZOOOZOZOZZOZOZOZOZOOZOOZOOOOZOZOOZOOOZOOOZOZZOZOZOOZZOOOOZ=.......\n.......~OOZZOZOZZZOOZOOZOZOZOZZOZZZZOZZZZOZOZZOOOOZ$ZZZZZZOZZZOZZOZOZZZO=.......\n.......~OOZZOO$??$OOZOOZZOOZOZOZ+~IZOOOZOZOOZZOOZI==IZOZZOZOOZOZZOZI~=7O=.......\n.......~OOZO$I:..~IZZZOZOZOZOZ$+...=7ZOOZOOZZOZZ=,..,=$ZZOZZZZZOZI~...,?=.......\n.......~OOOZI:....:IZOOOZZOOO$+:....~7ZOZOZOZOZ$,....,=$OOZOOOZOI~.....:~.......\n.......~OZI~........~IZZZOZ$?:........=IOOZZZ$+,.......,$ZOOOZZ7................\n.......=7~............~IOZI:............7ZO$+:..........,=7ZZ7=,................\n.......,,...............=~...............~=:..............,~=...................\n GlassGiant.com\"\"\" \nprint \"Hello World!\"\n" }, { "answer_id": 780060, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "//Maybe you should make anyone knows your code's purpose. \n" }, { "answer_id": 780103, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "// Author: If this code works, it was written by Paul DiLascia. If not then I don't know who wrote it." }, { "answer_id": 780234, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "/**\n * Happy Javadoc haiku:\n *\n * Without Javadoc\n * Builds break in Maven site stage\n * This fixes the build.\n */\n" }, { "answer_id": 780267, "author": "Brad Tutterow", "author_id": 308, "author_profile": "https://Stackoverflow.com/users/308", "pm_score": 4, "selected": false, "text": "TextBox2.Visible = True';\nFor Each row In data.Tables(0).Rows\n If row(\"Customers.Id\").ToString <> customerId Then\n customerId = row(\"Customers.ID\").ToString';\n name = \"Customer Name: \" & row(\"Name\").ToString & CrLf';\n address = \"Address: \" & row(\"Address\").ToString & CrLf & CrLf';\n TextBox2.Text += name & address ';s\n End If';\nNext';\n" }, { "answer_id": 780286, "author": "Niran", "author_id": 169495, "author_profile": "https://Stackoverflow.com/users/169495", "pm_score": 4, "selected": false, "text": "//todo: never to be implemented\n" }, { "answer_id": 780312, "author": "David", "author_id": 89682, "author_profile": "https://Stackoverflow.com/users/89682", "pm_score": 2, "selected": false, "text": "@charset \"UTF-8\";\n/* Who knew comments here could COMPLETELY ruin our page in Safari? */\nbody {\n /* Really important stuff here */\n /* Of course, comment or not, this will all get ignored by Safari because \n its the first rule after the comments which break everything.\n see http://www.w3.org/International/questions/qa-css-charset for the exact details!\n */\n}\n" }, { "answer_id": 780361, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 9, "selected": false, "text": " #Christmas tree initializer \n toConnect = [] \n toRead = [ ] \n toWrite = [ ] \n primes = [ ] \n responses = {} \n remaining = {} \n" }, { "answer_id": 780566, "author": "Mark Heath", "author_id": 7532, "author_profile": "https://Stackoverflow.com/users/7532", "pm_score": 4, "selected": false, "text": "// some sport psychology\nif (!focused)\n Focus();\n" }, { "answer_id": 780804, "author": "Iain", "author_id": 5993, "author_profile": "https://Stackoverflow.com/users/5993", "pm_score": 5, "selected": false, "text": "/** Logger */\nprivate Logger logger = Logger.getLogger();\n" }, { "answer_id": 781187, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "// now that's compact!\nlist->insert(list->end(),**pitch)->IdxOfSample=(pitch->pos-Offset)*SamplingRate;\n" }, { "answer_id": 781356, "author": "rawpower", "author_id": 25735, "author_profile": "https://Stackoverflow.com/users/25735", "pm_score": 5, "selected": false, "text": "// Joe is sorry\n // Harry is sorry too\n" }, { "answer_id": 781433, "author": "Florjon", "author_id": 86653, "author_profile": "https://Stackoverflow.com/users/86653", "pm_score": 1, "selected": false, "text": "[vrk:Cloud ID=\"cTags\" runat=\"server\" DataTextField=\"Tag\" DataWeightField=\"Total\"\n Width=\"100%\" DataHrefField=\"Tag\" DataHrefFormatString=\"~/tags.aspx?tag={0}\"]\n[/vrk:Cloud]\n\n[!--if anybody would like to change the control's color contact with FLORJON--]\n" }, { "answer_id": 781860, "author": "Jason Orendorff", "author_id": 94977, "author_profile": "https://Stackoverflow.com/users/94977", "pm_score": 2, "selected": false, "text": "/* This is gonna seem *real weird*, but if you put some other code between\n PyEval_EvalFrame() and PyEval_EvalCodeEx() you will need to adjust\n the test in the if statements in Misc/gdbinit (pystack and pystackv). */\n" }, { "answer_id": 782168, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "'Mind boggling, gibberish version of a SQL statement, but it work's, so dont touch it\n" }, { "answer_id": 782202, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "//BELOW IS THE REAL CODE...JABRONI\n //\n // Yeah, but can you play the outtro to Bark At The Moon?\n //\n\n //|--------------------------------------------------|------------------------------------------------|\n //|--------------------------------------------------|------------------------------------------------|\n //|--17^16-16-16-17^16-17^16-16-16-17^16-17^16----16-|-19^16----16-19^16-19^16---16-19^16-19^16----17-|\n //|--------------------------------------------19----|-------17----------------17---------------17----|\n //|--------------------------------------------------|----------------------------------------------\n" }, { "answer_id": 782502, "author": "skamradt", "author_id": 9217, "author_profile": "https://Stackoverflow.com/users/9217", "pm_score": 5, "selected": false, "text": "//**************************************\n// Dear code maintainer:\n//\n// This source contains COM interfaces, not to be confused with interfaces \n// of any other sort, please do not just willy-nilly add additional methods \n// to these interfaces as they are truely immutable, unlike the interfaces \n// that other software vendors like Microsoft maintain. IF you need to add \n// new functionality, then go thru the trouble of creating a NEW interface \n// and implement this functionality on only the objects you need. \n//\n// While the money is good for fixing all of the problems caused by not \n// following the rules, I would rather work on things which actually have\n// an impact on the future of the product rather than curse and yell \n// obsenities at the screen because someone didn't bother to understand the\n// true meaning of IMMUTABLE. \n//**************************************\n" }, { "answer_id": 782521, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "/* This is a replica of a horrible hack - many moons ago, the legacy PortfolioServer was modified to return cash trades in an \"optionTrade\" block, because the client side developer was too lazy to get their XPaths right. Their laziness echoes through the ages, and means we need a similar hack here...*/" }, { "answer_id": 782524, "author": "DJ.", "author_id": 83214, "author_profile": "https://Stackoverflow.com/users/83214", "pm_score": 6, "selected": false, "text": "//uncomment the following line if the program manager changes her mind again this week\n" }, { "answer_id": 782529, "author": "Steel Plume", "author_id": 85178, "author_profile": "https://Stackoverflow.com/users/85178", "pm_score": 2, "selected": false, "text": "public static final void attachListener(Object listener) {\n\n/* ======================= */\n\n// This does nothing, continue searching\n\n/* ======================= */\n\n...\n" }, { "answer_id": 782806, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "I don't understand how the following bit works, but it worked in the program I stole it from.\n" }, { "answer_id": 783220, "author": "savannah", "author_id": 94317, "author_profile": "https://Stackoverflow.com/users/94317", "pm_score": 3, "selected": false, "text": "//Time log says you've been here for 15 hours GO HOME, your code is hobo\n" }, { "answer_id": 783289, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "/* Only break the connection if it actually exists. It is important to\n * check the timeslot saved in the SOURCE of the disconnect message. */\n" }, { "answer_id": 783368, "author": "Jim Evans", "author_id": 87627, "author_profile": "https://Stackoverflow.com/users/87627", "pm_score": 2, "selected": false, "text": "'I hate nested regions and will delete them along with any code found in them.\n" }, { "answer_id": 783793, "author": "stdave", "author_id": 71091, "author_profile": "https://Stackoverflow.com/users/71091", "pm_score": 3, "selected": false, "text": "public boolean getDirty (String MAC) // not as fun as it sounds\n" }, { "answer_id": 783935, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "Tweet tweet = (Tweet) tweets.get(i); // Poetic.\n" }, { "answer_id": 784001, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "# This is my rifle.\ndef rifle(type='hunting'):\n print('This is my (%s) rifle.' % type)\n\n# This is my gun.\ndef gun(type='hand'):\n print('This is my (%s) gun.' % type)\n\n# This is for fighting.\ndef fighting(type='illegal'):\n print('This is for (%s) fighting.' % type)\n\n# This is for fun.\ndef fun(type='gaming'):\n print('This is for (%s) fun.' % type)" }, { "answer_id": 784055, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "// TODO: what the hell is this all about?\n" }, { "answer_id": 784725, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "// This is kind of almost useless\n // We also add/subtract some points based on what's going on, on the bottom\n// row. (I think this is retarded, but apparently when I coded this up \n// back in 1999 I didn't.)\n" }, { "answer_id": 784955, "author": "Jonathan C Dickinson", "author_id": 24064, "author_profile": "https://Stackoverflow.com/users/24064", "pm_score": 2, "selected": false, "text": "// TODO: Need some codemonkey to doc comment this class.\n" }, { "answer_id": 785220, "author": "bretik", "author_id": 42074, "author_profile": "https://Stackoverflow.com/users/42074", "pm_score": 3, "selected": false, "text": "// IE7 update. this is still bad code, but IE8 is probably a long way off :)\n" }, { "answer_id": 785272, "author": "Tim Post", "author_id": 50049, "author_profile": "https://Stackoverflow.com/users/50049", "pm_score": 4, "selected": false, "text": "/* Every time I re-visit this function, I feel like\n * I need to take a shower.\n *\n * Don't get too used to this function, its days are\n * numbered.\n */\n" }, { "answer_id": 785328, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "// need a coffee to fix this.\n" }, { "answer_id": 785345, "author": "Manrico Corazzi", "author_id": 4690, "author_profile": "https://Stackoverflow.com/users/4690", "pm_score": 3, "selected": false, "text": "// load image 1 - JPEG 240x320\nimg = f1.getImage();\nif (check(img))\n{\n load(img, Constants.JPEG_240x320);\n}\n\n// load image 2 - JPEG 128x128\nimg = f2.getImage();\nif (check(img))\n{\n load(img, Constants.JPEG_128x128);\n}\n\n...\n\n// load image 13 - GIF 256x256\nimg = f13.getImage();\nif (check(img))\n{\n load(img, Constants.GIF256x256);\n}\n\n// loaded all of the f**king images\n" }, { "answer_id": 786255, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "//I'm sorry, but our princess is in another castle.\n" }, { "answer_id": 786495, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "//too much log will kill you\n" }, { "answer_id": 786818, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "# ===== Never edit below this line. Ever. Or I'll kick your ass. ====\n" }, { "answer_id": 787238, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "//\n//3.4 JeK My manager promised me a lap dance if I can fix this release\n//3.5 JeK Still waiting for that dance from my manager\n//3.6 JeK My manager got changed, the new manager is hairy, dont want the dance anymore\n//3.7 Jek Got that dance, yuck!\n//\n" }, { "answer_id": 787243, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "BEGIN.\n// Here might be dragons\n.\n.\n IF...\n // Beware of the Jabberwocky\n .//user the force, luke\n .\n .\n ENDIF.\n.\nEND.\n" }, { "answer_id": 787301, "author": "splicer", "author_id": 86436, "author_profile": "https://Stackoverflow.com/users/86436", "pm_score": 6, "selected": false, "text": "// batmon.c drives the rastamobile\n" }, { "answer_id": 788086, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "consent = False\n" }, { "answer_id": 788223, "author": "Martin Cote", "author_id": 9936, "author_profile": "https://Stackoverflow.com/users/9936", "pm_score": 2, "selected": false, "text": "// The following array may contain either TexturedObjects or ColoredObjects.\n// I know, it sucks.\n" }, { "answer_id": 788577, "author": "MaoTseTongue", "author_id": 87375, "author_profile": "https://Stackoverflow.com/users/87375", "pm_score": 4, "selected": false, "text": "// Singleton object. Leave $me alone.\nprivate static $me;\n" }, { "answer_id": 789811, "author": "Neil Kodner", "author_id": 92287, "author_profile": "https://Stackoverflow.com/users/92287", "pm_score": 8, "selected": false, "text": "// no comments for you\n// it was hard to write\n// so it should be hard to read\n" }, { "answer_id": 792783, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "// woot, global var. I havent done this for a long time.\n" }, { "answer_id": 792901, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "// *** AAAAAHAHAHAH!! What is this??\n" }, { "answer_id": 792982, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "\n$you = live(\"free\") or die(\"hard\");\n" }, { "answer_id": 794252, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "# dont question, i just felt like throwing some globals in\n# this is actually quite pointless as youll soon see\n #draw the circles (complicated)...dont question\n # complicated process of drawing the circles in a\n# somewhat symmetrical, 3-d pattern\n# dont question again\n # will determine if user clicks on die\n# i determined these values...dont worry about them\n" }, { "answer_id": 794891, "author": "corymathews", "author_id": 1925, "author_profile": "https://Stackoverflow.com/users/1925", "pm_score": 1, "selected": false, "text": "TextBox1.Text = TextBox1.Text; //Point less yes, who writes this crap?\n" }, { "answer_id": 796400, "author": "Lyudmil", "author_id": 13121, "author_profile": "https://Stackoverflow.com/users/13121", "pm_score": 7, "selected": false, "text": "public boolean isDirty() {\n //Why do you always go out and\n return dirty;\n}\n" }, { "answer_id": 796746, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "Here V43 contains the Surname\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184618", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15985/" ]
184,641
<p>I have a mysql table with albums. Each album can be a top level album, or a child album of another album. Each album has a foldername which is the name of the folder its pictures are in. Each album also has a field called parent which is the id of the parent album. So, if I have a path to an image like this:</p> <pre><code>root/album1/album2/image1.jpg </code></pre> <p>then the album table in the database will look like this:</p> <pre><code>id parent foldername 1 NULL root 2 1 album1 3 2 album2 </code></pre> <p>The question is then, how do I get the path printed earlier from this table with only mysql?</p>
[ { "answer_id": 185255, "author": "BoltBait", "author_id": 20848, "author_profile": "https://Stackoverflow.com/users/20848", "pm_score": 0, "selected": false, "text": "DECLARE @FOLDER VARCHAR(200)\nDECLARE @TOPID AS INT\nDECLARE @MYID As int\n\nCREATE TABLE #tmp\n(\n [id] INT,\n [path] VARCHAR(50)\n)\n\nDECLARE tempCursor CURSOR FOR SELECT id FROM albums ORDER BY id\nOPEN tempCursor\n\nFETCH NEXT FROM tempCursor INTO @TOPID\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n SET @FOLDER = ''\n SET @MYID = @TOPID\n\n WHILE @MYID is not null\n BEGIN\n SELECT @MYFOLDER = foldername FROM albums WHERE id = @MYID\n SET @FOLDER = @MYFOLDER + '/' + @FOLDER\n SELECT @MYID = parent FROM albums WHERE id = @MYID\n END\n\n INSERT INTO #tmp\n SELECT @TOPID, @FOLDER\n\n FETCH NEXT FROM tempCursor INTO @TOPID\nEND\nCLOSE tempCursor\nDEALLOCATE tempCursor\n\nSELECT * FROM #tmp\nDROP TABLE #tmp\n" }, { "answer_id": 185317, "author": "sebthebert", "author_id": 24820, "author_profile": "https://Stackoverflow.com/users/24820", "pm_score": 3, "selected": false, "text": "id parent path foldername\n1 NULL / root\n2 1 /root/ album1\n3 2 /root/album1/ album2\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184641", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1585/" ]
184,643
<p>What is the best way to copy a list? I know the following ways, which one is better? Or is there another way?</p> <pre><code>lst = ['one', 2, 3] lst1 = list(lst) lst2 = lst[:] import copy lst3 = copy.copy(lst) </code></pre>
[ { "answer_id": 184660, "author": "Mark Roddy", "author_id": 9940, "author_profile": "https://Stackoverflow.com/users/9940", "pm_score": 8, "selected": true, "text": "lst2=lst1[:]\n import copy\nlst2=copy.deepcopy(lst1)\n" }, { "answer_id": 184679, "author": "Andrea Ambu", "author_id": 21384, "author_profile": "https://Stackoverflow.com/users/21384", "pm_score": 5, "selected": false, "text": "lst2 = lst1 * 1\n >>> a = range(5)\n>>> b = a*1\n>>> a,b\n([0, 1, 2, 3, 4], [0, 1, 2, 3, 4])\n>>> a[2] = 55 \n>>> a,b\n([0, 1, 55, 3, 4], [0, 1, 2, 3, 4])\n >>> \n>>> a = [range(i,i+3) for i in range(3)]\n>>> a\n[[0, 1, 2], [1, 2, 3], [2, 3, 4]]\n>>> b = a*1\n>>> a,b\n([[0, 1, 2], [1, 2, 3], [2, 3, 4]], [[0, 1, 2], [1, 2, 3], [2, 3, 4]])\n >>> for i in (a,b): print i \n[[0, 1, 2], [1, 2, 3], [2, 3, 4]]\n[[0, 1, 2], [1, 2, 3], [2, 3, 4]]\n>>> a[1].append('appended')\n>>> for i in (a,b): print i\n\n[[0, 1, 2], [1, 2, 3, 'appended'], [2, 3, 4]]\n[[0, 1, 2], [1, 2, 3, 'appended'], [2, 3, 4]]\n >>> from copy import deepcopy\n>>> b = deepcopy(a)\n>>> a[0].append('again...')\n>>> for i in (a,b): print i\n\n[[0, 1, 2, 'again...'], [1, 2, 3, 'appended'], [2, 3, 4]]\n[[0, 1, 2], [1, 2, 3, 'appended'], [2, 3, 4]]\n" }, { "answer_id": 184712, "author": "Jason Baker", "author_id": 2147, "author_profile": "https://Stackoverflow.com/users/2147", "pm_score": 2, "selected": false, "text": "import copy\nlist2 = copy.copy(list1)\n" }, { "answer_id": 184751, "author": "Martin Cote", "author_id": 9936, "author_profile": "https://Stackoverflow.com/users/9936", "pm_score": 4, "selected": false, "text": "a = [1, 2, 3]\nb = list(a)\n" }, { "answer_id": 185194, "author": "John Fouhy", "author_id": 15154, "author_profile": "https://Stackoverflow.com/users/15154", "pm_score": 3, "selected": false, "text": "lst2 = list(lst1)\n dct2 = dict(dct1)\n" }, { "answer_id": 8917632, "author": "DNS", "author_id": 51025, "author_profile": "https://Stackoverflow.com/users/51025", "pm_score": 2, "selected": false, "text": "list() lst2 = lst1[:] lst2 = list(lst1) list()" }, { "answer_id": 14821420, "author": "shakefu", "author_id": 1418232, "author_profile": "https://Stackoverflow.com/users/1418232", "pm_score": 2, "selected": false, "text": "In [1]: l = range(10)\n\nIn [2]: %timeit list(l)\n1000000 loops, best of 3: 477 ns per loop\n\nIn [3]: %timeit l[:]\n1000000 loops, best of 3: 236 ns per loop\n\nIn [6]: %timeit copy(l)\n1000000 loops, best of 3: 1.43 us per loop\n In [7]: l = range(50000)\n\nIn [8]: %timeit list(l)\n1000 loops, best of 3: 261 us per loop\n\nIn [9]: %timeit l[:]\n1000 loops, best of 3: 261 us per loop\n\nIn [10]: %timeit copy(l)\n1000 loops, best of 3: 248 us per loop\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4915/" ]
184,662
<p>In our product we have a big utilities file that we require (with <code>do</code>) at the beginning of a lot of our files. Is there a reason <em>not</em> to turn this into a module? For example, instead of doing this:</p> <pre><code>do '../dbi_utilities.pl'; our ($db,$user,$pw,$attr); my $Data = DBI-&gt;connect($db,$user,$pw,$attr) or die "Could not connect to database: $DBI::errstr"; </code></pre> <p>Couldn't I just do this?:</p> <pre><code>use AppUtil; my $Data = AppUtil-&gt;connect(); </code></pre>
[ { "answer_id": 184689, "author": "bmdhacks", "author_id": 14032, "author_profile": "https://Stackoverflow.com/users/14032", "pm_score": 3, "selected": false, "text": "use perl -wc use" }, { "answer_id": 184717, "author": "J.J.", "author_id": 21204, "author_profile": "https://Stackoverflow.com/users/21204", "pm_score": 1, "selected": false, "text": "use" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12448/" ]
184,678
<p>I'm using SimpleDateFormat with the pattern <code>EEE MM/dd hh:mma</code>, passing in the date String <code>Thu 10/9 08:15PM</code> and it's throwing an Unparseable date exception. Why? I've used various patterns with <code>SimpleDateFormat</code> before so I'm fairly familiar with its usage. Maybe I'm missing something obvious from staring at it too long.</p> <p>The other possibility is funky (technical term) whitespace. The context is a screen-scraping app, where I'm using HtmlCleaner to tidy up the messy html. While I've found HtmlCleaner to be pretty good overall, I've noticed strange issues with characters that look like whitespace but aren't recognized as such with a StringTokenizer, for example. I've mostly worked around it and haven't dug into the character encoding or anything like that but am starting to wonder.</p>
[ { "answer_id": 184694, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 1, "selected": false, "text": "EEE MM/d hh:mma\n d dd" }, { "answer_id": 184827, "author": "Eric Tuttleman", "author_id": 25677, "author_profile": "https://Stackoverflow.com/users/25677", "pm_score": 3, "selected": true, "text": "sdf = new java.text.SimpleDateFormat(\"EEE MM/dd hh:mma\");\nSystem.out.println(sdf.format(sdf.parse(\"Thu 10/9 08:15PM\")));\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184678", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26270/" ]
184,681
<p>Which of these pieces of code is faster?</p> <pre><code>if (obj is ClassA) {} if (obj.GetType() == typeof(ClassA)) {} </code></pre> <p>Edit: I'm aware that they don't do the same thing.</p>
[ { "answer_id": 184697, "author": "MagicKat", "author_id": 8505, "author_profile": "https://Stackoverflow.com/users/8505", "pm_score": 8, "selected": true, "text": "if (obj.GetType() == typeof(ClassA)) {}" }, { "answer_id": 184718, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 8, "selected": false, "text": "is ClassA GetType()" }, { "answer_id": 14836403, "author": "nawfal", "author_id": 661933, "author_profile": "https://Stackoverflow.com/users/661933", "pm_score": 4, "selected": false, "text": "var c1 = \"\";\nvar c2 = typeof(string);\nobject oc1 = c1;\nobject oc2 = c2;\n\nvar s1 = 0;\nvar s2 = '.';\nobject os1 = s1;\nobject os2 = s2;\n\nbool b = false;\n\nStopwatch sw = Stopwatch.StartNew();\nfor (int i = 0; i < 10000000; i++)\n{\n b = c1.GetType() == typeof(string); // ~60ms\n b = c1 is string; // ~60ms\n\n b = c2.GetType() == typeof(string); // ~60ms\n b = c2 is string; // ~50ms\n\n b = oc1.GetType() == typeof(string); // ~60ms\n b = oc1 is string; // ~68ms\n\n b = oc2.GetType() == typeof(string); // ~60ms\n b = oc2 is string; // ~64ms\n\n\n b = s1.GetType() == typeof(int); // ~130ms\n b = s1 is int; // ~50ms\n\n b = s2.GetType() == typeof(int); // ~140ms\n b = s2 is int; // ~50ms\n\n b = os1.GetType() == typeof(int); // ~60ms\n b = os1 is int; // ~74ms\n\n b = os2.GetType() == typeof(int); // ~60ms\n b = os2 is int; // ~68ms\n\n\n b = GetType1<string, string>(c1); // ~178ms\n b = GetType2<string, string>(c1); // ~94ms\n b = Is<string, string>(c1); // ~70ms\n\n b = GetType1<string, Type>(c2); // ~178ms\n b = GetType2<string, Type>(c2); // ~96ms\n b = Is<string, Type>(c2); // ~65ms\n\n b = GetType1<string, object>(oc1); // ~190ms\n b = Is<string, object>(oc1); // ~69ms\n\n b = GetType1<string, object>(oc2); // ~180ms\n b = Is<string, object>(oc2); // ~64ms\n\n\n b = GetType1<int, int>(s1); // ~230ms\n b = GetType2<int, int>(s1); // ~75ms\n b = Is<int, int>(s1); // ~136ms\n\n b = GetType1<int, char>(s2); // ~238ms\n b = GetType2<int, char>(s2); // ~69ms\n b = Is<int, char>(s2); // ~142ms\n\n b = GetType1<int, object>(os1); // ~178ms\n b = Is<int, object>(os1); // ~69ms\n\n b = GetType1<int, object>(os2); // ~178ms\n b = Is<int, object>(os2); // ~69ms\n}\n\nsw.Stop();\nMessageBox.Show(sw.Elapsed.TotalMilliseconds.ToString());\n static bool GetType1<S, T>(T t)\n{\n return t.GetType() == typeof(S);\n}\nstatic bool GetType2<S, T>(T t)\n{\n return typeof(T) == typeof(S);\n}\nstatic bool Is<S, T>(T t)\n{\n return t is S;\n}\n var c1 = new Class1();\nvar c2 = new Class2();\nobject oc1 = c1;\nobject oc2 = c2;\n\nvar s1 = new Struct1();\nvar s2 = new Struct2();\nobject os1 = s1;\nobject os2 = s2;\n\nbool b = false;\n\nStopwatch sw = Stopwatch.StartNew();\nfor (int i = 0; i < 10000000; i++)\n{\n b = c1.GetType() == typeof(Class1); // ~60ms\n b = c1 is Class1; // ~60ms\n\n b = c2.GetType() == typeof(Class1); // ~60ms\n b = c2 is Class1; // ~55ms\n\n b = oc1.GetType() == typeof(Class1); // ~60ms\n b = oc1 is Class1; // ~68ms\n\n b = oc2.GetType() == typeof(Class1); // ~60ms\n b = oc2 is Class1; // ~68ms\n\n\n b = s1.GetType() == typeof(Struct1); // ~150ms\n b = s1 is Struct1; // ~50ms\n\n b = s2.GetType() == typeof(Struct1); // ~150ms\n b = s2 is Struct1; // ~50ms\n\n b = os1.GetType() == typeof(Struct1); // ~60ms\n b = os1 is Struct1; // ~64ms\n\n b = os2.GetType() == typeof(Struct1); // ~60ms\n b = os2 is Struct1; // ~64ms\n\n\n b = GetType1<Class1, Class1>(c1); // ~178ms\n b = GetType2<Class1, Class1>(c1); // ~98ms\n b = Is<Class1, Class1>(c1); // ~78ms\n\n b = GetType1<Class1, Class2>(c2); // ~178ms\n b = GetType2<Class1, Class2>(c2); // ~96ms\n b = Is<Class1, Class2>(c2); // ~69ms\n\n b = GetType1<Class1, object>(oc1); // ~178ms\n b = Is<Class1, object>(oc1); // ~69ms\n\n b = GetType1<Class1, object>(oc2); // ~178ms\n b = Is<Class1, object>(oc2); // ~69ms\n\n\n b = GetType1<Struct1, Struct1>(s1); // ~272ms\n b = GetType2<Struct1, Struct1>(s1); // ~140ms\n b = Is<Struct1, Struct1>(s1); // ~163ms\n\n b = GetType1<Struct1, Struct2>(s2); // ~272ms\n b = GetType2<Struct1, Struct2>(s2); // ~140ms\n b = Is<Struct1, Struct2>(s2); // ~163ms\n\n b = GetType1<Struct1, object>(os1); // ~178ms\n b = Is<Struct1, object>(os1); // ~64ms\n\n b = GetType1<Struct1, object>(os2); // ~178ms\n b = Is<Struct1, object>(os2); // ~64ms\n}\n\nsw.Stop();\nMessageBox.Show(sw.Elapsed.TotalMilliseconds.ToString());\n sealed class Class1 { }\nsealed class Class2 { }\nstruct Struct1 { }\nstruct Struct2 { }\n GetType struct GetType object struct GetType GetType T class is T struct is GetType typeof(T) T class typeof(T) t.GetType object GetType class is struct typeof(T) is is" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9825/" ]
184,683
<p>Is there a way in C# to play audio (for example, MP3) direcly from a <a href="http://msdn.microsoft.com/en-us/library/system.io.stream%28v=vs.110%29.aspx" rel="noreferrer">System.IO.Stream</a> that for instance was returend from a WebRequest without saving the data temporarily to the disk?</p> <hr> <h3>Solution with <a href="https://github.com/naudio/NAudio" rel="noreferrer">NAudio</a></h3> <p>With the help of <a href="https://github.com/naudio/NAudio" rel="noreferrer">NAudio</a> 1.3 it is possible to:</p> <ol> <li>Load an MP3 file from a URL into a MemoryStream</li> <li>Convert MP3 data into wave data after it was completely loaded</li> <li>Playback the wave data using <a href="https://github.com/naudio/NAudio" rel="noreferrer">NAudio</a>'s WaveOut class</li> </ol> <p>It would have been nice to be able to even play a half loaded MP3 file, but this seems to be impossible due to the <a href="https://github.com/naudio/NAudio" rel="noreferrer">NAudio</a> library design.</p> <p>And this is the function that will do the work:</p> <pre><code> public static void PlayMp3FromUrl(string url) { using (Stream ms = new MemoryStream()) { using (Stream stream = WebRequest.Create(url) .GetResponse().GetResponseStream()) { byte[] buffer = new byte[32768]; int read; while ((read = stream.Read(buffer, 0, buffer.Length)) &gt; 0) { ms.Write(buffer, 0, read); } } ms.Position = 0; using (WaveStream blockAlignedStream = new BlockAlignReductionStream( WaveFormatConversionStream.CreatePcmStream( new Mp3FileReader(ms)))) { using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback())) { waveOut.Init(blockAlignedStream); waveOut.Play(); while (waveOut.PlaybackState == PlaybackState.Playing ) { System.Threading.Thread.Sleep(100); } } } } } </code></pre>
[ { "answer_id": 184796, "author": "OwenP", "author_id": 2547, "author_profile": "https://Stackoverflow.com/users/2547", "pm_score": 3, "selected": false, "text": "Play" }, { "answer_id": 185041, "author": "Mark Heath", "author_id": 7532, "author_profile": "https://Stackoverflow.com/users/7532", "pm_score": 7, "selected": true, "text": "MP3Frame AcmMp3FrameDecompressor BufferedWaveProvider BufferedWaveProvider" }, { "answer_id": 5081173, "author": "ReVolly", "author_id": 492016, "author_profile": "https://Stackoverflow.com/users/492016", "pm_score": 2, "selected": false, "text": "private Stream ms = new MemoryStream();\npublic void PlayMp3FromUrl(string url)\n{\n new Thread(delegate(object o)\n {\n var response = WebRequest.Create(url).GetResponse();\n using (var stream = response.GetResponseStream())\n {\n byte[] buffer = new byte[65536]; // 64KB chunks\n int read;\n while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)\n {\n var pos = ms.Position;\n ms.Position = ms.Length;\n ms.Write(buffer, 0, read);\n ms.Position = pos;\n }\n }\n }).Start();\n\n // Pre-buffering some data to allow NAudio to start playing\n while (ms.Length < 65536*10)\n Thread.Sleep(1000);\n\n ms.Position = 0;\n using (WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(ms))))\n {\n using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))\n {\n waveOut.Init(blockAlignedStream);\n waveOut.Play();\n while (waveOut.PlaybackState == PlaybackState.Playing)\n {\n System.Threading.Thread.Sleep(100);\n }\n }\n }\n}\n" }, { "answer_id": 9245124, "author": "M.Babcock", "author_id": 635634, "author_profile": "https://Stackoverflow.com/users/635634", "pm_score": 2, "selected": false, "text": "bool waiting = false;\nAutoResetEvent stop = new AutoResetEvent(false);\npublic void PlayMp3FromUrl(string url, int timeout)\n{\n using (Stream ms = new MemoryStream())\n {\n using (Stream stream = WebRequest.Create(url)\n .GetResponse().GetResponseStream())\n {\n byte[] buffer = new byte[32768];\n int read;\n while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)\n {\n ms.Write(buffer, 0, read);\n }\n }\n ms.Position = 0;\n using (WaveStream blockAlignedStream =\n new BlockAlignReductionStream(\n WaveFormatConversionStream.CreatePcmStream(\n new Mp3FileReader(ms))))\n {\n using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))\n {\n waveOut.Init(blockAlignedStream);\n waveOut.PlaybackStopped += (sender, e) =>\n {\n waveOut.Stop();\n };\n waveOut.Play();\n waiting = true;\n stop.WaitOne(timeout);\n waiting = false;\n }\n }\n }\n}\n var playThread = new Thread(timeout => PlayMp3FromUrl(\"http://translate.google.com/translate_tts?q=\" + HttpUtility.UrlEncode(relatedLabel.Text), (int)timeout));\nplayThread.IsBackground = true;\nplayThread.Start(10000);\n if (waiting)\n stop.Set();\n ParameterizedThreadDelegate playThread.Start(10000);" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184683", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25782/" ]
184,703
<p>I have a form that is sending in sizes of things, and I need to see what the strings are equal to so that I can set the price accordingly. When i try to do this, it says that they are not equal, and i get no prices. This is the code i'm using:</p> <pre><code>if ($_POST['sizes'] == "Small ($30)"){$total = "30";} if ($_POST['sizes'] == "Medium ($40)"){$total = "40";} if ($_POST['sizes'] == "Large ($50)"){$total = "50";} else {$total = $_POST['price'];} </code></pre> <p>What am i doing wrong here? I can echo $_POST['sizes'] and it gives me exactly one of those things.</p>
[ { "answer_id": 184737, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 1, "selected": false, "text": "if ($_POST['sizes'] == 'Small ($30)'){$total = \"30\";}\nelseif ($_POST['sizes'] == 'Medium ($40)'){$total = \"40\";}\nelseif ($_POST['sizes'] == 'Large ($50)'){$total = \"50\";}\nelse {$total = $_POST['price'];}\n" }, { "answer_id": 184752, "author": "Peter Bailey", "author_id": 8815, "author_profile": "https://Stackoverflow.com/users/8815", "pm_score": 4, "selected": true, "text": "$total $_POST['price'] 'Large ($50)' <?php\n\nswitch ( $_POST['sizes'] )\n{\n case 'Small ($30)' :\n $total = 30;\n break;\n case 'Medium ($40)' :\n $total = 40;\n break;\n case 'Large ($50)' :\n $total = 50;\n break;\n default:\n $total = $_POST['price'];\n break;\n}\n\n?>\n" }, { "answer_id": 184856, "author": "Darryl Hein", "author_id": 5441, "author_profile": "https://Stackoverflow.com/users/5441", "pm_score": 2, "selected": false, "text": "if ($_POST['sizes'] == \"Small ($30)\") { $total = \"30\";\n} else if ($_POST['sizes'] == \"Medium ($40)\") { $total = \"40\";\n} else if ($_POST['sizes'] == \"Large ($50)\") { $total = \"50\";\n} else { $total = $_POST['price']; }\n" }, { "answer_id": 509546, "author": "Bobby Jack", "author_id": 5058, "author_profile": "https://Stackoverflow.com/users/5058", "pm_score": 1, "selected": false, "text": "$vals = array(\n 'Small ($30)' => 30,\n 'Medium ($40)' => 40,\n 'Large ($50)' => 50\n);\n\n$total = array_key_exists($_POST['sizes'], $vals)\n ? $vals[$_POST['sizes']]\n : $_POST['price'];\n" }, { "answer_id": 509554, "author": "eplawless", "author_id": 1370, "author_profile": "https://Stackoverflow.com/users/1370", "pm_score": 0, "selected": false, "text": "// remove any non-decimal characters from the front, then extract your value,\n// then remove any trailing characters and cast to an integer\n$total = (integer)preg_replace(\"/^\\D*(\\d+)\\D.*/\", \"$1\", $_POST['sizes']);\nif (!$total) $total = $_POST['price'];\n" }, { "answer_id": 509572, "author": "Gumbo", "author_id": 53114, "author_profile": "https://Stackoverflow.com/users/53114", "pm_score": 1, "selected": false, "text": "<select name=\"sizes\">\n <option value=\"small\">Small ($30)</option>\n <option value=\"meduim\">Medium ($40)</option>\n <option value=\"large\">Large ($50)</option>\n</select>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50/" ]
184,704
<p>In Java, is there an elegant way to detect if an exception occurred prior to running the finally block? When dealing with "close()" statements, it's common to need exception handling within the finally block. Ideally, we'd want to maintain both exceptions and propagate them up (as both of them may contain useful information). The only way I can think of to do this is to have a variable outside the try-catch-finally scope to save a reference to a thrown exception. Then propagate the "saved" exception up with any that occur in the finally block.</p> <p>Is there a more elegant way of doing this? Perhaps an API call that will reveal this?</p> <p>Here's some rough code of what I'm talking about:</p> <pre><code>Throwable t = null; try { stream.write(buffer); } catch(IOException e) { t = e; //Need to save this exception for finally throw e; } finally { try { stream.close(); //may throw exception } catch(IOException e) { //Is there something better than saving the exception from the exception block? if(t!=null) { //propagate the read exception as the "cause"--not great, but you see what I mean. throw new IOException("Could not close in finally block: " + e.getMessage(),t); } else { throw e; //just pass it up } }//end close } </code></pre> <p>Obviously, there are a number of other similar kludges that might involve saving the exception as an member variable, returning it from a method, etc... but I'm looking for something a bit more elegant.</p> <p>Maybe something like <code>Thread.getPendingException()</code> or something similar? For that matter, is there an elegant solution in other languages?</p> <p>This question actually spawned from comments in <a href="https://stackoverflow.com/questions/183499/is-there-a-preference-for-nested-trycatch-blocks#183572">another question</a> that raised an interesting question. </p>
[ { "answer_id": 190631, "author": "gedevan", "author_id": 20225, "author_profile": "https://Stackoverflow.com/users/20225", "pm_score": 2, "selected": false, "text": "try { \n stream.write(buffer); \n} catch(IOException ex) {\n if (LOG.isErrorEnabled()) { // You can use log level whatever you want\n LOG.error(\"Something wrong: \" + ex.getMessage(), ex);\n }\n throw ex;\n} finally { \n if (stream != null) {\n try {\n stream.close();\n } catch (IOException ex) {\n if (LOG.isWarnEnabled()) {\n LOG.warn(\"Could not close in finally block\", ex);\n }\n }\n }\n}\n" }, { "answer_id": 1354697, "author": "Triynko", "author_id": 88409, "author_profile": "https://Stackoverflow.com/users/88409", "pm_score": 3, "selected": false, "text": "finally (Exception main_exception)\n{\n try\n {\n //cleanup that may throw an error (absolutely unpredictably)\n }\n catch (Exception err)\n {\n //Instead of throwing another error,\n //just add data to main exception mentioning that an error occurred in the finally block!\n main_exception.Data.Add( \"finally_error\", err );\n //main exception propagates from finally block normally, with additional data\n }\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17871/" ]
184,710
<p>What is the difference between a deep copy and a shallow copy?</p>
[ { "answer_id": 184730, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 6, "selected": false, "text": "class String\n{\n int size;\n char* data;\n};\n\nString s1(\"Ace\"); // s1.size = 3 s1.data=0x0000F000\n\nString s2 = shallowCopy(s1);\n // s2.size =3 s2.data = 0X0000F000\nString s3 = deepCopy(s1);\n // s3.size =3 s3.data = 0x0000F00F\n // (With Ace copied to this location.)\n" }, { "answer_id": 184754, "author": "John Dibling", "author_id": 241536, "author_profile": "https://Stackoverflow.com/users/241536", "pm_score": 5, "selected": false, "text": "char * Source = \"Hello, world.\";\n\nchar * ShallowCopy = Source; \n\nchar * DeepCopy = new char(strlen(Source)+1);\nstrcpy(DeepCopy,Source); \n" }, { "answer_id": 184761, "author": "Dour High Arch", "author_id": 22437, "author_profile": "https://Stackoverflow.com/users/22437", "pm_score": 3, "selected": false, "text": "var source = { firstName=\"Jane\", lastname=\"Jones\" };\nvar shallow = ShallowCopyOf(source);\nvar deep = DeepCopyOf(source);\nsource.lastName = \"Smith\";\nWriteLine(source.lastName); // prints Smith\nWriteLine(shallow.lastName); // prints Smith\nWriteLine(deep.lastName); // prints Jones\n" }, { "answer_id": 7200834, "author": "notytony", "author_id": 599848, "author_profile": "https://Stackoverflow.com/users/599848", "pm_score": 3, "selected": false, "text": "struct sample\n{\n char * ptr;\n}\nvoid shallowcpy(sample & dest, sample & src)\n{\n dest.ptr=src.ptr;\n}\nvoid deepcpy(sample & dest, sample & src)\n{\n dest.ptr=malloc(strlen(src.ptr)+1);\n memcpy(dest.ptr,src.ptr);\n}\n" }, { "answer_id": 13961428, "author": "komizo", "author_id": 1792434, "author_profile": "https://Stackoverflow.com/users/1792434", "pm_score": 1, "selected": false, "text": " static void Main()\n {\n int[] arr1 = new int[] { 1, 2, 3, 4, 5 }; \n int[] arr2 = new int[] { 6, 7, 8, 9, 0 };\n\n Console.WriteLine(arr1[2] + \" \" + arr2[2]);\n arr2 = arr1;\n Console.WriteLine(arr1[2] + \" \" + arr2[2]); \n arr2 = (int[])arr1.Clone();\n arr1[2] = 12;\n Console.WriteLine(arr1[2] + \" \" + arr2[2]);\n }\n" }, { "answer_id": 14478897, "author": "Abhishek Bedi", "author_id": 667586, "author_profile": "https://Stackoverflow.com/users/667586", "pm_score": 6, "selected": false, "text": "B A B = [A assign]; B = [A retain] B A B = [A copy];" }, { "answer_id": 20710307, "author": "Avinash Goud N J", "author_id": 2869930, "author_profile": "https://Stackoverflow.com/users/2869930", "pm_score": 0, "selected": false, "text": "MyClass& MyClass(const MyClass& obj) // copy constructor for MyClass\n{\n // write your code, to copy all the members and return the new object\n}\nMyClass& operator=(const MyClass& obj) // overloading assignment operator,\n{\n // write your code, to copy all the members and return the new object\n}\n" }, { "answer_id": 27540794, "author": "atish shimpi", "author_id": 1245337, "author_profile": "https://Stackoverflow.com/users/1245337", "pm_score": 5, "selected": false, "text": "MainObject1 field1 ContainObject1 ContainObject MainObject1 MainObject2 field2 field1 ContainObject1 field1 field2 ContainedObject1 MainObject2 ContainObject1 ContainObject1 MainObject1 MainObject2 field1 ContainObject1 ContainObject MainObject1 MainObject2 field2 field1 ContainObject2 ContainObject1 ContainObject1 MainObject1 MainObject2" }, { "answer_id": 30094230, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "public class Language implements Cloneable{\n \n String name;\n public Language(String name){\n this.name=name;\n }\n \n public String getName() {\n return name;\n }\n \n @Override\n protected Object clone() throws CloneNotSupportedException {\n return super.clone();\n }\n}\n public static void main(String args[]) throws ClassNotFoundException, CloneNotSupportedException{\n\n ArrayList<Language> list=new ArrayList<Language>();\n list.add(new Language(\"C\"));\n list.add(new Language(\"JAVA\"));\n\n ArrayList<Language> shallow=(ArrayList<Language>) list.clone();\n //We used here clone since this always shallow copied.\n\n System.out.println(list==shallow);\n \n for(int i=0;i<list.size();i++)\n System.out.println(list.get(i)==shallow.get(i));//true\n \n ArrayList<Language> deep=new ArrayList<Language>();\n for(Language language:list){\n deep.add((Language) language.clone());\n }\n System.out.println(list==deep);\n for(int i=0;i<list.size();i++)\n System.out.println(list.get(i)==deep.get(i));//false\n \n} \n list.get(0).name=\"ViSuaLBaSiC\";\n System.out.println(shallow.get(0).getName()+\" \"+deep.get(0).getName());\n" }, { "answer_id": 30519355, "author": "PeerNet", "author_id": 3964160, "author_profile": "https://Stackoverflow.com/users/3964160", "pm_score": 3, "selected": false, "text": "arr1 = arr2; //shallow copy\narr1 = arr2.clone(); //deep copy\n" }, { "answer_id": 41606231, "author": "Lance Ruo Zhang", "author_id": 5064393, "author_profile": "https://Stackoverflow.com/users/5064393", "pm_score": 1, "selected": false, "text": "x = [\n [1,2,3],\n [4,5,6],\n ]\n y = x\n y = list(x)\n y = x[:]\n" }, { "answer_id": 42622363, "author": "Lova Chittumuri", "author_id": 5256337, "author_profile": "https://Stackoverflow.com/users/5256337", "pm_score": 2, "selected": false, "text": "public class DeepAndShollowCopy {\n int id;\n String name;\n List<String> testlist = new ArrayList<>();\n\n /*\n // To performing Shallow Copy \n // Note: Here we are not creating any references. \n public DeepAndShollowCopy(int id, String name, List<String>testlist)\n { \n\n System.out.println(\"Shallow Copy for Object initialization\");\n this.id = id; \n this.name = name; \n this.testlist = testlist; \n\n }\n */ \n\n // To performing Deep Copy \n // Note: Here we are creating one references( Al arraylist object ). \n public DeepAndShollowCopy(int id, String name, List<String> testlist) {\n System.out.println(\"Deep Copy for Object initialization\");\n this.id = id;\n this.name = name;\n String item;\n List<String> Al = new ArrayList<>();\n Iterator<String> itr = testlist.iterator();\n while (itr.hasNext()) {\n item = itr.next();\n Al.add(item);\n }\n this.testlist = Al;\n }\n\n\n public static void main(String[] args) {\n List<String> list = new ArrayList<>();\n list.add(\"Java\");\n list.add(\"Oracle\");\n list.add(\"C++\");\n DeepAndShollowCopy copy=new DeepAndShollowCopy(10,\"Testing\", list);\n System.out.println(copy.toString());\n }\n @Override\n public String toString() {\n return \"DeepAndShollowCopy [id=\" + id + \", name=\" + name + \", testlist=\" + testlist + \"]\";\n }\n}\n" }, { "answer_id": 46417841, "author": "Arun Raaj", "author_id": 4334162, "author_profile": "https://Stackoverflow.com/users/4334162", "pm_score": 4, "selected": false, "text": "Employee e = new Employee(2, \"john cena\");\nEmployee e2=e.clone();\n super.clone(); Employee e = new Employee(2, \"john cena\", new Address(12, \"West Newbury\", \"Massachusetts\");\n" }, { "answer_id": 48353796, "author": "Sushant", "author_id": 5738231, "author_profile": "https://Stackoverflow.com/users/5738231", "pm_score": 3, "selected": false, "text": "import copy\nx =[1,[2]]\ny=copy.copy(x)\nz= copy.deepcopy(x)\nprint(y is z)\n x=[1,[2]] y = copy.copy(x) z = copy.deepcopy(x) False" }, { "answer_id": 48416456, "author": "Vivek Mehta", "author_id": 6285996, "author_profile": "https://Stackoverflow.com/users/6285996", "pm_score": 4, "selected": false, "text": "var originalObject = { \n a : 1, \n b : 2, \n c : 3,\n};\n var copyObject1 = originalObject;\n\nconsole.log(copyObject1.a); // it will print 1 \nconsole.log(originalObject.a); // it will also print 1 \ncopyObject1.a = 4; \nconsole.log(copyObject1.a); //now it will print 4 \nconsole.log(originalObject.a); // now it will also print 4\n\nvar copyObject2 = Object.assign({}, originalObject);\n\nconsole.log(copyObject2.a); // it will print 1 \nconsole.log(originalObject.a); // it will also print 1 \ncopyObject2.a = 4; \nconsole.log(copyObject2.a); // now it will print 4 \nconsole.log(originalObject.a); // now it will print 1\n var copyObject2 = Object.assign({}, originalObject);\n\nconsole.log(copyObject2.a); // it will print 1 \nconsole.log(originalObject.a); // it will also print 1 \ncopyObject2.a = 4; \nconsole.log(copyObject2.a); // now it will print 4 \nconsole.log(originalObject.a); // !! now it will print 1 !!\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184710", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1447/" ]
184,721
<p>I have a windows c# application and I want to display a pdf file, located on a webserver, in an acrobat com object added to my form. </p> <pre><code>pdf.loadfile(@"http://somewhere.com/nowwhere.pdf") </code></pre> <p>As my pdf is large, the application seems to hang till the entire file is loaded. </p> <p>I want to read the large file without the user being under the perception that the application is hung.</p>
[ { "answer_id": 184818, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 0, "selected": false, "text": "Pdf pdf;\n\nvoid ShowPdf() {\n if (this.InvokeRequired) {\n this.Invoke(() => this.ShowPdf());\n }\n // give pdf a window...\n}\n\nvoid LoadPdf() {\n System.Threading.ThreadPool.QueueUserWorkItem(() => {\n pdf.LoadFile(\"http://example.com/somelarge.pdf\");\n this.ShowPdf();\n });\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184721", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
184,766
<p>I believe the simplest way to request data from a server in XML format is to have a PHP/JSP/ASP.net page which actually generates XML based on HTTP GET params, and to somehow call/load this page from Flex.</p> <p>How exactly can this be achieved using the Flex library classes?</p>
[ { "answer_id": 185061, "author": "Raleigh Buckner", "author_id": 1153, "author_profile": "https://Stackoverflow.com/users/1153", "pm_score": 1, "selected": false, "text": "public var dataRequest:URLRequest;\npublic var dataLoader:URLLoader;\npublic var allowCache:Boolean;\n\ndataLoader = new URLLoader();\ndataLoader.addEventListener(Event.COMPLETE, onComplete);\ndataLoader.addEventListener(ProgressEvent.PROGRESS, onProgress);\ndataLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);\ndataLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);\ndataLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus);\n\ndataRequest = new URLRequest();\ndataRequest.url = \"xmlfilelocation.xml\" + ((this.allowCache) ? \"\" : \"?cachekiller=\" + new Date().valueOf());\n\ndataLoader.load(dataRequest);\n\npublic function onComplete(event:Event):void{\n trace(\"onComplete\");\n}\npublic function onProgress(event:ProgressEvent):void{\n trace(\"onProgress\");\n}\npublic function onIOError(event:IOErrorEvent):void{\n trace(\"onIOError\");\n}\npublic function onSecurityError(event:SecurityErrorEvent):void{\n trace(\"onSecurityError\");\n}\npublic function onHTTPStatus(event:HTTPStatusEvent):void{\n trace(\"onHTTPStatus\");\n}\n" }, { "answer_id": 186087, "author": "Laura", "author_id": 5103, "author_profile": "https://Stackoverflow.com/users/5103", "pm_score": 2, "selected": false, "text": "<mx:HTTPService resultFormat=\"e4x\" ..../> or <mx:HTTPService resultFormat=\"xml\" .../>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13220/" ]
184,773
<p>I am looking for a general UI design / work-flow for changing the same property across multiple objects. </p> <p>Suppose I have an object class called Person. The Person class has a property called City. I want to select 5 Person objects and change the City property on all 5 to "New York" in one action in the UI. </p> <p>This is not difficult to accomplish programatically, but I am having a difficult time coming up with an intuitive UI work-flow. One thought is to use a modal like the one used in iTunes to change information about multiple selected songs. I would like to come up with another work-flow, as this idea has already gotten push-back at work.</p> <p>Thoughts? Ideas?</p> <p><strong>Edit:</strong> I appreciate the answers so far. There are couple of extra points I would like to call out:</p> <ol> <li>Should the previous City values be display in some way? If so, how? Or how should the combined property screen show that all the City values are currently the same or different with a color or other indicator?</li> <li>How should boolean properties (Person.IsAlive for example) be displayed? Do you use a three-state toggle/check box? Us a drop-down with three values? Other ideas?</li> </ol>
[ { "answer_id": 1671912, "author": "Peter", "author_id": 202363, "author_profile": "https://Stackoverflow.com/users/202363", "pm_score": 0, "selected": false, "text": "Rows to update : 3\n\n ..........Old Value... Change?....New Value\n\n Field A ABC\n Field B 123 Y 845\n Field C BOB \n\n [<Back] [Next>] [Finish]\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184773", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13103/" ]
184,782
<p>I'm a doing some blackbox testing of a ASP.Net website and I need to test different session timeout scenarios. </p> <p>I'm not sure they fully encapsulated session timeouts. Other then leaving a page open for 20 minutes is there an easier way to force a session timeout?</p>
[ { "answer_id": 184810, "author": "Eduardo Campañó", "author_id": 12091, "author_profile": "https://Stackoverflow.com/users/12091", "pm_score": 2, "selected": false, "text": " <authentication mode=\"Forms\">\n <forms timeout=\"10\" protection=\"All\" slidingExpiration=\"true\" loginUrl=\"~/login.aspx\" cookieless=\"UseCookies\"/>\n </authentication>\n" }, { "answer_id": 375277, "author": "J c", "author_id": 25837, "author_profile": "https://Stackoverflow.com/users/25837", "pm_score": 7, "selected": true, "text": " <system.web>\n <sessionState timeout=\"60\" /> \n ...\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6161/" ]
184,813
<p>I have a (Wordpress powered) website, and Google is indexing some of the sub-directories. How can I stop Apache from showing users the directory listing? I know I can edit .htaccess to password-protect a directory, but I would prefer a 403 / custom redirect if possible.</p>
[ { "answer_id": 184821, "author": "Ates Goral", "author_id": 23501, "author_profile": "https://Stackoverflow.com/users/23501", "pm_score": 5, "selected": true, "text": ".htaccess" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4812/" ]
184,823
<p>I want to place a combobox inside one column of a Xtragrid. I can bind the combobox to array values but how do you bind the combobox to the column? </p>
[ { "answer_id": 5633362, "author": "Soham Dasgupta", "author_id": 238631, "author_profile": "https://Stackoverflow.com/users/238631", "pm_score": 2, "selected": false, "text": "Dim xSunday As New DevExpress.XtraEditors.Repository.RepositoryItemComboBox\nMe.GridView1.Columns(\"Sunday\").ColumnEdit = xSunday\nxSunday.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor\nxSunday.Items.Clear()\nxSunday.Items.Add(\"Full\")\nxSunday.Items.Add(\"Half\")\nxSunday.Items.Add(\"Off\")\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
184,840
<p>I'm working on an asp.net web site. We have to use com interop to interact with legacy vb6 activex components. The components in many cases rely on receiving a context object (which is itself a vb6 activex component) as a parameter. The context object is fairly costly to construct.</p> <p>Therefore one idea is that a context object is constructed once and stored in asp.net session. However, if this object is just a .net wrapper around an activex component, is it wise or advisible to persist such an object in session?</p> <p>Additionally the context object contains user specific information, so persisting using .net HttpRuntime Caching could be used, but would require a user specific key. </p> <p>I understand the other limitations and things you need to be aware of with asp.net session, <a href="https://stackoverflow.com/questions/133236/aspnet-session">aspnet-session question</a>.</p> <p>To ask the question a slightly different way: are their any issues or problems with storing an .net object that is just a wrapper around a com object? </p>
[ { "answer_id": 185051, "author": "Mike Dimmick", "author_id": 6970, "author_profile": "https://Stackoverflow.com/users/6970", "pm_score": 3, "selected": true, "text": "AspCompat" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4764/" ]
184,853
<p>I swear there used to be a way in X to start capturing all terminal traffic to a file on your host. It may have been a HummingBird extension, but I thought it was standard. Now, I can't find the trick. Am I hallucinating (happens when you get old), or is it possible?<br><br>I'm not talking about 'tee'. I want to be able to send a xterm control-sequence to stdout, giving a file name, and have everthing shown in the window from that time onward saved to the file (until the bookend cancel is issued).</p>
[ { "answer_id": 184867, "author": "André", "author_id": 9683, "author_profile": "https://Stackoverflow.com/users/9683", "pm_score": 0, "selected": false, "text": "man tee" }, { "answer_id": 759017, "author": "andrewdotn", "author_id": 14558, "author_profile": "https://Stackoverflow.com/users/14558", "pm_score": 3, "selected": true, "text": "cat ~/.ssh/authorized_keys ~/.profile --enable-logging #define ALLOWLOGFILECHANGES ^[[?46h Start logging\n^[[?46l Stop logging\n^[]46;filename\\007 Change log file to `filename`\n Xterm.log.hostname.yyyy.mm.dd.hh.mm.ss.XXXXXX" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14028/" ]
184,857
<p>I need to be able to receive a fax in a java application. I was wondering what are some ways of doing this. Efax? Use a fax to email provider?</p>
[ { "answer_id": 5226127, "author": "Adam M", "author_id": 625338, "author_profile": "https://Stackoverflow.com/users/625338", "pm_score": 0, "selected": false, "text": "GetList parameters = new GetList(TestConstants.USERNAME,\n TestConstants.PASSWORD,\n ListType.AllMessages, // Select the type of list you wish to return\n 10, // max items\n new MessageItem[0]\n );\n GetImageChunk parameters = new GetImageChunk(TestConstants.USERNAME,\n TestConstants.PASSWORD,\n MESSAGE_ID,\n MARK_AS_READ,\n CHUNK_SIZE,\n from,\n new byte[0]\n );\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5569/" ]
184,858
<p>I want to make a link call a Javascript function through the onclick event and not do anything else (follow the link). What is the best way to do that? I usually do this:</p> <pre><code>&lt;a href="#" onclick="foo()"&gt;Click&lt;/a&gt; </code></pre> <p>But I'm not sure that is the best way and in this case it is navigating to page.html# which isn't good for what I'm doing. </p>
[ { "answer_id": 184876, "author": "Chris Cudmore", "author_id": 18907, "author_profile": "https://Stackoverflow.com/users/18907", "pm_score": 0, "selected": false, "text": "<a href=\"javascript: foo()\" >Click</a>\n" }, { "answer_id": 184877, "author": "Avdi", "author_id": 20487, "author_profile": "https://Stackoverflow.com/users/20487", "pm_score": 3, "selected": false, "text": "false foo() function foo() {\n // ... do stuff\n return false;\n}\n <a href=\"#\" onclick=\"return foo()\">Click</a>\n <a href=\"#\" onclick=\"foo(); return false;\">Click</a>\n" }, { "answer_id": 184884, "author": "Rob Drimmie", "author_id": 24213, "author_profile": "https://Stackoverflow.com/users/24213", "pm_score": -1, "selected": false, "text": "return false;\n <a href=\"#\" onclick=\"foo();return false;\">Click</a>\n function foo() {\n // other stuff\n return false;\n}\n" }, { "answer_id": 184891, "author": "Matt Brunell", "author_id": 24970, "author_profile": "https://Stackoverflow.com/users/24970", "pm_score": -1, "selected": false, "text": "\n <a href=\"javascript:foo()\">Click</a>\n" }, { "answer_id": 184902, "author": "swilliams", "author_id": 736, "author_profile": "https://Stackoverflow.com/users/736", "pm_score": 2, "selected": false, "text": "href=\"#\" <a href=\"javascript:foo()\">clicky</a>\n <a id=\"foo\" href=\"#\">clicky</a>\n\n$('foo').observe('click', function(evt) { \n foo();\n evt.stop(); // keeps it from navigating to the href url\n}); \n" }, { "answer_id": 184908, "author": "Tom", "author_id": 20, "author_profile": "https://Stackoverflow.com/users/20", "pm_score": 2, "selected": false, "text": "window.onload = {\n var myLink = document.getElementById('myLinkID');\n myLink.onclick = function(evt) {\n var evt = (evt) ? evt : ((event) ? event : null); // for cross-browser issues\n evt.preventDefault();\n evt.stopPropagation();\n foo();\n }\n}\n" }, { "answer_id": 184916, "author": "Andrew Moore", "author_id": 26210, "author_profile": "https://Stackoverflow.com/users/26210", "pm_score": 5, "selected": true, "text": "<a href=\"search.php\" id=\"searchLink\">Search</a>\n var link = document.getElementById('searchLink');\n\nlink.onclick = function() {\n try {\n // Do Stuff Here \n } finally {\n return false;\n }\n};\n" }, { "answer_id": 185009, "author": "roenving", "author_id": 23142, "author_profile": "https://Stackoverflow.com/users/23142", "pm_score": 0, "selected": false, "text": "<a href=\"http://en.wikipedia.org/wiki/Css\" target=\"_blank\" onclick=\"window.open(this.href,'_blank','width=600,height=450,status=no');return false;\">Show wikipedia css</a>\n" }, { "answer_id": 185020, "author": "Tivac", "author_id": 7847, "author_profile": "https://Stackoverflow.com/users/7847", "pm_score": -1, "selected": false, "text": "<a href=\"#\">Click</a> <a href=\"#MAGIC\">Click</a>" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184858", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4915/" ]
184,863
<p>To save some typing and clarify my code, is there a standard version of the following method?</p> <pre><code>public static boolean bothNullOrEqual(Object x, Object y) { return ( x == null ? y == null : x.equals(y) ); } </code></pre>
[ { "answer_id": 32725394, "author": "Sam Berry", "author_id": 1756430, "author_profile": "https://Stackoverflow.com/users/1756430", "pm_score": 3, "selected": false, "text": "Objects.equal(x, y)" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184863", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1412/" ]
184,864
<p>Has anyone had good experiences of talking direct to RPG programs running on a V5R4 iSeries machine from Java? If so, what are the recommendations of the community, and what pitfalls should I try to avoid?</p> <p>From the various pieces of literature and spike solutions I have attempted it looks as though we can use ProgramCallBeans (either through PCML or xPCML), talking to the DataQueues (for asynchronous comms), or even JNI.</p> <p>I'm looking for something that's robust, performant, quick to develop, easy to maintain, and easy to test (aren't we all!?!).</p>
[ { "answer_id": 222558, "author": "Tracy Probst", "author_id": 22770, "author_profile": "https://Stackoverflow.com/users/22770", "pm_score": 4, "selected": false, "text": "CommandCall command = new CommandCall(as400);\ncommand.run(\"CPYF FROMFILE(BLAH) TOFILE(BLAHBLAH) CRTFILE(*YES)\");\n AS400Message[] messageList = command.getMessageList();\nfor (int i=0;i < messageList.length;i++) {\nString sMessageText = messageList[i].getText();\n sMessage+=sMessageText + \"\\n\";\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26283/" ]
184,865
<p>I have an RDLC report that I'm having problems with page breaks. The report has a group that has a number of records that do not fit on one page. This report renders fine in Normal Mode, but when I switch to Print Mode, "extra" page breaks that were not there before appear. This is causing the report to print on more pages than necessary. I do not have the group set to keep on one page, and I have been playing with the values for Height and InteractiveHeight, but nothing seems to work.</p> <p>Is there any way to resolve this problem? I need this report to print out properly, and these mysterious page breaks are causing this problem. Any help or suggestions are appreciated.</p>
[ { "answer_id": 32787126, "author": "ozat", "author_id": 4871939, "author_profile": "https://Stackoverflow.com/users/4871939", "pm_score": 1, "selected": false, "text": "ConsumeContainerWhiteSpace = True" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
184,869
<p>I'm working on a database in SQL Server 2000 that uses a GUID for each user that uses the app it's tied to. Somehow, two users ended up with the same GUID. I know that microsoft uses an algorithm to generate a random GUID that has an extremely low chance of causing collisons, but is a collision still possible?</p>
[ { "answer_id": 253830, "author": "GalacticCowboy", "author_id": 29638, "author_profile": "https://Stackoverflow.com/users/29638", "pm_score": 1, "selected": false, "text": "declare @table table\n(\n column1 uniqueidentifier default (newid()),\n column2 int,\n column3 datetime default (getdate())\n)\n\ndeclare @counter int\n\nset @counter = 1\n\nwhile @counter <= 10000\nbegin\n insert into @table (column2) values (@counter)\n set @counter = @counter + 1\nend\n\nselect * from @table\n\nselect * from @table t1 join @table t2 on t1.column1 = t2.column1 and t1.column2 != t2.column2\n" }, { "answer_id": 34863312, "author": "Ken Smith", "author_id": 68231, "author_profile": "https://Stackoverflow.com/users/68231", "pm_score": 0, "selected": false, "text": "NEWID()" }, { "answer_id": 66852600, "author": "gukoff", "author_id": 2116625, "author_profile": "https://Stackoverflow.com/users/2116625", "pm_score": 2, "selected": false, "text": "from math import sqrt, log\n\ndef how_many(bits, probability):\n return 2 ** ((bits + 1) / 2) * sqrt(-log(1 - probability))\n In [2]: how_many(bits=128, probability=0.01)\nOut[2]: 2.6153210405530885e+18\n In [3]: how_many(bits=128, probability=0.9999)\nOut[3]: 7.91721721556706e+19\n In [4]: how_many(bits=64, probability=0.01)\nOut[4]: 608926881\n\nIn [5]: how_many(bits=64, probability=0.9999)\nOut[5]: 18433707802\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2147/" ]
184,871
<p>I just want to enable or disable the button inside a ControlTemplate for a WPF Editor that I'm using.</p>
[ { "answer_id": 184963, "author": "Joel B Fant", "author_id": 22211, "author_profile": "https://Stackoverflow.com/users/22211", "pm_score": 2, "selected": false, "text": "ControlTemplate Enabled Button" }, { "answer_id": 7016854, "author": "Jerry Nixon", "author_id": 265706, "author_profile": "https://Stackoverflow.com/users/265706", "pm_score": 2, "selected": false, "text": "<Window.CommandBindings>\n <CommandBinding \n Command=\"{x:Static local:MyCommands.MyCommand}\"\n Executed=\"CommandBinding_Executed\"\n CanExecute=\"CommandBinding_CanExecute\" />\n</Window.CommandBindings>\n\n<Window.Resources>\n <ControlTemplate x:Key=\"MyTemplate\" TargetType=\"Label\">\n <Button Command=\"{x:Static local:MyCommands.MyCommand}\">\n <TextBlock>\n Click Me\n <TextBlock Text=\"{TemplateBinding Content}\" />\n </TextBlock>\n </Button>\n </ControlTemplate>\n</Window.Resources>\n\n<StackPanel>\n <Label Template=\"{StaticResource MyTemplate}\">1</Label>\n <Label Template=\"{StaticResource MyTemplate}\">2</Label>\n <Label Template=\"{StaticResource MyTemplate}\">3</Label>\n <Label Template=\"{StaticResource MyTemplate}\">4</Label>\n <Label Template=\"{StaticResource MyTemplate}\">5</Label>\n</StackPanel>\n public partial class MainWindow : Window\n{\n public MainWindow()\n {\n InitializeComponent();\n }\n\n private void CommandBinding_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)\n {\n // your logic here\n int _Integer = -1;\n int.TryParse(e.Parameter.ToString(), out _Integer);\n e.CanExecute = _Integer % 2 == 0;\n }\n\n private void CommandBinding_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)\n {\n // do something when clicked\n }\n}\n\npublic static class MyCommands\n{\n public static RoutedUICommand MyCommand = new RoutedUICommand();\n}\n" }, { "answer_id": 9840044, "author": "Dead.Rabit", "author_id": 424963, "author_profile": "https://Stackoverflow.com/users/424963", "pm_score": 0, "selected": false, "text": "hourHand = this.Template.FindName( \"PART_HourHand\", this ) as Rectangle;\n ...TemplateCommandStore public class BookingDetailsTemplateCommandStore\n{\n public OpenWindowCommand_Command OpenWindowCommand_Command { get; set; }\n\n public BookingDetailsTemplateCommandStore()\n {\n OpenWindowCommand_Command = new OpenWindowCommand_Command( this );\n } \n}\n <DataTemplate DataType=\"{x:Type LeisureServices:BookingSummary}\">\n <Border Height=\"50\" otherStyling=\"xyz\">\n <Border.Resources>\n <local:BookingDetailsTemplateCommandStore x:Key=\"CommandStore\" />\n </Border.Resources>\n <DockPanel>\n <Button otherStyling=\"xyz\"\n Command=\"{Binding Source={StaticResource CommandStore},\n Path=OpenWindowCommand_Command}\" />\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3047/" ]
184,927
<p>I have a webapp which resizes its window to exactly fit its contents:</p> <pre><code>window.resizeTo(200,300) </code></pre> <p>People do like having the page fit its window in this way. However with Firefox the next browser window the user opens comes up at the same size, which is ridiculously small.</p> <p>Is there a way to tell Firefox to resize the current window, but not change its notion of how large subsequent windows should be?</p>
[ { "answer_id": 184964, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 2, "selected": false, "text": "window.open" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4761/" ]
184,970
<p>I am using partial classes to split some functionality between 2 files, but I am getting an error. What am I doing wrong?</p> <p>A1.cs:</p> <pre><code>private partial class A { private string SomeProperty { get { return "SomeGeneratedString"; } } } </code></pre> <p>A2.cs:</p> <pre><code>private partial class A { void SomeFunction() { //trying to access this.SomeProperty produces the following compiler error, at least with C# 2.0 //error CS0117: 'A' does not contain a definition for 'SomeProperty' } } </code></pre>
[ { "answer_id": 185055, "author": "Troy Howard", "author_id": 19258, "author_profile": "https://Stackoverflow.com/users/19258", "pm_score": 3, "selected": false, "text": "namespace stackoverflow.answers\n{\n public class Foo\n {\n private partial class Bar\n {\n private string SomeProperty { get { return \"SomeGeneratedString\"; } }\n }\n }\n}\n namespace stackoverflow.answers\n{\n partial class Bar\n {\n void SomeFunction()\n {\n string bar = this.SomeProperty;\n }\n } \n}\n" }, { "answer_id": 51361703, "author": "Vic Seedoubleyew", "author_id": 2873507, "author_profile": "https://Stackoverflow.com/users/2873507", "pm_score": 0, "selected": false, "text": ".csproj <ClassNamespace> <Content Include=\"MyTemplate.tt\">\n <Generator>TextTemplatingFilePreprocessor</Generator>\n <ClassNamespace>My.Namespace</ClassNamespace>\n <LastGenOutput>MyTemplate.cs</LastGenOutput>\n</Content>\n" }, { "answer_id": 70267521, "author": "ΩmegaMan", "author_id": 285795, "author_profile": "https://Stackoverflow.com/users/285795", "pm_score": 0, "selected": false, "text": "O namespace StackOverflow {\npublic partial class MyVM\n namespace Stackoverflow {\npublic partial class MyVM\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184970", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4066/" ]
184,983
<p>I need to take a BufferedImage and convert it to YCbCr format so that I can do a more efficient Brightness/contrast manipulation on it, but I can't figure out how to do this. I've tried ColorConvertOp but there doesn't seem to be an appropriate ColorSpace for YCbCr (though there is a type for it?). </p> <p>I could do the conversion manually (the conversion is not difficult) but this would immediately kick my image out of the 'fast-path'. Does anyone know a solution?</p>
[ { "answer_id": 185055, "author": "Troy Howard", "author_id": 19258, "author_profile": "https://Stackoverflow.com/users/19258", "pm_score": 3, "selected": false, "text": "namespace stackoverflow.answers\n{\n public class Foo\n {\n private partial class Bar\n {\n private string SomeProperty { get { return \"SomeGeneratedString\"; } }\n }\n }\n}\n namespace stackoverflow.answers\n{\n partial class Bar\n {\n void SomeFunction()\n {\n string bar = this.SomeProperty;\n }\n } \n}\n" }, { "answer_id": 51361703, "author": "Vic Seedoubleyew", "author_id": 2873507, "author_profile": "https://Stackoverflow.com/users/2873507", "pm_score": 0, "selected": false, "text": ".csproj <ClassNamespace> <Content Include=\"MyTemplate.tt\">\n <Generator>TextTemplatingFilePreprocessor</Generator>\n <ClassNamespace>My.Namespace</ClassNamespace>\n <LastGenOutput>MyTemplate.cs</LastGenOutput>\n</Content>\n" }, { "answer_id": 70267521, "author": "ΩmegaMan", "author_id": 285795, "author_profile": "https://Stackoverflow.com/users/285795", "pm_score": 0, "selected": false, "text": "O namespace StackOverflow {\npublic partial class MyVM\n namespace Stackoverflow {\npublic partial class MyVM\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25920/" ]
184,985
<p>I seem to be having an issue with iPhone SDK 2.1 in as far as being able to establish a relationship between a ViewController and a View window. In as far as a Cocoa Touch Class, I went forward and added a <code>UIViewController</code> subclass. I made sure that the target is part of the existing project. Right afterwards I added a User Interfaces -> View XIB. Within the <code>UIViewController</code> I have some straight forward code I literally copy/pasted from sample code elsewhere:</p> <p>EditViewController.h:</p> <pre><code>@interface EditorViewController : UIViewController &lt;UITextFieldDelegate&gt; { UITextField *field; } @property(nonatomic, retain) IBOutlet UITextField *field; @end </code></pre> <p>EditViewController.m</p> <pre><code>#import "EditorViewController.h" @implementation EditorViewController - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)dealloc { [super dealloc]; } @end </code></pre> <p>As you can tell, it doesn't do much. Now when I click my new xib, and reference a class identity with <code>EditorViewController</code>, no auto complete happens, which to me implies that it has no such awareness of a <code>EditorViewClass</code>. When I attempt to control+click from the view to File's Owners, I get nada.</p> <p>What are some of the possible idiosyncrasies in this process that I'm overlooking that's not allowing me to outlet my view to a controller?</p> <p>How would I also ensure that my User Interface View XIB is associated with the project besides seeing the project name checked off as a Target?</p>
[ { "answer_id": 185055, "author": "Troy Howard", "author_id": 19258, "author_profile": "https://Stackoverflow.com/users/19258", "pm_score": 3, "selected": false, "text": "namespace stackoverflow.answers\n{\n public class Foo\n {\n private partial class Bar\n {\n private string SomeProperty { get { return \"SomeGeneratedString\"; } }\n }\n }\n}\n namespace stackoverflow.answers\n{\n partial class Bar\n {\n void SomeFunction()\n {\n string bar = this.SomeProperty;\n }\n } \n}\n" }, { "answer_id": 51361703, "author": "Vic Seedoubleyew", "author_id": 2873507, "author_profile": "https://Stackoverflow.com/users/2873507", "pm_score": 0, "selected": false, "text": ".csproj <ClassNamespace> <Content Include=\"MyTemplate.tt\">\n <Generator>TextTemplatingFilePreprocessor</Generator>\n <ClassNamespace>My.Namespace</ClassNamespace>\n <LastGenOutput>MyTemplate.cs</LastGenOutput>\n</Content>\n" }, { "answer_id": 70267521, "author": "ΩmegaMan", "author_id": 285795, "author_profile": "https://Stackoverflow.com/users/285795", "pm_score": 0, "selected": false, "text": "O namespace StackOverflow {\npublic partial class MyVM\n namespace Stackoverflow {\npublic partial class MyVM\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/184985", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
185,004
<p>I just noticed that java.beans.Introspector getBeanInfo does not pickup any superinterface's properties. Example:</p> <pre><code>public interface Person { String getName(); } public interface Employee extends Person { int getSalary(); } </code></pre> <p>Introspecting on Employee only yields salary even though name is inherited from Person.</p> <p>Why is this? I would rather not have to use reflection to get all the getters.</p>
[ { "answer_id": 185959, "author": "MetroidFan2002", "author_id": 8026, "author_profile": "https://Stackoverflow.com/users/8026", "pm_score": 1, "selected": false, "text": "public static BeanInfo getBeanInfo(Class<?> beanClass, Introspector.USE_ALL_BEANINFO);\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24396/" ]
185,034
<p>Is there a way to test the type of an element in JavaScript? </p> <p>The answer may or may not require the prototype library, however the following setup does make use of the library.</p> <pre><code>function(event) { var element = event.element(); // if the element is an anchor ... // if the element is a td ... } </code></pre>
[ { "answer_id": 185039, "author": "bobwienholt", "author_id": 24257, "author_profile": "https://Stackoverflow.com/users/24257", "pm_score": 6, "selected": false, "text": "if (element.nodeName == \"A\") {\n ...\n} else if (element.nodeName == \"TD\") {\n ...\n}\n" }, { "answer_id": 185046, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 8, "selected": true, "text": "typeof(N) elem.tagName elem.nodeName" }, { "answer_id": 185092, "author": "roenving", "author_id": 23142, "author_profile": "https://Stackoverflow.com/users/23142", "pm_score": 4, "selected": false, "text": "if(element.nodeType == 1){//element of type html-object/tag\n if(element.tagName==\"a\"){\n //this is an a-element\n }\n if(element.tagName==\"div\"){\n //this is a div-element\n }\n}\n" }, { "answer_id": 34826843, "author": "nicolsondsouza", "author_id": 2176723, "author_profile": "https://Stackoverflow.com/users/2176723", "pm_score": 0, "selected": false, "text": "Element.prototype.typeof = \"element\";\nvar element = document.body; // any dom element\nif (element && element.typeof == \"element\"){\n return true; \n // this is a dom element\n}\nelse{\n return false; \n // this isn't a dom element\n}" }, { "answer_id": 44747913, "author": "Herbertusz", "author_id": 1814837, "author_profile": "https://Stackoverflow.com/users/1814837", "pm_score": 2, "selected": false, "text": "var a = document.querySelector('a');\n\nvar img = document.createElement('img');\n\ndocument.body.innerHTML += '<div id=\"newthing\"></div>';\nvar div = document.getElementById('newthing');\n\nObject.prototype.toString.call(a); // \"[object HTMLAnchorElement]\"\nObject.prototype.toString.call(img); // \"[object HTMLImageElement]\"\nObject.prototype.toString.call(div); // \"[object HTMLDivElement]\"\n Object.prototype.toString.call(...).split(' ')[1].slice(0, -1);\n" }, { "answer_id": 50972410, "author": "Vignesh Raja", "author_id": 4593057, "author_profile": "https://Stackoverflow.com/users/4593057", "pm_score": 2, "selected": false, "text": "console.log(document.querySelector(\"#anchorelem\") instanceof HTMLAnchorElement);\nconsole.log(document.querySelector(\"#divelem\") instanceof HTMLDivElement);\nconsole.log(document.querySelector(\"#buttonelem\") instanceof HTMLButtonElement);\nconsole.log(document.querySelector(\"#inputelem\") instanceof HTMLInputElement); <a id=\"anchorelem\" href=\"\">Anchor element</a>\n<div id=\"divelem\">Div Element</div>\n<button id=\"buttonelem\">Button Element</button>\n<br><input id=\"inputelem\"> elem instanceof HTMLAnchorElement elem.constructor.name == \"HTMLAnchorElement\" true" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4682/" ]
185,042
<p><strong>Environment:</strong><br/> Windows Server 2003 R2 Enterprise 64bit, SP2<br/> .NET framework is supposedly installed (2.0 SP2, 3.0 SP2, 3.5 SP1)</p> <p>I say "supposedly" because they are listed as installed under Add/Remove programs. I'm not sure it's <em>properly</em> installed, because the "ASP.NET" tab isn't added to any of the sites in IIS.</p> <p>In the IIS Web Service Extensions section, I have both "ASP.NET v2.0.50727" (Allowed), and "ASP.NET v2.0.50727 (32-bit)" (Prohibited).</p> <p>The site in question has script-execute enabled.</p> <p><strong>Problem:</strong></p> <p>I created a super-simple ASP.NET/C# website: Default.aspx with a label id="Label1", and a code-behind with: <code>Label1.text = "Hello World";</code> and the error I'm getting is:</p> <blockquote> <p>%1 is not a valid Win32 application.</p> </blockquote>
[ { "answer_id": 185056, "author": "JamesSugrue", "author_id": 1075, "author_profile": "https://Stackoverflow.com/users/1075", "pm_score": 4, "selected": true, "text": "aspnet_regiis -i\n" }, { "answer_id": 14991957, "author": "Tom Kelly TAK", "author_id": 2093432, "author_profile": "https://Stackoverflow.com/users/2093432", "pm_score": 2, "selected": false, "text": "%PYTHON_HOME%;\n%PYTHON_HOME%\\Scripts;\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/751/" ]
185,043
<p>In emacs there is a handy way to launch the gdb and gui options for gdb, the C debugger.</p> <p>Is there a similar option in gvim?</p>
[ { "answer_id": 185295, "author": "bog", "author_id": 20909, "author_profile": "https://Stackoverflow.com/users/20909", "pm_score": -1, "selected": false, "text": "!gdb blah blah blah\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185043", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9628/" ]
185,072
<p>I took the plunge this afternoon and began studying LINQ, so far just mucking around with LINQ on collections. One of the first things I tried was to implement QSort.</p> <p>Now -- ignoring the fact that I <em>could</em> just use an ORDERBY and that this is a very silly qsort implementation -- what I came up with was this:</p> <pre><code>public class lqsort { public static List&lt;int&gt; QSLinq(List&lt;int&gt; _items) { if (_items.Count &lt;= 1) return _items; int _pivot = _items[0]; List&lt;int&gt; _less = (from _item in _items where _item &lt; _pivot select _item).ToList(); List&lt;int&gt; _same = (from _item in _items where _item == _pivot select _item).ToList(); List&lt;int&gt; _greater = (from _item in _items where _item &gt; _pivot select _item).ToList(); return (QSLinq(_less).Concat(_same.Concat(QSLinq(_greater)))).ToList(); } } </code></pre> <p>The only thing that really bugs me is all of the casting involved. Are there any LINQ tricks I might use? Or am I just using LINQ for things it wasn't intended for?</p>
[ { "answer_id": 185128, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 2, "selected": false, "text": "public static IEnumerable<int> QSLinq(IEnumerable<int> items)\n{\n if (items.Count() <= 1)\n return items;\n\n int pivot = items.First();\n\n return QSLinq(items.Where(i => i < pivot))\n .Concat(items.Where(i => i == pivot))\n .Concat(QSLinq(items.Where(i => i > pivot)));\n}\n" }, { "answer_id": 185146, "author": "Alfred B. Thordarson", "author_id": 3379, "author_profile": "https://Stackoverflow.com/users/3379", "pm_score": 4, "selected": true, "text": "IEnumerable var List<int> QSLinq int[] List<int> public static IEnumerable<int> QSLinq(IEnumerable<int> _items)\n {\n if (_items.Count() <= 1)\n return _items;\n\n var _pivot = _items.First();\n\n var _less = from _item in _items where _item < _pivot select _item;\n var _same = from _item in _items where _item == _pivot select _item;\n var _greater = from _item in _items where _item > _pivot select _item;\n\n return QSLinq(_less).Concat(QSLinq(_same)).Concat(QSLinq(_greater));\n }\n" }, { "answer_id": 185656, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 3, "selected": false, "text": " public static IEnumerable<int> QSort2(IEnumerable<int> source)\n {\n if (!source.Any())\n return source;\n int first = source.First();\n return source\n .GroupBy(i => i.CompareTo(first))\n .OrderBy(g => g.Key)\n .SelectMany(g => g.Key == 0 ? g : QSort2(g));\n }\n IEnumerable<int> source = Enumerable.Range(0, 1000).Reverse().ToList();\n" }, { "answer_id": 185769, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 2, "selected": false, "text": " public static IEnumerable<int> QSort3(IEnumerable<int> source)\n {\n if (!source.Any())\n return source;\n int first = source.First();\n\n QSort3Helper myHelper = \n source.GroupBy(i => i.CompareTo(first))\n .Aggregate(new QSort3Helper(), (a, g) =>\n {\n if (g.Key == 0)\n a.Same = g;\n else if (g.Key == -1)\n a.Less = g;\n else if (g.Key == 1)\n a.More = g;\n return a;\n });\n IEnumerable<int> myResult = Enumerable.Empty<int>();\n if (myHelper.Less != null)\n myResult = myResult.Concat(QSort3(myHelper.Less));\n if (myHelper.Same != null)\n myResult = myResult.Concat(myHelper.Same);\n if (myHelper.More != null)\n myResult = myResult.Concat(QSort3(myHelper.More));\n\n return myResult;\n }\n\n public class QSort3Helper\n {\n public IEnumerable<int> Less;\n public IEnumerable<int> Same;\n public IEnumerable<int> More;\n }\n" }, { "answer_id": 48954500, "author": "fartwhif", "author_id": 6620171, "author_profile": "https://Stackoverflow.com/users/6620171", "pm_score": 0, "selected": false, "text": "private static List<int> quickie7(List<int> ites)\n{\n if (ites.Count <= 1)\n return ites;\n var piv = ites[0];\n List<int> les = new List<int>();\n List<int> sam = new List<int>();\n List<int> mor = new List<int>();\n Enumerable.Range(0, 3).AsParallel().ForAll(i =>\n {\n switch (i)\n {\n case 0: les = (from _item in ites where _item < piv select _item).ToList(); break;\n case 1: sam = (from _item in ites where _item == piv select _item).ToList(); break;\n case 2: mor = (from _item in ites where _item > piv select _item).ToList(); break;\n }\n });\n var _les = new List<int>();\n var _mor = new List<int>();\n Enumerable.Range(0, 2).AsParallel().ForAll(i =>\n {\n switch (i)\n {\n case 0: _les = quickie7(les); break;\n case 1: _mor = quickie7(mor); break;\n }\n });\n List<int> allofem = new List<int>();\n allofem.AddRange(_les);\n allofem.AddRange(sam);\n allofem.AddRange(_mor);\n return allofem;\n}\n public static IEnumerable<int> QSLinq3(IEnumerable<int> _items)\n{\n if (_items.Count() <= 1)\n return _items;\n var _pivot = _items.First();\n IEnumerable<int> _less = null;\n IEnumerable<int> _same = null;\n IEnumerable<int> _greater = null;\n ConcurrentBag<ManualResetEvent> finishes = new ConcurrentBag<ManualResetEvent>();\n Enumerable.Range(0, 3).AsParallel().ForAll(i =>\n {\n var fin = new ManualResetEvent(false);\n finishes.Add(fin);\n (new Thread(new ThreadStart(() =>\n {\n if (i == 0)\n _less = from _item in _items where _item < _pivot select _item;\n else if (i == 1)\n _same = from _item in _items where _item == _pivot select _item;\n else if (i == 2)\n _greater = from _item in _items where _item > _pivot select _item;\n fin.Set();\n }))).Start();\n });\n finishes.ToList().ForEach(k => k.WaitOne());\n return QSLinq(_less).Concat(_same).Concat(QSLinq(_greater));\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185072", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7856/" ]
185,073
<p>I'm trying to call into a C++ library from Perl on an AIX 5.1 machine. I've created a very simple test project to try to exercise this.</p> <p>My C++ shared library (<code>test.cpp</code>):</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;iostream&gt; void myfunc() { printf("in myfunc()\n"); std::cout &lt;&lt; "in myfunc() also" &lt;&lt; std::endl; } </code></pre> <p>My SWIG interface file (<code>test.i</code>):</p> <pre><code>%module test %{ void myfunc(); %} void myfunc(); </code></pre> <p>I then build the shared object like so:</p> <pre><code>swig -c++ -perl test.i g++ -c test_wrap.cxx -I/usr/opt/perl5/lib/5.6.0/aix/CORE -o test_wrap.o g++ -c test.cpp -o test.o ld -G -bI:/usr/opt/perl5/lib/5.6.0/aix/CORE/perl.exp -bnoentry -bexpall -lc_r test.o test_wrap.o -o test.so </code></pre> <p>At this point, I have a <code>test.so</code> shared object that should be loadable in perl (via the SWIG generated <code>test.pm</code>). I have a very simple perl script to try to load the shared object and call the one function that I am exporting (<code>test.pl</code>):</p> <pre><code>#!/usr/bin/perl use test; test::myfunc(); </code></pre> <p>When I run <code>test.pl</code>, I get the following output:</p> <blockquote> <p>in myfunc()<br> Illegal instruction (core dumped)</p> </blockquote> <p>If I comment-out the <code>std::cout</code> usage in <code>myfunc</code>, it works without problem. It appears as though using anything in the C++ STL causes a core dump (I tried just declaring a <code>std::vector</code> and <code>std::stringstream</code>, both result in the core dump). I can create a standalone C++ executable that uses the STL without any issues, it's only when called in my shared object when loaded from perl that I get into trouble.</p> <p>I've also tried using xlc rather than gcc, but I get the same result. I'm thinking there is some funky linker flag that I need to pass in to ensure that all of the linkage occurs correctly? Any ideas are welcome...</p> <p>Edit: If I link using <code>gcc</code>/<code>xlc</code> instead of invoking the linker directly (<code>ld</code>), I immediately get a segmentation fault. It looks like it crashes when perl is trying to simply load the shared library. Calling <code>ld</code> as I have above is the closest that I've got it to working, but I think I may be missing some libraries or special AIX linker flags for the C++ libraries.</p> <p>Edit2: Ok, I've got it working. AIX is very fragile when it comes to linking. I ultimately came up with the following link command that seems to be working correctly:</p> <pre><code>ld -G -bI:/usr/opt/perl5/lib/5.6.0/aix/CORE/perl.exp -bnoentry -bexpall -lC -lc -ldl test.o test_wrap.o -o test.so </code></pre> <p>The libraries that I linked against are the most relevant. It turns out that the order in which the libraries are mentioned is very important also (ugh). Also note that this is being built against Perl 5.6.0 that ships with AIX 5.1. I've tried building this same simple application against Perl 5.8.8 and it doesn't work. However, I'm pretty sure the much more sane method of linking (using straight <code>gcc</code>/<code>xlc</code> instead of having to call <code>ld</code> directly) seems to work better. So this issue appears to be a bug in the Perl distribution or the linker or something.</p> <p>Hopefully this will help some poor soul cursed with having to work with AIX...</p>
[ { "answer_id": 185118, "author": "Tanktalus", "author_id": 23512, "author_profile": "https://Stackoverflow.com/users/23512", "pm_score": 2, "selected": false, "text": "-lstdc++ gcc -g -lstdc++ -shared test*.o -o test.so\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26302/" ]
185,082
<p>I would like to be able to spawn a linux process that would only have access to stdin, stdout, and stderr (nothing more and nothing less). Can I do this at the process level itself? I am also implicitly stating (oxymoron) that I don't want the spawned process to be able to change the "thing" that the other end of the stream points to. </p> <p>Metaphorically:</p> <ul> <li>the process has a input pipe that comes from somewhere, it cannot change where the pipe starts from, so it cannot control where input comes from.</li> <li>the process has output and error pipes that go somewhere, it cannot change where the other end of the output pipes point to, so it cannot control where output goes to.</li> <li>it cannot create any new pipes.</li> </ul> <p>I am also currently looking at SElinux. Would this allow me to create a process that only had access to these three streams? Thank you.</p>
[ { "answer_id": 185568, "author": "ephemient", "author_id": 20713, "author_profile": "https://Stackoverflow.com/users/20713", "pm_score": 1, "selected": false, "text": "ptrace strace" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185082", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21317/" ]
185,083
<p>I was wondering if its possible to inject a thread into a remote app domain running in a separate process. </p> <p>My guess is that I could do this using the debugging interfaces (ICorDebug) but I was wondering if there is any other way? </p>
[ { "answer_id": 189039, "author": "Ghirai", "author_id": 570, "author_profile": "https://Stackoverflow.com/users/570", "pm_score": 0, "selected": false, "text": "SetThreadContext" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17174/" ]
185,091
<p>I got a very similar error to the one below:</p> <p><a href="https://stackoverflow.com/questions/97800/how-can-i-fix-this-delphi-7-compile-error-duplicate-resources">How can I fix this delphi 7 compile error - &quot;Duplicate resource(s)&quot;</a></p> <p>However, the error I got is this:</p> <pre><code> [Error] WARNING. Duplicate resource(s): [Error] Type 10 (RCDATA), ID TFMMAINTQUOTE: [Error] File P:\[PATH SNIPPED]\Manufacturing.RES resource kept; file FMaintQuote.DFM resource discarded. </code></pre> <p>Manufacturing.res is the default resource file (application is called Manufacturing.exe), and FMainQuote is one of the forms. .dfm files are plain text files, so I'm not sure what resources is being duplicated, how to find it and fix it?</p> <p>If I tried to compile the project again, it works OK, but the exe's icon is different to the one I've set in Project Options using the "Load Icon" button. The icon on the app is some sort of bell image that I don't recognize.</p>
[ { "answer_id": 844181, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "{$R *.res} program Test;\n\nuses\n Forms,\n Unit1 in 'Unit1.pas' {Form1},\n Sample in 'Sample.pas',\n Proc in 'Proc.pas';\n\n{$R *.res} //<----delete this if you put them in the Unt1.pas. ok.\n\nbegin\n Application.Initialize;\n Application.CreateForm(TForm1, Form1);\n Application.Run;\nend.\n" }, { "answer_id": 5051631, "author": "Pekka Puhakka", "author_id": 624467, "author_profile": "https://Stackoverflow.com/users/624467", "pm_score": 1, "selected": false, "text": "File D:\\DELPHI\\DBISAM\\db324d6d.res resource kept; file \n D:\\DELPHI\\DBISAM\\db324d6d.res resource discarded.\nType 14 (ICON GROUP), ID MAINICON:\n package db324d6d;\n{$R *.res}\n{$R 'db324d6d.res'}\n...\n package db324d6d;\n{$R *.res}\n...\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185091", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26305/" ]
185,094
<p>I'm fairly new to MVC coming from a php background where I designed by view and created pages when I needed something like say a login form. I'd have a file called login. This only sucked when I needed a new login form to login a different type of user. Say an admin. I'd then have to create a new page called login-admin.php or something of that nature.</p> <p>Recently I began to explore MVC and particularly frameworks and the biggest problem I am having is determining how exactly you come up with your controllers. I've been told to either go the one controller per view file route, or get your controllers based upon your domain objects.</p> <p>I understand I can have a user controller and a lot of methods to manipulate that object say user/add, user/edit, user/delete, user/profile. But in this instance it seems that once you need views that don't necessarily fit within a "domain object" that it's hard to decide where to stick them.</p> <p>So, what is the best practice when determining what your controllers will be???</p>
[ { "answer_id": 185133, "author": "dbr", "author_id": 745, "author_profile": "https://Stackoverflow.com/users/745", "pm_score": 2, "selected": false, "text": "controller = mysection method = view id = 2 map.connect ':controller/:action/:id' @myuser = User.find(id) /usercontroller/new /usercontroller/edit /usercontroller/view" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
185,101
<p>I have an XSL stylesheet with content in an <code>xsl:text</code> node like this:</p> <pre><code>&lt;xsl:text&gt; foo bar baz &lt;/xsl:text&gt; </code></pre> <p>The stylesheet itself is a text file with "unix-style" newline line terminators. I invoke this stylesheet on Windows as well as unix-like platforms. It would be nice to have the output conform to the conventions of the platform on which it is invoked.</p> <p>When I run this stylesheet on Windows, the output has carriage return/newline pairs for everything <em>except</em> the contents of the <code>xsl:text</code> node.</p> <p><strong>Can I instruct the XSLT processor to translate the newline characters in the content of the <code>xsl:text</code> node into platform specific end-of-lines?</strong></p> <p>More context: I'm invoking the stylesheet from the <a href="http://ant.apache.org/manual/Tasks/style.html" rel="noreferrer">Apache Ant 1.7.1 XSLT task</a> like this:</p> <pre><code>&lt;xslt in="in.xml" out="out.xml" style="stylesheet.xsl"/&gt; </code></pre> <p>The stylesheet header currently looks like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" exclude-result-prefixes="xalan"&gt; &lt;!-- contents elided --&gt; &lt;/xsl:stylesheet&gt; </code></pre>
[ { "answer_id": 185231, "author": "Jen A", "author_id": 12979, "author_profile": "https://Stackoverflow.com/users/12979", "pm_score": 1, "selected": false, "text": "&#xD; &#xA; &#xA; <xsl:text>foo&#xD;&#xa;bar&#xD;&#xa;</xsl:text>" }, { "answer_id": 187729, "author": "Adam Crume", "author_id": 25498, "author_profile": "https://Stackoverflow.com/users/25498", "pm_score": 3, "selected": false, "text": "<xsl:param name=\"br\">\n <xsl:text>&#10;</xsl:text>\n</xsl:param>\n <xsl:copy-of select=\"$br\"/>\n" }, { "answer_id": 191983, "author": "Mads Hansen", "author_id": 14419, "author_profile": "https://Stackoverflow.com/users/14419", "pm_score": 2, "selected": false, "text": " <condition property=\"linebreak\" value=\"&#xD;&#xa;\">\n <os family=\"windows\"/>\n </condition>\n <condition property=\"linebreak\" value=\"&#xa;\">\n <os family=\"unix\"/>\n </condition>\n <xslt in=\"data.xml\" out=\"${out.dir}/out.xml\">\n <param name=\"linebreak\" expression=\"${linebreak}\" />\n </xslt>\n" }, { "answer_id": 5824987, "author": "granadaCoder", "author_id": 214977, "author_profile": "https://Stackoverflow.com/users/214977", "pm_score": 0, "selected": false, "text": "<xsl:param name=\"br\">\n <xsl:text>&#xD;&#xa;</xsl:text>\n</xsl:param>\n <xsl:value-of select=\"$br\" />\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n <!--<xsl:strip-space elements=\"*\" />-->\n <xsl:output method=\"text\" />\n <!-- <xsl:preserve-space elements=\"*\"/>-->\n<xsl:param name=\"br\">\n <xsl:text>&#xD;&#xa;</xsl:text>\n</xsl:param>\n\n\n <!-- -->\n <xsl:template match=\"/\">\n\n\n <xsl:for-each select=\"//root/Item\">\n\n <xsl:value-of select=\"@Name\" /> <!-- Your xpath will vary of course! -->\n <xsl:value-of select=\"$br\" />\n\n </xsl:for-each>\n\n</xsl:template>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13940/" ]
185,110
<p>Can you please let me know the SQL to split date ranges when they overlap?</p> <p>Data (sample data with a date range and possibly other columns):</p> <pre><code> Col1 FromDate ToDate 1. 1 1/1/2008 31/12/2010 2. 1 1/1/2009 31/12/2012 3. 1 1/1/2009 31/12/2014 </code></pre> <p>Output:</p> <pre><code> Col1 From Date ToDate 1. 1 1/1/2008 31/12/2008 (from row 1 above) 2. 1 1/1/2009 31/12/2010 (from rows 1,2 and 3 above) 3. 1 1/1/2011 31/12/2012 (from rows 2 and 3 above) 4. 1 1/1/2013 31/12/2014 (from row 3 above) </code></pre>
[ { "answer_id": 185305, "author": "Sklivvz", "author_id": 7028, "author_profile": "https://Stackoverflow.com/users/7028", "pm_score": 3, "selected": false, "text": "SQL query: SELECT * FROM `test` LIMIT 0, 30 ;\nRows: 3\nstart end\n2008-01-01 2010-12-31\n2009-01-01 2012-12-31\n2009-01-01 2014-12-31\n SELECT \n `start` , min( `end` )\nFROM (\n SELECT t1.start, t2.end\n FROM test t1, test t2\n WHERE t1.start < t2.end\n UNION\n SELECT t1.end + INTERVAL 1 DAY , t2.end\n FROM test t1, test t2\n WHERE t1.end + INTERVAL 1 DAY < t2.end\n UNION\n SELECT t1.start, t2.start - INTERVAL 1 DAY\n FROM test t1, test t2\n WHERE t1.start < t2.start - INTERVAL 1 DAY\n) allRanges\nGROUP BY `start`\n start min( `end` )\n2008-01-01 2008-12-31\n2009-01-01 2010-12-31\n2011-01-01 2012-12-31\n2013-01-01 2014-12-31\n" }, { "answer_id": 185871, "author": "Even Mien", "author_id": 73794, "author_profile": "https://Stackoverflow.com/users/73794", "pm_score": 2, "selected": false, "text": "DECLARE @DateTest TABLE \n(\n FromDate datetime,\n ToDate datetime \n)\n\ninsert into @DateTest (FromDate, ToDate)\n(\nselect cast('1/1/2008' as datetime), cast('12/31/2010' as datetime)\nunion\nselect cast('1/1/2009' as datetime), cast('12/31/2012' as datetime)\nunion\nselect cast('1/1/2009' as datetime), cast('12/31/2014' as datetime)\n)\n\nSELECT \n FromDate , min(ToDate)\nFROM (\n SELECT t1.FromDate, t2.ToDate\n FROM \n @DateTest t1, \n @DateTest t2\n WHERE t1.FromDate < t2.ToDate\n\n UNION\n\n SELECT dateadd(DAY, 1, t1.ToDate), t2.ToDate\n FROM \n @DateTest t1, \n @DateTest t2\n WHERE dateadd(DAY, 1, t1.ToDate) < t2.ToDate\n) allRanges\ngroup by FromDate\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26309/" ]
185,112
<p>I have a bit of html like so:</p> <pre><code>&lt;a href="#somthing" id="a1"&gt;&lt;img src="something" /&gt;&lt;/a&gt; &lt;a href="#somthing" id="a2"&gt;&lt;img src="something" /&gt;&lt;/a&gt; </code></pre> <p>I need to strip off the links so I'm just left with a couple of image tags. What would be the most efficient way to do this with jQuery?</p>
[ { "answer_id": 185140, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 4, "selected": true, "text": "$(\"a > img\").parent() // match all <a><img></a>, select <a> parents\n .each( function() // for each link\n { \n $(this).replaceWith( // replace the <a>\n $(this).children().remove() ); // with its detached children.\n });\n" }, { "answer_id": 185148, "author": "Andrew Moore", "author_id": 26210, "author_profile": "https://Stackoverflow.com/users/26210", "pm_score": 2, "selected": false, "text": "$('a[id^=a]').each(function() { $(this).replaceWith($(this).html()); });\n" }, { "answer_id": 185160, "author": "roenving", "author_id": 23142, "author_profile": "https://Stackoverflow.com/users/23142", "pm_score": 1, "selected": false, "text": "<script type=\"text/javascript\">\nwindow.onload = function(){\n var l = document.getElementsByTagName(\"a\");\n for(i=0, im=l.length; im>i; i++){\n if(l[i].firstChild.tagName == \"img\"){\n l[i].parentNode.replaceChild(l[i].firstChild,l[i]);\n }\n }\n}\n</script>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6007/" ]
185,114
<p>I have a module in the parent directory of my script and I would like to 'use' it.</p> <p>If I do</p> <pre><code>use '../Foo.pm'; </code></pre> <p>I get syntax errors.</p> <p>I tried to do:</p> <pre><code>push @INC, '..'; use EPMS; </code></pre> <p>and .. apparently doesn't show up in @INC</p> <p>I'm going crazy! What's wrong here?</p>
[ { "answer_id": 185120, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 2, "selected": false, "text": "push use use BEGIN { push @INC, \"..\"; }" }, { "answer_id": 185121, "author": "ephemient", "author_id": 20713, "author_profile": "https://Stackoverflow.com/users/20713", "pm_score": 8, "selected": true, "text": "use BEGIN {push @INC, '..'}\nuse EPMS;\n use lib use lib '..';\nuse EPMS;\n FindBin use FindBin; # locate this script\nuse lib \"$FindBin::RealBin/..\"; # use the parent directory\nuse EPMS;\n" }, { "answer_id": 185153, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 5, "selected": false, "text": "@INC PERL5LIB -I use lib @INC require" }, { "answer_id": 185154, "author": "Berserk", "author_id": 26313, "author_profile": "https://Stackoverflow.com/users/26313", "pm_score": 4, "selected": false, "text": "/www/modules/MyMods/Foo.pm\n/www/modules/MyMods/Bar.pm\n use lib qw(/www/modules);\nuse MyMods::Foo;\nuse MyMods::Bar;\n push @array => $pushee;\n" }, { "answer_id": 383845, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "BEGIN { require Module; import Module LIST; } require import BEGIN {\n require '../EPMS.pm';\n EPMS->import();\n}\n BEGIN {\n require '../EPMS.pm';\n}\n" }, { "answer_id": 70816975, "author": "Richard", "author_id": 4294886, "author_profile": "https://Stackoverflow.com/users/4294886", "pm_score": 0, "selected": false, "text": "@INC a/b/\n a/b/modules/tests/test1.pl\n BEGIN {\n unshift(@INC, \"..\"); \n}\n .. a/ a/b/modules .. ./modules cd modules/tests" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12448/" ]
185,124
<p>Say if I have a dropdown in a form and I have another nested class inside of this class . Now what's the best way to access this dropdown from the nested class? </p>
[ { "answer_id": 185144, "author": "Ray Hayes", "author_id": 7093, "author_profile": "https://Stackoverflow.com/users/7093", "pm_score": 7, "selected": false, "text": "// C#\nclass OuterClass \n{\n string s;\n // ...\n class InnerClass \n {\n OuterClass o_;\n public InnerClass(OuterClass o) { o_ = o; }\n public string GetOuterString() { return o_.s; }\n }\n void SomeFunction() {\n InnerClass i = new InnerClass(this);\n i.GetOuterString();\n }\n\n}\n s string s; private" }, { "answer_id": 185150, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 5, "selected": false, "text": "Outer<int>.Nested Outer<string>.Nested" }, { "answer_id": 185152, "author": "Jason Kresowaty", "author_id": 14280, "author_profile": "https://Stackoverflow.com/users/14280", "pm_score": 4, "selected": false, "text": "public partial class Form1 : Form\n{\n private Nested m_Nested;\n\n public Form1()\n {\n InitializeComponent();\n\n m_Nested = new Nested(this);\n m_Nested.Test();\n }\n\n private class Nested\n {\n private Form1 m_Parent;\n\n protected Form1 Parent\n {\n get\n {\n return m_Parent;\n }\n }\n\n public Nested(Form1 parent)\n {\n m_Parent = parent;\n }\n\n public void Test()\n {\n this.Parent.textBox1.Text = \"Testing access to parent Form's control\";\n }\n }\n}\n" }, { "answer_id": 185159, "author": "mannu", "author_id": 15858, "author_profile": "https://Stackoverflow.com/users/15858", "pm_score": 1, "selected": false, "text": "private NestedClass _nestedClass;\npublic ParentClass() \n{\n _nestedClass = new NestedClass(this);\n}\n" }, { "answer_id": 25000602, "author": "kmote", "author_id": 93394, "author_profile": "https://Stackoverflow.com/users/93394", "pm_score": 2, "selected": false, "text": "class Outer()\n{\n protected int outerVar;\n class Nested() : Outer\n {\n //can access outerVar here, without the need for a \n // reference variable (or the associated dot notation).\n }\n}\n" }, { "answer_id": 29672792, "author": "Levite", "author_id": 1680919, "author_profile": "https://Stackoverflow.com/users/1680919", "pm_score": 4, "selected": false, "text": "class OuterClass\n{\n private static int memberVar;\n\n class NestedClass \n {\n void SomeFunction() { OuterClass.memberVar = 42; }\n }\n}\n memberVar private class OuterClass\n{\n private int memberVar;\n private NestedClass n;\n\n OuterClass() { n = new NestedClass(this); }\n\n\n class NestedClass\n {\n private OuterClass parent;\n\n NestedClass(OuterClass p) { parent = p; }\n SomeFunction() { parent.memberVar = 42; }\n }\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
185,141
<p>I have a simple panel that is used as a drawing surface. The goal here is to draw a 4 pixel wide outline around a child ListView under certain circumstances. I would like to make the outline pulsate when something can be dragged into it. </p> <p>I am just drawing a simple rectangle around the ListView and updating the opacity of the rectangle inside of a timer tick event. When the opacity is changed, the border is re-drawn. I am double-buffering the painting at this point. I am also only allowing a redraw every 15 ticks or so (the timer interval is 20 ms). After all of this, the drawing process still flickers a bit. This is not acceptable, so I need some guidance on how I could avoid this.</p> <p>I don't see a way around painting the control quite often. There needs to be a smooth transition from opaque to solid and back again. When I lower the tick interval enough (down to about 300 -500 ms), the flashing stops, but the refresh rate is too slow.</p> <p>I am open to any and all ideas. Perhaps the way I am approaching this is just plain wrong, or perhaps one of you have already created a glow effect and know what to do. Thanks for any help in advance.</p>
[ { "answer_id": 185178, "author": "JamesSugrue", "author_id": 1075, "author_profile": "https://Stackoverflow.com/users/1075", "pm_score": 0, "selected": false, "text": "SetStyle(ControlStyles.OptimizedDoubleBuffer, true);\n" }, { "answer_id": 185475, "author": "Ed S.", "author_id": 1053, "author_profile": "https://Stackoverflow.com/users/1053", "pm_score": 3, "selected": true, "text": "SetStyle(ControlStyles.SupportsTransparentBackColor |\n ControlStyles.Opaque |\n ControlStyles.UserPaint |\n ControlStyles.AllPaintingInWmPaint, true);\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1053/" ]
185,149
<p>Please take a look at the html listed below and let me know why IE6 freezes when trying to load the remote script (located at '<a href="http://code.katzenbach.com/Default.aspx" rel="nofollow noreferrer">http://code.katzenbach.com/Default.aspx</a>'). The script returns JSONP and executes the 'callbackFunction' listed in the header. When it runs correctly, you'll see a pop-up alert showing numbers 1-500. This works fine in FF3 and IE7. I can't understand why it fails in Internet Explorer 6 -the processor gets pegged and everything hangs.</p> <p>Run it yourself and let me know if you experience the same problem. I've been staring at this problem all day. Thanks for your help.</p> <p>Andrew</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function callbackFunction(Result) { alert(Result) ; } &lt;/script&gt; &lt;script type="text/javascript" src="http://code.katzenbach.com/Default.aspx?callback=callbackFunction&amp;test=true&amp;c=500"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; Here &lt;/body&gt; &lt;/html&gt; </code></pre>
[ { "answer_id": 185188, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": 0, "selected": false, "text": "callbackFunction([\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\",\"26\",\"27\",\"28\",\"29\",\"30\",\"31\",\"32\",\"33\",\"34\",\"35\",\"36\",\"37\",\"38\",\"39\",\"40\",\"41\",\"42\",\"43\",\"44\",\"45\",\"46\",\"47\",\"48\",\"49\",\"50\",\"51\",\"52\",\"53\",\"54\",\"55\",\"56\",\"57\",\"58\",\"59\",\"60\",\"61\",\"62\",\"63\",\"64\",\"65\",\"66\",\"67\",\"68\",\"69\",\"70\",\"71\",\"72\",\"73\",\"74\",\"75\",\"76\",\"77\",\"78\",\"79\",\"80\",\"81\",\"82\",\"83\",\"84\",\"85\",\"86\",\"87\",\"88\",\"89\",\"90\",\"91\",\"92\",\"93\",\"94\",\"95\",\"96\",\"97\",\"98\",\"99\",\"100\",\"101\",\"102\",\"103\",\"104\",\"105\",\"106\",\"107\",\"108\",\"109\",\"110\",\"111\",\"112\",\"113\",\"114\",\"115\",\"116\",\"117\",\"118\",\"119\",\"120\",\"121\",\"122\",\"123\",\"124\",\"125\",\"126\",\"127\",\"128\",\"129\",\"130\",\"131\",\"132\",\"133\",\"134\",\"135\",\"136\",\"137\",\"138\",\"139\",\"140\",\"141\",\"142\",\"143\",\"144\",\"145\",\"146\",\"147\",\"148\",\"149\",\"150\",\"151\",\"152\",\"153\",\"154\",\"155\",\"156\",\"157\",\"158\",\"159\",\"160\",\"161\",\"162\",\"163\",\"164\",\"165\",\"166\",\"167\",\"168\",\"169\",\"170\",\"171\",\"172\",\"173\",\"174\",\"175\",\"176\",\"177\",\"178\",\"179\",\"180\",\"181\",\"182\",\"183\",\"184\",\"185\",\"186\",\"187\",\"188\",\"189\",\"190\",\"191\",\"192\",\"193\",\"194\",\"195\",\"196\",\"197\",\"198\",\"199\",\"200\",\"201\",\"202\",\"203\",\"204\",\"205\",\"206\",\"207\",\"208\",\"209\",\"210\",\"211\",\"212\",\"213\",\"214\",\"215\",\"216\",\"217\",\"218\",\"219\",\"220\",\"221\",\"222\",\"223\",\"224\",\"225\",\"226\",\"227\",\"228\",\"229\",\"230\",\"231\",\"232\",\"233\",\"234\",\"235\",\"236\",\"237\",\"238\",\"239\",\"240\",\"241\",\"242\",\"243\",\"244\",\"245\",\"246\",\"247\",\"248\",\"249\",\"250\",\"251\",\"252\",\"253\",\"254\",\"255\",\"256\",\"257\",\"258\",\"259\",\"260\",\"261\",\"262\",\"263\",\"264\",\"265\",\"266\",\"267\",\"268\",\"269\",\"270\",\"271\",\"272\",\"273\",\"274\",\"275\",\"276\",\"277\",\"278\",\"279\",\"280\",\"281\",\"282\",\"283\",\"284\",\"285\",\"286\",\"287\",\"288\",\"289\",\"290\",\"291\",\"292\",\"293\",\"294\",\"295\",\"296\",\"297\",\"298\",\"299\",\"300\",\"301\",\"302\",\"303\",\"304\",\"305\",\"306\",\"307\",\"308\",\"309\",\"310\",\"311\",\"312\",\"313\",\"314\",\"315\",\"316\",\"317\",\"318\",\"319\",\"320\",\"321\",\"322\",\"323\",\"324\",\"325\",\"326\",\"327\",\"328\",\"329\",\"330\",\"331\",\"332\",\"333\",\"334\",\"335\",\"336\",\"337\",\"338\",\"339\",\"340\",\"341\",\"342\",\"343\",\"344\",\"345\",\"346\",\"347\",\"348\",\"349\",\"350\",\"351\",\"352\",\"353\",\"354\",\"355\",\"356\",\"357\",\"358\",\"359\",\"360\",\"361\",\"362\",\"363\",\"364\",\"365\",\"366\",\"367\",\"368\",\"369\",\"370\",\"371\",\"372\",\"373\",\"374\",\"375\",\"376\",\"377\",\"378\",\"379\",\"380\",\"381\",\"382\",\"383\",\"384\",\"385\",\"386\",\"387\",\"388\",\"389\",\"390\",\"391\",\"392\",\"393\",\"394\",\"395\",\"396\",\"397\",\"398\",\"399\",\"400\",\"401\",\"402\",\"403\",\"404\",\"405\",\"406\",\"407\",\"408\",\"409\",\"410\",\"411\",\"412\",\"413\",\"414\",\"415\",\"416\",\"417\",\"418\",\"419\",\"420\",\"421\",\"422\",\"423\",\"424\",\"425\",\"426\",\"427\",\"428\",\"429\",\"430\",\"431\",\"432\",\"433\",\"434\",\"435\",\"436\",\"437\",\"438\",\"439\",\"440\",\"441\",\"442\",\"443\",\"444\",\"445\",\"446\",\"447\",\"448\",\"449\",\"450\",\"451\",\"452\",\"453\",\"454\",\"455\",\"456\",\"457\",\"458\",\"459\",\"460\",\"461\",\"462\",\"463\",\"464\",\"465\",\"466\",\"467\",\"468\",\"469\",\"470\",\"471\",\"472\",\"473\",\"474\",\"475\",\"476\",\"477\",\"478\",\"479\",\"480\",\"481\",\"482\",\"483\",\"484\",\"485\",\"486\",\"487\",\"488\",\"489\",\"490\",\"491\",\"492\",\"493\",\"494\",\"495\",\"496\",\"497\",\"498\",\"499\"])\n" }, { "answer_id": 193233, "author": "Grant Wagner", "author_id": 9254, "author_profile": "https://Stackoverflow.com/users/9254", "pm_score": 2, "selected": false, "text": "http://code.katzenbach.com/Default.aspx?callback=callbackFunction&test=true&c=500 application/json;; charset=utf-8 charset=utf-8 ) callbackFunction Content-Type: text/javascript" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21832/" ]
185,203
<p>I'm mostly familiar with Java, C and C++ in which there are ways to control that only one thread is accessing a resource at any given time. Now I'm in search for something similar but in PHP 5.x.</p> <p>To formulate my problem with one example:</p> <p>I have an ASCII-file which only stores a number, the value of a page load counter. At application deployment the file will simply hold a 0. For each access the value will be incremented by one. The goal is to keep track of page loads.</p> <p>The problem comes when many users are concurrently accessing the page containing the counter. When thread A has read the current value, let's say it is 11, another thread which we call B reads the value, still 11. Then the first thread A increments the read value and writes 12 in the file and closes it. Then the second thread B, increments the read value, which was 11, gets 12 and writes that into the file. The value 12 is stored in the file, when it really should have been 13.</p> <p>In another programming language I would have solved this using a mutex. I understand there are mutexes, shared memory and other funcionality as part of modules. But I would like a solution which works on "most servers" out there. Platform independent. Installed on most cheap web hosts. Is there a good solution to this problem? And if there isn't, which way would you take if using a <strong>database is not an option</strong>?</p>
[ { "answer_id": 185218, "author": "terson", "author_id": 22974, "author_profile": "https://Stackoverflow.com/users/22974", "pm_score": 4, "selected": true, "text": "<?php\n\n$fp = fopen(\"/tmp/counter.txt\", \"r+\");\n\necho \"Attempt to lock\\n\";\nif (flock($fp, LOCK_EX)) {\n echo \"Locked\\n\";\n // Read current value of the counter and increment\n $cntr = fread($fp, 80);\n $cntr = intval($cntr) + 1;\n\n // Pause to prove that race condition doesn't exist\n sleep(5);\n\n // Write new value to the file\n ftruncate($fp, 0);\n fseek($fp, 0, SEEK_SET);\n fwrite($fp, $cntr);\n flock($fp, LOCK_UN); // release the lock\n fclose($fp);\n}\n\n?>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
185,204
<p>I have a PHP script that sends out critical e-mails that needs to reach its destination. I know how to check whether the e-mail sent successfully, the only issue is knowing whether it actually got to its recipient.</p> <p>Any suggestions? If there is no way of knowing, how would you handle this situation?</p>
[ { "answer_id": 185271, "author": "stalepretzel", "author_id": 1615, "author_profile": "https://Stackoverflow.com/users/1615", "pm_score": 1, "selected": false, "text": "myserver.com/images/logo.gif?recipient@email.com" }, { "answer_id": 185364, "author": "Gary Richardson", "author_id": 2506, "author_profile": "https://Stackoverflow.com/users/2506", "pm_score": 2, "selected": false, "text": "http://trackingserver/track/$messageid/http://real.url/goes/here\n track http://real.url/goes/here" }, { "answer_id": 189103, "author": "Till", "author_id": 2859, "author_profile": "https://Stackoverflow.com/users/2859", "pm_score": 2, "selected": false, "text": "Errors-To Return-Path" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/131/" ]
185,208
<p>How can I get Environnment variables and if something is missing, set the value?</p>
[ { "answer_id": 185214, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 9, "selected": true, "text": "var value = System.Environment.GetEnvironmentVariable(variable [, Target])\n System.Environment.SetEnvironmentVariable(variable, value [, Target])\n Target EnvironmentVariableTarget Machine Process User" }, { "answer_id": 2763116, "author": "SpeedyNinja", "author_id": 331416, "author_profile": "https://Stackoverflow.com/users/331416", "pm_score": 4, "selected": false, "text": "String EnvironmentPath = System.Environment\n .GetEnvironmentVariable(\"Variable_Name\", EnvironmentVariableTarget.Machine);\n" }, { "answer_id": 9845159, "author": "Nathan Bedford", "author_id": 434, "author_profile": "https://Stackoverflow.com/users/434", "pm_score": 5, "selected": false, "text": "string keyName = @\"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\\\";\nstring existingPathFolderVariable = (string)Registry.LocalMachine.OpenSubKey(keyName).GetValue(\"PATH\", \"\", RegistryValueOptions.DoNotExpandEnvironmentNames);\n" }, { "answer_id": 11760142, "author": "Karthik Chintala", "author_id": 1551730, "author_profile": "https://Stackoverflow.com/users/1551730", "pm_score": 3, "selected": false, "text": "Environment.SetEnvironmentVariable(\"Variable name\", value, EnvironmentVariableTarget.User);\n" }, { "answer_id": 17033912, "author": "Tom Stickel", "author_id": 756246, "author_profile": "https://Stackoverflow.com/users/756246", "pm_score": 5, "selected": false, "text": "string getEnv = Environment.GetEnvironmentVariable(\"envVar\");\n string setEnv = Environment.SetEnvironmentVariable(\"envvar\", varEnv);\n" }, { "answer_id": 39141893, "author": "Ajit", "author_id": 1986966, "author_profile": "https://Stackoverflow.com/users/1986966", "pm_score": 0, "selected": false, "text": "string EnvPath = System.Environment.GetEnvironmentVariable(\"PATH\", EnvironmentVariableTarget.Machine) ?? string.Empty;\nif (!string.IsNullOrEmpty(EnvPath) && !EnvPath .EndsWith(\";\"))\n EnvPath = EnvPath + ';';\nEnvPath = EnvPath + @\"C:\\Test\";\nEnvironment.SetEnvironmentVariable(\"PATH\", EnvPath , EnvironmentVariableTarget.Machine);\n" }, { "answer_id": 65661184, "author": "Vijendran Selvarajah", "author_id": 7605370, "author_profile": "https://Stackoverflow.com/users/7605370", "pm_score": 1, "selected": false, "text": "var builder = new ConfigurationBuilder()\n .AddJsonFile(\"appSettings.json\")\n .AddEnvironmentVariables(prefix: \"ABC_\")\n\nvar config = builder.Build();\n AddEnvironmentVariables(prefix: \"ABC_\")" }, { "answer_id": 66724014, "author": "D. Kermott", "author_id": 1620607, "author_profile": "https://Stackoverflow.com/users/1620607", "pm_score": 0, "selected": false, "text": "var sConnectionStr = Properties.Settings.Default.ConnectionString;\n <applicationSettings>\n <Testing.Properties.Settings>\n <setting name=\"ConnectionString\" serializeAs=\"String\">\n <value>data source=blah-blah;etc-etc</value>\n </setting>\n </Testing.Properties.Settings>\n </applicationSettings>\n" }, { "answer_id": 68708239, "author": "OfirD", "author_id": 3002584, "author_profile": "https://Stackoverflow.com/users/3002584", "pm_score": 0, "selected": false, "text": "app.config web.config % app.config <connectionStrings>\n <add name=\"myConnectionString\" connectionString=\"%DEV_SQL_SERVER_CONNECTION_STRING%\" providerName=\"System.Data.SqlClient\" />\n</connectionStrings>\n string connectionStringEnv = ConfigurationManager.AppSettings[\"myConnectionString\"];\nstring connectionString = System.Environment.ExpandEnvironmentVariables(connectionStringEnv); \n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14441/" ]
185,235
<p>I've previously used <a href="https://jqueryui.com/tabs/" rel="nofollow noreferrer"><code>jquery-ui tabs</code></a> extension to load page fragments via <code>ajax</code>, and to conceal or reveal hidden <code>div</code>s within a page. Both of these methods are well documented, and I've had no problems there.</p> <p>Now, however, I want to do something different with tabs. When the user selects a tab, it should reload the page entirely - the reason for this is that the contents of each tabbed section are somewhat expensive to render, so I don't want to just send them all at once and use the normal method of toggling 'display:none' to reveal them.</p> <p>My plan is to intercept the tabs' <code>select</code> event, and have that function reload the page with by manipulating document.location.</p> <p>How, in the <code>select</code> handler, can I get the newly selected tab index and the html LI object it corresponds to?</p> <pre><code>$('#edit_tabs').tabs( { selected: 2, // which tab to start on when page loads select: function(e, ui) { var t = $(e.target); // alert("data is " + t.data('load.tabs')); // undef // alert("data is " + ui.data('load.tabs')); // undef // This gives a numeric index... alert( "selected is " + t.data('selected.tabs') ) // ... but it's the index of the PREVIOUSLY selected tab, not the // one the user is now choosing. return true; // eventual goal is: // ... document.location= extract-url-from(something); return false; } }); </code></pre> <p>Is there an attribute of the event or ui object that I can read that will give the index, id, or object of the newly selected tab or the anchor tag within it? </p> <p>Or is there a better way altogether to use tabs to reload the entire page?</p>
[ { "answer_id": 185257, "author": "imjoevasquez", "author_id": 24630, "author_profile": "https://Stackoverflow.com/users/24630", "pm_score": 6, "selected": true, "text": " $('.ui-tabs-nav').bind('tabsselect', function(event, ui) {\n ui.options // options used to intialize this widget\n ui.tab // anchor element of the selected (clicked) tab\n ui.panel // element, that contains the contents of the selected (clicked) tab\n ui.index // zero-based index of the selected (clicked) tab\n });\n" }, { "answer_id": 185354, "author": "Matt Hucke", "author_id": 2554901, "author_profile": "https://Stackoverflow.com/users/2554901", "pm_score": 0, "selected": false, "text": "$(document).ready(function() {\n $('#edit_tabs').tabs( {\n selected: [% page.selected_tab ? page.selected_tab : 0 %],\n select: function(e, ui) {\n // ui.tab is an 'a' object\n // it has an id of \"link_foo_bar\"\n // transform it into http://....something&cmd=foo-bar\n var url = idToTabURL(ui.tab.id);\n\n document.location = url;\n return false;\n }\n }).show();\n});\n" }, { "answer_id": 186665, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "$(document).ready(function() {\n $('#edit_tabs').tabs( {\n selected: [% page.selected_tab ? page.selected_tab : 0 %],\n select: function(e, ui) {\n // ui.tab is an 'a' object\n var url = ui.tab.href;\n\n document.location = url;\n return false;\n }\n }).show();\n});\n" }, { "answer_id": 992336, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": " <div id=\"tabNav\">\n\n <ul class=\"tabs\">\n <li><a href=\"#message\">Send a message</a></li>\n <li><a href=\"#shareFile\">Share a file</a></li>\n <li><a href=\"#arrange\">Arrange a meetup</a></li>\n </ul>\n</div>\n\n<div id=\"tabCont\">\n\n <div id=\"message\">\n <p>Lorem ipsum dolor sit amet.</p>\n </div>\n <div id=\"shareFile\">\n <p>Sed do eiusmod tempor incididunt.</p>\n </div>\n <div id=\"arrange\">\n <p>Ut enim ad minim veniam</p>\n </div>\n\n</div>\n $(document).ready(function() {\n$(function () {\n var tabs = [];\n var tabContainers = [];\n\n $('ul.tabs a').each(function () {\n // note that this only compares the pathname, not the entire url\n // which actually may be required for a more terse solution.\n if (this.pathname == window.location.pathname) {\n tabs.push(this);\n tabContainers.push($(this.hash).get(0));\n }\n });\n\n $(tabs).click(function () {\n // hide all tabs\n $(tabContainers).hide().filter(this.hash).show();\n\n\n // set up the selected class\n $(tabs).removeClass('active');\n $(this).addClass('active');\n\n return false;\n\n});\n\n\n\n\n $(tabs).filter(window.location.hash ? '[hash=' + window.location.hash + ']' : ':first').click();\n\n });\n\n});\n" }, { "answer_id": 3564091, "author": "user376026", "author_id": 376026, "author_profile": "https://Stackoverflow.com/users/376026", "pm_score": 3, "selected": false, "text": "select: function(e, ui){var index=ui.index;}\n" }, { "answer_id": 12813783, "author": "Yasser Shaikh", "author_id": 1182982, "author_profile": "https://Stackoverflow.com/users/1182982", "pm_score": 0, "selected": false, "text": "$('#edit_tabs').tabs({ selected: 2 }); \n" }, { "answer_id": 14560636, "author": "aorlando", "author_id": 1396276, "author_profile": "https://Stackoverflow.com/users/1396276", "pm_score": 3, "selected": false, "text": "ui.newTab.index()\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185235", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2554901/" ]
185,236
<p>I'm programming something that allows users to store documents and pictures on a webserver, to be stored and retrieved later. When users upload files to my server, PHP tells me what filetype it is based on the extension. However, I'm afraid that users could rename a zip file as somezipfile.png and store it, thus keeping a zip file on my server. Is there any reasonable way to open an uploaded file and "check" to see if it truly is of the said filetype?</p>
[ { "answer_id": 185756, "author": "Shoan", "author_id": 17404, "author_profile": "https://Stackoverflow.com/users/17404", "pm_score": 2, "selected": false, "text": "$ php -r 'var_dump(getimagesize(\"b&n.jpg\"));'\narray(7) {\n [0]=>\n int(200)\n [1]=>\n int(200)\n [2]=>\n int(2)\n [3]=>\n string(24) \"width=\"200\" height=\"200\"\"\n [\"bits\"]=>\n int(8)\n [\"channels\"]=>\n int(3)\n [\"mime\"]=>\n string(10) \"image/jpeg\"\n}\n\n$ php -r 'var_dump(getimagesize(\"/etc/passwd\"));'\nbool(false)\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1615/" ]
185,239
<p>I have a button on my webform. Clicking this button will do an HttpWebRequest during the onclick event handler. After the request we copy the response from the request into HttpContext.Current.Response and send that to the client.</p> <p>This web request can take a while (up to 5 seconds, since it's generating a report). During this time the user has no indication that anything is going on, except for the browser progress bar and the spinning IE icon (if they're using IE). So I need a loading indicator while this is happening.</p> <p>I've tried using javascript that fires during the button's onclick event (using OnClientClick) and while that works, I don't know how to find out when the web request is finished. Since we just send the response to the client, a full postback doesn't happen.</p> <p>I've tried wrapping the button in an UpdatePanel and using the UpdateProgress, but when we send the response to HttpContext.Current.Response and call Response.End(), we get an error in the javascript, since the response isn't well formed (we're sending back an excel sheet for the user to download).</p> <p>Since we're sending back a file for users to download, I don't want to pop-up a separate window, since then in IE they'd get the information bar blocking the download.</p> <p>Any ideas here? </p>
[ { "answer_id": 602412, "author": "Federico Zancan", "author_id": 15908, "author_profile": "https://Stackoverflow.com/users/15908", "pm_score": 0, "selected": false, "text": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<html>\n <head>\n <title>First Example</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n <style>\n .hidden {\n display: none;\n }\n .loadingInProgress {\n color: #FFFFFF;\n width: 75px;\n background-color: #FF0000;\n }\n </style>\n <script type=\"text/javascript\">\n var httpRequest;\n if (window.XMLHttpRequest) { // Mozilla, Safari, ...\n httpRequest = new XMLHttpRequest();\n httpRequest.overrideMimeType('text/xml');\n } else if (window.ActiveXObject) { // IE\n try {\n httpRequest = new ActiveXObject(\"Msxml2.XMLHTTP\");\n }\n catch (e) {\n try {\n httpRequest = new ActiveXObject(\"Microsoft.XMLHTTP\");\n }\n catch (e) {}\n }\n }\n\n if (!httpRequest) {\n alert('Giving up :( Cannot create an XMLHTTP instance');\n }\n\n httpRequest.onreadystatechange = function(){\n switch (httpRequest.readyState) {\n case 1: // Loading\n document.getElementById('loading').className = \"loadingInProgress\";\n break;\n case 4: // Complete\n document.getElementById('loading').className = \"hidden\";\n if (httpRequest.status == 200) {\n // perfect!\n } else {\n // there was a problem with the request,\n // for example the response may be a 404 (Not Found)\n // or 500 (Internal Server Error) response codes\n }\n break;\n }\n };\n\n function go() {\n httpRequest.open('GET', document.getElementById('form1').action, true);\n httpRequest.send('');\n }\n </script>\n\n </head>\n <body>\n <div id=\"loading\" class=\"hidden\">Loading...</div>\n <form id=\"form1\" name=\"form1\" action=\"doSomething.php\">\n <input type=\"button\" value=\"Click to submit:\" onclick=\"go()\" />\n </form>\n </body>\n</html>\n <div> <div> XMLHttpRequest readyState onreadystatechange XMLHttpRequest readyState action <?php\nsleep(5);\nheader('Cache-Control: no-cache');\necho \"OK\";\n?>\n Cache-control: no-cache" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/233/" ]
185,240
<p>I have an import-from-excel script as part of a CMS that previously ran without issue.</p> <p>My shared-hosting provider has recently upgraded their infrastructure, including PHP from 5.1 to 5.2.6, and the script now returns "Uninitialized string offset: -XXX in /path/scriptname.php on line 27" (XXX being a decreasing number from 512 and /path/scriptname.php of course being the full path to script in question). </p> <p>It returns this error for every line of the excel file. Line 27 is just a return from within a function that is the first point at which the imported data is being processed:</p> <pre><code>function GetInt4d($data, $pos) { return ord($data[$pos]) | (ord($data[$pos+1]) &lt;&lt; 8) | (ord($data[$pos+2]) &lt;&lt; 16) | (ord($data[$pos+3]) &lt;&lt; 24); } </code></pre> <p>It finally implodes with a "Fatal error: Allowed memory size of 47185920 bytes exhausted (tried to allocate 71 bytes) in /path/scriptname.php on line 133".</p> <p>There's nothing useful in Apache error logs. I am stumped. Anyone have any ideas of at least where to look? Even knowing if it's likely to be something within my script or something to do with upgrade would be useful. I had another issue with a different site on same provider that (after upgrade) couldn't write sessions to tmp directory (since resolved), but am pretty sure it's not that (?).</p> <p>EDIT: As it turned out that the answer was to do with the version of the parser being incompatible in some way with PHP 5.2.6, I thought it might be of use to someone that the parser in question is <a href="http://sourceforge.net/project/showfiles.php?group_id=99160&amp;package_id=106368" rel="nofollow noreferrer">Spreadsheet Excel Reader</a> .</p>
[ { "answer_id": 189625, "author": "Till", "author_id": 2859, "author_profile": "https://Stackoverflow.com/users/2859", "pm_score": 3, "selected": true, "text": "$data" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14979/" ]
185,252
<p>I have a Flex application where load time is extremely important (consumer site). i want to be able to get something up on screen and then allow additional modules to be loaded as necessary.</p> <p>The issue I'm facing is that the sum total of all the modules is much larger than if i were to include all the components in a single .swf file.</p> <p>Its pretty obvious why. For instance the classes needed for web service access seem to take about 100kb. If I dont use those classes in my main.swf then they'll be included in EVERY module that uses them. So if I have 5 modules thats an extra 500kB wasted.</p> <p>In theory I want 3 levels</p> <p>main.swf - minimum possible layout / style / font / framework type stuff common.swf - additional classes needed by module 1 + module 2 (such as web services) module1.swf - module 1 in site module2.swf - module 2 in site</p> <p>I dont know if this is even possible.</p> <p>I'm wondering if I can load swz/swf files for portions of the framework instead of the entire framework.</p> <p>I really need to get my main app size down to 200Kb. It grows to 450kb when I add web services and basic datagrid functionality.</p> <p>Any lessons learned would be appreciated.</p>
[ { "answer_id": 194615, "author": "James Fassett", "author_id": 27081, "author_profile": "https://Stackoverflow.com/users/27081", "pm_score": 1, "selected": false, "text": "\nprivate function loadContent(path:String):void \n{\n var contentLoader:Loader = new Loader();\n contentLoader.contentLoaderInfo.addEventListener(\n Event.COMPLETE,\n loadContent_onComplete);\n contentLoader.load(new URLRequest(path));\n}\n\n\nprivate function loadContent_onComplete (event:Event):void\n{ \n var content:DisplayObject = event.target.content;\n\n if(content is IFlexModuleFactory) \n {\n var content_onReady:Function = function (event:Event):void \n { \n var factory:IFlexModuleFactory = content as IFlexModuleFactory;\n var info:Object = factory.info();\n var instanceClass:Class = info.currentDomain.getDefinition(\n info.mainClassName) as Class;\n\n addChild (new instanceClass ());\n }\n\n content.addEventListener (\"ready\", content_onReady);\n\n } \n else\n {\n addChild (content); \n }\n}\n" }, { "answer_id": 675967, "author": "evanmcd", "author_id": 78199, "author_profile": "https://Stackoverflow.com/users/78199", "pm_score": 2, "selected": false, "text": "mxmlc -link-report=MyAppReport.xml MyApp.mxml\n mxmlc -load-externs=MyAppReport.xml MyModule.mxml\n cd C:\\Projects\\MyProject\\Develop\\Modules\nmxmlc -link-report=MyAppReport.xml C:\\Projects\\MyProject\\Develop\\Source\\Main.mxml\nmxmlc -load-externs=MyAppReport.xml MyModule.mxml\nmove /Y MyModule.swf ..\\Runtime\\Modules\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24727/" ]
185,254
<p>I'm currently passing the pid on the command line to the child, but is there a way to do this in the Win32 API? Alternatively, can someone alleviate my fear that the pid I'm passing might belong to another process after some time if the parent has died?</p>
[ { "answer_id": 558251, "author": "Jay", "author_id": 20840, "author_profile": "https://Stackoverflow.com/users/20840", "pm_score": 6, "selected": false, "text": "#include <stdio.h>\n#include <windows.h>\n#include <tlhelp32.h>\n\nint main(int argc, char *argv[]) \n{\n int pid = -1;\n HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n PROCESSENTRY32 pe = { 0 };\n pe.dwSize = sizeof(PROCESSENTRY32);\n\n //assume first arg is the PID to get the PPID for, or use own PID\n if (argc > 1) {\n pid = atoi(argv[1]);\n } else {\n pid = GetCurrentProcessId();\n }\n\n if( Process32First(h, &pe)) {\n do {\n if (pe.th32ProcessID == pid) {\n printf(\"PID: %i; PPID: %i\\n\", pid, pe.th32ParentProcessID);\n }\n } while( Process32Next(h, &pe));\n }\n\n CloseHandle(h);\n}\n" }, { "answer_id": 979116, "author": "Peter Ruderman", "author_id": 114421, "author_profile": "https://Stackoverflow.com/users/114421", "pm_score": 5, "selected": false, "text": "DuplicateHandle() Close Close" }, { "answer_id": 3137081, "author": "Napalm", "author_id": 378551, "author_profile": "https://Stackoverflow.com/users/378551", "pm_score": 4, "selected": false, "text": "ULONG_PTR GetParentProcessId() // By Napalm @ NetCore2K\n{\n ULONG_PTR pbi[6];\n ULONG ulSize = 0;\n LONG (WINAPI *NtQueryInformationProcess)(HANDLE ProcessHandle, ULONG ProcessInformationClass,\n PVOID ProcessInformation, ULONG ProcessInformationLength, PULONG ReturnLength); \n *(FARPROC *)&NtQueryInformationProcess = \n GetProcAddress(LoadLibraryA(\"NTDLL.DLL\"), \"NtQueryInformationProcess\");\n if(NtQueryInformationProcess){\n if(NtQueryInformationProcess(GetCurrentProcess(), 0,\n &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi))\n return pbi[5];\n }\n return (ULONG_PTR)-1;\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23524/" ]
185,262
<p>We've talked about <b>personal</b> password management <a href="https://stackoverflow.com/questions/11362/what-is-your-favorite-password-storage-tool">here</a> but how do you guys manage your passwords at a company wide level?</p>
[ { "answer_id": 185340, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 0, "selected": false, "text": "passwords.txt" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25820/" ]
185,282
<p>I would like to access a class everywhere in my application, how can I do this?</p> <p>To make it more clear, I have a class somewhere that use some code. I have an other class that use the same code. I do not want to duplicate so I would like to call the same code in both place by using something. In php I would just include("abc.php") in both... I do not want to create the object everytime I want to use the code.</p>
[ { "answer_id": 185296, "author": "Max Schmeling", "author_id": 3226, "author_profile": "https://Stackoverflow.com/users/3226", "pm_score": 3, "selected": false, "text": "public static class MyClass { } public class MyClass\n{\n private static MyClass myClass;\n\n public static MyClass MyClass\n {\n get { return myClass ?? (myClass = new MyClass()); }\n }\n\n private MyClass()\n {\n //private constructor makes it where this class can only be created by itself\n }\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185282", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21386/" ]
185,291
<p>This is kinda a general question, open for opinions. I've been trying to come up with a good way to design for localization of string resources for a Windows MFC application and related utilities. My wishlist is:</p> <ul> <li>Must preserve string literals in code (as opposed to replacing with macro #define resource ID's), so that the messages are still readable inline</li> <li>Must allow localized string resources (duh)</li> <li>Must not impose additional run-time environment restrictions (eg: dependency on .NET, etc.)</li> <li>Should have minimal obtrusion into existing code (the less modification the better)</li> <li>Should be debuggable</li> <li>Should generate resource files which are editable by common tools (ie: common format)</li> <li>Should not use copy/paste comment blocks to preserve literal strings in code, or anything else which creates the potential for de-synchronization</li> <li>Would be nice to allow static (compile-time) checking that every "notated" string is in the resource file(s)</li> <li>Would be nice to allow cross-language resource string pooling (for components in various languages, eg: native C++ and .NET)</li> </ul> <p>I have a way which fulfills all my wishlist to some extent except for static checking, but I have had to develop a bit of custom code to achieve it (and it has limitations). I'm wondering if anyone has solved this problem in a particularly good way.</p> <p>Edit: The solution I currently have looks like this:</p> <pre><code>ShowMessage( RESTRING( _T("Some string") ) ); ShowMessage( RESTRING( _T("Some string with variable %1"), sNonTranslatedStringVariable ) ); </code></pre> <p>I then have a custom utility to parse out the strings from within the 'RESTRING' blocks and put them into a .resx file for localization, and a separate C# COM object to load them from localized resource files with fallback. If the C# object is not available (or cannot load), I fallback to the string in the code. The macro expands to a template class which calls the COM object and does the formatting, etc.</p> <p>Anyway, I thought it would be useful to add what I have now for reference.</p>
[ { "answer_id": 185356, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 2, "selected": false, "text": "doAction(I18N.get(\"Press OK to continue\"));\n" }, { "answer_id": 185700, "author": "KPexEA", "author_id": 13676, "author_profile": "https://Stackoverflow.com/users/13676", "pm_score": 1, "selected": false, "text": "ID ENGLISH FRENCH GERMAN\nSTRING_YES YES OUI YA\nSTRING_NO NO NON NEIN\n" }, { "answer_id": 191799, "author": "MSalters", "author_id": 15416, "author_profile": "https://Stackoverflow.com/users/15416", "pm_score": 1, "selected": false, "text": "gettext MyString.Format(_(\"Some string with variable %ls\"), _(\"variable\")); boost::format(_(\"Some string with variable %1\")) % _(\"variable\"); _()" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185291", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26240/" ]
185,314
<p>I have a C# app which uses a System.Diagnostics.Process to run another exe. I ran into some example code where the process is started in a try block and closed in a finally block. I also saw example code where the process is not closed.</p> <p>What happens when the process is not closed? </p> <p>Are the resources used by the process reclaimed when the console app that created the process is closed? </p> <p>Is it bad to open lots of processes and not close any of them in a console app that's open for long periods of time?</p> <p>Cheers!</p>
[ { "answer_id": 185342, "author": "Duncan Smart", "author_id": 1278, "author_profile": "https://Stackoverflow.com/users/1278", "pm_score": 5, "selected": true, "text": "Close() Process Process IDisposable using(...) Dispose Close() using (Process p = Process.Start(...))\n{\n ...\n}\n IDisposable Dispose Close using(...)" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185314", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
185,327
<p>I knew stackoverflow would help me for other than know what is the "favorite programming cartoon" :P </p> <p>This was the accepted answer by: <a href="https://stackoverflow.com/questions/185327/oracle-joins-left-outer-right-etc-s#185439">Bill Karwin</a></p> <p>Thanks to all for the help ( I would like to double vote you all ) </p> <p>My query ended up like this ( this is the real one ) </p> <pre><code>SELECT accepted.folio, COALESCE( inprog.activityin, accepted.activityin ) as activityin, inprog.participantin, accepted.completiondate FROM performance accepted LEFT OUTER JOIN performance inprog ON( accepted.folio = inprog.folio AND inprog.ACTIVITYIN IN ( 4, 435 ) -- both are ids for inprogress AND inprog.PARTICIPANTIN != 1 ) -- Ignore the "bot" participant LEFT OUTER JOIN performance closed ON( accepted.folio = closed.folio AND closed.ACTIVITYIN IN ( 10,436, 4, 430 ) ) -- all these are closed or cancelled WHERE accepted.ACTIVITYIN IN ( 3, 429 ) --- both are id for new AND accepted.folio IS NOT NULL AND closed.folio IS NULL; </code></pre> <p>Now I just have to join with the other tables for a human readable report.</p> <p><hr> <strong>ORIGINAL POST</strong></p> <p>Hello. </p> <p>I'm struggling for about 6 hrs. now with a DB query ( my long time nemesis ) </p> <p>I have a data table with some fields like:</p> <pre><code>table performance( identifier varchar, activity number, participant number, closedate date, ) </code></pre> <p>It is used to keep track of the history of ticket</p> <p><strong>Identifier</strong>: is a customer id like ( NAF0000001 ) </p> <p><strong>activity</strong>: is a fk of where the ticket is ( new, in_progress, rejected, closed, etc )</p> <p><strong>participant</strong>: is a fk of who is attending at that point the ticket</p> <p><strong>closedate</strong>: is the date when that activity finished.</p> <p><strong>EDIT:</strong> I should have said "completiondate" rather than closedate. This is the date when the activity was completed, not necessary when the ticket was closed.</p> <p>For instance a typical history may be like this:</p> <pre> identifier|activity|participant|closedate ------------------------------------------- NA00000001| 1| 1|2008/10/08 15:00| ------------------------------------------- NA00000001| 2| 2|2008/10/08 15:20| ------------------------------------------- NA00000001| 3| 2|2008/10/08 15:40| ------------------------------------------- NA00000001| 4| 4|2008/10/08 17:05| ------------------------------------------- </pre> <p>And participant 1=jonh, 2=scott, 3=mike, 4=rob</p> <p>and activties 1=new, 2=inprogress, 3=waitingforapproval, 4=closed</p> <p>etc. And tens of other irrelevant info.</p> <p>Well my problem is the following.</p> <p>I have managed to create a query where I can know when a ticket was opened and closed</p> <p>it is like this:</p> <pre><code> select a.identifier, a.participant, a.closedate as start, b.closedate as finish from performance a, performance b where a.activity = 1 -- new and b.activity = 4 -- closed and a.identifier = b.identifier </code></pre> <p>But I can't know what tickets are <strong>not</strong> closed and who is attending them.</p> <p>So far I have something like this:</p> <pre><code> select a.identifier, a.participant, a.closedate as start from performance a where a.activity = 1 -- new and a.identifier not in ( select identifier from performance where activity = 4 ) --closed </code></pre> <p>That is give me all the ones who have an start ( new = 1 ) but are not closed ( closed = 4 ) </p> <p>But the big problem here is that it prints the participant who opened the ticket, but I need the participant who is attending it. So I add the "inprogress" activity to the query.</p> <pre><code> select a.identifier, a.participant, a.closedate as start from performance a, performance b where a.activity = 1 -- new and a.identifier not in ( select identifier from performance where activity = 4 ) --closed and b.identifier = a.identifier and b.activity = 2 -- inprogress.. </code></pre> <p>But not all the rows that are in "new" are "inprogress" and with that query I drop all of them.</p> <p>What I need is to show all the "inprogress" participant and if the ticket is not "inprogress", it will show as empty.</p> <p>Somthing like</p> <pre> identifier|activity|participant|closedate ------------------------------------------- NA00000002| 1| |2008/10/08 15:00| ------------------------------------------- NA00000003| 1| |2008/10/08 15:20| ------------------------------------------- NA00000004| 1| |2008/10/08 15:40| ------------------------------------------- NA00000005| 2| 4|2008/10/08 15:40| ------------------------------------------- NA00000006| 2| 4|2008/10/08 15:40| </pre> <p>In this case</p> <p>NA002, NA003 and NA004 are in "new", so no participant is shown</p> <p>While</p> <p>NA005 and NA006 are being "inprgress (act = 2 )" and they are being attended by rob ( participant 4 ) </p> <p>So I remember there was this thing called left outer join or something like that but I never ever understand it. What I would like to know is how can I fetch the identifiers that are "inprogress" and "new" and that are not closed.</p> <p>Probably taking a little rest would help me to clear my mind. If anyone knows how to do it I'll appreciate it.</p> <p>By the way I've tried:</p> <pre><code> select a.identifier, a.participant, a.closedate as start from performance a left outer join performance b on b.identifier = a.identifier where a.activity = 1 -- new and a.identifier not in ( select identifier from performance where activity = 4 ) --closed and b.activity = 2 -- inprogress.. </code></pre> <p>But gives me the same result as the previous ( drop the only in "new" records )</p>
[ { "answer_id": 185375, "author": "Andy Lester", "author_id": 8454, "author_profile": "https://Stackoverflow.com/users/8454", "pm_score": 2, "selected": false, "text": "select * from performance p1\nwhere not exists \n ( select * from performance p2 \n where p2.identifier = p1.identifier and p2.activity = 4 )\n (select identifier from performance where activity=4)" }, { "answer_id": 185425, "author": "abarax", "author_id": 24390, "author_profile": "https://Stackoverflow.com/users/24390", "pm_score": 2, "selected": false, "text": "select \n a.identifier,\n a.participant,\n a.closedate as start\nfrom \n performance a\nwhere\n a.activity = 1\n and not exists ( select identifier \n from performance b \n where b.activity = 4 \n and b.identifier = a.identifier) \n and not exists ( select identifier \n from performance c \n where c.activity = 2 \n and c.identifier = a.identifier) \nUNION ALL\nselect \n a.identifier,\n a.participant,\n a.closedate as start\nfrom \n performance a\nwhere\n a.activity = 2\n and not exists ( select identifier \n from performance b \n where b.activity = 4 \n and b.identifier = a.identifier); \n" }, { "answer_id": 185428, "author": "Josh", "author_id": 257, "author_profile": "https://Stackoverflow.com/users/257", "pm_score": 0, "selected": false, "text": "select identifier as closed_identifier \n from performance where identifier not exists\n (select identifier from performance where activity=4)\n select identifier as inprogress_identifier, participant performance \n from performance where activity=2\n select * from \n (select identifier as notclosed_identifier \n from performance where identifier not exists\n (select identifier from performance where activity=4)) closed \nleft join \n (select identifier as inprogress_identifier, participant performance \n from performance where activity=2) attended \non notclosed_identifier=inprogress_identifier\n" }, { "answer_id": 185439, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 3, "selected": true, "text": "SELECT p_new.identifier, COALESCE(p_inprog.activity, p_new.activity) AS activity,\n p_inprog.participant, COALESCE(p_inprog.closedate, p_new.closedate) AS closedate\nFROM performance p_new\n LEFT OUTER JOIN performance p_inprog \n ON (p_new.identifier = p_inprog.identifier AND p_inprog.activity = 2)\n LEFT OUTER JOIN performance p_closed \n ON (p_new.identifier = p_closed.identifier AND p_closed.activity = 4)\nWHERE p_new.activity = 1\n AND p_closed.identifier IS NULL;\n A LEFT OUTER JOIN B ON (...condition...)\n" }, { "answer_id": 185567, "author": "Metro", "author_id": 18978, "author_profile": "https://Stackoverflow.com/users/18978", "pm_score": 1, "selected": false, "text": "SELECT\n identifier,\n activity,\n participant,\n closedate\n FROM\n performance a\n WHERE\n (a.identifier, a.closedate) in\n (select b.identifier, max(b.closedate)\n from performance b\n group by b.identifier\n )\n;\n" }, { "answer_id": 185888, "author": "Salamander2007", "author_id": 10629, "author_profile": "https://Stackoverflow.com/users/10629", "pm_score": 0, "selected": false, "text": "select x.identifier, \n max(x.p_1) as new_participant, max(x.c_1) as new_date,\n max(x.p_2) as inprogress_participant, max(x.c_2) as inprogress_date,\n max(x.p_3) as approval_participant, max(x.c_3) as approval_date,\n max(x.p_4) as closing_participant, max(x.c_4) as closing_date\n from (\n select a.identifier, \n decode (activity, 1, participant, null) as p_1, decode (activity, 1, closedate, null) as c_1,\n decode (activity, 2, participant, null) as p_2, decode (activity, 2, closedate, null) as c_2,\n decode (activity, 3, participant, null) as p_3, decode (activity, 3, closedate, null) as c_3,\n decode (activity, 4, participant, null) as p_4, decode (activity, 4, closedate, null) as c_4\n from performance a\n ) x\n group by x.identifier\n" }, { "answer_id": 186305, "author": "Thorsten", "author_id": 25320, "author_profile": "https://Stackoverflow.com/users/25320", "pm_score": 0, "selected": false, "text": "select id\nfrom performance p1 where identifier not exists\n (select * from performance p2 where activity=4 and p1.id=p2.id)\n select id,\n (select participant \n from performance p3 \n where p3.activity=3 and p1.id=p2.id)\nfrom performance p1 where identifier not exists\n (select * from performance p2 where activity=4 and p1.id=p2.id)\n" }, { "answer_id": 187316, "author": "Dave Costa", "author_id": 6568, "author_profile": "https://Stackoverflow.com/users/6568", "pm_score": 1, "selected": false, "text": "SELECT * FROM (\n SELECT identifier,\n MAX(activity) activity,\n MAX(participant) KEEP (DENSE_RANK LAST ORDER BY activity)\n FROM performance\n GROUP BY identifier\n)\nWHERE activity in (1,2)\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185327", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20654/" ]
185,349
<p>In XAML I can declare a DataTemplate so that the template is used whenever a specific type is displayed. For example, this DataTemplate will use a TextBlock to display the name of a customer:</p> <pre><code>&lt;DataTemplate DataType="{x:Type my:Customer}"&gt; &lt;TextBlock Text="{Binding Name}" /&gt; &lt;/DataTemplate&gt; </code></pre> <p>I'm wondering if it's possible to define a DataTemplate that will be used any time an IList&lt;Customer&gt; is displayed. So if a ContentControl's Content is, say, an ObservableCollection&lt;Customer&gt; it would use that template.</p> <p>Is it possible to declare a generic type like IList in XAML using the {x:Type} Markup Extension?</p>
[ { "answer_id": 186694, "author": "Ian Oakes", "author_id": 21606, "author_profile": "https://Stackoverflow.com/users/21606", "pm_score": 5, "selected": false, "text": "DataTemplateSelector public class CustomerTemplateSelector : DataTemplateSelector\n{\n public override DataTemplate SelectTemplate(object item,\n DependencyObject container)\n {\n DataTemplate template = null;\n if (item != null)\n {\n FrameworkElement element = container as FrameworkElement;\n if (element != null)\n {\n string templateName = item is ObservableCollection<MyCustomer> ?\n \"MyCustomerTemplate\" : \"YourCustomerTemplate\";\n\n template = element.FindResource(templateName) as DataTemplate;\n } \n }\n return template;\n }\n}\n\npublic class MyCustomer\n{\n public string CustomerName { get; set; }\n}\n\npublic class YourCustomer\n{\n public string CustomerName { get; set; }\n}\n <ResourceDictionary \n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n xmlns:local=\"clr-namespace:WpfApplication1\"\n >\n <DataTemplate x:Key=\"MyCustomerTemplate\">\n <Grid>\n <Grid.RowDefinitions>\n <RowDefinition Height=\"Auto\"/>\n <RowDefinition Height=\"150\"/>\n </Grid.RowDefinitions>\n <TextBlock Text=\"My Customer Template\"/>\n <ListBox ItemsSource=\"{Binding}\"\n DisplayMemberPath=\"CustomerName\"\n Grid.Row=\"1\"/>\n </Grid>\n </DataTemplate>\n\n <DataTemplate x:Key=\"YourCustomerTemplate\">\n <Grid>\n <Grid.RowDefinitions>\n <RowDefinition Height=\"Auto\"/>\n <RowDefinition Height=\"150\"/>\n </Grid.RowDefinitions>\n <TextBlock Text=\"Your Customer Template\"/>\n <ListBox ItemsSource=\"{Binding}\"\n DisplayMemberPath=\"CustomerName\"\n Grid.Row=\"1\"/>\n </Grid>\n </DataTemplate>\n</ResourceDictionary>\n <Window \n x:Class=\"WpfApplication1.Window1\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Title=\"Window1\" \n Height=\"300\" \n Width=\"300\"\n xmlns:local=\"clr-namespace:WpfApplication1\"\n >\n <Grid>\n <Grid.Resources>\n <local:CustomerTemplateSelector x:Key=\"templateSelector\"/>\n </Grid.Resources>\n <ContentControl \n Content=\"{Binding}\" \n ContentTemplateSelector=\"{StaticResource templateSelector}\" \n />\n </Grid>\n</Window>\n public partial class Window1\n{\n public Window1()\n {\n InitializeComponent();\n ObservableCollection<MyCustomer> myCustomers\n = new ObservableCollection<MyCustomer>()\n {\n new MyCustomer(){CustomerName=\"Paul\"},\n new MyCustomer(){CustomerName=\"John\"},\n new MyCustomer(){CustomerName=\"Mary\"}\n };\n\n ObservableCollection<YourCustomer> yourCustomers\n = new ObservableCollection<YourCustomer>()\n {\n new YourCustomer(){CustomerName=\"Peter\"},\n new YourCustomer(){CustomerName=\"Chris\"},\n new YourCustomer(){CustomerName=\"Jan\"}\n };\n //DataContext = myCustomers;\n DataContext = yourCustomers;\n }\n}\n" }, { "answer_id": 4047863, "author": "Claudiu Mihaila", "author_id": 167350, "author_profile": "https://Stackoverflow.com/users/167350", "pm_score": 4, "selected": false, "text": "public class StringList : List<String>{}\n" }, { "answer_id": 40545499, "author": "Mike de Klerk", "author_id": 1567665, "author_profile": "https://Stackoverflow.com/users/1567665", "pm_score": 0, "selected": false, "text": "public class MyType : List<int> { }\n <DataTemplate DataType={x:Type myNamespace:MyType}>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185349", "https://Stackoverflow.com", "https://Stackoverflow.com/users/615/" ]
185,378
<p>What is the regular expression to match strings (in this case, file names) that start with 'Run' and have a filename extension of '.py'?</p> <p>The regular expression should match any of the following:</p> <pre><code>RunFoo.py RunBar.py Run42.py </code></pre> <p>It should not match:</p> <pre><code>myRunFoo.py RunBar.py1 Run42.txt </code></pre> <p>The SQL equivalent of what I am looking for is <code>... LIKE 'Run%.py' ...</code>.</p>
[ { "answer_id": 185387, "author": "moo", "author_id": 23107, "author_profile": "https://Stackoverflow.com/users/23107", "pm_score": 0, "selected": false, "text": "/^Run[\\w]*?\\.py$/\n" }, { "answer_id": 185388, "author": "Rob Howard", "author_id": 3528, "author_profile": "https://Stackoverflow.com/users/3528", "pm_score": 3, "selected": false, "text": "/^Run.*\\.py$/\n import re\nre.match(r\"^Run.*\\.py$\", stringtocheck)\n re.match(r\"^Run.*\\.py$\", stringtocheck, re.I)\n" }, { "answer_id": 185393, "author": "imjoevasquez", "author_id": 24630, "author_profile": "https://Stackoverflow.com/users/24630", "pm_score": 0, "selected": false, "text": "^Run.*\\.py$\n" }, { "answer_id": 185397, "author": "Brian", "author_id": 9493, "author_profile": "https://Stackoverflow.com/users/9493", "pm_score": 7, "selected": true, "text": "re.match(r'Run.*\\.py$')\n filename.startswith(\"Run\") and filename.endswith(\".py\")\n" }, { "answer_id": 185583, "author": "John Fouhy", "author_id": 15154, "author_profile": "https://Stackoverflow.com/users/15154", "pm_score": 2, "selected": false, "text": ">>> import re\n>>> regex = '^Run(?P<name>.*)\\.py$'\n>>> m = re.match(regex, 'RunFoo.py')\n>>> m.group('name')\n'Foo'\n" }, { "answer_id": 185593, "author": "Jerub", "author_id": 14648, "author_profile": "https://Stackoverflow.com/users/14648", "pm_score": 4, "selected": false, "text": "import os\nfor filename in os.listdir(dirname):\n root, ext = os.path.splitext(filename)\n if root.startswith('Run') and ext == '.py':\n print filename\n" }, { "answer_id": 186927, "author": "Simon Peverett", "author_id": 6063, "author_profile": "https://Stackoverflow.com/users/6063", "pm_score": 3, "selected": false, "text": "import os, glob\nfiles = glob.glob( \"\".join([ os.getcwd(), \"\\\\Run*.py\"]) )\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185378", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4872/" ]
185,381
<p>I have some System.Diagnotics.Processes to run. I'd like to call the close method on them automatically. Apparently the "using" keyword does this for me.</p> <p>Is this the way to use the using keyword?</p> <pre><code>foreach(string command in S) // command is something like "c:\a.exe" { try { using(p = Process.Start(command)) { // I literally put nothing in here. } } catch (Exception e) { // notify of process failure } } </code></pre> <p>I'd like to start multiple processes to run concurrently.</p>
[ { "answer_id": 185419, "author": "JB King", "author_id": 8745, "author_profile": "https://Stackoverflow.com/users/8745", "pm_score": 0, "selected": false, "text": "try\n{\n foreach(string command in S) // command is something like \"c:\\a.exe\"\n {\n using(p = Process.Start(command))\n {\n // I literally put nothing in here.\n }\n\n } \n}\ncatch (Exception e)\n{\n // notify of process failure\n}\n" }, { "answer_id": 185449, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 5, "selected": true, "text": "using(p = Process.Start(command))\n Process IDisposable Close Dispose Close Close p.Kill() p.WaitForExit() WaitHandle.WaitAll WaitHandle System.Diagnostics.Process WaitForMultipleObjects [System.Runtime.InteropServices.DllImport( \"kernel32.dll\" )]\nstatic extern uint WaitForMultipleObjects( uint nCount, IntPtr[] lpHandles, bool bWaitAll, uint dwMilliseconds );\n\nstatic void Main( string[] args )\n{\n var procs = new Process[] {\n Process.Start( @\"C:\\Program Files\\ruby\\bin\\ruby.exe\", \"-e 'sleep 2'\" ),\n Process.Start( @\"C:\\Program Files\\ruby\\bin\\ruby.exe\", \"-e 'sleep 3'\" ),\n Process.Start( @\"C:\\Program Files\\ruby\\bin\\ruby.exe\", \"-e 'sleep 4'\" ) };\n // all started asynchronously in the background\n\n var handles = procs.Select( p => p.Handle ).ToArray();\n WaitForMultipleObjects( (uint)handles.Length, handles, true, uint.MaxValue ); // uint.maxvalue waits forever\n\n}\n" }, { "answer_id": 185636, "author": "Robert Paulson", "author_id": 14033, "author_profile": "https://Stackoverflow.com/users/14033", "pm_score": 2, "selected": false, "text": "using(Writer writer = new Writer())\n{\n writer.Write(\"Hello\");\n}\n Writer writer = null;\ntry\n{\n writer = new Writer();\n writer.Write(\"Hello\");\n}\nfinally\n{\n if( writer != null)\n {\n ((IDisposable)writer).Dispose();\n }\n}\n using p p.WaitForExit() List<System.Diagnostics.Process> processList = new List<System.Diagnostics.Process>();\n\ntry\n{\n foreach (string command in Commands)\n {\n processList.Add(System.Diagnostics.Process.Start(command));\n }\n\n // loop until all spawned processes Exit normally.\n while (processList.Any())\n {\n System.Threading.Thread.Sleep(1000); // wait and see.\n List<System.Diagnostics.Process> finished = (from o in processList\n where o.HasExited\n select o).ToList();\n\n processList = processList.Except(finished).ToList();\n foreach (var p in finished)\n {\n // could inspect exit code and exit time.\n // note many properties are unavailable after process exits\n p.Close();\n }\n }\n}\ncatch (Exception ex)\n{\n // log the exception\n throw;\n}\nfinally\n{\n foreach (var p in processList)\n {\n if (p != null)\n {\n //if (!p.HasExited)\n // processes will still be running\n // but CloseMainWindow() or Kill() can throw exceptions\n p.Dispose();\n }\n\n }\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185381", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
185,384
<p>While working on a C# app I just noticed that in several places static initializers have dependencies on each other like this:</p> <pre><code>static private List&lt;int&gt; a = new List&lt;int&gt;() { 0 }; static private List&lt;int&gt; b = new List&lt;int&gt;() { a[0] }; </code></pre> <p>Without doing anything special that worked. Is that just luck? Does C# have rules to resolve this?</p> <p><strong>Edit:</strong> (re: Panos) In a file lexical order seems to be king? what about across files?</p> <p>In looking I tried a cyclical dependency like this:</p> <pre><code>static private List&lt;int&gt; a = new List&lt;int&gt;() { b[0] }; static private List&lt;int&gt; b = new List&lt;int&gt;() { a[0] }; </code></pre> <p>and the program didn't run the same (the test suit failed across the board and I didn't look further).</p>
[ { "answer_id": 185409, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 5, "selected": true, "text": "static private List<int> a = new List<int>() { 1 };\nstatic private List<int> b = new List<int>() { a[0] };\n NullReferenceException static private List<int> a = new List<int>() { b[0] };\nstatic private List<int> b = new List<int>() { 1 };\n public class A {\n public static List<int> a = new List<int>() { B.b[0] };\n}\npublic class B {\n public static List<int> b = new List<int>() { A.a[0] };\n}\n try { Console.WriteLine(B.b); } catch (Exception e) { Console.WriteLine(e.InnerException.Message.); }\ntry { Console.WriteLine(A.a); } catch (Exception e) { Console.WriteLine(e.InnerException.Message); }\ntry { Console.WriteLine(B.b); } catch (Exception e) { Console.WriteLine(e.InnerException.Message); }\n The type initializer for 'A' threw an exception.\nObject reference not set to an instance of an object.\nThe type initializer for 'A' threw an exception.\n B A a a null b" }, { "answer_id": 185418, "author": "Sam Saffron", "author_id": 17174, "author_profile": "https://Stackoverflow.com/users/17174", "pm_score": 0, "selected": false, "text": "static private List<int> a = new List<int>() { 0 };\nstatic private List<int> b = new List<int>() { a[0] };\n static private List<int> b = new List<int>() { a[0] };\nstatic private List<int> a = new List<int>() { 0 };\n static MyClass()\n{\n a = new List<int>() { 0 };\n b = new List<int>() { a[0] };\n}\n" }, { "answer_id": 185421, "author": "Bryant", "author_id": 10893, "author_profile": "https://Stackoverflow.com/users/10893", "pm_score": 2, "selected": false, "text": "static private List<int> a;\nstatic private List<int> b;\n\nstatic SomeClass()\n{\n a = new List<int>() { 0 };\n b = new List<int>() { a[0] };\n}\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185384", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1343/" ]
185,389
<p>I'm having problems structuring classes in the Model part of an MVC pattern in my Python app. No matter how I turn things, I keep running into circular imports. Here's what I have:</p> <p><strong>Model/__init__p.y</strong></p> <ul> <li>should hold all Model class names so I can do a "from Model import User" e.g. from a Controller or a unit test case</li> </ul> <p><strong>Model/Database.py</strong> </p> <ul> <li>holds Database class</li> <li>needs to import all Model classes to do ORM</li> <li>initialization should be performed on first module import, i.e. no extra init calls or instantiations (all methods on Database class are @classmethods)</li> </ul> <p><strong>Model/User.py</strong></p> <ul> <li>contains User model class</li> <li>needs access to Database class to do queries</li> <li>should inherit from base class common to all Model classes to share functionality (database persistency methods, parameter validation code etc.)</li> </ul> <p>I have yet to see a real world Python app employing MVC, so my approach is probably un-Pythonic (and possibly a language-agnostic mess on top of that...) - any suggestions on how to solve this?</p> <p>Thanks, Simon</p>
[ { "answer_id": 185411, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "__init__.py" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22404/" ]
185,391
<p>In ASP.NET, I have an XML file (within my project) that I would like to deserialize. FileStream objects do not allow you to open a file via URL. </p> <p>What is the easiest way to open the file so that I can deserialize it? </p>
[ { "answer_id": 185411, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": false, "text": "__init__.py" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
185,423
<p>I'm working on an application that is implemented as an HTA. I have a series of links that I would like to have open in the system's default web browser. Using <code>&lt;a href="url" target="_blank"&gt;</code> opens the link in IE regardless of the default browser.</p> <p>Is there a way to use the default browser? Using JavaScript is an option.</p>
[ { "answer_id": 185581, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 6, "selected": true, "text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html lang=\"en\">\n<head>\n <title>HTA Test</title>\n <hta:application applicationname=\"HTA Test\" scroll=\"yes\" singleinstance=\"yes\">\n <script type=\"text/javascript\">\n function openURL()\n {\n var shell = new ActiveXObject(\"WScript.Shell\");\n shell.run(\"http://www.google.com\");\n }\n </script>\n</head>\n<body>\n\n<input type=\"button\" onclick=\"openURL()\" value=\"Open Google\">\n\n</body>\n</html>\n" } ]
2008/10/08
[ "https://Stackoverflow.com/questions/185423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7441/" ]
185,429
<p>I know how to use JSON to create objects, but there doesn't seem to be away to use JSON to create an object that is of a specific object type.</p> <p>Here's an example of an Object and creating an instance of it:</p> <pre><code>Person = function() { }; Person.prototype = { FirstName: null, GetFirstName: function() { return this.FirstName; } }; //Create an instance of the Person Object var me = new Person(); me.FirstName = "Chris"; alert(me.GetFirstName()); //alert the FirstName property </code></pre> <p>Now, I would like to use JSON to create a new Person object so that the GetFirstName function works on it.</p> <p>Here's something like that I'm looking to do (but this code doesn't work):</p> <pre><code>var you = new Person() { FirstName: "Mike" }; // OR var you = new Person{ FirstName: "Mike" }; </code></pre> <p>Is there anyway to use JSON to create an object that is of a specific type?</p> <p>UPDATE: My sample with the Person object is just to simplify the question. In fact, I am unable to modify the constructors of the actual objects that I need to create instances of. The objects are part of a third-party library.</p> <p>UPDATE: Using some of the suggestions below, I was able to figure out a way to create an object that inherits from the original, and accept JSON in it's constructor. This is neat!</p> <pre><code>personWrapper = function(obj){ for(var o in obj){ this[o] = obj[o]; } }; personWrapper.prototype = new Person(); var you = new personWrapper({FirstName: "Chris"}); alert(you.GetFirstName()); alert(you instanceof Person); // returns True - we are successfully inheriting from Person! </code></pre>
[ { "answer_id": 185438, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 5, "selected": true, "text": "function Person() {\n this.loadFromJSON = function(json) {\n this.FirstName = json.FirstName;\n };\n}\n { _className : \"Person\", FirstName : \"Mike\" }\n function buildFromJSON(json) {\n var myObj = new json[\"_className\"]();\n myObj.loadFromJSON(json);\n return myObj;\n}\n Person.prototype.loadFromJSON = function(json) {\n // as above...\n};\n function populateObject(obj, json) {\n for (var i in json) {\n // you might want to put in a check here to test\n // that obj actually has an attribute named i\n obj[i] = json[i];\n }\n}\n" }, { "answer_id": 185443, "author": "Aupajo", "author_id": 10407, "author_profile": "https://Stackoverflow.com/users/10407", "pm_score": 2, "selected": false, "text": "var you = new Person({ firstName: 'Mike' });\n" }, { "answer_id": 185892, "author": "harley.333", "author_id": 26259, "author_profile": "https://Stackoverflow.com/users/26259", "pm_score": 2, "selected": false, "text": "function yourWrapper(obj) {\n theirObject.call(this);\n for (var s in obj) {\n this[s] = obj[s];\n }\n}\nyourWrapper.prototype = new theirObject();\n" } ]
2008/10/09
[ "https://Stackoverflow.com/questions/185429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7831/" ]
185,445
<p>My company has login integration with GroupWise, and Exchange 5.5/2000+. The Exchange 5.5/GroupWise logic is done using wldap32.dll (win32), and so the login code is in a managed c++ class. When the configuration tool (or the backend service) tries to load the dll built off this managed c++ project on my XP development box, it works fine. On QA/Customer Windows 2003 boxes, a FileLoadException is thrown.</p> <p>First off, this used to work fine. Secondly, I've validated the same working code on my box fails on the qa box. </p> <p>How can I track down the cause of this exception?</p>
[ { "answer_id": 185580, "author": "Henk", "author_id": 4613, "author_profile": "https://Stackoverflow.com/users/4613", "pm_score": 2, "selected": true, "text": "depends.exe" } ]
2008/10/09
[ "https://Stackoverflow.com/questions/185445", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18313/" ]
185,447
<p>Okay, I got this small program which tags (as in ID3v2.4 etc.) some music files. Now I want the user to have the option to move and/or rename those tagged files if he/she wishes to.</p> <p>Considering that I am trying to keep a fairly clean and loosely coupled design in this system (even though extensibility is not really important here, it's just fun), would you just call <code>someFileInfoObject.Move(someWhere)</code> where <code>someWhere</code> is the applied pattern or would it be wise to implement some classes - maybe MoveFileStrategy, RenameFileStrategy (I know that moving/renaming can be considered the same in some systems, but I want them to be enabled separately) - which figure out the destination and whether the strategy should be applied when an <code>Apply(FileInfo file)</code> method or so is called.</p> <p>If you think that some strategy classes may be useful, do you have any suggestion on a good implementation strategy?</p> <p>As already said, over-engineering is not really an issue here, because it is a fun project mainly targeted at getting some programming and engineering practice. :)</p>
[ { "answer_id": 185580, "author": "Henk", "author_id": 4613, "author_profile": "https://Stackoverflow.com/users/4613", "pm_score": 2, "selected": true, "text": "depends.exe" } ]
2008/10/09
[ "https://Stackoverflow.com/questions/185447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11963/" ]