qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
176,411
<p>A question about different methods of outputting html from PHP; what are the performance differences between these:</p> <p>Method 1 - variable concatenation</p> <pre><code>$html = ''; $html .= '&lt;ul&gt;'; for ($k = 1; $k &lt; = 1000; $k++){ $html .= '&lt;li&gt; This is list item #'.$k.'&lt;/li&gt;'; } $html .= '&lt;/ul&gt;'; echo $html; </code></pre> <p>Method 2 - output buffering</p> <pre><code>ob_start(); echo '&lt;ul&gt;'; for ($k = 1; $k &lt; = 1000; $k++){ echo '&lt;li&gt; This is list item #',$k,'&lt;/li&gt;'; } echo '&lt;/ul&gt;'; </code></pre> <p>I suspect you get some performance hit from continually modifying and enlarging a variable; is that correct?</p> <p>Cheers!</p> <p>Thanks GaryF, but I don't want an answer about architecture - this question is about performance. There seem to be some different opinions / testing about which one is faster, which is why there is not an accepted answer as yet.</p>
[ { "answer_id": 176434, "author": "Darryl Hein", "author_id": 5441, "author_profile": "https://Stackoverflow.com/users/5441", "pm_score": 2, "selected": false, "text": "<?php" }, { "answer_id": 176458, "author": "Erik van Brakel", "author_id": 909, "author_profile": "https://Stackoverflow.com/users/909", "pm_score": 1, "selected": false, "text": "$html = array();\n$html[] = '<ul>';\nfor ($k = 1; $k < = 1000; $k++){\n $html[] = '<li> This is list item #';\n $html[] = $k;\n $html[] = '</li>';\n}\n$html[] = '</ul>';\necho implode('',$html);\n" }, { "answer_id": 419195, "author": "too much php", "author_id": 28835, "author_profile": "https://Stackoverflow.com/users/28835", "pm_score": 3, "selected": true, "text": "echo" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176411", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2027/" ]
176,440
<p>I have a filter in a combobox with a number of entries. Instead of filtering the datagrid with an exact match, I would like to take the selected value and only display records where the selected value is contained in the datafield. For example: the user selects a value of "New" and the datagrid displays records where the contents of the record could be "New User", "New Person", "This one is New" etc. I think that I need to use RegExp, but I cant work out how to get it to work. Thanks in advance, S... </p>
[ { "answer_id": 176606, "author": "JustLogic", "author_id": 21664, "author_profile": "https://Stackoverflow.com/users/21664", "pm_score": 2, "selected": false, "text": " public function filter(item:Object):Boolean{\n var result:Boolean=false;\n if (item.name.toUpperCase().indexOf(cbo.selectedLabel.toUpperCase()) >= 0)\n result=true;\n return result;\n }\n" }, { "answer_id": 2140343, "author": "Big 'B'", "author_id": 242171, "author_profile": "https://Stackoverflow.com/users/242171", "pm_score": 2, "selected": false, "text": " private function filterByTerritory(item:Object):Boolean{\n tempString = item.name;\n tempString_Name = item.territory;\n if( (tempString.indexOf(sampleFilter.text,0) != -1) && \n (tempString_Name.indexOf(terrFilterTxt.text,0) != -1)){\n return true;\n }\n else{\n return false;\n }\n } \n private function doFilter():void{\n if( (sampleFilter.text.length == 0) && \n (terrFilterTxt.text.length == 0)) {\n myData.filterFunction == null;\n }\n else{\n myData.filterFunction = filterByTerritory;\n }\n myData.refresh();\n }\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176440", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25463/" ]
176,446
<p>Why do I get compiler errors with this Java code?</p> <pre><code>1 public List&lt;? extends Foo&gt; getFoos() 2 { 3 List&lt;? extends Foo&gt; foos = new ArrayList&lt;? extends Foo&gt;(); 4 foos.add(new SubFoo()); 5 return foos; 6 }</code></pre> <p>Where 'SubFoo' is a concrete class that implements Foo, and Foo is an interface.</p> <p>Errors I get with this code:</p> <ul> <li>On Line 3: "Cannot instantiate ArrayList&lt;? extends Foo&gt;"</li> <li>On Line 4: "The method add(capture#1-of ? extends Foo) in the type List&lt;capture#1-of ? extends Foo&gt; is not applicable for the arguments (SubFoo)"</li> </ul> <p><b>Update:</b> Thanks to Jeff C, I can change Line 3 to say "new ArrayList&lt;Foo&gt;();". But I'm still having the issue with Line 4.</p>
[ { "answer_id": 176478, "author": "erickson", "author_id": 3474, "author_profile": "https://Stackoverflow.com/users/3474", "pm_score": 6, "selected": true, "text": "1 public List<? extends Foo> getFoos()\n2 {\n3 List<Foo> foos = new ArrayList<Foo>(); /* Or List<SubFoo> */\n4 foos.add(new SubFoo());\n5 return foos;\n6 }\n" }, { "answer_id": 176484, "author": "SCdF", "author_id": 1666, "author_profile": "https://Stackoverflow.com/users/1666", "pm_score": 2, "selected": false, "text": "public List<? extends Foo> getFoos() {\n List<Foo> foos = new ArrayList<Foo>();\n foos.add(new SubFoo());\n return foos;\n}\n" }, { "answer_id": 176490, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "public List<Foo> getFoos() {\n List<Foo> foos = new ArrayList<Foo>();\n foos.add(new SubFoo());\n return foos;\n}\n" }, { "answer_id": 5406268, "author": "zslevi", "author_id": 95899, "author_profile": "https://Stackoverflow.com/users/95899", "pm_score": 2, "selected": false, "text": " List<SubFoo> sfoo = new ArrayList<SubFoo>();\n List<Foo> foo;\n List<? extends Foo> tmp;\n\n tmp = sfoo;\n foo = (List<Foo>) tmp;\n" }, { "answer_id": 11501363, "author": "Glen Best", "author_id": 1528401, "author_profile": "https://Stackoverflow.com/users/1528401", "pm_score": 4, "selected": false, "text": "List< Foo>" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176446", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2197/" ]
176,459
<p>Here are the declarations of the variables:</p> <pre><code>string strFirstName; string strLastName; string strAddress; string strCity; string strState; double dblSalary; string strGender; int intAge; </code></pre> <p>...Do some "cin" statements to get data...</p> <pre><code>retcode = SQLPrepare(StatementHandle, (SQLCHAR *)"INSERT INTO EMPLOYEE ([FirstName], [LastName], [Address], [City], [State], [Salary], [Gender],[Age]) VALUES (?,?,?,?,?,?,?,?)", SQL_NTS); retcode = SQLBindParameter(StatementHandle, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 50, 0 &amp;strFirstName,0, NULL); retcode = SQLBindParameter(StatementHandle, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 50, 0, &amp;strLastName,0, NULL); retcode = SQLBindParameter(StatementHandle, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 30, 0, &amp;strAddress,0, NULL); retcode = SQLBindParameter(StatementHandle, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 30, 0, &amp;strCity,0, NULL); retcode = SQLBindParameter(StatementHandle, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 3, 0, &amp;strState,0, NULL); retcode = SQLBindParameter(StatementHandle, 6, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &amp;dblSalary,0, NULL); retcode = SQLBindParameter(StatementHandle, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 2, 0, &amp;strGender,0, NULL); retcode = SQLBindParameter(StatementHandle, 8, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &amp;intAge,0, NULL); retcode = SQLExecute(StatementHandle); </code></pre> <p>The int and double work fine and get stored in the table...but I can't figure out how to get the strings to store...</p>
[ { "answer_id": 176509, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 4, "selected": true, "text": "ParameterValuePtr" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25642/" ]
176,476
<p>I've been using htmldoc for a while, but I've run into some fairly serious limitations. I need the end solution to work on a Linux box. I'll be calling this library/utility/application from a Perl app, so any Perl interfaces would be a bonus.</p>
[ { "answer_id": 29335384, "author": "MrTux", "author_id": 3906760, "author_profile": "https://Stackoverflow.com/users/3906760", "pm_score": 1, "selected": false, "text": "phantomjs rasterize.js 'http://en.wikipedia.org/w/index.php?title=Jakarta&printable=yes' jakarta.pdf\n" }, { "answer_id": 36924801, "author": "andrew-e", "author_id": 582326, "author_profile": "https://Stackoverflow.com/users/582326", "pm_score": 5, "selected": false, "text": "weasyprint input.html output.pdf\n" }, { "answer_id": 45671273, "author": "Roben", "author_id": 978497, "author_profile": "https://Stackoverflow.com/users/978497", "pm_score": 4, "selected": false, "text": "chrome --headless --disable-gpu --print-to-pdf file:///path/to/myfile.html" }, { "answer_id": 55436923, "author": "Brad Parks", "author_id": 26510, "author_profile": "https://Stackoverflow.com/users/26510", "pm_score": 1, "selected": false, "text": "ebook-convert" }, { "answer_id": 55592265, "author": "Cyril N.", "author_id": 330867, "author_profile": "https://Stackoverflow.com/users/330867", "pm_score": 1, "selected": false, "text": "\"source\"" }, { "answer_id": 61090446, "author": "Daniel Winterstein", "author_id": 346629, "author_profile": "https://Stackoverflow.com/users/346629", "pm_score": 0, "selected": false, "text": "unoconv" }, { "answer_id": 63046047, "author": "Lance", "author_id": 169992, "author_profile": "https://Stackoverflow.com/users/169992", "pm_score": 0, "selected": false, "text": "$ npm install @lancejpollard/act -g\n$ act convert tmp/index.html -o tmp/index.pdf -w 2000px -h 3000px\n" }, { "answer_id": 67034856, "author": "creativecoding", "author_id": 8952900, "author_profile": "https://Stackoverflow.com/users/8952900", "pm_score": 0, "selected": false, "text": "ebook-convert" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176476", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2901/" ]
176,479
<p>I have a image upload form that should take image types (PNG, JPEG, GIF), resize it and then save it to a path. </p> <p>For some reason I can't get the PNG file types to work, it works fine with JPEG/GIF and the file is copied so it looks like it's something to do with how I'm creating the PNG. </p> <p>Does PNG creation in PHP require different parameters or options? Some sample code of lines that do image creation:</p> <pre><code>$src = imagecreatefrompng($uploadedfile); imagecreatetruecolor($newWidth,$newHeight) imagecopyresampled($tmp,$src,0,0,0,0,$newWidth,$newHeight,$width,$height); imagepng($tmp,$destinationPath."/".$destinationFile,100); </code></pre> <p>The same commands work for JPG and GIF.</p>
[ { "answer_id": 176513, "author": "DreamWerx", "author_id": 15487, "author_profile": "https://Stackoverflow.com/users/15487", "pm_score": 2, "selected": false, "text": "GD Support enabled\nGD Version bundled (2.0.28 compatible) \nPNG Support enabled \n" }, { "answer_id": 176610, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "imagejpg()" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176479", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
176,504
<p>New to visual studio and programing in general.</p> <p>I am starting to work on a asp.net project. At home I have a computer running Windows 2008 Server with SQL 2008 and Visual 2008 running.</p> <p>I want to install the same thing on my laptop win2008/sql2008/vs2008 so I can take it with me on the go.</p> <p>What I want to know is how would I synchronized the two, where projects would syncrhonized to my laptop and I can take it on the go, then when i return and connect it to my network, it synchronizes back to my main workstation so the two are always the same?</p>
[ { "answer_id": 176894, "author": "Pablo Venturino", "author_id": 16732, "author_profile": "https://Stackoverflow.com/users/16732", "pm_score": 0, "selected": false, "text": "\\\\my_workstation\\path\\to\\project" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25631/" ]
176,512
<p>In short, how do you unit test an error condition such as EINTR on a system call.</p> <p>One particular example I'm working on, which could be a case all by itself, is whether it's necessary to call fclose again when it returns EOF with (errno==EINTR). The behavior depends on the implementation of fclose:</p> <pre><code>// Given an open FILE *fp while (fclose(fp)==EOF &amp;&amp; errno==EINTR) { errno = 0; } </code></pre> <p>This call can be unsafe if fp freed when EINTR occurs. How can I test the error handling for when (errno==EINTR)?</p>
[ { "answer_id": 176821, "author": "bmdhacks", "author_id": 14032, "author_profile": "https://Stackoverflow.com/users/14032", "pm_score": 2, "selected": false, "text": "int scull_release(struct inode *inode, struct file *filp)\n{\n return -EINTR;\n}\n" }, { "answer_id": 177001, "author": "mhawke", "author_id": 21945, "author_profile": "https://Stackoverflow.com/users/21945", "pm_score": 1, "selected": false, "text": "fclose()" }, { "answer_id": 277880, "author": "philant", "author_id": 18804, "author_profile": "https://Stackoverflow.com/users/18804", "pm_score": 1, "selected": false, "text": "fclose()" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24310/" ]
176,514
<p>What is meant by <code>nvarchar</code>?</p> <p>What is the difference between <code>char</code>, <code>nchar</code>, <code>varchar</code>, and <code>nvarchar</code> in SQL Server?</p>
[ { "answer_id": 176565, "author": "Brian Kim", "author_id": 5704, "author_profile": "https://Stackoverflow.com/users/5704", "pm_score": 11, "selected": true, "text": "nchar" }, { "answer_id": 1660254, "author": "ss.", "author_id": 200846, "author_profile": "https://Stackoverflow.com/users/200846", "pm_score": 4, "selected": false, "text": "char" }, { "answer_id": 8250586, "author": "Martin Smith", "author_id": 73226, "author_profile": "https://Stackoverflow.com/users/73226", "pm_score": 7, "selected": false, "text": "varchar" }, { "answer_id": 17335317, "author": "PeterAllenWebb", "author_id": 21365, "author_profile": "https://Stackoverflow.com/users/21365", "pm_score": 5, "selected": false, "text": "char" }, { "answer_id": 28433910, "author": "Rasel", "author_id": 3926727, "author_profile": "https://Stackoverflow.com/users/3926727", "pm_score": 4, "selected": false, "text": "nchar[(n)]" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176514", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
176,527
<p>I need to enumerate all classes in a package and add them to a List. The non-dynamic version for a single class goes like this:</p> <pre><code>List allClasses = new ArrayList(); allClasses.add(String.class); </code></pre> <p>How can I do this dynamically to add all classes in a package and all its subpackages?</p> <hr> <p><strong><em>Update:</em></strong> Having read the early answers, it's absolutely true that I'm trying to solve another secondary problem, so let me state it. And I know this is possible since other tools do it. See new question <a href="https://stackoverflow.com/questions/176913/how-can-i-run-all-unit-tests-except-those-ending-in-integrationtest-in-my-intel">here</a>. </p> <p><strong><em>Update:</em></strong> Reading this again, I can see how it's being misread. I'm looking to enumerate all of MY PROJECT'S classes from the file system after compilation. </p>
[ { "answer_id": 3527428, "author": "Dave Dopson", "author_id": 407731, "author_profile": "https://Stackoverflow.com/users/407731", "pm_score": 6, "selected": true, "text": "private static ArrayList<Class<?>> getClassesForPackage(Package pkg) {\n String pkgname = pkg.getName();\n ArrayList<Class<?>> classes = new ArrayList<Class<?>>();\n // Get a File object for the package\n File directory = null;\n String fullPath;\n String relPath = pkgname.replace('.', '/');\n System.out.println(\"ClassDiscovery: Package: \" + pkgname + \" becomes Path:\" + relPath);\n URL resource = ClassLoader.getSystemClassLoader().getResource(relPath);\n System.out.println(\"ClassDiscovery: Resource = \" + resource);\n if (resource == null) {\n throw new RuntimeException(\"No resource for \" + relPath);\n }\n fullPath = resource.getFile();\n System.out.println(\"ClassDiscovery: FullPath = \" + resource);\n\n try {\n directory = new File(resource.toURI());\n } catch (URISyntaxException e) {\n throw new RuntimeException(pkgname + \" (\" + resource + \") does not appear to be a valid URL / URI. Strange, since we got it from the system...\", e);\n } catch (IllegalArgumentException e) {\n directory = null;\n }\n System.out.println(\"ClassDiscovery: Directory = \" + directory);\n\n if (directory != null && directory.exists()) {\n // Get the list of the files contained in the package\n String[] files = directory.list();\n for (int i = 0; i < files.length; i++) {\n // we are only interested in .class files\n if (files[i].endsWith(\".class\")) {\n // removes the .class extension\n String className = pkgname + '.' + files[i].substring(0, files[i].length() - 6);\n System.out.println(\"ClassDiscovery: className = \" + className);\n try {\n classes.add(Class.forName(className));\n } \n catch (ClassNotFoundException e) {\n throw new RuntimeException(\"ClassNotFoundException loading \" + className);\n }\n }\n }\n }\n else {\n try {\n String jarPath = fullPath.replaceFirst(\"[.]jar[!].*\", \".jar\").replaceFirst(\"file:\", \"\");\n JarFile jarFile = new JarFile(jarPath); \n Enumeration<JarEntry> entries = jarFile.entries();\n while(entries.hasMoreElements()) {\n JarEntry entry = entries.nextElement();\n String entryName = entry.getName();\n if(entryName.startsWith(relPath) && entryName.length() > (relPath.length() + \"/\".length())) {\n System.out.println(\"ClassDiscovery: JarEntry: \" + entryName);\n String className = entryName.replace('/', '.').replace('\\\\', '.').replace(\".class\", \"\");\n System.out.println(\"ClassDiscovery: className = \" + className);\n try {\n classes.add(Class.forName(className));\n } \n catch (ClassNotFoundException e) {\n throw new RuntimeException(\"ClassNotFoundException loading \" + className);\n }\n }\n }\n } catch (IOException e) {\n throw new RuntimeException(pkgname + \" (\" + directory + \") does not appear to be a valid package\", e);\n }\n }\n return classes;\n}\n" }, { "answer_id": 32764815, "author": "Luke Hutchison", "author_id": 3950982, "author_profile": "https://Stackoverflow.com/users/3950982", "pm_score": 3, "selected": false, "text": "List<String> classNames;\ntry (ScanResult scanResult = new ClassGraph().whitelistPackages(\"my.package\")\n .enableClassInfo().scan()) {\n classNames = scanResult.getAllClasses().getNames();\n}\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13041/" ]
176,545
<p>I am going to be starting a javascript reporting engine for my website, and have started some prototyping using MooTools. I really like being able to do things like this:</p> <pre><code>function showLeagues(leagues) { var leagueList = $("leagues"); leagueList.empty(); for(var i = 0; i&lt;leagues.length; ++i) { var listItem = getLeagueListElement(leagues[i]); leagueList.adopt(listItem); } } function getLeagueListElement(league) { var listItem = new Element('li'); var newElement = new Element('a', { 'html': league.name, 'href': '?league='+league.key, 'events': { 'click': function() { showLeague(league); return false; } } }); listItem.adopt(newElement); return listItem; } </code></pre> <p>From what I've seen, jQuery's "adopt" type methods only take html strings or DOM Elements. Is there any jQuery equivalent to MooTools' <a href="http://mootools.net/docs/Element/Element#Element:constructor" rel="nofollow noreferrer">Element</a>? <hr/> EDIT: The big thing I'm looking for here is the programmatic attachment of my click event to the link.</p>
[ { "answer_id": 176567, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 2, "selected": false, "text": "function showLeagues(leagues) {\n var $leagueList = $(\"#leagues\");\n $leagueList.empty();\n $.each(leagues, function (index, league) {\n $leagueList.append(getLeagueListElement(league));\n });\n}\n\nfunction getLeagueListElement(league) {\n return $('<li></li>')\n .append($('<a></a>')\n .html(league.name)\n .attr('href', '?league=' + league.key)\n .click(function() {\n showLeague(league);\n return false;\n })\n )\n ;\n}\n" }, { "answer_id": 176744, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 4, "selected": true, "text": " document.createElement('li')\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/96/" ]
176,559
<p>In the Google C++ Style Guide, there's a section on <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Operator_Overloading" rel="noreferrer">Operator Overloading</a> that has a curious statement:</p> <blockquote> <p>Overloading also has surprising ramifications. For instance, you can't forward declare classes that overload <code>operator&amp;</code>.</p> </blockquote> <p>This seems incorrect, and I haven't been able to find any code that causes GCC to have a problem with it. Does anyone know what that statement is referring to?</p>
[ { "answer_id": 176581, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 0, "selected": false, "text": "class A;\n\nvoid f(A& x) {\n A* xPointer = &x;\n}\n" }, { "answer_id": 176640, "author": "Pete Kirkham", "author_id": 1527, "author_profile": "https://Stackoverflow.com/users/1527", "pm_score": 4, "selected": false, "text": "#include <iostream>\n\nclass Foo;\n\nvoid bar (Foo& foo) {\n std::cout << &foo << std::endl;\n}\n\nclass Foo {\npublic:\n bool operator & () { return true; }\n};\n\nvoid baz (Foo& foo) {\n std::cout << &foo << std::endl;\n}\n\nint main () {\n Foo foo;\n\n bar(foo);\n baz(foo);\n\n return 0;\n}\n" }, { "answer_id": 176653, "author": "Max Lybbert", "author_id": 10593, "author_profile": "https://Stackoverflow.com/users/10593", "pm_score": 3, "selected": false, "text": "int x = 5;\nint* p = &x; // unary &\nif (x & 1) // binary &\n" }, { "answer_id": 176779, "author": "Richard Corden", "author_id": 11698, "author_profile": "https://Stackoverflow.com/users/11698", "pm_score": 0, "selected": false, "text": "operator&" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12193/" ]
176,572
<p>I have a UI widget that needs to be put in an IFRAME both for performance reasons and so we can syndicate it out to affiliate sites easily. The UI for the widget includes tool-tips that display over the top of other page content. See screenshot below or <strong><a href="http://www.bookabach.co.nz/" rel="noreferrer">go to the site</a></strong> to see it in action. Is there any way to make content from within the IFRAME overlap the parent frame's content?</p> <p><img src="https://i.stack.imgur.com/8rAnj.png" alt="Tool-tip content needs to overlap parent frame content"></p>
[ { "answer_id": 176670, "author": "Luke Bennett", "author_id": 17602, "author_profile": "https://Stackoverflow.com/users/17602", "pm_score": 1, "selected": false, "text": "<script>" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11577/" ]
176,625
<p>I have the following query in iSeries SQL which I output to a file.</p> <pre><code>SELECT SSLOTMAK, SSLOTMDL, SSLOTYER, sum(SSCOUNT) FROM prqhdrss GROUP BY SSLOTMAK, SSLOTMDL, SSLotyer HAVING sum(SSCOUNT) &gt; 4 ORDER BY SSLOTMAK, SSLOTMDL, SSLOTYER </code></pre> <p>When I run it, the field created be the sum(SSCOUNT) is a 31 Packed field. This does not allow me to send it to my PC. How can I force SQL to create the field as a non-packed field.</p>
[ { "answer_id": 177635, "author": "pmg", "author_id": 25324, "author_profile": "https://Stackoverflow.com/users/25324", "pm_score": 3, "selected": true, "text": "SELECT SSLOTMAK, SSLOTMDL, SSLOTYER, cast(sum(SSCOUNT) as integer)\nFROM prqhdrss\nGROUP BY SSLOTMAK, SSLOTMDL, SSLotyer\nHAVING sum(SSCOUNT) > 4\nORDER BY SSLOTMAK, SSLOTMDL, SSLOTYER\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11270/" ]
176,627
<p>I run into this quite often where a new page is supposedly "tested" and ready to go. But as soon as I change the page from http to https (secure) mode I get the "This page contains both secure and nonsecure items." error.</p> <p>Usually I can find the problem and fix it pretty quick. Today is different. I've checked every image reference and every javascript reference and their source and haven't found anything that should be causing this error.</p> <p>Are there any developer tools or techniques that can point out specifically what is causing this error?</p>
[ { "answer_id": 176651, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 1, "selected": false, "text": "<script>" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747/" ]
176,673
<p>If I have a datetime field, how do I get just records created later than a certain time, ignoring the date altogether?</p> <p>It's a logging table, it tells when people are connecting and doing something in our application. I want to find out how often people are on later than 5pm. </p> <p>(Sorry - it is SQL Server. But this could be useful for other people for other databases)</p>
[ { "answer_id": 176684, "author": "Thilo", "author_id": 14955, "author_profile": "https://Stackoverflow.com/users/14955", "pm_score": 3, "selected": false, "text": "SELECT * FROM TABLE \n WHERE TO_CHAR(THE_DATE, 'HH24:MI:SS') BETWEEN '17:00:00' AND '23:59:59';\n" }, { "answer_id": 176686, "author": "Luke Bennett", "author_id": 17602, "author_profile": "https://Stackoverflow.com/users/17602", "pm_score": 5, "selected": true, "text": "select * from myTable where datepart(hh, myDateField) > 17\n" }, { "answer_id": 176689, "author": "thursdaysgeek", "author_id": 22523, "author_profile": "https://Stackoverflow.com/users/22523", "pm_score": 0, "selected": false, "text": "select myfield1, \n myfield2, \n mydatefield\n from mytable\n where datename(hour, mydatefield) > 17\n" }, { "answer_id": 176909, "author": "David Aldridge", "author_id": 6742, "author_profile": "https://Stackoverflow.com/users/6742", "pm_score": 0, "selected": false, "text": "select ...\nfrom ...\nwhere EXTRACT(HOUR FROM my_date) >= 17\n/\n" }, { "answer_id": 176997, "author": "ysth", "author_id": 17389, "author_profile": "https://Stackoverflow.com/users/17389", "pm_score": 2, "selected": false, "text": "where time(datetimefield) > '17:00:00'\n" }, { "answer_id": 193162, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 0, "selected": false, "text": "WHERE EXTEND(dt_column, HOUR TO SECOND) > DATETIME(17:00:00) HOUR TO SECOND\n" }, { "answer_id": 38336513, "author": "Zaxxon", "author_id": 4351706, "author_profile": "https://Stackoverflow.com/users/4351706", "pm_score": 1, "selected": false, "text": "\nDECLARE @TempDate datetime = '1/2/2016 6:28:03 AM'\nSELECT \n @TempDate as PassedInDate, \n CASE \n WHEN CONVERT(nvarchar(30), @TempDate, 108) < '06:30:00' then 'Before 6:30am'\n ELSE 'On or after 6:30am'\n END,\n CASE \n WHEN CONVERT(nvarchar(30), @TempDate, 108) >= '10:30:00' then 'On or after 10:30am'\n ELSE 'Before 10:30am'\n END \n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22523/" ]
176,695
<p>The attached screenshot is from OS X/Firefox 3. Note that the center tab (an image) has a dotted line around it, apparently because it was the most-recently selected tab. Is there a way I can eliminate this dotted line in CSS or JavaScript? (Hmmm...the free image hosting service has reduced the size of the image. But if you could see it, you'd notice a dotted-line select area around the block.)</p> <p><a href="http://www.freeimagehosting.net/uploads/th.fadf78173b.png" rel="nofollow noreferrer">Screen Shot http://www.freeimagehosting.net/uploads/th.fadf78173b.png</a></p>
[ { "answer_id": 176719, "author": "Dave Rutledge", "author_id": 2486915, "author_profile": "https://Stackoverflow.com/users/2486915", "pm_score": 5, "selected": true, "text": "a:active, a:focus { outline-style: none; -moz-outline-style:none; }\n" }, { "answer_id": 176725, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 1, "selected": false, "text": "*,*:hover,*:focus,*:active { outline: 0px none; } \n" }, { "answer_id": 15012369, "author": "AshAndrien", "author_id": 1934951, "author_profile": "https://Stackoverflow.com/users/1934951", "pm_score": 0, "selected": false, "text": "*:focus {outline:0px;} \n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176695", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17307/" ]
176,709
<p>I have a set of configuration items I need to persist to a "human readable" file. These items are in a hierarchy:</p> <pre> Device 1 Name Channel 1 Name Size ... Channel N Name ... Device M Name Channel 1 </pre> <p>Each of these item could be stored in a Dictionary with a string Key and a value. They could also be in a structure/DTO.</p> <p>I don't care about the format of the file as long as it's human readable. It could be XML or it could have something more like INI format</p> <pre> [Header] Key=value Key2=value ... </pre> <p>Is there a way to minimize the amount of boiler plate code I would need to write to manage storing/reading configuration items?</p> <p>Should I just create Data Transfer Objects (DTO)/structures and mark them serializable (Does that generate bloated XML still human readable?)</p> <p>Is there other suggestions?</p> <p>Edit: Not that the software has to <strong>write</strong> as well as <strong>read</strong> the config. That leaves app.config out.</p>
[ { "answer_id": 176776, "author": "Ron Savage", "author_id": 12476, "author_profile": "https://Stackoverflow.com/users/12476", "pm_score": 0, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<configuration>\n<!--****************************************************************\n Config File: FileToExcel_test.cfg\n Author: Ron Savage\n Date: 06/20/2008\n\n Description: \n File to test parsing a file into an Excel workbook.\n\n Modification History: \n Date Init Comment\n 06/20/2008 RS Created.\n******************************************************************-->\n\n<!--********************************************************************\n Global Key Definitions\n********************************************************************-->\n <config key=\"sqlTimeout\" value=\"1800\"/>\n <config key=\"emailSMTPServer\" value=\"smtp-server.austin.rr.com\"/>\n <config key=\"LogFile\" value=\"FiletoExcel_test_{yyyy}{mm}{hh}.log\"/>\n <config key=\"MaxEntries\" value=\"1\"/>\n\n<!--********************************************************************\n Delimiter Configurations\n********************************************************************-->\n <config key=\"pipe\" value=\"|\"/>\n\n\n<!--********************************************************************\n Source / Target Entries\n********************************************************************-->\n <config key=\"source_1\" value=\"FILE, c:\\inetpub\\ftproot\\filetoexcel.txt, pipe, , , , , \"/>\n <config key=\"target_1\" value=\"XLS, REPLACE, c:\\inetpub\\ftproot\\filetoexcel1.xls, , , , , , , ,c:\\inetpub\\ftproot\\filetoexcel_template.xls, ,3\"/>\n <config key=\"notify_1\" value=\"store_error, store_success\"/>\n</configuration>\n" }, { "answer_id": 176845, "author": "David Robbins", "author_id": 19799, "author_profile": "https://Stackoverflow.com/users/19799", "pm_score": 2, "selected": false, "text": "Product product = new Product(); \nproduct.Name = \"Apple\"; \nproduct.Expiry = new DateTime(2008, 12, 28); \nproduct.Price = 3.99M; \nproduct.Sizes = new string[] { \"Small\", \"Medium\", \"Large\" }; \n\nstring json = JavaScriptConvert.SerializeObject(product);\n//{\n// \"Name\": \"Apple\",\n// \"Expiry\": new Date(1230422400000),\n// \"Price\": 3.99,\n// \"Sizes\": [\n// \"Small\",\n// \"Medium\",\n// \"Large\"\n// ]\n//} \n\nProduct deserializedProduct = JavaScriptConvert.DeserializeObject<Product>(json);\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10703/" ]
176,712
<p>I'd like to find the base url of my application, so I can automatically reference other files in my application tree...</p> <p>So given a file config.php in the base of my application, if a file in a subdirectory includes it, knows what to prefix a url with. </p> <pre><code>application/config.php application/admin/something.php application/css/style.css </code></pre> <p>So given that <code>http://www.example.com/application/admin/something.php</code> is accessed, I want it to be able to know that the css file is in <code>$approot/css/style.css</code>. In this case, <code>$approot</code> is "<code>/application</code>" but I'd like it to know if the application is installed elsewhere.</p> <p>I'm not sure if it's possible, many applications (phpMyAdmin, Squirrelmail I think) have to set a config variable to begin with. It would be more user friendly if it just knew.</p>
[ { "answer_id": 176730, "author": "Jay", "author_id": 20840, "author_profile": "https://Stackoverflow.com/users/20840", "pm_score": 2, "selected": false, "text": "<?php\n echo dirname($_SERVER[\"REQUEST_URI\"]);\n?>\n" }, { "answer_id": 176736, "author": "Lucas Oman", "author_id": 6726, "author_profile": "https://Stackoverflow.com/users/6726", "pm_score": 1, "selected": false, "text": "$approot = substr(dirname(__FILE__),strlen($_SERVER['DOCUMENT_ROOT']));\n" }, { "answer_id": 176756, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https://Stackoverflow.com/users/5324", "pm_score": 0, "selected": false, "text": "../css/style.css\n" }, { "answer_id": 176760, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 0, "selected": false, "text": "$_SERVER['DOCUMENT_ROOT']" }, { "answer_id": 185725, "author": "Andrew Moore", "author_id": 26210, "author_profile": "https://Stackoverflow.com/users/26210", "pm_score": 5, "selected": true, "text": "define('ABSPATH', str_replace('\\\\', '/', dirname(__FILE__)) . '/');\n\n$tempPath1 = explode('/', str_replace('\\\\', '/', dirname($_SERVER['SCRIPT_FILENAME'])));\n$tempPath2 = explode('/', substr(ABSPATH, 0, -1));\n$tempPath3 = explode('/', str_replace('\\\\', '/', dirname($_SERVER['PHP_SELF'])));\n\nfor ($i = count($tempPath2); $i < count($tempPath1); $i++)\n array_pop ($tempPath3);\n\n$urladdr = $_SERVER['HTTP_HOST'] . implode('/', $tempPath3);\n\nif ($urladdr{strlen($urladdr) - 1}== '/')\n define('URLADDR', 'http://' . $urladdr);\nelse\n define('URLADDR', 'http://' . $urladdr . '/');\n\nunset($tempPath1, $tempPath2, $tempPath3, $urladdr);\n" }, { "answer_id": 4152728, "author": "rakesh sadaka", "author_id": 504269, "author_profile": "https://Stackoverflow.com/users/504269", "pm_score": 1, "selected": false, "text": "$protocol = (strstr('https',$_SERVER['SERVER_PROTOCOL']) === false)?'http':'https';\n$url = $protocol.'://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['REQUEST_URI']);\n" }, { "answer_id": 12583387, "author": "Murtaza Baig", "author_id": 1697315, "author_profile": "https://Stackoverflow.com/users/1697315", "pm_score": 3, "selected": false, "text": "define('SITE_BASE_PATH','http://'.preg_replace('/[^a-zA-Z0-9]/i','',$_SERVER['HTTP_HOST']).'/'.str_replace('\\\\','/',substr(dirname(__FILE__),strlen($_SERVER['DOCUMENT_ROOT']))).'/');\n" }, { "answer_id": 38683743, "author": "Richard Leishman", "author_id": 6659928, "author_profile": "https://Stackoverflow.com/users/6659928", "pm_score": 0, "selected": false, "text": "define('DOC_URL', ($_SERVER['HTTPS']=='on'?'https':'http').'://'.$_SERVER['SERVER_NAME'].(!in_array($_SERVER['SERVER_PORT'], array(80,443))?':'.$_SERVER['SERVER_PORT']:'')).dirname($_SERVER['REQUEST_URI']);\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14253/" ]
176,720
<p>What is the easiest way to do this? Is it possible with managed code?</p>
[ { "answer_id": 176734, "author": "Geoff", "author_id": 10427, "author_profile": "https://Stackoverflow.com/users/10427", "pm_score": 6, "selected": true, "text": "this.BackgroundImage = //Image\nthis.FormBorderStyle = FormBorderStyle.None;\nthis.Width = this.BackgroundImage.Width;\nthis.Height = this.BackgroundImage.Height;\nthis.TransparencyKey = Color.FromArgb(0, 255, 0); //Contrast Color\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4386/" ]
176,743
<p>I'm writing a .NET forms control to edit HTML using MSHTML. I am creating some custom elements and want to make them effectively read-only. I thought I could go about this by focusing on the entire element any time focus entered anywhere in that element but the HtmlElement.Focus() doesn't select the entire element and I don't seem to be able to capture entry of the cursor.</p> <p>Another option would be to raise an event whenever the text of the element is changed (on KeyDown I expect) but I can't get that event to fire, either. Any ideas about why my expectations about event behavior is wrong or alternate suggestions for implementation?</p>
[ { "answer_id": 179506, "author": "dmo", "author_id": 1807, "author_profile": "https://Stackoverflow.com/users/1807", "pm_score": 2, "selected": true, "text": "contentEditable=false\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1807/" ]
176,745
<p>Given an aggregation of class instances which refer to each other in a complex, circular, fashion: is it possible that the garbage collector may not be able to free these objects?</p> <p>I vaguely recall this being an issue in the JVM in the past, but I <em>thought</em> this was resolved years ago. yet, some investigation in jhat has revealed a circular reference being the reason for a memory leak that I am now faced with.</p> <p><em>Note: I have always been under the impression that the JVM was capable of resolving circular references and freeing such "islands of garbage" from memory. However, I am posing this question just to see if anyone has found any exceptions.</em> </p>
[ { "answer_id": 15748185, "author": "Rupesh", "author_id": 1270989, "author_profile": "https://Stackoverflow.com/users/1270989", "pm_score": 2, "selected": false, "text": "class A {\nprivate B b;\n\npublic void setB(B b) {\n this.b = b;\n}\n}\n\nclass B {\nprivate A a;\n\npublic void setA(A a) {\n this.a = a;\n}\n}\n\npublic class Main {\npublic static void main(String[] args) {\n A one = new A();\n B two = new B();\n\n // Make the objects refer to each other (creates a circular reference)\n one.setB(two);\n two.setA(one);\n\n // Throw away the references from the main method; the two objects are\n // still referring to each other\n one = null;\n two = null;\n}\n}\n" } ]
2008/10/06
[ "https://Stackoverflow.com/questions/176745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9931/" ]
176,749
<p>I have a web service that uses Python's SimpleJSON to serialize JSON, and a javascript/ client that uses Google's Visualization <a href="http://code.google.com/apis/visualization/documentation/reference.html" rel="nofollow noreferrer">API</a>. When I try to read in the JSON response using Google Data Table's Query method, I am getting a "invalid label" error. </p> <p>I noticed that Google spreadsheet outputs JSON without quotes around the object keys. I tried reading in JSON without the quotes and that works. I was wondering what was the best way to get SimpleJSON output to be read into Google datable using </p> <p><code>query = new google.visualization.Query("http://www.myuri.com/api/")</code>. </p> <p>I could use a regex to remove the quotes, but that seems sloppy. The javascript JSON parsing libraries I've tried won't read in JSON syntax without quotes around the object keys.</p> <p>Here's some good background reading re: quotes around object keys: </p> <p><a href="http://simonwillison.net/2006/Oct/11/json/" rel="nofollow noreferrer">http://simonwillison.net/2006/Oct/11/json/</a>.</p>
[ { "answer_id": 176780, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 3, "selected": true, "text": "google.visualization.Query.setResponse(\n{requestId:'0',status:'ok',signature:'1464883469881501252',\ntable:{cols: [{id:'A',label:'',type:'t',pattern:''},\n{id:'B',label:'',type:'t',pattern:''}],\nrows: [[{v:'a'},{v:'h'}],[{v:'b'},{v:'i'}],[{v:'c'},{v:'j'}],[{v:'d'},{v:'k'}],[{v:'e'},{v:'l'}],[{v:'f'},{v:'m'}],[{v:'g'},{v:'n'}]]}});\n" }, { "answer_id": 176814, "author": "Ates Goral", "author_id": 23501, "author_profile": "https://Stackoverflow.com/users/23501", "pm_score": 1, "selected": false, "text": "eval(\"{ foo: 42, bar: 43 }\"); // Results in invalid label\n" }, { "answer_id": 12973868, "author": "nickl-", "author_id": 1522117, "author_profile": "https://Stackoverflow.com/users/1522117", "pm_score": 0, "selected": false, "text": ">>> from re import sub\n>>> import json\n>>> js = \"{ a: 'a' }\"\n>>> json.loads(sub(\"'\", '\"', sub('\\s(\\w+):', r' \"\\1\":', js)))\n{u'a': u'a'}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1227001/" ]
176,774
<p>I have 2 tables. Table1 has fields A, B, C, D and Table2 has fields A, B. Field A and B of both tables have same record type. I would like to grab the records from both tables of fields A and B as single result.</p> <p>Is there any Query or Function in PHP+MySql?</p> <p>Thanks...</p>
[ { "answer_id": 176794, "author": "paxdiablo", "author_id": 14860, "author_profile": "https://Stackoverflow.com/users/14860", "pm_score": 3, "selected": false, "text": "select a,b from table1\n where <where-clause>\nunion all select a,b from table2\n where <where-clause>\n" }, { "answer_id": 176806, "author": "Frentos", "author_id": 23978, "author_profile": "https://Stackoverflow.com/users/23978", "pm_score": 3, "selected": false, "text": "create database foo;\ncreate table bill(a int, b varchar(10));\ncreate table ted(a int, b varchar(10), c datetime, d boolean);\ninsert into bill values (10, 'foo'), (20, 'bar');\ninsert into ted values (5, 'splot', now(), true), (10, 'splodge', now(), false);\nselect a,b from bill where a<=10 union select a,b from ted where a<=10;\n+------+---------+\n| a | b |\n+------+---------+\n| 10 | foo |\n| 5 | splot |\n| 10 | splodge |\n+------+---------+\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22962/" ]
176,775
<p>Currently I am <a href="http://msdn.microsoft.com/en-us/magazine/cc163696.aspx" rel="noreferrer">borrowing <code>java.math.BigInteger</code> from the J# libraries as described here</a>. Having never used a library for working with large integers before, this seems slow, on the order of 10 times slower, even for <code>ulong</code> length numbers. Does anyone have any better (preferably free) libraries, or is this level of performance normal?</p>
[ { "answer_id": 498820, "author": "Steve Severance", "author_id": 41717, "author_profile": "https://Stackoverflow.com/users/41717", "pm_score": 3, "selected": false, "text": "F#" }, { "answer_id": 1019202, "author": "Rasmus Faber", "author_id": 5542, "author_profile": "https://Stackoverflow.com/users/5542", "pm_score": 3, "selected": false, "text": "System.Numerics.BigInteger" }, { "answer_id": 56197552, "author": "RobertBaron", "author_id": 3826387, "author_profile": "https://Stackoverflow.com/users/3826387", "pm_score": 1, "selected": false, "text": "mpz_" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
176,777
<p>I'm trying to build a proxy module for .NET, but I'm having trouble copying the Headers from the current request to the new request. I am setting the headers of the new request, because I want the proxy to support SOAP requests. Here is a portion of my code. I can post everything if need, but this is the only part that seems related to the issue I am having:</p> <pre> <code> HttpApplication app = (HttpApplication)sender; // sender from context.BeginRequest event HttpRequest crntReq = app.Request; // set a reference to request object for easier access HttpWebRequest proxyReq = (HttpWebRequest)HttpWebRequest.Create(crntReq.Url.AbsoluteUri); // parse headers from current httpcontext.request.headers and add each name->value to the // new request object foreach (string header in crntReq.Headers) { proxyReq.Headers.Add(header, crntReq.Headers[header]); // throws exception :( } </code> </pre> <p><br /></p> <p>When my code hits the foreach loop, it throws an exception for the Headers.Add function. I'm assuming the collection has access restrictions, for security purposes. It appears that some of the header values are accessible with properties for the HttpWebRequest object itself. However in this case I'd rather get rid of the abstraction and set the properties manually. The exception that I'm receiving is:<br /><i>{"This header must be modified using the appropriate property.\r\nParameter name: name"}</i></p> <p><hr> Thanks in advance for your help,</p> <p>CJAM</p>
[ { "answer_id": 11146923, "author": "Jimmy Schementi", "author_id": 5721, "author_profile": "https://Stackoverflow.com/users/5721", "pm_score": 0, "selected": false, "text": "static void CopyHeaders (HttpRequest sourceRequest, HttpWebRequest targetRequest) {\n foreach (string key in sourceRequest.Headers) {\n var value = sourceRequest.Headers[key];\n object objectValue = value;\n var propName = key.Replace(\"-\", string.Empty);\n switch (key) {\n case \"Host\":\n case \"Content-Length\":\n // Do not propogate Host and Content-Length.\n continue;\n case \"Connection\":\n // Cannot set the following values ...\n if (value == \"Keep-Alive\" || value == \"Close\") {\n continue;\n }\n break;\n case \"If-Modified-Since\":\n objectValue = DateTime.Parse(value);\n break;\n }\n var prop = targetRequest.GetType().GetProperty(propName, BindingFlags.Public | BindingFlags.Instance);\n if (null != prop && prop.CanWrite) {\n prop.SetValue(targetRequest, objectValue, null);\n } else {\n targetRequest.Headers[key] = Convert.ToString(value);\n }\n }\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23869/" ]
176,782
<p>So, I have an autocomplete dropdown with a list of townships. Initially I just had the 20 or so that we had in the database... but recently, we have noticed that some of our data lies in other counties... even other states. So, the answer to that was buy one of those databases with all towns in the US (yes, I know, geocoding is the answer but due to time constraints we are doing this until we have time for that feature). </p> <p>So, when we had 20-25 towns the autocomplete worked stellarly... now that there are 80,000 it's not as easy. </p> <p>As I type I am thinking that the best way to do this is default to this state, then there will be much less. I will add a state selector to the page that defaults to NJ then you can pick another state if need be, this will narrow down the list to &lt; 1000. Though, I may have the same issue? Does anyone know of a work around for an autocomplete with a lot of data? </p> <p>should I post teh codez of my webservice?</p>
[ { "answer_id": 177195, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 0, "selected": false, "text": "select top 10 name from cities where @partialname < name order by name;\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4140/" ]
176,791
<p>I have a legacy application that I needed to implement a configuration page for to change text colors, fonts, etc.</p> <p>This applications output is also replicated with a PHP web application, where the fonts, colors, etc. are configured in a style sheet.</p> <p>I've not worked with CSS previously.</p> <p>Is there a programatic way to modify the CSS and save it without resorting to string parsing or regex?</p> <p>The application is VB6, but I could write a .net tool that would do the css manipulation if that was the only way.</p>
[ { "answer_id": 207161, "author": "Alexey Shatygin", "author_id": 10915, "author_profile": "https://Stackoverflow.com/users/10915", "pm_score": 0, "selected": false, "text": "border-color: #008a77;\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10119/" ]
176,827
<p>I have an ASP.NET linkbutton control on my form. I would like to use it for javascript on the client side and prevent it from posting back to the server. (I'd like to use the linkbutton control so I can skin it and disable it in some cases, so a straight up tag is not preferred).</p> <p>How do I prevent it from posting back to the server?</p>
[ { "answer_id": 176829, "author": "BoltBait", "author_id": 20848, "author_profile": "https://Stackoverflow.com/users/20848", "pm_score": 2, "selected": false, "text": "MyButton.Attributes.Add(\"onclick\", \"put your javascript here including... return false;\");\n" }, { "answer_id": 176841, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": -1, "selected": false, "text": "<asp:LinkButton runat=\"server\" id=\"button\" Text=\"Click Me\" OnClick=\"myfunction();return false;\" AutoPostBack=\"false\" />\n" }, { "answer_id": 176889, "author": "Russell Myers", "author_id": 18194, "author_profile": "https://Stackoverflow.com/users/18194", "pm_score": 7, "selected": true, "text": "<asp:LinkButton ID=\"someID\" runat=\"server\" Text=\"clicky\"></asp:LinkButton>\n" }, { "answer_id": 176969, "author": "John Rudy", "author_id": 14048, "author_profile": "https://Stackoverflow.com/users/14048", "pm_score": 5, "selected": false, "text": "onclick" }, { "answer_id": 2244797, "author": "Peter", "author_id": 271108, "author_profile": "https://Stackoverflow.com/users/271108", "pm_score": 0, "selected": false, "text": "createEventLinkButton.Attributes.Add(\"onClick\", \" if (this.innerHTML == 'Please Wait') { return false; } else { this.innerHTML='Please Wait'; }\");\n" }, { "answer_id": 3970312, "author": "Jaider", "author_id": 480700, "author_profile": "https://Stackoverflow.com/users/480700", "pm_score": 2, "selected": false, "text": "public partial class _Default : System.Web.UI.Page{\n protected void Page_Load(object sender, EventArgs e)\n {\n someID.Attributes.Add(\"onClick\", \"return false;\");\n }}\n" }, { "answer_id": 4867416, "author": "Denis", "author_id": 599013, "author_profile": "https://Stackoverflow.com/users/599013", "pm_score": 5, "selected": false, "text": "...LinkButton ID=\"BtnForgotPassword\" runat=\"server\" OnClientClick=\"ChangeText('1');return false\"..." }, { "answer_id": 6061477, "author": "Stefan Hakansson", "author_id": 761405, "author_profile": "https://Stackoverflow.com/users/761405", "pm_score": 1, "selected": false, "text": "OnClientClick" }, { "answer_id": 10559633, "author": "Randall Sutton", "author_id": 91177, "author_profile": "https://Stackoverflow.com/users/91177", "pm_score": 4, "selected": false, "text": "<asp:LinkButton ID=\"myLink\" runat=\"server\" href=\"#\">Click Me</asp:LinkButton>\n" }, { "answer_id": 12642809, "author": "Adam", "author_id": 1073205, "author_profile": "https://Stackoverflow.com/users/1073205", "pm_score": 3, "selected": false, "text": "OnClientClick" }, { "answer_id": 19863910, "author": "Andrew Gray", "author_id": 1404206, "author_profile": "https://Stackoverflow.com/users/1404206", "pm_score": 1, "selected": false, "text": "<asp:LinkButton runat=\"server\" id=\"someId\" href=\"javascript: void;\" Text=\"Click Me\" />\n" }, { "answer_id": 21441300, "author": "Senthilkumar baliah", "author_id": 3250501, "author_profile": "https://Stackoverflow.com/users/3250501", "pm_score": 0, "selected": false, "text": "var hrefcode = $('a[id*=linkbutton]').attr('href').split(':');\nvar onclickcode = \"javascript: if`(Condition()) {\" + hrefcode[1] + \";}\";\n$('a[id*=linkbutton]').attr('href', onclickcode);\n" }, { "answer_id": 52829886, "author": "Deepu Reghunath", "author_id": 6597375, "author_profile": "https://Stackoverflow.com/users/6597375", "pm_score": 2, "selected": false, "text": "return false" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/417/" ]
176,831
<p>I have a modal popup that initially shows some content but expands a div if a checkbox is selected. The modal expands correctly but doesn't recenter unless you scroll up or down. Is there a javascript event I can tack on to my javascript function to recenter the entire modal?</p>
[ { "answer_id": 481797, "author": "Luke", "author_id": 14275, "author_profile": "https://Stackoverflow.com/users/14275", "pm_score": 4, "selected": true, "text": "$find('ModalPopupExtenderClientID')._layout();\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14275/" ]
176,840
<p>It's the first <a href="http://oreilly.com/catalog/opensources/book/larry.html" rel="nofollow noreferrer">great virtue</a> of programmers. All of us have, at one time or another automated a task with a bit of throw-away code. Sometimes it takes a couple seconds tapping out a one-liner, sometimes we spend an exorbitant amount of time automating away a two-second task and then never use it again.</p> <p>What tiny hack have you found useful enough to <b>reuse</b>? To make go so far as to make an alias for?</p> <p>Note: before answering, please check to make sure it's not already on <a href="https://stackoverflow.com/questions/68372/what-is-your-single-most-favorite-command-line-trick-using-bash">favourite command-line tricks using BASH</a> or perl/ruby one-liner questions. </p>
[ { "answer_id": 176930, "author": "Frew Schmidt", "author_id": 12448, "author_profile": "https://Stackoverflow.com/users/12448", "pm_score": 1, "selected": false, "text": "#!/usr/bin/ruby -w\n\nDay = 60 * 60 * 24\n\nFromat = \"hjlsdahjsd/comics/st%Y%m%d.gif\"\n\nt = Time.local(2005, 2, 5)\n\nMWF = [1,3,5]\n\nuntil t == Time.local(2007, 7, 9)\n if MWF.include? t.wday\n `wget #{t.strftime(Fromat)}`\n sleep 3\n end\n\n t += Day\nend\n" }, { "answer_id": 176933, "author": "Frentos", "author_id": 23978, "author_profile": "https://Stackoverflow.com/users/23978", "pm_score": 2, "selected": false, "text": "#!/bin/bash\n## dsum Do checksums recursively over a directory.\n## Typical usage: dsum <directory> > outfile\n\nexport LC_ALL=C # Optional - use sort order across different locales\n\nif [ $# != 1 ]; then echo \"Usage: ${0/*\\//} <directory>\" 1>&2; exit; fi\ncd $1 1>&2 || exit\n#findargs=-follow # Uncomment to follow symbolic links\nfind . $findargs -type f | sort | xargs -d'\\n' cksum\n" }, { "answer_id": 176950, "author": "Claudiu", "author_id": 15055, "author_profile": "https://Stackoverflow.com/users/15055", "pm_score": 0, "selected": false, "text": "if reduce(lambda x, c: locks[x] and c, locknames, True):\n print \"Sub-threads terminated!\"\n" }, { "answer_id": 176995, "author": "joh6nn", "author_id": 21837, "author_profile": "https://Stackoverflow.com/users/21837", "pm_score": 4, "selected": false, "text": "###\n### Handy Extract Program\n###\nextract () {\n if [ -f $1 ] ; then\n case $1 in\n *.tar.bz2) tar xvjf $1 ;;\n *.tar.gz) tar xvzf $1 ;;\n *.bz2) bunzip2 $1 ;;\n *.rar) unrar x $1 ;;\n *.gz) gunzip $1 ;;\n *.tar) tar xvf $1 ;;\n *.tbz2) tar xvjf $1 ;;\n *.tgz) tar xvzf $1 ;;\n *.zip) unzip $1 ;;\n *.Z) uncompress $1 ;;\n *.7z) 7z x $1 ;;\n *) echo \"'$1' cannot be extracted via >extract<\" ;;\n esac\n else\n echo \"'$1' is not a valid file\"\n fi\n}\n" }, { "answer_id": 177116, "author": "Andy Lester", "author_id": 8454, "author_profile": "https://Stackoverflow.com/users/8454", "pm_score": 3, "selected": false, "text": "$ cat ~/bin/comma\n#!/usr/bin/perl -p\n\ns/(\\d{4,})/commify($1)/ge;\n\nsub commify {\n local $_ = shift;\n 1 while s/^([ -+]?\\d+)(\\d{3})/$1,$2/;\n return $_;\n}\n" }, { "answer_id": 201722, "author": "Magnus Smith", "author_id": 11461, "author_profile": "https://Stackoverflow.com/users/11461", "pm_score": 1, "selected": false, "text": "isqlw -S servername -d dbname -E -i F:\\blah\\whatever.sql -o F:\\results.txt\n" }, { "answer_id": 256762, "author": "Adam Liss", "author_id": 29157, "author_profile": "https://Stackoverflow.com/users/29157", "pm_score": 0, "selected": false, "text": "xterm" }, { "answer_id": 271036, "author": "Jim Puls", "author_id": 6010, "author_profile": "https://Stackoverflow.com/users/6010", "pm_score": 0, "selected": false, "text": "#!/usr/bin/env ruby\n\nrequire 'rubygems'\nrequire 'dnssd'\n\nhandle = DNSSD.browse('_ssh._tcp') do |reply|\n print \"alias #{reply.name}='ssh #{reply.name}.#{reply.domain}';\"\nend\n\nsleep 1\nhandle.stop\n" }, { "answer_id": 386621, "author": "Dutch Masters", "author_id": 42037, "author_profile": "https://Stackoverflow.com/users/42037", "pm_score": 2, "selected": false, "text": "import sys\nimport subprocess as sp\npgm = \"isql\"\nif len(sys.argv) == 1:\n print \"Usage: \\nsql sql-string [rows-affected]\"\n sys.exit()\nsql_str = sys.argv[1].upper()\nmax_rows_affected = 3\nif len(sys.argv) > 2:\n max_rows_affected = int(sys.argv[2])\n\nif sql_str.startswith(\"UPDATE\"):\n sql_str = \"BEGIN TRANSACTION\\\\n\" + sql_str\n p1 = sp.Popen([pgm, sql_str],stdout=sp.PIPE,\n shell=True)\n (stdout, stderr) = p1.communicate()\n print stdout\n # example -> (33 rows affected)\n affected = stdout.splitlines()[-1]\n affected = affected.split()[0].lstrip('(')\n num_affected = int(affected)\n if num_affected > max_rows_affected:\n print \"WARNING! \", num_affected,\"rows were affected, rolling back...\"\n sql_str = \"ROLLBACK TRANSACTION\"\n ret_code = sp.call([pgm, sql_str], shell=True)\n else:\n sql_str = \"COMMIT TRANSACTION\"\n ret_code = sp.call([pgm, sql_str], shell=True)\nelse:\n ret_code = sp.call([pgm, sql_str], shell=True)\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1582786/" ]
176,850
<p>I've used NUnit before, but not in a while, and never on this machine. I unzipped version 2.4.8 under <code>Program Files</code>, and I keep getting this error when trying to load my tests.</p> <blockquote> <p>Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified**</p> </blockquote> <p>In order to simplify the problem, I've compiled the most basic possible test file.</p> <pre><code>using NUnit.Framework; namespace test { [TestFixture] public class Tester { [Test] public void ATest() { Assert.IsTrue(false, "At least the test ran!"); } } } </code></pre> <p>I've added "C:\Program Files\NUnit-2.4.8-net-2.0\bin" to my PATH (and rebooted). Note that if I copy the test assembly into that folder, then</p> <pre> C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console test.dll </pre> <p>works, but</p> <pre> C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console c:\dev\nunit_test\test.dll </pre> <p>and</p> <pre> C:\dev\nunit_test>nunit_console test.dll </pre> <p>fail with the above error.</p> <p>Presumably I could get around this by copying the NUnit.Framework DLL file into my project's <code>bin</code> folder, but I don't remember having to do this in the past. Moreover, I get the same error in the GUI. Shouldn't the GUI know where the framework is located (that is, in the same folder)?</p> <p>I'm not using Visual Studio. I use the following line to compile the test project.</p> <pre> %windir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /r:"C:\Program Files\NUnit-2.4.8-net-2.0\bin\nunit.framework.dll" /t:library /out:test.dll test.cs </pre> <p>I tried both the .msi and the .zip file with the same result.</p>
[ { "answer_id": 688174, "author": "Jeffrey Knight", "author_id": 83418, "author_profile": "https://Stackoverflow.com/users/83418", "pm_score": 4, "selected": false, "text": "gacutil /l | find /i \"nunit\" > temp.bat && notepad temp.bat\n" }, { "answer_id": 7812614, "author": "Juancentro", "author_id": 645080, "author_profile": "https://Stackoverflow.com/users/645080", "pm_score": 2, "selected": false, "text": "gacutil /i <nunitframeworkpath>" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4525/" ]
176,851
<p>I have taken a copy of a database home with me so I can do some testing. However when I try to run a stored procedure I get Cannot open user default database. Login failed.. </p> <p>I have checked and checked and checked I can open tables in the databases login to sql management studio and access the default as well as other databases any ideas?</p> <p>Possibly a corrupt user it was from sql 2000 at work to 2005 at home</p>
[ { "answer_id": 176939, "author": "flatline", "author_id": 20846, "author_profile": "https://Stackoverflow.com/users/20846", "pm_score": 0, "selected": false, "text": "exec sp_change_users_login update_one, 'user', 'login'\n" }, { "answer_id": 177048, "author": "Hector Sosa Jr", "author_id": 12829, "author_profile": "https://Stackoverflow.com/users/12829", "pm_score": 2, "selected": true, "text": "USE AdventureWorks;\nALTER USER Mary5 WITH NAME = Mary51;\nGO\n" }, { "answer_id": 426235, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "ALTER LOGIN" }, { "answer_id": 5639558, "author": "Spydermary", "author_id": 704624, "author_profile": "https://Stackoverflow.com/users/704624", "pm_score": 1, "selected": false, "text": "CREATE LOGIN [NT\\mylogin] FROM WINDOWS WITH DEFAULT_DATABASE=[Master], DEFAULT_LANGUAGE=[us_english]\nGO\n" }, { "answer_id": 6911131, "author": "Filippo Vitale", "author_id": 81444, "author_profile": "https://Stackoverflow.com/users/81444", "pm_score": 2, "selected": false, "text": "C:\\> sqlcmd -E -d master\n1> ALTER LOGIN ***** WITH DEFAULT_DATABASE=master\n2> GO\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16989/" ]
176,856
<p>What's the best way for constructing headers, and footers? Should you call it all from the controller, or include it from the view file? I'm using CodeIgniter, and I'm wanting to know what's the best practice for this. Loading all the included view files from the controller, like this?</p> <pre><code>class Page extends Controller { function index() { $data['page_title'] = 'Your title'; $this-&gt;load-&gt;view('header'); $this-&gt;load-&gt;view('menu'); $this-&gt;load-&gt;view('content', $data); $this-&gt;load-&gt;view('footer'); } } </code></pre> <p>or calling the single view file, and calling the header and footer views from there:</p> <pre><code>//controller file class Page extends Controller { function index() { $data['page_title'] = 'Your title'; $this-&gt;load-&gt;view('content', $data); } } //view file &lt;?php $this-&gt;load-&gt;view('header'); ?&gt; &lt;p&gt;The data from the controller&lt;/p&gt; &lt;?php $this-&gt;load-&gt;view('footer'); ?&gt; </code></pre> <p>I've seen it done both ways, but want to choose now before I go too far down a path.</p>
[ { "answer_id": 176988, "author": "gradbot", "author_id": 17919, "author_profile": "https://Stackoverflow.com/users/17919", "pm_score": 2, "selected": false, "text": "class Page extends Controller {\n function index() {\n $data['page_title'] = 'Your title';\n \n $this->load->view('default_layout', array(\n 'header' => $this->load->view('header' , array(), true), \n 'menu' => $this->load->view('menu' , array(), true), \n 'content' => $this->load->view('content', $data , true), \n 'footer' => $this->load->view('footer' , array(), true), \n ));\n }\n}\n" }, { "answer_id": 178882, "author": "meleyal", "author_id": 4196, "author_profile": "https://Stackoverflow.com/users/4196", "pm_score": 4, "selected": true, "text": "$data['content'] = 'your_controller/index';\n\n// more code...\n\n$this->load->vars($data);\n$this->load->view('layouts/default');\n" }, { "answer_id": 476559, "author": "Jens Roland", "author_id": 57068, "author_profile": "https://Stackoverflow.com/users/57068", "pm_score": 4, "selected": false, "text": "Base_controller" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24708/" ]
176,857
<p>I should probably take this for a forum but figured someone here might know the answer. I'm trying to install sql server 2008 on a home vista machine but it keeps telling 'Restart computer failed' everytime it does a check to make sure pre-reqs are met. I've restarted my computer and even uinstalled/installed .net 3.5 sp1.<br> only thread i found about this was: <a href="http://forums.microsoft.com/msdn/showpost.aspx?postid=3656807&amp;siteid=1&amp;sb=0&amp;d=1&amp;at=7&amp;ft=11&amp;tf=0&amp;pageid=1" rel="noreferrer">http://forums.microsoft.com/msdn/showpost.aspx?postid=3656807&amp;siteid=1&amp;sb=0&amp;d=1&amp;at=7&amp;ft=11&amp;tf=0&amp;pageid=1</a></p> <p>the last post on that forum states that there is a way to 'forcefully' (using command prompt) there is a way to bypass the reboot check. </p> <p>does anyone know what commands can be used to bypass the rebook check??</p>
[ { "answer_id": 15720206, "author": "Paldom", "author_id": 1208812, "author_profile": "https://Stackoverflow.com/users/1208812", "pm_score": 0, "selected": false, "text": "INSTANCENAME=SQL2008\n/SQLSYSADMINACCOUNTS=”yourPcName\\yourUserName”\n/SAPWD=”yourSqlPassword” \n/SQLTEMPDBDIR=”C:\\SQL2008\\TempDB\\\\” \n/SQLUSERDBDIR=”C:\\SQL2008\\SQLData\\\\” \n/SQLUSERDBLOGDIR=”C:\\SQL2008\\SQLLog\\\\”\n" }, { "answer_id": 32535085, "author": "Renan Araújo", "author_id": 5071902, "author_profile": "https://Stackoverflow.com/users/5071902", "pm_score": 4, "selected": false, "text": "setup.exe /ACTION=INSTALL /SkipRules=RebootRequiredCheck\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
176,858
<p>In a static view, how can I view an old version of a file?</p> <p>Given an empty file (called <code>empty</code> in this example) I can subvert <code>diff</code> to show me the old version:</p> <pre> % cleartool diff -ser empty File@@/main/28 </pre> <p>This feels like a pretty ugly hack. Have I missed a more basic command? Is there a neater way to do this?</p> <p>(I don't want to edit the config spec - that's pretty tedious, and I'm trying to look at a bunch of old versions.)</p> <p><strong>Clarification</strong>: I want to send the version of the file to stdout, so I can use it with the rest of Unix (grep, sed, and so on.) If you found this question because you're looking for a way to save a version of an element to a file, see <a href="https://stackoverflow.com/questions/176858/in-clearcase-how-can-i-view-old-version-of-a-file-in-a-static-view-from-the-com/4962643#4962643">Brian's answer</a>.</p>
[ { "answer_id": 177273, "author": "Chris Arguin", "author_id": 25704, "author_profile": "https://Stackoverflow.com/users/25704", "pm_score": 2, "selected": false, "text": " cat File@@/main/28\n" }, { "answer_id": 177350, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 5, "selected": true, "text": "ct lsvtree -graph File" }, { "answer_id": 3868050, "author": "Bart", "author_id": 467350, "author_profile": "https://Stackoverflow.com/users/467350", "pm_score": 1, "selected": false, "text": "cat File" }, { "answer_id": 4962643, "author": "Brian", "author_id": 612108, "author_profile": "https://Stackoverflow.com/users/612108", "pm_score": 4, "selected": false, "text": "cleartool get -to ~/foo File@@/main/28\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176858", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17221/" ]
176,877
<p>I want to call <code>ShowDialog()</code> when a keyboard hook event is triggered, but I'm having some difficulties:</p> <ul> <li>ShowDialog() blocks, so I can't call it from the hook triggered event, because it will block the OS.</li> <li>I can start a new thread and call <code>ShowDialog()</code> from there, but I get some nasty exception. I guess I can't call <code>ShowDialog()</code> in any other thread.</li> <li>I can start a timer: in the next 50 milliseconds call <code>ShowDialog()</code> (which is a nasty hack BTW, and I rather not do this). But then the timer fires in a new thread, and then I run into the same problem explained in the previous bullet.</li> </ul> <p>Is there a way?</p>
[ { "answer_id": 176906, "author": "Brody", "author_id": 17131, "author_profile": "https://Stackoverflow.com/users/17131", "pm_score": 3, "selected": true, "text": "ShowDialog()" }, { "answer_id": 176920, "author": "Ed S.", "author_id": 1053, "author_profile": "https://Stackoverflow.com/users/1053", "pm_score": 0, "selected": false, "text": "ShowDialog()" }, { "answer_id": 177077, "author": "Judah Gabriel Himango", "author_id": 536, "author_profile": "https://Stackoverflow.com/users/536", "pm_score": 0, "selected": false, "text": "void MyKeyboardHookHandler(...)\n{\n WindowsFormsSynchronizationContext.Current.Post(state =>\n {\n Form f = new Form();\n f.ShowDialog();\n }, null);\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44972/" ]
176,902
<p>How do I run a .jar executable java file from outside NetBeans IDE? (Windows Vista). My project has a .jar file created by Netbeans. We'd like to run it. Either: how do we run the file or how do we create a 'proper' executable file in NetBeans 6.1?</p>
[ { "answer_id": 176905, "author": "Laplie Anderson", "author_id": 14204, "author_profile": "https://Stackoverflow.com/users/14204", "pm_score": 4, "selected": false, "text": "java -jar filename.jar\n" }, { "answer_id": 176911, "author": "Josh Moore", "author_id": 5004, "author_profile": "https://Stackoverflow.com/users/5004", "pm_score": 1, "selected": false, "text": "java -jar your_jar.jar" }, { "answer_id": 176912, "author": "Brian Gianforcaro", "author_id": 3415, "author_profile": "https://Stackoverflow.com/users/3415", "pm_score": 2, "selected": false, "text": "C:\\java\\java.exe -jar C:\\jar_you_want_to_run.jar\n" }, { "answer_id": 200251, "author": "Galghamon", "author_id": 26511, "author_profile": "https://Stackoverflow.com/users/26511", "pm_score": 2, "selected": false, "text": "java" }, { "answer_id": 3683843, "author": "Mr. Brahm Deo Sah", "author_id": 444245, "author_profile": "https://Stackoverflow.com/users/444245", "pm_score": 2, "selected": false, "text": "Java_Jar_File.jar" }, { "answer_id": 6599377, "author": "Raahil", "author_id": 831942, "author_profile": "https://Stackoverflow.com/users/831942", "pm_score": 2, "selected": false, "text": "java -jar filepath.jar\n" }, { "answer_id": 10054369, "author": "Jirik", "author_id": 1303387, "author_profile": "https://Stackoverflow.com/users/1303387", "pm_score": 0, "selected": false, "text": "GoTo Run Menu" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
176,910
<p>When I want an array of flags it has typically pained me to use an entire byte (or word) to store each one, as would be the result if I made an array of <code>bool</code>s or some other numeric type that could be set to 0 or 1. But now I wonder whether using a structure that is more space-efficient is worth it given the (albeit hopefully very slight) additional overhead of shifting and bit testing.</p> <p>In my company we use Rogue Wave tools (though hopefully not for much longer) and it's their <code>RWBitVec</code> that I've used for this purpose up until now.</p>
[ { "answer_id": 176946, "author": "Andrew Edgecombe", "author_id": 11694, "author_profile": "https://Stackoverflow.com/users/11694", "pm_score": 0, "selected": false, "text": "bool" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176910", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4790/" ]
176,913
<p>I basically want to run all JUnit <strong><em>unit</em></strong> tests in my IntelliJ IDEA project (excluding JUnit integration tests), using the static suite() method of JUnit. Why use the static suite() method? Because I can then use IntelliJ IDEA's JUnit test runner to run all unit tests in my application (and easily exclude all integration tests by naming convention). The code so far looks like this:</p> <pre><code>package com.acme; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class AllUnitTests extends TestCase { public static Test suite() { List classes = getUnitTestClasses(); return createTestSuite(classes); } private static List getUnitTestClasses() { List classes = new ArrayList(); classes.add(CalculatorTest.class); return classes; } private static TestSuite createTestSuite(List allClasses) { TestSuite suite = new TestSuite("All Unit Tests"); for (Iterator i = allClasses.iterator(); i.hasNext();) { suite.addTestSuite((Class&lt;? extends TestCase&gt;) i.next()); } return suite; } } </code></pre> <p>The method getUnitTestClasses() should be rewritten to add all project classes extending TestCase, except if the class name ends in "IntegrationTest".</p> <p>I know I can do this easily in Maven for example, but I need to do it in IntelliJ IDEA so I can use the integrated test runner - I like the green bar :)</p>
[ { "answer_id": 178030, "author": "Roel Spilker", "author_id": 12634, "author_profile": "https://Stackoverflow.com/users/12634", "pm_score": 4, "selected": true, "text": "public class ClassEnumerator {\n public static void main(String[] args) throws ClassNotFoundException {\n List<Class<?>> list = listClassesInSamePackage(Locator.class, true);\n\n System.out.println(list);\n }\n\n private static List<Class<?>> listClassesInSamePackage(Class<?> locator, boolean includeLocator) \n throws ClassNotFoundException {\n\n File packageFile = getPackageFile(locator);\n\n String ignore = includeLocator ? null : locator.getSimpleName() + \".class\";\n\n return toClassList(locator.getPackage().getName(), listClassNames(packageFile, ignore));\n }\n\n private static File getPackageFile(Class<?> locator) {\n URL url = locator.getClassLoader().getResource(locator.getName().replace(\".\", \"/\") + \".class\");\n if (url == null) {\n throw new RuntimeException(\"Cannot locate \" + Locator.class.getName());\n }\n\n try {\n return new File(url.toURI()).getParentFile();\n }\n catch (URISyntaxException e) {\n throw new RuntimeException(e);\n }\n }\n\n private static String[] listClassNames(File packageFile, final String ignore) {\n return packageFile.list(new FilenameFilter(){\n @Override\n public boolean accept(File dir, String name) {\n if (name.equals(ignore)) {\n return false;\n }\n return name.endsWith(\".class\");\n }\n });\n }\n\n private static List<Class<?>> toClassList(String packageName, String[] classNames)\n throws ClassNotFoundException {\n\n List<Class<?>> result = new ArrayList<Class<?>>(classNames.length);\n for (String className : classNames) {\n // Strip the .class\n String simpleName = className.substring(0, className.length() - 6);\n\n result.add(Class.forName(packageName + \".\" + simpleName));\n }\n return result;\n }\n}\n" }, { "answer_id": 179707, "author": "Arne Evertsson", "author_id": 16686, "author_profile": "https://Stackoverflow.com/users/16686", "pm_score": 3, "selected": false, "text": "test.\n quick.\n com.acme\n slow.\n com.acme\n" }, { "answer_id": 2351625, "author": "timomeinen", "author_id": 283136, "author_profile": "https://Stackoverflow.com/users/283136", "pm_score": 3, "selected": false, "text": "@RunWith(Suite.class)\n@Suite.SuiteClasses({\nUserUnitTest.class,\nAnotherUnitTest.class\n})\npublic class UnitTestSuite {}\n" }, { "answer_id": 37848062, "author": "Creos", "author_id": 3903990, "author_profile": "https://Stackoverflow.com/users/3903990", "pm_score": 0, "selected": false, "text": "@RunWith(WildcardPatternSuite.class)\n@SuiteClasses({\"**/*.class\", \"!**/*IntegrationTest.class\"})\npublic class AllTestsExceptionIntegrationSuit {\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13041/" ]
176,918
<p>Given a list <code>[&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]</code> and an item in the list <code>&quot;bar&quot;</code>, how do I get its index <code>1</code>?</p>
[ { "answer_id": 176921, "author": "Alex Coventry", "author_id": 1941213, "author_profile": "https://Stackoverflow.com/users/1941213", "pm_score": 13, "selected": true, "text": ">>> [\"foo\", \"bar\", \"baz\"].index(\"bar\")\n1\n" }, { "answer_id": 178399, "author": "davidavr", "author_id": 8247, "author_profile": "https://Stackoverflow.com/users/8247", "pm_score": 10, "selected": false, "text": ">>> help([\"foo\", \"bar\", \"baz\"])\nHelp on list object:\n\nclass list(object)\n ...\n\n |\n | index(...)\n | L.index(value, [start, [stop]]) -> integer -- return first index of value\n |\n" }, { "answer_id": 7241298, "author": "HongboZhu", "author_id": 270222, "author_profile": "https://Stackoverflow.com/users/270222", "pm_score": 7, "selected": false, "text": "index()" }, { "answer_id": 12054409, "author": "savinson", "author_id": 1614145, "author_profile": "https://Stackoverflow.com/users/1614145", "pm_score": 7, "selected": false, "text": "a = [\"foo\",\"bar\",\"baz\",'bar','any','much']\n\nindexes = [index for index in range(len(a)) if a[index] == 'bar']\n" }, { "answer_id": 16034499, "author": "tanzil", "author_id": 2239760, "author_profile": "https://Stackoverflow.com/users/2239760", "pm_score": 7, "selected": false, "text": "# if element is found it returns index of element else returns None\n\ndef find_element_in_list(element, list_element):\n try:\n index_element = list_element.index(element)\n return index_element\n except ValueError:\n return None\n" }, { "answer_id": 16593099, "author": "Graham Giller", "author_id": 2033154, "author_profile": "https://Stackoverflow.com/users/2033154", "pm_score": 6, "selected": false, "text": "[i for i in range(len(mylist)) if mylist[i]==myterm] # get the indices\n\n[each for each in mylist if each==myterm] # get the items\n\nmylist.index(myterm) if myterm in mylist else None # get the first index and fail quietly\n" }, { "answer_id": 16807733, "author": "kiriloff", "author_id": 1141493, "author_profile": "https://Stackoverflow.com/users/1141493", "pm_score": 5, "selected": false, "text": "a = [['hand', 'head'], ['phone', 'wallet'], ['lost', 'stock']]\nb = ['phone', 'lost']\n\nres = [[x[0] for x in a].index(y) for y in b]\n" }, { "answer_id": 16822116, "author": "Mathitis2Software", "author_id": 1563847, "author_profile": "https://Stackoverflow.com/users/1563847", "pm_score": 4, "selected": false, "text": ">>> a = ['red', 'blue', 'green', 'red']\n>>> b = 'red'\n>>> offset = 0;\n>>> indices = list()\n>>> for i in range(a.count(b)):\n... indices.append(a.index(b,offset))\n... offset = indices[-1]+1\n... \n>>> indices\n[0, 3]\n>>> \n" }, { "answer_id": 17202481, "author": "TerryA", "author_id": 1971805, "author_profile": "https://Stackoverflow.com/users/1971805", "pm_score": 9, "selected": false, "text": "enumerate()" }, { "answer_id": 17300987, "author": "FMc", "author_id": 55857, "author_profile": "https://Stackoverflow.com/users/55857", "pm_score": 8, "selected": false, "text": "indexes = [i for i, x in enumerate(xs) if x == 'foo']\n" }, { "answer_id": 22708420, "author": "bvanlew", "author_id": 584201, "author_profile": "https://Stackoverflow.com/users/584201", "pm_score": 4, "selected": false, "text": ">>> a = ['foo','bar','baz','bar','any', 'foo', 'much']\n>>> l = dict(zip(set(a), map(lambda y: [i for i,z in enumerate(a) if z is y ], set(a))))\n>>> l['foo']\n[0, 5]\n>>> l ['much']\n[6]\n>>> l\n{'baz': [2], 'foo': [0, 5], 'bar': [1, 3], 'any': [4], 'much': [6]}\n>>> \n" }, { "answer_id": 23862698, "author": "user3670684", "author_id": 3670684, "author_profile": "https://Stackoverflow.com/users/3670684", "pm_score": 6, "selected": false, "text": "if 'your_element' in mylist:\n print mylist.index('your_element')\nelse:\n print None\n" }, { "answer_id": 27712517, "author": "MrWonderful", "author_id": 2069807, "author_profile": "https://Stackoverflow.com/users/2069807", "pm_score": 4, "selected": false, "text": "def indices(l, val):\n \"\"\"Always returns a list containing the indices of val in the_list\"\"\"\n retval = []\n last = 0\n while val in l[last:]:\n i = l[last:].index(val)\n retval.append(last + i)\n last += i + 1 \n return retval\n\nl = ['bar','foo','bar','baz','bar','bar']\nq = 'bar'\nprint indices(l,q)\nprint indices(l,'bat')\nprint indices('abcdaababb','a')\n" }, { "answer_id": 30283031, "author": "dylankb", "author_id": 3950092, "author_profile": "https://Stackoverflow.com/users/3950092", "pm_score": 4, "selected": false, "text": "for" }, { "answer_id": 31230699, "author": "Coder123", "author_id": 5082430, "author_profile": "https://Stackoverflow.com/users/5082430", "pm_score": 3, "selected": false, "text": "name =\"bar\"\nlist = [[\"foo\", 1], [\"bar\", 2], [\"baz\", 3]]\nnew_list=[]\nfor item in list:\n new_list.append(item[0])\nprint(new_list)\ntry:\n location= new_list.index(name)\nexcept:\n location=-1\nprint (location)\n" }, { "answer_id": 33644671, "author": "Arnaldo P. Figueira Figueira", "author_id": 1579731, "author_profile": "https://Stackoverflow.com/users/1579731", "pm_score": 5, "selected": false, "text": "zip" }, { "answer_id": 33765024, "author": "rbrisuda", "author_id": 2250569, "author_profile": "https://Stackoverflow.com/users/2250569", "pm_score": 6, "selected": false, "text": "import numpy as np\n\narray = [1, 2, 1, 3, 4, 5, 1]\nitem = 1\nnp_array = np.array(array)\nitem_index = np.where(np_array==item)\nprint item_index\n# Out: (array([0, 2, 6], dtype=int64),)\n" }, { "answer_id": 45559614, "author": "PythonProgrammi", "author_id": 6464947, "author_profile": "https://Stackoverflow.com/users/6464947", "pm_score": 5, "selected": false, "text": ">>> alist = ['foo', 'spam', 'egg', 'foo']\n>>> foo_indexes = [n for n,x in enumerate(alist) if x=='foo']\n>>> foo_indexes\n[0, 3]\n>>>\n" }, { "answer_id": 45654421, "author": "jihed gasmi", "author_id": 1946787, "author_profile": "https://Stackoverflow.com/users/1946787", "pm_score": 2, "selected": false, "text": ">>> [i for i,j in zip(range(len(haystack)), haystack) if j == 'needle' ]\n" }, { "answer_id": 45808300, "author": "Russia Must Remove Putin", "author_id": 541136, "author_profile": "https://Stackoverflow.com/users/541136", "pm_score": 6, "selected": false, "text": "[\"foo\", \"bar\", \"baz\"]" }, { "answer_id": 48530557, "author": "someone", "author_id": 1434265, "author_profile": "https://Stackoverflow.com/users/1434265", "pm_score": 2, "selected": false, "text": "mylist = [\"foo\", \"bar\", \"baz\", \"bar\"]\nnewlist = enumerate(mylist)\nfor index, item in newlist:\n if item == \"bar\":\n print(index, item)\n" }, { "answer_id": 49093542, "author": "Hamed Baatour", "author_id": 2602962, "author_profile": "https://Stackoverflow.com/users/2602962", "pm_score": 3, "selected": false, "text": "index()" }, { "answer_id": 49159543, "author": "Ankit Gupta", "author_id": 7864006, "author_profile": "https://Stackoverflow.com/users/7864006", "pm_score": 3, "selected": false, "text": "list(filter(lambda x: x[1]==\"bar\",enumerate([\"foo\", \"bar\", \"baz\", \"bar\", \"baz\", \"bar\", \"a\", \"b\", \"c\"])))\n" }, { "answer_id": 50537324, "author": "Ketan", "author_id": 2595035, "author_profile": "https://Stackoverflow.com/users/2595035", "pm_score": 4, "selected": false, "text": "idx = L.index(x) if (x in L) else -1\n" }, { "answer_id": 52263806, "author": "FatihAkici", "author_id": 6520041, "author_profile": "https://Stackoverflow.com/users/6520041", "pm_score": 2, "selected": false, "text": "list.index(item)" }, { "answer_id": 52502151, "author": "pylang", "author_id": 4531270, "author_profile": "https://Stackoverflow.com/users/4531270", "pm_score": 2, "selected": false, "text": "more_itertools" }, { "answer_id": 53306924, "author": "Siddharth Satpathy", "author_id": 10626090, "author_profile": "https://Stackoverflow.com/users/10626090", "pm_score": 2, "selected": false, "text": "lst" }, { "answer_id": 55218236, "author": "sahasrara62", "author_id": 5086255, "author_profile": "https://Stackoverflow.com/users/5086255", "pm_score": 1, "selected": false, "text": "from collections import defaultdict\n\nindex_dict = defaultdict(list) \nword_list = ['foo','bar','baz','bar','any', 'foo', 'much']\n\nfor word_index in range(len(word_list)) :\n index_dict[word_list[word_index]].append(word_index)\n\nword_index_to_find = 'foo' \nprint(index_dict[word_index_to_find])\n\n# output : [0, 5]\n" }, { "answer_id": 61016685, "author": "Vlad Bezden", "author_id": 30038, "author_profile": "https://Stackoverflow.com/users/30038", "pm_score": 3, "selected": false, "text": "import bisect\nfrom timeit import timeit\n\ndef bisect_search(container, value):\n return (\n index \n if (index := bisect.bisect_left(container, value)) < len(container) \n and container[index] == value else -1\n )\n\ndata = list(range(1000))\n# value to search\nvalue = 666\n\n# times to test\nttt = 1000\n\nt1 = timeit(lambda: data.index(value), number=ttt)\nt2 = timeit(lambda: bisect_search(data, value), number=ttt)\n\nprint(f\"{t1=:.4f}, {t2=:.4f}, diffs {t1/t2=:.2f}\")\n" }, { "answer_id": 62518645, "author": "Caveman", "author_id": 9225733, "author_profile": "https://Stackoverflow.com/users/9225733", "pm_score": 3, "selected": false, "text": "# Throws ValueError if nothing is found\nsome_list = ['foo', 'bar', 'baz'].index('baz')\n# some_list == 2\n" }, { "answer_id": 63631183, "author": "Badri Paudel", "author_id": 9898251, "author_profile": "https://Stackoverflow.com/users/9898251", "pm_score": 4, "selected": false, "text": "list = [\"foo\", \"bar\", \"baz\"]\n\nitem_to_find = \"foo\"\n\nif item_to_find in list:\n index = list.index(item_to_find)\n print(\"Index of the item is \" + str(index))\nelse:\n print(\"That word does not exist\") \n" }, { "answer_id": 67031974, "author": "Blackjack", "author_id": 13682949, "author_profile": "https://Stackoverflow.com/users/13682949", "pm_score": 3, "selected": false, "text": "array.index()" }, { "answer_id": 67384774, "author": "illuminato", "author_id": 2975438, "author_profile": "https://Stackoverflow.com/users/2975438", "pm_score": -1, "selected": false, "text": "a = [\"foo\", \"bar\", \"baz\"]\n[i for i in range(len(a)) if a[i].find(\"bar\") != -1]\n" }, { "answer_id": 69425614, "author": "MD SHAYON", "author_id": 8725395, "author_profile": "https://Stackoverflow.com/users/8725395", "pm_score": 2, "selected": false, "text": ">>> expences = [2200, 2350, 2600, 2130, 2190]\n>>> 2000 in expences\nFalse\n>>> expences.index(2200)\n0\n>>> expences.index(2350)\n1\n>>> index = expences.index(2350)\n>>> expences[index]\n2350\n\n>>> try:\n... print(expences.index(2100))\n... except ValueError as e:\n... print(e)\n... \n2100 is not in list\n>>> \n\n\n" }, { "answer_id": 70143454, "author": "Abdul Niyas P M", "author_id": 6699447, "author_profile": "https://Stackoverflow.com/users/6699447", "pm_score": 1, "selected": false, "text": "enumerate" }, { "answer_id": 70523709, "author": "Franz Kurt", "author_id": 7327114, "author_profile": "https://Stackoverflow.com/users/7327114", "pm_score": 2, "selected": false, "text": "'oi tchau'.index('oi') # 0\n['oi','tchau'].index('oi') # 0\n('oi','tchau').index('oi') # 0\n" }, { "answer_id": 70615103, "author": "sargupta", "author_id": 9658895, "author_profile": "https://Stackoverflow.com/users/9658895", "pm_score": 2, "selected": false, "text": "text = [\"foo\", \"bar\", \"baz\"]\ntarget = \"bar\"\n\n[index for index, value in enumerate(text) if value == target]\n" }, { "answer_id": 70702309, "author": "LunaticXXD10", "author_id": 16067738, "author_profile": "https://Stackoverflow.com/users/16067738", "pm_score": 4, "selected": false, "text": "index()" }, { "answer_id": 71017253, "author": "Kofi", "author_id": 12888115, "author_profile": "https://Stackoverflow.com/users/12888115", "pm_score": 3, "selected": false, "text": "a_list = [\"a\", \"b\", \"a\"]\nprint([index for (index , item) in enumerate(a_list) if item == \"a\"])\n" }, { "answer_id": 71900535, "author": "Abiodun Mustapha", "author_id": 18475123, "author_profile": "https://Stackoverflow.com/users/18475123", "pm_score": 5, "selected": false, "text": "me = [\"foo\", \"bar\", \"baz\"]\nme.index(\"bar\") \n" }, { "answer_id": 72121787, "author": "Deepeshkumar", "author_id": 1780667, "author_profile": "https://Stackoverflow.com/users/1780667", "pm_score": 0, "selected": false, "text": "list1 = [\"foo\",\"bar\",\"baz\"]\nfor index,value in zip(range(0,len(list1)),list1):\n if value == \"bar\":\n print(index)\n" }, { "answer_id": 73924789, "author": "My Car", "author_id": 16124033, "author_profile": "https://Stackoverflow.com/users/16124033", "pm_score": 2, "selected": false, "text": "[\"foo\", \"bar\", \"baz\"].index(\"bar\")\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25680/" ]
176,922
<p>For decades, in the field of computing (except disk manufacturers), a KB (kilobyte) was understood to mean 1024 bytes. In the past few years, there has been a movement to use KiB ("kibibyte") to mean 1024 bytes, and <i>change the meaning of kilobyte to be 1000 bytes</i>, dooming us to many more years of confusion. On the other hand, the movement seems to be confined to Gnome, and some <a href="http://en.wikipedia.org/wiki/Talk:Kilobyte#Kibibyte.3F" rel="noreferrer">overzealous wikipedia editing</a>.</p> <p><i>Will you be converting your programs to use KiB?</i> If you have ever displayed a filesize in KB, did you divide by 1000 or 1024?</p>
[ { "answer_id": 1402810, "author": "Noon Silk", "author_id": 154152, "author_profile": "https://Stackoverflow.com/users/154152", "pm_score": 0, "selected": false, "text": "1,000" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15947/" ]
176,931
<p>How can I get MSBuild to evaluate and print in a <code>&lt;Message /&gt;</code> task an absolute path given a relative path?</p> <p><strong>Property Group</strong></p> <pre><code>&lt;Source_Dir&gt;..\..\..\Public\Server\&lt;/Source_Dir&gt; &lt;Program_Dir&gt;c:\Program Files (x86)\Program\&lt;/Program_Dir&gt; </code></pre> <p><strong>Task</strong></p> <pre><code>&lt;Message Importance="low" Text="Copying '$(Source_Dir.FullPath)' to '$(Program_Dir)'" /&gt; </code></pre> <p><strong>Output</strong></p> <blockquote> <p>Copying '' to 'c:\Program Files (x86)\Program\'</p> </blockquote>
[ { "answer_id": 177136, "author": "brock.holum", "author_id": 15860, "author_profile": "https://Stackoverflow.com/users/15860", "pm_score": 3, "selected": false, "text": "public class ResolveRelativePath : Task\n{\n [Required]\n public string RelativePath { get; set; }\n\n [Output]\n public string FullPath { get; private set; }\n\n public override bool Execute()\n {\n try\n {\n DirectoryInfo dirInfo = new DirectoryInfo(RelativePath);\n FullPath = dirInfo.FullName;\n }\n catch (Exception ex)\n {\n Log.LogErrorFromException(ex);\n }\n return !Log.HasLoggedErrors;\n }\n}\n" }, { "answer_id": 177151, "author": "Scott Dorman", "author_id": 1559, "author_profile": "https://Stackoverflow.com/users/1559", "pm_score": 3, "selected": false, "text": "<PropertyGroup>\n <Program_Dir>c:\\Program Files (x86)\\Program\\</Program_Dir>\n</PropertyGroup>\n<ItemGroup>\n <Source_Dir Include=\"..\\Desktop\"/>\n</ItemGroup> \n<Target Name=\"BuildAll\">\n <Message Text=\"Copying '%(Source_Dir.FullPath)' to '$(Program_Dir)'\" />\n</Target>\n" }, { "answer_id": 179289, "author": "Scott Weinstein", "author_id": 25201, "author_profile": "https://Stackoverflow.com/users/25201", "pm_score": 2, "selected": false, "text": " <Target Name='Build'>\n <CreateItem Include='$(Source_Dir)'>\n <Output ItemName='SRCDIR' TaskParameter='Include' />\n </CreateItem>\n" }, { "answer_id": 1251198, "author": "Roman Starkov", "author_id": 33080, "author_profile": "https://Stackoverflow.com/users/33080", "pm_score": 8, "selected": true, "text": "$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\\your\\path'))\n" }, { "answer_id": 4894456, "author": "Aaron Carlson", "author_id": 57913, "author_profile": "https://Stackoverflow.com/users/57913", "pm_score": 5, "selected": false, "text": "<PropertyGroup>\n <Source_Dir>$([System.IO.Path]::GetFullPath('..\\..\\..\\Public\\Server\\'))</Source_Dir>\n</PropertyGroup>\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3957/" ]
176,964
<p>I want to return top 10 records from each section in one query. Can anyone help with how to do it? Section is one of the columns in the table.</p> <p>Database is SQL Server 2005. I want to return the top 10 by date entered. Sections are business, local, and feature. For one particular date I want only the top (10) business rows (most recent entry), the top (10) local rows, and the top (10) features.</p>
[ { "answer_id": 176977, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 5, "selected": false, "text": "select *\nfrom Things t\nwhere t.ThingID in (\n select top 10 ThingID\n from Things tt\n where tt.Section = t.Section and tt.ThingDate = @Date\n order by tt.DateEntered desc\n )\n and t.ThingDate = @Date\norder by Section, DateEntered desc\n" }, { "answer_id": 176979, "author": "Blorgbeard", "author_id": 369, "author_profile": "https://Stackoverflow.com/users/369", "pm_score": 4, "selected": false, "text": "select top 10 * from table where section=1\nunion\nselect top 10 * from table where section=2\nunion\nselect top 10 * from table where section=3\n" }, { "answer_id": 176985, "author": "Darrel Miller", "author_id": 6819, "author_profile": "https://Stackoverflow.com/users/6819", "pm_score": 8, "selected": false, "text": "SELECT rs.Field1,rs.Field2 \n FROM (\n SELECT Field1,Field2, Rank() \n over (Partition BY Section\n ORDER BY RankCriteria DESC ) AS Rank\n FROM table\n ) rs WHERE Rank <= 10\n" }, { "answer_id": 177212, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 4, "selected": false, "text": "SELECT a.* FROM articles AS a\n LEFT JOIN articles AS a2 \n ON a.section = a2.section AND a.article_date <= a2.article_date\nGROUP BY a.article_id\nHAVING COUNT(*) <= 10;\n" }, { "answer_id": 4991993, "author": "Diadistis", "author_id": 47401, "author_profile": "https://Stackoverflow.com/users/47401", "pm_score": 3, "selected": false, "text": "WITH [TopCategoryArticles] AS (\n SELECT \n [ArticleID],\n ROW_NUMBER() OVER (\n PARTITION BY [ArticleCategoryID]\n ORDER BY [ArticleDate] DESC\n ) AS [Order]\n FROM [dbo].[Articles]\n)\nSELECT [Articles].* \nFROM \n [TopCategoryArticles] LEFT JOIN \n [dbo].[Articles] ON\n [TopCategoryArticles].[ArticleID] = [Articles].[ArticleID]\nWHERE [TopCategoryArticles].[Order] = 1\n" }, { "answer_id": 5058731, "author": "bharathreddy", "author_id": 625448, "author_profile": "https://Stackoverflow.com/users/625448", "pm_score": 3, "selected": false, "text": "SQL> select * from emp e \n 2 where e.empno in (select d.empno from emp d \n 3 where d.deptno=e.deptno and rownum<3)\n 4 order by deptno\n 5 ;\n\n EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO\n" }, { "answer_id": 11052618, "author": "lorond", "author_id": 513392, "author_profile": "https://Stackoverflow.com/users/513392", "pm_score": 5, "selected": false, "text": "SELECT r.*\nFROM\n(\n SELECT\n r.*,\n ROW_NUMBER() OVER(PARTITION BY r.[SectionID]\n ORDER BY r.[DateEntered] DESC) rn\n FROM [Records] r\n) r\nWHERE r.rn <= 10\nORDER BY r.[DateEntered] DESC\n" }, { "answer_id": 11187383, "author": "Phil Rabbitt", "author_id": 1479651, "author_profile": "https://Stackoverflow.com/users/1479651", "pm_score": 7, "selected": false, "text": "WITH TOPTEN AS (\n SELECT *, ROW_NUMBER() \n over (\n PARTITION BY [group_by_field] \n order by [prioritise_field]\n ) AS RowNo \n FROM [table_name]\n)\nSELECT * FROM TOPTEN WHERE RowNo <= 10\n" }, { "answer_id": 14640138, "author": "Craig Tullis", "author_id": 618649, "author_profile": "https://Stackoverflow.com/users/618649", "pm_score": 3, "selected": false, "text": "SECTION SUBSECTION\n\ndeer American Elk/Wapiti\ndeer Chinese Water Deer\ndog Cocker Spaniel\ndog German Shephard\nhorse Appaloosa\nhorse Morgan\n" }, { "answer_id": 27658678, "author": "Vadim Loboda", "author_id": 623190, "author_profile": "https://Stackoverflow.com/users/623190", "pm_score": 4, "selected": false, "text": "declare @t table (\n Id int ,\n Section int,\n Moment date\n);\n\ninsert into @t values\n( 1 , 1 , '2014-01-01'),\n( 2 , 1 , '2014-01-02'),\n( 3 , 1 , '2014-01-03'),\n( 4 , 1 , '2014-01-04'),\n( 5 , 1 , '2014-01-05'),\n\n( 6 , 2 , '2014-02-06'),\n( 7 , 2 , '2014-02-07'),\n( 8 , 2 , '2014-02-08'),\n( 9 , 2 , '2014-02-09'),\n( 10 , 2 , '2014-02-10'),\n\n( 11 , 3 , '2014-03-11'),\n( 12 , 3 , '2014-03-12'),\n( 13 , 3 , '2014-03-13'),\n( 14 , 3 , '2014-03-14'),\n( 15 , 3 , '2014-03-15');\n\n\n-- TWO earliest records in each Section\n\nselect top 1 with ties\n Id, Section, Moment \nfrom\n @t\norder by \n case \n when row_number() over(partition by Section order by Moment) <= 2 \n then 0 \n else 1 \n end;\n\n\n-- THREE earliest records in each Section\n\nselect top 1 with ties\n Id, Section, Moment \nfrom\n @t\norder by \n case \n when row_number() over(partition by Section order by Moment) <= 3 \n then 0 \n else 1 \n end;\n\n\n-- three LATEST records in each Section\n\nselect top 1 with ties\n Id, Section, Moment \nfrom\n @t\norder by \n case \n when row_number() over(partition by Section order by Moment desc) <= 3 \n then 0 \n else 1 \n end;\n" }, { "answer_id": 41863032, "author": "Ali", "author_id": 2588755, "author_profile": "https://Stackoverflow.com/users/2588755", "pm_score": 1, "selected": false, "text": " SELECT city, country, population\n FROM\n (SELECT city, country, population, \n @country_rank := IF(@current_country = country, @country_rank + 1, 1) AS country_rank,\n @current_country := country \n FROM cities\n ORDER BY country, population DESC\n ) ranked\n WHERE country_rank <= 10;\n" }, { "answer_id": 47246291, "author": "Raghu S", "author_id": 3437885, "author_profile": "https://Stackoverflow.com/users/3437885", "pm_score": 3, "selected": false, "text": "SELECT rs.Field1,rs.Field2 \nFROM (\n SELECT Field1,Field2, ROW_NUMBER() \n OVER (Partition BY Section\n ORDER BY RankCriteria DESC ) AS Rank\n FROM table\n ) rs WHERE Rank <= 10\n" }, { "answer_id": 50326690, "author": "Lukas Eder", "author_id": 521799, "author_profile": "https://Stackoverflow.com/users/521799", "pm_score": 2, "selected": false, "text": "CROSS APPLY" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14752/" ]
176,966
<p>I've been looking for the answer for how to use BSWAP for lower 32-bit sub-register of 64-bit register. For example, <code>0x0123456789abcdef</code> is inside RAX register, and I want to change it to <code>0x01234567efcdab89</code> with a single instruction (because of performance).</p> <p>So I tried following inline function:</p> <pre class="lang-c prettyprint-override"><code>#define BSWAP(T) { \ __asm__ __volatile__ ( \ "bswap %k0" \ : "=q" (T) \ : "q" (T)); \ } </code></pre> <p>And the result was <code>0x00000000efcdab89</code>. I don't understand why the compiler acts like this. Does anybody know the efficient solution?</p>
[ { "answer_id": 176981, "author": "Dan Lenski", "author_id": 20789, "author_profile": "https://Stackoverflow.com/users/20789", "pm_score": -1, "selected": false, "text": "gcc -s" }, { "answer_id": 178474, "author": "Dan Lenski", "author_id": 20789, "author_profile": "https://Stackoverflow.com/users/20789", "pm_score": 4, "selected": true, "text": "ror" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25683/" ]
176,973
<p>I am a new to the prefuse visualization toolkit and have a couple of general questions. For my purpose, I would like to perform an initial visualization using prefuse (graphview / graphml). Once rendered, upon a user click of a node, I would like to completely reload a new xml file for a new visualization. I want to do this in order to allow me to "pre-package" graphs for display. </p> <p>For example. If I search for Ted. I would like to have an xml file relating to Ted load and render a display. Now in the display I see that Ted has nodes associated called Bill and Joe. When I click Joe, I would like to clear the display and load an xml file associated with Joe. And so on. </p> <p>I have looked into loading one very large xml file containing all node and node relationship info and allowing prefuse to handle this using the hops from one level to another. However, eventually I am sure that system performance issues will arise due to the size of data.</p> <p>Thanks in advance for any help, John </p>
[ { "answer_id": 13370364, "author": "alemangui", "author_id": 1046444, "author_profile": "https://Stackoverflow.com/users/1046444", "pm_score": 0, "selected": false, "text": "public void refresh(clickedNode){\n visualization.removeGroup(GRAPH);\n visualization.removeGroup(AGGR);\n activity.cancel();\n actionList.cancel();\n visualization.reset();\n // process the XML and reload your graph here\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
176,983
<p>I am trying to learn CodeIgniter to use for a shopping site, but I am not having luck with the official doc. Does anyone know of anything that will help?</p>
[ { "answer_id": 177117, "author": "jmccartie", "author_id": 24708, "author_profile": "https://Stackoverflow.com/users/24708", "pm_score": 3, "selected": true, "text": "<link href=\"<?=base_url();?>content/css/main.css\" rel=\"stylesheet\" type=\"text/css\" />\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25695/" ]
176,989
<p>In the early days of C++ when it was bolted on top of C, you could not use NULL as it was defined as <code>(void*)0</code>. You could not assign NULL to any pointer other than <code>void*</code>, which made it kind of useless. Back in those days, it was accepted that you used <code>0</code> (zero) for null pointers.</p> <p>To this day, I have continued to use zero as a null pointer but those around me insist on using <code>NULL</code>. I personally do not see any benefit to giving a name (<code>NULL</code>) to an existing value - and since I also like to test pointers as truth values:</p> <pre><code>if (p &amp;&amp; !q) do_something(); </code></pre> <p>then using zero makes more sense (as in if you use <code>NULL</code>, you cannot logically use <code>p &amp;&amp; !q</code> - you need to explicitly compare against <code>NULL</code>, unless you assume <code>NULL</code> is zero, in which case why use <code>NULL</code>).</p> <p>Is there any objective reason to prefer zero over NULL (or vice versa), or is all just personal preference?</p> <p>Edit: I should add (and meant to originally say) that with RAII and exceptions, I rarely use zero/NULL pointers, but sometimes you do need them still.</p>
[ { "answer_id": 177007, "author": "Martin Cote", "author_id": 9936, "author_profile": "https://Stackoverflow.com/users/9936", "pm_score": 9, "selected": true, "text": "NULL" }, { "answer_id": 177009, "author": "mxg", "author_id": 11157, "author_profile": "https://Stackoverflow.com/users/11157", "pm_score": 4, "selected": false, "text": "char *p;\n\n...\n\nif (p) { ... }\n" }, { "answer_id": 177013, "author": "Dominik Grabiec", "author_id": 3719, "author_profile": "https://Stackoverflow.com/users/3719", "pm_score": 4, "selected": false, "text": "#ifndef __cplusplus\n#define NULL (void*)0\n#else\n#define NULL 0\n#endif\n" }, { "answer_id": 177016, "author": "Jimmy", "author_id": 25071, "author_profile": "https://Stackoverflow.com/users/25071", "pm_score": 2, "selected": false, "text": "void *ptr = &something;\n/* lots o' code */\nptr = NULL; // more obvious that it's a pointer and not being used\n" }, { "answer_id": 177095, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 5, "selected": false, "text": "static const int nullptr = 0;\n" }, { "answer_id": 177187, "author": "Andrew Stein", "author_id": 13029, "author_profile": "https://Stackoverflow.com/users/13029", "pm_score": 6, "selected": false, "text": "NULL" }, { "answer_id": 177716, "author": "Richard Corden", "author_id": 11698, "author_profile": "https://Stackoverflow.com/users/11698", "pm_score": 7, "selected": false, "text": "NULL" }, { "answer_id": 700412, "author": "jon-hanson", "author_id": 84538, "author_profile": "https://Stackoverflow.com/users/84538", "pm_score": 4, "selected": false, "text": "const // It is a const object...\nclass nullptr_t \n{\npublic:\n template<class T>\n operator T*() const // convertible to any type of null non-member pointer...\n { return 0; }\n\n template<class C, class T>\n operator T C::*() const // or any type of null member pointer...\n { return 0; }\n\nprivate:\n void operator&() const; // Can't take address of nullptr\n\n} nullptr = {};\n" }, { "answer_id": 700895, "author": "Ðаn", "author_id": 8877, "author_profile": "https://Stackoverflow.com/users/8877", "pm_score": 2, "selected": false, "text": "void foo(const Bar* pBar) { ... }\n" }, { "answer_id": 1234382, "author": "Fernando N.", "author_id": 147336, "author_profile": "https://Stackoverflow.com/users/147336", "pm_score": 1, "selected": false, "text": "void foo(char *); \nvoid foo(int); \nfoo(NULL); // calls int version instead of pointer version! \n" }, { "answer_id": 1437224, "author": "Michael Krelin - hacker", "author_id": 95382, "author_profile": "https://Stackoverflow.com/users/95382", "pm_score": 3, "selected": false, "text": "0" }, { "answer_id": 4227356, "author": "abonet", "author_id": 513751, "author_profile": "https://Stackoverflow.com/users/513751", "pm_score": 5, "selected": false, "text": " cerr << sizeof(0) << endl;\n cerr << sizeof(NULL) << endl;\n cerr << sizeof(void*) << endl;\n\n ============\n On a 64-bit gcc RHEL platform you get:\n 4\n 8\n 8\n ================\n" }, { "answer_id": 4331500, "author": "Pizzach", "author_id": 527477, "author_profile": "https://Stackoverflow.com/users/527477", "pm_score": -1, "selected": false, "text": "virtual void DrawTo(BITMAP *buffer) =0;" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/176989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23744/" ]
177,011
<p>OK I have an array of tserversocket and am using the tag property to keep track of its index. When an event is fired off such as _clientconnect i am using Index := (Sender as TServerSocket).Tag; but i get an error that highlights that line and tells me its an invalid typecast. What am I doing wrong if all I want to do is get the tag property field? It works with other objects.</p>
[ { "answer_id": 177270, "author": "Chris Latta", "author_id": 20977, "author_profile": "https://Stackoverflow.com/users/20977", "pm_score": 2, "selected": false, "text": "procedure TfrmServer.sskServerClientConnect(Sender: TObject; Socket: TCustomWinSocket);\n" }, { "answer_id": 179830, "author": "Jody Dawkins", "author_id": 1234, "author_profile": "https://Stackoverflow.com/users/1234", "pm_score": 2, "selected": false, "text": "TMyServerWinSocket = class(TServerWinSocket)\nprivate\n FServerSocket : TServerSocket;\npublic\n destructor Destroy; override;\n property Server : TServerSocket read FServerSocket write FServerSocket;\nend;\n\nTMyServerSocket = class(TServerSocket)\npublic\n constructor Create(AOwner : TComponent);\nend;\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177011", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
177,039
<p>First, two examples:</p> <pre><code>// This works int foo = 43; long lFoo = foo; // This doesn't object foo = (int)43; long? nullFoo = foo as long?; // returns null long lFoo = (long)foo; // throws InvalidCastException if (foo.GetType() == typeof(int)) Console.WriteLine("But foo is an int..."); // This gets written out </code></pre> <p>Now, my guess as to why the second doesn't work is because of boxing. The purpose behind this code is to implement <code>IComparable</code>. I need some way to coerce an object into either a long or a ulong as appropriate, or if it's neither, than to throw an error. I don't want to have to implement checks for each basic numeric type (byte, int, long, ubyte, ...) I'd rather just catch them in the largest numeric type and deal with it that way. Thoughts from all the smart people here? How can I unbox the object, preferably avoiding reflection, but I suppose if that's the only way... Or should I just not implement the non-generics version of <code>IComparable</code>?</p> <p><strong>Edit:</strong></p> <p>This seems to work, but seems like a horrible hack around the problem. Is it just me?</p> <pre><code>long lFoo = long.Parse(foo.ToString()); </code></pre>
[ { "answer_id": 177081, "author": "Nat", "author_id": 13813, "author_profile": "https://Stackoverflow.com/users/13813", "pm_score": 0, "selected": false, "text": "object foo = (int)43;\nlong outVal;\nif(long.TryParse(foo.ToString(),out outVal))\n{\n//take action with correct value of long\n}\nelse\n{\n//maybe passed you another type of object\n}\n" }, { "answer_id": 177101, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 4, "selected": true, "text": "object foo = (int) 43;\nlong lFoo = ((IConvertible) foo).ToInt64(null);\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
177,042
<p>I am having an issue setting up cURL with IIS 6.0, Windows Server 2003, PHP 5.2.6</p> <p>I have installed to <code>C:\PHP</code></p> <pre><code>set PHPRC = C:\PHP\php.ini </code></pre> <p>copied <code>ssleay32.dll</code> and <code>libeay32.dll</code> to <code>C:\PHP</code></p> <p>in php.ini, uncommented the line</p> <pre><code>extension=php_curl.dll extension_dir="C:\PHP\ext" </code></pre> <p><code>c:\php\ext</code> has the dll <code>php_curl.dll</code></p> <p><code>C:\PHP</code> is in <code>PATH</code></p> <p>still getting </p> <blockquote> <p>Fatal error: Call to undefined function curl_init()</p> </blockquote>
[ { "answer_id": 177112, "author": "Randy", "author_id": 9361, "author_profile": "https://Stackoverflow.com/users/9361", "pm_score": 2, "selected": false, "text": "php -c . -i | find /i \"curl\"\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20641/" ]
177,052
<p>I am working on integrating geolocation services into a website and the best source of data I've found so far is MaxMind's GeoIP API with GeoLite City data. Even this data seems to often be questionable though. For example, I am located in downtown Palo Alto, but it locates my IP as being in Portola Valley, which is about 7 miles away. Palo Alto has a population of 60k+, whereas Portola Valley has a population of less than 5k. I would think if you see an IP originating somewhere around there it would make more sense to assume it was coming from the highly populated city, not the tiny one. I've also had it locate Palo Alto IPs completely across the country in Kentucky, etc.</p> <p>Does anyone know of any better sources of data, or any tools/technologies/efforts to improve the accuracy of geolocation efforts? Commercial solutions are fine.</p>
[ { "answer_id": 205585, "author": "stevemegson", "author_id": 25028, "author_profile": "https://Stackoverflow.com/users/25028", "pm_score": 2, "selected": false, "text": "ORDER BY ( Distance / LOG( Population ) )\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2168/" ]
177,054
<p>There's a common way to store multiple values in one variable, by using a bitmask. For example, if a user has read, write and execute privileges on an item, that can be converted to a single number by saying <code>read = 4 (2^2), write = 2 (2^1), execute = 1 (2^0)</code> and then add them together to get 7.</p> <p>I use this technique in several web applications, where I'd usually store the variable into a field and give it a type of MEDIUMINT or whatever, depending on the number of different values.</p> <p>What I'm interested in, is whether or not there is a practical limit to the number of values you can store like this? For example, if the number was over 64, you couldn't use (64 bit) integers any more. If this was the case, what would you use? How would it affect your program logic (ie: could you still use bitwise comparisons)?</p> <p><em>I know that once you start getting really large sets of values, a different method would be the optimal solution, but I'm interested in the boundaries of <strong>this</strong> method.</em></p>
[ { "answer_id": 177092, "author": "Mike Spross", "author_id": 17862, "author_profile": "https://Stackoverflow.com/users/17862", "pm_score": 3, "selected": true, "text": "set_bit" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177054", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
177,062
<p>I know that to change the index page for rails I need to do three things: delete the index.html, do something with routes.rb, and probably make an action that the route will point to. It's the details that I am a little fuzzy on :-)</p>
[ { "answer_id": 177913, "author": "allesklar", "author_id": 19893, "author_profile": "https://Stackoverflow.com/users/19893", "pm_score": 3, "selected": false, "text": "<h1>My New Index Page</h1>\n<p>Some text here.</p>\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12448/" ]
177,080
<p>Method signature in Java:</p> <pre><code>public List&lt;String&gt; getFilesIn(List&lt;File&gt; directories) </code></pre> <p>similar one in ruby</p> <pre><code>def get_files_in(directories) </code></pre> <p>In the case of Java, the type system gives me information about what the method expects and delivers. In Ruby's case, I have <strong>no</strong> clue what I'm supposed to pass in, or what I'll expect to receive.</p> <p>In Java, the object must formally implement the interface. In Ruby, the object being passed in must respond to whatever methods are called in the method defined here. </p> <p>This seems highly problematic:</p> <ol> <li>Even with 100% accurate, up-to-date documentation, the Ruby code has to essentially expose its implementation, breaking encapsulation. "OO purity" aside, this would seem to be a maintenance nightmare.</li> <li>The Ruby code gives me <strong>no</strong> clue what's being returned; I would have to essentially experiment, or read the code to find out what methods the returned object would respond to.</li> </ol> <p>Not looking to debate static typing vs duck typing, but looking to understand how you maintain a production system where you have almost no ability to design by contract.</p> <h3>Update</h3> <p>No one has really addressed the exposure of a method's internal implementation via documentation that this approach requires. Since there are no interfaces, if I'm not expecting a particular type, don't I have to itemize every method I might call so that the caller knows what can be passed in? Or is this just an edge case that doesn't really come up?</p>
[ { "answer_id": 177110, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 3, "selected": false, "text": "i = {}\n=> {}\ni.methods.sort\n=> [\"==\", \"===\", \"=~\", \"[]\", \"[]=\", \"__id__\", \"__send__\", \"all?\", \"any?\", \"class\", \"clear\", \"clone\", \"collect\", \"default\", \"default=\", \"default_proc\", \"delete\", \"delete_if\", \"detect\", \"display\", \"dup\", \"each\", \"each_key\", \"each_pair\", \"each_value\", \"each_with_index\", \"empty?\", \"entries\", \"eql?\", \"equal?\", \"extend\", \"fetch\", \"find\", \"find_all\", \"freeze\", \"frozen?\", \"gem\", \"grep\", \"has_key?\", \"has_value?\", \"hash\", \"id\", \"include?\", \"index\", \"indexes\", \"indices\", \"inject\", \"inspect\", \"instance_eval\", \"instance_of?\", \"instance_variable_defined?\", \"instance_variable_get\", \"instance_variable_set\", \"instance_variables\", \"invert\", \"is_a?\", \"key?\", \"keys\", \"kind_of?\", \"length\", \"map\", \"max\", \"member?\", \"merge\", \"merge!\", \"method\", \"methods\", \"min\", \"nil?\", \"object_id\", \"partition\", \"private_methods\", \"protected_methods\", \"public_methods\", \"rehash\", \"reject\", \"reject!\", \"replace\", \"require\", \"respond_to?\", \"select\", \"send\", \"shift\", \"singleton_methods\", \"size\", \"sort\", \"sort_by\", \"store\", \"taint\", \"tainted?\", \"to_a\", \"to_hash\", \"to_s\", \"type\", \"untaint\", \"update\", \"value?\", \"values\", \"values_at\", \"zip\"]\ni.respond_to?('keys')\n=> true\ni.respond_to?('get_files_in') \n=> false\n" }, { "answer_id": 177115, "author": "Alan", "author_id": 17205, "author_profile": "https://Stackoverflow.com/users/17205", "pm_score": 3, "selected": false, "text": "def get_files_in(directories)\n unless File.directory? directories\n raise ArgumentError, \"directories should be a file directory, you bozo :)\"\n end\n # rest of my block\nend\n" }, { "answer_id": 177127, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 5, "selected": false, "text": "get_files_in" }, { "answer_id": 177158, "author": "jop", "author_id": 11830, "author_profile": "https://Stackoverflow.com/users/11830", "pm_score": 2, "selected": false, "text": "get_files_in(directory)" }, { "answer_id": 25228749, "author": "Boris Stitnicky", "author_id": 1153747, "author_profile": "https://Stackoverflow.com/users/1153747", "pm_score": 2, "selected": false, "text": "get_files_in" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3029/" ]
177,113
<p>I have a std::string with UTF-8 characters in it.<br> I want to convert the string to its closest equivalent with ASCII characters.</p> <p>For example:</p> <p>Łódź => Lodz<br> Assunção => Assuncao<br> Schloß => Schloss</p> <p>Unfortunatly ICU library is realy unintuitive and I haven't found good documentation on its usage, so it would take me too much time to learn to use it. Time I dont have.</p> <p>Could someone give a little example about how can this be done??<br> thanks.</p>
[ { "answer_id": 177224, "author": "shoosh", "author_id": 9611, "author_profile": "https://Stackoverflow.com/users/9611", "pm_score": 2, "selected": false, "text": "ICONV_SET_TRANSLITERATE" }, { "answer_id": 1533156, "author": "Steven R. Loomis", "author_id": 185799, "author_profile": "https://Stackoverflow.com/users/185799", "pm_score": 1, "selected": false, "text": "ucnv_setFromUCallBack(gConverter, &UCNV_FROM_U_CALLBACK_DECOMPOSE, &status);\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25700/" ]
177,118
<p>I saw this question on Reddit, and there were no positive solutions presented, and I thought it would be a perfect question to ask here. This was in a thread about interview questions:</p> <blockquote> <p>Write a method that takes an int array of size m, and returns (True/False) if the array consists of the numbers n...n+m-1, all numbers in that range and only numbers in that range. The array is not guaranteed to be sorted. (For instance, {2,3,4} would return true. {1,3,1} would return false, {1,2,4} would return false.</p> <p>The problem I had with this one is that my interviewer kept asking me to optimize (faster O(n), less memory, etc), to the point where he claimed you could do it in one pass of the array using a constant amount of memory. Never figured that one out.</p> </blockquote> <p>Along with your solutions please indicate if they assume that the array contains unique items. Also indicate if your solution assumes the sequence starts at 1. (I've modified the question slightly to allow cases where it goes 2, 3, 4...)</p> <p><strong>edit:</strong> I am now of the opinion that there does not exist a linear in time and constant in space algorithm that handles duplicates. Can anyone verify this?</p> <p>The duplicate problem boils down to testing to see if the array contains duplicates in O(n) time, O(1) space. If this can be done you can simply test first and if there are no duplicates run the algorithms posted. So can you test for dupes in O(n) time O(1) space?</p>
[ { "answer_id": 177126, "author": "hazzen", "author_id": 5066, "author_profile": "https://Stackoverflow.com/users/5066", "pm_score": 4, "selected": false, "text": "1" }, { "answer_id": 177128, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 0, "selected": false, "text": "def test(a, n, m):\n seen = [False] * m\n for x in a:\n if x < n or x >= n+m:\n return False\n if seen[x-n]:\n return False\n seen[x-n] = True\n return False not in seen\n\nprint test([2, 3, 1], 1, 3)\nprint test([1, 3, 1], 1, 3)\nprint test([1, 2, 4], 1, 3)\n" }, { "answer_id": 177145, "author": "Kent Fredric", "author_id": 15614, "author_profile": "https://Stackoverflow.com/users/15614", "pm_score": 0, "selected": false, "text": "def uniqueSet( array )\n check_index = 0; \n check_value = 0; \n min = array[0];\n array.each_with_index{ |value,index|\n check_index = check_index ^ ( 1 << index );\n check_value = check_value ^ ( 1 << value );\n min = value if value < min\n } \n check_index = check_index << min;\n return check_index == check_value; \nend\n" }, { "answer_id": 177217, "author": "David Crow", "author_id": 2783, "author_profile": "https://Stackoverflow.com/users/2783", "pm_score": -1, "selected": false, "text": "is_range(int[] nums, int n, int m) {\n sum_to_m := (m * (m + 1)) / 2\n expected_sum := sum_to_m - (n * (n - 1)) / 2\n real_sum := sum(nums)\n expected_product := m! / (n - 1)!\n real_product := product(nums)\n return ((real_sum == expected_sum) && (expected_product == real_product))\n" }, { "answer_id": 177222, "author": "CaptSolo", "author_id": 2025531, "author_profile": "https://Stackoverflow.com/users/2025531", "pm_score": -1, "selected": false, "text": "def try_arr(arr):\n n = len(arr)\n return (not any(x<1 or x>n for x in arr)) and sum(arr)==n*(n+1)/2\n\n$ print try_arr([1,2,3])\nTrue\n\n$ print try_arr([1,3,1])\nFalse\n\n$ print try_arr([1,2,4])\nFalse\n" }, { "answer_id": 177256, "author": "Loren Pechtel", "author_id": 10659, "author_profile": "https://Stackoverflow.com/users/10659", "pm_score": -1, "selected": false, "text": "Fail := False;\nSum1 := 0;\nSum2 := 0;\nTSum1 := 0;\nTSum2 := 0;\n\nFor i := 1 to m do\n Begin\n TSum1 := TSum1 + i;\n TSum2 := TSum2 + i * i;\n Item := Array[i] - n;\n If (Item < 0) or (Item >= m) then \n Fail := True\n Else \n Begin\n Sum1 := Sum1 + Item;\n Sum2 := Sum2 + Item * Item;\n End;\n End;\nFail := Fail Or (Sum1 <> TSum1) or (Sum2 <> TSum2);\n" }, { "answer_id": 177264, "author": "Kevin Day", "author_id": 10973, "author_profile": "https://Stackoverflow.com/users/10973", "pm_score": 1, "selected": false, "text": "for i = 0 to m\n if (a[a[i]]==a[i]) return false; // we have a duplicate\n while (a[a[i]] > a[i]) swapArrayIndexes(a[i], i)\n sum = sum + a[i]\nnext\n\nif sum = (n+m-1)*m return true else return false\n" }, { "answer_id": 177269, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 0, "selected": false, "text": "[n ... n + m - 1]" }, { "answer_id": 177566, "author": "b3.", "author_id": 14946, "author_profile": "https://Stackoverflow.com/users/14946", "pm_score": -1, "selected": false, "text": "-1 + 2 - 3 + 4 - 5 \n" }, { "answer_id": 177605, "author": "hurst", "author_id": 10991, "author_profile": "https://Stackoverflow.com/users/10991", "pm_score": 0, "selected": false, "text": "public class Program\n{\n static bool puzzle(int[] inAry)\n {\n var m = inAry.Count();\n var outAry = new int?[2 * m - 1];\n int diff = 0;\n int left = 0;\n int right = 0;\n outAry[m - 1] = inAry[0];\n for (var i = 1; i < m; i += 1)\n {\n diff = inAry[i] - inAry[0];\n if (diff > m - 1 + right || diff < 1 - m + left) return false;\n if (outAry[m - 1 + diff] != null) return false;\n outAry[m - 1 + diff] = inAry[i];\n if (diff > left) left = diff;\n if (diff < right) right = diff;\n }\n return true;\n }\n\n static void Main(string[] args)\n {\n var inAry = new int[3]{ 2, 3, 4 };\n Console.WriteLine(puzzle(inAry));\n inAry = new int[13] { -3, 5, -1, -2, 9, 8, 2, 3, 0, 6, 4, 7, 1 };\n Console.WriteLine(puzzle(inAry));\n inAry = new int[3] { 21, 31, 41 };\n Console.WriteLine(puzzle(inAry));\n Console.ReadLine();\n }\n\n}\n" }, { "answer_id": 177659, "author": "popopome", "author_id": 1556, "author_profile": "https://Stackoverflow.com/users/1556", "pm_score": -1, "selected": false, "text": "bool is_same(const int* a, const int* b, int len)\n{\n int even_xor = 0; \n int odd_xor = 0;\n\n for(int i=0;i<len;++i)\n {\n if(a[i] & 0x01) odd_xor ^= a[i];\n else even_xor ^= a[i];\n\n if(b[i] & 0x01) odd_xor ^= b[i];\n else even_xor ^= b[i];\n }\n\n return (even_xor == 0) && (odd_xor == 0);\n}\n" }, { "answer_id": 177662, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 1, "selected": false, "text": "function testArray($nums, $n, $m) {\n // check the sum. PHP offers this array_sum() method, but it's\n // trivial to write your own. O(n) here.\n if (array_sum($nums) != ($m * ($m + 2 * $n - 1) / 2)) {\n return false; // checksum failed.\n }\n for ($i = 0; $i < $m; ++$i) {\n // check if the number is in the proper range\n if ($nums[$i] < $n || $nums[$i] >= $n + $m) {\n return false; // value out of range.\n }\n\n while (($shouldBe = $nums[$i] - $n) != $i) {\n if ($nums[$shouldBe] == $nums[$i]) {\n return false; // duplicate\n }\n $temp = $nums[$i];\n $nums[$i] = $nums[$shouldBe];\n $nums[$shouldBe] = $temp;\n }\n }\n return true; // huzzah!\n}\n\nvar_dump(testArray(array(1, 2, 3, 4, 5), 1, 5)); // true\nvar_dump(testArray(array(5, 4, 3, 2, 1), 1, 5)); // true\nvar_dump(testArray(array(6, 4, 3, 2, 0), 1, 5)); // false - out of range\nvar_dump(testArray(array(5, 5, 3, 2, 1), 1, 5)); // false - checksum fail\nvar_dump(testArray(array(5, 4, 3, 2, 5), 1, 5)); // false - dupe\nvar_dump(testArray(array(-2, -1, 0, 1, 2), -2, 5)); // true\n" }, { "answer_id": 177807, "author": "Skizz", "author_id": 1898, "author_profile": "https://Stackoverflow.com/users/1898", "pm_score": 0, "selected": false, "text": "variance = sum [i=1..n] (f(i)-mean).(f(i)-mean)/n\n" }, { "answer_id": 182378, "author": "Stephen Denne", "author_id": 11721, "author_profile": "https://Stackoverflow.com/users/11721", "pm_score": 3, "selected": false, "text": "a[i] % a.length" }, { "answer_id": 185360, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 0, "selected": false, "text": "a = {0, 2, 7, 5,}" }, { "answer_id": 186528, "author": "Rafał Dowgird", "author_id": 12166, "author_profile": "https://Stackoverflow.com/users/12166", "pm_score": -1, "selected": false, "text": "d" }, { "answer_id": 188315, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 0, "selected": false, "text": "34" }, { "answer_id": 188791, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 0, "selected": false, "text": "{1, 1, 2, 4, 6, 7, 7}" }, { "answer_id": 189825, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 0, "selected": false, "text": "def ispermutation(iterable, m, n):\n \"\"\"Whether iterable and the range [n, n+m) have the same elements.\n\n pre-condition: there are no duplicates in the iterable\n \"\"\" \n for i, elem in enumerate(iterable):\n if not n <= elem < n+m:\n return False\n\n return i == m-1\n\nprint(ispermutation([1, 42], 2, 1) == False)\nprint(ispermutation(range(10), 10, 0) == True)\nprint(ispermutation((2, 1, 3), 3, 1) == True)\nprint(ispermutation((2, 1, 3), 3, 0) == False)\nprint(ispermutation((2, 1, 3), 4, 1) == False)\nprint(ispermutation((2, 1, 3), 2, 1) == False)\n" }, { "answer_id": 189891, "author": "caskey", "author_id": 114986, "author_profile": "https://Stackoverflow.com/users/114986", "pm_score": 1, "selected": false, "text": "public class StraightArray { \n static int evict(int[] a, int i) {\n int t = a[i];\n a[i] = a[t%a.length];\n a[t%a.length] = t;\n return t;\n }\n static boolean isStraight(int[] values) {\n for(int i = 0; i < values.length; i++) {\n while(values[i]%values.length != i) {\n int evicted = evict(values, i);\n if(evicted%values.length == values[i]%values.length) {\n return false;\n }\n }\n }\n for(int i = 0; i < values.length-1; i++) {\n int n = (values[i]%values.length)+1;\n int m = values[(i+1)]%values.length;\n if(n != m) {\n return false;\n }\n }\n return true;\n }\n}\n" }, { "answer_id": 311497, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": -1, "selected": false, "text": "int m" }, { "answer_id": 861093, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "count = 0\nprod = fact = 1\nfor num in my_list:\n prod *= num\n count +=1 \n fact *= count\nif not prod % fact: \n return 1 \nelse: \n return 0 \n" }, { "answer_id": 863653, "author": "Eric Bainville", "author_id": 80448, "author_profile": "https://Stackoverflow.com/users/80448", "pm_score": 0, "selected": false, "text": "S_i is an int array of size P_i, initially filled with 0, i=1..K\nM is the length of the input sequence\nMn = INT_MAX\nMx = INT_MIN\n\nfor x in the input sequence:\n for i in 1..K: S_i[x % P_i]++ // count occurrences mod Pi\n Mn = min(Mn,x) // update min\n Mx = max(Mx,x) // and max\n\nif Mx-Mn != M-1: return False // Check bounds\n\nfor i in 1..K:\n // Check profile mod P_i\n Q = M / P_i\n R = M % P_i\n Check S_i[(Mn+j) % P_i] is Q+1 for j=0..R-1 and Q for j=R..P_i-1\n if this test fails, return False\n\nreturn True\n" }, { "answer_id": 867911, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 0, "selected": false, "text": "def contiguous( values )\n #initialization\n encountered = Array.new( values.size, false )\n min, max = nil, nil\n visited = 0\n\n values.each do |v|\n\n index = v % encountered.size\n\n if( encountered[ index ] )\n return \"duplicates\"; \n end\n\n encountered[ index ] = true\n min = v if min == nil or v < min\n max = v if max == nil or v > max \n visited += 1\n end\n\n if ( max - min + 1 != values.size ) or visited != values.size\n return \"hole\"\n else\n return \"contiguous\"\n end\n\nend\n\ntests = [ \n[ false, [ 2,4,5,6 ] ], \n[ false, [ 10,11,13,14 ] ] , \n[ true , [ 20,21,22,23 ] ] , \n[ true , [ 19,20,21,22,23 ] ] ,\n[ true , [ 20,21,22,23,24 ] ] ,\n[ false, [ 20,21,22,23,24+5 ] ] ,\n[ false, [ 2,2,3,4,5 ] ]\n]\n\ntests.each do |t|\n result = contiguous( t[1] )\n if( t[0] != ( result == \"contiguous\" ) )\n puts \"Failed Test : \" + t[1].to_s + \" returned \" + result\n end\nend\n" }, { "answer_id": 1009632, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "//Java: assumes all numbers in arr > 1\nboolean checkArrayConsecutiveRange(int[] arr) {\n\n// find min/max\nint min = arr[0]; int max = arr[0]\nfor (int i=1; i<arr.length; i++) {\n min = (arr[i] < min ? arr[i] : min);\n max = (arr[i] > max ? arr[i] : max);\n}\nif (max-min != arr.length) return false;\n\n// flag and check\nboolean ret = true;\nfor (int i=0; i<arr.length; i++) {\n int targetI = Math.abs(arr[i])-min;\n if (arr[targetI] < 0) {\n ret = false; \n break;\n }\n arr[targetI] = -arr[targetI];\n}\nfor (int i=0; i<arr.length; i++) {\n arr[i] = Math.abs(arr[i]);\n}\n\nreturn ret;\n}\n" }, { "answer_id": 2878096, "author": "erisco", "author_id": 260584, "author_profile": "https://Stackoverflow.com/users/260584", "pm_score": 0, "selected": false, "text": "function is_permutation($ints) {\n\n /* Gather some meta-data. These scans can\n be done simultaneously */\n $lowest = min($ints);\n $length = count($ints);\n\n $max_index = $length - 1;\n\n $sort_run_count = 0;\n\n /* I do not have any proof that running this sort twice\n will always completely sort the array (of course only\n intentionally happening if the array is a permutation) */\n\n while ($sort_run_count < 2) {\n\n for ($i = 0; $i < $length; ++$i) {\n\n $dest_index = $ints[$i] - $lowest;\n\n if ($i == $dest_index) {\n continue;\n }\n\n if ($dest_index > $max_index) {\n return false;\n }\n\n if ($ints[$i] == $ints[$dest_index]) {\n return false;\n }\n\n $temp = $ints[$dest_index];\n $ints[$dest_index] = $ints[$i];\n $ints[$i] = $temp;\n\n }\n\n ++$sort_run_count;\n\n }\n\n return true;\n\n}\n" }, { "answer_id": 2885916, "author": "MSN", "author_id": 6210, "author_profile": "https://Stackoverflow.com/users/6210", "pm_score": 0, "selected": false, "text": "n" }, { "answer_id": 3336509, "author": "ignoramous", "author_id": 402375, "author_profile": "https://Stackoverflow.com/users/402375", "pm_score": 1, "selected": false, "text": "#include<stdio.h>\n\n#define swapxor(a,i,j) a[i]^=a[j];a[j]^=a[i];a[i]^=a[j];\n\nint check_ntom(int a[], int n, int m) {\n int i = 0, j = 0;\n for(i = 0; i < m; i++) {\n if(a[i] < n || a[i] >= n+m) return 0; //invalid entry\n j = a[i] - n;\n while(j != i) {\n if(a[i]==a[j]) return -1; //bucket already occupied. Dupe.\n swapxor(a, i, j); //faster bitwise swap\n j = a[i] - n;\n if(a[i]>=n+m) return 0; //[NEW] invalid entry\n }\n }\n return 200; //OK\n}\n\nint main() {\n int n=5, m=5;\n int a[] = {6, 5, 7, 9, 8};\n int r = check_ntom(a, n, m);\n printf(\"%d\", r);\n return 0;\n}\n" }, { "answer_id": 7860115, "author": "Vibhaj", "author_id": 941691, "author_profile": "https://Stackoverflow.com/users/941691", "pm_score": -1, "selected": false, "text": "(maximum - minimum + 1) == array_size\n" }, { "answer_id": 8888883, "author": "yvette", "author_id": 1153036, "author_profile": "https://Stackoverflow.com/users/1153036", "pm_score": 1, "selected": false, "text": "boolean determineContinuousArray(int *arr, int len)\n{\n // Suppose the array is like below:\n //int arr[10] = {7,11,14,9,8,100,12,5,13,6};\n //int len = sizeof(arr)/sizeof(int);\n\n int n = arr[0];\n\n int *result = new int[len];\n for(int i=0; i< len; i++)\n result[i] = -1;\n for (int i=0; i < len; i++)\n {\n int cur = arr[i];\n int hold ;\n if ( arr[i] < n){\n n = arr[i];\n }\n while(true){\n if ( cur - n >= len){\n cout << \"array index out of range: meaning this is not a valid array\" << endl;\n return false;\n }\n else if ( result[cur - n] != cur){\n hold = result[cur - n];\n result[cur - n] = cur;\n if (hold == -1) break;\n cur = hold;\n\n }else{\n cout << \"found duplicate number \" << cur << endl;\n return false;\n }\n\n }\n }\n cout << \"this is a valid array\" << endl;\n for(int j=0 ; j< len; j++)\n cout << result[j] << \",\" ;\n cout << endl;\n return true;\n}\n" }, { "answer_id": 21698030, "author": "Vikram Bhat", "author_id": 2661290, "author_profile": "https://Stackoverflow.com/users/2661290", "pm_score": 0, "selected": false, "text": "public static boolean check_range(int arr[],int n,int m) {\n\n for(int i=0;i<m;i++) {\n arr[i] = arr[i] - n;\n if(arr[i]>=m)\n return(false);\n }\n\n System.out.println(\"In range\");\n\n int j=0;\n while(j<m) {\n System.out.println(j);\n if(arr[j]<m) {\n\n if(arr[arr[j]]<m) {\n\n int t = arr[arr[j]];\n arr[arr[j]] = arr[j] + m;\n arr[j] = t;\n if(j==arr[j]) {\n\n arr[j] = arr[j] + m;\n j++;\n }\n\n }\n\n else return(false);\n\n }\n\n else j++;\n\n }\n" }, { "answer_id": 68717286, "author": "maraca", "author_id": 4785110, "author_profile": "https://Stackoverflow.com/users/4785110", "pm_score": 0, "selected": false, "text": "int max = arr[0];\nint min = arr[0];\nfor (int i = 0; i < n; i++) {\n int x = abs(arr[i]);\n int y = x % n;\n if (arr[y] < 0)\n return false;\n arr[y] = -arr[y];\n if (x > max)\n max = x;\n else if (x < min)\n min = x;\n}\nreturn max - min == n - 1;\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/658/" ]
177,121
<p>In particular, I am interested in: 1) Getting up a <em>free</em> environment setup to do workflows. 2) How to use existing workflow items/states and what is involved in that.</p> <p>Thanks!</p>
[ { "answer_id": 5694752, "author": "krisragh MSFT", "author_id": 528570, "author_profile": "https://Stackoverflow.com/users/528570", "pm_score": 3, "selected": false, "text": "public void HandleLoanRequest (string customerID, Application app)\n{\n if (CheckCredit(customerId, app.Amount))\n {\n MakeOffer (customerId, app);\n }\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13990/" ]
177,122
<p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p> <ul> <li><p><strong>Firstly</strong>: Given an established Perl project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li> <li><p><strong>Secondly</strong>: When writing a program from scratch in Perl, what are some good ways to greatly improve performance?</p></li> </ul> <p>For the first question, imagine you are handed a decently written project and you need to improve performance, but you can't seem to get much of a gain through refactoring/optimization. What would you do to speed it up in this case short of rewriting it in something like C?</p> <p><strong>Please stay away from general optimization techniques unless they are <em>Perl specific</em>.</strong></p> <p>I asked this about <a href="https://stackoverflow.com/questions/172720/speeding-up-python">Python</a> earlier, and I figured it might be good to do it for other languages (I'm especially curious if there are corollaries to <a href="http://psyco.sourceforge.net/" rel="nofollow noreferrer">psycho</a> and <a href="http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/" rel="nofollow noreferrer">pyrex</a> for Perl).</p>
[ { "answer_id": 177252, "author": "pjf", "author_id": 19422, "author_profile": "https://Stackoverflow.com/users/19422", "pm_score": 5, "selected": false, "text": "Devel::NYTProf" }, { "answer_id": 177643, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 5, "selected": false, "text": "@INC" }, { "answer_id": 181516, "author": "MarkR", "author_id": 13724, "author_profile": "https://Stackoverflow.com/users/13724", "pm_score": 3, "selected": false, "text": "keys()" }, { "answer_id": 181798, "author": "tsee", "author_id": 13164, "author_profile": "https://Stackoverflow.com/users/13164", "pm_score": 3, "selected": false, "text": "package Car;\n# sub new {...}\n\nsub get_color {\n my $self = shift;\n return $self->{color};\n}\n\npackage main;\n#...\nmy $color = $car->get_color();\n" }, { "answer_id": 435305, "author": "jrockway", "author_id": 8457, "author_profile": "https://Stackoverflow.com/users/8457", "pm_score": 3, "selected": false, "text": "while(my $new_item = <>){\n push @list, $new_item;\n @list = sort @list;\n ... use sorted list\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177122", "https://Stackoverflow.com", "https://Stackoverflow.com/users/145/" ]
177,133
<p>I am trying to override the DataGridViewTextBoxCell's paint method in a derived class so that I can indent the foreground text by some variable amount of pixels. I would like it if the width of the column adjusts so that its total width is the length of my cells text plus the "buffer" indent. Does anyone know of a way to accomplish this? My lame implementation is listed below:</p> <pre><code>public class MyTextBoxCell : DataGridViewTextBoxCell{ .... protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { clipBounds.Inflate(100, 0); DataGridViewPaintParts pp = DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ErrorIcon; base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, pp); string text = formattedValue as string; //My lame attempt to indent 20 pixels?? TextRenderer.DrawText(graphics, text, cellStyle.Font, new Point(cellBounds.Location.X + 20, cellBounds.Location.Y), cellStyle.SelectionForeColor ,TextFormatFlags.EndEllipsis); } </code></pre> <p>}</p>
[ { "answer_id": 177184, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": 2, "selected": false, "text": " if (e.ColumnIndex == 1)\n {\n string val = (string)e.Value;\n e.Value = String.Format(\" {0}\", val);\n e.FormattingApplied = true;\n }\n" }, { "answer_id": 180289, "author": "sbeskur", "author_id": 10446, "author_profile": "https://Stackoverflow.com/users/10446", "pm_score": 2, "selected": false, "text": "public class MyTextBoxCell : DataGridViewTextBoxCell{ ....\n private static readonly int INDENTCOEFFICIENT = 5;\n protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) {\n int indent = ((MyRow)OwningRow).Indent * INDENTCOEFFICIENT;\n Size s = base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);\n int textWidth = 2; //arbitrary amount\n if (Value != null) {\n string text = Value as string;\n textWidth = TextRenderer.MeasureText(text, cellStyle.Font).Width;\n }\n\n s.Width += textWidth + indent;\n return s;\n }\n\n private static readonly StringFormat strFmt = new StringFormat(StringFormatFlags.NoWrap);\n\n protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {\n\n DataGridViewPaintParts pp = DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground\n | DataGridViewPaintParts.ErrorIcon;\n\n base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, pp);\n\n string text = formattedValue as string;\n\n int indent = ((MyRow)OwningRow).Indent * INDENTCOEFFICIENT;\n strFmt.Trimming = StringTrimming.EllipsisCharacter;\n Rectangle r = cellBounds;\n r.Offset(indent, 0);\n r.Inflate(-indent, 0);\n graphics.DrawString(text, cellStyle.Font, Brushes.Black, r, strFmt);\n }\n\n}\n" }, { "answer_id": 180467, "author": "Vivek", "author_id": 7418, "author_profile": "https://Stackoverflow.com/users/7418", "pm_score": 2, "selected": true, "text": "Column.AutoSizeMode" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10446/" ]
177,146
<p>How do I get the list of open file handles by process id in C#? </p> <p>I'm interested in digging down and getting the file names as well. </p> <p>Looking for the programmatic equivalent of what process explorer does. </p> <p>Most likely this will require interop. </p> <p>Considering adding a bounty on this, the implementation is nasty complicated.</p>
[ { "answer_id": 177351, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 4, "selected": false, "text": "NtQuerySystemInformation" }, { "answer_id": 5372541, "author": "manuc66", "author_id": 77135, "author_profile": "https://Stackoverflow.com/users/77135", "pm_score": 4, "selected": false, "text": "DetectOpenFiles.GetOpenFilesEnumerator(processID);\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17174/" ]
177,154
<p>I'm trying to create an instance of a class at run time. The classes I'm trying to create all inherit from a base class, ConfigMgrObj, and are named <code>ConfigMgr_xxxxxx</code> e.g. <code>ConfigMgr_Collection</code>. They all take a special object that I'm calling oController and a string as arguments.</p> <p>This is the line I'm using to do it, where ClassToGet is a string that contains the name of the class e.g. <code>ConfigMgr_Collection</code>.</p> <pre><code>object oNewObject = System.Activator.CreateInstance(null, "StackOverflowNamespace." + ClassToGet, new object[] { oController, ClassToGet }); </code></pre> <p>This throws a TypeLoadException exception. What's up with it?</p>
[ { "answer_id": 177164, "author": "jop", "author_id": 11830, "author_profile": "https://Stackoverflow.com/users/11830", "pm_score": 0, "selected": false, "text": "\"StackOverflowNamespace.\"+ClassToGet" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5133/" ]
177,160
<p>Is it possible to set an iPhone Xcode project to skip the 'CompressResources' build step?</p> <p>Specifically, I want to skip the stage where it runs pngcrush on all of my .png files, many of which don't survive the experience in a form which my app can read.</p> <p><strong>Edit:</strong> the version of pngcrush used creates png files which contain a non-standard 'mandatory, private' chunk which explicitly prevents decoding. I've modified my png reader to handle these files, but I'd still like a per-project method of skipping this step. One of the other side effects of pngcrush is that it doesn't save the colour value of transparent pixels, so alpha-ed textures show fringing at smaller mip levels.</p> <p>The iphone png format is described here: <a href="https://web.archive.org/web/20110519164905/http://modmyi.com/wiki/index.php/Iphone_PNG_images" rel="nofollow noreferrer">https://web.archive.org/web/20110519164905/http://modmyi.com/wiki/index.php/Iphone_PNG_images</a>. In short,</p> <ul> <li>Skip the CgBI chunk</li> <li>Skip the zlib headers</li> <li>Swap BGR to RGB channel order</li> </ul> <p><strong>Edit:</strong> It appears it also premultiplies the alpha, so:</p> <ul> <li>Divide by alpha</li> </ul>
[ { "answer_id": 178599, "author": "jblocksom", "author_id": 20626, "author_profile": "https://Stackoverflow.com/users/20626", "pm_score": 2, "selected": false, "text": "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/iphoneos-optimize" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25352/" ]
177,161
<p>I need to get just the first item (actually, just the first key) off a rather large associative array in JavaScript. Here's how I'm doing it currently (using jQuery):</p> <pre><code>getKey = function (data) { var firstKey; $.each(data, function (key, val) { firstKey = key; return false; }); return firstKey; }; </code></pre> <p>Just guessing, but I'd say there's got to be a better (read: more efficient) way of doing this. Any suggestions?</p> <p>UPDATE: Thanks for the insightful answers and comments! I had forgotten my JavaScript 101, wherein the spec says you're not guaranteed a particular order in an associative array. It's interesting, though, that most browsers do implement it that way. I'd prefer not to sort the array before getting that first key, but it may be unavoidable given my use case.</p>
[ { "answer_id": 177191, "author": "Jonathan Lonowski", "author_id": 15031, "author_profile": "https://Stackoverflow.com/users/15031", "pm_score": 7, "selected": true, "text": "function getKey(data) {\n for (var prop in data)\n return prop;\n}\n" }, { "answer_id": 13179330, "author": "dmnc", "author_id": 904846, "author_profile": "https://Stackoverflow.com/users/904846", "pm_score": 2, "selected": false, "text": "Array.prototype.getKey = function() {\n for (var prop in this)\n if (this.propertyIsEnumerable(prop))\n return prop;\n}\n" }, { "answer_id": 26617955, "author": "Erik Anderson", "author_id": 130614, "author_profile": "https://Stackoverflow.com/users/130614", "pm_score": 6, "selected": false, "text": "Object.keys()" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11577/" ]
177,188
<p>I'm not talking about a post build event for a project. Rather, I want to run an executable automatically after the entire solution is built. Is there a way to do a post build event for the solution?</p>
[ { "answer_id": 177243, "author": "Ryan Lundy", "author_id": 5486, "author_profile": "https://Stackoverflow.com/users/5486", "pm_score": 6, "selected": true, "text": "Public Sub AfterBuild(scope As vsBuildScope, action As vsBuildAction) _\n Handles BuildEvents.OnBuildDone\n If scope = vsBuildScope.vsBuildScopeSolution Then\n System.Diagnostics.Process.Start(\"some file I want to run\")\n End If\nEnd Sub\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5469/" ]
177,189
<p>Sometime I see many application such as msn, windows media player etc that are single instance applications (when user executes while application is running a new application instance will not created).</p> <p>In C#, I use <code>Mutex</code> class for this but I don't know how to do this in Java.</p>
[ { "answer_id": 177201, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 7, "selected": true, "text": "InetAddress.getLocalHost()" }, { "answer_id": 2002948, "author": "Robert", "author_id": 240453, "author_profile": "https://Stackoverflow.com/users/240453", "pm_score": 6, "selected": false, "text": "private static boolean lockInstance(final String lockFile) {\n try {\n final File file = new File(lockFile);\n final RandomAccessFile randomAccessFile = new RandomAccessFile(file, \"rw\");\n final FileLock fileLock = randomAccessFile.getChannel().tryLock();\n if (fileLock != null) {\n Runtime.getRuntime().addShutdownHook(new Thread() {\n public void run() {\n try {\n fileLock.release();\n randomAccessFile.close();\n file.delete();\n } catch (Exception e) {\n log.error(\"Unable to remove lock file: \" + lockFile, e);\n }\n }\n });\n return true;\n }\n } catch (Exception e) {\n log.error(\"Unable to create and/or lock file: \" + lockFile, e);\n }\n return false;\n}\n" }, { "answer_id": 4256557, "author": "parvez Ahmad", "author_id": 517498, "author_profile": "https://Stackoverflow.com/users/517498", "pm_score": 3, "selected": false, "text": "if(!isFileshipAlreadyRunning()){\n MessageDialog.openError(display.getActiveShell(), \"Fileship already running\", \"Another instance of this application is already running. Exiting.\");\n return IApplication.EXIT_OK;\n } \n\n\nprivate static boolean isFileshipAlreadyRunning() {\n // socket concept is shown at http://www.rbgrn.net/content/43-java-single-application-instance\n // but this one is really great\n try {\n final File file = new File(\"FileshipReserved.txt\");\n final RandomAccessFile randomAccessFile = new RandomAccessFile(file, \"rw\");\n final FileLock fileLock = randomAccessFile.getChannel().tryLock();\n if (fileLock != null) {\n Runtime.getRuntime().addShutdownHook(new Thread() {\n public void run() {\n try {\n fileLock.release();\n randomAccessFile.close();\n file.delete();\n } catch (Exception e) {\n //log.error(\"Unable to remove lock file: \" + lockFile, e);\n }\n }\n });\n return true;\n }\n } catch (Exception e) {\n // log.error(\"Unable to create and/or lock file: \" + lockFile, e);\n }\n return false;\n}\n" }, { "answer_id": 7176774, "author": "Andrew Thompson", "author_id": 418556, "author_profile": "https://Stackoverflow.com/users/418556", "pm_score": 4, "selected": false, "text": "SingleInstanceService" }, { "answer_id": 36772436, "author": "Dreamspace President", "author_id": 3500521, "author_profile": "https://Stackoverflow.com/users/3500521", "pm_score": 1, "selected": false, "text": "public static void main(final String[] args) {\n\n // ENSURE SINGLE INSTANCE\n if (!SingleInstanceChecker.INSTANCE.isOnlyInstance(Main::otherInstanceTriedToLaunch, false)) {\n System.exit(0);\n }\n\n // launch rest of application here\n System.out.println(\"Application starts properly because it's the only instance.\");\n}\n\nprivate static void otherInstanceTriedToLaunch() {\n // Restore your application window and bring it to front.\n // But make sure your situation is apt: This method could be called at *any* time.\n System.err.println(\"Deiconified because other instance tried to start.\");\n}\n" }, { "answer_id": 40763340, "author": "kolobok", "author_id": 751200, "author_profile": "https://Stackoverflow.com/users/751200", "pm_score": 3, "selected": false, "text": "public static void main(String[] args) {\n String appId = \"myapplicationid\";\n boolean alreadyRunning;\n try {\n JUnique.acquireLock(appId, new MessageHandler() {\n public String handle(String message) {\n // A brand new argument received! Handle it!\n return null;\n }\n });\n alreadyRunning = false;\n } catch (AlreadyLockedException e) {\n alreadyRunning = true;\n }\n if (!alreadyRunning) {\n // Start sequence here\n } else {\n for (int i = 0; i < args.length; i++) {\n JUnique.sendMessage(appId, args[0]));\n }\n }\n}\n" }, { "answer_id": 58903886, "author": "Pratanu Mandal", "author_id": 1215488, "author_profile": "https://Stackoverflow.com/users/1215488", "pm_score": 2, "selected": false, "text": "import tk.pratanumandal.unique4j.Unique4j;\nimport tk.pratanumandal.unique4j.exception.Unique4jException;\n\npublic class Unique4jDemo {\n\n // unique application ID\n public static String APP_ID = \"tk.pratanumandal.unique4j-mlsdvo-20191511-#j.6\";\n\n public static void main(String[] args) throws Unique4jException, InterruptedException {\n\n // create unique instance\n Unique4j unique = new Unique4j(APP_ID) {\n @Override\n public void receiveMessage(String message) {\n // display received message from subsequent instance\n System.out.println(message);\n }\n\n @Override\n public String sendMessage() {\n // send message to first instance\n return \"Hello World!\";\n }\n };\n\n // try to obtain lock\n boolean lockFlag = unique.acquireLock();\n\n // sleep the main thread for 30 seconds to simulate long running tasks\n Thread.sleep(30000);\n\n // try to free the lock before exiting program\n boolean lockFreeFlag = unique.freeLock();\n\n }\n\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24550/" ]
177,197
<p>Please anybody can tell me the questions, that can be asked in an interview for below topics</p> <ul> <li>Socket Programming</li> <li>Multi-Threading</li> </ul> <p>An advance thanks goes to everybody who provide their time</p>
[ { "answer_id": 11804526, "author": "jxh", "author_id": 315052, "author_profile": "https://Stackoverflow.com/users/315052", "pm_score": 1, "selected": false, "text": "accept" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21599/" ]
177,205
<p>What is the data that Process and Thread will not share ? </p> <p>An advance thanks goes to everybody who provide their time</p>
[ { "answer_id": 177336, "author": "bk1e", "author_id": 8090, "author_profile": "https://Stackoverflow.com/users/8090", "pm_score": 0, "selected": false, "text": "FD_CLOEXEC" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21599/" ]
177,228
<p>What is the easiest way of finding out what version of the iPhone SDK is installed on my OS X?</p> <p>When you log into the Apple's iPhone Developer Center, you can see the build number of the current available version of the SDK, but you have to remember if you have already downloaded that version or not. </p> <p>What is the easiest way of staying current?</p>
[ { "answer_id": 46978885, "author": "greymouser", "author_id": 404640, "author_profile": "https://Stackoverflow.com/users/404640", "pm_score": 0, "selected": false, "text": "$ xcrun --sdk iphoneos --show-sdk-path\n/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk\n\n$ xcrun --sdk iphoneos --show-sdk-platform-version\n11.0\n\n$ xcrun --sdk iphoneos --show-sdk-build-version\n15A372\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2954/" ]
177,240
<p>Lets just say you have a table in Oracle:</p> <pre><code>CREATE TABLE person ( id NUMBER PRIMARY KEY, given_names VARCHAR2(50), surname VARCHAR2(50) ); </code></pre> <p>with these function-based indices:</p> <pre><code>CREATE INDEX idx_person_upper_given_names ON person (UPPER(given_names)); CREATE INDEX idx_person_upper_last_name ON person (UPPER(last_name)); </code></pre> <p>Now, given_names has no NULL values but for argument's sake last_name does. If I do this:</p> <pre><code>SELECT * FROM person WHERE UPPER(given_names) LIKE 'P%' </code></pre> <p>the explain plan tells me its using the index but change it to:</p> <pre><code>SELECT * FROM person WHERE UPPER(last_name) LIKE 'P%' </code></pre> <p>it doesn't. The Oracle docs say that to use the function-based index will only be used when several conditions are met, one of which is ensuring there are no NULL values since they aren't indexed.</p> <p>I've tried these queries:</p> <pre><code>SELECT * FROM person WHERE UPPER(last_name) LIKE 'P%' AND UPPER(last_name) IS NOT NULL </code></pre> <p>and</p> <pre><code>SELECT * FROM person WHERE UPPER(last_name) LIKE 'P%' AND last_name IS NOT NULL </code></pre> <p>In the latter case I even added an index on last_name but no matter what I try it uses a full table scan. Assuming I can't get rid of the NULL values, how do I get this query to use the index on UPPER(last_name)?</p>
[ { "answer_id": 177304, "author": "CaptainPicard", "author_id": 15203, "author_profile": "https://Stackoverflow.com/users/15203", "pm_score": 2, "selected": false, "text": "CREATE INDEX idx_person_upper_surname ON person (UPPER(surname));\n\nSELECT * FROM person WHERE UPPER(surname) LIKE 'P%';\n" }, { "answer_id": 177765, "author": "Tony Andrews", "author_id": 18747, "author_profile": "https://Stackoverflow.com/users/18747", "pm_score": 4, "selected": true, "text": "SQL> create table my_objects\n 2 as select object_id, object_name\n 3 from all_objects;\n\nTable created.\n\nSQL> select count(*) from my_objects;\n 2 /\n\n COUNT(*)\n----------\n 83783\n\n\nSQL> alter table my_objects modify object_name null;\n\nTable altered.\n\nSQL> update my_objects\n 2 set object_name=null\n 3 where object_name like 'T%';\n\n1305 rows updated.\n\nSQL> create index my_objects_name on my_objects (lower(object_name));\n\nIndex created.\n\nSQL> set autotrace traceonly\n\nSQL> select * from my_objects\n 2 where lower(object_name) like 'emp%';\n\n29 rows selected.\n\n\nExecution Plan\n----------------------------------------------------------\n\n------------------------------------------------------------------------------------\n| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|\n------------------------------------------------------------------------------------\n| 0 | SELECT STATEMENT | | 17 | 510 | 355 (1)|\n| 1 | TABLE ACCESS BY INDEX ROWID| MY_OBJECTS | 17 | 510 | 355 (1)|\n|* 2 | INDEX RANGE SCAN | MY_OBJECTS_NAME | 671 | | 6 (0)|\n------------------------------------------------------------------------------------\n" }, { "answer_id": 177957, "author": "David Aldridge", "author_id": 6742, "author_profile": "https://Stackoverflow.com/users/6742", "pm_score": 0, "selected": false, "text": "CREATE INDEX idx_person_upper_surname ON person (UPPER(surname),0);\n" }, { "answer_id": 178175, "author": "Nick Pierpoint", "author_id": 4003, "author_profile": "https://Stackoverflow.com/users/4003", "pm_score": 0, "selected": false, "text": "create index idx_person_upper_surname on person (nvl(upper(surname),'N/A'));\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18393/" ]
177,241
<p>I know how to load themes dynamically when they are stored locally. Is it possible to store theses themes in the database yet still apply them programmatically as described in referenced MSDN article?</p> <p>Also - If you do store them in the filesystem, is it possible to change the path of the App_Themes directory to a different location? Like Amazon S3?</p> <p><a href="http://msdn.microsoft.com/en-us/library/tx35bd89.aspx" rel="nofollow noreferrer">Apply Themes Programattically</a></p>
[ { "answer_id": 177304, "author": "CaptainPicard", "author_id": 15203, "author_profile": "https://Stackoverflow.com/users/15203", "pm_score": 2, "selected": false, "text": "CREATE INDEX idx_person_upper_surname ON person (UPPER(surname));\n\nSELECT * FROM person WHERE UPPER(surname) LIKE 'P%';\n" }, { "answer_id": 177765, "author": "Tony Andrews", "author_id": 18747, "author_profile": "https://Stackoverflow.com/users/18747", "pm_score": 4, "selected": true, "text": "SQL> create table my_objects\n 2 as select object_id, object_name\n 3 from all_objects;\n\nTable created.\n\nSQL> select count(*) from my_objects;\n 2 /\n\n COUNT(*)\n----------\n 83783\n\n\nSQL> alter table my_objects modify object_name null;\n\nTable altered.\n\nSQL> update my_objects\n 2 set object_name=null\n 3 where object_name like 'T%';\n\n1305 rows updated.\n\nSQL> create index my_objects_name on my_objects (lower(object_name));\n\nIndex created.\n\nSQL> set autotrace traceonly\n\nSQL> select * from my_objects\n 2 where lower(object_name) like 'emp%';\n\n29 rows selected.\n\n\nExecution Plan\n----------------------------------------------------------\n\n------------------------------------------------------------------------------------\n| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|\n------------------------------------------------------------------------------------\n| 0 | SELECT STATEMENT | | 17 | 510 | 355 (1)|\n| 1 | TABLE ACCESS BY INDEX ROWID| MY_OBJECTS | 17 | 510 | 355 (1)|\n|* 2 | INDEX RANGE SCAN | MY_OBJECTS_NAME | 671 | | 6 (0)|\n------------------------------------------------------------------------------------\n" }, { "answer_id": 177957, "author": "David Aldridge", "author_id": 6742, "author_profile": "https://Stackoverflow.com/users/6742", "pm_score": 0, "selected": false, "text": "CREATE INDEX idx_person_upper_surname ON person (UPPER(surname),0);\n" }, { "answer_id": 178175, "author": "Nick Pierpoint", "author_id": 4003, "author_profile": "https://Stackoverflow.com/users/4003", "pm_score": 0, "selected": false, "text": "create index idx_person_upper_surname on person (nvl(upper(surname),'N/A'));\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177241", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12442/" ]
177,242
<p>Whenever I start our Apache Felix (OSGi) based application under SUN Java ( build 1.6.0_10-rc2-b32 and other 1.6.x builds) I see the following message output on the console (usually under Ubuntu 8.4):</p> <blockquote> <p>Warning: The encoding 'UTF-8' is not supported by the Java runtime.</p> </blockquote> <p>I've seen this message display occasionally when running both Tomcat and Resin as well. If java supports unicode and UTF-8, what causes this message? I've yet to find any reference, or answer to this anywhere else.</p>
[ { "answer_id": 177934, "author": "tgdavies", "author_id": 11002, "author_profile": "https://Stackoverflow.com/users/11002", "pm_score": 3, "selected": false, "text": "import java.nio.charset.Charset;\n\npublic class TestCharset {\n public static void main(String[] args) {\n System.out.println(Charset.forName(\"UTF-8\"));\n }\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177242", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1720/" ]
177,251
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/65820/unit-testing-c-code">Unit Testing C Code</a> </p> </blockquote> <p>I've seen a few questions specific to C++, but I'm really curious about C. I'm trying to add a standard unit test framework into our build environment. My primary goals are to encourage our developers to write unit tests, and to standardize those test so others can run them. Ideally I'd like to run the unit tests as part of our nightly build.</p> <p>We started some work with CUnit, which worked except that everything ran in one thread and any memory faults caused the unit tests to stop running, which was rather annoying. I also found it incredibly difficult to write the tests, but that might just be unit testing for you.</p> <p>Does anybody know of good alternatives? Has anybody had any experience with the C++ Unit Testers with C-only code?</p>
[ { "answer_id": 177440, "author": "philant", "author_id": 18804, "author_profile": "https://Stackoverflow.com/users/18804", "pm_score": 0, "selected": false, "text": "void test_function_returning_a_pointer(void)\n{\n struct_t *theStruct = function_returning_a_pointer();\n MU_ASSERT(theStruct != NULL);\n\n //--- now you can use the pointer \n MU_ASSERT(theStruct->field1 == 0);\n\n return MU_PASSED;\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177251", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25704/" ]
177,258
<p>Please can someone help me make sense of the Batch madness?</p> <p>I'm trying to debug an Axapta 3.0 implementation that has about 50 Batch Jobs. Most of the batched classes do not implement the <strong><code>description()</code></strong> method, so when you look at the <em>Batch List</em> form (Basic>>Inquiries>>Batch list) the description field is blank. You can see the <strong>Batch Group</strong> and the <strong>Start Time</strong>, etc. but you can't tell which class is actually being called.</p> <p>The <em>Batch</em> table contains a hidden field called <em>ClassNum</em> which identifies the <em>ID</em> property of the class. Can anyone tell me how I can find the corresponding class from the ID? Once I've identified the culprits I can add descriptions.</p> <p>I tried using the standard <em>Find</em> function on the AOT but it doesn't pick them up. </p> <p>Any suggestions would be most welcome!</p> <p>Many thanks, Mike</p>
[ { "answer_id": 177357, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "display str Classname()\n{\n return ClassId2Name(this.ClassNum); \n}\n" }, { "answer_id": 179362, "author": "Jay Hofacker", "author_id": 535, "author_profile": "https://Stackoverflow.com/users/535", "pm_score": 2, "selected": false, "text": "DictClass" }, { "answer_id": 66544243, "author": "Roger Manich", "author_id": 6548256, "author_profile": "https://Stackoverflow.com/users/6548256", "pm_score": 0, "selected": false, "text": "display str Classname()\n{\n return classId2Name(ClassIdGet(this)); \n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
177,259
<p>Always was interested why are <a href="http://msdn.microsoft.com/en-us/library/system.array.sort.aspx" rel="nofollow noreferrer">Array.Sort()</a> and <a href="http://msdn.microsoft.com/en-us/library/system.array.indexof.aspx" rel="nofollow noreferrer">Array.IndexOf()</a> methods made static and similar <a href="http://msdn.microsoft.com/en-us/library/system.collections.arraylist.sort.aspx" rel="nofollow noreferrer">ArrayList.Sort()</a> and <a href="http://msdn.microsoft.com/en-us/library/system.collections.arraylist.indexof.aspx" rel="nofollow noreferrer">ArrayList.IndexOf()</a> are designed as member methods. Thank you for any ideas.</p>
[ { "answer_id": 414084, "author": "JacquesB", "author_id": 7488, "author_profile": "https://Stackoverflow.com/users/7488", "pm_score": 2, "selected": false, "text": "ArrayList" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177259", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11256/" ]
177,271
<p>Can anyone provide some pseudo code for a roulette selection function? How would I implement this:</p> <p><img src="https://upload.wikimedia.org/math/0/d/2/0d24a82d8e813380f670bf80ae74486b.png" alt="alt text"></p> <p>I don't really understand how to read this math notation. I never took any probability or statistics.</p>
[ { "answer_id": 391712, "author": "Wartin", "author_id": 48778, "author_profile": "https://Stackoverflow.com/users/48778", "pm_score": 3, "selected": false, "text": "// Find the sum of fitnesses. The function fitness(i) should \n//return the fitness value for member i**\n\nfloat sumFitness = 0.0f;\nfor (int i=0; i < nmembers; i++)\n sumFitness += fitness(i);\n\n// Get a floating point number in the interval 0.0 ... sumFitness**\nfloat randomNumber = (float(rand() % 10000) / 9999.0f) * sumFitness;\n\n// Translate this number to the corresponding member**\nint memberID=0;\nfloat partialSum=0.0f;\n\nwhile (randomNumber > partialSum)\n{\n partialSum += fitness(memberID);\n memberID++;\n} \n\n**// We have just found the member of the population using the roulette algorithm**\n**// It is stored in the \"memberID\" variable**\n**// Repeat this procedure as many times to find random members of the population**\n" }, { "answer_id": 3995038, "author": "deceleratedcaviar", "author_id": 431528, "author_profile": "https://Stackoverflow.com/users/431528", "pm_score": 2, "selected": false, "text": "Index | Fitness | Sum | 7 < Sum\n0 | 2 | 2 | false\n1 | 3 | 5 | false\n2 | 1 | 6 | false\n3 | 4 | 10 | true\n4 | 2 | 12 | ...\n" }, { "answer_id": 5315710, "author": "noio", "author_id": 224949, "author_profile": "https://Stackoverflow.com/users/224949", "pm_score": 4, "selected": false, "text": "def roulette_select(population, fitnesses, num):\n \"\"\" Roulette selection, implemented according to:\n <http://stackoverflow.com/questions/177271/roulette\n -selection-in-genetic-algorithms/177278#177278>\n \"\"\"\n total_fitness = float(sum(fitnesses))\n rel_fitness = [f/total_fitness for f in fitnesses]\n # Generate probability intervals for each individual\n probs = [sum(rel_fitness[:i+1]) for i in range(len(rel_fitness))]\n # Draw new population\n new_population = []\n for n in xrange(num):\n r = rand()\n for (i, individual) in enumerate(population):\n if r <= probs[i]:\n new_population.append(individual)\n break\n return new_population\n" }, { "answer_id": 5888841, "author": "flavour404", "author_id": 109614, "author_profile": "https://Stackoverflow.com/users/109614", "pm_score": -1, "selected": false, "text": "private Individual Select_Roulette(double sum_fitness)\n {\n Individual ret = new Individual();\n bool loop = true;\n\n while (loop)\n {\n //this will give us a double within the range 0.0 to total fitness\n double slice = roulette_selector.NextDouble() * sum_fitness;\n\n double curFitness = 0.0;\n\n foreach (Individual ind in _generation)\n {\n curFitness += ind.Fitness;\n if (curFitness >= slice)\n {\n loop = false;\n ret = ind;\n break;\n }\n }\n }\n return ret;\n\n }\n" }, { "answer_id": 8463663, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "def select(fs):\n p = random.uniform(0, sum(fs))\n for i, f in enumerate(fs):\n if p <= 0:\n break\n p -= f\n return i\n" }, { "answer_id": 10949834, "author": "NickD", "author_id": 1320066, "author_profile": "https://Stackoverflow.com/users/1320066", "pm_score": 1, "selected": false, "text": "public static gene rouletteSelection()\n{\n float totalScore = 0;\n float runningScore = 0;\n for (gene g : genes)\n {\n totalScore += g.score;\n }\n\n float rnd = (float) (Math.random() * totalScore);\n\n for (gene g : genes)\n { \n if ( rnd>=runningScore &&\n rnd<=runningScore+g.score)\n {\n return g;\n }\n runningScore+=g.score;\n }\n\n return null;\n}\n" }, { "answer_id": 22479118, "author": "kiaGh", "author_id": 3419171, "author_profile": "https://Stackoverflow.com/users/3419171", "pm_score": 0, "selected": false, "text": "Based on my research ,Here is another implementation in C# if there is a need for it:\n\n\n//those with higher fitness get selected wit a large probability \n//return-->individuals with highest fitness\n private int RouletteSelection()\n {\n double randomFitness = m_random.NextDouble() * m_totalFitness;\n int idx = -1;\n int mid;\n int first = 0;\n int last = m_populationSize -1;\n mid = (last - first)/2;\n\n // ArrayList's BinarySearch is for exact values only\n // so do this by hand.\n while (idx == -1 && first <= last)\n {\n if (randomFitness < (double)m_fitnessTable[mid])\n {\n last = mid;\n }\n else if (randomFitness > (double)m_fitnessTable[mid])\n {\n first = mid;\n }\n mid = (first + last)/2;\n // lies between i and i+1\n if ((last - first) == 1)\n idx = last;\n }\n return idx;\n }\n" }, { "answer_id": 23264253, "author": "manlio", "author_id": 3235496, "author_profile": "https://Stackoverflow.com/users/3235496", "pm_score": 3, "selected": false, "text": "/// \\param[in] f_max maximum fitness of the population\n///\n/// \\return index of the selected individual\n///\n/// \\note Assuming positive fitness. Greater is better.\n\nunsigned rw_selection(double f_max)\n{\n for (;;)\n {\n // Select randomly one of the individuals\n unsigned i(random_individual());\n\n // The selection is accepted with probability fitness(i) / f_max\n if (uniform_random_01() < fitness(i) / f_max)\n return i;\n } \n}\n" }, { "answer_id": 35013768, "author": "Setu Kumar Basak", "author_id": 4299527, "author_profile": "https://Stackoverflow.com/users/4299527", "pm_score": 1, "selected": false, "text": "TotalFitness=sum(Fitness);\n ProbSelection=zeros(PopLength,1);\n CumProb=zeros(PopLength,1);\n\n for i=1:PopLength\n ProbSelection(i)=Fitness(i)/TotalFitness;\n if i==1\n CumProb(i)=ProbSelection(i);\n else\n CumProb(i)=CumProb(i-1)+ProbSelection(i);\n end\n end\n\n SelectInd=rand(PopLength,1);\n\n for i=1:PopLength\n flag=0;\n for j=1:PopLength\n if(CumProb(j)<SelectInd(i) && CumProb(j+1)>=SelectInd(i))\n SelectedPop(i,1:IndLength)=CurrentPop(j+1,1:IndLength);\n flag=1;\n break;\n end\n end\n if(flag==0)\n SelectedPop(i,1:IndLength)=CurrentPop(1,1:IndLength);\n end\n end\n" }, { "answer_id": 42492888, "author": "Evgenia Karunus", "author_id": 3192470, "author_profile": "https://Stackoverflow.com/users/3192470", "pm_score": 1, "selected": false, "text": "# there will be some amount of repeating organisms here.\nmating_pool = []\n\nall_organisms_in_population.each do |organism|\n organism.fitness.times { mating_pool.push(organism) }\nend\n\n# [very_fit_organism, very_fit_organism, very_fit_organism, not_so_fit_organism]\nreturn mating_pool.sample #=> random, likely fit, parent!\n" }, { "answer_id": 53402623, "author": "Pat Niemeyer", "author_id": 74975, "author_profile": "https://Stackoverflow.com/users/74975", "pm_score": 0, "selected": false, "text": "public extension Array where Element == Double {\n\n /// Consider the elements as weight values and return a weighted random selection by index.\n /// a.k.a Roulette wheel selection.\n func weightedRandomIndex() -> Int {\n var selected: Int = 0\n var total: Double = self[0]\n\n for i in 1..<self.count { // start at 1\n total += self[i]\n if( Double.random(in: 0...1) <= (self[i] / total)) { selected = i }\n }\n\n return selected\n }\n}\n" }, { "answer_id": 61955345, "author": "Thieu Nguyen", "author_id": 5408129, "author_profile": "https://Stackoverflow.com/users/5408129", "pm_score": 0, "selected": false, "text": "from numpy import min, sum, ptp, array \nfrom numpy.random import uniform \n\nlist_fitness1 = array([-12, -45, 0, 72.1, -32.3])\nlist_fitness2 = array([0.5, 6.32, 988.2, 1.23])\n\ndef get_index_roulette_wheel_selection(list_fitness=None):\n \"\"\" It can handle negative also. Make sure your list fitness is 1D-numpy array\"\"\"\n scaled_fitness = (list_fitness - min(list_fitness)) / ptp(list_fitness)\n minimized_fitness = 1.0 - scaled_fitness\n total_sum = sum(minimized_fitness)\n r = uniform(low=0, high=total_sum)\n for idx, f in enumerate(minimized_fitness):\n r = r + f\n if r > total_sum:\n return idx\n\nget_index_roulette_wheel_selection(list_fitness1)\nget_index_roulette_wheel_selection(list_fitness2)\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/577/" ]
177,277
<p>I have a TreeView control in my WinForms .NET application that has multiple levels of childnodes that have childnodes with more childnodes, with no defined depth. When a user selects any parent node (not necessarily at the root level), how can I get a list of all the nodes beneith that parent node?</p> <p>For example, I started off with this:</p> <pre><code>Dim nodes As List(Of String) For Each childNodeLevel1 As TreeNode In parentNode.Nodes For Each childNodeLevel2 As TreeNode In childNodeLevel1.Nodes For Each childNodeLevel3 As TreeNode In childNodeLevel2.Nodes nodes.Add(childNodeLevel3.Text) Next Next Next </code></pre> <p>The problem is that this loop depth is defined and I'm only getting nodes burried down three levels. What if next time the user selects a parent node, there are seven levels?</p>
[ { "answer_id": 177282, "author": "Steven A. Lowe", "author_id": 9345, "author_profile": "https://Stackoverflow.com/users/9345", "pm_score": 4, "selected": false, "text": "function outputNodes(Node root)\n writeln(root.Text)\n foreach(Node n in root.ChildNodes)\n outputNodes(n)\n end\nend\n" }, { "answer_id": 177289, "author": "jop", "author_id": 11830, "author_profile": "https://Stackoverflow.com/users/11830", "pm_score": 5, "selected": true, "text": "Function GetChildren(parentNode as TreeNode) as List(Of String)\n Dim nodes as List(Of String) = New List(Of String)\n GetAllChildren(parentNode, nodes)\n return nodes\nEnd Function\n\nSub GetAllChildren(parentNode as TreeNode, nodes as List(Of String))\n For Each childNode as TreeNode in parentNode.Nodes\n nodes.Add(childNode.Text)\n GetAllChildren(childNode, nodes)\n Next\nEnd Sub\n" }, { "answer_id": 590437, "author": "Adrian Regan", "author_id": 120545, "author_profile": "https://Stackoverflow.com/users/120545", "pm_score": 4, "selected": false, "text": "List< TreeNode > nodes = TreeViewUtils.FlattenDepth(tree);\n" }, { "answer_id": 969044, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "VB.Net" }, { "answer_id": 969082, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 4, "selected": false, "text": "public static IEnumerable<TreeNode> DescendantNodes( this TreeNode input ) {\n foreach ( TreeNode node in input.Nodes ) {\n yield return node;\n foreach ( var subnode in node.DescendantNodes() )\n yield return subnode;\n }\n}\n" }, { "answer_id": 3075412, "author": "Sunil", "author_id": 370998, "author_profile": "https://Stackoverflow.com/users/370998", "pm_score": 2, "selected": false, "text": "nodParent As TreeNode\n'nodParent = your parent Node\ntvwOpt.Nodes.Find(nodParent.Name, True)\n" }, { "answer_id": 32962044, "author": "Gusstavv Gil", "author_id": 4304781, "author_profile": "https://Stackoverflow.com/users/4304781", "pm_score": 2, "selected": false, "text": "Dim FlattenedNodes As List(Of TreeNode) = clTreeUtil.FlattenDepth(Me.TreeView1) \n" }, { "answer_id": 32962245, "author": "Gusstavv Gil", "author_id": 4304781, "author_profile": "https://Stackoverflow.com/users/4304781", "pm_score": 1, "selected": false, "text": "Public Shared Function GetChildren(objTree As TreeView) As List(Of TreeNode)\n Dim nodes As List(Of TreeNode) = New List(Of TreeNode)\n For Each parentNode As TreeNode In objTree.Nodes\n nodes.Add(parentNode)\n GetAllChildren(parentNode, nodes)\n Next\n\n Return nodes\nEnd Function\n\nPublic Shared Sub GetAllChildren(parentNode As TreeNode, nodes As List(Of TreeNode))\n For Each childNode As TreeNode In parentNode.Nodes\n nodes.Add(childNode)\n GetAllChildren(childNode, nodes)\n Next\nEnd Sub\n" }, { "answer_id": 41134563, "author": "antony thomas", "author_id": 6628432, "author_profile": "https://Stackoverflow.com/users/6628432", "pm_score": 1, "selected": false, "text": "textbox1.Text = treeview1.nodes(0).Text.ToString()\n" }, { "answer_id": 62589105, "author": "elle0087", "author_id": 3061212, "author_profile": "https://Stackoverflow.com/users/3061212", "pm_score": 0, "selected": false, "text": "Find()" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5473/" ]
177,284
<p>I have a table that looks something like this:</p> <pre> word big expensive smart fast dog 9 -10 -20 4 professor 2 4 40 -7 ferrari 7 50 0 48 alaska 10 0 1 0 gnat -3 0 0 0 </pre> <p>The + and - values are associated with the word, so professor is smart and dog is not smart. Alaska is big, as a proportion of the total value associated with its entries, and the opposite is true of gnat.</p> <p>Is there a good way to get the absolute value of the number farthest from zero, and some token whether absolute value =/= value? Relatedly, how might I calculate whether the results for a given value are proportionately large with respect to the other values? I would write something to format the output to the effect of: "dog: not smart, probably not expensive; professor smart; ferrari: fast, expensive; alaska: big; gnat: probably small." (The formatting is not a question, just an illustration, I am stuck on the underlying queries.) </p> <p>Also, the rest of the program is python, so if there is any python solution with normal dbapi modules or a more abstract module, any help appreciated.</p>
[ { "answer_id": 177308, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 2, "selected": false, "text": "select word, big from myTable order by abs(big)\n" }, { "answer_id": 177311, "author": "Mark Harrison", "author_id": 116, "author_profile": "https://Stackoverflow.com/users/116", "pm_score": 3, "selected": true, "text": "select max(abs(mycol)) from mytbl\n" }, { "answer_id": 177637, "author": "unmounted", "author_id": 11596, "author_profile": "https://Stackoverflow.com/users/11596", "pm_score": 0, "selected": false, "text": "show_distinct" }, { "answer_id": 177898, "author": "Thorsten", "author_id": 25320, "author_profile": "https://Stackoverflow.com/users/25320", "pm_score": 1, "selected": false, "text": "word property value\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11596/" ]
177,287
<p>Is it possible to produce an alert similar to JavaScript's alert("message") in python, with an application running as a daemon.</p> <p>This will be run in Windows, Most likely XP but 2000 and Vista are also very real possibilities.</p> <p>Update:<br /> This is intended to run in the background and alert the user when certain conditions are met, I figure that the easiest way to alert the user would be to produce a pop-up, as it needs to be handled immediately, and other options such as just logging, or sending an email are not efficient enough.</p>
[ { "answer_id": 177312, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": true, "text": "import win32api\n\nwin32api.MessageBox(0, 'hello', 'title')\n" }, { "answer_id": 177316, "author": "Mikael Jansson", "author_id": 18753, "author_profile": "https://Stackoverflow.com/users/18753", "pm_score": -1, "selected": false, "text": "echo \"foo\" > c:\\your\\file" }, { "answer_id": 11831178, "author": "Tabares", "author_id": 1399262, "author_profile": "https://Stackoverflow.com/users/1399262", "pm_score": 2, "selected": false, "text": "import win32api\nimport win32com.client\nimport pythoncom\n\nresult = win32api.MessageBox(None,\"Do you want to open a file?\", \"title\",1)\n\nif result == 1:\n print 'Ok'\nelif result == 2:\n print 'cancel'\n" }, { "answer_id": 20461473, "author": "NoBugs", "author_id": 778234, "author_profile": "https://Stackoverflow.com/users/778234", "pm_score": 2, "selected": false, "text": "from gi.repository import Gtk\n\ndialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO,\n Gtk.ButtonsType.OK, \"This is an INFO MessageDialog\")\ndialog.format_secondary_text(\n \"And this is the secondary text that explains things.\")\ndialog.run()\nprint \"INFO dialog closed\"\n" }, { "answer_id": 57871358, "author": "Matt Binford", "author_id": 11994601, "author_profile": "https://Stackoverflow.com/users/11994601", "pm_score": 4, "selected": false, "text": "# Python 3.x code\n# Imports\nimport tkinter\nfrom tkinter import messagebox\n\n# This code is to hide the main tkinter window\nroot = tkinter.Tk()\nroot.withdraw()\n\n# Message Box\nmessagebox.showinfo(\"Title\", \"Message\")\n" }, { "answer_id": 64858863, "author": "mathcat", "author_id": 13238936, "author_profile": "https://Stackoverflow.com/users/13238936", "pm_score": 2, "selected": false, "text": "pip install pyautogui\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
177,323
<p>What is the most efficient way to read the last row with SQL Server?</p> <p>The table is indexed on a unique key -- the "bottom" key values represent the last row.</p>
[ { "answer_id": 177325, "author": "willurd", "author_id": 1943957, "author_profile": "https://Stackoverflow.com/users/1943957", "pm_score": 4, "selected": false, "text": "SELECT * FROM table_name ORDER BY unique_column DESC LIMIT 1" }, { "answer_id": 177327, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https://Stackoverflow.com/users/5324", "pm_score": 5, "selected": false, "text": "select whatever,columns,you,want from mytable\n where mykey=(select max(mykey) from mytable);\n" }, { "answer_id": 177328, "author": "EggyBach", "author_id": 15475, "author_profile": "https://Stackoverflow.com/users/15475", "pm_score": 9, "selected": true, "text": "SELECT TOP 1 * FROM table_Name ORDER BY unique_column DESC \n" }, { "answer_id": 593540, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "select top 1 column_name from table_name order by column_name desc; \n" }, { "answer_id": 5382791, "author": "maniakk", "author_id": 670077, "author_profile": "https://Stackoverflow.com/users/670077", "pm_score": -1, "selected": false, "text": "SELECT last(column_name) FROM table\n" }, { "answer_id": 6551635, "author": "manas", "author_id": 825332, "author_profile": "https://Stackoverflow.com/users/825332", "pm_score": 0, "selected": false, "text": "SELECT * from Employees where [Employee ID] = ALL (SELECT MAX([Employee ID]) from Employees)\n" }, { "answer_id": 13135762, "author": "Muhammad Sajid", "author_id": 1785061, "author_profile": "https://Stackoverflow.com/users/1785061", "pm_score": 0, "selected": false, "text": "compalints" }, { "answer_id": 14000778, "author": "lionelmessi", "author_id": 1772722, "author_profile": "https://Stackoverflow.com/users/1772722", "pm_score": 4, "selected": false, "text": "SELECT * FROM TABLE WHERE ID = (SELECT MAX(ID) FROM TABLE)" }, { "answer_id": 21049665, "author": "Rogerio Gelonezi", "author_id": 3096335, "author_profile": "https://Stackoverflow.com/users/3096335", "pm_score": 0, "selected": false, "text": "SELECT IDENT_CURRENT('tablename')\n" }, { "answer_id": 24841332, "author": "Hamza Abuzahra", "author_id": 3856069, "author_profile": "https://Stackoverflow.com/users/3856069", "pm_score": -1, "selected": false, "text": "SELECT * FROM TABLE WHERE ID = (SELECT MAX(ID) FROM TABLE)\n" }, { "answer_id": 25798182, "author": "Neha Verma", "author_id": 3746019, "author_profile": "https://Stackoverflow.com/users/3746019", "pm_score": 2, "selected": false, "text": "select max(WorkflowStateStatusId) from WorkflowStateStatus \n" }, { "answer_id": 26404801, "author": "Sylvain Rodrigue", "author_id": 54783, "author_profile": "https://Stackoverflow.com/users/54783", "pm_score": 1, "selected": false, "text": "SELECT top 1 sys.fn_PhysLocFormatter(%%physloc%%) AS [File:Page:Slot], \n T.*\nFROM MyTable As T\norder by sys.fn_PhysLocFormatter(%%physloc%%) DESC\n" }, { "answer_id": 28425923, "author": "ConsiderItDone", "author_id": 4548942, "author_profile": "https://Stackoverflow.com/users/4548942", "pm_score": 3, "selected": false, "text": "SELECT * FROM table \nWHERE ID not in (SELECT TOP (SELECT COUNT(1)-1 \n FROM table) \n ID \n FROM table)\n" }, { "answer_id": 29365784, "author": "Ashish Pathak", "author_id": 3828166, "author_profile": "https://Stackoverflow.com/users/3828166", "pm_score": 1, "selected": false, "text": "SELECT id from comission_fees ORDER BY id DESC LIMIT 1\n" }, { "answer_id": 29944542, "author": "Gil Gomes", "author_id": 2358229, "author_profile": "https://Stackoverflow.com/users/2358229", "pm_score": 2, "selected": false, "text": "SELECT LAST_VALUE(column) OVER (PARTITION BY column ORDER BY column)..." }, { "answer_id": 51670011, "author": "Walter Verhoeven", "author_id": 8000382, "author_profile": "https://Stackoverflow.com/users/8000382", "pm_score": 0, "selected": false, "text": "select distinct T.contractId,\nLAST_VALUE(t.Price)over(partition by t.ContractId order by created ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)\nfrom [dbo].[Tick] as T\nwhere T.TickType=4\n" }, { "answer_id": 56755749, "author": "Jignesh Bhayani", "author_id": 7895529, "author_profile": "https://Stackoverflow.com/users/7895529", "pm_score": 2, "selected": false, "text": "OFFSET" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2536/" ]
177,331
<p>what sql query will i need to show the activated server roles in a specific user?</p>
[ { "answer_id": 177403, "author": "sef", "author_id": 21963, "author_profile": "https://Stackoverflow.com/users/21963", "pm_score": 1, "selected": false, "text": "select 'ServerRole' = spv.name, 'MemberName' = lgn.name, 'MemberSID' = lgn.sid\nfrom master.dbo.spt_values spv, master.dbo.sysxlogins lgn\nwhere spv.low = 0 and\n spv.type = 'SRV' and\n lgn.srvid IS NULL and\n spv.number & lgn.xstatus = spv.number\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
177,338
<p>When you unload a project in Visual Studio, any referencing projects get warning triangles on their reference to the unloaded project. I've written myself a macro to do clever stuff (detect add/remove of project and transform any references from-to file/project dependency), but I can't believe that I'm not missing something much simpler. How can the unload function be any use if I have to go around manually changing references (and it breaks the 'personal solutions/shared projects' team development paradigm).</p> <p>(This question is related to answers to <a href="https://stackoverflow.com/questions/152053/structuring-projects-dependencies-of-large-winforms-applications-in-c">this question</a> about structuring large solutions in Visual Studio - some answers mentioned having solutions with lots of projects, but 'unloading' unused projects to improve performance.)</p>
[ { "answer_id": 177403, "author": "sef", "author_id": 21963, "author_profile": "https://Stackoverflow.com/users/21963", "pm_score": 1, "selected": false, "text": "select 'ServerRole' = spv.name, 'MemberName' = lgn.name, 'MemberSID' = lgn.sid\nfrom master.dbo.spt_values spv, master.dbo.sysxlogins lgn\nwhere spv.low = 0 and\n spv.type = 'SRV' and\n lgn.srvid IS NULL and\n spv.number & lgn.xstatus = spv.number\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177338", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11410/" ]
177,353
<p>I am using VB.NET. In Visual Studio, if I right-click a property name and click "Find All References", it searches for all instances of the property being used.</p> <p>However, a property is always used either for assignment (Set method) or retrieval (Get method). Is there any way of searching for only one of these uses? e.g. search for all uses of the property in code where it is being assigned a value, not when the value is being retrieved.</p>
[ { "answer_id": 177426, "author": "Dandikas", "author_id": 23436, "author_profile": "https://Stackoverflow.com/users/23436", "pm_score": 1, "selected": false, "text": "ReSharper.FindUsages" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10786/" ]
177,363
<p>Is there a way to generate a hash of a string so that the hash itself would be of specific length? I've got a function that generates 41-byte hashes (SHA-1), but I need it to be 33-bytes max (because of certain hardware limitations). If I truncate the 41-byte hash to 33, I'd probably (certainly!) lost the uniqueness.</p> <p>Or actually I suppose an MD5 algorithm would fit nicely, if I could find some C code for one with your help.</p> <p>EDIT: Thank you all for the quick and knowledgeable responses. I've chosen to go with an MD5 hash and it fits fine for my purpose. The uniqueness is an important issue, but I don't expect the number of those hashes to be very large at any given time - these hashes represent software servers on a home LAN, so at max there would be 5, maybe 10 running.</p>
[ { "answer_id": 177369, "author": "Robert Gould", "author_id": 15124, "author_profile": "https://Stackoverflow.com/users/15124", "pm_score": 2, "selected": false, "text": "/*****Please include following header files*****/\n// string\n/***********************************************/\n\n/*****Please use following namespaces*****/\n// std\n/*****************************************/\n\nstatic unsigned int ELFHash(string str) {\n unsigned int hash = 0;\n unsigned int x = 0;\n unsigned int i = 0;\n unsigned int len = str.length();\n\n for (i = 0; i < len; i++)\n {\n hash = (hash << 4) + (str[i]);\n if ((x = hash & 0xF0000000) != 0)\n {\n hash ^= (x >> 24);\n }\n hash &= ~x;\n }\n\n return hash;\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20208/" ]
177,373
<p>I have a generic list...</p> <p>public List&lt;ApprovalEventDto&gt; ApprovalEvents</p> <p>The ApprovalEventDto has </p> <pre><code>public class ApprovalEventDto { public string Event { get; set; } public DateTime EventDate { get; set; } } </code></pre> <p>How do I sort the list by the event date?</p>
[ { "answer_id": 177380, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 3, "selected": false, "text": "using System.Linq;\n\nvoid List<ApprovalEventDto> sort(List<ApprovalEventDto> list)\n { return list.OrderBy(x => x.EventDate).ToList();\n }\n" }, { "answer_id": 177390, "author": "EggyBach", "author_id": 15475, "author_profile": "https://Stackoverflow.com/users/15475", "pm_score": 5, "selected": true, "text": "ApprovalEvents.Sort((lhs, rhs) => (lhs.EventDate.CompareTo(rhs.EventDate)));\n" }, { "answer_id": 177394, "author": "Afree", "author_id": 11317, "author_profile": "https://Stackoverflow.com/users/11317", "pm_score": 2, "selected": false, "text": "ApprovalEvents.Sort((x, y) => { return x.EventDate.CompareTo(y.EventDate); });\n" }, { "answer_id": 2756764, "author": "al-bex", "author_id": 204688, "author_profile": "https://Stackoverflow.com/users/204688", "pm_score": 0, "selected": false, "text": "ApprovalEvents.Sort((a, b) => (a.EventDate.CompareTo(b.EventDate)));\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6268/" ]
177,389
<p>This question will expand on: <a href="https://stackoverflow.com/questions/68774/best-way-to-open-a-socket-in-python">Best way to open a socket in Python</a><br /> When opening a socket how can I test to see if it has been established, and that it did not timeout, or generally fail. <br /><br /> Edit: I tried this:</p> <pre><code>try: s.connect((address, '80')) except: alert('failed' + address, 'down') </code></pre> <p>but the alert function is called even when that connection should have worked.</p>
[ { "answer_id": 177411, "author": "kender", "author_id": 4172, "author_profile": "https://Stackoverflow.com/users/4172", "pm_score": 7, "selected": true, "text": "s" }, { "answer_id": 177652, "author": "bortzmeyer", "author_id": 15625, "author_profile": "https://Stackoverflow.com/users/15625", "pm_score": 3, "selected": false, "text": "import socket, sys\n\ndef alert(msg):\n print >>sys.stderr, msg\n sys.exit(1)\n\n(family, socktype, proto, garbage, address) = \\\n socket.getaddrinfo(\"::1\", \"http\")[0] # Use only the first tuple\ns = socket.socket(family, socktype, proto)\n\ntry:\n s.connect(address) \nexcept Exception, e:\n alert(\"Something's wrong with %s. Exception type is %s\" % (address, e))\n" }, { "answer_id": 20541919, "author": "ssoto", "author_id": 423906, "author_profile": "https://Stackoverflow.com/users/423906", "pm_score": 4, "selected": false, "text": "s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\nresult = s.connect_ex((host, port))\ns.close()\nif result:\n print \"problem with socket!\"\nelse:\n print \"everything it's ok!\"\n" }, { "answer_id": 60972756, "author": "Patrik Bütler", "author_id": 13185102, "author_profile": "https://Stackoverflow.com/users/13185102", "pm_score": 2, "selected": false, "text": "try:\n s.connect((address, '80'))\nexcept:\n alert('failed' + address, 'down')\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
177,393
<p>In our code we used to have something like this:</p> <pre><code> *(controller-&gt;bigstruct) = ( struct bigstruct ){ 0 }; </code></pre> <p>This used to work great, and then we upgraded versions of GCC and suddenly started seeing stack overflows. Looking at the assembly, the old GCC code (2.x) was basically doing this:</p> <pre><code>memset(controller-&gt;bigstruct, 0, sizeof(struct bigstruct)); </code></pre> <p>The new GCC (3.4.x) was doing this</p> <pre><code> struct bigstruct temp = { 0 }; controller-&gt;bigstruct = temp; </code></pre> <p>After reviewing the C99 spec, I could see why; C99 basically requires that anonymous structures exist on the stack. It's a good concept, but this structure was 4 Megabytes large, and only ever intended to exist on heap!</p> <p>We've resorted to making our own 'initialize' function that explicitly sets the members, but that's ugly and a maintenance headache. I don't consider memset a proper solution, because I can't know that a bit-value of 0 is an appropriate zero value for the type ( nit-picking, I know, but there you are; I don't mind that the compiler does it, because it <em>can</em> know )</p> <p>What is the "correct", or at least best, way to initialize a large structure like this? </p> <p>To furthur clarify why I think memset isn't a solution: The rules of initialization of members not explicitly initialized are the same as static initialization, and are as follows: - If it has pointer type, it is initialized to a null pointer; - If it has arithmetic type, it is initialized to ( positive or unsigned ) zero; ...</p> <p>'memset' will set the memory to bit-pattern zero, which isn't necessarily the same thing. Imagine a system that doesn't use IEEE floating point numbers. Unusual, but supported by C. The representation of 0.0 doesn't have to mean "all-bits zero", it could be anything convenient to the processor.</p>
[ { "answer_id": 177402, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": true, "text": "#define InitStruct(var, type) type var; memset(&var, 0, sizeof(type))\n" }, { "answer_id": 177460, "author": "Ilya", "author_id": 6807, "author_profile": "https://Stackoverflow.com/users/6807", "pm_score": 2, "selected": false, "text": "void init_big_struct(struct bigstruct *s) \n{ \n memset(s, 0, sizeof(struct bigstruct)); \n s->some_pointer = NULL; // Multiply this as needed \n}\n" }, { "answer_id": 177931, "author": "Graeme Perrow", "author_id": 1821, "author_profile": "https://Stackoverflow.com/users/1821", "pm_score": 2, "selected": false, "text": "sizeof( foo )" }, { "answer_id": 61413277, "author": "Antonin GAVREL", "author_id": 3161139, "author_profile": "https://Stackoverflow.com/users/3161139", "pm_score": 0, "selected": false, "text": "#include <stdlib.h> // calloc header\n#include <stdio.h> // printf header\n\nvoid *init_heap_array(int elem_nb, int elem_size) {\n void *ptr;\n\n if (!(ptr = calloc(elem_nb, elem_size)))\n return NULL;\n\n return ptr;\n}\n\nvoid set_int_value_at_index(int *ptr, int value, int i) {\n ptr[i] = value;\n}\n\nvoid print_int_array_until(int *ptr, const int until) {\n for (int i = 0; i < until; i++)\n printf(\"%02d \", ptr[i]);\n putchar('\\n');\n}\n\nint main(void) {\n const int array_len = 300000;\n int *n;\n\n if (!(n = init_heap_array(array_len, sizeof(int))))\n return 1; \n\n print_int_array_until(n, 5);\n set_int_value_at_index(n, 42, 1);\n print_int_array_until(n, 5);\n\n return 0;\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177393", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25704/" ]
177,414
<p>How can i go about programaticaly getting the IP address of my network as seen from the Internet? Its obviously a property that my router has access to when it connects to the ISP. Is there any way to get this info from a router using a standard protocol. My only other option is to either find a WS which returns my IP address (suprisingly difficult to do), or just go to something like <a href="http://www.whatismyip.com" rel="nofollow noreferrer">whatismyip.com</a> and strip out all the HTML (very dirty and susceptable to change). Is there any other way??? </p>
[ { "answer_id": 177418, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 1, "selected": false, "text": "<?php\necho $_SERVER['REMOTE_ADDR'];\n?>\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
177,437
<pre><code>const static int foo = 42; </code></pre> <p>I saw this in some code here on StackOverflow and I couldn't figure out what it does. Then I saw some confused answers on other forums. My best guess is that it's used in C to hide the constant <code>foo</code> from other modules. Is this correct? If so, why would anyone use it in a C++ context where you can just make it <code>private</code>?</p>
[ { "answer_id": 177443, "author": "Kevin", "author_id": 6386, "author_profile": "https://Stackoverflow.com/users/6386", "pm_score": 3, "selected": false, "text": "const static int foo = 42;\n" }, { "answer_id": 177451, "author": "Chris Arguin", "author_id": 25704, "author_profile": "https://Stackoverflow.com/users/25704", "pm_score": 8, "selected": true, "text": "static" }, { "answer_id": 177454, "author": "Jim Buck", "author_id": 2666, "author_profile": "https://Stackoverflow.com/users/2666", "pm_score": 2, "selected": false, "text": "static const int foo = 42;\n" }, { "answer_id": 177455, "author": "Roskoto", "author_id": 13635, "author_profile": "https://Stackoverflow.com/users/13635", "pm_score": 2, "selected": false, "text": "namespace\n{\n enum\n {\n foo = 42\n };\n}\n" }, { "answer_id": 177524, "author": "oz10", "author_id": 14069, "author_profile": "https://Stackoverflow.com/users/14069", "pm_score": 2, "selected": false, "text": "static const int foo = 42;\n" }, { "answer_id": 177781, "author": "Richard Corden", "author_id": 11698, "author_profile": "https://Stackoverflow.com/users/11698", "pm_score": 6, "selected": false, "text": "// foo.h\nstatic const int i = 0;\n" }, { "answer_id": 177892, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 5, "selected": false, "text": "const int foo = 42;\n" }, { "answer_id": 178259, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 8, "selected": false, "text": "const" }, { "answer_id": 37169233, "author": "Alexey Pelekh", "author_id": 5124187, "author_profile": "https://Stackoverflow.com/users/5124187", "pm_score": 3, "selected": false, "text": "static" }, { "answer_id": 53883715, "author": "Ciro Santilli OurBigBook.com", "author_id": 895245, "author_profile": "https://Stackoverflow.com/users/895245", "pm_score": 3, "selected": false, "text": "inline" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2079/" ]
177,459
<p>I have a sort of tree structure that represent a hierarchy of layers in a map, divided by types of layers and categories. Each node can be a different class for different types of layers (but all nodes implement a common interface).</p> <p>I need to convert that class to an ASP.NET TreeView control. Each node in the input tree is a node in the output tree, with properties set that are dependant on the type of the node. I don't want the input tree classes to know the UI classes, so I can't write a "ToTreeViewNode()" method in them. There are currently 4 types of concrete node classes, 2 of them are composite (contain child-nodes) and 2 of them are leaves. This might change in the future.</p> <p>It feels like there is a design pattern here itching to be used, can you help me find what it is?</p>
[ { "answer_id": 193922, "author": "rabashani", "author_id": 10977, "author_profile": "https://Stackoverflow.com/users/10977", "pm_score": 1, "selected": false, "text": "public class Node\n{\n public IDraw genericDrawing;\n public Node[] Childs;\n public Node() { //init you genericDrawinf }\n public void Draw() \n {\n genericDrawing.Draw(this);\n foreach (Node child in Childs)\n {\n child.Draw();\n }\n }\n}\n\npublic interface IDraw\n{\n void Draw(Node node);\n}\npublic class SimpleDraw : IDraw\n{\n public void Draw(Node node)\n {\n // code your stuf in here.\n }\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3389/" ]
177,475
<p>I am building a desktop application. Our analysis says it would be better built with a RCP. Should I use the eclipse or netbeans platform to build my application . Some of the factors to consider are</p> <ul> <li>Performance</li> <li>Look and Feel</li> <li>Popularity among target users (developers/testers)</li> <li>License (has to be some FOSS)</li> </ul> <p>The application will be having things like text editor, grid views, block diagrams and graph visualizations.</p> <p>I already have experience with netbeans development, but learning eclipse won't hurt. any other options would be welcome too.</p>
[ { "answer_id": 228470, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "http://www.netbeans.org/kb/trails/platform.html\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9425/" ]
177,492
<p>What I would like to achive is: </p> <ul> <li>I go to admin site, apply some filters to the list of objects</li> <li>I click and object edit, edit, edit, hit 'Save'</li> <li>Site takes me to the list of objects... unfiltered. I'd like to have the filter from step 1 remembered and applied.</li> </ul> <p>Is there an easy way to do it?</p>
[ { "answer_id": 2645126, "author": "Ben James", "author_id": 189179, "author_profile": "https://Stackoverflow.com/users/189179", "pm_score": 1, "selected": false, "text": "ModelAdmin" }, { "answer_id": 9112369, "author": "Krzysztof", "author_id": 994350, "author_profile": "https://Stackoverflow.com/users/994350", "pm_score": 0, "selected": false, "text": "changelist_view" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177492", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9622/" ]
177,496
<p>I have a simple HTML. I am using the JQuery for AJAX purpose. Now, I want to put my javascript function in a separate javascript file. What is the syntax for this? For example, currently my script section in the HTML is something like this:</p> <pre><code>&lt;script&gt; &lt;script type="text/javascript" src="scripts/scripts.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="scripts/jquery.js"&gt;&lt;/script&gt; &lt;script type = "text/javascript" language="javascript"&gt; $(document).ready(function() { $("#SubmitForm").click(Submit()); }); &lt;/script&gt; </code></pre> <p>But I want to put the function </p> <pre><code>function() { $("#SubmitForm").click(Submit()); }) </code></pre> <p>in the file scripts.js. Can I use assign a name to that function and refer to it? </p> <p>EDit: I still have a bit of problem here: I changed the code to </p> <pre><code>&lt;script type = "text/javascript" language="javascript"&gt; $(document).ready(function() { $("#SubmitForm").click(submitMe); }); &lt;/script&gt; </code></pre> <p>and in a separate js file, I have the following code:</p> <pre><code>var submitMe = function(){ alert('clicked23!'); //$('#Testing').html('news'); }; </code></pre> <p>Here's the body section:</p> <pre><code>&lt;body&gt; welcome &lt;form id="SubmitForm" action="/showcontent" method="POST"&gt; &lt;input type="file" name="vsprojFiles" /&gt; &lt;br/&gt; &lt;input type="submit" id="SubmitButton"/&gt; &lt;/form&gt; &lt;div id="Testing"&gt; hi &lt;/div&gt; &lt;/body&gt; </code></pre> <p>Yet, it is still not working, anything I miss?</p>
[ { "answer_id": 177499, "author": "Mote", "author_id": 24789, "author_profile": "https://Stackoverflow.com/users/24789", "pm_score": -1, "selected": false, "text": "$('head').append('&lt;script type=\"text/javascript\" src=\"scripts/scripts.js\"/&gt;')\n" }, { "answer_id": 177517, "author": "NickV", "author_id": 8322, "author_profile": "https://Stackoverflow.com/users/8322", "pm_score": 1, "selected": false, "text": "var myfunc = function(){\n // Do some stuff\n}\n" }, { "answer_id": 177518, "author": "Luke Bennett", "author_id": 17602, "author_profile": "https://Stackoverflow.com/users/17602", "pm_score": 4, "selected": true, "text": "script" }, { "answer_id": 177522, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 0, "selected": false, "text": "$(document).ready(function() {\n $(\"#SubmitForm\").click(Submit);\n});\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
177,506
<pre class="lang-cpp prettyprint-override"><code>double r = 11.631; double theta = 21.4; </code></pre> <p>In the debugger, these are shown as <code>11.631000000000000</code> and <code>21.399999618530273</code>.</p> <p>How can I avoid this?</p>
[ { "answer_id": 177525, "author": "Mark Ingram", "author_id": 986, "author_profile": "https://Stackoverflow.com/users/986", "pm_score": 4, "selected": false, "text": "double theta = 21.4;\n" }, { "answer_id": 177749, "author": "Peter Wone", "author_id": 1715673, "author_profile": "https://Stackoverflow.com/users/1715673", "pm_score": 3, "selected": false, "text": "decimal" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
177,514
<p>I was hoping to implement a simple XMPP server in Java. </p> <p>What I need is a library which can parse and understand xmpp requests from a client. I have looked at Smack (mentioned below) and JSO. Smack appears to be client only so while it might help parsing packets it doesn't know how to respond to clients. Is JSO maintained it looks very old. The only promising avenue is to pull apart Openfire which is an entire commercial (OSS) XMPP server.</p> <p>I was just hoping for a few lines of code on top of Netty or Mina, so I could get started processing some messages off the wire.</p> <hr> <p>Joe - </p> <p>Well the answer to what I am trying to do is somewhat long - I'll try to keep it short. </p> <p>There are two things, that are only loosely related:</p> <p>1) I wanted to write an XMPP server because I imagine writing a custom protocol for two clients to communicate. Basically I am thinking of a networked iPhone app - but I didn't want to rely on low-level binary protocols because using something like XMPP means the app can "grow up" very quickly from a local wifi based app to an internet based one...</p> <p>The msgs exchanged should be relatively low latency, so strictly speaking a binary protocol would be best, but I felt that it might be worth exploring if XMPP didn't introduce too much overhead such that I could use it and then reap benefits of it's extensability and flexability later.</p> <p>2) I work for Terracotta - so I have this crazy bent to cluster everything. As soon as I started thinking about writing some custom server code, I figured I wanted to cluster it. Terracotta makes scaling out Java POJOs trivial, so my thought was to build a super simple XMPP server as a demonstration app for Terracotta. Basically each user would connect to the server over a TCP connection, which would register the user into a hashmap. Each user would have a LinkedBlockingQueue with a listener thread taking message from the queue. Then any connected user that wants to send a message to any other user (e.g. any old chat application) simply issues an XMPP message (as usual) to that user over the connection. The server picks it up, looks up the corresponding user object in a map and places the message onto the queue. Since the queue is clustered, regardless of wether the destination user is connected to the same physical server, or a different physical server, the message is delivered and the thread that is listening picks it up and sends it back down the destination user's tcp connection.</p> <p>So - not too short of a summary I'm afraid. But that's what I want to do. I suppose I could just write a plugin for Openfire to accomplish #1 but I think it takes care of a lot of plumbing so it's harder to do #2 (especially since I was hoping for a very small amount of code that could fit into a simple 10-20kb Maven project).</p>
[ { "answer_id": 2427358, "author": "Bill Barnhill", "author_id": 204343, "author_profile": "https://Stackoverflow.com/users/204343", "pm_score": 3, "selected": false, "text": "object Main {\n\n/**\n* @param args the command line arguments\n*/\n def main(args: Array[String]) :Unit = {\n new XMPPComponent(\n new ComponentConfig() {\n def secret() : String = { \"secret.goes.here\" }\n def server() : String = { \"communitivity.com\" }\n def subdomain() : String = { \"weather\" }\n def name() : String = { \"US Weather\" }\n def description() : String = { \"Weather component that also supported SPARQL/XMPP\" }\n },\n actor {\n loop {\n react {\n case (pkt:Packet, out : Actor) =>\n Console.println(\"Received packet...\\n\"+pkt.toXML)\n pkt match {\n case message:Message =>\n val reply = new Message()\n reply.setTo(message.getFrom())\n reply.setFrom(message.getTo())\n reply.setType(message.getType())\n reply.setThread(message.getThread())\n reply.setBody(\"Received '\"+message.getBody()+\"', tyvm\")\n out ! reply\n case _ =>\n Console.println(\"Received something other than Message\")\n }\n case _ =>\n Console.println(\"Received something other than (Packet, actor)\")\n }\n }\n }\n ).start\n }\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177514", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19013/" ]
177,519
<p>Im trying to squeeze some extra performance from searching through a table with many rows. My current reasoning is that if I can throw away some of the seldom used member from the searched table thereby reducing rowsize the amount of pagesplits and hence IO should drop giving a benefit when data start to spill from memory. </p> <p>Any good resource detailing such effects? Any experiences?</p> <p>Thanks.</p>
[ { "answer_id": 178204, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 1, "selected": false, "text": "SET STATISTICS IO ON\nGO\n\n\n-- Execute your query here\n\n\nSET STATISTICS IO OFF\nGO\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177519", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21182/" ]
177,520
<p>I am wondering if there are any alternatives to using the Expand key word when performing an LINQ to ADO.net Data Services query. The expand method does get me the data I am interested in, but it requires me to know all of the sub-objects that I am going to be working with in advance. My absolute preference would be that those sub-objects would be lazy loaded for me when I access them, but this doesn't look to be an option (I could add this lazy loading to the get on that sub-object property, but it gets wiped out when I do an update of the data service reference).</p> <p>Does anyone have any suggestions/best practices/alternatives for this situation? Thanks.</p> <p>===== Example Code using Member that has a MailingAddress =====</p> <p>Works: </p> <pre><code>var me = (from m in ctx.Member.Expand("MailingAddress") where m.MemberID == 10000 select m).First(); MessageBox.Show(me.MailingAddress.Street); </code></pre> <p>Would Prefer (would really like if this then went and loaded the MailingAddress)</p> <pre><code>var me = (from m in ctx.Member where m.MemberID == 10000 select m).First(); MessageBox.Show(me.MailingAddress.Street); </code></pre> <p>Or at least (note: something similar to this, with MailingAddressReference, works on the server side if I do so as LINQ to Entities in a Service Operation)</p> <pre><code>var me = (from m in ctx.Member where m.MemberID == 10000 select m).First(); if (!(me.MailingAddress.IsLoaded())) me.MailingAddress.Load() MessageBox.Show(me.MailingAddress.Street); </code></pre>
[ { "answer_id": 178391, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 2, "selected": false, "text": "me = me.Include(\"MailingAddress\");\n" }, { "answer_id": 190016, "author": "ChrisHDog", "author_id": 25719, "author_profile": "https://Stackoverflow.com/users/25719", "pm_score": 4, "selected": true, "text": "var me = (from m in ctx.Member.Expand(\"MailingAddress\") \n where m.MemberID == 10000 \n select m).First();\nMessageBox.Show(me.MailingAddress.Street);\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177520", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25719/" ]
177,536
<p>Is there a simple way to prevent browser from downloading and displaying images, best would be via some magic style tag or javasctipe.</p> <p>The thing is, I'd like to tweak the company's website a bit to be more usable via mobile devices. The company is a gaming one, there's like 5MBs of images on it's main page (and those can't be touched). They alredy display deadly slow on my dsl, and they can be killers to someone who's paying for his GPRS per MB ;)</p> <p>The code of the page is not mine and shouldn't be touched too (in fact, it should be written from scratch, but it's not in my gesture to do it now) :)</p> <p>I was thinking about two solutions:</p> <p>1) If there was some kind of style-tag (or maybe a javascript? the one that would work on mobile browsers tho) that would prevent browser from downloading images and force to display alt-parameter instead I could simply attach this style if I discovered a user-agent to be some known mobile thing. or 2) I could tweak the webserver a bit to check the User-agent header and if client requests an image (.png, .gif and .jpg) send 404 instead. That has a downside tho - I'd like to allow the user to view images if he actually wants to.</p> <p>It seems that first solution would be best - what you guys think? And is there a javascript way to do it? </p> <p>I could try building document DOM, then get all <code>&lt;img&gt;</code> elements, and replace their <code>src</code> with some placeholder even but will that work on most mobile browsers (Opera Mini I suppose, the Windows Mobile thingy, the basic Symbian browser from Nokia)? And would playing with document DOM be a good solution on a mobile device (I'm not sure about it's memory-and-cpu requirements to be honest).</p>
[ { "answer_id": 177654, "author": "Treb", "author_id": 22114, "author_profile": "https://Stackoverflow.com/users/22114", "pm_score": 0, "selected": false, "text": "<link rel=\"stylesheet\" media=\"screen,projection,tv\" href=\"main.css\" type=\"text/css\">\n<link rel=\"stylesheet\" media=\"handheld\" href=\"smallscreen.css\" type=\"text/css\">\n" }, { "answer_id": 178182, "author": "matte", "author_id": 25768, "author_profile": "https://Stackoverflow.com/users/25768", "pm_score": 3, "selected": true, "text": "RewriteCond %{HTTP_USER_AGENT} (nokia¦symbian¦iphone¦blackberry) [NC] \nRewriteCond %{REQUEST_URI} !^/images/$\nRewriteRule (.*) /blank.jpg [L]\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4172/" ]
177,538
<p>Every time I need to do something <em>N</em> times inside an algorithm using C# I write this code</p> <pre><code>for (int i = 0; i &lt; N; i++) { ... } </code></pre> <p>Studying Ruby I have learned about method <em>times()</em> which can be used with the same semantics like this</p> <pre><code>N.times do ... end </code></pre> <p>Code fragment in C# looks more complex and we should declare useless variable <em>i</em>.</p> <p>I tried to write extension method which returns <em>IEnumerable</em>, but I am not satisfied with the result because again I have to declare a cycle variable <em>i</em>.</p> <pre><code>public static class IntExtender { public static IEnumerable Times(this int times) { for (int i = 0; i &lt; times; i++) yield return true; } } ... foreach (var i in 5.Times()) { ... } </code></pre> <p>Is it possible using some new C# 3.0 language features to make <em>N</em> times cycle more elegant?</p>
[ { "answer_id": 177551, "author": "cvk", "author_id": 25397, "author_profile": "https://Stackoverflow.com/users/25397", "pm_score": 4, "selected": false, "text": "public interface ILoopIterator\n{\n void Do(Action action);\n void Do(Action<int> action);\n}\n\nprivate class LoopIterator : ILoopIterator\n{\n private readonly int _start, _end;\n\n public LoopIterator(int count)\n {\n _start = 0;\n _end = count - 1;\n }\n\n public LoopIterator(int start, int end)\n {\n _start = start;\n _end = end;\n } \n\n public void Do(Action action)\n {\n for (int i = _start; i <= _end; i++)\n {\n action();\n }\n }\n\n public void Do(Action<int> action)\n {\n for (int i = _start; i <= _end; i++)\n {\n action(i);\n }\n }\n}\n\npublic static ILoopIterator Times(this int count)\n{\n return new LoopIterator(count);\n}\n" }, { "answer_id": 177554, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "public static class IEnumerableExtensions\n {\n public static void Each<T>(\n this IEnumerable<T> source,\n Action<T> action)\n {\n foreach(T item in source)\n {\n action(item);\n }\n }\n }\n" }, { "answer_id": 177561, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 7, "selected": true, "text": "public static class Extensions\n{\n public static void Times(this int count, Action action)\n {\n for (int i=0; i < count; i++)\n {\n action();\n }\n }\n\n public static void Times(this int count, Action<int> action)\n {\n for (int i=0; i < count; i++)\n {\n action(i);\n }\n }\n}\n" }, { "answer_id": 15975916, "author": "Anthony Garcia-Labiad", "author_id": 1380332, "author_profile": "https://Stackoverflow.com/users/1380332", "pm_score": 0, "selected": false, "text": "public static class IntegerExtension\n{\n public static void Times(this int n, Action<int> action)\n {\n if (action == null) throw new ArgumentNullException(\"action\");\n\n for (int i = 0; i < n; ++i)\n {\n action(i);\n }\n }\n}\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11256/" ]
177,550
<p>While estimating straight row and table sizes are fairly simple math, we find it challenging to guess just how much space each index will occupy (for a given table size). What areas can we learn to calculate a better estimate and growth rate for indexes?</p>
[ { "answer_id": 23830119, "author": "Marcello Miorelli", "author_id": 1501497, "author_profile": "https://Stackoverflow.com/users/1501497", "pm_score": 1, "selected": false, "text": "--Find out the disk size of an index:\n--USE [DB NAME HERE]\ngo\nSELECT\nOBJECT_NAME(I.OBJECT_ID) AS TableName,\nI.name AS IndexName, \n8 * SUM(AU.used_pages) AS 'Index size (KB)',\nCAST(8 * SUM(AU.used_pages) / 1024.0 AS DECIMAL(18,2)) AS 'Index size (MB)'\nFROM\nsys.indexes I\nJOIN sys.partitions P ON P.OBJECT_ID = I.OBJECT_ID AND P.index_id = I.index_id\nJOIN sys.allocation_units AU ON AU.container_id = P.partition_id\n--WHERE \n-- OBJECT_NAME(I.OBJECT_ID) = '<TableName>' \nGROUP BY\nI.OBJECT_ID, \nI.name\nORDER BY\nTableName\n\n--========================================================================================\n\n--http://msdn.microsoft.com/en-us/library/fooec9de780-68fd-4551-b70b-2d3ab3709b3e.aspx\n\n--I believe that keeping the GROUP BY \n--is the best option in this case\n--because of sys.allocation_units\n--can have 4 types of data inside\n--as below:\n\n--type tinyint\n--Type of allocation unit.\n--0 = Dropped\n--1 = In-row data (all data types, except LOB data types)\n--2 = Large object (LOB) data (text, ntext, image, xml, large value types, and CLR user-defined types)\n--3 = Row-overflow data\n\n--marcelo miorelli 8-NOV-2013\n--========================================================================================\n" } ]
2008/10/07
[ "https://Stackoverflow.com/questions/177550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2663/" ]