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" }, { "an...
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" }, { "an...
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...
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, ...
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": "technophil...
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_profil...
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...
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...
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 =...
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, "a...
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...
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...
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, ...
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, "au...
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" }, ...
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_prof...
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":...
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...
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" }, { "ans...
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://Sta...
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 // rende...
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...
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, "aut...
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://Stackov...
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 whe...
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...
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/...
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, ...
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": "Jos...
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": "Tr...
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://Stac...
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_p...
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 [Passwor...
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/3...
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.Row...
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": ...
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_funct...
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 ...
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" },...
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"...
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 / \"'\" / \"(\...
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_profil...
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\" Inher...
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" }, { "...
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, ...
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, ...
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/mx...
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"...
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_prof...
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": 2...
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" }, ...
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 w...
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", "...
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" }, ...
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, "auth...
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": "Yel...
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", "au...
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...
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,...
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": "htt...
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;...
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:/...
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 ...
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"...
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=\"...
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, ...
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{\...
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...
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.CheckboxSelectM...
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.G...
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://Stac...
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"...
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": "Ja...
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 ...
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\" d...
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].[udfGetLowestLevel...
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 HorizontalInputRegion...
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, "au...
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 ho...
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...
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);\nSendMes...
2008/09/29
[ "https://Stackoverflow.com/questions/147929", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13713/" ]