qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
146,795
<p>I can't use the <code>Get*Profile</code> functions because I'm using an older version of the Windows CE platform SDK which doesn't have those. It doesn't have to be too general.</p> <pre><code>[section] name = some string </code></pre> <p>I just need to open the file, check for the existence of "section", and the value associated with "name". Standard C++ is preferred.</p>
[ { "answer_id": 146830, "author": "Micah", "author_id": 17744, "author_profile": "https://Stackoverflow.com/users/17744", "pm_score": 1, "selected": false, "text": "MyDependencyProperty.OverrideMetadata(typeof(MyNewType), \n new PropertyMetadata());\n" }, { "answer_id": 993561, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "Label myLabel = new Label();\nthis.RegisterName(myLabel.Name, myLabel);\n" }, { "answer_id": 1412194, "author": "statenjason", "author_id": 88340, "author_profile": "https://Stackoverflow.com/users/88340", "pm_score": 4, "selected": true, "text": "DependencyProperty.Register" }, { "answer_id": 4262967, "author": "Shimmy Weitzhandler", "author_id": 75500, "author_profile": "https://Stackoverflow.com/users/75500", "pm_score": 0, "selected": false, "text": "Selector" }, { "answer_id": 48708748, "author": "Davy", "author_id": 1790588, "author_profile": "https://Stackoverflow.com/users/1790588", "pm_score": 0, "selected": false, "text": "BindingOperations.ClearAllBindings(this);\nDispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new DispatcherOperationCallback(delegate { return null; }), null);\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3146/" ]
146,801
<p>I am using virtual machines for development,but each time I need a new VM, I copy the file and create a new server, but I need a new name for the server to add it to our network.</p> <p>After renaming the server, the Sharepoint sites have many errors and do not run.</p>
[ { "answer_id": 146830, "author": "Micah", "author_id": 17744, "author_profile": "https://Stackoverflow.com/users/17744", "pm_score": 1, "selected": false, "text": "MyDependencyProperty.OverrideMetadata(typeof(MyNewType), \n new PropertyMetadata());\n" }, { "answer_id": 993561, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "Label myLabel = new Label();\nthis.RegisterName(myLabel.Name, myLabel);\n" }, { "answer_id": 1412194, "author": "statenjason", "author_id": 88340, "author_profile": "https://Stackoverflow.com/users/88340", "pm_score": 4, "selected": true, "text": "DependencyProperty.Register" }, { "answer_id": 4262967, "author": "Shimmy Weitzhandler", "author_id": 75500, "author_profile": "https://Stackoverflow.com/users/75500", "pm_score": 0, "selected": false, "text": "Selector" }, { "answer_id": 48708748, "author": "Davy", "author_id": 1790588, "author_profile": "https://Stackoverflow.com/users/1790588", "pm_score": 0, "selected": false, "text": "BindingOperations.ClearAllBindings(this);\nDispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, new DispatcherOperationCallback(delegate { return null; }), null);\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13813/" ]
146,835
<p>I have a project the requires the use of the exec family. My project consist of making an interactive shell. The shell will implement a few basic commands like cd, ls, echo, etc. I have been researching the use of exec, but have not found a useful site. Any suggested links would help.</p> <pre><code>int ret; ret = execl ("/bin/ls", "ls", "-1", (char *)0); </code></pre> <p>How would i get the output of this operation to show on the screen?</p>
[ { "answer_id": 146885, "author": "Jose Vega", "author_id": 17162, "author_profile": "https://Stackoverflow.com/users/17162", "pm_score": 2, "selected": false, "text": "int fd = 1;\ndup(fd);\nclose(fd);\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146835", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17162/" ]
146,890
<p>Is anyone successfully using the CJ web services? I just keep getting <code>java.lang.NullPointerException</code>s even though my app is .net (clearly their errors). CJ support doesn't even know what a web service is. I googled and found many people getting this or other errors. Question is: is it a temporary problem or am I doomed to parse manually downloaded reports for eternity?</p> <p>The specific API I'm trying to use is the <a href="http://help.cj.com/en/web_services/Publisher_Commission_Service.htm" rel="nofollow noreferrer">daily publisher commission service</a>. <a href="https://pubcommission.api.cj.com/wsdl/version2/publisherCommissionService.wsdl" rel="nofollow noreferrer">Here</a> is the WSDL.</p> <p>Links:</p> <ul> <li><a href="http://webservices.cj.com/" rel="nofollow noreferrer">CJ web services home</a></li> <li><a href="http://help.cj.com/en/web_services/web_services.htm" rel="nofollow noreferrer">API Reference</a></li> </ul>
[ { "answer_id": 3047681, "author": "explodes", "author_id": 367553, "author_profile": "https://Stackoverflow.com/users/367553", "pm_score": 0, "selected": false, "text": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:api=\"https://pubcommission.api.cj.com\">\n <soapenv:Header/>\n <soapenv:Body>\n <api:findPublisherCommissions>\n <api:developerKey>*DEVKEY*</api:developerKey>\n <api:date>01/19/2007</api:date>\n <api:dateType>event</api:dateType>\n <api:advertiserIds></api:advertiserIds>\n <api:websiteIds>123456</api:websiteIds>\n <api:actionStatus>all</api:actionStatus>\n <api:actionTypes></api:actionTypes>\n <api:adIds></api:adIds>\n <api:countries></api:countries>\n <api:correctionStatus></api:correctionStatus>\n <api:sortBy>commissionAmount</api:sortBy>\n <api:sortOrder>desc</api:sortOrder>\n </api:findPublisherCommissions>\n </soapenv:Body>\n </soapenv:Envelope>\n" }, { "answer_id": 3146595, "author": "Surjit", "author_id": 379687, "author_profile": "https://Stackoverflow.com/users/379687", "pm_score": 2, "selected": false, "text": "$client = new SoapClient($cjCommissionUrl,\n\n array('trace' => 1,\n 'soap_version' => SOAP_1_1,\n 'style' => SOAP_DOCUMENT,\n 'encoding' => SOAP_LITERAL\n ));\n\n\n$date = '06/23/2010';\n $results = $client->findPublisherCommissions(array(\n \"developerKey\" => $cjDeveloperKey,\n \"date\" => $date,\n \"dateType\" => 'posting',\n \"countries\" => 'all',\n));\n" }, { "answer_id": 20738833, "author": "waqas umar", "author_id": 2787658, "author_profile": "https://Stackoverflow.com/users/2787658", "pm_score": 1, "selected": false, "text": "include('../../../../wp-load.php');\n\n$stringkeyw=urlencode(get_option('cj_keyword'));\nif(get_option('rm_num_products')==''){\n$pperkeyword=50;\n}else{\n$pperkeyword= get_option('rm_num_products');\n}//number of products against keyword\n\n$ch = curl_init();\n\ncurl_setopt($ch, CURLOPT_URL, \"https://product-search.api.cj.com/v2/product-search?website-id=\".get_option('cj_siteid').\"&keywords=\".$stringkeyw.\"&records-per-page=\".$pperkeyword.\"&serviceable-area=US\");\n\ncurl_setopt($ch, CURLOPT_HEADER,false); \n\ncurl_setopt($ch, CURLOPT_HTTPGET, true); \n\ncurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\n\ncurl_setopt($ch, CURLOPT_HTTPHEADER, array(\"Accept: application/xml\", \"Authorization:\".get_option('cj_devid').\"\"));\n\n$result = curl_exec($ch);\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21239/" ]
146,893
<p>I am a firm believer in the idea that one of the most important things you get from learning a new language is not how to use a new language, but the knowledge of concepts that you get from it. I am not asking how important or useful you think Assembly is, nor do I care if I never use it in any of my real projects. </p> <p>What I want to know is what concepts of Assembly do you think are most important for any general programmer to know? It doesn't have to be directly related to Assembly - it can also be something that you feel the typical programmer who spends all their time in higher-level languages would not understand or takes for granted, such as the CPU cache.</p>
[ { "answer_id": 147171, "author": "Dark Shikari", "author_id": 11206, "author_profile": "https://Stackoverflow.com/users/11206", "pm_score": 2, "selected": false, "text": "c: 1332\nmmx: 187\nsse2: 127\n" }, { "answer_id": 264036, "author": "Artelius", "author_id": 31945, "author_profile": "https://Stackoverflow.com/users/31945", "pm_score": 4, "selected": true, "text": "while(x--)\n{\n ...\n}\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23175/" ]
146,896
<p>How can I access <code>UserId</code> in ASP.NET Membership without using <code>Membership.GetUser(username)</code> in ASP.NET Web Application Project?</p> <p>Can <code>UserId</code> be included in <code>Profile</code> namespace next to <code>UserName</code> (<code>System.Web.Profile.ProfileBase</code>)?</p>
[ { "answer_id": 148026, "author": "Andrew Myhre", "author_id": 5152, "author_profile": "https://Stackoverflow.com/users/5152", "pm_score": 0, "selected": false, "text": "select * from [dbo.User] where Username = 'andrew.myhre'\n" }, { "answer_id": 154280, "author": "technophile", "author_id": 23029, "author_profile": "https://Stackoverflow.com/users/23029", "pm_score": 0, "selected": false, "text": "System.Web.HttpContext.Current.User.Identity.Name" }, { "answer_id": 161301, "author": "GrZeCh", "author_id": 23280, "author_profile": "https://Stackoverflow.com/users/23280", "pm_score": 3, "selected": true, "text": "System.Web.HttpContext.Current.User.Identity.Name\n" }, { "answer_id": 347185, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "{\nMembershipUser m = Membership.GetUser();\nResponse.Write(\"ID: \" + m.ProviderUserKey.ToString());\n}\n" }, { "answer_id": 416731, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "MembershipUser CurrentUser = Membership.GetUser(User.Identity.Name);\nResponse.Write(\"CurrentUser ID :: \" + CurrentUser.ProviderUserKey);\n" }, { "answer_id": 6677031, "author": "Maysam", "author_id": 689779, "author_profile": "https://Stackoverflow.com/users/689779", "pm_score": 0, "selected": false, "text": " <roleManager\n enabled=\"true\"\n cacheRolesInCookie=\"true\"\n defaultProvider=\"QuickStartRoleManagerSqlProvider\"\n cookieName=\".ASPXROLES\"\n cookiePath=\"/\"\n cookieTimeout=\"30\"\n cookieRequireSSL=\"false\"\n cookieSlidingExpiration=\"true\"\n createPersistentCookie=\"false\"\n cookieProtection=\"All\">\n <providers>\n <add name=\"QuickStartRoleManagerSqlProvider\"\n type=\"System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"\n connectionStringName=\"ASPNETDB\"\n applicationName=\"SecurityQuickStart\"/>\n </providers>\n</roleManager>\n" }, { "answer_id": 16026419, "author": "Jun", "author_id": 2284474, "author_profile": "https://Stackoverflow.com/users/2284474", "pm_score": 2, "selected": false, "text": "Membership.GetUser().ProviderUserKey\n" }, { "answer_id": 27070809, "author": "HamidSadeghi", "author_id": 1807399, "author_profile": "https://Stackoverflow.com/users/1807399", "pm_score": 1, "selected": false, "text": "public string GetUserID()\n {\n MembershipUser _User;\n string _UserId = \"\";\n _User = Membership.GetUser();\n Guid UserId = (Guid)_User.ProviderUserKey;\n return _UserId = UserId.ToString();\n }\n" }, { "answer_id": 73163058, "author": "Moumit", "author_id": 2052085, "author_profile": "https://Stackoverflow.com/users/2052085", "pm_score": 0, "selected": false, "text": "sql server" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23280/" ]
146,897
<p>This is a bit of a weird one, and I could well be coding this completely wrong - hence why I've hit the same error twice in two days, in completely different parts of a script. The code I'm using is below:</p> <pre><code> public function findAll( $constraints = array() ) { // Select all records $SQL = 'SELECT * FROM ' . $this->tableName; // See if there's any constraints if( count( $constraints ) > 0 ) { $SQL .= ' WHERE '; foreach( $constraints as $field => $value ) { $SQL .= $field . ' = :' . $field . ' AND '; } } // Remove the final AND and prepare the statement $SQL = substr( $SQL, 0, -5 ); $PDOStatement = $this->PDO->prepare( $SQL ); // Loop through constraints and bind parameters foreach( $constraints as $field => $value ) { print 'Binding ' . $field . ' to ' . $value . ' <br />'; $PDOStatement->bindParam( $field, $value ); } $PDOStatement->execute(); var_dump($PDOStatement); while ( $results = $PDOStatement->fetch( PDO::FETCH_ASSOC ) ) { var_dump($results); } } </code></pre> <p>I'm pretty new to using PDO, but basically I'm attempting to pass an array of constraints e.g. <pre><code>array( 'active' => 1, 'name' => 'James' )</code></pre> and return all rows from the table <pre><code>WHERE active = 1 AND name = 'James'</code></pre></p> <p>If I use this array, the SQL executed from the first <pre><code>var_dump( )</code></pre> is <pre><code>SELECT * FROM {table} WHERE active = :active AND name = 'James'</code></pre> - exactly as I expect. The bound parameters prints 'Binding active to 1' and 'Binding name to James' - exactly as expected. The rows exist in the database, and yet the second <pre><code>var_dump()</code></pre> call for $results outputs nothing - i.e. no rows are returned.</p> <p>If I pass an array of a single constraint, e.g. <pre><code>array( 'active' => 1 )</code></pre>, this works perfectly fine. It appears to be whenever multiple constraints are passed that it stops working.</p>
[ { "answer_id": 146925, "author": "troelskn", "author_id": 18180, "author_profile": "https://Stackoverflow.com/users/18180", "pm_score": 4, "selected": true, "text": "bindParam" }, { "answer_id": 27653260, "author": "Seth McCauley", "author_id": 1775548, "author_profile": "https://Stackoverflow.com/users/1775548", "pm_score": 0, "selected": false, "text": "bindValue" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/393028/" ]
146,901
<p>I'm using C# and i have written a locally installed application that dynamically generates files which need to be on an FTP server.</p> <p>Do i generate them to disk then upload them to the FTP server? or is there a way to open a stream to an FTP server and write the files directly?</p>
[ { "answer_id": 146918, "author": "Caerbanog", "author_id": 23190, "author_profile": "https://Stackoverflow.com/users/23190", "pm_score": 0, "selected": false, "text": "System.Net.FtpWebRequest\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13227/" ]
146,914
<p>Is there any way to see an overview of what kind of queries are spent the most time on every day on MySQL?</p>
[ { "answer_id": 146933, "author": "Gordon Wilson", "author_id": 23071, "author_profile": "https://Stackoverflow.com/users/23071", "pm_score": 4, "selected": true, "text": "mysqld" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8005/" ]
146,916
<p>I have the following problem:</p> <p>I have an HTML textbox (<code>&lt;input type="text"&gt;</code>) whose contents are modified by a script I cannot touch (it is my page, but i'm using external components).</p> <p>I want to be notified in my script every time the value of that textbox changes, so I can react to it.</p> <p>I've tried this:</p> <pre><code>txtStartDate.observe('change', function() { alert('change' + txtStartDate.value) }); </code></pre> <p>which (predictably) doesn't work. It only gets executed if I myself change the textbox value with the keyboard and then move the focus elsewhere, but it doesn't get executed if the script changes the value.</p> <p>Is there another event I can listen to, that i'm not aware of?</p> <p><br /><br /></p> <p>I'm using the Prototype library, and in case it's relevant, the external component modifying the textbox value is Basic Date Picker (www.basicdatepicker.com) </p>
[ { "answer_id": 146928, "author": "noah", "author_id": 12034, "author_profile": "https://Stackoverflow.com/users/12034", "pm_score": 4, "selected": true, "text": "basicDatePicker.selectDate = basicDatePicker.selectDate.wrap(function(orig,year,month,day,hide) {\n myListener(year,month,day);\n return orig(year,month,day,hide);\n});\n" }, { "answer_id": 147011, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 2, "selected": false, "text": "var value = someInput.value;\n\nsetInterval(function()\n{\n if (someInput.value != value)\n {\n alert(\"Changed from \" + value + \" to \" + someInput.value);\n value = someInput.value;\n }\n}, 250);\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3314/" ]
146,924
<p>I'm using C and sometimes I have to handle paths like</p> <ul> <li>C:\Whatever</li> <li>C:\Whatever\</li> <li>C:\Whatever\Somefile</li> </ul> <p>Is there a way to check if a given path is a directory or a given path is a file?</p>
[ { "answer_id": 146938, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "struct stat s;\nif( stat(path,&s) == 0 )\n{\n if( s.st_mode & S_IFDIR )\n {\n //it's a directory\n }\n else if( s.st_mode & S_IFREG )\n {\n //it's a file\n }\n else\n {\n //something else\n }\n}\nelse\n{\n //error\n}\n" }, { "answer_id": 32564076, "author": "anurag-jain", "author_id": 277375, "author_profile": "https://Stackoverflow.com/users/277375", "pm_score": -1, "selected": false, "text": "CFile" }, { "answer_id": 43281413, "author": "Roi Danton", "author_id": 4566599, "author_profile": "https://Stackoverflow.com/users/4566599", "pm_score": 5, "selected": false, "text": "is_directory()" }, { "answer_id": 65586461, "author": "Juan Carlos", "author_id": 6828138, "author_profile": "https://Stackoverflow.com/users/6828138", "pm_score": 0, "selected": false, "text": "bool IsDirectory(std::wstring path)\n{\n DWORD attrib = GetFileAttributes(path.c_str());\n\n if ((attrib & FILE_ATTRIBUTE_DIRECTORY) != 0)\n return true;\n\n return false;\n}\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/87/" ]
146,931
<p>I am working with a log of events where there are about 60 different "types" of events. Each event shares about 10 properties, and then there are subcategories of events that share various extra properties.</p> <p>How I work with these events does depend on their type or what categorical interfaces they implement.</p> <p>But it seems to be leading to code bloat. I have a lot of redundancy in the subclass methods because they implement some of the same interfaces.</p> <p>Is it more appropriate to use a single event class with a "type" property and write logic that checks type and maintain some organization of categories of types (e.g. a list of event types that are category a, a second list that are category b, etc)? Or is the subclass design more appropriate in this case?</p> <p>First Approach:</p> <pre><code>public interface Category1 {} public interface Category2 {} public abstract class Event { private base properties...; } public class EventType1 extends Event implements Category1, Category2 { private extra properties ...; } public class EventType2 extends Event implements Category3, Category4 { private extra properties ...; } </code></pre> <p>Second Approach:</p> <pre><code>public enum EventType {TYPE1, TYPE2, TYPE3, ...} public class Event { private union of all possible properties; private EventType type; } </code></pre> <p>My personal opinion is that it seems like a single event object is what is appropriate, because, if I am thinking about it correctly, there is no need for using inheritance to represent the model because it is really only the behavior and my conditions that alter based on the type. </p> <p>I need to have code that does stuff like:</p> <pre><code>if(event instanceof Category1) { ... } </code></pre> <p>This works well in the first approach in that instead of instanceof I can just call the method on the event and implement "the same code" in each of the appropriate subclasses. </p> <p>But the second approach is so much more concise. Then I write stuff like:</p> <pre><code>if(CATEGORY1_TYPES.contains(event.getEventType()) { ... } </code></pre> <p>And all my "processing logic" can be organized into a single class and none of it is redundantly spread out among the subclasses. So is this a case where although OO appears more appropriate, it would be better not too?</p>
[ { "answer_id": 146981, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "class EventType {\n\n protected EventPropertyHandler handler;\n\n public EventType(EventPropertyHandler h) {\n handler = h;\n }\n\n void handleEvent(map<String,String> properties) {\n handler.handle(properties);\n }\n}\n\nabstract class EventPropertyHandler {\n abstract void handle(map<String, String> properties);\n}\nclass SomeHandler extends EventPropertyHandler {\n void handle(map<String, String> properties) {\n String value = properties.get(\"somekey\");\n // do something with value..\n }\n}\n\nclass EventBuilder {\n public static EventType buildSomeEventType() {\n // \n EventType e = new EventType( new SomeHandler() );\n }\n}\n" }, { "answer_id": 146988, "author": "pythonquick", "author_id": 6225, "author_profile": "https://Stackoverflow.com/users/6225", "pm_score": 1, "selected": false, "text": "public class Category1Impl implements Category1 {\n ...\n}\n\npublic class Category2Impl implements Category2 {\n ...\n}\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2204759/" ]
146,936
<p>As you work in a legacy codebase what will have the greatest impact over time that will improve the quality of the codebase?</p> <ul> <li>Remove unused code</li> <li>Remove duplicated code </li> <li>Add unit tests to improve test coverage where coverage is low</li> <li>Create consistent formatting across files</li> <li>Update 3rd party software</li> <li>Reduce warnings generated by static analysis tools (i.e.Findbugs)</li> </ul> <p>The codebase has been written by many developers with varying levels of expertise over many years, with a lot of areas untested and some untestable without spending a significant time on writing tests.</p>
[ { "answer_id": 217164, "author": "Hapkido", "author_id": 27646, "author_profile": "https://Stackoverflow.com/users/27646", "pm_score": 4, "selected": false, "text": "* Remove unused code\n" }, { "answer_id": 15070375, "author": "craigmcnulty", "author_id": 1949785, "author_profile": "https://Stackoverflow.com/users/1949785", "pm_score": 1, "selected": false, "text": "if" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15352/" ]
146,943
<p>This is something simple I came up with for <a href="https://stackoverflow.com/questions/146795/how-to-read-config-file-entries-from-an-ini-file">this question</a>. I'm not entirely happy with it and I saw it as a chance to help improve my use of STL and streams based programming.</p> <pre><code>std::wifstream file(L"\\Windows\\myini.ini"); if (file) { bool section=false; while (!file.eof()) { std::wstring line; std::getline(file, line); if (line.empty()) continue; switch (line[0]) { // new header case L'[': { std::wstring header; size_t pos=line.find(L']'); if (pos!=std::wstring::npos) { header=line.substr(1, pos); if (header==L"Section") section=true; else section=false; } } break; // comments case ';': case ' ': case '#': break; // var=value default: { if (!section) continue; // what if the name = value does not have white space? // what if the value is enclosed in quotes? std::wstring name, dummy, value; lineStm &gt;&gt; name &gt;&gt; dummy; ws(lineStm); WCHAR _value[256]; lineStm.getline(_value, ELEMENTS(_value)); value=_value; } } } } </code></pre> <p>How would you improve this? Please do not recommend alternative libraries - I just want a simple method for parsing out some config strings from an INI file.</p>
[ { "answer_id": 146998, "author": "Airsource Ltd", "author_id": 18017, "author_profile": "https://Stackoverflow.com/users/18017", "pm_score": 1, "selected": false, "text": "for (size_t i=1; i<line.length(); i++)\n {\n if (line[i]!=L']')\n header.push_back(line[i]);\n else\n break;\n }\n" }, { "answer_id": 147169, "author": "Dprado", "author_id": 21943, "author_profile": "https://Stackoverflow.com/users/21943", "pm_score": 3, "selected": true, "text": "boost::smatch matches;\nboost::regex name_value(\"(\\S+)\\s*=\\s*(\\S+)\");\nif(boost::regex_match(line, matches, name_value))\n{\n name = matches[1];\n value = matches[2];\n}\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146943", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3146/" ]
146,963
<p>I'm creating an ORM in PHP, and I've got a class 'ORM' which basically creates an object corresponding to a database table (I'm aiming for similar to/same functionality as an ActiveRecord pattern.) ORM itself extends 'Database', which sets up the database connection. </p> <p>So, I can call: <code><pre>$c = new Customer(); $c->name = 'John Smith'; $c->save();</pre></code></p> <p>The ORM class provides this functionality (sets up the class properties, provides save(), find(), findAll() etc. methods), and Customer extends ORM. However, in the future I may be wanting to add extra public methods to Customer (or any other model I create), so should this be extending ORM or not?</p> <p>I know I haven't provided much information here, but hopefully this is understandable on a vague explanation, as opposed to posting up 300+ lines of code.</p>
[ { "answer_id": 147148, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 3, "selected": true, "text": "// Customer.class.php\nfunction getByName($name) {\n // SELECT * FROM `customer` WHERE `name` = $name\n}\n\n// ** this could instead be written as: **\n// ORM.class.php\nfunction getByField($field, $value) {\n // SELECT * FROM `$this->table` WHERE `$field` = $value\n}\n" }, { "answer_id": 147256, "author": "Michał Niedźwiedzki", "author_id": 2169, "author_profile": "https://Stackoverflow.com/users/2169", "pm_score": 2, "selected": false, "text": "class Customer {\n public $name;\n public function save() {\n $orm = new ORM('customers', 'id'); // table name and primary key\n $orm->name = $this->name;\n $orm->save();\n }\n}\n" }, { "answer_id": 147727, "author": "SchizoDuckie", "author_id": 18077, "author_profile": "https://Stackoverflow.com/users/18077", "pm_score": 0, "selected": false, "text": "class Poll extends dbObject // dbObject is my ORM. Poll can extend it so it gets all properties.\n{\n function __construct($ID=false)\n {\n $this->__setupDatabase('polls', // db table\n array('ID_Poll' => 'ID', // db field => object property\n 'strPollQuestion' => 'strpollquestion', \n 'datPublished' => 'datpublished', \n 'datCloseDate' => 'datclosedate', \n 'enmClosed' => 'enmclosed', \n 'enmGoedgekeurd' => 'enmgoedgekeurd'),\n 'ID_Poll', // primary db key \n $ID); // primary key value\n $this->addRelation('Pollitem'); //Connect PollItem to Poll 1;1\n $this->addRelation('Pollvote', 'PollUser'); // connect pollVote via PollUser (many:many)\n\n\n }\n\nfunction Display()\n{\n\n // do your displayíng for poll here:\n $pollItems = $this->Find(\"PollItem\"); // find all poll items\n $alreadyvoted = $this->Find(\"PollVote\", array(\"IP\"=>$_SERVER['REMOTE_ADDR'])); // find all votes for current ip\n}\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146963", "https://Stackoverflow.com", "https://Stackoverflow.com/users/393028/" ]
146,973
<p>I'm making an automated script to read a list from a site posting the latest compiled code. That's the part I've already figured out. The next part of the script is to grab that compiled code from a server with an Untrusted Cert.</p> <p>This is how I'm going about grabbing the file:</p> <pre><code>$web = new-object System.Net.WebClient $web.DownloadFile("https://uri/file.msi", "installer.msi") </code></pre> <p>Then I get the following error:</p> <blockquote> <p>Exception calling "DownloadFile" with "2" argument(s): "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."</p> </blockquote> <p>I know I'm missing something, but I can't get the correct way to search for it.</p>
[ { "answer_id": 57874312, "author": "jpvantuyl", "author_id": 992425, "author_profile": "https://Stackoverflow.com/users/992425", "pm_score": 0, "selected": false, "text": "[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
146,986
<p>I'm writing some semi-portable code and want to be able to detect when I'm compiling for iPhone. So I want something like <code>#ifdef IPHONE_SDK...</code>. </p> <p>Presumably Xcode defines something, but I can't see anything under project properties, and Google isn't much help.</p>
[ { "answer_id": 147027, "author": "Airsource Ltd", "author_id": 18017, "author_profile": "https://Stackoverflow.com/users/18017", "pm_score": 8, "selected": true, "text": "#include \"TargetConditionals.h\"\n" }, { "answer_id": 173297, "author": "lajos", "author_id": 3740, "author_profile": "https://Stackoverflow.com/users/3740", "pm_score": 5, "selected": false, "text": "-g3 -save-temps -dD\n" }, { "answer_id": 46227527, "author": "russbishop", "author_id": 551519, "author_profile": "https://Stackoverflow.com/users/551519", "pm_score": 2, "selected": false, "text": "+--------------------------------------+\n| TARGET_OS_MAC |\n| +---+ +---------------------------+ |\n| | | | TARGET_OS_IPHONE | |\n| |OSX| | +-----+ +----+ +-------+ | |\n| | | | | IOS | | TV | | WATCH | | |\n| | | | +-----+ +----+ +-------+ | |\n| +---+ +---------------------------+ |\n+--------------------------------------+\n\nDevices: TARGET_OS_EMBEDDED\nSimulators: TARGET_OS_SIMULATOR\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146986", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18017/" ]
146,989
<p>One of my nasty (?) programming habits in C++ and Java is to always precede calls or accesses to members with a <code>this</code>. For example: <code>this.process(this.event)</code>.</p> <p>A few of my students commented on this, and I'm wondering if I am teaching bad habits. </p> <p>My rationale is:</p> <ol> <li>Makes code more readable — Easier to distinguish fields from local variables.</li> <li>Makes it easier to distinguish standard calls from static calls (especially in Java)</li> <li>Makes me remember that this call (unless the target is final) could end up on a different target, for example in an overriding version in a subclass.</li> </ol> <p>Obviously, this has zero impact on the compiled program, it's just readability. So am I making it more or less readable?</p> <p>Note: I turned it into a CW since there really isn't a correct answer.</p>
[ { "answer_id": 146995, "author": "cynicalman", "author_id": 410, "author_profile": "https://Stackoverflow.com/users/410", "pm_score": 6, "selected": false, "text": "this.fieldName = fieldName\n" }, { "answer_id": 147009, "author": "Jason Baker", "author_id": 2147, "author_profile": "https://Stackoverflow.com/users/2147", "pm_score": 3, "selected": false, "text": "class SomeClass{\n int x;\n int y;\n\n SomeClass(int x, int y){\n this.x = x\n this.y = y\n }\n}\n" }, { "answer_id": 147217, "author": "OscarRyz", "author_id": 20654, "author_profile": "https://Stackoverflow.com/users/20654", "pm_score": 1, "selected": false, "text": "//Before\nthis.calculateMass();\nthis.perfornmDengerAction();\nthis.var = ...\nthis.other = ...\n" }, { "answer_id": 147253, "author": "user23313", "author_id": 23313, "author_profile": "https://Stackoverflow.com/users/23313", "pm_score": 0, "selected": false, "text": "public void setFoo(String foo) {\n this.foo = foo; //member assignment\n}\n\npublic doSomething() {\n doThat(); //member method\n}\n" }, { "answer_id": 147292, "author": "coppro", "author_id": 16855, "author_profile": "https://Stackoverflow.com/users/16855", "pm_score": 2, "selected": false, "text": "this" }, { "answer_id": 148276, "author": "Rob Gilliam", "author_id": 23408, "author_profile": "https://Stackoverflow.com/users/23408", "pm_score": 4, "selected": false, "text": "if (0 == someValue)\n{\n ....\n}\n" }, { "answer_id": 150040, "author": "paercebal", "author_id": 14089, "author_profile": "https://Stackoverflow.com/users/14089", "pm_score": 2, "selected": false, "text": "this" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23072/" ]
146,994
<p>I'm looking for a free, preferably open source, http <a href="http://en.wikipedia.org/wiki/Image_server" rel="noreferrer">image processing server</a>. I.e. I would send it a request like this:</p> <pre><code>http://myimageserver/rotate?url=http%3A%2F%2Fstackoverflow.com%2FContent%2FImg%2Fstackoverflow-logo-250.png&amp;angle=90 </code></pre> <p>and it would return that image rotated. Features wanted:</p> <ul> <li>Server-side caching</li> <li>Several operations/effects (like scaling, watermarking, etc). The more the merrier.</li> <li>POST support to supply the image (instead of the server GETting it).</li> <li>Different output formats (PNG, JPEG, etc).</li> <li>Batch operations</li> </ul> <p>It would be something like <a href="http://leadtools.com/SDK/web-services/Image-Service/default.htm" rel="noreferrer">this</a>, but free and less SOAPy. Is there anything like this or am I asking too much?</p>
[ { "answer_id": 147103, "author": "Till", "author_id": 2859, "author_profile": "https://Stackoverflow.com/users/2859", "pm_score": 2, "selected": false, "text": "<Location /img>\nPerlFixupHandler Apache::ImageMagick\nPerlSetVar AIMCacheDir /tmp/your/cache/directory\n</Location>\n" }, { "answer_id": 8795348, "author": "Lilith River", "author_id": 166893, "author_profile": "https://Stackoverflow.com/users/166893", "pm_score": 4, "selected": true, "text": "image.jpg?width=100&height=100&mode=crop" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/146994", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21239/" ]
147,016
<p>I thought that <code>CSIDL_COMMON_APPDATA\company\product</code> should be the place to put files that are common for all users of the application and that the application can modify, however, on Vista this is a read-only location, unless modified by the installer (as per MSDN - <a href="http://msdn.microsoft.com/en-us/library/ms995853.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms995853.aspx</a>), so... what's best? Modify the location's security settings to allow writing or use <code>CSIDL_COMMON_DOCUMENTS\company\product</code> instead? Maybe there's a third option?</p> <p>Also, is there an "official" Microsoft recommendation on this somewhere?</p>
[ { "answer_id": 147045, "author": "Christoffer Lette", "author_id": 11808, "author_profile": "https://Stackoverflow.com/users/11808", "pm_score": 1, "selected": false, "text": "CSIDL" }, { "answer_id": 7136452, "author": "Wyatt O'Day", "author_id": 124805, "author_profile": "https://Stackoverflow.com/users/124805", "pm_score": 3, "selected": false, "text": "#include <windows.h>\n\n#include <shlobj.h>\n#pragma comment(lib, \"shell32.lib\")\n\n// for PathAppend\n#include <Shlwapi.h>\n#pragma comment(lib, \"Shlwapi.lib\")\n\n#include <stdio.h>\n#include <aclapi.h>\n#include <tchar.h>\n#pragma comment(lib, \"advapi32.lib\") \n\n#include <iostream>\n#include <fstream>\nusing namespace std;\n\nint _tmain(int argc, _TCHAR* argv[])\n{\n DWORD dwRes, dwDisposition;\n PSID pEveryoneSID = NULL;\n PACL pACL = NULL;\n PSECURITY_DESCRIPTOR pSD = NULL;\n EXPLICIT_ACCESS ea;\n SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;\n SID_IDENTIFIER_AUTHORITY SIDAuthNT = SECURITY_NT_AUTHORITY;\n SECURITY_ATTRIBUTES sa;\n\n // Create a well-known SID for the Everyone group.\n if (!AllocateAndInitializeSid(&SIDAuthWorld, 1,\n SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0,\n &pEveryoneSID))\n {\n _tprintf(_T(\"AllocateAndInitializeSid Error %u\\n\"), GetLastError());\n goto Cleanup;\n }\n\n // Initialize an EXPLICIT_ACCESS structure for an ACE.\n // The ACE will allow Everyone access to files & folders you create.\n ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));\n ea.grfAccessPermissions = 0xFFFFFFFF;\n ea.grfAccessMode = SET_ACCESS;\n\n // both folders & files will inherit this ACE\n ea.grfInheritance= CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE;\n ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;\n ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;\n ea.Trustee.ptstrName = (LPTSTR) pEveryoneSID;\n\n // Create a new ACL that contains the new ACEs.\n dwRes = SetEntriesInAcl(1, &ea, NULL, &pACL);\n if (ERROR_SUCCESS != dwRes)\n {\n _tprintf(_T(\"SetEntriesInAcl Error %u\\n\"), GetLastError());\n goto Cleanup;\n }\n\n // Initialize a security descriptor.\n pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);\n if (NULL == pSD)\n {\n _tprintf(_T(\"LocalAlloc Error %u\\n\"), GetLastError());\n goto Cleanup;\n }\n\n if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION))\n {\n _tprintf(_T(\"InitializeSecurityDescriptor Error %u\\n\"), GetLastError());\n goto Cleanup;\n }\n\n // Add the ACL to the security descriptor.\n if (!SetSecurityDescriptorDacl(pSD,\n TRUE, // bDaclPresent flag\n pACL,\n FALSE)) // not a default DACL\n {\n _tprintf(_T(\"SetSecurityDescriptorDacl Error %u\\n\"), GetLastError());\n goto Cleanup;\n }\n\n // Initialize a security attributes structure.\n sa.nLength = sizeof(SECURITY_ATTRIBUTES);\n sa.lpSecurityDescriptor = pSD;\n sa.bInheritHandle = FALSE;\n\n\n\n TCHAR szPath[MAX_PATH];\n\n if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, szPath))) \n {\n PathAppend(szPath, TEXT(\"Your Shared Folder\"));\n\n if (!CreateDirectory(szPath, &sa)\n && GetLastError() != ERROR_ALREADY_EXISTS) \n {\n goto Cleanup;\n }\n\n PathAppend(szPath, TEXT(\"textitup.txt\"));\n\n HANDLE hFile = CreateFile(szPath, GENERIC_READ | GENERIC_WRITE, 0, &sa, CREATE_ALWAYS, 0, 0);\n if (hFile == INVALID_HANDLE_VALUE)\n goto Cleanup;\n else\n CloseHandle(hFile);\n\n //TODO: do the writing\n ofstream fsOut;\n fsOut.exceptions(ios::eofbit | ios::failbit | ios::badbit);\n fsOut.open(szPath, ios::out | ios::binary | ios::trunc);\n\n fsOut << \"Hello world!\\n\";\n fsOut.close();\n }\n\nCleanup:\n\n if (pEveryoneSID) \n FreeSid(pEveryoneSID);\n if (pACL) \n LocalFree(pACL);\n if (pSD) \n LocalFree(pSD);\n\n return 0;\n}\n" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/147016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20208/" ]
147,033
<p>When you create a new web user control in visual studio it by default adds the Page_Load event. What is the advantage to using this rather than overriding the base <code>OnLoad</code> event on the control? Is it just that the <code>Page_Load</code> event fires before <code>OnLoad</code>?</p>
[ { "answer_id": 147042, "author": "Adrian Clark", "author_id": 148, "author_profile": "https://Stackoverflow.com/users/148", "pm_score": 4, "selected": true, "text": "OnLoad" }, { "answer_id": 147077, "author": "Christoffer Lette", "author_id": 11808, "author_profile": "https://Stackoverflow.com/users/11808", "pm_score": 0, "selected": false, "text": "UserControl" } ]
2008/09/28
[ "https://Stackoverflow.com/questions/147033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2975/" ]
147,040
<p>Is there a way to have Visual Studio 2008 automatically add heading information to files? For example, "Copyright 2008" or something along those lines. I've been digging through the options, but nothing seems to be jumping out at me.</p>
[ { "answer_id": 147043, "author": "TheSoftwareJedi", "author_id": 18941, "author_profile": "https://Stackoverflow.com/users/18941", "pm_score": 3, "selected": true, "text": "%ProgramFiles%\\Microsoft Visual Studio 9.0\\Common7\\IDE\\ItemTemplates\\CSharp\\Code\\1033\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147040", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1880/" ]
147,049
<p>In other words, is it correct to use:</p> <pre><code>public class CustomerList : System.Collections.Generic.List&lt;Customer&gt; { /// supposed to be empty } </code></pre> <p>instead of:</p> <pre><code>using CustomerList = System.Collections.Generic.List&lt;Customer&gt; </code></pre> <p>I'd rather use the first approach because I'd just define CustomerList once, and every time I needed a customer list I'd always use the same type. On the other hand, using the name aliasing approach not only forces me to have to redefine it everywhere, but also a different alias could be given every time someone wanted to use it (think of a big team), and thus cause the code to be less readable.</p> <p>Please note that the intention in this case would never be to extend the class, just to create an alias.</p>
[ { "answer_id": 147060, "author": "Ed S.", "author_id": 1053, "author_profile": "https://Stackoverflow.com/users/1053", "pm_score": 4, "selected": false, "text": "List<Customer> customerList = new List<Customer>();\n" }, { "answer_id": 147068, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 1, "selected": false, "text": "List<Customer>" }, { "answer_id": 147069, "author": "Dr8k", "author_id": 6014, "author_profile": "https://Stackoverflow.com/users/6014", "pm_score": 1, "selected": false, "text": "List<Customer> customerList = new List<Customer>();\n" }, { "answer_id": 147682, "author": "Hallgrim", "author_id": 15454, "author_profile": "https://Stackoverflow.com/users/15454", "pm_score": 4, "selected": true, "text": "List<Customer> \n" }, { "answer_id": 148009, "author": "Robert Paulson", "author_id": 14033, "author_profile": "https://Stackoverflow.com/users/14033", "pm_score": 2, "selected": false, "text": "List<Customer>" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7839/" ]
147,053
<p>I'm creating a new mail item, in C# VS-2008 outlook 2007, and attaching a file. The first issue is that I don't see an attachment area under the subject line showing the attachment. If I send the e-mail its properties show that there is an attachment and the e-mail size has grown by the attachment amount. I just cannot see it or extract the attachment.</p> <p>Here is the code I'm using:</p> <pre><code>Outlook.MailItem mailItem = (Outlook.MailItem)this.Application.CreateItem(Outlook.OlItemType.olMailItem); attachments.Add(ReleaseForm.ZipFile, Outlook.OlAttachmentType.olByValue, 0, "DisplayName"); </code></pre> <p>I am expecting the part "DisplayName" would show as the attachment name and I should be using the filename.</p> <p>I don't call .Send() on the e-mail programmatically, I call mailItem.Display(true) to show the e-mail to the user for any final edits. At this point I can look at the properties and see that there is an attachment there.</p> <p>If I press send (sending to myself) I see the same thing, the attachment appears to be there but not accessible.</p>
[ { "answer_id": 147188, "author": "John Dyer", "author_id": 2862, "author_profile": "https://Stackoverflow.com/users/2862", "pm_score": 2, "selected": false, "text": "attachments.Add(ReleaseForm.ZipFile, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);\n" }, { "answer_id": 46370776, "author": "Nik", "author_id": 7159784, "author_profile": "https://Stackoverflow.com/users/7159784", "pm_score": 0, "selected": false, "text": "attachments.Add(path, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2862/" ]
147,057
<p>I am programming a UNIX shell and I have to use the <code>execv()</code> system call to create a process. One of the parameters for <code>execv()</code> is the filepath for the executable. So if somebody types in <code>/bin/ls</code>, it will run the <code>ls</code> executable. But what I need is a function such that when <code>ls</code> is typed, it will search for the filepath of <code>ls</code> (like the <code>which</code> command). Is there a function which allows me to do that?</p> <p>Unfortunately, this is a school project and I am not allowed to use <code>execvp()</code>. I need to implement some path searching function and then add that filepath to the <code>execv()</code> parameter.</p>
[ { "answer_id": 147064, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 0, "selected": false, "text": "execvp" }, { "answer_id": 147073, "author": "mhawke", "author_id": 21945, "author_profile": "https://Stackoverflow.com/users/21945", "pm_score": 0, "selected": false, "text": " The functions execlp() and execvp() will duplicate the actions of the\n shell in searching for an executable file if the specified filename\n does not contain a slash (/) character. The search path is the path\n specified in the environment by the PATH variable. If this variable\n isn’t specified, the default path ‘‘:/bin:/usr/bin’’ is used. In addi-\n tion, certain errors are treated specially.\n" }, { "answer_id": 147076, "author": "spiv", "author_id": 22701, "author_profile": "https://Stackoverflow.com/users/22701", "pm_score": 2, "selected": false, "text": "execvp" }, { "answer_id": 147081, "author": "Terence Simpson", "author_id": 22395, "author_profile": "https://Stackoverflow.com/users/22395", "pm_score": 2, "selected": false, "text": "char** environ" }, { "answer_id": 148655, "author": "Steve Baker", "author_id": 13566, "author_profile": "https://Stackoverflow.com/users/13566", "pm_score": 4, "selected": false, "text": "PATH = getenv(\"PATH\")" }, { "answer_id": 151324, "author": "mhawke", "author_id": 21945, "author_profile": "https://Stackoverflow.com/users/21945", "pm_score": 2, "selected": false, "text": "access()" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
147,084
<p>Sorry for the second newbie question, I'm a developer not a sysadmin so this is all quite new to me. I hope I can explain myself clearly! Here goes.</p> <p>Here's what I did:</p> <ul> <li><p><strong>Logged into the root account</strong></p></li> <li><p>Created the accounts 'richard' and 'austin'</p></li> <li><p>Created the group 'developers', and added 'richard' and 'austin' to it</p></li> <li><p>Created the directory /server, and used "chown richard:developers /server" to change the owner</p></li> <li><p>Changed the permissions of /server to drwxrwxr-x (so the group can write to it)</p></li> <li><p><strong>Logged out of the root account, and into the 'richard' account</strong></p></li> <li><p>Created the directories /server/production and /server/staging</p></li> <li><p>Used "ls -l" inside /server to list the contents, and found permissions of drwxr-xr-x and ownership of "richard:richard" for both /server/production and /server/staging. Consequently, 'austin' can edit inside the /server directory, but not inside the directories 'richard' created.</p></li> </ul> <p>What am I doing wrong? I want to ensure that any files or folders created inside the /server directory have group write permissions and belong to the developers group. How do I go about that?</p> <p>Thanks for any help!</p>
[ { "answer_id": 147101, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 1, "selected": false, "text": "sudo chown richard:developers\nsudo chmod 775\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/326176/" ]
147,100
<p>I want to take html, including the text and images and turn it into one image containing everything. Is there a free way to do it?</p> <p>This is using .net 3.5.</p> <h3>See also:</h3> <p><a href="https://stackoverflow.com/questions/119116/server-generated-web-screenshots">Server Generated web screenshots?</a><br /> <a href="https://stackoverflow.com/questions/65078/what-is-the-best-way-to-create-a-web-page-thumbnail">What is the best way to create a web page thumbnail?</a></p>
[ { "answer_id": 151552, "author": "Chris Pietschmann", "author_id": 7831, "author_profile": "https://Stackoverflow.com/users/7831", "pm_score": 2, "selected": false, "text": "public Bitmap GenerateScreenshot(string url)\n{\n // This method gets a screenshot of the webpage\n // rendered at its full size (height and width)\n return GenerateScreenshot(url, -1, -1);\n}\n\npublic Bitmap GenerateScreenshot(string url, int width, int height)\n{\n // Load the webpage into a WebBrowser control\n WebBrowser wb = new WebBrowser();\n wb.ScrollBarsEnabled = false;\n wb.ScriptErrorsSuppressed = true;\n wb.Navigate(url);\n while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }\n\n\n // Set the size of the WebBrowser control\n wb.Width = width;\n wb.Height = height;\n\n if (width == -1)\n {\n // Take Screenshot of the web pages full width\n wb.Width = wb.Document.Body.ScrollRectangle.Width;\n }\n\n if (height == -1)\n {\n // Take Screenshot of the web pages full height\n wb.Height = wb.Document.Body.ScrollRectangle.Height;\n }\n\n // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control\n Bitmap bitmap = new Bitmap(wb.Width, wb.Height);\n wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));\n wb.Dispose();\n\n return bitmap;\n}\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10102/" ]
147,129
<p><strong>Is there a better way of binding a list of base class to a UI other than downcasting e.g:</strong></p> <pre><code>static void Main(string[] args) { List&lt;Animal&gt; list = new List&lt;Animal&gt;(); Pig p = new Pig(5); Dog d = new Dog("/images/dog1.jpg"); list.Add(p); list.Add(d); foreach (Animal a in list) { DoPigStuff(a as Pig); DoDogStuff(a as Dog); } } static void DoPigStuff(Pig p) { if (p != null) { label1.Text = String.Format("The pigs tail is {0}", p.TailLength); } } static void DoDogStuff(Dog d) { if (d != null) { Image1.src = d.Image; } } class Animal { public String Name { get; set; } } class Pig : Animal{ public int TailLength { get; set; } public Pig(int tailLength) { Name = "Mr Pig"; TailLength = tailLength; } } class Dog : Animal { public String Image { get; set; } public Dog(String image) { Name = "Mr Dog"; Image = image; } } </code></pre>
[ { "answer_id": 147139, "author": "Dan Herbert", "author_id": 392, "author_profile": "https://Stackoverflow.com/users/392", "pm_score": 3, "selected": false, "text": "public class Animal\n{\n public abstract void DoStuff();\n}\n\npublic Dog : Animal\n{\n public override void DoStuff()\n {\n // Do dog specific stuff here\n }\n}\n\npublic Pig : Animal\n{\n public override void DoStuff()\n {\n // Do pig specific stuff here\n }\n}\n" }, { "answer_id": 147383, "author": "jop", "author_id": 11830, "author_profile": "https://Stackoverflow.com/users/11830", "pm_score": 2, "selected": false, "text": "if (animal is Pig) DoPigStuff();\nif (animal is Dog) DoDogStuff();\n" }, { "answer_id": 147407, "author": "Jacob Krall", "author_id": 3140, "author_profile": "https://Stackoverflow.com/users/3140", "pm_score": 4, "selected": true, "text": "interface IVisitor\n{\n void DoPigStuff(Piggy p);\n void DoDogStuff(Doggy d);\n}\n\nclass GuiVisitor : IVisitor\n{\n void DoPigStuff(Piggy p)\n {\n label1.Text = String.Format(\"The pigs tail is {0}\", p.TailLength);\n }\n\n void DoDogStuff(Doggy d)\n {\n Image1.src = d.Image;\n }\n}\n\nabstract class Animal\n{\n public String Name { get; set; }\n public abstract void Visit(IVisitor visitor);\n}\n\nclass Piggy : Animal\n{\n public int TailLength { get; set; }\n\n public Piggy(int tailLength) \n {\n Name = \"Mr Pig\";\n TailLength = tailLength;\n }\n\n public void Visit(IVisitor visitor)\n {\n visitor.DoPigStuff(this);\n }\n}\n\nclass Doggy : Animal \n{\n public String Image { get; set; }\n\n public Doggy(String image) \n {\n Name = \"Mr Dog\";\n Image = image;\n }\n\n public void Visit(IVisitor visitor)\n {\n visitor.DoDogStuff(this);\n }\n}\n\npublic class AnimalProgram\n{\n static void Main(string[] args) {\n List<Animal> list = new List<Animal>(); \n Pig p = new Pig(5); \n Dog d = new Dog(\"/images/dog1.jpg\"); \n list.Add(p); \n list.Add(d);\n\n IVisitor visitor = new GuiVisitor(); \n foreach (Animal a in list) \n {\n a.Visit(visitor);\n } \n }\n}\n" }, { "answer_id": 147470, "author": "Hallgrim", "author_id": 15454, "author_profile": "https://Stackoverflow.com/users/15454", "pm_score": 0, "selected": false, "text": "Dictionary<Func<Animal, bool>, Func<Animal, AnimalView>> factories;\nfactories.Add(item => item is Dog, item => new DogView(item as Dog));\nfactories.Add(item => item is Pig, item => new PigView(item as Pig));\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1736/" ]
147,130
<p>I'm not asking this question because of the merits of garbage collection first of all. My main reason for asking this is that I do know that Bjarne Stroustrup has said that C++ will have a garbage collector at some point in time.</p> <p>With that said, why hasn't it been added? There are already some garbage collectors for C++. Is this just one of those "easier said than done" type things? Or are there other reasons it hasn't been added (and won't be added in C++11)?</p> <p>Cross links:</p> <ul> <li><a href="https://stackoverflow.com/questions/81062/garbage-collectors-for-c">Garbage collectors for C++</a></li> </ul> <p>Just to clarify, I understand the reasons why C++ didn't have a garbage collector when it was first created. I'm wondering why the collector can't be added in.</p>
[ { "answer_id": 2326748, "author": "Matthieu M.", "author_id": 147192, "author_profile": "https://Stackoverflow.com/users/147192", "pm_score": 7, "selected": false, "text": "Martin Beckett" }, { "answer_id": 19466425, "author": "Aaron McDaid", "author_id": 146041, "author_profile": "https://Stackoverflow.com/users/146041", "pm_score": 4, "selected": false, "text": "void f(int n, int x) {\n Gadget *p = new Gadget{n};\n if(x<100) throw SomeException{};\n if(x<200) return;\n delete p;\n}\n" }, { "answer_id": 48046118, "author": "einpoklum", "author_id": 1593077, "author_profile": "https://Stackoverflow.com/users/1593077", "pm_score": 4, "selected": false, "text": "reintrepret_cast" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147130", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2147/" ]
147,173
<p>I am trying to understand some assembly.</p> <p>The assembly as follows, I am interested in the <code>testl</code> line:</p> <pre><code>000319df 8b4508 movl 0x08(%ebp), %eax 000319e2 8b4004 movl 0x04(%eax), %eax 000319e5 85c0 testl %eax, %eax 000319e7 7407 je 0x000319f0 </code></pre> <p>I am trying to understand that point of <code>testl</code> between <code>%eax</code> and <code>%eax</code>? I think the specifics of what this code isn't important, I am just trying to understand the test with itself - wouldn't the value always be true?</p>
[ { "answer_id": 147176, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 8, "selected": true, "text": "eax" }, { "answer_id": 147183, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": false, "text": "test" }, { "answer_id": 147192, "author": "Nils Pipenbrinck", "author_id": 15955, "author_profile": "https://Stackoverflow.com/users/15955", "pm_score": 5, "selected": false, "text": "cmp eax, 0\nje somewhere\n" }, { "answer_id": 38032818, "author": "Peter Cordes", "author_id": 224132, "author_profile": "https://Stackoverflow.com/users/224132", "pm_score": 5, "selected": false, "text": "test" }, { "answer_id": 41005118, "author": "user7259278", "author_id": 7259278, "author_profile": "https://Stackoverflow.com/users/7259278", "pm_score": 0, "selected": false, "text": "0x080483f4 <main+0>: push ebp\n0x080483f5 <main+1>: mov ebp,esp\n0x080483f7 <main+3>: and esp,0xfffffff0\n0x080483fa <main+6>: sub esp,0x60 \n0x080483fd <main+9>: mov DWORD PTR [esp+0x5c],0x0 ;puts a zero on stack\n0x08048405 <main+17>: lea eax,[esp+0x1c]\n0x08048409 <main+21>: mov DWORD PTR [esp],eax\n0x0804840c <main+24>: call 0x804830c <gets@plt>\n0x08048411 <main+29>: mov eax,DWORD PTR [esp+0x5c] \n0x08048415 <main+33>: test eax,eax ; checks if its zero\n0x08048417 <main+35>: je 0x8048427 <main+51>\n0x08048419 <main+37>: mov DWORD PTR [esp],0x8048500 \n0x08048420 <main+44>: call 0x804832c <puts@plt>\n0x08048425 <main+49>: jmp 0x8048433 <main+63>\n0x08048427 <main+51>: mov DWORD PTR [esp],0x8048529\n0x0804842e <main+58>: call 0x804832c <puts@plt>\n0x08048433 <main+63>: leave\n0x08048434 <main+64>: ret\n" }, { "answer_id": 42780193, "author": "cbei_you", "author_id": 7622541, "author_profile": "https://Stackoverflow.com/users/7622541", "pm_score": -1, "selected": false, "text": "testl %edx,%edx. jle .L3" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10733/" ]
147,178
<p>Suppose I have a date, i.e. year, month and day, as integers. What's a good (correct), concise and fairly readable algorithm for computing the <a href="http://en.wikipedia.org/wiki/ISO_8601" rel="noreferrer">ISO 8601</a> <a href="http://en.wikipedia.org/wiki/ISO_week_date" rel="noreferrer">week number</a> of the week the given date falls into? I have come across some truly horrendous code that makes me think surely there must be a better way.</p> <p>I'm looking to do this in Java but psuedocode for any kind of object-oriented language is fine.</p>
[ { "answer_id": 147815, "author": "skaffman", "author_id": 21234, "author_profile": "https://Stackoverflow.com/users/21234", "pm_score": 3, "selected": false, "text": "* four digit weekyear, see rules below\n* two digit week of year, from 01 to 53\n* one digit day of week, from 1 to 7 where 1 is Monday and 7 is Sunday\n* two digit hour, from 00 to 23\n* two digit minute, from 00 to 59\n* two digit second, from 00 to 59\n* three decimal places for milliseconds if required\n" }, { "answer_id": 736110, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "use POSIX qw(mktime);\nuse Time::localtime;\n\nsub monday_of_week {\n my $year=shift;\n my $week=shift;\n my $p_date=shift;\n\n my $seconds_1_jan=mktime(0,0,0,1,0,$year-1900,0,0,0);\n my $t1=localtime($seconds_1_jan);\n my $seconds_for_week;\n if (@$t1[6] < 5) {\n#first of january is a thursday (or below)\n $seconds_for_week=$seconds_1_jan+3600*24*(7*($week-1)-@$t1[6]+1);\n } else {\n $seconds_for_week=$seconds_1_jan+3600*24*(7*($week-1)-@$t1[6]+8);\n }\n my $wt=localtime($seconds_for_week);\n $$p_date=sprintf(\"%02d/%02d/%04d\",@$wt[3],@$wt[4]+1,@$wt[5]+1900);\n}\n" }, { "answer_id": 20199492, "author": "DoctorBug", "author_id": 232423, "author_profile": "https://Stackoverflow.com/users/232423", "pm_score": 4, "selected": false, "text": "/* Build a calendar suitable to extract ISO8601 week numbers\n * (see http://en.wikipedia.org/wiki/ISO_8601_week_number) */\nCalendar calendar = Calendar.getInstance();\ncalendar.setMinimalDaysInFirstWeek(4);\ncalendar.setFirstDayOfWeek(Calendar.MONDAY);\n\n/* Set date */\ncalendar.setTime(date);\n\n/* Get ISO8601 week number */\ncalendar.get(Calendar.WEEK_OF_YEAR);\n" }, { "answer_id": 23838302, "author": "Mike Gleason", "author_id": 2569885, "author_profile": "https://Stackoverflow.com/users/2569885", "pm_score": 2, "selected": false, "text": "$ TZ=UTC /usr/bin/date --date=\"2010-01-01 12:34:56\" \"+%a %b %d %T %Z %%Y=%Y,%%G=%G %%W=%W,%%V=%V %s\"\nFri Jan 01 12:34:56 UTC %Y=2010,%G=2009 %W=00,%V=53 1262349296\n" }, { "answer_id": 34987052, "author": "Basil Bourque", "author_id": 642706, "author_profile": "https://Stackoverflow.com/users/642706", "pm_score": 5, "selected": false, "text": "LocalDate.of( 2015 , 12 , 30 )\n .get ( \n IsoFields.WEEK_OF_WEEK_BASED_YEAR \n )\n" }, { "answer_id": 35181080, "author": "istovatis", "author_id": 1675670, "author_profile": "https://Stackoverflow.com/users/1675670", "pm_score": 2, "selected": false, "text": "Calendar calendar = Calendar.getInstance();\ncalendar.setMinimalDaysInFirstWeek(4);\ncalendar.setFirstDayOfWeek(Calendar.MONDAY);\ncalendar.setTime(date);\n\n// Now you are ready to take the week of year.\ncalendar.get(Calendar.WEEK_OF_YEAR);\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9511/" ]
147,181
<p>If I have a Java source file (*.java) or a class file (*.class), how can I convert it to a .exe file?</p> <p>I also need an installer for my program.</p>
[ { "answer_id": 147233, "author": "Jay", "author_id": 20840, "author_profile": "https://Stackoverflow.com/users/20840", "pm_score": 10, "selected": true, "text": "javapackager" }, { "answer_id": 18290528, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "start javaw -jar JarFile.jar\n" }, { "answer_id": 67789213, "author": "DuncG", "author_id": 4712734, "author_profile": "https://Stackoverflow.com/users/4712734", "pm_score": 3, "selected": false, "text": "javapackager" }, { "answer_id": 70576590, "author": "Phil Freihofner", "author_id": 805007, "author_profile": "https://Stackoverflow.com/users/805007", "pm_score": 1, "selected": false, "text": "jpackage" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22634/" ]
147,184
<p>What web app architecture works well receiving/sending SMS text messages? By "architecture, I mean specific architecture, not generally, such as MVC.</p> <p>Background: I'm building a web app that receives queries from/sends answers to cell phones. The app design (and business model) expects to communicate with cell devices via SMS text messages. IOW: There is no MVC web page "view". The cell phone screen is effectively the "view".</p>
[ { "answer_id": 147381, "author": "Andrew", "author_id": 17408, "author_profile": "https://Stackoverflow.com/users/17408", "pm_score": 2, "selected": false, "text": "Cellphone -> Cellular Network -> Gateway -> Your Service" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23306/" ]
147,187
<p>What is the practical benefit of using HTTP GET, PUT, DELETE, POST, HEAD? Why not focus on their behavioral benefits (safety and idempotency), forgetting their names, and use GET, PUT or POST depending on which behavior we want?</p> <p><strong>Why shouldn't we only use GET, PUT and POST (and drop HEAD, DELETE)?</strong></p>
[ { "answer_id": 245900, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 1, "selected": false, "text": "-I" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14731/" ]
147,207
<p>I'm wondering how you'd implement the following use-case in REST. Is it even possible to do without compromising the conceptual model?</p> <p>Read or update multiple resources within the scope of a single transaction. For example, transfer $100 from Bob's bank account into John's account.</p> <p>As far as I can tell, the only way to implement this is by cheating. You could POST to the resource associated with either John or Bob and carry out the entire operation using a single transaction. As far as I'm concerned this breaks the REST architecture because you're essentially tunneling an RPC call through POST instead of really operating on individual resources.</p>
[ { "answer_id": 147248, "author": "TheSoftwareJedi", "author_id": 18941, "author_profile": "https://Stackoverflow.com/users/18941", "pm_score": 4, "selected": false, "text": "http://service/transaction (some sort of tx request)\nhttp://service/bankaccount/bob (give tx id)\nhttp://service/bankaccount/john (give tx id)\nhttp://service/transaction (request to commit)\n" }, { "answer_id": 3887530, "author": "Phasmal", "author_id": 453373, "author_profile": "https://Stackoverflow.com/users/453373", "pm_score": 1, "selected": false, "text": "<url-base>/account/a" }, { "answer_id": 4741696, "author": "Jon Watte", "author_id": 89233, "author_profile": "https://Stackoverflow.com/users/89233", "pm_score": 6, "selected": false, "text": "POST /transfer/txn\n{\"source\":\"john's account\", \"destination\":\"bob's account\", \"amount\":10}\n\n{\"id\":\"/transfer/txn/12345\", \"state\":\"pending\", \"source\":...}\n" }, { "answer_id": 5533350, "author": "Tuckster", "author_id": 690368, "author_profile": "https://Stackoverflow.com/users/690368", "pm_score": 5, "selected": false, "text": "POST /transaction\n" }, { "answer_id": 8499518, "author": "13ren", "author_id": 50979, "author_profile": "https://Stackoverflow.com/users/50979", "pm_score": 4, "selected": false, "text": "/transaction" }, { "answer_id": 33210839, "author": "Martin Kersten", "author_id": 2695344, "author_profile": "https://Stackoverflow.com/users/2695344", "pm_score": 2, "selected": false, "text": "POST: accounts/alice, new Transfer {target:\"BOB\", abmount:100, currency:\"CHF\"}.\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14731/" ]
147,208
<p>Is there a way to hide table rows without affecting the overall table width? I've got some javascript that shows/hides some table rows, but when the rows are set to <code>display: none;</code>, the table with shrinks to fit the contents of the visible rows.</p>
[ { "answer_id": 147216, "author": "levik", "author_id": 4465, "author_profile": "https://Stackoverflow.com/users/4465", "pm_score": 4, "selected": true, "text": "table.style.width = table.clientWidth + \"px\";\ntable.rows[3].style.display = \"none\";\n" }, { "answer_id": 147288, "author": "Wilco", "author_id": 5291, "author_profile": "https://Stackoverflow.com/users/5291", "pm_score": 2, "selected": false, "text": "$('#tableId').width($('#tableId').width());\n" }, { "answer_id": 148630, "author": "pcorcoran", "author_id": 15992, "author_profile": "https://Stackoverflow.com/users/15992", "pm_score": 2, "selected": false, "text": "table-layout: fixed;" }, { "answer_id": 314418, "author": "labilbe", "author_id": 1195872, "author_profile": "https://Stackoverflow.com/users/1195872", "pm_score": 0, "selected": false, "text": "<table border=\"1\">\n <colgroup>\n <col width=\"150px\" />\n <col width=\"10px\" />\n <col width=\"220px\" />\n </colgroup>\n <tr>\n <td valign=\"top\">1</td>\n <td> </td>\n <td>2</td>\n </tr>\n <tr>\n <td>3</td>\n <td> </td>\n <td>4</td>\n </tr>\n</table>" }, { "answer_id": 55048215, "author": "Klesun", "author_id": 2750743, "author_profile": "https://Stackoverflow.com/users/2750743", "pm_score": 3, "selected": false, "text": "visibility: collapse" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5291/" ]
147,210
<p>I have a T-SQL <strong>table variable</strong> (not a table) which has an auto incrementing identity column. I want to clear all data from this variable and reset the identity column value to 1. How can this be done?</p>
[ { "answer_id": 147224, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 5, "selected": false, "text": "DBCC CHECKIDENT (yourtableName, reseed, @NewStartSeedValue)\n" }, { "answer_id": 147356, "author": "Josef", "author_id": 5581, "author_profile": "https://Stackoverflow.com/users/5581", "pm_score": 6, "selected": true, "text": "DBCC CHECKIDENT" }, { "answer_id": 7923516, "author": "user1017467", "author_id": 1017467, "author_profile": "https://Stackoverflow.com/users/1017467", "pm_score": -1, "selected": false, "text": "declare @myTbl (...)" }, { "answer_id": 24615938, "author": "Lauren Glenn", "author_id": 2092959, "author_profile": "https://Stackoverflow.com/users/2092959", "pm_score": 0, "selected": false, "text": " declare @tb table (recid int,lineof int identity(1,1))\n\n insert into @tb(recid)\n select recid from tabledata \n\n delete from @tb where lineof>(select min(lineof) from @tb)+@maxlimit\n" }, { "answer_id": 28145013, "author": "Pavlo Carerra", "author_id": 4493671, "author_profile": "https://Stackoverflow.com/users/4493671", "pm_score": 1, "selected": false, "text": "Insert into @Table2 from @Table1\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/747/" ]
147,240
<pre><code>('1' * N) !~ /^1?$|^(11+?)\1+$/ </code></pre> <p>On the net, I found this piece of Ruby code that works for N >= 0 that determines whether or not N is a prime. From what I can tell, it looks like play with regex but I have no idea how it works. Could someone tell me how it works?</p>
[ { "answer_id": 147832, "author": "Markus Jarderot", "author_id": 22364, "author_profile": "https://Stackoverflow.com/users/22364", "pm_score": 1, "selected": false, "text": "/^(1+)\\1*=\\1+$/.match('1' * x + '=' + '1' * y)[1].length\n" }, { "answer_id": 2088790, "author": "Trevoke", "author_id": 234025, "author_profile": "https://Stackoverflow.com/users/234025", "pm_score": 4, "selected": false, "text": " require 'mathn'\n 38749711234868463.prime?\n => false\n" }, { "answer_id": 4174637, "author": "Ming-Tang", "author_id": 303939, "author_profile": "https://Stackoverflow.com/users/303939", "pm_score": 1, "selected": false, "text": "/(1{2,}){2,}/" }, { "answer_id": 22780847, "author": "rajagopal", "author_id": 3484256, "author_profile": "https://Stackoverflow.com/users/3484256", "pm_score": 2, "selected": false, "text": "require 'prime'\n\nPrime.prime?(4)\n# => false\n\nPrime.prime?(5)\n# => true\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
147,267
<p>Here's what I am trying to do: </p> <pre><code>typedef enum { ONE, TWO, THREE } Numbers; </code></pre> <p>I am trying to write a function that would do a switch case similar to the following: </p> <pre><code>char num_str[10]; int process_numbers_str(Numbers num) { switch(num) { case ONE: case TWO: case THREE: { strcpy(num_str, num); //some way to get the symbolic constant name in here? } break; default: return 0; //no match return 1; } </code></pre> <p>Instead of defining at every case, is there a way to set it using the enum variable like I am trying to do above?</p>
[ { "answer_id": 147283, "author": "sk.", "author_id": 16399, "author_profile": "https://Stackoverflow.com/users/16399", "pm_score": 5, "selected": true, "text": "char*" }, { "answer_id": 147347, "author": "paxdiablo", "author_id": 14860, "author_profile": "https://Stackoverflow.com/users/14860", "pm_score": 3, "selected": false, "text": "typedef enum { ONE, TWO, THREE } Numbers;\nchar *strNumbers[] = {\"one\",\"two\",\"three\"};\nprintf (\"Value for TWO is %s\\n\",strNumbers[TWO]);\n" }, { "answer_id": 147492, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 1, "selected": false, "text": "/*\n@(#)File: $RCSfile: paste1.h,v $\n@(#)Version: $Revision: 1.1 $\n@(#)Last changed: $Date: 2008/05/17 21:38:05 $\n@(#)Purpose: Automated Token Pasting\n*/\n\n#ifndef JLSS_ID_PASTE_H\n#define JLSS_ID_PASTE_H\n\n/*\n * Common case when someone just includes this file. In this case,\n * they just get the various E* tokens as good old enums.\n */\n#if !defined(ETYPE)\n#define ETYPE(val, desc) E##val,\n#define ETYPE_ENUM\nenum {\n#endif /* ETYPE */\n\n ETYPE(PERM, \"Operation not permitted\")\n ETYPE(NOENT, \"No such file or directory\")\n ETYPE(SRCH, \"No such process\")\n ETYPE(INTR, \"Interrupted system call\")\n ETYPE(IO, \"I/O error\")\n ETYPE(NXIO, \"No such device or address\")\n ETYPE(2BIG, \"Arg list too long\")\n\n/*\n * Close up the enum block in the common case of someone including\n * this file.\n */\n#if defined(ETYPE_ENUM)\n#undef ETYPE_ENUM\n#undef ETYPE\nETYPE_MAX\n};\n#endif /* ETYPE_ENUM */\n\n#endif /* JLSS_ID_PASTE_H */\n" }, { "answer_id": 147582, "author": "Bill Forster", "author_id": 3955, "author_profile": "https://Stackoverflow.com/users/3955", "pm_score": 6, "selected": false, "text": "// Define your enumeration like this (in say numbers.h);\nENUM_BEGIN( Numbers )\n ENUM(ONE),\n ENUM(TWO),\n ENUM(FOUR)\nENUM_END( Numbers )\n\n// The macros are defined in a more fundamental .h file (say defs.h);\n#define ENUM_BEGIN(typ) enum typ {\n#define ENUM(nam) nam\n#define ENUM_END(typ) };\n\n// Now in one and only one .c file, redefine the ENUM macros and reinclude\n// the numbers.h file to build a string table\n#undef ENUM_BEGIN\n#undef ENUM\n#undef ENUM_END\n#define ENUM_BEGIN(typ) const char * typ ## _name_table [] = {\n#define ENUM(nam) #nam\n#define ENUM_END(typ) };\n#undef NUMBERS_H_INCLUDED // whatever you need to do to enable reinclusion\n#include \"numbers.h\"\n\n// Now you can do exactly what you want to do, with no retyping, and for any\n// number of enumerated types defined with the ENUM macro family\n// Your code follows;\nchar num_str[10];\nint process_numbers_str(Numbers num) {\n switch(num) {\n case ONE:\n case TWO:\n case THREE:\n {\n strcpy(num_str, Numbers_name_table[num]); // eg TWO -> \"TWO\"\n } break;\n default:\n return 0; //no match\n return 1;\n}\n\n// Sweet no ? After being frustrated by this for years, I finally came up\n// with this solution for my most recent project and plan to reuse the idea\n// forever\n" }, { "answer_id": 148610, "author": "JayG", "author_id": 5823, "author_profile": "https://Stackoverflow.com/users/5823", "pm_score": 4, "selected": false, "text": " // Source data -- Enum, String\n #define X_NUMBERS \\\n X(ONE, \"one\") \\\n X(TWO, \"two\") \\\n X(THREE, \"three\")\n\n ...\n\n // Use preprocessor to create the Enum\n typedef enum {\n #define X(Enum, String) Enum,\n X_NUMBERS\n #undef X\n } Numbers;\n\n ...\n\n // Use Preprocessor to expand data into switch statement cases\n switch(num)\n {\n #define X(Enum, String) \\\n case Enum: strcpy(num_str, String); break;\n X_NUMBERS\n #undef X\n\n default: return 0; break;\n }\n return 1;\n" }, { "answer_id": 148714, "author": "plinth", "author_id": 20481, "author_profile": "https://Stackoverflow.com/users/20481", "pm_score": 3, "selected": false, "text": "#define MACROSTR(k) #k\n\ntypedef enum {\n kZero,\n kOne,\n kTwo,\n kThree\n} kConst;\n\nstatic char *kConstStr[] = {\n MACROSTR(kZero),\n MACROSTR(kOne),\n MACROSTR(kTwo),\n MACROSTR(kThree)\n};\n\nstatic void kConstPrinter(kConst k)\n{\n printf(\"%s\", kConstStr[k]);\n}\n" }, { "answer_id": 202511, "author": "Suma", "author_id": 16673, "author_profile": "https://Stackoverflow.com/users/16673", "pm_score": 6, "selected": false, "text": "// expansion macro for enum value definition\n#define ENUM_VALUE(name,assign) name assign,\n\n// expansion macro for enum to string conversion\n#define ENUM_CASE(name,assign) case name: return #name;\n\n// expansion macro for string to enum conversion\n#define ENUM_STRCMP(name,assign) if (!strcmp(str,#name)) return name;\n\n/// declare the access function and define enum values\n#define DECLARE_ENUM(EnumType,ENUM_DEF) \\\n enum EnumType { \\\n ENUM_DEF(ENUM_VALUE) \\\n }; \\\n const char *GetString(EnumType dummy); \\\n EnumType Get##EnumType##Value(const char *string); \\\n\n/// define the access function names\n#define DEFINE_ENUM(EnumType,ENUM_DEF) \\\n const char *GetString(EnumType value) \\\n { \\\n switch(value) \\\n { \\\n ENUM_DEF(ENUM_CASE) \\\n default: return \"\"; /* handle input error */ \\\n } \\\n } \\\n EnumType Get##EnumType##Value(const char *str) \\\n { \\\n ENUM_DEF(ENUM_STRCMP) \\\n return (EnumType)0; /* handle input error */ \\\n } \\\n" }, { "answer_id": 3180757, "author": "Samuel Danielson", "author_id": 100089, "author_profile": "https://Stackoverflow.com/users/100089", "pm_score": 3, "selected": false, "text": "const char *myenum_str(myenum e)\n{\n switch(e) {\n case ONE: return \"one\";\n case TWO: return \"two\";\n }\n return \"invalid\";\n}\n" }, { "answer_id": 9406109, "author": "Giacomo M.", "author_id": 670589, "author_profile": "https://Stackoverflow.com/users/670589", "pm_score": 2, "selected": false, "text": "#include \"EnumUtilities.h\"\n" }, { "answer_id": 12499645, "author": "daminetreg", "author_id": 271781, "author_profile": "https://Stackoverflow.com/users/271781", "pm_score": 0, "selected": false, "text": "#ifndef SWISSARMYKNIFE_ENUMS_ADAPT_ENUM_HPP\n#define SWISSARMYKNIFE_ENUMS_ADAPT_ENUM_HPP\n\n#include <swissarmyknife/detail/config.hpp>\n\n#include <string>\n#include <ostream>\n#include <boost/preprocessor/cat.hpp>\n#include <boost/preprocessor/stringize.hpp>\n#include <boost/preprocessor/seq/for_each.hpp>\n\n\n#define SWISSARMYKNIFE_ADAPT_ENUM_EACH_ENUMERATION_ENTRY_C( \\\n R, unused, ENUMERATION_ENTRY) \\\n case ENUMERATION_ENTRY: \\\n return BOOST_PP_STRINGIZE(ENUMERATION_ENTRY); \\\n break; \n\n/**\n * \\brief Adapts ENUM to reflectable types.\n *\n * \\param ENUM_TYPE To be adapted\n * \\param ENUMERATION_SEQ Sequence of enum states\n */\n#define SWISSARMYKNIFE_ADAPT_ENUM(ENUM_TYPE, ENUMERATION_SEQ) \\\n inline std::string to_string(const ENUM_TYPE& enum_value) { \\\n switch (enum_value) { \\\n BOOST_PP_SEQ_FOR_EACH( \\\n SWISSARMYKNIFE_ADAPT_ENUM_EACH_ENUMERATION_ENTRY_C, \\\n unused, ENUMERATION_SEQ) \\\n default: \\\n return BOOST_PP_STRINGIZE(ENUM_TYPE); \\\n } \\\n } \\\n \\\n inline std::ostream& operator<<(std::ostream& os, const ENUM_TYPE& value) { \\\n os << to_string(value); \\\n return os; \\\n }\n\n#endif\n" }, { "answer_id": 13188605, "author": "Ben", "author_id": 385273, "author_profile": "https://Stackoverflow.com/users/385273", "pm_score": 1, "selected": false, "text": "#define stringify( name ) # name\n\nenum MyEnum {\n ENUMVAL1\n};\n...stuff...\n\nstringify(EnumName::ENUMVAL1); // Returns MyEnum::ENUMVAL1\n" }, { "answer_id": 17982571, "author": "Robert Husák", "author_id": 2105235, "author_profile": "https://Stackoverflow.com/users/2105235", "pm_score": 0, "selected": false, "text": "streamable_enum" }, { "answer_id": 23342705, "author": "janisj", "author_id": 3581575, "author_profile": "https://Stackoverflow.com/users/3581575", "pm_score": 2, "selected": false, "text": "const char * enum_to_string_map[]={ [enum1]='string1', [enum2]='string2'};\n" }, { "answer_id": 29561365, "author": "Juan Gonzalez Burgos", "author_id": 4622991, "author_profile": "https://Stackoverflow.com/users/4622991", "pm_score": 2, "selected": false, "text": "#define MACROSTR(k) #k\n\n#define X_NUMBERS \\\n X(kZero ) \\\n X(kOne ) \\\n X(kTwo ) \\\n X(kThree ) \\\n X(kFour ) \\\n X(kMax )\n\nenum {\n#define X(Enum) Enum,\n X_NUMBERS\n#undef X\n} kConst;\n\nstatic char *kConstStr[] = {\n#define X(String) MACROSTR(String),\n X_NUMBERS\n#undef X\n};\n\nint main(void)\n{\n int k;\n printf(\"Hello World!\\n\\n\");\n\n for (k = 0; k < kMax; k++)\n {\n printf(\"%s\\n\", kConstStr[k]);\n }\n\n return 0;\n}\n" }, { "answer_id": 55418238, "author": "gerardw", "author_id": 697099, "author_profile": "https://Stackoverflow.com/users/697099", "pm_score": 0, "selected": false, "text": "std::ostream& operator<<(std::ostream& os, provenance_wrapper::CaptureState cs)\n{\n#define HANDLE(x) case x: os << #x; break;\n switch (cs) {\n HANDLE(CaptureState::UNUSED)\n HANDLE(CaptureState::ACTIVE)\n HANDLE(CaptureState::CLOSED)\n }\n return os;\n#undef HANDLE\n}\n" }, { "answer_id": 69697463, "author": "Simon K", "author_id": 13299284, "author_profile": "https://Stackoverflow.com/users/13299284", "pm_score": 0, "selected": false, "text": " #define ENUM_PUSH(ENUM) ENUM,\n #define STRING_PUSH(STR) #STR,\n \n #define FETCH_MSG(X) \\\n X(string1) \\\n X(string2) \\\n \n static const char * msgStr[] = {\n FETCH_MSG(STRING_PUSH)\n };\n \n enum msg {\n FETCH_MSG(ENUM_PUSH)\n };\n \n static enum msg message;\n \n \n void iterate(void) {\n switch (message) {\n case string1:\n// do your thing here\n break;\n case string2:\n break;\n }\n }\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147267", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9628/" ]
147,298
<p>I currently have heavily multi-threaded server application, and I'm shopping around for a good multi-threaded memory allocator.</p> <p>So far I'm torn between:</p> <ul> <li>Sun's umem</li> <li>Google's tcmalloc</li> <li>Intel's threading building blocks allocator</li> <li>Emery Berger's hoard</li> </ul> <p>From what I've found hoard might be the fastest, but I hadn't heard of it before today, so I'm skeptical if its really as good as it seems. Anyone have personal experience trying out these allocators?</p>
[ { "answer_id": 10308055, "author": "Jay D", "author_id": 143897, "author_profile": "https://Stackoverflow.com/users/143897", "pm_score": 2, "selected": false, "text": "light weight Memory manager" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15124/" ]
147,307
<p>The System.Diagnostics.EventLog class provides a way to interact with a windows event log. I use it all the time for simple logging...</p> <pre><code>System.Diagnostics.EventLog.WriteEntry("MyEventSource", "My Special Message") </code></pre> <p>Is there a way to set the user information in the resulting event log entry using .NET?</p>
[ { "answer_id": 159683, "author": "Johan Buret", "author_id": 15366, "author_profile": "https://Stackoverflow.com/users/15366", "pm_score": 4, "selected": true, "text": "DLLImportAttribute" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23303/" ]
147,339
<p>Some of us would invariably have to support 'legacy' code using Microsoft's Visual Studio 6.0 IDEs which - although opinions would differ - are generally regarded to be less user friendly compared to the later incarnations of the Visual Studio series of IDEs.</p> <p>So I'd like to hear about some of your best hidden/poorly documented IDE features (could be for either C++ or VB). As is the usual practice one feature per post, please. </p>
[ { "answer_id": 151634, "author": "Mike Spross", "author_id": 17862, "author_profile": "https://Stackoverflow.com/users/17862", "pm_score": 3, "selected": false, "text": "Collection" }, { "answer_id": 184901, "author": "Nemanja Trifunovic", "author_id": 8899, "author_profile": "https://Stackoverflow.com/users/8899", "pm_score": 3, "selected": false, "text": "@err,hr" }, { "answer_id": 184945, "author": "John Dibling", "author_id": 241536, "author_profile": "https://Stackoverflow.com/users/241536", "pm_score": 3, "selected": false, "text": "C:\\Program Files\\Microsoft Visual Studio\\Common\\MSDev98\\Bin\\AUTOEXP.DAT" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4368/" ]
147,351
<p>In general, what needs to be done to convert a 16 bit Windows program to Win32? I'm sure I'm not the only person to inherit a codebase and be stunned to find 16-bit code lurking in the corners.</p> <p>The code in question is C.</p>
[ { "answer_id": 147538, "author": "Benjamin Pollack", "author_id": 2354, "author_profile": "https://Stackoverflow.com/users/2354", "pm_score": 5, "selected": true, "text": "wParam" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16220/" ]
147,359
<p>I have this function in VB.net "ENCRYPT" (see below)</p> <pre><code>Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24} Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219} Public Function Encrypt(ByVal plainText As String) As Byte() ' Declare a UTF8Encoding object so we may use the GetByte ' method to transform the plainText into a Byte array. Dim utf8encoder As UTF8Encoding = New UTF8Encoding() Dim inputInBytes() As Byte = utf8encoder.GetBytes(plainText) ' Create a new TripleDES service provider Dim tdesProvider As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider() ' The ICryptTransform interface uses the TripleDES ' crypt provider along with encryption key and init vector ' information Dim cryptoTransform As ICryptoTransform = tdesProvider.CreateEncryptor(Me.key, Me.iv) ' All cryptographic functions need a stream to output the ' encrypted information. Here we declare a memory stream ' for this purpose. Dim encryptedStream As MemoryStream = New MemoryStream() Dim cryptStream As CryptoStream = New CryptoStream(encryptedStream, cryptoTransform, CryptoStreamMode.Write) ' Write the encrypted information to the stream. Flush the information ' when done to ensure everything is out of the buffer. cryptStream.Write(inputInBytes, 0, inputInBytes.Length) cryptStream.FlushFinalBlock() encryptedStream.Position = 0 ' Read the stream back into a Byte array and return it to the calling method. Dim result(encryptedStream.Length - 1) As Byte encryptedStream.Read(result, 0, encryptedStream.Length) cryptStream.Close() Return result End Function </code></pre> <p>I want to save the encrypted string in the SQL database. How do I do it?</p>
[ { "answer_id": 147487, "author": "Adrian Clark", "author_id": 148, "author_profile": "https://Stackoverflow.com/users/148", "pm_score": 2, "selected": false, "text": "CREATE TABLE [Test]\n(\n [Id] NOT NULL IDENTITY(1,1) PRIMARY KEY,\n [Username] NOT NULL VARCHAR(500),\n [Password] NOT NULL VARBINARY(500)\n)\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
147,362
<p>Like many companies that require all access be through stored procedures, we seem to have a lot of business logic locked away in sprocs. These things are just plain hard to test, and some of them have become silly long. Does anyone out there have a set of best practices that can make it a little easier to confidently test these things?</p> <p>At present we maintain 30 or so "Problem" databases that we run against. This isn't always particularly well documented and it sure isn't automated.</p>
[ { "answer_id": 181419, "author": "6eorge Jetson", "author_id": 23422, "author_profile": "https://Stackoverflow.com/users/23422", "pm_score": 1, "selected": false, "text": "\nUSE [SpacelySprockets]\nGO\n/****** Object: StoredProcedure [dbo].[uspBrownNoseMrSpacely] Script Date: 02/03/3000 00:24:41 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\n--================================\n--Stored Procedure DDL:\n--================================\n\n--Example Inputs\n/*\nDECLARE @SuckupPloyId int\nDECLARE @SuckupIdentityRecordId int \nSET @SuckupPloyId = 3\n*/\n\n-- =============================================\n-- Author: 6eorge Jetson\n-- Create date: 01/02/3000\n-- Description: Sucks up to the boss\n-- =============================================\nCREATE PROCEDURE [dbo].[uspBrownNoseMrSpacely]\n @SuckupPloyId int\n ,@SuckupIdentityRecordId int OUTPUT \nAS\nBEGIN\n DECLARE @EmployeeId int\n DECLARE @SuckupPoints int\n DECLARE @DateTimeStamp datetime\n\n SET @EmployeeId = dbo.svfGetEmployeeId('6eorge Jetson')\n SET @SuckupPoints = dbo.svfGetSuckupPoints(@SuckupPloyId)\n SET @DateTimeStamp = getdate()\n\n --Data state-changing statement in sproc\n INSERT INTO [dbo].[tblSuckupPointsEarned]([EmployeeId], [SuckupPoints], [DateTimeStamp] )\n VALUES (@EmployeeId, @SuckupPoints, @DateTimeStamp)\n\n SET @SuckupIdentityRecordId = @@Identity\nEND\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1327/" ]
147,364
<p>In one of my ASP.NET Web Applications, I am using a <a href="http://blogs.msdn.com/mattdotson/articles/490868.aspx" rel="nofollow noreferrer">BulkEditGridView</a> (a GridView which allows all rows to be edited at the same time) to implement an order form. In my grid, I have a column which calculates the total for each item (cost x quantity) and a grand total field at the bottom of the page. Currently, however, these fields are only refreshed on every post-back. I need to have these fields updated dynamically so that as users change quantities, the totals and grand total update to reflect the new values. I have attempted to use AJAX solutions to accomplish this, but the asynchronous post-backs interfere with the focus on the page. I imagine that a purely client-side solution exists, and I'm hopeful that someone in the community can share.</p>
[ { "answer_id": 147620, "author": "WebDude", "author_id": 15360, "author_profile": "https://Stackoverflow.com/users/15360", "pm_score": 1, "selected": false, "text": "private string _jscript;\nprotected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)\n{\n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n //Get your textbox\n Textbox tb = e.Row.FindControl(\"tbAddUp\");\n //Add the event that you're going to call to this textbox's attributes\n tb.Attributes.Add(\"onkeyup\", \"MyAddUpJavaScriptMethod();\");\n //Build the javascript for the MyAddUpJavaScriptMethod\n jscript += \"document.getElementById('\" + tb.ClientId + '\").value + \";\n }\n}\n" }, { "answer_id": 148216, "author": "Aaron Powell", "author_id": 11388, "author_profile": "https://Stackoverflow.com/users/11388", "pm_score": 3, "selected": true, "text": "$(\"#myGridView input[type='text']\").each(function(){\n this.change(function(){\n updateTotal(this.value);\n });\n});\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/317/" ]
147,372
<pre><code>#include &lt;vector&gt; std::vector&lt;long int&gt; as; long int a(size_t n){ if(n==1) return 1; if(n==2) return -2; if(as.size()&lt;n+1) as.resize(n+1); if(as[n]&lt;=0) { as[n]=-4*a(n-1)-4*a(n-2); } return mod(as[n], 65535); } </code></pre> <p>The above code sample using memoization to calculate a recursive formula based on some input <code>n</code>. I know that this uses memoization, because I have written a purely recursive function that uses the same formula, but this one much, much faster for much larger values of <code>n</code>. I've never used vectors before, but I've done some research and I understand the concept of them. I understand that memoization is supposed to store each calculated value, so that instead of performing the same calculations over again, it can simply retrieve ones that have already been calculated. </p> <p>My question is: how is this memoization, and how does it work? I can't seem to see in the code at which point it checks to see if a value for n already exists. Also, I don't understand the purpose of the <code>if(as[n]&lt;=0)</code>. This formula can yield positive and negative values, so I'm not sure what this check is looking for.</p> <hr> <p>Thank you, I think I'm close to understanding how this works, it's actually a bit more simple than I was thinking it was.</p> <p>I do not think the values in the sequence can ever be 0, so this should work for me, as I think n has to start at 1. </p> <p>However, if zero was a viable number in my sequence, what is another way I could solve it? For example, what if five could never appear? Would I just need to fill my vector with fives?</p> <p>Edit: Wow, I got a lot of other responses while checking code and typing this one. Thanks for the help everyone, I think I understand it now.</p>
[ { "answer_id": 147374, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 4, "selected": true, "text": "if (as[n] <= 0)" }, { "answer_id": 147410, "author": "Greg Rogers", "author_id": 5963, "author_profile": "https://Stackoverflow.com/users/5963", "pm_score": 0, "selected": false, "text": "if(as[n]<=0)" }, { "answer_id": 147430, "author": "A. Rex", "author_id": 3508, "author_profile": "https://Stackoverflow.com/users/3508", "pm_score": 0, "selected": false, "text": "if(as[n]==0)" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23323/" ]
147,378
<p>So, one commonly heard comment when talking about performance is that you write your code with whatever language gets the job done fastest. If performance in specific areas is a problem, then rewrite those bits in C/C++.</p> <p>But, what if you're starting with a native C++ app? What options do you have if you want to write the easy bits, or refactor the old bits, in a language like Python, Ruby, C#, or whatever? Keep in mind that transferring data between the native and other sides is a must. Being able to simply call a function written in an "easier" language, while passing C++ classes as data, would be beautiful.</p> <p>We've got a crusty Win32 app that would benefit greatly if we could crank out new code, or refactor old code, in C# or something. Very little of it requires the complexity of C++, and dealing with the little fiddly bits is dragging down the programming process. </p>
[ { "answer_id": 147389, "author": "Douglas Mayle", "author_id": 8458, "author_profile": "https://Stackoverflow.com/users/8458", "pm_score": 1, "selected": false, "text": "char const* greet()\n{\n return \"hello, world\";\n}\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147378", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12567/" ]
147,391
<p>I have a program that uses the mt19937 random number generator from boost::random. I need to do a random_shuffle and want the random numbers generated for this to be from this shared state so that they can be deterministic with respect to the mersenne twister's previously generated numbers.</p> <p>I tried something like this:</p> <pre><code>void foo(std::vector&lt;unsigned&gt; &amp;vec, boost::mt19937 &amp;state) { struct bar { boost::mt19937 &amp;_state; unsigned operator()(unsigned i) { boost::uniform_int&lt;&gt; rng(0, i - 1); return rng(_state); } bar(boost::mt19937 &amp;state) : _state(state) {} } rand(state); std::random_shuffle(vec.begin(), vec.end(), rand); } </code></pre> <p>But i get a template error calling random_shuffle with rand. However this works:</p> <pre><code>unsigned bar(unsigned i) { boost::mt19937 no_state; boost::uniform_int&lt;&gt; rng(0, i - 1); return rng(no_state); } void foo(std::vector&lt;unsigned&gt; &amp;vec, boost::mt19937 &amp;state) { std::random_shuffle(vec.begin(), vec.end(), bar); } </code></pre> <p>Probably because it is an actual function call. But obviously this doesn't keep the state from the original mersenne twister. What gives? Is there any way to do what I'm trying to do without global variables?</p>
[ { "answer_id": 147438, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 4, "selected": false, "text": "#include <algorithm>\n#include <functional>\n#include <vector>\n#include <boost/random.hpp>\n\nstruct bar : std::unary_function<unsigned, unsigned> {\n boost::mt19937 &_state;\n unsigned operator()(unsigned i) {\n boost::uniform_int<> rng(0, i - 1);\n return rng(_state);\n }\n bar(boost::mt19937 &state) : _state(state) {}\n};\n\nvoid foo(std::vector<unsigned> &vec, boost::mt19937 &state)\n{\n bar rand(state);\n std::random_shuffle(vec.begin(), vec.end(), rand);\n}\n" }, { "answer_id": 2457636, "author": "baol", "author_id": 295076, "author_profile": "https://Stackoverflow.com/users/295076", "pm_score": 3, "selected": false, "text": "#include <algorithm>\n#include <tr1/random>\n\n\nstd::tr1::mt19937 engine;\nstd::tr1::uniform_int<> unigen;\nstd::tr1::variate_generator<std::tr1::mt19937, \n std::tr1::uniform_int<> >gen(engine, unigen);\nstd::random_shuffle(vec.begin(), vec.end(), gen);\n" }, { "answer_id": 22057817, "author": "Eliot", "author_id": 350761, "author_profile": "https://Stackoverflow.com/users/350761", "pm_score": 1, "selected": false, "text": "#include <random>\n#include <algorithm>\n\nstd::random_device rd;\nstd::mt19937 randEng(rd());\nstd::shuffle(vec.begin(), vec.end(), randEng);\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5963/" ]
147,408
<p>From what I've seen in the past, StackOverflow seems to like programming challenges, such as the <a href="https://stackoverflow.com/questions/69115/char-to-hex-string-exercise">fast char to string exercise problem</a> which got dozens of responses. This is an optimization challenge: take a very simple function and see if you can come up with a smarter way of doing it.</p> <p>I've had a function that I've wanted to further optimize for quite some time but I always find that my optimizations have some hole that result in incorrect output--some rare special case in which they fail. But, given the function, I've always figured one should be able to do better than this.</p> <p>The function takes an input datastream (effectively random bits, from an entropy perspective) and wraps it into a NAL unit. This involves placing escape codes: any byte sequence of 00 00 00, 00 00 01, 00 00 02, or 00 00 03 gets replaced with 00 00 03 XX, where XX is that last byte of the original sequence. As one can guess, these only get placed about 1 in every 4 million bytes of input, given the odds against such a sequence--so this is a challenge where one is <strong>searching an enormous amount of data and doing almost nothing to it</strong> except in very rare cases. However, because "doing something" involves <em>inserting bytes</em>, it makes things a bit trickier. The current unoptimized code is the following C:</p> <p>src and dst are pointers to arrays of bytes, and end is the pointer to the end of the input data.</p> <pre><code>int i_count = 0; while( src &lt; end ) { if( i_count == 2 &amp;&amp; *src &lt;= 0x03 ) { *dst++ = 0x03; i_count = 0; } if( *src == 0 ) i_count++; else i_count = 0; *dst++ = *src++; } </code></pre> <p>Common input sizes to this function range from roughly between 1000 and 1000000 bytes of data.</p> <p>Initial ideas of mine include a function which (somehow) quickly searches the input for situations where an escape code is needed, to avoid more complex logic in the vast majority of inputs where escape codes don't need to be placed.</p> <hr>
[ { "answer_id": 147424, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "#define unlikely(x) __builtin_expect((x),0)\n\nwhile( src < end )\n{\n const char s = *src++;\n if( unlikely(i_count==2 && s<=0x03) )\n {\n *dst++ = 0x03;\n i_count = 0;\n }\n if( unlikely(s==0) )\n i_count++;\n else\n i_count = 0;\n *dst++ = s;\n}\n" }, { "answer_id": 147477, "author": "Dark Shikari", "author_id": 11206, "author_profile": "https://Stackoverflow.com/users/11206", "pm_score": 0, "selected": false, "text": "#define unlikely(x) __builtin_expect((x),0)\nwhile( src < end )\n{\n if( unlikely(i_count == 2) && unlikely(*src <= 0x03) )\n {\n *dst++ = 0x03;\n i_count = 0;\n }\n if( unlikely(*src == 0) )\n i_count++;\n else\n i_count = 0;\n *dst++ = *src++;\n}\n" }, { "answer_id": 147493, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 0, "selected": false, "text": "while (src < end-2)\n{\n if ((src[0] == 0) && (src[1] == 0) && (src[2] <= 3))\n {\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 3;\n dst[3] = src[2];\n src += 3;\n dst += 4;\n }\n else\n *dst++ = *src++;\n}\nwhile (src < end)\n *dst++ = *src++;\n" }, { "answer_id": 147499, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "#define likely(x) __builtin_expect((x),1)\n#define unlikely(x) __builtin_expect((x),0)\n\nwhile( likely(src < end) )\n{\n //Copy non-zero run\n int runlen = strlen( src );\n if( unlikely(src+runlen >= end) )\n {\n memcpy( dest, src, end-src );\n dest += end-src;\n src = end;\n break;\n }\n\n memcpy( dest, src, runlen );\n src += runlen;\n dest += runlen;\n\n //Deal with 0 byte\n if( unlikely(src[1]==0 && src[2]<=3 && src<=end-3) )\n {\n *dest++ = 0;\n *dest++ = 0;\n *dest++ = 3;\n *dest++ = *src++;\n }\n else\n {\n *dest++ = 0;\n src++;\n }\n}\n" }, { "answer_id": 147520, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 0, "selected": false, "text": "while (src < end-2)\n{\n if (src[0] == 0)\n {\n if (src[1] == 0)\n {\n if (src[2] <= 3)\n {\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = 3;\n dst[3] = src[2];\n src += 3;\n dst += 4;\n }\n else\n {\n dst[0] = 0;\n dst[1] = 0;\n dst[2] = src[2];\n src += 3;\n dst += 3;\n }\n }\n else\n {\n dst[0] = 0;\n dst[1] = src[1];\n src += 2;\n dst += 2;\n }\n }\n else\n *dst++ = *src++;\n}\nwhile (src < end)\n *dst++ = *src++;\n" }, { "answer_id": 2741636, "author": "Bevan", "author_id": 30280, "author_profile": "https://Stackoverflow.com/users/30280", "pm_score": 0, "selected": false, "text": "memcpy()" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11206/" ]
147,416
<p>In .NET (VB), how can I take all of the items in one collection, and add them to a second collection (without losing pre-existing items in the second collection)? I'm looking for something a little more efficient than this:</p> <pre><code>For Each item As Host In hostCollection1 hostCollection2.Add(item) Next </code></pre> <p>My collections are generic collections, inherited from the base class -- Collection(Of )</p>
[ { "answer_id": 147418, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 3, "selected": false, "text": "List<string> list1 = new List<string>();\nlist1.Add(\"Hello\");\nList<string> list2 = new List<string>(list1);\n" }, { "answer_id": 147421, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "Array.Copy" }, { "answer_id": 147427, "author": "Austin Salonen", "author_id": 4068, "author_profile": "https://Stackoverflow.com/users/4068", "pm_score": 1, "selected": false, "text": "Dim collection As IEnumerable(Of T) \nDim instance As New List(collection)\n" }, { "answer_id": 147436, "author": "jop", "author_id": 11830, "author_profile": "https://Stackoverflow.com/users/11830", "pm_score": 6, "selected": true, "text": "hostCollection2.AddRange(hostCollection1)" }, { "answer_id": 147439, "author": "johnc", "author_id": 5302, "author_profile": "https://Stackoverflow.com/users/5302", "pm_score": 2, "selected": false, "text": "List<T>.AddRange(otherList<T>)" }, { "answer_id": 1320905, "author": "Kangkan", "author_id": 118500, "author_profile": "https://Stackoverflow.com/users/118500", "pm_score": 2, "selected": false, "text": "IList" }, { "answer_id": 49214545, "author": "user4951", "author_id": 700663, "author_profile": "https://Stackoverflow.com/users/700663", "pm_score": 0, "selected": false, "text": " Dim newlines = _singSongs.ToList\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147416", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5473/" ]
147,437
<p>I am trying to use Difflib.SequenceMatcher to compute the similarities between two files. These two files are almost identical except that one contains some extra whitespaces, empty lines and other doesn't. I am trying to use</p> <pre><code>s=difflib.SequenceMatcher(isjunk,text1,text2) ratio =s.ratio() </code></pre> <p>for this purpose.</p> <p>So, the question is how to write the lambda expression for this isjunk method so the SequenceMatcher method will discount all the whitespaces, empty lines etc. I tried to use the parameter lambda x: x==" ", but the result isn't as great. For two closely similar text, the ratio is very low. This is highly counter intuitive. </p> <p>For testing purpose, here are the two strings that you can use on testing:</p> <blockquote> <p>What Motivates jwovu to do your Job Well? OK, this is an entry trying to win $100 worth of software development books despite the fact that I don‘t read </p> <p>programming books. In order to win the prize you have to write an entry and<br> what motivatesfggmum to do your job well. Hence this post. First motivation </p> <p>money. I know, this doesn‘t sound like a great inspiration to many, and saying that money is one of the motivation factors might just blow my chances away. </p> <p>As if money is a taboo in programming world. I know there are people who can‘t be motivated by money. Mme, on the other hand, am living in a real world, </p> <p>with house mortgage to pay, myself to feed and bills to cover. So I can‘t really exclude money from my consideration. If I can get a large sum of money for </p> <p>doing a good job, then definitely boost my morale. I won‘t care whether I am using an old workstation, or forced to share rooms or cubicle with other </p> <p>people, or have to put up with an annoying boss, or whatever. The fact that at the end of the day I will walk off with a large pile of money itself is enough </p> <p>for me to overcome all the obstacles, put up with all the hard feelings and hurt egos, tolerate a slow computer and even endure</p> </blockquote> <p>And here's another string</p> <blockquote> <p>What Motivates You to do your Job Well? OK, this is an entry trying to win $100 worth of software development books, despite the fact that I don't read programming books. In order to win the prize you have to write an entry and describes what motivates you to do your job well. Hence this post.</p> <p>First motivation, money. I know, this doesn't sound like a great inspiration to many, and saying that money is one of the motivation factors might just blow my chances away. As if money is a taboo in programming world. I know there are people who can't be motivated by money. Kudos to them. Me, on the other hand, am living in a real world, with house mortgage to pay, myself to feed and bills to cover. So I can't really exclude money from my consideration.</p> <p>If I can get a large sum of money for doing a good job, then thatwill definitely boost my morale. I won't care whether I am using an old workstation, or forced to share rooms or cubicle with other people, or have to put up with an annoying boss, or whatever. The fact that at the end of the day I will walk off with a large pile of money itself is enough for me to overcome all the obstacles, put up with all the hard feelings and hurt egos, tolerate a slow computer and even endure</p> </blockquote> <p>I ran the above command, and set the isjunk to lambda x:x==" ", the ratio is only 0.36. </p>
[ { "answer_id": 147732, "author": "mhawke", "author_id": 21945, "author_profile": "https://Stackoverflow.com/users/21945", "pm_score": 2, "selected": false, "text": ">>> s=difflib.SequenceMatcher(lambda x: x == '\\n', s1, s2)\n>>> s.ratio()\n0.94669848846459825\n" }, { "answer_id": 147791, "author": "Florian Bösch", "author_id": 19435, "author_profile": "https://Stackoverflow.com/users/19435", "pm_score": 4, "selected": true, "text": "difflib.SequenceMatcher(lambda x: x in \" \\t\\n\", doc1, doc2).ratio()\n" }, { "answer_id": 148364, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 2, "selected": false, "text": "difflib.SequenceMatcher(lambda x: x in \" \\t\\n\", doc1, doc2).ratio()\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
147,449
<p>My custom homebrew photography processing software, running on 64 bit Linux/GNU, writes out PNG and TIFF files. These are to be sent to a quality printing shop to be made into fine art. Working with interior designers - it's important to get the colors just right! </p> <p>The print shops usually have no trouble with TIFF and PNGs made from commercial software such as Photoshop. Even though i have the TIFF 6.0 specs, PNG specs, and other info in hand, it is not clear how to include color calibration data or implement color management system on linux. My files are often rejected as faulty, without sufficient error reports to make fixes. </p> <p>This has been a nasty problem for a while for many. Even my contacts at the Hollywood postproduction studios are struggling with this issue. One studio even wanted to hire me to take care of their color calibration, thinking i was the expert - but no, i am just as blind and lost as everyone!</p> <p>Does anyone know of good code examples, detailed technical information, or have any other enlightenment? Or time to switch to pure Apple?</p>
[ { "answer_id": 23540340, "author": "fish2000", "author_id": 298171, "author_profile": "https://Stackoverflow.com/users/298171", "pm_score": 0, "selected": false, "text": "imagetestsuite" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10468/" ]
147,451
<p>In an HTML form post what are valid characters for creating a multipart boundary?</p>
[ { "answer_id": 147467, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 5, "selected": true, "text": " boundary := 0*69<bchars> bcharsnospace\n\n bchars := bcharsnospace / \" \"\n\n bcharsnospace := DIGIT / ALPHA / \"'\" / \"(\" / \")\" /\n \"+\" / \"_\" / \",\" / \"-\" / \".\" /\n \"/\" / \":\" / \"=\" / \"?\"\n" }, { "answer_id": 147469, "author": "camflan", "author_id": 22445, "author_profile": "https://Stackoverflow.com/users/22445", "pm_score": 1, "selected": false, "text": "Content-type: multipart/mixed; boundary=\"fU3W4Vzr4G3D54f3\"\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3740/" ]
147,454
<p>It is much more convenient and cleaner to use a single statement like</p> <pre><code>import java.awt.*; </code></pre> <p>than to import a bunch of individual classes</p> <pre><code>import java.awt.Panel; import java.awt.Graphics; import java.awt.Canvas; ... </code></pre> <p>What is wrong with using a wildcard in the <code>import</code> statement?</p>
[ { "answer_id": 147461, "author": "Benjamin Pollack", "author_id": 2354, "author_profile": "https://Stackoverflow.com/users/2354", "pm_score": 10, "selected": true, "text": "java.awt.Event" }, { "answer_id": 147473, "author": "hazzen", "author_id": 5066, "author_profile": "https://Stackoverflow.com/users/5066", "pm_score": 5, "selected": false, "text": "import java.util.*;\nimport java.awt.*;\n\n...\nList blah; // Ambiguous, needs to be qualified.\n" }, { "answer_id": 149282, "author": "davetron5000", "author_id": 3029, "author_profile": "https://Stackoverflow.com/users/3029", "pm_score": 8, "selected": false, "text": "java.sql.Date" }, { "answer_id": 150315, "author": "Scott Stanchfield", "author_id": 12541, "author_profile": "https://Stackoverflow.com/users/12541", "pm_score": 8, "selected": false, "text": "import java.awt.*;\nimport java.util.*;\n\n// ...\n\nList list;\n" }, { "answer_id": 39600304, "author": "Aftab", "author_id": 1599792, "author_profile": "https://Stackoverflow.com/users/1599792", "pm_score": 2, "selected": false, "text": "java.awt.*" }, { "answer_id": 49344758, "author": "Leon", "author_id": 4865117, "author_profile": "https://Stackoverflow.com/users/4865117", "pm_score": 2, "selected": false, "text": "import ...*" }, { "answer_id": 64302718, "author": "Milan Paudyal", "author_id": 6770146, "author_profile": "https://Stackoverflow.com/users/6770146", "pm_score": 2, "selected": false, "text": ".*" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147454", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22807/" ]
147,458
<p>I have an ASP.NET 3.5 WebForm that leverages the frameworks Page.ClientScript.GetCallbackEventReference() method and I'd like some of the calls to be synchronous. </p> <p>Now, the documentation says that the 5th parameter (see below) controls this. Specifically, when you pass 'false' it's supposed to be a non-asynchronous call. However, regardless if it's true or false, it still processes the call asynchronously. </p> <pre><code>Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context",false); </code></pre> <p>Is there a work-around for this or perhaps I'm doing something wrong? </p>
[ { "answer_id": 16345178, "author": "Javal Patel", "author_id": 896527, "author_profile": "https://Stackoverflow.com/users/896527", "pm_score": 1, "selected": false, "text": "<%@ Page Language=\"VB\" AutoEventWireup=\"false\" CodeFile=\"How-to-use-GetCallbackEventReference.aspx.vb\" Inherits=\"How_to_use_Callback\" %>\n\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head runat=\"server\">\n <title>How to use GetCallbackEventReference</title>\n <script type=\"text/javascript\">\n function GetNumber() {\n UseCallback();\n }\n function GetRandomNumberFromServer(txtGetNumber, context) {\n document.forms[0].txtGetNumber.value = txtGetNumber\n }\n </script>\n</head>\n<body>\n <form id=\"form1\" runat=\"server\">\n <div>\n <input id=\"Button1\" type=\"button\" value=\"Get Random Number\" onclick=\"GetNumber()\" /><br /><br />\n <asp:TextBox ID=\"txtGetNumber\" runat=\"server\"></asp:TextBox>&nbsp;</div>\n </form>\n</body>\n</html>\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147458", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4646/" ]
147,460
<p>I've developed a Visual C#.NET 2008 Express Edition solution containing three projects. I am cleaning it up to commit it into a CVS repository.</p> <p>There are several files that are created during the build process that are not necessary to be placed in the repository since they will be regenerated automatically.</p> <p>The question: Can anyone suggest a list of patterns to be placed into a .cvsignore file so that these generated files and folders are ignored?</p>
[ { "answer_id": 336984, "author": "Kevin P.", "author_id": 18542, "author_profile": "https://Stackoverflow.com/users/18542", "pm_score": 2, "selected": false, "text": "bin\nobj\n*.cache\n*.suo\n*.csproj.user\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18542/" ]
147,468
<p><a href="https://pmd.github.io/" rel="noreferrer">PMD</a> would report a violation for:</p> <pre><code>ArrayList&lt;Object&gt; list = new ArrayList&lt;Object&gt;(); </code></pre> <p>The violation was "Avoid using implementation types like 'ArrayList'; use the interface instead".</p> <p>The following line would correct the violation:</p> <pre><code>List&lt;Object&gt; list = new ArrayList&lt;Object&gt;(); </code></pre> <p>Why should the latter with <code>List</code> be used instead of <code>ArrayList</code>?</p>
[ { "answer_id": 148712, "author": "Rastislav Komara", "author_id": 22068, "author_profile": "https://Stackoverflow.com/users/22068", "pm_score": 1, "selected": false, "text": "class Counter {\n static int sizeOf(List<?> items) {\n return items.size();\n }\n}\n" }, { "answer_id": 151322, "author": "MetroidFan2002", "author_id": 8026, "author_profile": "https://Stackoverflow.com/users/8026", "pm_score": 1, "selected": false, "text": "public void someMethod() {\nList theList = new ArrayList();\n//do stuff with the list\n}\n" }, { "answer_id": 41347099, "author": "Ravindra babu", "author_id": 4999394, "author_profile": "https://Stackoverflow.com/users/4999394", "pm_score": 2, "selected": false, "text": "ArrayList" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22807/" ]
147,486
<p>Given the following XML structure</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;div&gt; &lt;span&gt;Test: Text2&lt;/span&gt; &lt;/div&gt; &lt;div&gt; &lt;span&gt;Test: Text3&lt;/span&gt; &lt;/div&gt; &lt;div&gt; &lt;span&gt;Test: Text5&lt;/span&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>What is the best XPath query to locate any <code>span</code> with text that starts with <code>Test</code>?</p>
[ { "answer_id": 147497, "author": "A. Rex", "author_id": 3508, "author_profile": "https://Stackoverflow.com/users/3508", "pm_score": 6, "selected": true, "text": "//span[starts-with(.,'Test')]\n" }, { "answer_id": 13396943, "author": "Jackson Lee", "author_id": 1632017, "author_profile": "https://Stackoverflow.com/users/1632017", "pm_score": 2, "selected": false, "text": "//span[contains(.,'Test')]\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10673/" ]
147,491
<p>I have the function below ENCRYPT.</p> <pre><code>Public Function Encrypt(ByVal plainText As String) As Byte() Dim key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24} Dim iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219} ' Declare a UTF8Encoding object so we may use the GetByte ' method to transform the plainText into a Byte array. Dim utf8encoder As UTF8Encoding = New UTF8Encoding() Dim inputInBytes() As Byte = utf8encoder.GetBytes(plainText) ' Create a new TripleDES service provider Dim tdesProvider As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider() ' The ICryptTransform interface uses the TripleDES ' crypt provider along with encryption key and init vector ' information Dim cryptoTransform As ICryptoTransform = tdesProvider.CreateEncryptor(Me.key, Me.iv) ' All cryptographic functions need a stream to output the ' encrypted information. Here we declare a memory stream ' for this purpose. Dim encryptedStream As MemoryStream = New MemoryStream() Dim cryptStream As CryptoStream = New CryptoStream(encryptedStream, cryptoTransform, CryptoStreamMode.Write) ' Write the encrypted information to the stream. Flush the information ' when done to ensure everything is out of the buffer. cryptStream.Write(inputInBytes, 0, inputInBytes.Length) cryptStream.FlushFinalBlock() encryptedStream.Position = 0 ' Read the stream back into a Byte array and return it to the calling ' method. Dim result(encryptedStream.Length - 1) As Byte encryptedStream.Read(result, 0, encryptedStream.Length) cryptStream.Close() Return result End Function </code></pre> <p>How do i see the byte value of the text?</p>
[ { "answer_id": 147559, "author": "Tim Jarvis", "author_id": 10387, "author_profile": "https://Stackoverflow.com/users/10387", "pm_score": 2, "selected": false, "text": "string.Join(\",\", byteArray.Select(b => b.ToString()).ToArray());\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
147,500
<p>Is it possible to include one CSS file in another?</p>
[ { "answer_id": 147508, "author": "Kevin Read", "author_id": 23303, "author_profile": "https://Stackoverflow.com/users/23303", "pm_score": 11, "selected": true, "text": "@import url(\"base.css\");\n" }, { "answer_id": 147510, "author": "Sören Kuklau", "author_id": 1600, "author_profile": "https://Stackoverflow.com/users/1600", "pm_score": 5, "selected": false, "text": "@import" }, { "answer_id": 147517, "author": "Gordon Wilson", "author_id": 23071, "author_profile": "https://Stackoverflow.com/users/23071", "pm_score": 4, "selected": false, "text": "@import \"your.css\";\n" }, { "answer_id": 147637, "author": "Ronnie Liew", "author_id": 1987, "author_profile": "https://Stackoverflow.com/users/1987", "pm_score": 7, "selected": false, "text": "@import \"mystyle.css\";\n@import url(\"mystyle.css\");\n" }, { "answer_id": 147773, "author": "Gene", "author_id": 22673, "author_profile": "https://Stackoverflow.com/users/22673", "pm_score": 5, "selected": false, "text": "@import url(\"base.css\");" }, { "answer_id": 6839124, "author": "Floyd", "author_id": 677693, "author_profile": "https://Stackoverflow.com/users/677693", "pm_score": 3, "selected": false, "text": "@import(\"/path-to-your-styles.css\");" }, { "answer_id": 14464308, "author": "vidhi", "author_id": 1970036, "author_profile": "https://Stackoverflow.com/users/1970036", "pm_score": 3, "selected": false, "text": "@import url(\"mycssfile.css\");\n" }, { "answer_id": 22030789, "author": "Pocky_Thailand", "author_id": 3354010, "author_profile": "https://Stackoverflow.com/users/3354010", "pm_score": 0, "selected": false, "text": "@import url('/css/header.css') screen;\n@import url('/css/content.css') screen;\n@import url('/css/sidebar.css') screen;\n@import url('/css/print.css') print;\n" }, { "answer_id": 29521490, "author": "eQ19", "author_id": 4058484, "author_profile": "https://Stackoverflow.com/users/4058484", "pm_score": 3, "selected": false, "text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"EN\" dir=\"ltr\">\n<head>\n<title>Using @import</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n<style type=\"text/css\">\n@import url(\"main.css\");\n</style>\n</head>\n<body>\n</body>\n</html>\n" }, { "answer_id": 40560653, "author": "Dinesh Vaitage", "author_id": 5710925, "author_profile": "https://Stackoverflow.com/users/5710925", "pm_score": 1, "selected": false, "text": "@import url('style.css');\n@import url('platforms.css');\n" }, { "answer_id": 41157397, "author": "NARGIS PARWEEN", "author_id": 6333230, "author_profile": "https://Stackoverflow.com/users/6333230", "pm_score": 1, "selected": false, "text": "@import url(\"url_path\");\n" }, { "answer_id": 43304653, "author": "peterC_", "author_id": 2165418, "author_profile": "https://Stackoverflow.com/users/2165418", "pm_score": 2, "selected": false, "text": "@import url('style.css');\n" }, { "answer_id": 49667794, "author": "PythonProgrammi", "author_id": 6464947, "author_profile": "https://Stackoverflow.com/users/6464947", "pm_score": 2, "selected": false, "text": "@import url(\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\");\n" }, { "answer_id": 50255589, "author": "Colin Keenan", "author_id": 1707904, "author_profile": "https://Stackoverflow.com/users/1707904", "pm_score": 0, "selected": false, "text": " <link rel=\"stylesheet\" media=\"print\" href=\"myap-print.css\">\n <link rel=\"stylesheet\" media=\"print\" href=\"myap-screen.css\">\n <link rel=\"stylesheet\" media=\"screen\" href=\"myap-screen.css\">\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/460927/" ]
147,505
<p>I am trying to get a Flex application to communicate with a custom python webserver I have developed. </p> <p>I am noticing that I cannot read the postdata received because Flex does not seem to include the Content-Length in the HTTP headers. (My webserver work when posted to from plain HTML)</p> <p>Is this a known problem? any ideas how to set the content-length header? </p> <p>Here is the current headers being sent:</p> <pre> Host: localhost:7070 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0 .3 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive </pre>
[ { "answer_id": 149811, "author": "bill d", "author_id": 1798, "author_profile": "https://Stackoverflow.com/users/1798", "pm_score": 2, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<mx:Application layout=\"absolute\"\n xmlns:mx=\"http://www.adobe.com/2006/mxml\"\n creationComplete=\"init()\">\n\n <mx:HTTPService id=\"service\" \n url=\"http://localhost:8000/\"\n method=\"POST\"\n resultFormat=\"text\"\n result=\"response.htmlText=ResultEvent(event).result.toString()\"/>\n\n <mx:Text id=\"response\" width=\"100%\" height=\"100%\"/>\n\n <mx:Script>\n <![CDATA[\n import mx.rpc.events.ResultEvent;\n private function init() : void {\n service.send({\n foo: \"Fred\",\n bar: \"Barney\"\n });\n }\n ]]>\n </mx:Script>\n</mx:Application>\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147505", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1638/" ]
147,507
<p>Given a string with a module name, how do you import everything in the module as if you had called:</p> <pre><code>from module import * </code></pre> <p>i.e. given string S="module", how does one get the equivalent of the following:</p> <pre><code>__import__(S, fromlist="*") </code></pre> <p>This doesn't seem to perform as expected (as it doesn't import anything).</p>
[ { "answer_id": 147541, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 6, "selected": true, "text": "import *" }, { "answer_id": 160636, "author": "Brian M. Hunt", "author_id": 19212, "author_profile": "https://Stackoverflow.com/users/19212", "pm_score": 0, "selected": false, "text": "from platform import node\n\nsettings_files = { 'BMH.lan': 'settings_bmh.py\", ... } \n\n__import__( settings_files[ node() ] )\n" }, { "answer_id": 293189, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "try:\n import socket\n hostname = socket.gethostname().replace('.','_')\n exec \"from host_settings.%s import *\" % hostname\nexcept ImportError, e:\n raise e\n" }, { "answer_id": 1350959, "author": "ilya n.", "author_id": 115200, "author_profile": "https://Stackoverflow.com/users/115200", "pm_score": 0, "selected": false, "text": "config = [__import__(name) for name in names_list]\n\noptions = {}\nfor conf in config:\n options.update(conf.__dict__)\n" }, { "answer_id": 3286758, "author": "David Marble", "author_id": 216735, "author_profile": "https://Stackoverflow.com/users/216735", "pm_score": 3, "selected": false, "text": "__name__" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19212/" ]
147,515
<p>How do you calculate the least common multiple of multiple numbers?</p> <p>So far I've only been able to calculate it between two numbers. But have no idea how to expand it to calculate 3 or more numbers.</p> <p>So far this is how I did it </p> <pre><code>LCM = num1 * num2 / gcd ( num1 , num2 ) </code></pre> <p>With gcd is the function to calculate the greatest common divisor for the numbers. Using euclidean algorithm</p> <p>But I can't figure out how to calculate it for 3 or more numbers.</p>
[ { "answer_id": 147523, "author": "A. Rex", "author_id": 3508, "author_profile": "https://Stackoverflow.com/users/3508", "pm_score": 9, "selected": true, "text": "lcm(a,b,c) = lcm(a,lcm(b,c))\n" }, { "answer_id": 147539, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 7, "selected": false, "text": "def gcd(a, b):\n \"\"\"Return greatest common divisor using Euclid's Algorithm.\"\"\"\n while b: \n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n \"\"\"Return lowest common multiple.\"\"\"\n return a * b // gcd(a, b)\n\ndef lcmm(*args):\n \"\"\"Return lcm of args.\"\"\" \n return reduce(lcm, args)\n" }, { "answer_id": 2142933, "author": "Matt Ellen", "author_id": 204723, "author_profile": "https://Stackoverflow.com/users/204723", "pm_score": 3, "selected": false, "text": "lcm' :: Integral a => a -> a -> a\nlcm' a b = a`div`(gcd a b) * b\nlcm :: Integral a => [a] -> a\nlcm (n:ns) = foldr lcm' n ns\n" }, { "answer_id": 2641293, "author": "T3db0t", "author_id": 297824, "author_profile": "https://Stackoverflow.com/users/297824", "pm_score": 5, "selected": false, "text": "function gcd(a, b){\n // Euclidean algorithm\n while (b != 0){\n var temp = b;\n b = a % b;\n a = temp;\n }\n return a;\n}\n\nfunction lcm(a, b){\n return (a * b / gcd(a, b));\n}\n\nfunction lcmm(args){\n // Recursively iterate through pairs of arguments\n // i.e. lcm(args[0], lcm(args[1], lcm(args[2], args[3])))\n\n if(args.length == 2){\n return lcm(args[0], args[1]);\n } else {\n var arg0 = args[0];\n args.shift();\n return lcm(arg0, lcmm(args));\n }\n}\n" }, { "answer_id": 11851434, "author": "Eratosthenes", "author_id": 1499713, "author_profile": "https://Stackoverflow.com/users/1499713", "pm_score": 3, "selected": false, "text": "from sys import argv \n\ndef lcm(x,y):\n tmp=x\n while (tmp%y)!=0:\n tmp+=x\n return tmp\n\ndef lcmm(*args):\n return reduce(lcm,args)\n\nargs=map(int,argv[1:])\nprint lcmm(*args)\n" }, { "answer_id": 13731775, "author": "t9mike", "author_id": 420175, "author_profile": "https://Stackoverflow.com/users/420175", "pm_score": 2, "selected": false, "text": "public class MathUtils\n{\n /// <summary>\n /// Calculates the least common multiple of 2+ numbers.\n /// </summary>\n /// <remarks>\n /// Uses recursion based on lcm(a,b,c) = lcm(a,lcm(b,c)).\n /// Ported from http://stackoverflow.com/a/2641293/420175.\n /// </remarks>\n public static Int64 LCM(IList<Int64> numbers)\n {\n if (numbers.Count < 2)\n throw new ArgumentException(\"you must pass two or more numbers\");\n return LCM(numbers, 0);\n }\n\n public static Int64 LCM(params Int64[] numbers)\n {\n return LCM((IList<Int64>)numbers);\n }\n\n private static Int64 LCM(IList<Int64> numbers, int i)\n {\n // Recursively iterate through pairs of arguments\n // i.e. lcm(args[0], lcm(args[1], lcm(args[2], args[3])))\n\n if (i + 2 == numbers.Count)\n {\n return LCM(numbers[i], numbers[i+1]);\n }\n else\n {\n return LCM(numbers[i], LCM(numbers, i+1));\n }\n }\n\n public static Int64 LCM(Int64 a, Int64 b)\n {\n return (a * b / GCD(a, b));\n }\n\n /// <summary>\n /// Finds the greatest common denominator for 2 numbers.\n /// </summary>\n /// <remarks>\n /// Also from http://stackoverflow.com/a/2641293/420175.\n /// </remarks>\n public static Int64 GCD(Int64 a, Int64 b)\n {\n // Euclidean algorithm\n Int64 t;\n while (b != 0)\n {\n t = b;\n b = a % b;\n a = t;\n }\n return a;\n }\n}'\n" }, { "answer_id": 14162416, "author": "Roger Garzon Nieto", "author_id": 1101845, "author_profile": "https://Stackoverflow.com/users/1101845", "pm_score": 0, "selected": false, "text": "def gcd(x,y):\n while y:\n if y<0:\n x,y=-x,-y\n x,y=y,x % y\n return x\n\ndef gcdl(*list):\n return reduce(gcd, *list)\n\ndef lcm(x,y):\n return x*y / gcd(x,y)\n\ndef lcml(*list):\n return reduce(lcm, *list)\n" }, { "answer_id": 16827210, "author": "Alessandro Martin", "author_id": 1162490, "author_profile": "https://Stackoverflow.com/users/1162490", "pm_score": 0, "selected": false, "text": "from operator import mul as MULTIPLY\n\ndef factors(n):\n f = {} # a dict is necessary to create 'factor : exponent' pairs \n divisor = 2\n while n > 1:\n while (divisor <= n):\n if n % divisor == 0:\n n /= divisor\n f[divisor] = f.get(divisor, 0) + 1\n else:\n divisor += 1\n return f\n\n\ndef mcm(numbers):\n #numbers is a list of numbers so not restricted to two items\n high_factors = {}\n for n in numbers:\n fn = factors(n)\n for (key, value) in fn.iteritems():\n if high_factors.get(key, 0) < value: # if fact not in dict or < val\n high_factors[key] = value\n return reduce (MULTIPLY, ((k ** v) for k, v in high_factors.items()))\n" }, { "answer_id": 17136781, "author": "Saebekassebil", "author_id": 75267, "author_profile": "https://Stackoverflow.com/users/75267", "pm_score": 1, "selected": false, "text": "function gcd(...numbers) {\n return numbers.reduce((a, b) => b === 0 ? a : gcd(b, a % b));\n}\n\nfunction lcm(...numbers) {\n return numbers.reduce((a, b) => Math.abs(a * b) / gcd(a, b));\n}\n" }, { "answer_id": 23268872, "author": "SepehrM", "author_id": 2550529, "author_profile": "https://Stackoverflow.com/users/2550529", "pm_score": 2, "selected": false, "text": "static int LCM(int[] numbers)\n{\n return numbers.Aggregate(LCM);\n}\n\nstatic int LCM(int a, int b)\n{\n return a * b / GCD(a, b);\n}\n" }, { "answer_id": 23283500, "author": "MD Nashid Anjum", "author_id": 3571340, "author_profile": "https://Stackoverflow.com/users/3571340", "pm_score": 0, "selected": false, "text": "clc;\n\ndata = [1 2 3 4 5]\n\nLCM=1;\n\nfor i=1:1:length(data)\n\n LCM = lcm(LCM,data(i))\n\nend \n" }, { "answer_id": 28349070, "author": "Roman Pietrzak", "author_id": 867387, "author_profile": "https://Stackoverflow.com/users/867387", "pm_score": 0, "selected": false, "text": "0: Assume we got inputs[] array, filled with integers. So, for example:\n inputsArray = [6, 15, 25, ...]\n lcm = 1\n\n1: Find minimal prime factor for each input.\n Minimal means for 6 it's 2, for 25 it's 5, for 34 it's 17\n minFactorsArray = []\n\n2: Find lowest from minFactors:\n minFactor = MIN(minFactorsArray)\n\n3: lcm *= minFactor\n\n4: Iterate minFactorsArray and if the factor for given input equals minFactor, then divide the input by it:\n for (inIdx in minFactorsArray)\n if minFactorsArray[inIdx] == minFactor\n inputsArray[inIdx] \\= minFactor\n\n5: repeat steps 1-4 until there is nothing to factorize anymore. \n So, until inputsArray contains only 1-s.\n" }, { "answer_id": 28667302, "author": "User", "author_id": 1589737, "author_profile": "https://Stackoverflow.com/users/1589737", "pm_score": 0, "selected": false, "text": "int main()\n{\n int a[20],i,n,result=1; // assumption: count can't exceed 20\n printf(\"Enter number of numbers to calculate LCM(less than 20):\");\n scanf(\"%d\",&n);\n printf(\"Enter %d numbers to calculate their LCM :\",n);\n for(i=0;i<n;i++)\n scanf(\"%d\",&a[i]);\n for(i=0;i<n;i++)\n result=lcm(result,a[i]);\n printf(\"LCM of given numbers = %d\\n\",result);\n return 0;\n}\n\nint lcm(int a,int b)\n{\n int gcd=gcd_two_numbers(a,b);\n return (a*b)/gcd;\n}\n\nint gcd_two_numbers(int a,int b)\n{\n int temp;\n if(a>b)\n {\n temp=a;\n a=b;\n b=temp;\n }\n if(b%a==0)\n return a;\n else\n return gcd_two_numbers(b%a,a);\n}\n" }, { "answer_id": 29458752, "author": "mpalanco", "author_id": 2963704, "author_profile": "https://Stackoverflow.com/users/2963704", "pm_score": 1, "selected": false, "text": " library(numbers)\n mGCD(c(4, 8, 12, 16, 20))\n[1] 4\n mLCM(c(8,9,21))\n[1] 504\n # Sequences\n mLCM(1:20)\n[1] 232792560\n" }, { "answer_id": 29717490, "author": "Rodrigo López", "author_id": 3393095, "author_profile": "https://Stackoverflow.com/users/3393095", "pm_score": 4, "selected": false, "text": "static long LCM(long[] numbers)\n{\n return numbers.Aggregate(lcm);\n}\nstatic long lcm(long a, long b)\n{\n return Math.Abs(a * b) / GCD(a, b);\n}\nstatic long GCD(long a, long b)\n{\n return b == 0 ? a : GCD(b, a % b);\n}\n" }, { "answer_id": 29977721, "author": "Behnam Dezfouli", "author_id": 4852336, "author_profile": "https://Stackoverflow.com/users/4852336", "pm_score": 0, "selected": false, "text": "int mathOps::compLCM(std::vector<int> &in_numbers)\n {\n int tmpNumbers = in_numbers.size();\n int tmpMax = *max_element(in_numbers.begin(), in_numbers.end());\n bool tmpNotDividable = false;\n\n while (true)\n {\n for (int i = 0; i < tmpNumbers && tmpNotDividable == false; i++)\n {\n if (tmpMax % in_numbers[i] != 0 )\n tmpNotDividable = true;\n }\n\n if (tmpNotDividable == false)\n return tmpMax;\n else\n tmpMax++;\n }\n}\n" }, { "answer_id": 34661952, "author": "Nikhil", "author_id": 2924577, "author_profile": "https://Stackoverflow.com/users/2924577", "pm_score": 0, "selected": false, "text": "lcm_n(args, num)" }, { "answer_id": 39515394, "author": "vipul", "author_id": 3835990, "author_profile": "https://Stackoverflow.com/users/3835990", "pm_score": 0, "selected": false, "text": "int gcd(int a, int b) {\n if (b == 0) return a;\n return gcd(b, a%b);\n }\n int lcm(int[] a, int n) {\n int res = 1, i;\n for (i = 0; i < n; i++) {\n res = res*a[i]/gcd(res, a[i]);\n }\n return res;\n}" }, { "answer_id": 40387536, "author": "Asclepius", "author_id": 832230, "author_profile": "https://Stackoverflow.com/users/832230", "pm_score": 3, "selected": false, "text": "from functools import reduce\nfrom math import gcd\n" }, { "answer_id": 40596079, "author": "Zach-M", "author_id": 942536, "author_profile": "https://Stackoverflow.com/users/942536", "pm_score": 2, "selected": false, "text": "def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\ndef gcd(nums: Iterable[Int]): Int = nums.reduce(gcd)\ndef lcm(a: Int, b: Int): Int = if (a == 0 || b == 0) 0 else a * b / gcd(a, b)\ndef lcm(nums: Iterable[Int]): Int = nums.reduce(lcm)\n" }, { "answer_id": 40704222, "author": "Aaditya Mishra", "author_id": 7185304, "author_profile": "https://Stackoverflow.com/users/7185304", "pm_score": 2, "selected": false, "text": " def function(l):\n s = 1\n for i in l:\n s = lcm(i, s)\n return s\n" }, { "answer_id": 40796304, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "#!/bin/sh\ngcd() { # Calculate $1 % $2 until $2 becomes zero.\n until [ \"$2\" -eq 0 ]; do set -- \"$2\" \"$(($1%$2))\"; done\n echo \"$1\"\n }\n\nlcm() { echo \"$(( $1 / $(gcd \"$1\" \"$2\") * $2 ))\"; }\n\nwhile [ $# -gt 1 ]; do\n t=\"$(lcm \"$1\" \"$2\")\"\n shift 2\n set -- \"$t\" \"$@\"\ndone\necho \"$1\"\n" }, { "answer_id": 41321661, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "def lcm(*args):\n \"\"\"Calculates lcm of args\"\"\"\n biggest = max(args) #find the largest of numbers\n rest = [n for n in args if n != biggest] #the list of the numbers without the largest\n factor = 1 #to multiply with the biggest as long as the result is not divisble by all of the numbers in the rest\n while True:\n #check if biggest is divisble by all in the rest:\n ans = False in [(biggest * factor) % n == 0 for n in rest]\n #if so the clm is found break the loop and return it, otherwise increment factor by 1 and try again\n if not ans:\n break\n factor += 1\n biggest *= factor\n return \"lcm of {0} is {1}\".format(args, biggest)\n" }, { "answer_id": 41331934, "author": "mehmet riza oz", "author_id": 3628270, "author_profile": "https://Stackoverflow.com/users/3628270", "pm_score": 1, "selected": false, "text": "private static int gcd(int a, int b) {\n while (b > 0) {\n int temp = b;\n b = a % b; // % is remainder\n a = temp;\n }\n return a;\n}\n\nprivate static int gcd(int[] input) {\n int result = input[0];\n for (int i = 1; i < input.length; i++) {\n result = gcd(result, input[i]);\n }\n return result;\n}\n\nprivate static int lcm(int a, int b) {\n return a * (b / gcd(a, b));\n}\n\nprivate static int lcm(int[] input) {\n int result = input[0];\n for (int i = 1; i < input.length; i++) {\n result = lcm(result, input[i]);\n }\n return result;\n}\n" }, { "answer_id": 42284184, "author": "Vishwajeet Gaur", "author_id": 7577367, "author_profile": "https://Stackoverflow.com/users/7577367", "pm_score": 0, "selected": false, "text": "def greater(n):\n\n a=num[0]\n\n for i in range(0,len(n),1):\n if(a<n[i]):\n a=n[i]\n return a\n\nr=input('enter limit')\n\nnum=[]\n\nfor x in range (0,r,1):\n\n a=input('enter number ')\n num.append(a)\na= greater(num)\n\ni=0\n\nwhile True:\n\n while (a%num[i]==0):\n i=i+1\n if(i==len(num)):\n break\n if i==len(num):\n print 'L.C.M = ',a\n break\n else:\n a=a+1\n i=0\n" }, { "answer_id": 46445266, "author": "Avatar", "author_id": 1066234, "author_profile": "https://Stackoverflow.com/users/1066234", "pm_score": 1, "selected": false, "text": " // https://stackoverflow.com/q/12412782/1066234\n function math_gcd($a,$b) \n {\n $a = abs($a); \n $b = abs($b);\n if($a < $b) \n {\n list($b,$a) = array($a,$b); \n }\n if($b == 0) \n {\n return $a; \n }\n $r = $a % $b;\n while($r > 0) \n {\n $a = $b;\n $b = $r;\n $r = $a % $b;\n }\n return $b;\n }\n\n function math_lcm($a, $b)\n {\n return ($a * $b / math_gcd($a, $b));\n }\n\n // https://stackoverflow.com/a/2641293/1066234\n function math_lcmm($args)\n {\n // Recursively iterate through pairs of arguments\n // i.e. lcm(args[0], lcm(args[1], lcm(args[2], args[3])))\n\n if(count($args) == 2)\n {\n return math_lcm($args[0], $args[1]);\n }\n else \n {\n $arg0 = $args[0];\n array_shift($args);\n return math_lcm($arg0, math_lcmm($args));\n }\n }\n\n // fraction bonus\n function math_fraction_simplify($num, $den) \n {\n $g = math_gcd($num, $den);\n return array($num/$g, $den/$g);\n }\n\n\n var_dump( math_lcmm( array(4, 7) ) ); // 28\n var_dump( math_lcmm( array(5, 25) ) ); // 25\n var_dump( math_lcmm( array(3, 4, 12, 36) ) ); // 36\n var_dump( math_lcmm( array(3, 4, 7, 12, 36) ) ); // 252\n" }, { "answer_id": 49467256, "author": "cmilr", "author_id": 9063453, "author_profile": "https://Stackoverflow.com/users/9063453", "pm_score": 3, "selected": false, "text": "// Euclid's algorithm for finding the greatest common divisor\nfunc gcd(_ a: Int, _ b: Int) -> Int {\n let r = a % b\n if r != 0 {\n return gcd(b, r)\n } else {\n return b\n }\n}\n\n// Returns the least common multiple of two numbers.\nfunc lcm(_ m: Int, _ n: Int) -> Int {\n return m / gcd(m, n) * n\n}\n\n// Returns the least common multiple of multiple numbers.\nfunc lcmm(_ numbers: [Int]) -> Int {\n return numbers.reduce(1) { lcm($0, $1) }\n}\n" }, { "answer_id": 51070443, "author": "Sri", "author_id": 6277581, "author_profile": "https://Stackoverflow.com/users/6277581", "pm_score": -1, "selected": false, "text": "def lcm(a,b,c):\n for i in range(max(a,b,c), (a*b*c)+1, max(a,b,c)):\n if i%a == 0 and i%b == 0 and i%c == 0:\n return i\n" }, { "answer_id": 51958985, "author": "Rodrigo López", "author_id": 3393095, "author_profile": "https://Stackoverflow.com/users/3393095", "pm_score": 0, "selected": false, "text": "from functools import reduce\n\ngcd = lambda a,b: a if b==0 else gcd(b, a%b)\ndef lcm(lst): \n return reduce(lambda x,y: x*y//gcd(x, y), lst) \n" }, { "answer_id": 61932152, "author": "Hosam Aly", "author_id": 41283, "author_profile": "https://Stackoverflow.com/users/41283", "pm_score": 0, "selected": false, "text": "> [2, 3, 4, 6].reduce(:lcm)\n=> 12\n\n> [16, 32, 96].reduce(:gcd)\n=> 16\n" }, { "answer_id": 64370627, "author": "bigbounty", "author_id": 6849682, "author_profile": "https://Stackoverflow.com/users/6849682", "pm_score": 0, "selected": false, "text": "math" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2976/" ]
147,528
<p>In the markup shown below, I'm trying to get the content div to stretch all the way to the bottom of the page but it's only stretching if there's content to display. The reason I want to do this is so the vertical border still appears down the page even if there isn't any content to display.</p> <p>Here is my <strong>DEMO</strong>:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>body { font-family: Trebuchet MS, Verdana, MS Sans Serif; font-size:0.9em; margin:0; padding:0; } div#header { width: 100%; height: 100px; } #header a { background-position: 100px 30px; background: transparent url(site-style-images/sitelogo.jpg) no-repeat fixed 100px 30px; height: 80px; display: block; } #header, #menuwrapper { background-repeat: repeat; background-image: url(site-style-images/darkblue_background_color.jpg); } #menu #menuwrapper { height:25px; } div#menuwrapper { width:100% } #menu, #content { width:1024px; margin: 0 auto; } div#menu { height: 25px; background-color:#50657a; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form id="form1"&gt; &lt;div id="header"&gt; &lt;a title="Home" href="index.html" /&gt; &lt;/div&gt; &lt;div id="menuwrapper"&gt; &lt;div id="menu"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="content"&gt; &lt;/div&gt; &lt;/form&gt;</code></pre> </div> </div> </p>
[ { "answer_id": 147537, "author": "Owen", "author_id": 4853, "author_profile": "https://Stackoverflow.com/users/4853", "pm_score": 3, "selected": false, "text": "<div style=\"min-height: 100%\">stuff</div>\n" }, { "answer_id": 147545, "author": "Kevin Read", "author_id": 23303, "author_profile": "https://Stackoverflow.com/users/23303", "pm_score": 4, "selected": false, "text": "#content {\n min-height: 600px;\n height: auto !important;\n height: 600px;\n}\n" }, { "answer_id": 151681, "author": "Adam Franco", "author_id": 15872, "author_profile": "https://Stackoverflow.com/users/15872", "pm_score": 2, "selected": false, "text": "<html>\n<head>\n<style type='text/css'>\n div {\n border: 1px solid #000000;\n } \n</style>\n<script type='text/javascript'>\n\n function expandToWindow(element) {\n var margin = 10; \n\n if (element.style.height < window.innerHeight) { \n element.style.height = window.innerHeight - (2 * margin) \n }\n }\n\n\n</script>\n</head>\n<body onload='expandToWindow(document.getElementById(\"content\"));'>\n<div id='content'>Hello World</div>\n</body>\n</html>\n" }, { "answer_id": 578995, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<html>" }, { "answer_id": 579123, "author": "Jason Hernandez", "author_id": 34863, "author_profile": "https://Stackoverflow.com/users/34863", "pm_score": 8, "selected": true, "text": "html,body { height:100%; }\n" }, { "answer_id": 5226420, "author": "Steph", "author_id": 648987, "author_profile": "https://Stackoverflow.com/users/648987", "pm_score": 2, "selected": false, "text": "html, body {\n height: 102%;\n}\n.wrapper {\n position: relative;\n height: 100%;\n width: 100%;\n}\n.div {\n position: absolute;\n top: 0;\n bottom: 0;\n width: 1000px;\n min-height: 100%;\n}\n" }, { "answer_id": 7581340, "author": "Martin", "author_id": 346461, "author_profile": "https://Stackoverflow.com/users/346461", "pm_score": 0, "selected": false, "text": "height: 100%;\n" }, { "answer_id": 18040296, "author": "Vinicius José Latorre", "author_id": 1944643, "author_profile": "https://Stackoverflow.com/users/1944643", "pm_score": 2, "selected": false, "text": "<!DOCTYPE html>\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"author\" content=\"http://mystrd.at\">\n <meta name=\"robots\" content=\"noindex, nofollow\">\n <title>James Dean CSS Sticky Footer</title>\n <style type=\"text/css\">\n html {\n position: relative;\n min-height: 100%;\n }\n body {\n margin: 0 0 100px;\n /* bottom = footer height */\n padding: 25px;\n }\n footer {\n background-color: orange;\n position: absolute;\n left: 0;\n bottom: 0;\n height: 100px;\n width: 100%;\n overflow: hidden;\n }\n </style>\n</head>\n<body>\n <article>\n <!-- or <div class=\"container\">, etc. -->\n <h1>James Dean CSS Sticky Footer</h1>\n\n <p>Blah blah blah blah</p>\n <p>More blah blah blah</p>\n </article>\n <footer>\n <h1>Footer Content</h1>\n </footer>\n</body>\n\n</html>\n" }, { "answer_id": 18249135, "author": "David Horák", "author_id": 600082, "author_profile": "https://Stackoverflow.com/users/600082", "pm_score": 2, "selected": false, "text": "<body>\n <div id=\"wrap\">\n </div>\n <div id=\"footer\">\n </div>\n</body>\n" }, { "answer_id": 23986464, "author": "Gima", "author_id": 961517, "author_profile": "https://Stackoverflow.com/users/961517", "pm_score": 6, "selected": false, "text": "<body>\n \n <div class=div1>\n div1<br>\n div1<br>\n div1<br>\n </div>\n \n <div class=div2>\n div2<br>\n div2<br>\n div2<br>\n </div>\n \n</body>\n" }, { "answer_id": 35920954, "author": "Nico", "author_id": 2341216, "author_profile": "https://Stackoverflow.com/users/2341216", "pm_score": 3, "selected": false, "text": "<body class=\"full-height\">\n <form id=\"form1\">\n <div id=\"header\">\n <a title=\"Home\" href=\"index.html\" />\n </div>\n\n <div id=\"menuwrapper\">\n <div id=\"menu\">\n </div>\n </div>\n\n <div id=\"content\" class=\"full-height\">\n </div>\n</body>\n" }, { "answer_id": 38824645, "author": "David Marciel", "author_id": 4670625, "author_profile": "https://Stackoverflow.com/users/4670625", "pm_score": 1, "selected": false, "text": "html, body {\n height: 100%;\n}\n" }, { "answer_id": 69088411, "author": "NHerwich", "author_id": 15036136, "author_profile": "https://Stackoverflow.com/users/15036136", "pm_score": -1, "selected": false, "text": "#content {\n height: calc(100% - the amount of pixels the content div is away from the top);\n}\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17211/" ]
147,533
<p>I need to save a user's login information in encrypted form for this application I'm building, but I'm not sure of the best place to save the file. I don't want to save it into the program application folder as I want it per user.</p> <p>So what is the best folder (or way) to save it into?</p> <p>Edit: Using C++.</p>
[ { "answer_id": 147613, "author": "Lodle", "author_id": 23339, "author_profile": "https://Stackoverflow.com/users/23339", "pm_score": 1, "selected": false, "text": "char localAppPath[MAX_PATH];\nSHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, localAppPath);\n" }, { "answer_id": 207630, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147533", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23339/" ]
147,557
<p>I am making my switch from coding in C++ to C#. I need to replace my C++ error logging/reporting macro system with something similar in C#.</p> <p>In my C++ source I can write</p> <p>LOGERR("Some error"); or LOGERR("Error with inputs %s and %d", stringvar, intvar);</p> <p>The macro &amp; supporting library code then passes the (possibly varargs) formatted message into a database along with the source file, source line, user name, and time. The same data is also stuffed into a data structure for later reporting to the user.</p> <p>Does anybody have C# code snippets or pointers to examples that do this basic error reporting/logging?</p> <p><strong>Edit:</strong> At the time I asked this question I was really new to .NET and was unaware of System.Diagnostics.Trace. System.Diagnostics.Trace was what I needed at that time. Since then I have used log4net on projects where the logging requirements were larger and more complex. Just edit that 500 line XML configuration file and log4net will do everything you will ever need :)</p>
[ { "answer_id": 147574, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 3, "selected": false, "text": "log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));\nlog.Error(“Some error”);\nlog.ErrorFormat(\"Error with inputs {0} and {1}\", stringvar, intvar);\n" }, { "answer_id": 147584, "author": "FryHard", "author_id": 231, "author_profile": "https://Stackoverflow.com/users/231", "pm_score": 2, "selected": false, "text": "private static readonly ILog _log = LogManager.GetLogger(typeof([Class Name]));\n" }, { "answer_id": 148117, "author": "Chris S", "author_id": 21574, "author_profile": "https://Stackoverflow.com/users/21574", "pm_score": 7, "selected": true, "text": "System.Diagnostics.Trace\n" }, { "answer_id": 22584094, "author": "Nicholas Blumhardt", "author_id": 138206, "author_profile": "https://Stackoverflow.com/users/138206", "pm_score": 2, "selected": false, "text": "Log.Information(\"Hello, {0}\", username);\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6188/" ]
147,558
<p>How do I get command line utilities like ping to use the default proxy in Windows XP.</p> <p>proxycfg -u sets the proxy to the default (IE) proxy alright, but it doesn't seem to be working.</p> <p><strong>Update</strong>: I am behind a proxy and would like a way to check if a site is up or not hence trying to use ping! Also would like a way to telnet (without using Putty) to a specific site and port to check connectivity.</p>
[ { "answer_id": 148179, "author": "Alexander", "author_id": 16724, "author_profile": "https://Stackoverflow.com/users/16724", "pm_score": 2, "selected": false, "text": "$ nc yourproxy 3128\nCONNECT yourtelnetserver:23 HTTP/1.0\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147558", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11674/" ]
147,572
<pre><code>class someclass {}; class base { int a; int *pint; someclass objsomeclass; someclass* psomeclass; public: base() { objsomeclass = someclass(); psomeclass = new someclass(); pint = new int(); throw "constructor failed"; a = 43; } } int main() { base temp(); } </code></pre> <p>In the above code, the constructor throws. Which objects will be leaked, and how can the memory leaks be avoided?</p> <pre><code>int main() { base *temp = new base(); } </code></pre> <p>How about in the above code? How can the memory leaks be avoided after the constructor throws?</p>
[ { "answer_id": 147578, "author": "Colen", "author_id": 13500, "author_profile": "https://Stackoverflow.com/users/13500", "pm_score": -1, "selected": false, "text": "psomeclass = new someclass();\npint = new int(); \n" }, { "answer_id": 147585, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 0, "selected": false, "text": "psomeclass = NULL;\npint = NULL;\n/* So on for any pointers you allocate */\n\ntry {\n objsomeclass = someclass();\n psomeclass = new someclass();\n pint = new int(); \n throw \"constructor failed\";\n a = 43;\n }\n catch (...)\n {\n delete psomeclass;\n delete pint;\n throw;\n }\n" }, { "answer_id": 147587, "author": "KTC", "author_id": 12868, "author_profile": "https://Stackoverflow.com/users/12868", "pm_score": 3, "selected": false, "text": "class base {\n int a;\n boost::shared_ptr<int> pint;\n someclass objsomeclass;\n boost::shared_ptr<someclass> psomeclass;\n\n base() :\n objsomeclass( someclass() ),\n boost::shared_ptr<someclass> psomeclass( new someclass() ),\n boost::shared_ptr<int> pint( new int() )\n {\n throw \"constructor failed\";\n a = 43;\n }\n};\n" }, { "answer_id": 147589, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 6, "selected": true, "text": "class base{\n int a;\n scoped_ptr<int> pint;\n someclass objsomeclass;\n scoped_ptr<someclass> psomeclass;\n base() : \n pint( new int),\n objsomeclass( someclass()),\n psomeclass( new someclass())\n\n {\n throw \"constructor failed\";\n a = 43;\n }\n}\n" }, { "answer_id": 9045251, "author": "Tzvi R.", "author_id": 1175170, "author_profile": "https://Stackoverflow.com/users/1175170", "pm_score": 1, "selected": false, "text": "#include <stdio.h>\n\n\nclass A\n{\n int x;\n\npublic:\n A(int x) : x(x) { printf(\"A constructor [%d]\\n\", x); }\n ~A() { printf(\"A destructor [%d]\\n\", x); }\n};\n\n\nclass B\n{\n A a1;\n A a2;\n\npublic:\n B()\n : a1(3),\n a2(5)\n {\n printf(\"B constructor\\n\");\n throw \"failed\";\n }\n ~B() { printf(\"B destructor\\n\"); }\n};\n\n\nint main()\n{\n B b;\n\n return 0;\n}\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
147,626
<p>in Javascript, the following:</p> <pre><code>var test = '"the quick" "brown fox" "jumps over" "the lazy dog"'; var result = test.match(/".*?"/g); alert(result); </code></pre> <p>yields "the quick","brown fox","jumps over","the lazy dog"</p> <p>I want each matched element to be unquoted: the quick,brown fox,jumps over,the lazy dog</p> <p>what regexp will do this?</p>
[ { "answer_id": 147644, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 0, "selected": false, "text": "var test = '\"the quick\" \"brown fox\" \"jumps over\" \"the lazy dog\"';\n\nvar result = test.replace(/\"/, '');\n" }, { "answer_id": 147645, "author": "Gordon Wilson", "author_id": 23071, "author_profile": "https://Stackoverflow.com/users/23071", "pm_score": -1, "selected": false, "text": "var test = '\"the quick\" \"brown fox\" \"jumps over\" \"the lazy dog\"';\nvar result = test.replace(/\"(.*?)\"/g, \"$1\");\nalert(result);\n" }, { "answer_id": 147667, "author": "David Crow", "author_id": 2783, "author_profile": "https://Stackoverflow.com/users/2783", "pm_score": 4, "selected": true, "text": "var test = '\"the quick\" \"brown fox\" \"jumps over\" \"the lazy dog\"';\nvar result = test.match(/[^\"]+(?=(\" \")|\"$)/g);\nalert(result);\n" }, { "answer_id": 147668, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 2, "selected": false, "text": "var test = '\"the quick\" \"brown fox\" \"jumps over\" \"the lazy dog\"';\n\nvar result = test.match(/\".*?\"/g);\n// [\"the quick\",\"brown fox\",\"jumps over\",\"the lazy dog\"]\n\nresult.map(function(el) { return el.replace(/^\"|\"$/g, \"\"); });\n// [the quick,brown fox,jumps over,the lazy dog] \n" }, { "answer_id": 148133, "author": "grapefrukt", "author_id": 914, "author_profile": "https://Stackoverflow.com/users/914", "pm_score": 0, "selected": false, "text": "var test:String = '\"the quick\" \"brown fox\" \"jumps over\" \"the lazy dog\"';\nvar result:Array = test.match(/(?<=^\"| \").*?(?=\" |\"$)/g);\nfor each(var str:String in result){\n trace(str);\n}\n" }, { "answer_id": 148644, "author": "Scott Evernden", "author_id": 11397, "author_profile": "https://Stackoverflow.com/users/11397", "pm_score": 1, "selected": false, "text": "match(/[^\"]+(?=(\"\\s*\")|\"$)/g)\n" }, { "answer_id": 41868716, "author": "antoni", "author_id": 2012407, "author_profile": "https://Stackoverflow.com/users/2012407", "pm_score": 0, "selected": false, "text": "'\"What\\'s up?\"'" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11397/" ]
147,636
<p>What is the best way to detect if a user leaves a web page?</p> <p>The <code>onunload</code> JavaScript event doesn't work every time (the HTTP request takes longer than the time required to terminate the browser).</p> <p>Creating one will probably be blocked by current browsers.</p>
[ { "answer_id": 147765, "author": "Andreas Petersson", "author_id": 16542, "author_profile": "https://Stackoverflow.com/users/16542", "pm_score": 9, "selected": true, "text": "onbeforeunload" }, { "answer_id": 5893539, "author": "DuckMaestro", "author_id": 29152, "author_profile": "https://Stackoverflow.com/users/29152", "pm_score": 5, "selected": false, "text": "window.addEventListener('beforeunload', function(e) {\n var myPageIsDirty = ...; //you implement this logic...\n if(myPageIsDirty) {\n //following two lines will cause the browser to ask the user if they\n //want to leave. The text of this dialog is controlled by the browser.\n e.preventDefault(); //per the standard\n e.returnValue = ''; //required for Chrome\n }\n //else: user is allowed to leave without a warning dialog\n});\n" }, { "answer_id": 22992909, "author": "Merr Leader", "author_id": 1822265, "author_profile": "https://Stackoverflow.com/users/1822265", "pm_score": 2, "selected": false, "text": "window.onbeforeunload = function (e) {\n if ((window.event.clientY < 0)) {\n //window.localStorage.clear();\n //alert(\"Y coords: \" + window.event.clientY)\n }\n};\n" }, { "answer_id": 45119500, "author": "rustyx", "author_id": 485343, "author_profile": "https://Stackoverflow.com/users/485343", "pm_score": 4, "selected": false, "text": "$(document).bind(\"mouseleave\", function(e) {\n if (e.pageY - $(window).scrollTop() <= 1) { \n $('#BeforeYouLeaveDiv').show();\n }\n});\n" }, { "answer_id": 57188812, "author": "Adam", "author_id": 8545031, "author_profile": "https://Stackoverflow.com/users/8545031", "pm_score": 0, "selected": false, "text": "session_start();\n\n$_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];\n\nif(isset($_SESSION['userID'])){\n if(!strpos($_SESSION['activeID'], '-')){\n $_SESSION['activeID'] = $_SESSION['userID'].'-'.$_SESSION['activeID'];\n }\n}elseif(!isset($_SESSION['activeID'])){\n $_SESSION['activeID'] = time();\n}\n" }, { "answer_id": 57805547, "author": "Jeffrey Sweeney", "author_id": 1080079, "author_profile": "https://Stackoverflow.com/users/1080079", "pm_score": 3, "selected": false, "text": "// The delay should be longer than the heartbeat by a significant enough amount that there won't be false positives\nconst liveTimeoutDelay = 10000\nlet liveTimeout = null\n\nglobal.self.addEventListener('fetch', event => {\n clearTimeout(liveTimeout)\n liveTimeout = setTimeout(() => {\n console.log('User left page')\n // handle page leave\n }, liveTimeoutDelay)\n // Forward any events except for hearbeat events\n if (event.request.url.endsWith('/heartbeat')) {\n event.respondWith(\n new global.Response('Still here')\n )\n }\n})\n" }, { "answer_id": 60964951, "author": "Tal Yaron", "author_id": 3940742, "author_profile": "https://Stackoverflow.com/users/3940742", "pm_score": 3, "selected": false, "text": "beforeunload" }, { "answer_id": 72615899, "author": "Rohìt Jíndal", "author_id": 4116300, "author_profile": "https://Stackoverflow.com/users/4116300", "pm_score": 0, "selected": false, "text": "visibilitychange" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147636", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2721/" ]
147,646
<p>What would I do if I want to have a generic method that only accepts types that have overloaded an operator, for instance the subtraction operator. I tried using an interface as a constraint but interfaces can't have operator overloading. </p> <p>What is the best way to achieve this?</p>
[ { "answer_id": 147656, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 7, "selected": true, "text": "T result = Operator.Add(first, second); // implicit <T>; here\n" }, { "answer_id": 6481274, "author": "YellPika", "author_id": 349384, "author_profile": "https://Stackoverflow.com/users/349384", "pm_score": 3, "selected": false, "text": "ldarg.0\nldarg.1\nadd\nret\n" }, { "answer_id": 32074803, "author": "John Alexiou", "author_id": 380384, "author_profile": "https://Stackoverflow.com/users/380384", "pm_score": -1, "selected": false, "text": "IL" }, { "answer_id": 73243252, "author": "IsakGo", "author_id": 18730707, "author_profile": "https://Stackoverflow.com/users/18730707", "pm_score": 0, "selected": false, "text": "public class Example\n{\n public static T Add<T>(T left, T right, Func<T, T, T> addFunc) =>\n addFunc(left, right);\n}\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9107/" ]
147,650
<p>I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?</p>
[ { "answer_id": 4467129, "author": "heehoo", "author_id": 545560, "author_profile": "https://Stackoverflow.com/users/545560", "pm_score": 1, "selected": false, "text": "${workspace_loc:myeclipseprojectname/bin/paster}\n" }, { "answer_id": 4618535, "author": "jimmyorr", "author_id": 19239, "author_profile": "https://Stackoverflow.com/users/19239", "pm_score": 3, "selected": false, "text": "#!/usr/bin/env python\n\nfrom paste.script.serve import ServeCommand\n\nServeCommand(\"serve\").run([\"development.ini\"])\n" }, { "answer_id": 5829836, "author": "Mikael Lepistö", "author_id": 360060, "author_profile": "https://Stackoverflow.com/users/360060", "pm_score": 0, "selected": false, "text": "winpdb /usr/local/bin/paster serve development.ini\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18338/" ]
147,657
<p>According to MSDN </p> <pre><code>form.RightToLeftLayout = True; form.RightToLeft = ifWeWantRTL() ? RightToLeft.True : RightToLeft.False; </code></pre> <p>is enough to mirrow the form content for RTL languages.</p> <p>But controls placement gets mirrowed only for controls immediately on the form,<br> those inside a GroupBox or a Panel <strong>are not mirrowed</strong>, unless I put them on a TableLayoutPanel or a FlowLayoutPanel fisrt.</p> <p>This is a lot of manual work to place a TableLayoutPanel inside each GroupBox, and especially to rearrange the controls (one control per table cell, padding, margin, etc)</p> <p>Is there an easier way to make mirrowing work for all controls? </p> <p>Or at least, how can I bypass the rearranging step, for it is quite a task with our number of forms?</p> <hr> <p><strong>Edit</strong>: RightToLeft property for each control on the form by default is inherited,<br> so Panels and GroupBoxes always have the needed RightToLeft setting.<br> Nevertheless, I tryed to reassign it for them both programmatically and from designer, it did not help.</p>
[ { "answer_id": 148108, "author": "FryHard", "author_id": 231, "author_profile": "https://Stackoverflow.com/users/231", "pm_score": 4, "selected": true, "text": "private void SetRTL (bool setRTL)\n{\n ApplyRTL(setRTL, this);\n}\n\nprivate void ApplyRTL(bool yes, Control startControl)\n{\n if ((startControl is Panel ) || (startControl is GroupBox))\n {\n foreach (Control control in startControl.Controls)\n {\n control.Location = CalculateRTL(control.Location, startControl.Size, control.Size);\n }\n }\n\n foreach (Control control in startControl.Controls)\n ApplyRTL(yes, control);\n}\n\nprivate Point CalculateRTL (Point currentPoint, Size parentSize, Size currentSize)\n{\n return new Point(parentSize.Width - currentSize.Width - currentPoint.X, currentPoint.Y);\n}\n" }, { "answer_id": 6132845, "author": "Amro", "author_id": 770565, "author_profile": "https://Stackoverflow.com/users/770565", "pm_score": 2, "selected": false, "text": " protected override CreateParams CreateParams\n {\n get\n {\n return Control_RTF(base.CreateParams, base.RightToLeft);\n }\n }\n\n private CreateParams Control_RTF(CreateParams CP, RightToLeft rightToLeft)\n {\n if (rightToLeft == System.Windows.Forms.RightToLeft.Yes)\n CP.ExStyle = ((CP.ExStyle | 0x400000) | 0x100000);\n return CP;\n }\n" }, { "answer_id": 16366201, "author": "dahall", "author_id": 1196360, "author_profile": "https://Stackoverflow.com/users/1196360", "pm_score": 0, "selected": false, "text": "ContainerControl" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147657", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17495/" ]
147,659
<p>How can I get the list of available databases on a SQL Server instance? I'm planning to make a list of them in a combo box in VB.NET.</p>
[ { "answer_id": 147662, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 11, "selected": true, "text": "SELECT name FROM master.sys.databases" }, { "answer_id": 147707, "author": "GilM", "author_id": 10192, "author_profile": "https://Stackoverflow.com/users/10192", "pm_score": 6, "selected": false, "text": "SELECT [name]\nFROM master.dbo.sysdatabases\nWHERE dbid > 6\n" }, { "answer_id": 4922306, "author": "Frank", "author_id": 606557, "author_profile": "https://Stackoverflow.com/users/606557", "pm_score": 5, "selected": false, "text": "SELECT [name] \nFROM master.dbo.sysdatabases \nWHERE dbid > 4 \n" }, { "answer_id": 6139726, "author": "GilShalit", "author_id": 149769, "author_profile": "https://Stackoverflow.com/users/149769", "pm_score": 7, "selected": false, "text": "WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb');\n" }, { "answer_id": 6976252, "author": "Chris Diver", "author_id": 385149, "author_profile": "https://Stackoverflow.com/users/385149", "pm_score": 5, "selected": false, "text": "Dim server As New Microsoft.SqlServer.Management.Smo.Server(\"localhost\")\nFor Each db As Database In server.Databases\n Console.WriteLine(db.Name)\nNext\n" }, { "answer_id": 19628572, "author": "ManiG", "author_id": 2927018, "author_profile": "https://Stackoverflow.com/users/2927018", "pm_score": 3, "selected": false, "text": "SELECT [name] \nFROM master.dbo.sysdatabases \nWHERE dbid > 4 and [name] <> 'ReportServer' and [name] <> 'ReportServerTempDB'\n" }, { "answer_id": 20523195, "author": "Rob Prouse", "author_id": 30827, "author_profile": "https://Stackoverflow.com/users/30827", "pm_score": 3, "selected": false, "text": "using Microsoft.SqlServer.Management.Smo;\n\npublic static string[] GetDatabaseNames( string serverName )\n{\n var server = new Server( serverName );\n return ( from Database database in server.Databases \n where !database.IsSystemObject && !database.IsDatabaseSnapshot\n select database.Name \n ).ToArray();\n}\n" }, { "answer_id": 24529854, "author": "Tarık Özgün Güner", "author_id": 1786056, "author_profile": "https://Stackoverflow.com/users/1786056", "pm_score": 3, "selected": false, "text": "select DATABASE_NAME = db_name(s_mf.database_id)\nfrom sys.master_files s_mf\nwhere\n s_mf.state = 0 -- ONLINE\n and has_dbaccess(db_name(s_mf.database_id)) = 1\n and db_name(s_mf.database_id) NOT IN ('master', 'tempdb', 'model', 'msdb')\n and db_name(s_mf.database_id) not like 'ReportServer%'\ngroup by s_mf.database_id\norder by 1;\n" }, { "answer_id": 24823396, "author": "Balaji", "author_id": 3616924, "author_profile": "https://Stackoverflow.com/users/3616924", "pm_score": 5, "selected": false, "text": "select * from sys.databases\n" }, { "answer_id": 25827236, "author": "watch_amajigger", "author_id": 4038453, "author_profile": "https://Stackoverflow.com/users/4038453", "pm_score": 2, "selected": false, "text": " SELECT db.[name] as dbname \n FROM [master].[sys].[databases] db\n LEFT OUTER JOIN [master].[sys].[sysusers] su on su.sid = db.owner_sid\n WHERE su.sid is null\n order by db.[name]\n" }, { "answer_id": 41904965, "author": "thedanotto", "author_id": 2869337, "author_profile": "https://Stackoverflow.com/users/2869337", "pm_score": 0, "selected": false, "text": "show databases;" }, { "answer_id": 42220725, "author": "Luca", "author_id": 7561711, "author_profile": "https://Stackoverflow.com/users/7561711", "pm_score": -1, "selected": false, "text": "SELECT name FROM master.dbo.sysdatabases where sid <>0x01\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
147,669
<p>I've got a c# assembly which I'm invoking via COM from a Delphi (win32 native) application.</p> <p>This works on all the machines I've tested it on, except one.</p> <p>The problem is that the Delphi application gets "Class not registered" when trying to create the COM object.</p> <p>Now, when I look in the registry under <code>HKEY_CLASSES_ROOT\DelphiToCSharp\CLSID</code>, the GUID listed there is not the same as the assembly Guid in AssemblyInfo.cs. It should be the same - it IS the same on all the other computers where it's installed.</p> <p>I have tried <code>regasm /unregister delphitocsharp.dll</code>, and that removes the registry key. Then if I do <code>regasm delphitocsharp.dll</code>, the registry key returns, but the GUID is the same as before (ie. wrong), and Delphi still gets "Class not registered".</p> <p>DelphiToCSharp.dll on the working machine is identical (verified with md5) to the version on the non-working machine.</p> <p>All I can think of is that an old version of the dll was registered before, and there still exists some remnant of that file which is making regasm confused.</p> <p>How can I fix or at least further diagnose this issue?</p>
[ { "answer_id": 147785, "author": "nedruod", "author_id": 5504, "author_profile": "https://Stackoverflow.com/users/5504", "pm_score": 5, "selected": true, "text": "[Guid(\"00001111-2222-3333-4444-555566667777\"), ComVisible(true)] \npublic class MyCOMRegisteredClass\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/369/" ]
147,670
<p>How can I extract the list of available SQL servers in an SQL server group? I'm planning to put that list in a combo box in VB.NET.</p>
[ { "answer_id": 147680, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 4, "selected": true, "text": "osql -L\n" }, { "answer_id": 147694, "author": "Jiminy", "author_id": 23355, "author_profile": "https://Stackoverflow.com/users/23355", "pm_score": 0, "selected": false, "text": "[DllImport(\"odbc32.dll\", CharSet = CharSet.Ansi)]\n\nprivate static extern short SQLBrowseConnect(\nIntPtr hconn, StringBuilder inString,\nshort inStringLength, StringBuilder outString, short outStringLength, out short \noutLengthNeeded);\n" }, { "answer_id": 154618, "author": "Chris Tybur", "author_id": 741, "author_profile": "https://Stackoverflow.com/users/741", "pm_score": 3, "selected": false, "text": "Private Sub cmbServer_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbServer.DropDown\n Dim oTable As Data.DataTable\n Dim lstServers As List(Of String)\n Try\n If cmbServer.Items.Count = 0 Then\n System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor\n oTable = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources\n\n For Each oRow As DataRow In oTable.Rows\n If oRow(\"InstanceName\").ToString = \"\" Then\n cmbServer.Items.Add(oRow(\"ServerName\"))\n Else\n cmbServer.Items.Add(oRow(\"ServerName\").ToString & \"\\\" & oRow(\"InstanceName\").ToString)\n End If\n Next oRow\n End If\n Catch ex As Exception\n ErrHandler(\"frmLogin\", \"cmbServer_DropDown\", ex.Source, ex.Message, Ex.InnerException)\n Finally\n System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default\n\n If oTable IsNot Nothing Then\n oTable.Dispose()\n End If\n End Try\nEnd Sub\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147670", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
147,671
<p>I'm looking at ways to deploy a Ruby on Rails app (running on JRuby) to a Tomcat instance for testing.</p> <p>The tomcat instance is running on a Solaris server that I can SSH to. I've looked at using Capistrano, but there doesn't seem to be a lot out there about using it to deploy to Tomcat, or even about running it under JRuby, and I keep hitting bugs in Capistrano due to the Windows/JRuby environment my PC is running (yeah, it's corporate - not my choice, but I've got to live with it).</p> <p>I'm using warble to build the .war file, and the app deploys and runs fine once I manually copy it up and deploy it. I'm wanting something easier and more automated to actually get it there.</p> <p>Anyone done this before? Documentation on the web seems pretty thin.</p>
[ { "answer_id": 238652, "author": "Caleb Powell", "author_id": 31643, "author_profile": "https://Stackoverflow.com/users/31643", "pm_score": 4, "selected": false, "text": "desc \"Run the warble command to deploy the site\"\nnamespace(:deploy) do\n task :warble do\n run \". ~/.profile;cd #{release_path};warble\"\n end\nend\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147671", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14160/" ]
147,684
<p>I have a page which is largely created by DOM script, which generates a table of images (normal img elements) from several webcams (helping out a friend with a pet boarding and my HTML/DOM is a bit rusty).</p> <p>It works fine in FF3 or Chrome, but not in IE7, In fact, the whole table is not visible in IE (but the body background-color is applied).</p> <p>Looking at the page in IE, there are no script errors, the CSS appears to be applied OK, and the DOM appears to show all the cells and rows in the table, which are all generated.</p> <p>Using the IE Developer Toolbar, running the Image report even shows the images (even though they don't appear in the table and there is no evidence of the table in the page as rendered - even the text in the cells isn't rendered)</p> <p>In looking at the img elements and using the trace style feature, at one time, I saw that the img elements all had display : none, and it said inline style, but there's nothing in my code or stylesheet which does this. That problem appears to have gone away as I started to add explicit entries for every table element in my stylesheet.</p> <p>Where to start?</p> <pre><code>body { background-color : gray ; color : white ; margin : 0 ; font-family : Verdana, "lucida console", arial, sans-serif ; } #CameraPreviewParent { text-align : center ; width : 100% ; } #CameraTable { text-align : center ; width : 100% ; } #CameraLiveParent { text-align : center ; margin : 50px ; } #CameraLiveHeading { color : white ; } td.CameraCell { text-align : center ; } img.CameraImage { border : none ; } a:link, a:visited, a:active, a:hover { text-decoration : none ; color : inherit ; } table#CameraTable { color : white ; background-color : gray ; } td.CameraCell { color : white ; background-color : gray ; } </code></pre> <p>Removing the stylesheet completely has no effect.</p> <p>Here's the code of the page after generation (I apologize for the formatting from the DOM toolbar - I've tried to put in some linefeeds to make it easier to read):</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML Strict//EN"&gt;&lt;META http-equiv="Content-Type" content="text/html; charset=windows-1252"&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE&gt;&lt;/TITLE&gt; &lt;SCRIPT src="cameras.js" type="text/javascript"&gt; &lt;/SCRIPT&gt; &lt;SCRIPT type="text/javascript"&gt; function CallOnLoad() { document.title = PreviewPageTitle ; BuildPreview(document.getElementById("CameraPreviewParent")) ; } &lt;/SCRIPT&gt; &lt;/HEAD&gt; &lt;BODY&gt; &lt;!-- Any HTML can go here to modify page content/layout --&gt; &lt;DIV id="CameraPreviewParent"&gt; &lt;TABLE id="CameraTable" class="CameraTable"&gt; &lt;TR id="CameraRow0" class="CameraRow"&gt; &lt;TD id="CameraCell0" class="CameraCell"&gt;&lt;A id="CameraNameLink0" href="http://192.168.4.3:801" class="CameraNameLink"&gt;Luxury Suite 1 (1)&lt;/A&gt;&lt;BR /&gt;&lt;A id="CameraLink0" href="camlive.html?camIndex=0" class="CameraLink"&gt;&lt;IMG id="CameraImage0" title="Click For Live Video from Luxury Suite 1 (1)" height="0" alt="Click For Live Video from Luxury Suite 1 (1)" src="http://192.168.4.3:801/IMAGE.JPG" width="0" class="CameraImage" /&gt;&lt;/A&gt;&lt;/TD&gt; &lt;TD id="CameraCell1" class="CameraCell"&gt;&lt;A id="CameraNameLink1" href="http://192.168.4.3:802" class="CameraNameLink"&gt;Luxury Suite 2 (2)&lt;/A&gt;&lt;BR /&gt;&lt;A id="CameraLink1" href="camlive.html?camIndex=1" class="CameraLink"&gt;&lt;IMG id="CameraImage1" title="Click For Live Video from Luxury Suite 2 (2)" height="0" alt="Click For Live Video from Luxury Suite 2 (2)" src="http://192.168.4.3:802/IMAGE.JPG" width="0" class="CameraImage" /&gt;&lt;/A&gt;&lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;/DIV&gt;&lt;!-- This element is used to hold the preview --&gt; &lt;!-- Any HTML can go here to modify page content/layout --&gt; &lt;/BODY&gt; &lt;/HTML&gt; </code></pre> <p>Apparently the DOM code which inserts with width and height of the images is not working right in IE:</p> <pre><code>var PhotoWidth = 320 ; var PhotoHeight = 240 ; var image = document.createElement("img") ; image.setAttribute("id", "CameraImage" + camIndex) ; image.setAttribute("class", "CameraImage") ; image.setAttribute("src", thisCam.ImageURL()) ; image.setAttribute("width", PhotoWidth) ; image.setAttribute("height", PhotoHeight) ; image.setAttribute("alt", thisCam.PreviewAction()) ; image.setAttribute("title", thisCam.PreviewAction()) ; link.appendChild(image) ; </code></pre> <p><strong>The response about the require TBODY element when dynamically building tables appears to be the entire problem - this appears to even set the image width and height to 0 in the DOM!</strong></p>
[ { "answer_id": 147690, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 1, "selected": false, "text": "<script>" }, { "answer_id": 147698, "author": "Staale", "author_id": 3355, "author_profile": "https://Stackoverflow.com/users/3355", "pm_score": 3, "selected": true, "text": "document.createElement()" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18255/" ]
147,703
<p>I have a generic list, i.e. <code>List&lt;myclass&gt;</code>. Here <code>myclass</code> contains two string properties. </p> <p>How can I assign a datasource to the list collection?</p>
[ { "answer_id": 147728, "author": "Tim Jarvis", "author_id": 10387, "author_profile": "https://Stackoverflow.com/users/10387", "pm_score": 4, "selected": false, "text": "private void button2_Click(object sender, EventArgs e)\n{\n List<MyClass> list = new List<MyClass>();\n list.Add(new MyClass() { FirstName = \"Tim\", Lastname = \"Jarvis\"});\n list.Add(new MyClass() { FirstName = \"John\", Lastname = \"Doe\" });\n\n listBox1.DataSource = list;\n listBox1.DisplayMember = \"FirstName\"; // or override MyClass's ToString() method.\n}\n" }, { "answer_id": 147737, "author": "Eric Schoonover", "author_id": 3957, "author_profile": "https://Stackoverflow.com/users/3957", "pm_score": 1, "selected": false, "text": "List<>" }, { "answer_id": 147745, "author": "jussij", "author_id": 14738, "author_profile": "https://Stackoverflow.com/users/14738", "pm_score": 2, "selected": false, "text": " // create a dummy class\n public class MyClass\n {\n private string name;\n public MyClass(string name)\n {\n ItemName = name;\n }\n public string ItemName\n {\n get { return name; }\n set { name = value; }\n }\n }\n" }, { "answer_id": 147746, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "System.ComponentModel.BindingList<myClass> bindingList = new System.ComponentModel.BindingList<myClass>(originalList);\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
147,713
<p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p> <pre><code>unsigned long value = 0xdeadbeef; value &amp;= ~(1&lt;&lt;10); </code></pre> <p>How do I do that in Python ?</p>
[ { "answer_id": 147716, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "value = 0xdeadbeef\nvalue &= ~(1<<10)\n" }, { "answer_id": 147718, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 2, "selected": false, "text": ">>> value = 0xdeadbeef\n>>> value &= ~(1<<10)\n>>> hex (value)\n'0xdeadbaef'\n" }, { "answer_id": 147721, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 2, "selected": false, "text": "value = 0xDEADBEEF\nvalue &= ~(1<<10)\nprint value\n\"0x%08X\" % value\n" }, { "answer_id": 147722, "author": "Martin W", "author_id": 14199, "author_profile": "https://Stackoverflow.com/users/14199", "pm_score": 3, "selected": false, "text": "value = 0xdeadbeef\nvalue &= ~(1 << 10)\n" }, { "answer_id": 147736, "author": "Fredrik Johansson", "author_id": 1163767, "author_profile": "https://Stackoverflow.com/users/1163767", "pm_score": 7, "selected": true, "text": "&" }, { "answer_id": 45564104, "author": "witold-gren", "author_id": 2458471, "author_profile": "https://Stackoverflow.com/users/2458471", "pm_score": 2, "selected": false, "text": "a = int('00001111', 2)\nb = int('11110000', 2)\nbin(a & b)[2:].zfill(8)\nbin(a | b)[2:].zfill(8)\nbin(a << 2)[2:].zfill(8)\nbin(a >> 2)[2:].zfill(8)\nbin(a ^ b)[2:].zfill(8)\nint(bin(a | b)[2:].zfill(8), 2)\n" }, { "answer_id": 49942785, "author": "Boern", "author_id": 1701600, "author_profile": "https://Stackoverflow.com/users/1701600", "pm_score": 3, "selected": false, "text": "def get_bit(value, n):\n return ((value >> n & 1) != 0)\n\ndef set_bit(value, n):\n return value | (1 << n)\n\ndef clear_bit(value, n):\n return value & ~(1 << n)\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147713", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16144/" ]
147,714
<p>I would like to refer HTML templates designed/developed especially for form based Web Applications.</p> <p>I have been searching them but am not able to find out which I find better.</p> <p>Regards, Jatan</p>
[ { "answer_id": 152256, "author": "garrow", "author_id": 21095, "author_profile": "https://Stackoverflow.com/users/21095", "pm_score": 2, "selected": false, "text": "<style type=\"text/css\" media=\"screen\">\n div#page { width:900px; margin:0; auto; }\n</style>\n<body>\n <div id=\"page\">\n <div id=\"header\">\n <!-- Menu Goes Here! -->\n </div>\n <div id=\"content\">\n <!-- Put some Forms n stuff here -->\n </div>\n </div> \n</body>\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/959/" ]
147,719
<p>Is there a Delphi equivalent of the C# #if(DEBUG) compiler directive?</p>
[ { "answer_id": 147725, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 6, "selected": true, "text": "{$IFDEF DEBUG}\n...\n{$ENDIF}\n" }, { "answer_id": 147855, "author": "PatrickvL", "author_id": 12170, "author_profile": "https://Stackoverflow.com/users/12170", "pm_score": 3, "selected": false, "text": "{$IF NOT DECLARED(SOME_SYMBOL)} \n // Mind you : The NOT above is optional\n{$ELSE}\n{$IFEND}\n" }, { "answer_id": 153043, "author": "JosephStyons", "author_id": 672, "author_profile": "https://Stackoverflow.com/users/672", "pm_score": 2, "selected": false, "text": "{$IFDEF}\n{$ELSE}\n{$ENDIF}\n{$IFNDEF} //if *not* defined\n" }, { "answer_id": 1572604, "author": "Lawrence Barsanti", "author_id": 13054, "author_profile": "https://Stackoverflow.com/users/13054", "pm_score": 3, "selected": false, "text": "ReportMemoryLeaksOnShutdown := DebugHook <> 0; // show memory leaks when debugging\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
147,726
<p>One of the feature requests I've got for the program I'm working on is to be able to save the list of credentials users enter in, so they can be shared around. The specific use case that inspired this request was using our program on a large corporate network, made up of fairly good LANs connected by a flaky WAN. The idea was that, instead of having our program beat against the WAN when it's down, they'd send a 'configuration' file containing the closely-guarded admin credentials, run it in each LAN and zip up the results and e-mail it back.</p> <p>Yeah.</p> <p>My initial instinct is to scoff at this request - saving passwords? <em>really?</em> and surely the network division of the company would prefer you to try and sell whatever WAN products they have - but it turns out one of the classes I use the credentials for can take a SecureString, and, well, it's always good to look out for ways you can save people some effort. That got me to wondering:</p> <p>Is it possible to save an encrypted SecureString, so that I can save the sensitive data to a file and open it up someplace else?</p> <p>What are your thoughts, Stack Overflow?</p>
[ { "answer_id": 317690, "author": "configurator", "author_id": 9536, "author_profile": "https://Stackoverflow.com/users/9536", "pm_score": 3, "selected": false, "text": "using System.Security.Cryptography;\n\npublic byte[] GetPasswordHash(string username, string password, string salt)\n{\n // get salted byte[] buffer, containing username, password and some (constant) salt\n byte[] buffer;\n using (MemoryStream stream = new MemoryStream())\n using (StreamWriter writer = new StreamWriter(stream))\n {\n writer.Write(salt);\n writer.Write(username);\n writer.Write(password);\n writer.Flush();\n\n buffer = stream.ToArray();\n }\n\n // create a hash\n SHA1 sha1 = SHA1.Create();\n return sha1.ComputeHash(buffer);\n}\n" }, { "answer_id": 7329939, "author": "balexandre", "author_id": 28004, "author_profile": "https://Stackoverflow.com/users/28004", "pm_score": 0, "selected": false, "text": "SecureString" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5133/" ]
147,741
<p>In a text file, there is a string "I don't like this".</p> <p>However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use </p> <pre><code>f1 = open (file1, "r") text = f1.read() </code></pre> <p>command to do the reading.</p> <p>Now, is it possible to read the string in such a way that when it is read into the string, it is "I don't like this", instead of "I don\xe2\x80\x98t like this like this"?</p> <p>Second edit: I have seen some people use mapping to solve this problem, but really, is there no built-in conversion that does this kind of ANSI to unicode ( and vice versa) conversion?</p>
[ { "answer_id": 147751, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 1, "selected": false, "text": "text = text.replace (u\"\\u2018\", \"'\")\n" }, { "answer_id": 147755, "author": "xardias", "author_id": 23156, "author_profile": "https://Stackoverflow.com/users/23156", "pm_score": 1, "selected": false, "text": ">>> test = u\"I don\\u2018t like this\"\n>>> test\nu'I don\\u2018t like this'\n>>> print test\nI don‘t like this\n" }, { "answer_id": 147756, "author": "Jay", "author_id": 20840, "author_profile": "https://Stackoverflow.com/users/20840", "pm_score": 9, "selected": true, "text": "import codecs\nwith codecs.open('unicode.rst', encoding='utf-8') as f:\n for line in f:\n print repr(line)\n" }, { "answer_id": 147762, "author": "Logan", "author_id": 3518, "author_profile": "https://Stackoverflow.com/users/3518", "pm_score": 3, "selected": false, "text": "punctuation = {\n u'\\u2018': \"'\",\n u'\\u2019': \"'\",\n}\nfor src, dest in punctuation.iteritems():\n text = text.replace(src, dest)\n" }, { "answer_id": 147790, "author": "DzinX", "author_id": 18745, "author_profile": "https://Stackoverflow.com/users/18745", "pm_score": 4, "selected": false, "text": ">>> text = u'‘'\n>>> print repr(text)\nu'\\u2018'\n" }, { "answer_id": 147799, "author": "DzinX", "author_id": 18745, "author_profile": "https://Stackoverflow.com/users/18745", "pm_score": 2, "selected": false, "text": ">>> print repr(text)\n'I don\\\\u2018t like this'\n" }, { "answer_id": 154782, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": ">>> import iconvcodec\n>>> from locale import setlocale, LC_ALL\n>>> setlocale(LC_ALL, '')\n>>> u'\\u2018'.encode('ascii//translit')\n\"'\"\n" }, { "answer_id": 53548660, "author": "Stein", "author_id": 8554558, "author_profile": "https://Stackoverflow.com/users/8554558", "pm_score": 4, "selected": false, "text": "f = open (file.txt, 'r', encoding='utf-8')\ntext = f.read()\nf.close()\n" }, { "answer_id": 65541530, "author": "nvd", "author_id": 1943525, "author_profile": "https://Stackoverflow.com/users/1943525", "pm_score": 1, "selected": false, "text": "with open(fName, \"rb\") as fData:\n lines = fData.read().splitlines()\n lines = [line.decode(\"utf-8\", errors=\"ignore\") for line in lines]\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
147,752
<p>In the admin interface and newforms there is the brilliant helper of being able to define choices. You can use code like this:</p> <pre><code>APPROVAL_CHOICES = ( ('yes', 'Yes'), ('no', 'No'), ('cancelled', 'Cancelled'), ) client_approved = models.CharField(choices=APPROVAL_CHOICES) </code></pre> <p>to create a drop down box in your form and force the user to choose one of those options.</p> <p>I'm just wondering if there is a way to define a set of choices where multiple can be chosen using checkboxes? (Would also be nice to be able to say that the user can select a maximum number of them.) It seems like it's a feature that is probably implemented, it's just I can't seem to find it in the documentation.</p>
[ { "answer_id": 147793, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 7, "selected": true, "text": "class MyForm(forms.Form):\n my_field = forms.MultipleChoiceField(choices=SOME_CHOICES, widget=forms.CheckboxSelectMultiple())\n\n def clean_my_field(self):\n if len(self.cleaned_data['my_field']) > 3:\n raise forms.ValidationError('Select no more than 3.')\n return self.cleaned_data['my_field']\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23366/" ]
147,801
<p>What is the best way to parse a float in CSharp? I know about TryParse, but what I'm particularly wondering about is dots, commas etc.</p> <p>I'm having problems with my website. On my dev server, the ',' is for decimals, the '.' for separator. On the prod server though, it is the other way round. How can I best capture this?</p>
[ { "answer_id": 147806, "author": "TcKs", "author_id": 20382, "author_profile": "https://Stackoverflow.com/users/20382", "pm_score": 3, "selected": false, "text": "string strFloat = (15.789f).ToString(System.Globalization.CultureInfo.InvariantInfo);\nfloat numFloat = float.Parse(System.Globalization.CultureInfo.InvariantInfo, strFloat);\nstring strNow = DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantInfo);\nDateTime now = DateTime.Parse(System.Globalization.CultureInfo.InvariantInfo, strNow);\n" }, { "answer_id": 147811, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 6, "selected": false, "text": "string s = \"123,456.789\";\nfloat f = float.Parse(s, CultureInfo.InvariantCulture);\n" }, { "answer_id": 147813, "author": "Davy Landman", "author_id": 11098, "author_profile": "https://Stackoverflow.com/users/11098", "pm_score": 3, "selected": false, "text": "double number = Double.Parse(\"42,22\", new CultureInfo(\"nl-NL\").NumberFormat); // dutch number formatting\n" }, { "answer_id": 152226, "author": "stefano m", "author_id": 19261, "author_profile": "https://Stackoverflow.com/users/19261", "pm_score": 0, "selected": false, "text": "System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CurrentCulture;\n" }, { "answer_id": 66703993, "author": "TarmoPikaro", "author_id": 2338477, "author_profile": "https://Stackoverflow.com/users/2338477", "pm_score": 0, "selected": false, "text": "var CurrentCultureInfo = new CultureInfo(\"en\", false);\nCurrentCultureInfo.NumberFormat.NumberDecimalSeparator = \".\";\nCurrentCultureInfo.NumberFormat.CurrencyDecimalSeparator = \".\";\nThread.CurrentThread.CurrentUICulture = CurrentCultureInfo;\nThread.CurrentThread.CurrentCulture = CurrentCultureInfo;\nCultureInfo.DefaultThreadCurrentCulture = CurrentCultureInfo;\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
147,802
<p>I made a Java Applet with some Standard GUI Components on it. I used the <a href="http://www.miglayout.com/" rel="nofollow noreferrer">MigLayout</a> Manager.</p> <p>If I move the mouse slowly over the various GUI Components everything appears to be fine, but if I move the mouse fast, it flickers.</p> <p>What could make that nasty ugly redraw? (Core 2 Duo 6300, 2GB Ram, Windows XP)</p>
[ { "answer_id": 147898, "author": "Epaga", "author_id": 6583, "author_profile": "https://Stackoverflow.com/users/6583", "pm_score": 3, "selected": true, "text": "repaint()" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21027/" ]
147,816
<p>Suppose I have written a decorator that does something very generic. For example, it might convert all arguments to a specific type, perform logging, implement memoization, etc.</p> <p>Here is an example:</p> <pre><code>def args_as_ints(f): def g(*args, **kwargs): args = [int(x) for x in args] kwargs = dict((k, int(v)) for k, v in kwargs.items()) return f(*args, **kwargs) return g @args_as_ints def funny_function(x, y, z=3): """Computes x*y + 2*z""" return x*y + 2*z &gt;&gt;&gt; funny_function("3", 4.0, z="5") 22 </code></pre> <p>Everything well so far. There is one problem, however. The decorated function does not retain the documentation of the original function:</p> <pre><code>&gt;&gt;&gt; help(funny_function) Help on function g in module __main__: g(*args, **kwargs) </code></pre> <p>Fortunately, there is a workaround:</p> <pre><code>def args_as_ints(f): def g(*args, **kwargs): args = [int(x) for x in args] kwargs = dict((k, int(v)) for k, v in kwargs.items()) return f(*args, **kwargs) g.__name__ = f.__name__ g.__doc__ = f.__doc__ return g @args_as_ints def funny_function(x, y, z=3): """Computes x*y + 2*z""" return x*y + 2*z </code></pre> <p>This time, the function name and documentation are correct:</p> <pre><code>&gt;&gt;&gt; help(funny_function) Help on function funny_function in module __main__: funny_function(*args, **kwargs) Computes x*y + 2*z </code></pre> <p>But there is still a problem: the function signature is wrong. The information "*args, **kwargs" is next to useless.</p> <p>What to do? I can think of two simple but flawed workarounds:</p> <p>1 -- Include the correct signature in the docstring:</p> <pre><code>def funny_function(x, y, z=3): """funny_function(x, y, z=3) -- computes x*y + 2*z""" return x*y + 2*z </code></pre> <p>This is bad because of the duplication. The signature will still not be shown properly in automatically generated documentation. It's easy to update the function and forget about changing the docstring, or to make a typo. [<i>And yes, I'm aware of the fact that the docstring already duplicates the function body. Please ignore this; funny_function is just a random example.</i>]</p> <p>2 -- Not use a decorator, or use a special-purpose decorator for every specific signature:</p> <pre><code>def funny_functions_decorator(f): def g(x, y, z=3): return f(int(x), int(y), z=int(z)) g.__name__ = f.__name__ g.__doc__ = f.__doc__ return g </code></pre> <p>This works fine for a set of functions that have identical signature, but it's useless in general. As I said in the beginning, I want to be able to use decorators entirely generically.</p> <p>I'm looking for a solution that is fully general, and automatic.</p> <p>So the question is: is there a way to edit the decorated function signature after it has been created?</p> <p>Otherwise, can I write a decorator that extracts the function signature and uses that information instead of "*kwargs, **kwargs" when constructing the decorated function? How do I extract that information? How should I construct the decorated function -- with exec?</p> <p>Any other approaches?</p>
[ { "answer_id": 147844, "author": "DzinX", "author_id": 18745, "author_profile": "https://Stackoverflow.com/users/18745", "pm_score": 3, "selected": false, "text": "decorator" }, { "answer_id": 147878, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 8, "selected": true, "text": "$ pip install decorator\n" }, { "answer_id": 25555400, "author": "macm", "author_id": 506038, "author_profile": "https://Stackoverflow.com/users/506038", "pm_score": 3, "selected": false, "text": "\nimport wrapt\nimport inspect\n\n@wrapt.decorator\ndef args_as_ints(wrapped, instance, args, kwargs):\n if instance is None:\n if inspect.isclass(wrapped):\n # Decorator was applied to a class.\n return wrapped(*args, **kwargs)\n else:\n # Decorator was applied to a function or staticmethod.\n return wrapped(*args, **kwargs)\n else:\n if inspect.isclass(instance):\n # Decorator was applied to a classmethod.\n return wrapped(*args, **kwargs)\n else:\n # Decorator was applied to an instancemethod.\n return wrapped(*args, **kwargs)\n\n\n@args_as_ints\ndef funny_function(x, y, z=3):\n \"\"\"Computes x*y + 2*z\"\"\"\n return x * y + 2 * z\n\n\n>>> funny_function(3, 4, z=5))\n# 22\n\n>>> help(funny_function)\nHelp on function funny_function in module __main__:\n\nfunny_function(x, y, z=3)\n Computes x*y + 2*z\n" }, { "answer_id": 31540540, "author": "Tim", "author_id": 302343, "author_profile": "https://Stackoverflow.com/users/302343", "pm_score": 5, "selected": false, "text": "functools" }, { "answer_id": 55163816, "author": "smarie", "author_id": 7262247, "author_profile": "https://Stackoverflow.com/users/7262247", "pm_score": 2, "selected": false, "text": "help" }, { "answer_id": 69434291, "author": "Yilmaz", "author_id": 10262805, "author_profile": "https://Stackoverflow.com/users/10262805", "pm_score": 1, "selected": false, "text": "def args_as_ints(f):\n def g(*args, **kwargs):\n args = [int(x) for x in args]\n kwargs = dict((k, int(v)) for k, v in kwargs.items())\n return f(*args, **kwargs)\n g.__name__ = f.__name__\n g.__doc__ = f.__doc__\n return g\n" }, { "answer_id": 70331050, "author": "Dogeek", "author_id": 4496048, "author_profile": "https://Stackoverflow.com/users/4496048", "pm_score": 2, "selected": false, "text": "from inspect import signature\n\n\ndef args_as_ints(f):\n def g(*args, **kwargs):\n args = [int(x) for x in args]\n kwargs = dict((k, int(v)) for k, v in kwargs.items())\n return f(*args, **kwargs)\n sig = signature(f)\n g.__signature__ = sig\n g.__doc__ = f.__doc__\n g.__annotations__ = f.__annotations__\n g.__name__ = f.__name__\n return g\n\n@args_as_ints\ndef funny_function(x, y, z=3):\n \"\"\"Computes x*y + 2*z\"\"\"\n return x*y + 2*z\n\n>>> funny_function(\"3\", 4.0, z=\"5\")\n22\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1163767/" ]
147,821
<p>I'm creating an installation script for an application that I'm developing and need to create databases dynamically from within PHP. I've got it to create the database but now I need to load in several .sql files. I had planned to open the file and mysql_query it a line at a time - until I looked at the schema files and realised they aren't just one query per line.</p> <p>So, how do I load an sql file from within PHP (as phpMyAdmin does with its import command)?</p>
[ { "answer_id": 147842, "author": "olle", "author_id": 22422, "author_profile": "https://Stackoverflow.com/users/22422", "pm_score": 2, "selected": false, "text": "mysql_query(\"LOAD DATA LOCAL INFILE '/path/to/file' INTO TABLE mytable\");\n" }, { "answer_id": 147914, "author": "cam8001", "author_id": 15088, "author_profile": "https://Stackoverflow.com/users/15088", "pm_score": 2, "selected": false, "text": "$query = '';\n$handle = @fopen(\"/sqlfile.sql\", \"r\");\n\nif ($handle) {\n while (!feof($handle)) {\n $query.= fgets($handle, 4096);\n\n if (substr(rtrim($query), -1) === ';') {\n // ...run your query, then unset the string\n $query = '';\n }\n }\n\n fclose($handle);\n}\n" }, { "answer_id": 147971, "author": "dbr", "author_id": 745, "author_profile": "https://Stackoverflow.com/users/745", "pm_score": 2, "selected": false, "text": "all_query = read_file(\"/my/file.sql\")\ncon = mysql_connect(\"localhost\")\ncon.mysql_select_db(\"mydb\")\ncon.mysql_query(all_query)\ncon.close()\n" }, { "answer_id": 149456, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 5, "selected": false, "text": "-- Comment lines cannot be prepared as statements\n-- This is a MySQL client tool builtin command. \n-- It cannot be prepared or executed by server.\nUSE testdb;\n\n-- This is a multi-line statement.\nCREATE TABLE foo (\n string VARCHAR(100)\n);\n\n-- This statement is not supported as a prepared statement.\nLOAD DATA INFILE 'datafile.txt' INTO TABLE foo;\n\n-- This statement is not terminated with a semicolon.\nDELIMITER //\n\n-- This multi-line statement contains a semicolon \n-- but not as the statement terminator.\nCREATE PROCEDURE simpleproc (OUT param1 INT)\nBEGIN\n SELECT COUNT(*) INTO param1 FROM foo;\nEND\n// \n" }, { "answer_id": 149806, "author": "phatduckk", "author_id": 3896, "author_profile": "https://Stackoverflow.com/users/3896", "pm_score": 3, "selected": false, "text": "mysqli" }, { "answer_id": 4670704, "author": "Chip", "author_id": 572965, "author_profile": "https://Stackoverflow.com/users/572965", "pm_score": 0, "selected": false, "text": "$sql = explode(\";\",file_get_contents('[your dump file].sql'));// \n\nforeach($sql as $query)\n mysql_query($query);\n" }, { "answer_id": 5824563, "author": "Plahcinski", "author_id": 590949, "author_profile": "https://Stackoverflow.com/users/590949", "pm_score": 2, "selected": false, "text": "$file_content = file('myfile.sql');\n$query = \"\";\nforeach($file_content as $sql_line){\n if(trim($sql_line) != \"\" && strpos($sql_line, \"--\") === false){\n $query .= $sql_line;\n if (substr(rtrim($query), -1) == ';'){\n echo $query;\n $result = mysql_query($query)or die(mysql_error());\n $query = \"\";\n }\n }\n }\n" }, { "answer_id": 6607547, "author": "Abu Sadat Mohammed Yasin", "author_id": 833071, "author_profile": "https://Stackoverflow.com/users/833071", "pm_score": 6, "selected": false, "text": "<?php\nini_set('memory_limit', '5120M');\nset_time_limit ( 0 );\n/***************************************************************************\n* sql_parse.php\n* -------------------\n* begin : Thu May 31, 2001\n* copyright : (C) 2001 The phpBB Group\n* email : support@phpbb.com\n*\n* $Id: sql_parse.php,v 1.8 2002/03/18 23:53:12 psotfx Exp $\n*\n****************************************************************************/\n\n/***************************************************************************\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n ***************************************************************************/\n\n/***************************************************************************\n*\n* These functions are mainly for use in the db_utilities under the admin\n* however in order to make these functions available elsewhere, specifically\n* in the installation phase of phpBB I have seperated out a couple of\n* functions into this file. JLH\n*\n\\***************************************************************************/\n\n//\n// remove_comments will strip the sql comment lines out of an uploaded sql file\n// specifically for mssql and postgres type files in the install....\n//\nfunction remove_comments(&$output)\n{\n$lines = explode(\"\\n\", $output);\n$output = \"\";\n\n// try to keep mem. use down\n$linecount = count($lines);\n\n$in_comment = false;\nfor($i = 0; $i < $linecount; $i++)\n{\n if( preg_match(\"/^\\/\\*/\", preg_quote($lines[$i])) )\n {\n $in_comment = true;\n }\n\n if( !$in_comment )\n {\n $output .= $lines[$i] . \"\\n\";\n }\n\n if( preg_match(\"/\\*\\/$/\", preg_quote($lines[$i])) )\n {\n $in_comment = false;\n }\n}\n\nunset($lines);\nreturn $output;\n}\n\n//\n// remove_remarks will strip the sql comment lines out of an uploaded sql file\n//\nfunction remove_remarks($sql)\n{\n$lines = explode(\"\\n\", $sql);\n\n// try to keep mem. use down\n$sql = \"\";\n\n$linecount = count($lines);\n$output = \"\";\n\nfor ($i = 0; $i < $linecount; $i++)\n{\n if (($i != ($linecount - 1)) || (strlen($lines[$i]) > 0))\n {\n if (isset($lines[$i][0]) && $lines[$i][0] != \"#\")\n {\n $output .= $lines[$i] . \"\\n\";\n }\n else\n {\n $output .= \"\\n\";\n }\n // Trading a bit of speed for lower mem. use here.\n $lines[$i] = \"\";\n }\n}\n\nreturn $output;\n\n}\n\n//\n// split_sql_file will split an uploaded sql file into single sql statements.\n// Note: expects trim() to have already been run on $sql.\n//\nfunction split_sql_file($sql, $delimiter)\n{\n// Split up our string into \"possible\" SQL statements.\n$tokens = explode($delimiter, $sql);\n\n// try to save mem.\n$sql = \"\";\n$output = array();\n\n// we don't actually care about the matches preg gives us.\n$matches = array();\n\n// this is faster than calling count($oktens) every time thru the loop.\n$token_count = count($tokens);\nfor ($i = 0; $i < $token_count; $i++)\n{\n // Don't wanna add an empty string as the last thing in the array.\n if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0)))\n {\n // This is the total number of single quotes in the token.\n $total_quotes = preg_match_all(\"/'/\", $tokens[$i], $matches);\n // Counts single quotes that are preceded by an odd number of backslashes,\n // which means they're escaped quotes.\n $escaped_quotes = preg_match_all(\"/(?<!\\\\\\\\)(\\\\\\\\\\\\\\\\)*\\\\\\\\'/\", $tokens[$i], $matches);\n\n $unescaped_quotes = $total_quotes - $escaped_quotes;\n\n // If the number of unescaped quotes is even, then the delimiter did NOT occur inside a string literal.\n if (($unescaped_quotes % 2) == 0)\n {\n // It's a complete sql statement.\n $output[] = $tokens[$i];\n // save memory.\n $tokens[$i] = \"\";\n }\n else\n {\n // incomplete sql statement. keep adding tokens until we have a complete one.\n // $temp will hold what we have so far.\n $temp = $tokens[$i] . $delimiter;\n // save memory..\n $tokens[$i] = \"\";\n\n // Do we have a complete statement yet?\n $complete_stmt = false;\n\n for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++)\n {\n // This is the total number of single quotes in the token.\n $total_quotes = preg_match_all(\"/'/\", $tokens[$j], $matches);\n // Counts single quotes that are preceded by an odd number of backslashes,\n // which means they're escaped quotes.\n $escaped_quotes = preg_match_all(\"/(?<!\\\\\\\\)(\\\\\\\\\\\\\\\\)*\\\\\\\\'/\", $tokens[$j], $matches);\n\n $unescaped_quotes = $total_quotes - $escaped_quotes;\n\n if (($unescaped_quotes % 2) == 1)\n {\n // odd number of unescaped quotes. In combination with the previous incomplete\n // statement(s), we now have a complete statement. (2 odds always make an even)\n $output[] = $temp . $tokens[$j];\n\n // save memory.\n $tokens[$j] = \"\";\n $temp = \"\";\n\n // exit the loop.\n $complete_stmt = true;\n // make sure the outer loop continues at the right point.\n $i = $j;\n }\n else\n {\n // even number of unescaped quotes. We still don't have a complete statement.\n // (1 odd and 1 even always make an odd)\n $temp .= $tokens[$j] . $delimiter;\n // save memory.\n $tokens[$j] = \"\";\n }\n\n } // for..\n } // else\n }\n}\n\nreturn $output;\n}\n\n$dbms_schema = 'yourfile.sql';\n\n$sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema)) or die('problem ');\n$sql_query = remove_remarks($sql_query);\n$sql_query = split_sql_file($sql_query, ';');\n\n$host = 'localhost';\n$user = 'user';\n$pass = 'pass';\n$db = 'database_name';\n\n// mysql_* is deprecated, prefer using mysqli_* instead\n// mysql_connect($host,$user,$pass) or die('error connection');\n// mysql_select_db($db) or die('error database selection');\n$connection = mysqli_connect($host,$user,$pass) or die('error connection');\nmysqli_select_db($connection, $db) or die('error database selection');\n\n$i=1;\nforeach($sql_query as $sql){\n echo $i++;\n echo \"<br />\";\n // mysql_* is deprecated, prefer using mysqli_* instead\n // mysql_query($sql) or die('error in query');\n mysqli_query($connection, $sql) or die('error in query');\n}\n" }, { "answer_id": 7178917, "author": "Luis Granja", "author_id": 910060, "author_profile": "https://Stackoverflow.com/users/910060", "pm_score": 6, "selected": false, "text": "$db = new PDO($dsn, $user, $password);\n\n$sql = file_get_contents('file.sql');\n\n$qr = $db->exec($sql);\n" }, { "answer_id": 7374348, "author": "Lorenz Lo Sauer", "author_id": 901946, "author_profile": "https://Stackoverflow.com/users/901946", "pm_score": 1, "selected": false, "text": " You have an error in your SQL syntax; check the manual that corresponds to your\n MySQL server version for the right syntax to use near 'INSERT INTO `outputdb:`\n (`intid`, `entry_id`, `definition`) VALUES...\n" }, { "answer_id": 7879709, "author": "Ricky", "author_id": 1011385, "author_profile": "https://Stackoverflow.com/users/1011385", "pm_score": 2, "selected": false, "text": "$file_content = file('myfile.sql');\n$query = \"\";\nforeach($file_content as $sql_line){\nif(trim($sql_line) != \"\" && strpos($sql_line, \"--\") === false){\n $query .= $sql_line;\n if (substr(rtrim($query), -1) == ';'){\n echo $query;\n $result = mysql_query($query)or die(mysql_error());\n $query = \"\";\n }\n }\n}\n" }, { "answer_id": 7973005, "author": "Nono", "author_id": 584262, "author_profile": "https://Stackoverflow.com/users/584262", "pm_score": 2, "selected": false, "text": "// SQL File\n$SQLFile = 'YourSQLFile.sql';\n\n// Server Name\n$hostname = 'localhost';\n\n// User Name\n$db_user = 'root';\n\n// User Password\n$db_password = '';\n\n// DBName\n$database_name = 'YourDBName';\n\n// Connect MySQL\n$link = mysql_connect($hostname, $db_user, $db_password);\n\nif (!$link) {\ndie(\"MySQL Connection error\");\n}\n\n// Select MySQL DB\nmysql_select_db($database_name, $link) or die(\"Wrong MySQL Database\");\n\n// Function For Run Multiple Query From .SQL File\nfunction MultiQuery($sqlfile, $sqldelimiter = ';') {\nset_time_limit(0);\n\nif (is_file($sqlfile) === true) {\n$sqlfile = fopen($sqlfile, 'r');\n\nif (is_resource($sqlfile) === true) {\n$query = array();\necho \"<table cellspacing='3' cellpadding='3' border='0'>\";\n\nwhile (feof($sqlfile) === false) {\n$query[] = fgets($sqlfile);\n\nif (preg_match('~' . preg_quote($sqldelimiter, '~') . '\\s*$~iS', end($query)) === 1) {\n$query = trim(implode('', $query));\n\nif (mysql_query($query) === false) {\necho '<tr><td>ERROR:</td><td> ' . $query . '</td></tr>';\n} else {\necho '<tr><td>SUCCESS:</td><td>' . $query . '</td></tr>';\n}\n\nwhile (ob_get_level() &gt; 0) {\nob_end_flush();\n}\n\nflush();\n}\n\nif (is_string($query) === true) {\n$query = array();\n}\n}\necho \"</table>\";\n\nreturn fclose($sqlfile);\n}\n}\n\nreturn false;\n}\n\n/* * * Use Function Like This: ** */\n\nMultiQuery($SQLFile);\n" }, { "answer_id": 8788450, "author": "Vijin Paulraj", "author_id": 972501, "author_profile": "https://Stackoverflow.com/users/972501", "pm_score": 0, "selected": false, "text": "//Empty all tables' contents\n\n$result_t = mysql_query(\"SHOW TABLES\");\nwhile($row = mysql_fetch_assoc($result_t))\n{\nmysql_query(\"TRUNCATE \" . $row['Tables_in_' . $mysql_database]);\n}\n// Temporary variable, used to store current query\n$templine = '';\n// Read in entire file\n$lines = file($filename);\n// Loop through each line\nforeach ($lines as $line)\n{\n// Skip it if it's a comment\nif (substr($line, 0, 2) == '--' || $line == '')\n continue;\n\n// Add this line to the current segment\n$templine .= $line;\n// If it has a semicolon at the end, it's the end of the query\nif (substr(trim($line), -1, 1) == ';')\n{\n // Perform the query\n mysql_query($templine) or print('Error performing query \\'<strong>' . $templine . '\\': ' . mysql_error() . '<br /><br />');\n // Reset temp variable to empty\n $templine = '';\n}\n}\n\n?>\n" }, { "answer_id": 10710943, "author": "Nemanja", "author_id": 1411306, "author_profile": "https://Stackoverflow.com/users/1411306", "pm_score": 2, "selected": false, "text": "$ mysql -u username -p -h localhost dbname < dumpfile.sql \n" }, { "answer_id": 11525265, "author": "sanneo", "author_id": 1129941, "author_profile": "https://Stackoverflow.com/users/1129941", "pm_score": 2, "selected": false, "text": "$fp = file('database.sql', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);\n$query = '';\nforeach ($fp as $line) {\n if ($line != '' && strpos($line, '--') === false) {\n $query .= $line;\n if (substr($query, -1) == ';') {\n mysql_query($query);\n $query = '';\n }\n }\n}\n" }, { "answer_id": 15354406, "author": "Gromo", "author_id": 2159497, "author_profile": "https://Stackoverflow.com/users/2159497", "pm_score": 4, "selected": false, "text": "<?php\n\n/**\n * Import SQL from file\n *\n * @param string path to sql file\n */\nfunction sqlImport($file)\n{\n\n $delimiter = ';';\n $file = fopen($file, 'r');\n $isFirstRow = true;\n $isMultiLineComment = false;\n $sql = '';\n\n while (!feof($file)) {\n\n $row = fgets($file);\n\n // remove BOM for utf-8 encoded file\n if ($isFirstRow) {\n $row = preg_replace('/^\\x{EF}\\x{BB}\\x{BF}/', '', $row);\n $isFirstRow = false;\n }\n\n // 1. ignore empty string and comment row\n if (trim($row) == '' || preg_match('/^\\s*(#|--\\s)/sUi', $row)) {\n continue;\n }\n\n // 2. clear comments\n $row = trim(clearSQL($row, $isMultiLineComment));\n\n // 3. parse delimiter row\n if (preg_match('/^DELIMITER\\s+[^ ]+/sUi', $row)) {\n $delimiter = preg_replace('/^DELIMITER\\s+([^ ]+)$/sUi', '$1', $row);\n continue;\n }\n\n // 4. separate sql queries by delimiter\n $offset = 0;\n while (strpos($row, $delimiter, $offset) !== false) {\n $delimiterOffset = strpos($row, $delimiter, $offset);\n if (isQuoted($delimiterOffset, $row)) {\n $offset = $delimiterOffset + strlen($delimiter);\n } else {\n $sql = trim($sql . ' ' . trim(substr($row, 0, $delimiterOffset)));\n query($sql);\n\n $row = substr($row, $delimiterOffset + strlen($delimiter));\n $offset = 0;\n $sql = '';\n }\n }\n $sql = trim($sql . ' ' . $row);\n }\n if (strlen($sql) > 0) {\n query($row);\n }\n\n fclose($file);\n}\n\n/**\n * Remove comments from sql\n *\n * @param string sql\n * @param boolean is multicomment line\n * @return string\n */\nfunction clearSQL($sql, &$isMultiComment)\n{\n if ($isMultiComment) {\n if (preg_match('#\\*/#sUi', $sql)) {\n $sql = preg_replace('#^.*\\*/\\s*#sUi', '', $sql);\n $isMultiComment = false;\n } else {\n $sql = '';\n }\n if(trim($sql) == ''){\n return $sql;\n }\n }\n\n $offset = 0;\n while (preg_match('{--\\s|#|/\\*[^!]}sUi', $sql, $matched, PREG_OFFSET_CAPTURE, $offset)) {\n list($comment, $foundOn) = $matched[0];\n if (isQuoted($foundOn, $sql)) {\n $offset = $foundOn + strlen($comment);\n } else {\n if (substr($comment, 0, 2) == '/*') {\n $closedOn = strpos($sql, '*/', $foundOn);\n if ($closedOn !== false) {\n $sql = substr($sql, 0, $foundOn) . substr($sql, $closedOn + 2);\n } else {\n $sql = substr($sql, 0, $foundOn);\n $isMultiComment = true;\n }\n } else {\n $sql = substr($sql, 0, $foundOn);\n break;\n }\n }\n }\n return $sql;\n}\n\n/**\n * Check if \"offset\" position is quoted\n *\n * @param int $offset\n * @param string $text\n * @return boolean\n */\nfunction isQuoted($offset, $text)\n{\n if ($offset > strlen($text))\n $offset = strlen($text);\n\n $isQuoted = false;\n for ($i = 0; $i < $offset; $i++) {\n if ($text[$i] == \"'\")\n $isQuoted = !$isQuoted;\n if ($text[$i] == \"\\\\\" && $isQuoted)\n $i++;\n }\n return $isQuoted;\n}\n\nfunction query($sql)\n{\n global $mysqli;\n //echo '#<strong>SQL CODE TO RUN:</strong><br>' . htmlspecialchars($sql) . ';<br><br>';\n if (!$query = $mysqli->query($sql)) {\n throw new Exception(\"Cannot execute request to the database {$sql}: \" . $mysqli->error);\n }\n}\n\nset_time_limit(0);\n\n$mysqli = new mysqli('localhost', 'root', '', 'test');\n$mysqli->set_charset(\"utf8\");\n\nheader('Content-Type: text/html;charset=utf-8');\nsqlImport('import.sql');\n\necho \"Peak MB: \", memory_get_peak_usage(true)/1024/1024;\n" }, { "answer_id": 18877897, "author": "canoodle", "author_id": 2729288, "author_profile": "https://Stackoverflow.com/users/2729288", "pm_score": 0, "selected": false, "text": "/* load sql-commands from a sql file */\nfunction loadSQLFromFile($url)\n{\n // ini_set ( 'memory_limit', '512M' );\n // set_time_limit ( 0 );\n\n global $settings_database_name;\n global $mysqli_object; global $worked; $worked = false;\n\n $sql_query = \"\";\n\n // read line by line\n $lines = file($url);\n $count = count($lines);\n\n for($i = 0;$i<$count;$i++)\n {\n $line = $lines[$i];\n $cmd3 = substr($line, 0, 3);\n $cmd4 = substr($line, 0, 4);\n $cmd6 = substr($line, 0, 6);\n if($cmd3 == \"USE\")\n {\n // cut away USE ``;\n $settings_database_name = substr($line, 5, -3);\n }\n else if($cmd4 == \"DROP\")\n {\n $mysqli_object->query($line); // execute this line\n }\n else if(($cmd6 == \"INSERT\") || ($cmd6 == \"CREATE\"))\n {\n // sum all lines up until ; is detected\n $multiline = $line;\n while(!strstr($line, ';'))\n {\n $i++;\n $line = $lines[$i];\n $multiline .= $line;\n }\n $multiline = str_replace(\"\\n\", \"\", $multiline); // remove newlines/linebreaks\n $mysqli_object->query($multiline); // execute this line\n } \n }\n\n return $worked;\n}\n?>\n" }, { "answer_id": 18892982, "author": "Darius Miliauskas", "author_id": 2663883, "author_profile": "https://Stackoverflow.com/users/2663883", "pm_score": 1, "selected": false, "text": "$file_content = file('myfile.sql');\n$query = \"\";\nforeach($file_content as $sql_line){\n if(trim($sql_line) != \"\" && strpos($sql_line, \"--\") === false){\n $query .= $sql_line;\n if (substr(rtrim($query), -1) == ';'){\n echo $query;\n $result = mysql_query($query)or die(mysql_error());\n $query = \"\";\n }\n }\n }\n" }, { "answer_id": 19545760, "author": "White Rabbit", "author_id": 2912022, "author_profile": "https://Stackoverflow.com/users/2912022", "pm_score": 1, "selected": false, "text": "function myquery($query) {\n\nmysql_connect(dbhost, dbuser, dbpass);\n\nmysql_select_db(dbname);\n\n$result = mysql_query($query);\n\nif (!mysql_errno() && @mysql_num_rows($result) > 0) {\n}\n\nelse {\n\n$result=\"not\";\n}\nmysql_close();\n\nreturn $result;\n\n}\n\n\n\nfunction mybatchquery ($str) {\n\n$sql = str_replace(\"\\n\",\"\",$str)\n\n$sql = explode(\";\",$str);\n\n$x=0;\n\nwhile (isset($str[$x])) {\n\nif (preg_match(\"/(\\w|\\W)+`(\\w|\\W)+) {\n\nmyquery($str[$x]);\n\n}\n\n$x++\n\n}\n\nreturn TRUE;\n\n}\n\n\n\n\nfunction myrows($result) {\n\n$rows = @mysql_num_rows($result);\n\nreturn $rows;\n}\n\n\n\n\nfunction myarray($result) {\n\n$array = mysql_fetch_array($result);\n\nreturn $array;\n}\n\n\n\n\nfunction myescape($query) {\n\n$escape = mysql_escape_string($query);\n\nreturn $escape;\n}\n\n\n\n$str = file_get_contents(\"foo.sql\");\nmybatchquery($str);\n" }, { "answer_id": 28063592, "author": "kepes", "author_id": 3319170, "author_profile": "https://Stackoverflow.com/users/3319170", "pm_score": 0, "selected": false, "text": "multi_query" }, { "answer_id": 29421536, "author": "zstate", "author_id": 2225558, "author_profile": "https://Stackoverflow.com/users/2225558", "pm_score": 3, "selected": false, "text": "$db = new PDO($dsn, $user, $password);\n\n$sql = file_get_contents('file.sql');\n\n$qr = $db->exec($sql);\n" }, { "answer_id": 30370765, "author": "Xav", "author_id": 2002493, "author_profile": "https://Stackoverflow.com/users/2002493", "pm_score": 2, "selected": false, "text": "$ mysqldump db > db.sql" }, { "answer_id": 41926857, "author": "Dion Truter", "author_id": 815219, "author_profile": "https://Stackoverflow.com/users/815219", "pm_score": 2, "selected": false, "text": "$pdo = new PDO($connectionString, $userName, $password);\n$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n$parser = new SqlScriptParser();\n$sqlStatements = $parser->parse($fileName);\nforeach ($sqlStatements as $statement) {\n $distilled = $parser->removeComments($statement);\n if (!empty($distilled)) {\n $statement = $pdo->prepare($sql);\n $affectedRows = $statement->execute();\n }\n}\n" }, { "answer_id": 55427166, "author": "Dave H.", "author_id": 11279981, "author_profile": "https://Stackoverflow.com/users/11279981", "pm_score": 0, "selected": false, "text": "<?php\n\n /*\n ingestSql(string) : string\n\n Read the contents of a SQL batch file, stripping away comments and\n joining statements that are broken over multiple lines with the goal\n of producing lines of sql statements that can be successfully executed\n by PDO exec() or execute() functions.\n\n For example:\n -- My SQL Batch\n CREATE TABLE foo(\n bar VARCHAR(80),\n baz INT NOT NULL);\n\n Becomes:\n CREATE TABLE foo(bar VARCHAR(80), baz INT NOT NULL);\n */\n\n function ingestSql($sqlFilePath=__DIR__ . \"/create-db.sql\") {\n $sqlFile = file($sqlFilePath);\n $ingestedSql = \"\";\n $statement = \"\";\n foreach($sqlFile as $line) {\n\n // Ignore anything between a double-dash and the end of the line.\n $commentStart = strpos($line, \"--\");\n if ($commentStart !== false) {\n $line = substr($line, 0, $commentStart);\n }\n\n // Only process non-blank lines.\n if (strlen($line)) {\n\n // Remove any leading and trailing whitespace and append what's\n // left of the line to the current statement.\n $line = trim($line);\n $statement .= $line;\n\n // A semi-colon ends the current statement. Otherwise what was a\n // newline becomes a single space;\n if (substr($statement, -1) == \";\") {\n $ingestedSql .= $statement;\n $statement = \"\\n\";\n }\n else {\n $statement .= \" \";\n }\n }\n }\n\n return $ingestedSql;\n }\n\n?>\n" }, { "answer_id": 64409361, "author": "embulldogs99", "author_id": 5728363, "author_profile": "https://Stackoverflow.com/users/5728363", "pm_score": 1, "selected": false, "text": " $sql = file_get_contents(\"sql.sql\");\n" }, { "answer_id": 73634433, "author": "Rashmitha Himath", "author_id": 14837678, "author_profile": "https://Stackoverflow.com/users/14837678", "pm_score": 0, "selected": false, "text": "<?php\n$conn = new mysqli('localhost', 'root', '' , 'sql_auto_test_table');\n\n$query = ''; \n$sqlScript = file('sqlFileName.sql');\n\nforeach ($sqlScript as $line) {\n\n $startWith = substr(trim($line), 0 ,2);\n $endWith = substr(trim($line), -1 ,1);\n \n if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') {\n continue;\n }\n \n $query = $query . $line . \"/*<br>*/\"; \n if ($endWith == ';') {\n mysqli_query($conn,$query) or die('<div>Problem in executing the SQL query <b>,<br><br>' . $query. '</b><br><br>'.$conn->error.'</div>');\n $query= ''; \n }\n}\necho '<div>SQL file imported successfully</div>';\n?>\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10583/" ]
147,824
<p>To be more precise, I need to know whether (and if possible, how) I can find whether a given string has double byte characters or not. Basically, I need to open a pop-up to display a given text which can contain double byte characters, like Chinese or Japanese. In this case, we need to adjust the window size than it would be for English or ASCII. Anyone has a clue?</p>
[ { "answer_id": 147854, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 0, "selected": false, "text": "window.resizeTo(document.body.clientWidth, document.body.clientHeight);\n" }, { "answer_id": 147886, "author": "JasonTrue", "author_id": 13433, "author_profile": "https://Stackoverflow.com/users/13433", "pm_score": 3, "selected": false, "text": "o = document.getElementById(\"test\");\n\ndocument.defaultView.getComputedStyle(o,\"\").getPropertyValue(\"height\"))\n" }, { "answer_id": 148613, "author": "pcorcoran", "author_id": 15992, "author_profile": "https://Stackoverflow.com/users/15992", "pm_score": 6, "selected": true, "text": "function isDoubleByte(str) {\n for (var i = 0, n = str.length; i < n; i++) {\n if (str.charCodeAt( i ) > 255) { return true; }\n }\n return false;\n}\n" }, { "answer_id": 1697749, "author": "james", "author_id": 206374, "author_profile": "https://Stackoverflow.com/users/206374", "pm_score": 6, "selected": false, "text": "u" }, { "answer_id": 46719196, "author": "laurent", "author_id": 561309, "author_profile": "https://Stackoverflow.com/users/561309", "pm_score": 4, "selected": false, "text": "const text1 = `The Chinese Wikipedia was established along with 12 other Wikipedias in May 2001. 中文維基百科的副標題是「海納百川,有容乃大」,這是中国的清朝政治家林则徐(1785年-1850年)於1839年為`;\n\nconst regex = /[^\\u0000-\\u00ff]/; // Small performance gain from pre-compiling the regex\nfunction containsNonLatinCodepoints(s) {\n return regex.test(s);\n}\n\nfunction isDoubleByte(str) {\n for (var i = 0, n = str.length; i < n; i++) {\n if (str.charCodeAt( i ) > 255) { return true; }\n }\n return false;\n}\n\nfunction benchmark(fn, str) {\n let startTime = new Date();\n for (let i = 0; i < 10000000; i++) {\n fn(str);\n } \n let endTime = new Date();\n\n return endTime.getTime() - startTime.getTime();\n}\n\nconsole.info('isDoubleByte => ' + benchmark(isDoubleByte, text1));\nconsole.info('containsNonLatinCodepoints => ' + benchmark(containsNonLatinCodepoints, text1));\n" }, { "answer_id": 53420716, "author": "David Dehghan", "author_id": 705945, "author_profile": "https://Stackoverflow.com/users/705945", "pm_score": 3, "selected": false, "text": "function containsNonLatinCodepoints(s) {\n return /[^\\u0000-\\u00ff]/.test(s);\n}\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147824", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23373/" ]
147,837
<p>I am already excited about document databases and especially about CouchDB's simplicity. But I have a hard time understanding if such databases are a viable option for multi user systems. Since those systems require some kind of relations between records which document databases do not provide.</p> <p>Is it completely the wrong tool for such cases? Or some tagging and temporary views are the way to accomplish this? Or else...</p> <p>UPDATE:<br> I understand the answers so far. But let me rephrase the question a bit. Lets say I have a load of semi-structured data which is normally a fit for CouchDB. I can tag them like "type=post" and "year=2008". My question is how far can I go with this type of tagging? Say can I create an array field with 10.000 names in it? Or is there a better way of doing this? It is a matter of understanding how to think in this document based sense.</p>
[ { "answer_id": 149084, "author": "Paul J. Davis", "author_id": 129506, "author_profile": "https://Stackoverflow.com/users/129506", "pm_score": 4, "selected": true, "text": "{\n _id: \"permission_doc_1\",\n type: \"acl\",\n user: \"John\",\n docid: \"John's Account Info\",\n read: true,\n write: true\n}\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3812/" ]
147,850
<p>I have the problem that an specific step in Ant can only be executed when we have Java 1.5 installed in the build computer. The task definition uses uses a jar file that was compiled using 1.5, so running with a 1.4 virtual machine will throw an IncompatibleClassVersion exception.</p> <p>I have to find a solution meanwhile to have this task working for this specific project that requires 1.4, but a question came to me. How can I avoid defining this task and executing this optional step if I don't have a specific java version?</p> <p>I could use the "if" or "unless" tags on the target tag, but those only check if a property is set or not. I also would like to have a solution that doesn't require extra libraries, but I don't know if the build-in functionality in standard is enough to perform such a task.</p>
[ { "answer_id": 147890, "author": "McDowell", "author_id": 304, "author_profile": "https://Stackoverflow.com/users/304", "pm_score": 4, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<project name=\"project\" default=\"default\">\n\n <target name=\"default\" depends=\"javaCheck\" if=\"isJava6\">\n <echo message=\"Hello, World!\" />\n </target>\n\n <target name=\"javaCheck\">\n <echo message=\"ant.java.version=${ant.java.version}\" />\n <condition property=\"isJava6\">\n <equals arg1=\"${ant.java.version}\" arg2=\"1.6\" />\n </condition>\n </target>\n\n</project>\n" }, { "answer_id": 147907, "author": "Lorenzo Boccaccia", "author_id": 2273540, "author_profile": "https://Stackoverflow.com/users/2273540", "pm_score": 2, "selected": false, "text": "${ant.java.version}" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2309/" ]
147,891
<p>In Firefox I can get the stack trace of an exception by using <code>exception.stack</code>.</p> <p>Is there a way to get that in other browsers, too?</p> <p><b>Edit:</b> I actually want to save the stack trace automatically (if possible) and not debug it at the time (i.e. I know how to get the stack trace in a debugger).</p>
[ { "answer_id": 14562673, "author": "Francesco Casula", "author_id": 828366, "author_profile": "https://Stackoverflow.com/users/828366", "pm_score": 6, "selected": false, "text": "console.log(new Error().stack);\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4936/" ]
147,897
<p>I want to generate some XML in a stored procedure based on data in a table.</p> <p>The following insert allows me to add many nodes but they have to be hard-coded or use variables (sql:variable):</p> <pre><code>SET @MyXml.modify(' insert &lt;myNode&gt; {sql:variable("@MyVariable")} &lt;/myNode&gt; into (/root[1]) ') </code></pre> <p>So I could loop through each record in my table, put the values I need into variables and execute the above statement.</p> <p>But is there a way I can do this by just combining with a select statement and avoiding the loop?</p> <p><strong>Edit</strong> I have used <code>SELECT FOR XML</code> to do similar stuff before but I always find it hard to read when working with a hierarchy of data from multiple tables. I was hoping there would be something using the <code>modify</code> where the XML generated is more explicit and more controllable.</p>
[ { "answer_id": 148877, "author": "6eorge Jetson", "author_id": 23422, "author_profile": "https://Stackoverflow.com/users/23422", "pm_score": 4, "selected": true, "text": "DECLARE @NestedInput_SpecificDogNameId int\nSET @NestedInput_SpecificDogNameId = 99\nSELECT [dbo].[udfGetLowestLevelNestedNode_SpecificDogName] \n(@NestedInput_SpecificDogNameId)\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18107/" ]
147,908
<p>Under the View-Model-ViewModel pattern for WPF, I am trying to databind the Heights and Widths of various definitions for grid controls, so I can store the values the user sets them to after using a GridSplitter. However, the normal pattern doesn't seem to work for these particular properties.</p> <p><em>Note: I'm posting this as a reference question that I'm posting as Google failed me and I had to work this out myself. My own answer to follow.</em></p>
[ { "answer_id": 147928, "author": "Nidonocu", "author_id": 483, "author_profile": "https://Stackoverflow.com/users/483", "pm_score": 6, "selected": true, "text": "private GridLength myHorizontalInputRegionSize = new GridLength(0, GridUnitType.Auto)\npublic GridLength HorizontalInputRegionSize\n{\n get\n {\n // If not yet set, get the starting value from the DataModel\n if (myHorizontalInputRegionSize.IsAuto)\n myHorizontalInputRegionSize = new GridLength(ConnectionTabDefaultUIOptions.HorizontalInputRegionSize, GridUnitType.Pixel);\n return myHorizontalInputRegionSize;\n }\n set\n {\n myHorizontalInputRegionSize = value;\n if (ConnectionTabDefaultUIOptions.HorizontalInputRegionSize != myHorizontalInputRegionSize.Value)\n {\n // Set the value in the DataModel\n ConnectionTabDefaultUIOptions.HorizontalInputRegionSize = value.Value;\n }\n OnPropertyChanged(\"HorizontalInputRegionSize\");\n }\n}\n" }, { "answer_id": 150797, "author": "Joel B Fant", "author_id": 22211, "author_profile": "https://Stackoverflow.com/users/22211", "pm_score": 2, "selected": false, "text": "GridLength" }, { "answer_id": 7358445, "author": "Greg Sansom", "author_id": 503969, "author_profile": "https://Stackoverflow.com/users/503969", "pm_score": 6, "selected": false, "text": "IValueConverter" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147908", "https://Stackoverflow.com", "https://Stackoverflow.com/users/483/" ]
147,920
<p>I miss it so much (used it a lot in C#). can you do it in C++?</p>
[ { "answer_id": 147954, "author": "Matt Hanson", "author_id": 5473, "author_profile": "https://Stackoverflow.com/users/5473", "pm_score": 5, "selected": true, "text": "#pragma region Region_Name\n//Your content.\n#pragma endregion Region_Name\n" }, { "answer_id": 30398977, "author": "Jon", "author_id": 973838, "author_profile": "https://Stackoverflow.com/users/973838", "pm_score": 1, "selected": false, "text": "#Region \"identifier_string\" \n' Your content\n#End Region\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18426/" ]
147,924
<p>Can share with me any of this script?</p>
[ { "answer_id": 147963, "author": "Till", "author_id": 2859, "author_profile": "https://Stackoverflow.com/users/2859", "pm_score": 2, "selected": false, "text": "#!/usr/bin/ruby -w\n\n# A Subversion post-commit hook. Edit the configurable stuff below, and\n# copy into your repository's hooks/ directory as \"post-commit\". Don't\n# forget to \"chmod a+x post-commit\".\n\n# ------------------------------------------------------------------------\n\n# You *will* need to change these.\n\naddress=\"FOO@SOME_DOMAIN.com\"\nsendmail=\"/usr/sbin/sendmail\"\nsvnlook=\"/usr/bin/svnlook\"\n\n# ------------------------------------------------------------------------\n\nrequire 'cgi'\n\n# Subversion's commit-email.pl suggests that svnlook might create files.\nDir.chdir(\"/tmp\")\n\n# What revision in what repository?\nrepo = ARGV.shift()\nrev = ARGV.shift()\n\n# Get the overview information.\ninfo=`#{svnlook} info #{repo} -r #{rev}`\ninfo_lines=info.split(\"\\n\")\nauthor=info_lines.shift\ndate=info_lines.shift\ninfo_lines.shift\ncomment=info_lines\n\n# Output the overview.\nbody = \"<p><b>#{author}</b> #{date}</p>\"\nbody << \"<p>\"\ncomment.each { |line| body << \"#{CGI.escapeHTML(line)}<br/>\\n\" }\nbody << \"</p>\"\nbody << \"<hr noshade>\"\n\n# Get and output the patch.\nchanges=`#{svnlook} diff #{repo} -r #{rev}`\nbody << \"<pre>\"\nchanges.each do |top_line|\n top_line.split(\"\\n\").each do |line|\n color = case\n when line =~ /^Modified: / || line =~ /^=+$/ || line =~ /^@@ /: \"gray\"\n when line =~ /^-/: \"red\"\n when line =~ /^\\+/: \"blue\"\n else \"black\"\n end\n body << %Q{<font style=\"color:#{color}\">#{CGI.escapeHTML(line)}</font><br/>\\n}\n end\nend\nbody << \"</pre>\"\n\n# Write the header.\nheader = \"\"\nheader << \"To: #{address}\\n\"\nheader << \"From: #{address}\\n\"\nheader << \"Subject: [SVN] #{repo} revision #{rev}\\n\"\nheader << \"Reply-to: #{address}\\n\"\nheader << \"MIME-Version: 1.0\\n\"\nheader << \"Content-Type: text/html; charset=UTF-8\\n\"\nheader << \"Content-Transfer-Encoding: 8bit\\n\"\nheader << \"\\n\"\n\n# Send the mail.\nbegin\n fd = open(\"|#{sendmail} #{address}\", \"w\")\n fd.print(header)\n fd.print(body)\nrescue\n exit(1)\nend\nfd.close\n\n# We're done.\nexit(0)\n" }, { "answer_id": 148011, "author": "fluffels", "author_id": 12828, "author_profile": "https://Stackoverflow.com/users/12828", "pm_score": 2, "selected": false, "text": "#!/bin/sh\n\nREPOS=\"$1\"\nREV=\"$2\"\n\nsvnnotify --repos-path \"$REPOS\" --revision \"$REV\" --with-diff --to mailinglist@server.domain --smtp mailserver.domain --from svn@server.domain -VVVVVVVVV -P \"[repository_name]\"\n" }, { "answer_id": 5254262, "author": "pokute", "author_id": 652691, "author_profile": "https://Stackoverflow.com/users/652691", "pm_score": 1, "selected": false, "text": "#!/bin/ksh\n#\n# This is a custom post-commit for sending email\n# when an svn repo is changed.\n#\n\nrcpts=\"foo@bar.edu, baz@bar.edu\"\n\nrepodir=$1\nrevision=$2\n\nauthor=`/usr/bin/svnlook author -r $revision $repodir`\ndate=`/usr/bin/svnlook date -r $revision $repodir`\nlog=`/usr/bin/svnlook log -r $revision $repodir`\ninfo=`/usr/bin/svnlook changed -r $revision $repodir`\n\nrepo=${repodir##*/}\n\nsubject=\"$repo svn updated by $author\"\n\nurl=\"https://myserver.bar.edu/svn/$repo\"\n\n/usr/bin/mail -s \"$subject\" \"$rcpts\"<<EOM\nrepository: $url\ndate: $date\nusername: $author\nrevision: $revision\ncomment: $log\n\n$info\nEOM\n" }, { "answer_id": 29715560, "author": "vishal sahasrabuddhe", "author_id": 4435863, "author_profile": "https://Stackoverflow.com/users/4435863", "pm_score": 0, "selected": false, "text": "/usr/bin/svnnotify --revision \"$REV\" --repos-path \"$REPOS\" \\\n --subject-cx --subject-prefix \"[Project:commit] \" --max-sub-length 128 \\\n --with-diff --handler Alternative --alt HTML::ColorDiff \\\n --to 'abc@xyz.com' --from 'svn@xyz.com' --set-sender" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17147/" ]
147,925
<p>What's the best way to get a string containing a folder name that I can be certain does <strong>not</strong> exist? That is, if I call <code>DirectoryInfo.Exists</code> for the given path, it should return false.</p> <p>EDIT: The reason behind it is I am writing a test for an error checker, the error checker tests whether the path exists, so I wondered aloud on the best way to get a path that doesn't exist.</p>
[ { "answer_id": 147937, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": false, "text": " string path = Path.GetTempFileName();\n File.Delete(path);\n Directory.CreateDirectory(path);\n" }, { "answer_id": 147940, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 3, "selected": false, "text": "DirectoryInfo.Exists" }, { "answer_id": 147949, "author": "mdb", "author_id": 8562, "author_profile": "https://Stackoverflow.com/users/8562", "pm_score": 0, "selected": false, "text": "string ParentPath = System.IO.Path.Combine(Environment.GetEnvironmentVariable(\"TEMP\"), \"MyAppName\");\nstring UniquePath = System.IO.Path.Combine(ParentPath, Guid.NewGuid().ToString());\nSystem.IO.Directory.CreateDirectory(UniquePath);\n" }, { "answer_id": 148046, "author": "robertkroll", "author_id": 3851, "author_profile": "https://Stackoverflow.com/users/3851", "pm_score": 2, "selected": false, "text": "using System.IO;\n\nstring path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3851/" ]
147,929
<p>I've been searching around, and I haven't found how I would do this from C#.</p> <p>I was wanting to make it so I could tell Google Chrome to go <strong>Forward</strong>, <strong>Back</strong>, <strong>Open New Tab</strong>, <strong>Close Tab</strong>, <strong>Open New Window</strong>, and <strong>Close Window</strong> from my C# application.</p> <p>I did something similar with WinAmp using</p> <pre><code>[DllImport("user32", EntryPoint = "SendMessageA")] private static extern int SendMessage(int Hwnd, int wMsg, int wParam, int lParam); </code></pre> <p>and a a few others. But I don't know what message to send or how to find what window to pass it to, or anything. </p> <p>So could someone show me how I would send those 6 commands to Chrome from C#? thanks</p> <p>EDIT: Ok, I'm getting voted down, so maybe I wasn't clear enough, or people are assuming I didn't try to figure this out on my own.</p> <p>First off, I'm not very good with the whole DllImport stuff. I'm still learning how it all works.</p> <p>I found how to do the same idea in winamp a few years ago, and I was looking at my code. I made it so I could skip a song, go back, play, pause, and stop winamp from my C# code. I started by importing:</p> <pre><code> [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName, [MarshalAs(UnmanagedType.LPTStr)] string lpWindowName); [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int SendMessageA(IntPtr hwnd, int wMsg, int wParam, uint lParam); [DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)] public static extern int GetWindowText(IntPtr hwnd, string lpString, int cch); [DllImport("user32", EntryPoint = "FindWindowExA")] private static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2); [DllImport("user32", EntryPoint = "SendMessageA")] private static extern int SendMessage(int Hwnd, int wMsg, int wParam, int lParam); </code></pre> <p>Then the code I found to use this used these constants for the messages I send.</p> <pre><code> const int WM_COMMAND = 0x111; const int WA_NOTHING = 0; const int WA_PREVTRACK = 40044; const int WA_PLAY = 40045; const int WA_PAUSE = 40046; const int WA_STOP = 40047; const int WA_NEXTTRACK = 40048; const int WA_VOLUMEUP = 40058; const int WA_VOLUMEDOWN = 40059; const int WINAMP_FFWD5S = 40060; const int WINAMP_REW5S = 40061; </code></pre> <p>I would get the <em>hwnd</em> (the program to send the message to) by:</p> <pre><code>IntPtr hwnd = FindWindow(m_windowName, null); </code></pre> <p>then I would send a message to that program:</p> <pre><code>SendMessageA(hwnd, WM_COMMAND, WA_STOP, WA_NOTHING); </code></pre> <p>I assume that I would do something very similar to this for Google Chrome. but I don't know what some of those values should be, and I googled around trying to find the answer, but I couldn't, which is why I asked here. So my question is how do I get the values for:</p> <p><strong>m_windowName</strong> and <strong>WM_COMMAND</strong></p> <p>and then, the values for the different commands, <strong>forward</strong>, <strong>back</strong>, <strong>new tab</strong>, <strong>close tab</strong>, <strong>new window</strong>, <strong>close window</strong>?</p>
[ { "answer_id": 150140, "author": "Joel", "author_id": 13713, "author_profile": "https://Stackoverflow.com/users/13713", "pm_score": 2, "selected": false, "text": "IntPtr hWnd = FindWindow(\"Chrome_RenderWidgetHostHWND\", null);\nSendMessage(hWnd, WM_KEYDOWN, VK_BROWSER_BACK, 0);\nSendMessage(hWnd, WM_KEYUP, VK_BROWSER_BACK, 0);\n" }, { "answer_id": 152365, "author": "Chris S", "author_id": 21574, "author_profile": "https://Stackoverflow.com/users/21574", "pm_score": 2, "selected": false, "text": "private const UInt32 WM_KEYDOWN = 0x0100;\nprivate const UInt32 WM_KEYUP = 0x0101;\n\npublic const ushort VK_BROWSER_BACK = 0xA6;\npublic const ushort VK_BROWSER_FORWARD = 0xA7;\npublic const ushort VK_BROWSER_REFRESH = 0xA8;\npublic const ushort VK_BROWSER_STOP = 0xA9;\npublic const ushort VK_BROWSER_SEARCH = 0xAA;\npublic const ushort VK_BROWSER_FAVORITES = 0xAB;\npublic const ushort VK_BROWSER_HOME = 0xAC;\n" } ]
2008/09/29
[ "https://Stackoverflow.com/questions/147929", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13713/" ]