instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>Am I right to think that there is no way to set the selected value in the C# class SelectList after it is created? Isn't that a bit silly?</p>
<p>I think you are fighting the framework. The data going into your views should be created at the Last Possible Minute (LPM).</p> <p>Thinking this way, a <code>SelectList</code> is a type to feed the <code>DropDownList</code> HTML helper. It is NOT a place to store data while you decide how to process it.</p> <p>A...
<p>You mean client-side, in the browser?</p> <pre><code>var select = document.getElementById('mySelect'); select.options[newIndex].selected = true; </code></pre>
38,743
<p>When I use ApacheBench to test https, the error is returned, "ssl handshake failed".</p> <p>How can I use ApacheBench to test https?</p>
<p>ApacheBench doesn't seem to be capable of ignoring certificate problems (at least some of them) so I wrote this script:</p> <pre><code>#!/bin/bash K=200; HTTPSA='https://192.168.1.103:443/' date +%M-%S-%N&gt;wgetres.txt for (( c=1; c&lt;=$K; c++ )) do wget --no-check-certificate --secure-protocol=SSLv3 ...
<p>I ran into this problem recently. As a work around I used the loadtest npm package, which has similar options as ab:</p> <p><a href="https://www.npmjs.com/package/loadtest" rel="nofollow noreferrer">https://www.npmjs.com/package/loadtest</a></p>
23,054
<p>I often have to sort a dictionary (consisting of keys &amp; values) by value. For example, I have a hash of words and respective frequencies that I want to order by frequency.</p> <p>There is a <code>SortedList</code> which is good for a single value (say frequency), that I want to map back to the word.</p> <p><a hr...
<p>Use:</p> <pre><code>using System.Linq.Enumerable; ... List&lt;KeyValuePair&lt;string, string&gt;&gt; myList = aDictionary.ToList(); myList.Sort( delegate(KeyValuePair&lt;string, string&gt; pair1, KeyValuePair&lt;string, string&gt; pair2) { return pair1.Value.CompareTo(pair2.Value); } ); </c...
<p>You can sort the Dictionary by value and get the result in dictionary using the code below:</p> <pre><code>Dictionary &lt;&lt;string, string&gt;&gt; ShareUserNewCopy = ShareUserCopy.OrderBy(x =&gt; x.Value).ToDictionary(pair =&gt; pair.Key, pair =&gt; ...
2,279
<p>Where is a reliable registry key to find install location of Excel 2007?</p>
<p>How about:</p> <pre><code>[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\X.0\Common\InstallRoot] </code></pre> <blockquote> <p>which contains a key named 'Path' with the installation directory of that version of Office. This is consistent for Excel 8.0 through 12.0. If you want to look for a specific prod...
<p>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Excel\InstallRoot\</p>
30,325
<p>Interface Builder can be used for basic dependency injection in a Cocoa app, but is anyone aware of more complete dependency injection frameworks for Objective-C/Cocoa for when you don't want to instantiate objects in a NIB file?</p> <p><strong>Edit</strong></p> <p>To clarify, I recognize that IB can be used for b...
<p>I think you'll find that you don't need it in late-binding languages like Objective C, Ruby, Lisp and so on. Like Jamis' revelation that he was going down an overly complex path when he tried to build needle, a DI framework for Ruby- <a href="http://weblog.jamisbuck.org/2007/7/29/net-ssh-revisited" rel="nofollow n...
<p>I work with Spring all day and I've checked Groovy. I'm by no means an XCode/Cocoa expert, but IB does only some dependency injection, which Groovy doesn't even really claims to be doing.</p> <p>I reckon you are not looking for DI, but rather for a well compiled set of integrated libraries which saves you from typi...
39,901
<p>Let's say I have the following table:</p> <pre><code>CustomerID ParentID Name ========== ======== ==== 1 null John 2 1 James 3 2 Jenna 4 3 Jennifer 5 3 Peter 6 5 Alice 7 5 Steve 8 1 Larry </...
<p>On SQL Server 2005 you can use <a href="https://web.archive.org/web/20210927200924/http://www.4guysfromrolla.com/webtech/071906-1.shtml" rel="noreferrer">CTEs (Common Table Expressions)</a> :</p> <pre><code>with Hierachy(CustomerID, ParentID, Name, Level) as ( select CustomerID, ParentID, Name, 0 as Level from ...
<p>Unless I'm missing something, recursion isn't necessary...</p> <pre><code>SELECT d.NAME FROM Customers As d INNER JOIN Customers As p ON p.CustomerID = d.ParentID WHERE p.Name = 'James' </code></pre>
29,603
<p>I have a PHP class that creates a PNG image on the fly and sends it to browser. PHP manual says that I need to make sure that <em>imagedestroy</em> function is called at end to release the memory. Now, if I weren't using a class, I would have some code like this:</p> <pre><code>function shutdown_func() { globa...
<p>I just tested with Apache, PHP being used as Apache module. I created an endless loop like this:</p> <pre><code>&lt;?php class X { function __destruct() { $fp = fopen("/var/www/htdocs/dtor.txt", "w+"); fputs($fp, "Destroyed\n"); fclose($fp); } }; $obj = new X(); while (true) { ...
<p>I think one big thing that you have missed is that all the memory PHP has allocated during script execution is freed once the script terminates. Even if the user presses the stop-button, PHP processes the script until it is finished, gives it back to the HTTP daemon to be served to the visitor (or not, depending on ...
29,301
<p>I'm creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read somewhere that (at least in GCC) the compiler can make the enum any width they need to be to hold their values. So, is it possible to have an enu...
<p>An <code>enum</code> is only guaranteed to be large enough to hold <code>int</code> values. The compiler is free to choose the actual type used based on the enumeration constants defined so it can choose a smaller type if it can represent the values you define. If you need enumeration constants that don't fit into...
<p>Consider this code:</p> <pre><code>enum value{a,b,c,d,e,f,g,h,i,j,l,m,n}; value s; cout &lt;&lt; sizeof(s) &lt;&lt; endl; </code></pre> <p>It will give 4 as output. So no matter the number of elements an <code>enum</code> contains, its size is always fixed.</p>
47,777
<ol> <li>Is it possible to capture Python interpreter's output from a Python script?</li> <li>Is it possible to capture Windows CMD's output from a Python script?</li> </ol> <p>If so, which librar(y|ies) should I look into?</p>
<p>If you are talking about the python interpreter or CMD.exe that is the 'parent' of your script then no, it isn't possible. In every POSIX-like system (now you're running Windows, it seems, and that might have some quirk I don't know about, YMMV) each process has three streams, standard input, standard output and sta...
<p>In which context are you asking?</p> <p>Are you trying to capture the output from a program you start on the command line?</p> <p>if so, then this is how to execute it:</p> <pre><code>somescript.py | your-capture-program-here </code></pre> <p>and to read the output, just read from standard input.</p> <p>If, on ...
4,457
<p>I've googled around and found most people advocating the use of <code>kmalloc</code>, as you're guaranteed to get contiguous physical blocks of memory. However, it also seems as though <code>kmalloc</code> can fail if a contiguous <strong>physical</strong> block that you want can't be found.<br> What are the advanta...
<p>You only need to worry about using physically contiguous memory if the buffer will be accessed by a DMA device on a physically addressed bus (like PCI). The trouble is that many system calls have no way to know whether their buffer will eventually be passed to a DMA device: once you pass the buffer to another kernel...
<p>In short, vmalloc and kmalloc both could fix fragmentation. vmalloc use memory mappings to fix external fragmentation; kmalloc use slab to fix internal frgamentation. Fot what it's worth, kmalloc also has many other advantages.</p>
14,175
<p>I have been using the partial class modifier for some time in order to put helper classes in their own file.</p> <p>Today we got a new guy and he said that the last team he worked with didn't allow partial classes for this because modifying a helper class that is in a separate file would cause the main partial clas...
<p>Partial classes are <em>primarily</em> for code-generator usage, such as designers - but I use the approach you have cited - in particular when an object implements multiple (non-trivial) interfaces, I find it useful to break it up 1 file per interface implementation. I also commonly have a file for the static metho...
<p>I think it's good to remember that your tool's default behavior is to create a low-level form of Coupling Not Cohesion; and view it skeptically, and override it unless it makes sense for some of the specific reasons listed above. But it's not good default behavior.</p>
45,728
<p>I have created a web reference (Add Web Reference) from Visual Studio 2008 and strangely, I need to set the <em>propertyNameField</em>Specified to true for all the fields I want to submit. Failure to do that and values are not passed back to the WCF Service. </p> <p>I have read at several places that this was fixed...
<p>Here is a complete answer: <a href="http://blogs.msdn.com/eugeneos/archive/2007/02/05/solving-the-disappearing-data-issue-when-using-add-web-reference-or-wsdl-exe-with-wcf-services.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/eugeneos/archive/2007/02/05/solving-the-disappearing-data-issue-when-using-add-web...
<p>I saw this happen in VB.NET with nullable values, C# however had the 'correct' code.</p> <p>Maybe an idea will be to reference the service from a C# project. Then reference that project from your VB.NET code.</p>
16,153
<p>I come from a java background.</p> <p>But I would like a cross-platform perspective on what is considered best practice for persisting objects.</p> <p>The way I see it, there are 3 camps:</p> <ul> <li>ORM camp</li> <li>direct query camp e.g. JDBC/DAO, iBatis</li> <li>LINQ camp</li> </ul> <p>Do people still handc...
<p>There is no one best practice for persistence (although the number of people screaming that ORM is best practice might lead you to believe otherwise). The only best practice is to use the method that is most appropriate for your team and your project.</p> <p>We use ADO.NET and stored procedures for data access (tho...
<p>I am currently reading up on persisting objects in .net. As such I cannot offer a best practice, but maybe my insights can bring you some benefit. Up until a few months ago I have always used handcoded queries, a bad habit from my ASP.classic days.</p> <p><strong>Linq2SQL</strong> - Very lightweight and easy to get...
47,292
<p>Is there a way to draw a line along a curved path with a gradient that varies in a direction perpendicular to the direction of the line? I am using the GDI+ framework for my graphics.</p>
<p>The simple answer is no. You can create a GraphicsPath in order to describe what you would like to draw, using AddPoint/AddLine/AddBezier and so forth as needed to describe the complex path of what you want to draw. When you draw the path you can provide a Brush which can be something like LinearGradientBrush or Rad...
<p>One possible method you can use is to set the clip region of the Graphics object to be that of the line only. Then draw a Linear Gradient over the extremes of the line e.g.</p> <pre><code>GraphicsPath gp = new GraphicsPath(); gp.AddArc(); // etc... graphics.SetClip( gp ); graphics.FillRectangle( myLinearGradient...
8,824
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/77172/stored-procedures-db-schema-in-source-control">Stored procedures/DB schema in source control</a> </p> </blockquote> <p>What's the best way to version control my tables, views, sprocs, etc? Preferably auto...
<p>I asked this one yesterday and got some nice responses:</p> <p><a href="https://stackoverflow.com/questions/77172/stored-proceduresdb-schema-in-source-control">Stored procedures/DB schema in source control</a></p>
<p>If you were super lazy you could use the SMO (SQL Server Management Objects) or if using SQL Server prior to 2005 the DMO (distributed managmeent objects) to script out all tables/views/stored procedures daily and then compare the script to the script in source control and if there are any changes check the new vers...
11,079
<p>Personally, I've found that when good developers deal with clients, they often get sucked into the after-sales support process and this process has been difficult to reverse, so was just interested to hear the various strategies that developers employ in maintaining a healthy, useful relationship that keeps clients ...
<p>Just a tip: Write down every single thing a client says to you.</p>
<p>Lots and lots of communication. Communication can be as simple as checking in with your customers by stopping by at their desks (if you are co-located) or keeping in touch over the phone. The more personal the communication is (in-person beats phone call, phone call beats email, etc.), the stronger your relationsh...
37,309
<p>I am building a relatively simple <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollow noreferrer">Django</a> application and apart from the main page where most of the dynamic parts of the application are, there are a few pages that I will need that will not be dynamic at all (<em>About</...
<p>Have you looked at <a href="http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/#ref-contrib-flatpages" rel="noreferrer">flat pages</a> in Django? It probably does everything you're looking for.</p>
<p>If you want to just create a template for each of them, you could use the <a href="https://docs.djangoproject.com/en/1.4/ref/generic-views/#django-views-generic-simple-direct-to-template" rel="nofollow noreferrer"><code>direct_to_template</code></a> generic view to serve it up.</p> <p>Another option would be the <a...
31,400
<p>When running all my tests in Eclipse (Eclipse 3.4 'Ganymede'), one test is listed under "Unrooted Tests". I'm using Junit 3.8 and this particular test extends TestCase. I do not see any difference between this test and the other tests. I don't remember seeing this occur in Eclipse 3.3 (Europa).</p> <p>Clarification...
<p>If your class extends TestCase somewhere in its hierarchy, you have to use the JUnit 3 test runner listed in the drop down under run configurations. Using the JUnit 4 runner (the default I believe) causes that unrooted test phenomenon to occur.</p>
<p>I could the fix the issue by shifting from TestRunner ver 4.0 to 3 in run configurations for the individual test method.</p>
14,700
<p>When the autocomplete listbox/dropdown is displayed in Aqua Data Studio, you have to hit enter in order for the current hightlighted item to complete the identifier. Is there a way that I can hit the tab key to autocomplete instead? This is the default behavior for Visual Studio and I cannot find the keyboard shortc...
<p>Goto File->Options->Key Mappings.<br> Select your Active KeyMap.<br> Under Keymap Settings, Goto General -> Query:Auto Complete and Select it.<br> Under Shortcut, click on the button Edit and you can change to suite your need.</p> <p>Make sure there are no conflicts.<br><img src="https://i.stack.imgur.com/TRtIs.png...
<p>Look in the preferences for "keybindings"/"hotkeys".</p>
19,103
<p>I am developing an application that controls an Machine.<br/> When I receive an error from the Machine the users should be able to directly notice it, one way that is done is Flashing the tray on the taskbar. When the machine clears the error the tray should stop flashing.</p> <p>There's one little annoyance using t...
<p>Behaviour is the same when a window finishes flashing for as long as it's supposed to: the taskbar button stays coloured. I don't think this is a bug. If you think about it, when you use <code>FLASHW_STOP</code>, the flashing does in fact stop, but the point of the flashing is to get the user's attention. The button...
<p>Just set uCount to 0 to stop the flashing.</p>
4,199
<p>We have a set of web services which is also our internal API. They perfectly share one common web.config file.</p> <p>Is there a way to somehow make log4net create one log for the whole site, for all of them? And have common error handler? The problem I think they are all separate virtual directories, separate appl...
<p>From log4net's <a href="http://logging.apache.org/log4net/release/faq.html" rel="nofollow noreferrer">FAQ</a>:</p> <blockquote> <p>How do I get multiple process to log to the same file?</p> <p>By default the FileAppender holds an exclusive write lock on the log file while it is logging. This prevents ...
<p>Are they all inside the same project? Are they ASMX Services? If so and you can put them in the same virtual directory there shouldn't be a problem.</p>
39,540
<p>Try as I might, I'm unable to resolve an address to IP. The code snippet is shown below. I keep getting the No such host is known exception, even though I could access google with my browser (The DNS server is almost certainly working). I'm however behind company's firewall.</p> <pre><code>try { foreach (IPAddre...
<p>There is nothing wrong with your code. Given that you can access www.google.com from a web browser the next most likely problem is that the web browser is using a proxy server. The web browser is actually accessing www.google.com through the proxy server which is allowed through the firewall. The simple applicati...
<p>Rather than try through a browser, try pinging www.google.com (or some other host, of course) from the command line.</p> <p>The ping itself may well not work, but it should show the IP address resolution first. If you get an error message like this:</p> <pre> Ping request could not find host www.google.com. ...
36,862
<p>Is there an easy way to rename a group of files already contained in a directory, using Python?</p> <p><strong>Example:</strong> I have a directory full of *.doc files and I want to rename them in a consistent way.</p> <blockquote> <p>X.doc -> "new(X).doc"</p> <p>Y.doc -> "new(Y).doc"</p> </blockquote>
<p>Such renaming is quite easy, for example with <a href="http://docs.python.org/lib/module-os.html" rel="noreferrer">os</a> and <a href="http://docs.python.org/lib/module-glob.html" rel="noreferrer">glob</a> modules:</p> <pre><code>import glob, os def rename(dir, pattern, titlePattern): for pathAndFilename in gl...
<h1>This code will work</h1> <h1>The function exactly takes two arguments f_patth as your path to rename file and new_name as your new name to the file.</h1> <pre><code>import glob2 import os def rename(f_path, new_name): filelist = glob2.glob(f_path + "*.ma") count = 0 for file in filelist: pri...
27,905
<p>What is the minimal conventional directory structure for a Java web app? What do I need to put in a <code>build.xml</code> file to get ant to build it and make a WAR file?</p> <p>My goal is to deploy a Wicket app to Tomcat without using an IDE. I want to do it with only ant and my favourite text editor.</p>
<p>Maybe not the most minimalist possible, but the Tomcat project has an <a href="http://tomcat.apache.org/tomcat-7.0-doc/appdev/index.html" rel="nofollow noreferrer">Application Developer's Guide</a> with a <a href="http://tomcat.apache.org/tomcat-7.0-doc/appdev/source.html" rel="nofollow noreferrer">section on source...
<p>You should check out maven. It's really complicated, but to build a war file it's simple, and there are plugins that will deploy the war to tomcat.</p>
20,540
<p>I'm in the process of developing a social network site.</p> <p>And been thinking of scalability from day one of the project, I've fine tuned the site and queries to the best of my ability.</p> <p>However; Certain pages are very data heavy and I'm not quite sure if they are loading as fast as they could so I was th...
<p>I'd implement caching at each and every layer of your application if at all possible.</p> <p>You can cache pages at the highest level, objects at the code level, and ensure your database is caching both queries and key data correctly at the lowest level.</p> <p>In terms of WHAT you need to cache, any objects that ...
<p>Web design guru <a href="http://www.webpagesthatsuck.com/" rel="nofollow noreferrer">Vincent Flanders</a> suggests that anything over 4 seconds is too long for a web page to load. I think that this is a pretty good rule of thumb.</p> <p>As far as caching or other performance optimization go, I would recommend you ...
26,925
<p>I've never liked wrapping the </p> <pre><code>mysql_real_escape_string </code></pre> <p>function around input I expect to be integer for inclusion in a MySQL query. Recently I came across the </p> <pre><code>filter_var </code></pre> <p>function. Nice!</p> <p>I'm currently using the code:</p> <pre><code>if (i...
<p>I myself would create a function for that task, possibly in a static class somewhere, </p> <pre><code>public static function escape_int($i) { $sanitised = intval($i); if( '_' . $sanitised . '_' === '_' . $i . '_' &amp;&amp; $sanitised &gt; 0 ) { return $sanitised; } throw new IntegerEscape...
<p>This is all you need</p> <pre><code>if ($idUser = filter_var($idUserIN, FILTER_VALIDATE_INT)) { $sql = 'SELECT * FROM TABLE_NAME WHERE idUser = '.$idUser; } else { // handle invalid data } </code></pre> <p>or</p> <pre><code>if ($idUser = filter_input(INPUT_POST, 'userId', FILTER_VALIDATE_INT)) { </code></...
40,066
<p>I have a few scripts on a site I recently started maintaining. I get those Object Not Found errors in IE6 (which Firefox fails to report in its Error Console?). What's the best way to debug these- any good cross-browser-compatible IDEs, or javascript debugging libraries of some sort?</p>
<p>There's no cross-browser JS debugger that I know of (because most browsers use different JS engines).</p> <p>For firefox, I'd definitely recommend firebug (<a href="http://www.getfirebug.com" rel="nofollow noreferrer">http://www.getfirebug.com</a>)</p> <p>For IE, the best I've found is Microsoft Script Debugger (<...
<p>You could use this tool apparently - <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2f465be0-94fd-4569-b3c4-dffdf19ccd99&amp;displaylang=en" rel="nofollow noreferrer">Microsoft Script Debugger</a></p> <p>Personally I try to go through the code and figure out what's going on - it gives you the lin...
10,435
<p>I have a swf file that's embedded in a html page, and I have a close button in the swf page, I want the swf to disappear when I click on the button, what is the best way to do that? Thanks.</p>
<p>If your ursing swfobject 2.1 to embed the swf you can use this built-in javascript swfobject.removeSWF() function: </p> <pre><code>function removeFlashFromHTML() { swfobject.removeSWF("id_of_your_html_object"); } </code></pre> <p>now you call the javascript function from flash using ExternalInterface:</p> <pre>...
<p>Write a JavaScript function that will hide the swf or its containing element, and call that function via the "close button" in the swf itself.</p>
36,719
<p>I'm working on a .NET 3.5 website, with three projects under one solution. I'm using jQuery in this project. I'd like to use the Visual Studio JavaScript debugger to step through my JavaScript code. If I set a breakpoint in any of the .js files I get a warning that says:</p> <blockquote> <p>The breakpoint will no...
<p>I was experiencing the same behavior in Visual Studio 2008, and after spending several minutes trying to get the symbols to load I ended up using a workaround - adding a line with the "debugger;" command in my JavaScript file.</p> <p>After adding <code>debugger;</code> when you then reload the script in Internet&nb...
<p>I sometimes have this problem with external JavaScript files - it is caused by the browser cache holding onto an old copy of the file. Forcing a refresh of the page linking to the JavaScript code solves the issue in this case.</p> <p>Of course, make sure your debugger is attached to the correct browser process. ;)<...
14,078
<p>I'm regularly running into similar situations : I have a bunch of COM .DLLs (no IDL files) which I need to use and invoke to be able to access some foreign (non-open, non-documented) data format.</p> <p>Microsoft's Visual Studio platform has very nice capabilities to import such COM DLLs and use them in my project ...
<p>Answering myself but I managed to find the <b>perfect</b> library for OLE/COM calling in non-Microsoft compilers : <a href="http://disphelper.sourceforge.net/" rel="noreferrer">disphelper</a>.</p> <p>(it's available from <a href="http://sourceforge.net/projects/disphelper/" rel="noreferrer">sourceforge.net</a> unde...
<p>I think you should be able to use the free tool Ole/Com Object Viewer to make the header files.</p>
10,980
<p>I have a swf file that is not controlled by me. The swf expects a javascript call to set some variables after initialization. </p> <p>The swf is embedded using the swfobject and I'm trying to call the as function right after the embed. This appears to be too soon because I get an error. Everything else should be fi...
<p>Are you doing this while the page is still loading? Or from am onload handler? If it's inline javascript I would suggest doing it in the onload handler from javascript which you can do like this -</p> <pre><code>window.onload = function() { // your code here } </code></pre> <p>it will run your code once the pag...
<p>I <a href="http://www.idealog.us/2007/02/check_if_a_java.html" rel="nofollow noreferrer">found some code</a> for checking whether the function exists yet. In summary:</p> <pre><code>if (typeof yourFunctionName == 'function') { yourFunctionName(); } </code></pre> <p>Does that work for you? If it does then you c...
25,962
<p>I have some text displaying in a larger font size than what it is supposed to. I used Firebug and it shows that the text is 12px as defined in the element's CSS. However Web Developer and CSSViewer both report that the text is 16px, which is what is currently displaying.</p> <p>With all these tools I am unable to q...
<p>While using the <em>web developer toolkit</em> you can see the DOM path of the element - just see if one of the higher elements has different font size. Firebug should show from which element the style is inherited</p>
<p>If using Firebug doesn't help, I would globally search your CSS for "16px", temporarily delete that attribute and see if that helps. CSS does not always behave as expected, especially across different browsers. Incorrect formatting of code, for example can trigger very strange behavior.</p> <p>Also, validate your X...
33,617
<p>I have an activex object I loaded into an html page. I then use that activex object to create another object, but I need to register an event with the new object created. The object is expecting an event listener of a certain type.</p> <p>I can load this same dll in c# and it will work fine. Code looks like this ...
<p>During idle times, you can disable the socket by setting the Receive Buffer size to zero:</p> <pre><code> int optval = 0; /* May need to be 1 on some platforms */ setsockopt(sockDesc, SOL_SOCKET, SO_RCVBUF, (char *)(&amp;optval), sizeof(optval)); </code></pre> <p>Re-enable by setting "optval" to a larger buffer ...
<p>I have not tried it, and it might be totally unwise for performance reasons (but if your app sleeps anyway, it might not be a problem), but: you might try setting the socket's receive buffer to some very small value before the sleep. I'm hoping this will cause the socket to not be able to buffer data that arrives wh...
25,687
<p>I'm writing a wrapper class for a command line executable. This exe accepts input from <code>stdin</code> until I hit <code>Ctrl+C</code> in the command prompt shell, in which case it prints output to <code>stdout</code> based on the input. I want to simulate that <code>Ctrl+C</code> press in C# code, sending the ...
<p>I've actually just figured out the answer. Thank you both for your answers, but it turns out that all i had to do was this:</p> <pre><code>p.StandardInput.Close() </code></pre> <p>which causes the program I've spawned to finish reading from stdin and output what i need.</p>
<p>Try actually sending the Key Combination Ctrl+C, instead of directly terminating the process:</p> <pre><code> [DllImport("user32.dll")] public static extern int SendMessage( int hWnd, // handle to destination window uint Msg, // message long wParam, // f...
35,875
<p>Here is a snippet of CSS that I need explained:</p> <pre class="lang-css prettyprint-override"><code>#section { width: 860px; background: url(/blah.png); position: absolute; top: 0; left: 50%; margin-left: -445px; } </code></pre> <p>Ok so it's absolute positioning of an image, obviously.</p...
<ol> <li><p>Top is the distance from the top of the html element or, if this is within another element with absolute position, from the top of that.</p></li> <li><p>&amp; 3. It depends on the width of the image but it might be for centering the image horizontally (if the width of the image is 890px). There are other wa...
<p>When position is absolute, top is vertical distance from the parent (probably the body tag, so 0 is the top edge of the browser window). Left 50% is distance from the left edge. The negative margin moves it back left 445px. As to why, your guess is as good as mine.</p>
12,320
<p>I recently upgraded my Ender 3 Pro with a <a href="https://printermods.com/products/direct-drive-mod-for-creality-ender-3-cr-10" rel="nofollow noreferrer">direct drive kit</a>, primarily so I can print soft materials like TPU. I bought a spool of <a href="https://rads.stackoverflow.com/amzn/click/com/B07VBKDM74" rel...
<p>That depends very much on what your goal is with the box. If it needs to be hollow and you don't need any access to the inside (and also prefer it to be printed in one piece) than the answer provided by user77232 would probably be the best.</p> <p>Alternatively, if you need access to the inside of the box you would ...
<ol> <li>Print it as a whole object</li> <li>Use 20% infill.</li> <li>Profit!</li> </ol>
1,739
<p>I've been using the Rome API to parse data from an XML feed pretty successfully so for, but have run in to a bit of a snag. </p> <p>Given the following snippet of XML:</p> <p>&lt;entry&gt;<br> &lt;id&gt;uniqueId&lt;/id&gt;<br> &lt;updated&gt;2008-11-05T01:32:35Z&lt;/updated&gt;<br> &lt;mm:status xmlns:mm=...
<p>Here is the raw classes from our code without much explanation (but it is late here!). This parses elements:</p> <pre><code>import com.sun.syndication.io.ModuleGenerator; import com.sun.syndication.io.impl.DateParser; import com.sun.syndication.feed.module.Module; import java.util.Collections; import java.util....
<p>If you're not already using it, <a href="http://wiki.java.net/bin/view/Javawsxml/RomeChangesLog##RomeV10RC1" rel="nofollow noreferrer">v1.0RC1</a> has several parsing fixes. Maybe try upgrading?</p>
44,549
<p>Many of the parameters for interacting with the Office Object model in VSTO require object parameters that are passed by reference, even when the notional type of the parameter is an int or string.</p> <ol> <li>I suppose that this mechanism is used so that code can modify the parameter, although I can't figure out ...
<p>I agree with Joe. I even developed helper structs and classes like this one:</p> <pre><code>internal struct Argument { internal static object False = false; internal static object Missing = System.Type.Missing; internal static object True = true; } </code></pre> <p>And this one:</p> <pre><code>/// &...
<p>I'd be interested in this too. I'm coding several apps that uses automation in Word and I even have things like</p> <pre><code>object oFalse = false, oTrue = true, oOne = 1; </code></pre> <p>It's very nasty, but it's the only way I know so far. </p> <p>The only thing I can think of is writing a wrapper class for ...
9,894
<p>How can I host a (<code>.Net, Java, VB6, MFC, etc</code>) application in a <code>WPF window</code> ?.</p> <p>I have a need to use <code>WPF windows</code> to wrap external applications and control the window size and location. </p> <p>Does anyone have any ideas on how to accomplish this or a direction to research...
<p>Use a HwndHost to host the outside window in your application.</p>
<p>This <a href="http://www.ddj.com/windows/197003872?pgno=2" rel="nofollow noreferrer">article</a> explains how to use HwndHost along with a few other Win32 API calls to accomplish the task.</p>
9,358
<p>I have a couple tables in which I created an object ID as either an Int or Bigint, and in both cases, they seem to autoincrement by 10 (ie, the first insert is object ID 1, the second is object ID 11, the third is object ID 21, etc). Two questions:</p> <ol> <li><p>Why does it do that?</p></li> <li><p>Is that a pro...
<p>Check to see the seed value of the autoincrement isn't set to 10.</p> <p>You can check by:</p> <pre><code>SELECT Auto_increment FROM information_schema.tables WHERE table_name='the_table_you_want'; </code></pre> <p>As noted elsewhere you can change by using the system variable @@set_auto_increment_increment</p> ...
<p>autoincriment value can jump if using insert with IGNORE attribute in case when record was not created</p> <pre><code>insert IGNORE into my_table set column=1 </code></pre>
25,330
<p>I have a large database of normalized order data that is becoming very slow to query for reporting. Many of the queries that I use in reports join five or six tables and are having to examine tens or hundreds of thousands of lines.</p> <p>There are lots of queries and most have been optimized as much as possible t...
<p>I know more about mssql that mysql, but I don't think the number of joins or number of rows you are talking about should cause you too many problems with the correct indexes in place. Have you analyzed the query plan to see if you are missing any?</p> <p><a href="http://dev.mysql.com/doc/refman/5.0/en/explain.html...
<p>You might also want to consider selecting into a temporary table and then performing queries on that temporary table. This would avoid the need to rejoin your tables for every single query you issue (assuming that you can use the temporary table for numerous queries, of course). This basically gives you denormaliz...
3,396
<p>I have this setup where in my development copy I can commit changes on a certain file to the repository. Then in my production copy, which does checkouts only, I would normally edit this file because this contains references which are environment independent. Is there any way I can ignore this file on the subsequent...
<p>I would suggest renaming the file in the repository from config.php to config.php.sample. This is the file that you would edit to change the default options. For deployment, either to your development environment or to the production server, you would copy config.php.sample to config.php and edit it without worrying...
<p>An alternative workaround is to use the tsvn:ignore-on-commit property. It will make files always start off unchecked in TortoiseSVN's commit dialog. If you'd want to commit it, you need to manually check it.</p> <p><a href="http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-commit.html" rel="nofollow nore...
13,900
<p>We had a need for a <strong>document management solution</strong> and were hoping <code>SharePoint 2007</code> would satisfy our needs. We felt our needs were relatively simple. We needed to manage <strong>versioning</strong>, have <strong>searching capabilities</strong>, and having an <strong>approval workflow</str...
<p>Here is a <a href="http://www.sharepointblogs.com/johnwpowell/archive/2007/07/13/display-version-number-and-other-sharepoint-metadata-in-word-2003-documents.aspx" rel="nofollow noreferrer">blog post</a> which seem to be exactly the solution of your problem.</p> <p>Basically they create a custom field in the documen...
<p>Does this information need to be in the footer? A lot of the information is available within the Office 2007 application. If you click on the round button in the upper left, and select "Server", you can view the version history, a lot of the other properties are available by clicking the round button and opening t...
8,370
<p>I've had a tough time setting up my replication server. Is there any program (OS X, Windows, Linux, or PHP no problem) that lets me monitor and resolve replication issues? (btw, for those following, I've been on this issue <a href="https://stackoverflow.com/questions/8166/mysql-replication-if-i-dont-specify-any-data...
<p>To monitor the servers we use the free <a href="http://www.maatkit.org/tools.html" rel="nofollow noreferrer">tools from Maatkit</a> ... simple, yet efficient.</p> <p>The binary replication is available in 5.1, so I guess you've got some balls. We still use 5.0 and it works OK, but of course we had our share of issu...
<p>We use mysql replication to replicate data to close to 30 servers. We monitor them with nagios. You can probably check the replication status and use an event handler to restart it with 'SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; Start Slave;'. That will fix the error, but you'll lose the insert that caused the error. </p...
5,590
<p>I have an HTTP server that returns large bodies in response to POST requests (it is a SOAP server). These bodies are "streamed" via chunking. If I encounter an error midway through streaming the response how can I report that error to the client and still keep the connection open? The implementation uses a proprieta...
<p>Once the server has sent the status line (the very first line of the response) to the client, you can't change the status code of the response anymore. Many servers delay sending the response by buffering it internally until the buffer is full. While the buffer is filling up, you can still change your mind about the...
<p>you can change the status code as long as response.iscommitted() returns false. (fot HttpServletResponse in java, im sure there exists an equivalent in other languages)</p>
19,700
<p>I'm trying to save the output of an vector image drawin in Java2D to an SWF file. There are great libraries for saving java2D output as things like SVG (BATIK) and PDF(itext) but I can't find one for SWF. Any ideas?</p>
<p>I just got an example to work using the <a href="http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/modules/swfutils/src/java/flash/graphics/g2d/SpriteGraphics2D.java" rel="nofollow noreferrer">SpriteGraphics2D</a> object from <a href="http://opensource.adobe.com/wiki/display/flexsdk/Downloads" rel="nofollow ...
<p>As far as I know flash does not use SVG at all. I'm not at all convinced that the answer mentioning that is correct. (But I can't just add this as a comment as I wanted to as I don't have enough points...)</p>
33,479
<p>I have been researching and playing with functional programming lately, solely to broaden my thinking about programming, because I find thinking "functionally" difficult.</p> <p>I have downloaded Glasgow Haskell and experimented with that.</p> <p>What I am wondering is, what is the best platform for Windows to exp...
<p>If you really want to learn how to think in a functional way, Haskell is definitely the right choice. Just about every other language out there lets you slip into an imperative style much too easily. Haskell will force you into a functional mindset. I found this indispensible when learning. (You may certainly be...
<p>ever tried Prolog? ... that'll </p> <pre><code>?- bend(your_mind). Yes ?- bend(X). X = your_mind </code></pre> <p>It gave me a whole new perspective anyway ... <a href="http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/contents.html" rel="nofollow noreferrer">plenty</a> <a href="http://www.gprolog.org/" rel...
31,976
<p>Let's say I've made a 3D scan of my face and managed to get that into FreeCAD. How might I then create an object (it's a mask, okay?) that conforms to the shape of my face, with a given thickness, such that I can export and 3D-print that part only?</p> <p>So if I printed it, it would fit over my face, but still look...
<p>Instead of using FreeCAD, I would import the mesh data into a vertex-based 3D modeling software, such as blender.</p> <p>After stitching the model in any areas where you still have gaps, you remove any vertex belonging to areas you do not want to use for the mask. This leaves you with pretty much a skin-tight base f...
<p>It depends on the software you're using, but here is an example with TinkerCad.</p> <p>Step 1: Import your 3D model (imagine that the ball is a head):<br /> <a href="https://i.stack.imgur.com/vZwKP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vZwKP.jpg" alt="enter image description here" /></a>...
1,920
<p>I'm talking about c# <del>3.5</del> 3.0. I know how to do it when cache or ServiceProvider can have only one instance for the whole application. In this case ServiceProvider can look like this</p> <pre><code>public static class Service&lt;T&gt; { public static T Value {get; set;} } </code></pre> <p>and can be ...
<p>Why are you particularly desperate to avoid casting? Yes, it feels "unsafe" - but you can basically guarantee that it's not going to be an issue in ServiceProvider, and the clients aren't doing any casting.</p> <p>This is a reasonably common problem, but I don't believe there's any nice solution to it within .NET g...
<p><del>I think I found the solution. Here you have my implementation of ServiceProvider You can find the description of it on <a href="http://seermindflow.blogspot.com/2008/10/is-it-possible-to-write-c-application.html" rel="nofollow noreferrer">my blog</a>.</p> <pre><code>public class ServiceContainer : IDisposable ...
21,480
<p>Can I access a users microphone in Python?</p> <p>Sorry I forgot not everyone is a mind reader: Windows at minimum XP but Vista support would be VERY good.</p>
<p>I got the job done with <a href="http://people.csail.mit.edu/hubert/pyaudio/" rel="noreferrer">pyaudio</a></p> <p>It comes with a binary installer for windows and there's even an example on how to record through the microphone and save to a wave file. Nice! I used it on Windows XP, not sure how it will do on Vista ...
<p>You might try <a href="http://code.google.com/p/pygalaxy/wiki/SWMixer" rel="nofollow noreferrer" title="SWMixer">SWMixer</a>.</p>
23,552
<p>Now that Silverlight 2 has finally shipped. I'm wondering if anyone has put together any logging frameworks for it, maybe something like <a href="http://msdn.microsoft.com/en-us/library/ff647183.aspx" rel="noreferrer">enterprise library logging</a> or <a href="http://logging.apache.org/log4net/" rel="noreferrer">log...
<p>If you're willing to take your astronaut's helmet off for a minute, below is a lightweight logger I've written for Silverlight, for client-side logging (for use mainly with WCF operations but could be for any errors).</p> <p>It was originally used in Monotouch for iPhone apps, and has been adapted for <code>Isolate...
<p>I have ended up writing a new logging framework from scratch that addresses this flaw. I created a local queue that will get the log/trace messages and then do the filter and send them to the server. The queue then will be backed by Isolated Storage so even if the client goes off line permanently for that session th...
28,306
<p>I originally posted this on Meta StackExchange to judge whether my thoughts fit within SE and have been redirected back to our Meta.</p> <p>We've received a few questions along the lines of purchasing references since we've opened in Beta. While I personally don't think direct questions about "<em>What is the best ...
<h2>I like the idea of incorporating product reviews into the 3dprinting StackExchange</h2> <p><strong>Why?</strong></p> <ol> <li>It fits the Q&amp;A model of Stack Exchange</li> <li>Product pre-purchase questions are probably the number 1 question every new user wants to ask and needs to know (<a href="https://3dpri...
<p>I've seen a few questions in the past week or so of people asking questions that would fit under the printer-review or buyer review tags you've suggested. However I don't think they are quite within the scope of the main site. </p> <p>Specific questions regarding the benefits of one style of printer over another wo...
33
<p>I've grokked the code for all the aforementioned apps and I still can't find a straightforward way to create a static directory structure from a single command.</p>
<p>Check out <a href="http://rubigen.rubyforge.org" rel="noreferrer">rubigen</a>. You can also view a <a href="http://rubyconf2007.confreaks.com/d3t1p1_rubigen.html" rel="noreferrer">presentation</a> by dr nic.</p>
<p>So what you want is to able to issue a command that will generate an entire directory tree?</p> <pre><code>cp -r &lt;template&gt; &lt;destination&gt; </code></pre> <p>Or am I misunderstanding? If you want to generate a consistent directory structure, your best bet is to simply copy it from a template. Fast, easy...
3,178
<p>I am working on a site where users can login to get more private information. My client has another site else where that uses <em>nt authentication</em> for accessing it.</p> <p>What they want to do is have a <code>button</code> on the site I am working on under the private area that will send them to the <em>nt a...
<p>Here's an (untested) theory, the details of which will greatly depend on what types of authentication the Sharepoint site will accept. I'll tackle <a href="http://en.wikipedia.org/wiki/Basic_access_authentication" rel="nofollow noreferrer">Basic</a>, since it's the easiest.</p> <p>You'll write out some JavaScript t...
<p>How will the other site validate your username and password?</p> <p>Ideally your site shouldn't even be remembering the user's password to be able to pass it to another site (you store hashes of the password, not the password itself, and only use the actually password during validation).</p> <p>What if your site p...
6,576
<p>How do you perform databinding against the MonthCalendar.SelectionRange property? Given the property is of type 'SelectionRange' which is a class I am not sure how to go about it. Any examples would be much appreciated.</p>
<p>Well, there don't seem to be any obvious events for this either on the <code>MonthCalendar</code> or the <code>SelectionRange</code>, and neither implements <code>INotifyPropertyChanged</code>, so it <em>looks</em> like data-binding might not be possible here.</p> <p>Update: It does, however, raise the DateChanged,...
<p>For me it seems to be very simple. I just bound SelectionStart and SelectionEnd properties of the MonthCalendar component.</p> <pre><code>this.Calendar1.DataBindings.Add(new System.Windows.Forms.Binding("SelectionStart", bindingSource, "DateField", true)); this.Calendar1.DataBindings.Add(new System.Windows.Forms.Bi...
49,385
<p>I have a windows setup project that installs a service. All works well except for one thing: The default directory offered to the user during install is of the form "C:\Program Files\Microsoft\ProgramName". I am trying to modify this so that instead of "Microsoft" we would have our company's name.</p> <p>I found th...
<p>Click on your setup project in Visual Studio, open the Properties and you will notice that there are a number of Properties that you can set like Manufacturer, SupportURL, etc.</p>
<p>Note if you're confused/frustrated doing this seemingly trivial thing: if you open properties by right-clicking on the project and clicking "Properties" in the right-mouse menu, you will get the wrong dialog box. You need to select the project, but then navigate to the properties tag. One way to navigate to the pr...
34,334
<p>I am the tech intern for an online independent newspaper, and the writers on the staff are not tech-savvy. They don't quite understand how web pages work, and often they upload and include images straight from their digital cameras, or scanned from original media. These images become a burden when there are 10 ima...
<p>You'd be better off doing the GD image processing during the upload process. GD can take up quite a bit of resources, so processing each image on every request would not be a preferable solution. If you can't do it during the upload process, you should cache all the resampled images and use those if/when available...
<p>With the current web site that I'm working on I needed to answer a similar question. I've opted for using the joomla addon <a href="http://www.joomla-addons.org/components/easy-gallery/easy-gallery.html" rel="nofollow noreferrer">Easy Gallery</a>. The two stand out features for me are the automated thumbnail creatio...
34,359
<p>I am planning to upgrade my printer with a second extruder. Since my printer is a Tronxy X8 it's frame is not exactly vibration resistant, so I'd like to keep the print head weight down. At the same time I really don't want a Bowden setup.</p> <p>I came up with the idea of making a dual extruder driven only by a sin...
<p>That is perfectly viable these days in Marlin firmware, there are options for setting this up using the configuration file, e.g.:</p> <pre><code>// :[0, 1, 2, 3, 4, 5, 6, 7, 8] #define EXTRUDERS 1 ... ... ... // A dual extruder that uses a single stepper motor //#define SWITCHING_EXTRUDER #if ENABLED(SWITCHING_EXTRU...
<p>You'll need a custom firmware.</p> <p>Yur custom firmware will have to react to the &quot;Change extruder&quot; command differently than a normal firmware: instead of just swapping to a different extruder, you'll need to perform some operations to alter the gearing (possibly a solenoid?), and possibly include some k...
1,806
<p>This has inspired some discussion and I may be just splitting hairs, but I've always been confused by this strategy. The specific example I'm referring to is here: <a href="https://3dprinting.stackexchange.com/a/29/60">https://3dprinting.stackexchange.com/a/29/60</a></p> <p>In many cases on SE, I see people post "...
<p>Sometimes, "don't try to do what you're trying to do" is the only valid answer, see e.g. <a href="https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem">XY problem</a>.</p>
<p>If it tries to answer the question, it's still an answer... </p> <p>But it doesn't mean it's always a good one.</p> <p>Generally, in these cases, you would be able to flag such an answer as Very Low Quality, especially if they would fit better in the comment space. The reason why you can't here however, is because...
8
<p>Relating to my <a href="https://stackoverflow.com/questions/48733/javahibernate-jpa-designing-the-server-data-reload">earlier question</a>, I want to ensure all the child objects are loaded as I have a multiple threads that may need to access the data (and thus avoid lazy loading exceptions). I understand the way t...
<p>Changing the annotation is a bad idea IMO. As it can't be changed to lazy at runtime. Better to make everything lazy, and fetch as needed.</p> <p>I'm not sure I understand your problem without mappings. Left join fetch should be all you need for the use case you describe. Of course you'll get back an order for ever...
<p>If the problem is just LazyInitializationExceptions, you can avoid that by adding an OpenSessionInViewFilter.<br> This will allow the objects to be loaded in the view, but will not help with the speed issue.</p> <pre><code> &lt;filter&gt; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt; &l...
9,641
<p>We have a .NET 2.0 application which we normally run on IIS6, and used to run fine on IIS7, but recently after installing SP1 for Vista IIS7 seems to be choking on a line in the Web.Config file:</p> <pre><code>&lt;system.web AllowLocation="true"&gt; </code></pre> <p>Is it safe to remove the AllowLocation attribut...
<p>From MSDN:</p> <blockquote> <p>When set to false, the AllowLocation property indicates that the section is accessed by native-code readers. Therefore, the use of the location attribute is not allowed, because the native-code readers do not support the concept of location.</p> </blockquote> <p>The default value i...
<p>Having this set to true should enable any <code>&lt;location&gt;</code> sections in your web.config, so you should be fine to remove it if there's none in there.</p>
16,534
<p>So I've got a form in my Rails app which uses a custom FormBuilder to give me some custom field tags</p> <pre><code>&lt;% form_for :staff_member, @staff_member, :builder =&gt; MyFormBuilder do |f| %&gt; [...] &lt;%= render :partial =&gt; "staff_members/forms/personal_details", :locals =&gt; {:f =&gt; f, :skill_...
<p>Use <code>fields_for</code> inside your partial. It performs a similar task but without wrapping the form tags. See the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001386" rel="noreferrer">API docs</a>.</p>
<p>You could instantiate a new instance of your form builder in the controller, though it feels sort of lousy to me:</p> <pre><code># in the controller render :partial =&gt; { :f =&gt; MyFormBuilder.new(:staff_member, @staff_member, template), :skill_groups =&gt; @skill_groups, :staff_member =&gt; @staff_member ...
48,503
<p>I'd like to call a function in python using a dictionary with matching key-value pairs for the parameters.</p> <p>Here is some code:</p> <pre><code>d = dict(param='test') def f(param): print(param) f(d) </code></pre> <p>This prints <code>{'param': 'test'}</code> but I'd like it to just print <code>test</code>....
<p>Figured it out for myself in the end. It is simple, I was just missing the ** operator to unpack the dictionary</p> <p>So my example becomes:</p> <pre><code>d = dict(p1=1, p2=2) def f2(p1,p2): print p1, p2 f2(**d) </code></pre>
<p>Here ya go - works just any other iterable:</p> <pre><code>d = {'param' : 'test'} def f(dictionary): for key in dictionary: print key f(d) </code></pre>
43,392
<p>I'd like to start experimenting with Cocoa and programming for Mac OSX. I'm not terribly concerned with Objective C syntax/constructs/bheaviors at this point, but more curious as to an efficient setup on in terms of an editor and/or IDE that will get me going quickly. Is there any IDE even remotely similar to Visu...
<p>I'd suggest you pick a fun little product and dive in. If you're looking for a book I'd suggest <a href="https://rads.stackoverflow.com/amzn/click/com/0321503619" rel="noreferrer" rel="nofollow noreferrer">Cocoa Programming for Max OSX</a> which is a very good introduction both to Objective-C and Cocoa.</p> <p>XCod...
<p>AFAIK, pretty much every OS X developer uses Xcode.</p> <p>That, and Interface Builder for creating the GUIs.</p> <p>FWIW, try to get hold of a copy of Hillegas's book, as it's a great introductory tutorial, and the reference Docs Apple provides really aren't. (They are generally very good reference docs, however...
3,645
<p>All,</p> <p>I'd like to check Django out and maybe hack together some web pages to see how it feels - but after having a look at a few tutorials like <a href="http://www.showmedo.com/videos/video?name=stoops010" rel="nofollow noreferrer">this one</a> I am starting to wonder if there is any way of getting it up and ...
<p>As someone who just started playing around with Django as well, I found the official documentation very helpful. Just walk through the "First steps" tutorials at:</p> <p><a href="http://docs.djangoproject.com/en/dev/" rel="nofollow noreferrer">http://docs.djangoproject.com/en/dev/</a></p> <p>It will teach you the ...
<p>It doesn't take half an hour, nor should you think that development is mostly about writing code. There is always going to setup work and such involved. That being said, I understand your plight. You might have luck finding a project that interests you and already exists. Simply checking out their latest revision sh...
42,625
<p>I am creating an XLS worksheet that would be used to collect data from the users. I have restricted the user input using validations. In order to easily be able to print the worksheet i have set the lenghts of the columns. Have made the relevant columns wrap. However i would like to protect the worksheet such that U...
<p>The key is <em>after</em> you protect the sheet to use the interface exposed in "Allow Users To Edit Ranges". I'm going to assume you are using Office 2003 since you didn't specify, so you find it in <strong>Tools -> Protection -> Allow Users to Edit Ranges</strong>.<br><br>From there it should be pretty obvious - ...
<p>Normally when you protect a sheet you get a dialog box which allows you to select what users can and can't do. If you select the right options you will be able to do what you want.</p> <p>Have a look at <a href="http://all-e-courses.blogspot.com/2008/03/protect-worksheets.html" rel="nofollow noreferrer">this blog ...
22,113
<p>How can I rename a schema using SQL Server? </p>
<p>If you have a large number of objects in a schema, you can use something like this to generate all the changes automatically (it only does tables and views, so before you run it, you might need to expand it to SPs, UDFs, etc.)</p> <pre><code>USE SandBox DECLARE @OldSchema AS varchar(255) DECLARE @NewSchema AS varc...
<p>Easiest solution that worked for me is:<br> I have just one schema dbo with two tables <code>PopulationByCountrySTG</code> and <code>CountryRegionSTG</code></p> <p>(1) I created a new schema by executing,</p> <pre><code>create schema stg </code></pre> <p>(2) I executed the following commands,</p> <pre><code>ALTE...
40,866
<p>How do I post a form from an HTML page to and ASPX page (2.0) and be able to read the values?</p> <p>I currently have an ASP.NET site using the Membership provider and everything is working fine. Users can log in from the Login.aspx page.</p> <p>We now want to be able to have users log in directly from another we...
<p>This is <em>very</em> possible. I mocked up 3 pages which should give you a proof of concept:</p> <p>.aspx page:</p> <pre><code>&lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:TextBox TextMode="password" ID="TextBo...
<p>I found a working solution in <a href="https://www.mikesdotnetting.com/article/293/request-form-is-empty-when-posting-to-aspx-page" rel="nofollow noreferrer">https://www.mikesdotnetting.com/article/293/request-form-is-empty-when-posting-to-aspx-page</a>. The key is, remove .aspx from action attribute.</p> <p>EX: <co...
25,684
<p>This link describes an exploit into my app using fckEditor: <a href="http://knitinr.blogspot.com/2008/07/script-exploit-via-fckeditor.html" rel="nofollow noreferrer">http://knitinr.blogspot.com/2008/07/script-exploit-via-fckeditor.html</a></p> <p>How do I make my app secure while still using fckEditor? Is it an f...
<p>Sanitize html server-side, no other choice. For PHP it would be <a href="http://htmlpurifier.org" rel="nofollow noreferrer">HTML Purifier</a>, for .NET I don't know. It's tricky to sanitize HTML - it's not sufficient to strip script tags, you also have to watch out for on* event handlers and even more, thanks to stu...
<blockquote> <p>I understand the DONTS. I'm lacking a DO.</p> </blockquote> <p>Is use of FCKEditor a requirement, or can you use a different editor/markup language? I advise using Markdown and WMD Editor, the same language used by StackOverflow. The Markdown library for .NET should have an option to escape all HTML ...
9,144
<p>I have a temporary file with data that's returned as part of a SOAP response via a MTOM binary attachment. I would like to trash it as soon as the method call "ends" (i.e., finishes transferring). What's the best way for me to do this? The best way I can figure out how to do this is to delete them when the sessio...
<p>I ran into this same problem. The issue is that the JAX-WS stack manages the file. It is not possible to determine in your code when JAX-WS is done with the file so you do not know when to delete it.</p> <p>In my case, I am using a DataHandler on my object model rather than a file. MyFileResult would have the follo...
<p>Are you using standard java temp files? If so, you can do this:</p> <pre><code>File script = File.createTempFile("temp", ".tmp", new File("./")); ... use the file ... script.delete(); // delete when done. </code></pre>
19,181
<p>I'm checking out the Delphi 2009 Trial, but run into problems with the generics stuff right away.</p> <p>The following code does not compile, and I haven't the slightest idea why it's giving me E2015 for the Equals() method:</p> <pre><code>type TPrimaryKey&lt;T&gt; = class(TObject) strict private fValue: T...
<p>What if T is a string? What if it's a TSize record?</p> <p>Without constraining T (e.g. with &lt;T :class>), you can't be sure that the comparison will be meaningful.</p> <p>If, instead, you wanted to compare two values of type T, you can use the Generics.Defaults unit and use:</p> <pre><code>TEqualityComparer&lt...
<p>The compiler has trouble in determining that both "T"'s are the same. But with a little trick you can make it work:</p> <pre><code>type TPrimaryKey&lt;T&gt; = class(TObject) public type TCompare&lt;T1&gt; = reference to function(const A1, A2: TPrimaryKey&lt;T1&gt;): Boolean; private fValue: T; ...
34,035
<p>Is there a way to get at the ItemContaner of a selected item in a listbox? In Silverlight 2.0 Beta 1 I could, but the container is hidden in Beta 2 of Silverlight 2.0. </p> <p>I'm trying to resize the listbox item when it is unselected to a specific size and when selected to a variable size. I also want to get th...
<p>There is a way to obtain the Panel containing the item's UIElement and the mapping of items to UIElements. You have to inherit from ListBox (this actually works for any ItemsControl) and override PrepareContainerForItemOverride:</p> <pre><code>protected override void PrepareContainerForItemOverride(DependencyObject...
<p>If you are adding non-UI elements to the listbox (such as strings or non-UI data objects), then this is probably pretty difficult. However if you wrap your items in some sort of FrameworkElement-derived object before adding them to the listbox, you can use TransformToVisual to get the relative size and use Height a...
8,430
<p>Generally I connect and retrieve data using the standard way (error checking removed for simplicity):</p> <pre><code>$db = mysql_select_db("dbname", mysql_connect("host","username","passord")); $items = mysql_query("SELECT * FROM $db"); while($item = mysql_fetch_array($items)) { my_function($item[rowname]); } ...
<p>Since version 5.1, PHP is shipped with the PDO driver, which gives a class for prepared statements.</p> <pre><code>$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); //connect to the database //each :keyword represents a parameter or value to be bound later $query= $dbh-&gt;prepare('SELECT * F...
<p>You can use the mysql_fetch_object()</p> <p><a href="http://is2.php.net/manual/en/function.mysql-fetch-object.php" rel="nofollow noreferrer">http://is2.php.net/manual/en/function.mysql-fetch-object.php</a></p>
34,801
<p>I am taking on a maintenance team and would like to introduce tools like FxCop and StyleCop to help improve the code and introduce the developers to better programming techniques and standards. Since we are maintaining code and not making significant enhancements, we will probably only deal with a couple of methods/...
<p>I am using FxCopCmd.exe (FxCop 1.36) as an external tool with various command line parameters, including this one:</p> <pre><code>/types:&lt;type list&gt; [Short form: /t:&lt;type list&gt;] Analyze only these types and members. </code></pre>
<p>I would guess that it can't (seems a too-specific need).</p>
12,918
<p>I have a read query that I execute within a transaction so that I can specify the isolation level. Once the query is complete, what should I do?</p> <ul> <li>Commit the transaction </li> <li>Rollback the transaction</li> <li>Do nothing (which will cause the transaction to be rolled back at the end of the using blo...
<p>You commit. Period. There's no other sensible alternative. If you started a transaction, you should close it. Committing releases any locks you may have had, and is equally sensible with ReadUncommitted or Serializable isolation levels. Relying on implicit rollback - while perhaps technically equivalent - is just po...
<p>Do you need to block others from reading the same data? Why use a transaction?</p> <p>@Joel - My question would be better phrased as "Why use a transaction on a read query?"</p> <p>@Stefan - If you are going to use AdHoc SQL and not a stored proc, then just add the WITH (NOLOCK) after the tables in the query. This...
39,921
<p>Is it possible to create a toggle button in C# WinForms? I know that you can use a CheckBox control and set it's Appearance property to "Button", but it doesn't look right. I want it to appear sunken, not flat, when pressed. Any thoughts?</p>
<p>You can just use a <code>CheckBox</code> and set its appearance to <code>Button</code>:</p> <pre><code>CheckBox checkBox = new System.Windows.Forms.CheckBox(); checkBox.Appearance = System.Windows.Forms.Appearance.Button; </code></pre>
<p>Changing a CheckBox appearance to Button will give you difficulty in adjustments. You cannot change its dimensions because its size depends on the size of your text or image.</p> <p>You can try this: (initialize the <em>count</em> variable first to 1 | int count = 1)</p> <pre><code>private void settingsBtn_Click(o...
35,718
<p>can you set SO_RCVTIMEO and SO_SNDTIMEO socket options in boost asio?</p> <p>If so how?</p> <p>Note I know you can use timers instead, but I'd like to know about these socket options in particular. </p>
<p>Absolutely! Boost ASIO allows you to access the native/underlying data, which in this case is the SOCKET itself. So, let's say you have:</p> <pre><code>boost::asio::ip::tcp::socket my_socket; </code></pre> <p>And let's say you've already called <code>open</code> or <code>bind</code> or some member function that ...
<p>An easy work-around to this problem would be to use the native read and write functions.</p> <p>For writing with 1sec timeout:</p> <pre><code>struct timeval tv = { 1, 0 }; setsockopt(socket.native_handle(), SOL_SOCKET, SO_SNDTIMEO, &amp;tv, sizeof(tv)); ssize_t nsent = ::write(socket-&gt;native_handle(), buff, siz...
37,390
<p>If I have a windows service on a server, what is 'best practise' for updating the service? (say there was a bug in it, or I need to ad more features to it).</p> <p>Is there a way I could shutdown the service, patch it and get it up and running in a more automated way?</p> <p>(any links with code would be great)</p...
<p>Well, you could always up the version on the installer (if you used one) and run that, from my experience it overlays old versions with the newer one.</p> <p>Or you could simply shut down the service, copy in the new .exe (and dependencies if any) and start it back up. This could all be done with scripting and the ...
<p>InstallShield supports Windows Services. Leveraging installers will make your task much simpler.</p>
30,653
<p>I mean other than using it when required for functions, classes, if, while, switch, try-catch.</p> <p>I didn't know that it could be done like <a href="https://stackoverflow.com/questions/241088/what-do-curly-braces-by-themselves-mean-in-java">this until I saw this SO question</a>.</p> <p>In the above link, Eli me...
<p>I do if I am using a resource which I want to free at a specific time eg:</p> <pre><code>void myfunction() { { // Open serial port SerialPort port("COM1", 9600); port.doTransfer(data); } // Serial port gets closed here. for(int i = 0; i &lt; data.size(); i++) doProcessData(data[i]); etc......
<p>I agree with agartzke. If you feel that you need to segment larger logical code blocks for readability, you should consider refactoring to clean up busy and cluttered members.</p>
30,950
<p>First of all, this question regards MySQL 3.23.58, so be advised.</p> <p>I have 2 tables with the following definition:</p> <pre><code>Table A: id INT (primary), customer_id INT, offlineid INT Table B: id INT (primary), name VARCHAR(255) </code></pre> <p>Now, table A contains in the range of 65k+ records, while ...
<p>I'm going to guess that your main problem is that you are using such an old version of MySQL. Maybe MySQL 3 doesn't like the COUNT(DISTINCT()).</p> <p>Alternately, it might just be system performance. How much memory do you have?</p> <p>Still, MySQL 3 is really old. I would at least put together a test system to s...
<p>How is kundeid defined? It would be helpful to see the full schema for both tables (as generated by MySQL, ie. with indexes) as well as the output of EXPLAIN with the queries above.</p> <p>The easiest way to debug this and find out what is your bottleneck would be to start removing fields, one by one, from the quer...
13,959
<p>This seems like a very simple and a very common problem. The simplest example I can think of is this:</p> <p>The form has five checkboxes with a "check all/check none" checkbox above them. When a user selects checking all checkboxes, I toggle the states of the "children" - obviously I don't want to fire the check e...
<p>I've come across this before and usually seen people do this:</p> <pre><code>/*SNIP*/ private bool isMassUpdate; public void Check1_Check(object sender, EventArgs e) { if(!isMassUpdate) { do some stuff } } /*SNIP*/ </code></pre> <p>You can also detach and reattach the event handlers, however, I'...
<p>You could also consider handling 'click' events for the buttons, rather than check-changed. That might be nearer to your intent.</p>
36,593
<p>I have some auto-generated code which effectively writes out the following in a bunch of different places in some code:</p> <pre><code>no warnings 'uninitialized'; local %ENV = %ENV; local $/ = $/; local @INC = @INC; local %INC = %INC; local $_ = $_; local $| = $|; local %SIG = %SIG; use warnings 'uninitializ...
<p>Perhaps you can arrange for the code that uses those locals to be generated as a closure? Then you could</p> <pre><code>sub run_with_env { my ($sub, @args) = @_; no warnings 'uninitialized'; local %ENV = %ENV; local $/ = $/; local @INC = @INC; local %INC = %INC; local $_ = $_; lo...
<p>Perl has <a href="http://search.cpan.org/dist/Sub-Uplevel/lib/Sub/Uplevel.pm" rel="nofollow noreferrer">Sub::Uplevel</a></p>
24,475
<p>We run a .NET 1.1 application on W2k3 server. The app pool is configured to recycle at 512MB. However, a week ago it started to recycle every 2 minutes. Since we run a web farm, the anonymous user we run IIS with is a domain account. About a week ago, that user account expired, and we have to re-enable it. Could tha...
<p>Try finding out more info by <a href="http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx" rel="nofollow noreferrer">Logging ASP.NET Application Shutdown Events</a> </p>
<p>If after checking the logs and all the standard "App Pool Health" settings (the obvious), I would look for other processes that might be mucking around with your web.config file (check the timestamp on it), which of course causes the app to restart.</p> <p>I was once at a customer site and we couldn't figure out wh...
22,409
<p>Has anyone spent several hours to get the UI of their application render correctly in all the browsers?</p> <p>How do you tackle the frustration when simple styles tend to work in one browser but not others..and end of the day you invent the hack to handle it (in some cases that too does not happen), only after was...
<p>I design in Firefox then test in IE rather than the other way around. FireFox is stricter so if it works there it is more likely to work in IE. Saves a little bit of the frustration... </p>
<p>You accept it, learn from it, and with a few years practice know what to do when.</p> <p>Every modern browser but IE is pretty much seemless for all but the most exotic. Keep things simple therefore. Build iteratively against firefox with firebug. Conceptualise the objects well, stick to standards. When you're read...
41,475
<p>Is there a mode, some switch or a programmatic way that I can ask MSBuild to display or output it's calculated dependencies for a given build file?</p> <p><strong>Some background</strong> - I have a large project that requires splitting up to speed up the build time and want to remove the slow changing infrastruct...
<p>The <a href="http://www.codeplex.com/msbuildprofiler" rel="nofollow noreferrer">MSBuild Profiler</a> project should be able to help you in seeing where time is being taken on the build. It doesn't directly show dependencies. With or without build dependencies, just profiling the builds can probably give some insig...
<p>Whilst I asked the original question quite a long time ago, I have moved on in jobs and surprisingly encountered the same need. In this case I was more successful in my pursuit of a tool and discovered <a href="http://www.attrice.info/msbuild/index.htm" rel="nofollow">Microsoft Build Sidekick</a> which offers:</p> ...
20,550
<p>I have a .ico file that is embedded as a resource (build action set to resource). I am trying to create a NotifyIcon. How can I reference my icon?</p> <pre><code>notifyIcon = new NotifyIcon(); notifyIcon.Icon = ?? // my icon file is called MyIcon.ico and is embedded </code></pre>
<p>Your icon file should be added to one of your project assemblies and its Build Action should be set to Resource. After adding a reference to the assembly, you can create a NotifyIcon like this:</p> <pre><code>System.Windows.Forms.NotifyIcon icon = new System.Windows.Forms.NotifyIcon(); Stream iconStream = Applicati...
<p>I created a project here and used an embedded resource (build action was set to Embedded Resource, rather than just resource). This solution doesn't work with Resource, but you may be able to manipulate it. I put this on the OnIntialized() but it doesn't have to go there.</p> <pre><code>//IconTest = namespace; excl...
10,012
<p>There are three places where menus show up in the new MFC functionality (Feature Pack):</p> <ul> <li>In menu bars (CMFCMenuBar)</li> <li>In popup menus (CMFCPopupMenu)</li> <li>In the 'dropdown menu' version of CMFCButton</li> </ul> <p>I want to put icons (high-color and with transparancy) in the menus in all of t...
<p>This is how I got it to work:</p> <h3>First</h3> <p>, as the others said, create an invisible toolbar next to your main toolbar (I'm using the usual names based on AppWizard's names):</p> <pre><code>MainFrm.h: class CMainFrame { //... CMFCToolBar m_wndToolBar; CMFCToolBar m_wndInvisibleToolBar; ...
<p>One thing that can catch a person by surprise is that for customizable (ie, non-locked) toolbars, the first toolbar you make, the framework splits up and turns into some sort of palette bitmap of all icons in the program. If you try to add more toolbars later (or different toolbars) that have bitmaps (or pngs) with...
9,575
<p>quick question: my customer has a situation where he has his database with a varchar field and the corresponding jdbc code is storing/retrieving a boolean.</p> <p>I guess that the boolean values false and true are going to be translated to "0" and "1" but I would like to have a confirmation of this (I can't find th...
<p>I agree with the answer that the semantics are highly database specific, which is why I think the important answer is that you <em>shouldn't</em> do this. A change in JDBC driver or something similar could cause the implicit behaviour to break.</p> <p>Instead, If using raw JDBC, have the code take the boolean and ...
<p>Unfortunately, <code>BOOLEAN</code> semantics are highly database-specific. I'm <em>guessing</em> that the Oracle driver is going to translate boolean values to a <code>VARCHAR</code> field into "<code>true</code>" and "<code>false</code>", rather than <code>0</code> and <code>1</code>, but you should verify this y...
11,490
<p>From a shell script, how do I check if a directory contains files?</p> <p>Something similar to this</p> <pre class="lang-sh prettyprint-override"><code>if [ -e /some/dir/* ]; then echo "huzzah"; fi; </code></pre> <p>but which works if the directory contains one or several files (the above one only works with exac...
<p>The solutions so far use <code>ls</code>. Here's an all bash solution:</p> <pre><code>#!/bin/bash shopt -s nullglob dotglob # To include hidden files files=(/some/dir/*) if [ ${#files[@]} -gt 0 ]; then echo "huzzah"; fi </code></pre>
<pre><code>if ls /some/dir/* &gt;/dev/null 2&gt;&amp;1 ; then echo "huzzah"; fi; </code></pre>
11,682
<p>I need the month+year from the datetime in SQL Server like 'Jan 2008'. I'm grouping the query by month, year. I've searched and found functions like datepart, convert, etc., but none of them seem useful for this. Am I missing something here? Is there a function for this?</p>
<p>If you mean you want them back as a string, in that format;</p> <pre><code>SELECT CONVERT(CHAR(4), date_of_birth, 100) + CONVERT(CHAR(4), date_of_birth, 120) FROM customers </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms187928.aspx" rel="noreferrer">Here are the other format options</a></p...
<p>The following works perfectly! I just used it, try it out.</p> <pre><code>date_format(date,'%Y-%c') </code></pre>
6,744
<p>Every time I start Emacs I see a page of help text and a bunch of messages suggesting that I try the tutorial. How do I stop this from happening?</p>
<p>Emacs has a couple of variables which inhibit these actions. If you edit your emacs control file (.emacs) and insert the following:</p> <pre><code>;; inhibit-startup-echo-area-message MUST be set to a hardcoded ;; string of your login name (setq inhibit-startup-echo-area-message "USERNAME") (setq inhibit-startup...
<p>If your init file is byte-compiled, use the following form instead:</p> <pre><code>(eval '(setq inhibit-startup-echo-area-message "YOUR-USER-NAME")) </code></pre>
17,481
<p>I'm looking for a built-in function/extended function in T-SQL for string manipulation similar to the <code>String.Format</code> method in .NET.</p>
<p>If you are using SQL Server 2012 and above, you can use <code>FORMATMESSAGE</code>. eg.</p> <pre><code>DECLARE @s NVARCHAR(50) = 'World'; DECLARE @d INT = 123; SELECT FORMATMESSAGE('Hello %s, %d', @s, @d) -- RETURNS 'Hello World, 123' </code></pre> <hr> <p>More examples from MSDN: <a href="https://learn.microsoft...
<p>Not exactly, but I would check out some of the <a href="http://www.simple-talk.com/author/robyn-page-and-phil-factor/" rel="nofollow noreferrer">articles</a> on string handling (amongst other things) by "Phil Factor" (geddit?) on Simple Talk.</p>
19,301
<p>I've been using PHP for too long, but I'm new to JavaScript integration in some places. </p> <p>I'm trying to find the fastest way to pass database information into a page where it can be modified and displayed dynamically in JavaScript. </p> <p>Right now, I'm looking at loading a <em>JSON with PHP</em> echo state...
<p>Use the library. If you try to generate it manually, I predict with 99% certainty that the resulting text will be invalid in some way. Especially with more esoteric features like Unicode strings or exponential notation.</p>
<p>Library has worked great for me. FWIW I needed to do this on a project with earlier version of PHP lacking JSON support. Function below worked as a granted risky version of "json_encode" for arrays of strings.</p> <pre><code>function my_json_encode($row) { $json = "{"; $keys = array_keys($row); ...
6,184
<p>What do <code>*args</code> and <code>**kwargs</code> mean?</p> <pre><code>def foo(x, y, *args): def bar(x, y, **kwargs): </code></pre>
<p>The <code>*args</code> and <code>**kwargs</code> is a common idiom to allow arbitrary number of arguments to functions as described in the section <a href="http://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions" rel="noreferrer">more on defining functions</a> in the Python documentation.</p> <...
<ul> <li><code>def foo(param1, *param2):</code> is a method can accept arbitrary number of values for <code>*param2</code>,</li> <li><code>def bar(param1, **param2):</code> is a method can accept arbitrary number of values with keys for <code>*param2</code></li> <li><code>param1</code> is a simple parameter.</li> </ul>...
5,751
<p>I'm using the <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx" rel="nofollow noreferrer">AutoComplete</a> control from the ASP.NET AJAX Control Toolkit and I'm experiencing an issue where the AutoComplete does not populate when I set the focus to the assigned textbox. </p>...
<p>We had exactly the same problem. What we had to do is write a script at the bottom of the page that quickly blurs then refocuses to the textbox. You can have a look at the (terribly hacky) solution here: <a href="http://www.drive.com.au" rel="nofollow noreferrer">http://www.drive.com.au</a> </p> <p>The textbox id...
<p>How are you setting focus? I haven't tried the specific scenario you've suggested, but here's how I set focus to my controls:</p> <pre><code>Public Sub SetFocus(ByVal ctrl As Control) Dim sb As New System.Text.StringBuilder Dim p As Control p = ctrl.Parent While (Not (p.GetType() Is GetType(System.W...
6,444
<p>The section <strong>Last links in the chain: Stashing and the reflog</strong> in <a href="http://ftp.newartisans.com/pub/git.from.bottom.up.pdf" rel="noreferrer">http://ftp.newartisans.com/pub/git.from.bottom.up.pdf</a> recommends stashing often to take snapshots of your work in progress. The author goes as far as...
<p>I certainly wouldn't set up automatic stashing as described in that (otherwise excellent) article, for exactly the reasons you cite.</p> <p>I prefer to use the stash as it is intended to be used, where I deliberately stash and apply changes as I'm working. For periodic backups, I use a proper backup solution. In my...
<p>For backing things up I'd recommend online backup service, similar to dropbox.com You literally don't need to do anything, it just tracks all the changes you make during the day for you.</p> <p>I have it enabled for all my git repositories which just helps me focus on the actual task at hand.</p>
37,981
<p>I've found the "open" command in Mac OS X very handy in the command line. From "man open":</p> <blockquote> <p>The <code>open</code> command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determin...
<p>You could try <code>xdg-open</code>, most Linux distros have it. It will open default associated app for your file.</p> <p>FYI <a href="https://portland.freedesktop.org/doc/xdg-open.html" rel="noreferrer">https://portland.freedesktop.org/doc/xdg-open.html</a></p>
<p>Under Gnome Desktop environment, I use the following command:</p> <pre><code>nautilus `pwd` &amp; </code></pre> <p>This is similar as "open ." command in Mac</p>
33,115
<p>My dilemma is, basically, how to share an enumeration between two applications.</p> <p>The users upload documents through a front-end application that is on the web. This application calls a web service of the back-end application and passes the document to it. The back-end app saves the document and inserts a row ...
<p>I'd suggest against passing an integer between them, simply for purposes of readability and debugging. Say you're going through your logs and you see a bunch of 500 errors for DocumentType=4. Now you've got to go look up which DocumentType is 4. Or if one of the applications refers to a number that doesn't exist ...
<p>I've noticed that when using "Add Service Reference" as opposed to "Add Web Reference" from VS.net, the actual enum values come across as well as the enum names. This is really annoying as I need to support both 2.0 and 3.5 clients. I end up having to go into the 2.0 generated web service proxy code and manually a...
2,402
<p>Whats the best/easiest way to obtain a count of items within an IEnumerable collection without enumerating over all of the items in the collection?</p> <p>Possible with LINQ or Lambda?</p>
<p>You will have to enumerate to get a count. Other constructs like the List keep a running count.</p>
<p>Not possible with LINQ, as calling .Count(...) does enumerate the collection. If you're running into the problem where you can't iterate through a collection twice, try this:</p> <pre><code>List&lt;MyTableItem&gt; myList = dataContext.MyTable.ToList(); int myTableCount = myList.Count; foreach (MyTableItem in myLi...
4,837
<p>I'm writing a mapping app that uses a Canvas for positioning elements. For each element I have to programatically convert element's Lat/Long to the canvas' coordinate, then set the Canvas.Top and Canvas.Left properties.</p> <p>If I had a 360x180 Canvas, can I convert the coordinates on the canvas to go from -180 t...
<p>Here's an all-XAML solution. Well, mostly XAML, because you have to have the IValueConverter in code. So: Create a new WPF project and add a class to it. The class is MultiplyConverter:</p> <pre><code>namespace YourProject { public class MultiplyConverter : System.Windows.Data.IValueConverter { p...
<p>I'm pretty sure you can't do that exactly, but it would be pretty trivial to have a method which translated from lat/long to Canvas coordinates.</p> <pre><code>Point ToCanvas(double lat, double lon) { double x = ((lon * myCanvas.ActualWidth) / 360.0) - 180.0; double y = ((lat * myCanvas.ActualHeight) / 180.0) -...
31,689