instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>I'm loading an XML document in my C# application with the following:</p> <pre><code>XDocument xd1 = new XDocument(); xd1 = XDocument.Load(myfile); </code></pre> <p>but before that, I do test to make sure the file exists with:</p> <pre><code>File.Exists(myfile); </code></pre> <p>But... is there an (easy) way to t...
<p>It's probably just worth catching the specific exception if you want to show a message to the user:</p> <pre><code> try { XDocument xd1 = new XDocument(); xd1 = XDocument.Load(myfile); } catch (XmlException exception) { ShowMessage("Your XML was probably bad..."); } </code></pre>
<p>I would not XDocument.Load(), as per the accepted answer; why would you read the entire file into memory, it could be a huge file?</p> <p>I'd probably read the first few bytes into a byteArray (it could even be any binary file), convert the byteArray to string e.g. <code>System.Text.Encoding.ASCII.GetString(byteAr...
49,158
<p>I'm making a simple form to create polls, therefore I want the possibility to add additional input fields in case the user wants more options in the poll.</p> <p>I've made Javascript code that adds a new input field to the form, but the dynamically added input fields are not posted when the form is submitted (I use...
<p>I just debugged my site where I was having a similar issue. For me it turned out that having my table and form tags in the "wrong" order caused the issue.</p> <p>Broken:</p> <pre> table form </pre> <p>Working:</p> <pre> form table </pre> <p>This points out something pretty important. The browser may render ...
<p>You can always serialize the form yourself using a javascript function and then submit that (using AJAX or a get request or something).<br> <a href="http://malsup.com/jquery/form/comp/" rel="nofollow noreferrer">http://malsup.com/jquery/form/comp/</a></p>
40,289
<p>I have a script that works fine on my test server (using IIS6). The script processes an ajax request and sends a response with the following line:</p> <pre><code>header( 'application/javascript' ); </code></pre> <p>But on my live server, this line crashes the page and causes a 500 error.</p> <p>Do I need to allow...
<p>The header is incorrect, try this instead:</p> <pre><code>header('Content-Type: application/javascript'); </code></pre>
<p>take a look at <strong><a href="http://en.wikipedia.org/wiki/Mime_type" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Mime_type</a></strong></p> <p>There it says you should use application/javascript instead of text/javascript.</p>
10,759
<p>I'd like to be able to create a large (say 20,000 x 20,000) pixel bitmap in a C++ MFC application, using a CDC derived class to write to the bitmap. I've tried using memory DCs as described in the MSDN docs, but these appear to be restricted to sizes compatible with the current display driver.</p> <p>I'm currently...
<p>CDC and CBitmap appears to only support device dependant bitmaps, you might have more luck creating your bitmap with <a href="http://msdn.microsoft.com/en-us/library/ms532292(VS.85).aspx" rel="nofollow noreferrer">::CreateDIBSection</a>, then attaching a CBitmap to that. The raw GDI interfaces are a little hoary, un...
<p>If the image has to be this resolution - say a hi-res scan of an x-ray - then you might want to look at writing custom spooling routines for it - 1.5 gb is very expensive - even for modern desktops.</p> <p>If it is vector based then you can look at SVG as it supports view ports and most allow you to render to other...
16,713
<p>In my experience Meta-templates are really fun (when your compilers are compliant), and can give good performance boosts, and luckily I'm surrounded by seasoned C++ programmers that also grok meta-templates, however occasionally a new developer arrives and can't make heads or tails of some of the meta-template trick...
<p>If you can you find enough candidates who really know template meta-programing then by all means, require it. You will be showing a lot of qualified and potentially productive people the door (there are plenty of legitimate reasons not to know how to do this, namely that if you do it on a lot of platforms, you will...
<p>It's not absolutely necessary to know how to use C++ templates. You can do most things without them. They are however a fantastic feature.</p> <p>Since you roll your own templates, anyone new is going to have to come up to speed with them just like the rest of your code which is going to be the bigger chunk of th...
24,391
<p>"The Google" is very helpful... unless your language is called "R," in which case it spits out tons of irrelevant stuff.</p> <p>Anyone have any search engine tricks for "R"? There are some specialized websites, like those below, but how can you tell Google you mean "R" the language? If I'm searching for something s...
<p><a href="http://rseek.org" rel="noreferrer">http://rseek.org</a> is a great search engine for R manuals, mailing lists, and various websites. It's a Google syndicated search app with specialized UI. I always use it.</p>
<p>You could always search for "R stats", considering R is a statistical program. </p> <p>Edit: <a href="http://www.google.com/search?source=ig&amp;hl=en&amp;rlz=&amp;q=R+stats&amp;btnG=Google+Search" rel="nofollow noreferrer">http://www.google.com/search?source=ig&amp;hl=en&amp;rlz=&amp;q=R+stats&amp;btnG=Google+Sear...
12,758
<p><strong>When using the Entity Framework, does ESQL perform better than Linq to Entities?</strong> </p> <p>I'd prefer to use Linq to Entities (mainly because of the strong-type checking), but some of my other team members are citing performance as a reason to use ESQL. I would like to get a full idea of the pro's/co...
<p>The most obvious differences are:</p> <p>Linq to Entities is strongly typed code including nice query comprehension syntax. The fact that the “from” comes before the “select” allows IntelliSense to help you.</p> <p>Entity SQL uses traditional string based queries with a more familiar SQL like syntax where the SELE...
<p>For direct queries I'm using linq to entities, for dynamic queries I'm using ESQL. Maybe the answer isn't either/or, but and/also.</p>
5,957
<p>For example:</p> <pre><code>javac Foo.java Note: Foo.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. </code></pre>
<p>This comes up in Java 5 and later if you're using collections without type specifiers (e.g., <code>Arraylist()</code> instead of <code>ArrayList&lt;String&gt;()</code>). It means that the compiler can't check that you're using the collection in a type-safe way, using <a href="http://java.sun.com/j2se/1.5.0/docs/gui...
<p>You can keep it in the generic form and write it as:</p> <pre><code>// list 2 is made generic and can store any type of Object ArrayList&lt;Object&gt; list2 = new ArrayList&lt;Object&gt;(); </code></pre> <p>Setting type of <code>ArrayList</code> as <code>Object</code> gives us the advantage to store any type of data...
24,103
<p>All throughout an application wherever error messages (or other user messages) are used I typically hard-code a string. Obviosly this can be really bad (especially when you may have to come back and localize an app). What is the best approach to centralize these strings? A static class? Constants? An XML File? Or a ...
<p>Create the strings in a resource file. You can then localise by adding additional resource files.</p> <p>Check out <a href="https://web.archive.org/web/20190903233229/http://geekswithblogs.net/dotNETPlayground/archive/2007/11/09/116726.aspx" rel="nofollow noreferrer">http://geekswithblogs.net/dotNETPlayground/archiv...
<p>.net has a pretty good support for so-called ressource-files where you can store all strings for one language.</p>
16,485
<p>The question is if a database connection should be passed in by reference or by value?</p> <p>For me I'm specifically questioning a PHP to MySQL connection, but I think it applies to all databases.</p> <p>I have heard that in PHP when you pass a variable to a function or object, that it is copied in memory and the...
<p>A PHP resource is a special type that already is a reference in itself. Passing it by value or explicitly by reference won't make a difference (ie, it's still a reference). You can check this for yourself under PHP4:</p> <pre><code>function get_connection() { $test = mysql_connect('localhost', 'user', 'password')...
<p>i don't really have a specific answer for php, but in general it would seem to me that you would want to pass this by reference if you are not explicitly sure that you encounter performance issues when passing by value.</p>
29,869
<p>Does anybody has an experience with <a href="http://springframework.org/spring-integration" rel="nofollow noreferrer">Spring Integration</a> project as embedded ESB?</p> <p>I'm highly interesting in such use cases as:</p> <ul> <li>Reading files from directory on schedule basis</li> <li>Getting data from JDBC data ...
<p>Remember, "ESB" is just a marketing term designed to sell more expensive software, it's not a magic bullet. You need to consider the specific jobs you need your software to do, and pick accordingly. If Spring Integration seems to fit the bill, I wouldn't be too concerned if it doesn't look much like an uber-expensiv...
<p>This link describes the <a href="http://www.jroller.com/habuma/entry/spring_integration_return_of_the" rel="nofollow noreferrer">FileSucker</a> with Spring Integration. Read up on your Enterprise Integration patterns for more info I think.</p> <p>I kinda think you need to do a bit more investigation your self, or d...
37,371
<p>So I have been working on a small web application (site) for a group of friends of mine and have come to the realization that things need to change. The application has two faces to it </p> <ol> <li>a public facing side that serves dynamic data to visitors and non admins, and </li> <li>an admin side where admins c...
<p>We have a similar problem where we are creating a very large ASP.NET MVC application and to separate functionality into areas we are using a process very similar to <a href="http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx" rel="nofollow noreferrer">this post by Phil Haack</a>. By creating areas you ca...
<p>On a MVC project I am working on I put all the admin stuff in an admin folder. To see the admin folder you must be authenticated and in the correct role. My controllers tend to be very minimal, most logic is in a business layer that the controllers use. </p>
45,667
<p>I have a canvas in Flex that shall be able only to be scrolled in vertical direction, so I set the attributes of the canvas as follows:</p> <pre><code>verticalScrollPolicy="auto" horizontalScrollPolicy="off" </code></pre> <p>The problem here is that the vertical scrollbar covers the content when it appears - altou...
<p>It's a bug. See <em><a href="http://www.nbilyk.com/flex-scrollpolicy-bug" rel="noreferrer">Flex verticalScrollPolicy bug</a></em> for a workaround.</p>
<p>I'm, too. I usually have some problems with the verticalScrollBar in Flex, so I prefer to use the browser's scrollbar for scrolling the complete application. You can found a workaround here: <a href="http://www.davidortinau.com/blog/how_to_resize_the_flex_stage_and_use_the_browser_scrollbar/" rel="nofollow noreferre...
37,365
<p>Has anyone had luck with removing large amount of issues from a jira database instead of using the frontend? Deleting 60000 issues with the bulktools is not really feasible.</p> <p>Last time I tried it, the jira went nuts because of its own way of doing indexes.</p>
<p>We got gutsy and did a truncate on the jiraissues table and then use the rebuild index feature on the frontend. It looks like it's working!</p>
<p>This is old, but I see that this question was just edited recently, so to chime in:</p> <p>Writing directly to the JIRA database is problematic. The reindex feature suggested in the Oct 14 08 answer just rebuilds the Lucene index, so it is unlikely to clean up everything that needs to be cleaned up from the databas...
24,510
<p>Is it even sensible to try forming a scrum when one of the participants is in India (+05:30), and others are in the US (-06:00 and -08:00)? There isn't a comfortable meeting time for everyone with that.</p>
<p>You might want to have everyone post status and questions to a wiki daily in addition to the scrum for the US participants. The point is daily communication in the most effective manner.</p>
<p>Make the process in such a way that the communication happens through one channel. Have scrum at each place and let them update it on to the Project portal(Wiki) or VSTS or any other single channel. So instead of just one morning scrum let this be two scrums per day so you guys will get the benefit of a 24 hours pro...
39,052
<h2>Problem</h2> <p>My CR-10 printer seems to be trying to print the model 4 or 5 layers too low. This means that for the first few layers, the printing nozzle is forced against the bed, preventing extrusion until the print reaches higher layers.</p> <h2>Outcome</h2> <p>This results in the bottom part of the print h...
<p>Did you verify the Cura z-offset actually changed the corresponding G-Codes? </p> <p>I had the opposite problem on my RF1000. To fix the problem I added the following 2 lines to my start G-Codes:</p> <pre><code>M3001 ; Activate Z-Compensation M206 Z-0.3 ; Set z offset 0.3mm closer to the nozzle </code></pre> <p>...
<p>Did you verify the Cura z-offset actually changed the corresponding G-Codes? </p> <p>I had the opposite problem on my RF1000. To fix the problem I added the following 2 lines to my start G-Codes:</p> <pre><code>M3001 ; Activate Z-Compensation M206 Z-0.3 ; Set z offset 0.3mm closer to the nozzle </code></pre> <p>...
1,437
<p>I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) and I've run into this issue in designing my code layout.</p> <p>I have a number of functions that I want to be able to call by index. Specifically, I need to be able to call one randomly for the encrypt process, but the...
<p>What's wrong with function array?</p> <p>You need to call functions by index. So they must be put into some "indexable by index" structure <em>somehow</em>. Array is probably the simplest structure that suits this need.</p> <p>Example (typing out of my head, might not compile):</p> <pre><code>struct FunctionPair ...
<p>An object with an operator() method defined can act a lot like a function but be generally nicer to work with.</p>
15,311
<p>What is the difference in terms of functionality between the Apache HTTP Server and Apache Tomcat?</p> <p>I know that Tomcat is written in Java and the HTTP Server is in C, but other than that I do not really know how they are distinguished. Do they have different functionality?</p>
<p>Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.</p> <p>So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.</p> ...
<p>Apache is an HTTP web server which serve as HTTP.</p> <p>Apache Tomcat is a java servlet container. It features same as web server but is customized to execute java servlet and JSP pages.</p>
5,051
<p>Rails uses the concept of migrations to deal with model changes using the ActiveRecord API.</p> <p>CouchDB uses JSON (nested maps and arrays) to represent its model objects.</p> <p>In working with CouchDB so far, I don't see good ways of recognizing when the document's structure has changed (other than being disci...
<p>Time for RDBMS de-brainwashing. :)</p> <p>One of the biggest points of couchdb's schema-less design is directly aimed at preventing the need for migrations. The JSON representation of objects makes it easy to just duck type your objects.</p> <p>For example, given that you have a blog type web app with posts and wh...
<p>Check out <a href="https://github.com/arunthampi/activecouch/tree/master" rel="nofollow noreferrer">ActiveCouch</a>.</p> <p>CouchDB is schema-less on purpose, so there is not a 1-to-1 mapping of concepts from the ActiveRecord migrations to a CouchDB equivalent. However, ActiveCouch does include migrations for Couc...
15,798
<p>I'm using Visual Studio 2008 Professional Edition. In previous versions, there has been integration with VSS, through which one could "open from SourceSafe" and then, in the solution view, have the ability to interact with the source control by clicking on individual files. I seem to have some integration under 2008...
<p>You have to install the VSS client software, and if you want the auto check out, etc. the project has to be bound to the source control repository. </p> <p>Also try looking in the Tools -> Options -> Source control menu item.</p>
<p>I have tried all the settings in this dropdown.</p> <p>Until I find a way to get the solution explorer integration working correctly, I am running VSS client in a separate window and checking out files by hand.</p>
37,848
<p>Here is the input (html, not xml):</p> <pre><code>... html content ... &lt;tag1&gt; content for tag 1 &lt;/tag1&gt; &lt;tag2&gt; content for tag 2 &lt;/tag2&gt; &lt;tag3&gt; content for tag 3 &lt;/tag3&gt; ... html content ... </code></pre> <p>I would like to get 3 matches, each with two groups. First group would ...
<p>I don't see why you would want to use match group names for that.</p> <p>Here is a regular expression that would match tag name and tag content into numbered sub matches.</p> <pre><code>&lt;(tag1|tag2|tag3)&gt;(.*?)&lt;/$1&gt; </code></pre> <p>Here is a variant with .NET style group names</p> <pre><code>&lt;(?'n...
<p>This will give you named capture groups for what you want. It won't work for nested tags, however.</p> <p><code> /&lt;(?&lt;name&gt;[^&gt;]+)&gt;(?&lt;value&gt;[^&lt;]+)&lt;/\1&gt;/ </code></p>
24,467
<p>I've programmed C and C++ for a long time and so far I've never used exceptions and try / catch. What are the benefits of using that instead of just having functions return error codes? </p>
<p>Possibly an obvious point - a developer can ignore (or not be aware of) your return status and go on blissfully unaware that something failed.</p> <p>An exception needs to be acknowledged in some way - it can't be silently ignored without actively putting something in place to do so.</p>
<p>As @Martin pointed out throwing exceptions forces the programmer to handle the error. For example, not checking return codes is one of the biggest sources of security holes in C programs. Exceptions make sure that you handle the error (hopefully) and provide some kind of recover path for your program. And if you cho...
23,878
<p>Is there a way to force a Samba process to close a given file without killing it?</p> <p>Samba opens a process for each client connection, and sometimes I see it holds open files far longer than needed. Usually i just kill the process, and the (windows) client will reopen it the next time it access the share; but ...
<p>This happens all the time on our systems, particularly when connecting to Samba from a Win98 machine. We follow these steps to solve it (which are probably similar to yours):</p> <ul> <li>See which computer is using the file (i.e. <code>lsof|grep -i &lt;file_name&gt;</code>)</li> <li>Try to open that file from the...
<p>If there isn't an explicit option in samba, that would be impossible to externally close an open file descriptor with standard unix interfaces.</p>
17,168
<p>I'm creating an app that holds loads of loads of user data in memory, and it's mostly keeping it all in List&lt;T&gt; structures (and some Dictionary&lt;T,T&gt; when I need lookup).</p> <p>And I'm wondering...</p> <p>How efficient are Lists? How much memory overhead do I get for each of them? (that is, memory spac...
<p>Lists are arrays underneath, so the performance hit of adding an item, unless it is at the end, will be very costly.</p> <p>Otherwise they will be basically as fast as an array.</p>
<p>The .Net List doesn't use a linked list. It is an array, it starts with 4 positions by default and I think it doubles in size as you add things. So performance can vary a bit depending on how you use it.</p> <hr> <p>If your using VS 2008 run the profiler before you get too far down this rat hole. When we starte...
5,344
<p>Is there any commonly printed plastic which I can buy that might be transparent to UV light? </p> <p>I wish to print a mould, then pour in my plastic which requires a UV light to activate the curing process. </p>
<p>Have you tried printing with Form labs clear resin ? </p> <p>( This is assuming you have access to a desktop SLA like the Form2+ or Form 1 )</p> <p>The printed part itself gets hardened after exposure to uv light and actually can increase the life time of your mould .</p> <p>I have been using the Form labs Form 2...
<p>This is more of a Chemistry question, but seeing as we love 3D printing with exotics, here are a few.</p> <p><a href="https://topas.com/uv-transmission?gclid=Cj0KCQjwy9LVBRDOARIsAGqoVnuAAAiwiHetZN76JqaRFnq7KKy6br9e6MLDQA4Zlrt01Ceh8GfQrzIaAu7xEALw_wcB" rel="nofollow noreferrer">Topas</a> olefin copolymer</p> <p>From ...
856
<p>I'm a 1-2 man band at work, and so far I've been using VSS for two reasons 1) the company was using that when I started a few months ago, and 2) it is friendly with Visual Studio.</p> <p>Needless to say, I would very much like to upgrade to a not-so-archaic source control system. However, I don't want to give up t...
<p>If you can pay for it, <a href="http://www.sourcegear.com/" rel="nofollow noreferrer">Source Gear Vault</a> is designed to be a drop-in replacement.</p> <p>If you can't pay, Subversion with AnkhSVN works well but is a bit different.</p>
<p>For one or two users, <a href="http://www.perforce.com" rel="nofollow noreferrer">perforce</a> is free as well. Once you need more that two users though, you have to start paying for it. They have a SCC plugin as well to allow integration into Visual Studio (and any other program that supports that interface).</p>...
9,288
<p>I'm using some meta-programming to generate a bunch of methods in ruby like so:</p> <pre><code>class EmotionalObject def self.mood( name, *details ) define_method(name) do # ... end end mood :happy, #... mood :sad, #... mood :ebuillent, #... #... end </code></pre> <p>I know that I can p...
<p>Here is a link on a very simple Forms Authentication implementation with roles. I believe this is the most basic Forms Authentication implementation: <a href="http://www.codeproject.com/KB/web-security/formsroleauth.aspx" rel="noreferrer">http://www.codeproject.com/KB/web-security/formsroleauth.aspx</a></p> <p>Her...
<p>Personally if you are going to use the role management, and user functionality already presented in ASP.NET why try to hack together a solution that down the road will limit your ability to expand.</p> <p>Working with the default functionality for role assignment is easy, and you don't have to worry about the prope...
42,283
<p>I want to check if a variable has a valid year using a regular expression. Reading the <a href="http://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html" rel="noreferrer">bash manual</a> I understand I could use the operator =~</p> <p>Looking at the example below, I would expect to see "not OK"...
<p>It was changed between 3.1 and 3.2:</p> <blockquote> <p>This is a terse description of the new features added to bash-3.2 since the release of bash-3.1.</p> <p>Quoting the string argument to the [[ command's =~ operator now forces string matching, as with the other pattern-matching operators.</p> </blockquote> <p>S...
<p>You need spaces around the operator =~</p> <pre> i="test" if [[ $i =~ "200[78]" ]]; then echo "OK" else echo "not OK" fi </pre>
39,198
<p>I am trying to prevent data races in a multihreaded server. My problem is the following: there is a <code>List&lt;RServer&gt;</code>, the type <code>RServer</code> is a class with several fields. Now, the server has several threads all running at the same time and they can modify both the <code>List</code> (adding m...
<p>If you have a contended lock, the second thread has to wait until the first releases the lock.</p> <p>Your plan sounds <em>nearly</em> okay - but you need to lock when <em>reading</em> data as well, to make sure you get the most recent values, and consistent ones. Otherwise you could be half way through writing som...
<p>That is safe. If one thread has acquired the lock, other threads will have to wait until the lock is released.</p> <p>However, improbable as it is, you could hit a performance problem since the lock may be TOO global. It really depends on what your state is and how it is mutated by those threads, so I can't help yo...
27,627
<p>I have two html pages, when you click on something on the first html, it will go to the second one. What I want to do is to show text according to what you clicked on the first html. different texts are wrapped with different ids. Here's how I wrote:</p> <pre><code>&lt;a href="secondpage.html#one"&gt;&lt;/a&gt; &lt...
<p>What you want to do is simulate a click on your anchor when the page loads. Since you're using jQuery, the simplest approach (but far form best) would be the following:</p> <pre> $(window).observe('domready', function () { $(location.hash).click(); }); </pre> <p>attach ondomready-event to window. Fetch element...
<p>When you say "different ids" how are you setting up your anchors on the 2nd page? The anchor on the 2nd page should look like this:</p> <pre><code>&lt;a name='one'&gt;&lt;/a&gt; </code></pre> <p>Put this right above the text that you want to mark on the 2nd page.</p>
33,863
<p>How do I get the <a href="http://en.wikipedia.org/wiki/ASCII" rel="noreferrer">ASCII</a> value of a character as an <code>int</code> in Python?</p>
<p>From <a href="http://mail.python.org/pipermail/python-win32/2005-April/003100.html" rel="noreferrer">here</a>:</p> <blockquote> <p>The function <strong><code>ord()</code></strong> gets the int value of the char. And in case you want to convert back after playing with the number, function <strong><code>chr()</code></...
<p>To get the ASCII code of a character, you can use the <code>ord()</code> function.</p> <p>Here is an example code:</p> <pre><code>value = input("Your value here: ") list=[ord(ch) for ch in value] print(list) </code></pre> <p>Output:</p> <pre><code>Your value here: qwerty [113, 119, 101, 114, 116, 121] </code></p...
28,147
<p>I'm writing a function that fishes out the src from the first image tag it finds in an html file. Following the instructions in <a href="https://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php">this thread</a> on here, I got something that seemed to be working:</p> <pre>...
<p>These two lines of PHP code should give you a list of all the values of the src attribute in all img tags in an HTML file:</p> <pre><code>preg_match_all('/&lt;img\s+[^&lt;&gt;]*src=["\']?([^"\'&lt;&gt;\s]+)["\']?/i', $content, $result, PREG_PATTERN_ORDER); $result = $result[1]; </code></pre> <p>To keep the regex s...
<p>Most likely because the "XML" being picked up by the regex isn't proper XML for whatever reason. I would probably go for a more complicated regex that would pull out the src attribute, instead of using SimpleXML to get the src. This REGEX might be close to what you need.</p> <pre><code>&lt;img[^&gt;]*src\s*=\s*['...
42,248
<p>Is it possible to determine whether my web site is being accessed as a trusted site? In <a href="https://stackoverflow.com/questions/251696/best-way-to-readset-ie-options">another question</a> we determined that, in general, it is not prudent to have visibility to client IE settings. Would this qualify as an excep...
<p>Here's a test you could use:</p> <pre><code>function isTrustedIE(){ try{ var test=new ActiveXObject("Scripting.FileSystemObject"); } catch(e){ return false; } return true; } </code></pre> <p>This will, of course, fail if the user has disabled that particular object, even on a t...
<p>from my understanding this is not possible but you may have some luck testing for a more specific condition, such as the availability of the specific technology or technologies you need. What type of requirements does your client code place on the browser (ActiveX, Java, scripting etc)? Knowing that will be a very...
31,779
<p>I'm trying to pick up ruby by porting a medium-sized (non-OO) perl program. One of my personal idioms is to set options like this:</p> <pre><code>use Getopt::Std; our $opt_v; # be verbose getopts('v'); # and later ... $opt_v &amp;&amp; print "something interesting\n"; </code></pre> <p>In perl, I kind of grit my t...
<p>A while back I ran across <a href="http://blog.toddwerth.com/entries/5" rel="nofollow noreferrer">this blog post</a> (by Todd Werth) which presented a rather lengthy skeleton for command-line scripts in Ruby. His skeleton uses a hybrid approach in which the application code is encapsulated in an application class wh...
<p>The <a href="http://www.rubyinside.com/trollop-command-line-option-parser-for-ruby-944.html" rel="nofollow noreferrer">first hit</a> on google for "<a href="http://www.google.com/search?q=processing%20command%20line%20options%20in%20ruby&amp;sourceid=mozilla2&amp;ie=utf-8&amp;oe=utf-8" rel="nofollow noreferrer">proc...
5,965
<p>I'm considering using Annotations to define my Hibernate mappings but have run into a problem: I want to use a base entity class to define common fields (including the ID field) but I want different tables to have different ID generation strategies:</p> <pre><code>@MappedSuperclass public abstract class Base imple...
<p>In the code above, it looks like you're mixing annotations on fields (superclass) and methods (subclass). The Hibernate <a href="http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#entity-mapping-entity" rel="nofollow noreferrer">reference documentation</a> recommends avoiding this, and I suspect...
<p>If you put your annotations on the getter rather than the field, when you override the method in the subclass, the annotations placed there will be used rather than the ones in the superclass.</p>
42,535
<p>There are some fairly powerful tools like <a href="http://www.culater.net/software/SIMBL/SIMBL.php" rel="nofollow noreferrer">SIMBL</a> or <a href="http://rogueamoeba.com/airfoil/mac/index.php" rel="nofollow noreferrer">Airfoil/Instant Hijack</a> which use code injection.<br> As far as I understand this, these tools...
<p>It depends on what you're using it for and the quality of the code that is being injected. It's possible to have perfectly stable injected code. In fact, when I used to develop third party anti-cheat software for games, code injection was a big part of it, and I was often able to make the games more stable by elimin...
<p>I believe it does not just refer to that <a href="http://en.wikipedia.org/wiki/Code_injection" rel="nofollow noreferrer">kind of code injection</a> for hacking or cracking a system.</p> <p>It is also a technique often used in java world, with tools like <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programm...
26,402
<p>I am using MySQL and PHP for a project I am working. I have created separate users for carrying out different functions (one for running select queries, one for running update queries, etc.) to provide an extra layer of security. This way, I figure if someone does manage to carry out an injection attack (which is ...
<p>Aside from the extended logic, you will also have different connections and essential overhead in that area.</p> <p>IMHO it's wise to not do all your queries in a webapp with the root user and if the data is so <em>hot</em>, then make sure the designated user has no DROP, DELETE etc. priviledges. You could implemen...
<p>I personally don't think it's worth the bother, since it's trickier to code, test and deploy. Make sure your software is immune to SQL injection instead.</p>
17,826
<p>Basically I need a hosted solution, where one can create an account for a project and the distributed team members can interact through that site during the project implementation. I know a lot of such software but not a hosted one.</p>
<p>I think <a href="http://basecamphq.com" rel="nofollow noreferrer">Basecamp</a> is the most popular one.</p>
<p>I use <strong>codeplex.com</strong> from Microsoft and find it excellent, it now accepts svn connections as well as Team System.</p> <p>An excellent alternative would be <strong>code.google.com</strong>, which I've not found wanting.</p> <p>I would propose that both of these are very popular and of the highest qua...
29,214
<p><strong>Situation:</strong></p> <p>I have a simple <em>XML</em> document that contains image information. I need to transform it into <em>HTML</em>. However, I can't see where the open tag is and when I use the <em>XSL</em> code below, it shows the following error message: </p> <blockquote> <p>"Cannot write an a...
<p>Just to clarify the problem here - the error is in the following bit of code:</p> <pre><code>&lt;xsl:attribute name="src"&gt; &lt;xsl:copy-of select="/root/Image/node()"/&gt; &lt;/xsl:attribute&gt; </code></pre> <p>The instruction xsl:copy-of takes a node or node-set and makes a copy of it - outputting a node ...
<p>The other option to try is a straightforward </p> <pre><code>&lt;img width="100" height="100" src="/root/Image/image.jpeg" class="CalloutRightPhoto"/&gt; </code></pre> <p>i.e. without {} but instead giving the direct image path</p>
6,792
<p>When Xdebug is installed/enabled, standard PHP errors (when set to display in the browser) are replaced with more informative messages that include stack traces for each. Also, I've noticed that it also seems to improve output in other areas such as the var_dump() function, formatting/color-coding the output to make...
<p>As for your debugging you'll only find access through PHP extensions, regardless of what IDE you are using.</p> <p>Xdebug is the most popular due to it's extra features, beyond that of what you've even described. Xdebug will do profiling (tracing) into the valgrind format that you can use programs like Kcachegrind ...
<p>Try NuSphere's PHP IDE. It has an integrated debugger also, and you can get a demo version free if you like.</p> <p><a href="http://www.nusphere.com/" rel="nofollow noreferrer">http://www.nusphere.com/</a></p>
27,457
<p>I'm making a method combining Scrum with the OpenUP lifecycle and deliverables. I also want to keep the OpenUP disciplines apart from "Project Management". I can "hide" it so that it's not immediately obvious in my generated method site. But when you then navigate to the "Risk List" artefact for example the PM is s...
<p>I've never used EPF Composer.</p> <p>I did a little bit of google searches and I understand what you are looking for can be done through Configurations (select OpenUP in your Library view) and published View definitions.</p> <p>See slide 83 and 84 of this PPT document. You should be able to take it from there.</p>...
<p>To those who are to lazy <a href="https://www.google.co.uk/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=5&amp;ved=0ahUKEwiUr9P6prjJAhVM2RoKHeQ7AWgQFgg0MAQ&amp;url=http%3A%2F%2Fwww.mountainview-itsm.com%2Fitil-training%2Fdownloads%2FAn_Introduction_to_EPF.ppt&amp;usg=AFQjCNHCNYUI70q5JaQKxZbpqMtdUIAu_w&a...
9,683
<p>Instead of just filling out the form in HTML it should also be possible to just send a post request containing the params.. Is it possible to turn off the authenticity token if, for example, the Accept flag is set to 'application/JSON' in the HTTP header?</p>
<p>The request forgery protection works on the basis of checking the content-type of requests and it only checks the requests that can be made by a browser. No browser is able to generate a request with the content-type set to "application/json" for example. That's why the rails forgery protection routine won't check i...
<blockquote> <p>Wouldn't it be easier to just add the authenticity token to every json request?</p> </blockquote> <p>Yes, but then the client would have to send a request first just to get the token and then another with the actual POST request, which does not make sense IMHO..</p>
45,405
<p>What is the equivalent to web controls in frameworks other than ASP.Net?</p> <p>Specifically I'd like to know about Java, PHP and Ruby on Rails.</p> <p>What are the relative merits/faults of each of these frameworks for web development?</p> <p>I've had some exposure to ASP.Net and have been asked to look into dev...
<p>I believe there aren't.</p> <p>ASP.NET Web controls are a hodgepodge of <code>&lt;input&gt;</code> and <code>&lt;submit&gt;</code> HTML elements put together to make use of the ASP.NET Web Forms Page Lifecycle. This in turn to facilitate windows-forms like behavior in a web application.</p> <p>AFAIK in other frame...
<p>There aren't any. But many high level frameworks define their type of web ui widgets.</p>
31,086
<p>Is it possible to make a big 50MB database native on the iPhone? So that it can be searched very quickly in a smart way? With SQlite?</p>
<p>Yes, you can use SQLite on the iPhone. Since the database is just a file, you can add the 50 MB file to your application, and that's it. SQLite's performance on the iPhone is good, in my experience, although YMMV depending on your exact table layout and indexes.</p> <p>In my opinion, it's definitely worth checking ...
<p>I know the OP probably has long found their solution by now, but I thought I'd add (for the sake of anyone landing here from a google search) our database SDK, RDM Embedded, from Raima, as another possible solution.</p> <p>As far as I can tell, it's the only other native database (not a wrapper) alternative to SQLi...
41,913
<p>How would I go about spawning a separate process using a SQL Server 05/08 trigger? Ideally, I would like to spawn the process and have SQL Server not wait on the process to finish execution. I need to pass a couple parameters from the insert that is triggering the process, but the executable would take care of the r...
<p>a bit of CLR Integration, combined with SQL Service Broker can help you here.</p> <p><a href="http://microsoft.apress.com/feature/70/asynchronous-stored-procedures-in-sql-server-2005" rel="nofollow noreferrer">http://microsoft.apress.com/feature/70/asynchronous-stored-procedures-in-sql-server-2005</a></p>
<p>you want to use the system stored procedure xp_cmdshell </p> <p>info here: <a href="http://msdn.microsoft.com/en-us/library/ms175046.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms175046.aspx</a></p>
15,668
<p>Given the URL (single line):<br> <a href="http://test.example.com/dir/subdir/file.html" rel="noreferrer">http://test.example.com/dir/subdir/file.html</a></p> <p>How can I extract the following parts using regular expressions:</p> <ol> <li>The Subdomain (test)</li> <li>The Domain (example.com)</li> <li>The path wit...
<blockquote> <p>A single regex to parse and breakup a full URL including query parameters and anchors e.g.</p> <p><a href="https://www.google.com/dir/1/2/search.html?arg=0-a&amp;arg1=1-b&amp;arg3-c#hash" rel="noreferrer">https://www.google.com/dir/1/2/search.html?arg=0-a&amp;arg1=1-b&amp;arg3-c#hash</a> </p>...
<pre><code>String s = "https://www.thomas-bayer.com/axis2/services/BLZService?wsdl"; String regex = "(^http.?://)(.*?)([/\\?]{1,})(.*)"; System.out.println("1: " + s.replaceAll(regex, "$1")); System.out.println("2: " + s.replaceAll(regex, "$2")); System.out.println("3: " + s.replaceAll(regex, "$3")); System.out.print...
4,741
<p>What advantage, if any, is provided by formatting C code as follows:</p> <pre><code>while(lock_file(lockdir)==0) { count++; if(count==20) { fprintf(stderr,"Can't lock dir %s\n",lockdir); exit(1); } sleep(3); } if(rmdir(serverdir)!=0) { switch(errno) ...
<p>The top example is know as "Whitesmiths style". <a href="http://en.wikipedia.org/wiki/Indent_style" rel="noreferrer">Wikipedia's entry on Indent Styles</a> explains several styles along with their advantages and disadvantages.</p>
<p>Its just another style--people code how they like to code, and that is one accepted style (though not my preferred). I don't think it has much of a disadvantage or advantage over the more common style in which brackets are not indented but the code within them is. Perhaps one could justify it by saying that it mor...
9,633
<p>I have a large source repository split across multiple projects. I would like to produce a report about the health of the source code, identifying problem areas that need to be addressed.</p> <p>Specifically, I'd like to call out routines with a high cyclomatic complexity, identify repetition, and perhaps run some ...
<p>For measuring cyclomatic complexity, there's a nice tool available at <a href="http://www.traceback.org/2008/03/31/measuring-cyclomatic-complexity-of-python-code/" rel="noreferrer">traceback.org</a>. The page also gives a good overview of how to interpret the results.</p> <p>+1 for <a href="http://www.logilab.org/...
<p>There is a tool called <a href="http://clonedigger.sourceforge.net/" rel="nofollow noreferrer">CloneDigger</a> that helps you find similar code snippets.</p>
12,560
<p>I have developed a simple mechanism for my mvc website to pull in html via jquery which then populates a specified div. All is well and it looks cool.<br> My problem is that i'm now creating html markup inside of my controller (Which is very easy to do in VB.net btw) I'd rather not mix up the sepparation of concern...
<p>This is a solution that is working with ASP.Net MVC 1.0 (many that claim to work with beta 3 don't work with 1.0), doesn't suffer of the 'Server cannot set content type after HTTP headers have been sent' problem and can be called from within a controller (not only a view):</p> <pre><code>/// &lt;summary&gt; /// Ren...
<p>In rails this is called rendering a partial view, and you do it with <code>render :partial =&gt; 'yourfilename'</code>. I believe ASP.NET MVC has a similar <code>RenderPartial</code> method, but I can't find the official docs for MVC to confirm or deny such a thing.</p>
36,354
<p>This I think is related to my use of the nlog C++ API (and my question on the nlog forum is <a href="http://www.nabble.com/NLogC-problems-with-VB6-IDE-tt19662300s6167.html" rel="nofollow noreferrer">here</a>); the purpose of my asking this question here is to get a wider audience to my problem and perhaps to also ge...
<p>Got around the problem by using NLog's COM interface (NLog.ComInterop.DLL) from my unmanaged C++ code. Not as easy to do as the C\C++ API but at least it doesn't crash my VB6 components.</p>
<p>I would try tweaking some of the <strong>Compile</strong> options found in the <strong>Project</strong>, <strong>Properties</strong> menu, <strong>Compile</strong> panel to see if they yield any additional hints as to what is going wrong.</p> <p>For example if you compile the executable to <strong>p-code</strong> r...
15,943
<p>We use BigIP to load balance between our two IIS servers. We recently deployed a WCF service hosted on by IIS 6 onto these two Windows Server 2003R2 servers.</p> <p>Each server is configured with two host headers: one for the load balancer address, and then a second host header that points only to that server. T...
<p>On your bigIP Create 2 new virtual servers <a href="http://server1.domain.com/" rel="nofollow noreferrer">http://server1.domain.com/</a> <a href="http://server2.domain.com/" rel="nofollow noreferrer">http://server2.domain.com/</a></p> <p>create a pool for each VS with only the specific server in it - so there will ...
<p>The URL it uses is based on the bindings in IIS. Does the website have more than one binding? If it does, or is the WCF service used by multiple sites? If it is, then you are SOL AFAIK. We ran into this issue. Basically, there can be only one IIS binding for HTTP, otherwise it bombs.</p> <p>Also, here's info on <a ...
14,922
<p>I am writing code in VS2005 using its STL. I have one UI thread to read a vector, and a work thread to write to a vector. I use ::boost::shared_ptr as vector element.</p> <pre><code>vector&lt;shared_ptr&lt;Class&gt;&gt; vec; </code></pre> <p>but I find, if I manipulate the vec in both thread in the same time(I can...
<p>When you're accessing the same resource from more than one thread, locking is necessary. If you don't, you have all sorts of strange behaviour, like you're seeing.</p> <p>Since you're using Boost, an easy way to use locking is to use the Boost.Thread library. The best kind of locks you can use for this scenario are...
<p>Another alternative is to eliminate the locking altogether by ensuring that the vector is accessed in only one thread. For example, by having the worker thread send a message to the main thread with the element(s) to add to the vector.</p>
33,650
<p>Let's say I'm building a data access layer for an application. Typically I have a class definition for a each kind of object that is stored in the database. Of course, the actual data access retrieves data in the form of a datareader, typed or untyped dataset, or similar, usually with the data needed to create one...
<p>If you aren't content with DataRow or SqlDataReader, you should look at an ORM system like Linq to Sql or nHibernate, instead of re-inventing the wheel yourself.</p> <p>(By the way, this is called the "ActiveRecord" pattern)</p>
<p>@Joel (re: complex queries, joins, etc)</p> <p>The NHibernate and Castle ActiveRecord tool can handle very complex queries and joins via class relationships and a thorough 'Expression' class (which you can add to the query methods) or the use of the 'Hibernate Query Language' (HQL).</p> <p>You can Google any of th...
6,151
<p>How do I raise an event from a user control that was created dynamically?</p> <p>Here's the code that I'm trying where Bind is a public EventHandler</p> <pre><code>protected indDemographics IndDemographics; protected UserControl uc; override protected void OnInit(EventArgs e) { uc = (UserControl)LoadControl("i...
<p>First off, you'll need to make sure that you have the event defined in your usercontrol's code.</p> <p>for example:</p> <pre><code>public class MyUserControl Inherits UserControl Public Event Bind(sender as object, e as EventArgs) public sub SomeFunction() RaiseEvent Bind(me, new EventArgS()) End Su...
<p>I see it (IndDemographics) declared but never actually created, so I'd expect it to be null with just this code.</p>
44,083
<p>Is there a way (preferrably using JavaScript) to determine whether a URL is to a SWF or a JPG? </p> <p>The obvious answer is to sniff the filename for ".jpg" or ".swf" but I'm dealing with banners that are dynamically decided by the server and usually have a lot of parameters and generally don't include an extensio...
<p>You could use javascript to detect if it is a image by creating a dynamic img-tag.</p> <pre><code>function isImage(url, callback) { var img = document.createElement('img'); img.onload = function() { callback(url); } img.src = url; } </code></pre> <p>And then calling it with:</p> <pre><code...
<p>If the URL doesn't have an extension then there is no way to tell without requesting the file from the server.</p>
33,378
<p>We need to develop some kind of buffer management for an application we are developing using C#.</p> <p>Essentially, the application receives messages from devices as and when they come in (there could be many in a short space of time). We need to queue them up in some kind of buffer pool so that we can process the...
<p>C# sharps memory management is actually quite good, so instead of having a pool of buffers, you could just allocate exactly what you need and stick it into a queue. Once you are done with buffer just let the garbage collector handle it.</p> <p>One other option (knowing only very little about your application), is t...
<p>I'm doing something similar. I have messages coming in on MTA threads that need to be serviced on STA threads. </p> <p>I used a <a href="http://blogs.msdn.com/pfxteam/" rel="nofollow noreferrer">BlockingCollection</a> (part of the parallel fx extensions) that is monitored by several STA threads (configurable, bu...
35,688
<p>Is there a way to tunnel a proxy to access a remote sql server database on visual studio 2008? I'm working in a project at college that uses a sql server database but the access is restricted to the internal network. I'd like to access the database from my home too. Thanks in advance.</p>
<p>You can <a href="https://stackoverflow.com/questions/68799/setting-up-a-vpn">setup a VPN</a> easily...</p> <p>Take a look to <a href="http://secure.logmein.com/products/hamachi/vpn.asp?lang=es" rel="nofollow noreferrer">Hamachi</a> and <a href="http://www.remobo.com/" rel="nofollow noreferrer">Rebombo</a>, very eas...
<p>If the colledge has VPN set up, you can set up the VPN on your computer to access the database from home.</p>
31,991
<p>I have HTML that includes symbols such as the Trademark "TM" as superscript (&trade;). In normal HTML, I would use <code>"&amp;trade;"</code> or <code>&amp;#153;</code> to display the Trademark TM. However, I can find no way to import HTML like this into Flex and have it displayed correctly. I am having similar issu...
<p>Okay, this is a tricky one. I just finished a project where we used this open-source library to display HTML: <a href="http://code.google.com/p/flex-htmlfilter" rel="nofollow noreferrer">http://code.google.com/p/flex-htmlfilter</a></p> <p>It handles lists, tables, etc, and is pretty easy to work with. But, I don...
<p>I don't know if this is a good solution for all problems, but if you want to use a RichText control you can load FlowText in to it which allows you to use more HTML, including superscript and other glyphs, like the ones you want to use.</p> <p><a href="https://stackoverflow.com/questions/4601507/how-to-use-superscr...
39,928
<p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p> <ul> <li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li> <li><p><strong>Secondly</stron...
<p>The usual suspects -- profile it, find the most expensive line, figure out what it's doing, fix it. If you haven't done much profiling before, there could be some big fat quadratic loops or string duplication hiding behind otherwise innocuous-looking expressions.</p> <p>In Python, two of the most common causes I've...
<p>A couple of ways to speed up Python code were introduced after this question was asked:</p> <ul> <li><strong>Pypy</strong> has a JIT-compiler, which makes it a lot faster for CPU-bound code.</li> <li>Pypy is written in <a href="https://code.google.com/p/rpython/" rel="nofollow"><strong>Rpython</strong></a>, a subse...
20,809
<p>I admit - I'm a complete novice when it comes to unit testing. I can grasp the concepts easily enough (test one thing, break-fix-test-repeat, etc.), but I'm having a bit of a problem getting my mind around this one...</p> <p>I've been tasked with rewriting a large section of our application, and I've got the class ...
<p>You can also make a subclass of the test-subject that is in the same namespace as the test-subject, and the subclass could expose whatever features necessary for testing. </p> <p>Assuming you have some way of giving this subclass a "test" scope, you're home free. (You dont want this class in your regular code since...
<p>I think that your unit tests should not <em>require</em> anything of the source code, so the first answer certainly works. Have you considered using Reflection? I think it gets around changing the source code; there's a good discussion of this here: <a href="http://www.codeproject.com/KB/cs/testnonpublicmembers.aspx...
29,877
<p>I have been looking for a quadtree/quadtree node implementation on the net for ages. There is some basic stuff but nothing that I would be able to really use it a game.</p> <p>My purpose is to store objects in a game for processing things such as collision detection. I am not 100% certain that a quadtree is the bes...
<p>Quadtrees are used when you only need to store things that are effectively on a plane. Like units in a classic RTS where they are all on the ground or just a little bit above it. Essentially each node has links to 4 children that divide the node's space up into evenly distributed quarters.</p> <p>Octrees do the sam...
<p>Trees in general are problematic for this in that any item inserted can lie on a boundary, and all the methods of dealing with that situation are fairly unsatisfactory.</p> <p>You'll most likely want to sort your objects into moveable and static, and check anything that moved on a given frame against the static obj...
48,546
<p>I have a image upload form that should take image types (PNG, JPEG, GIF), resize it and then save it to a path. </p> <p>For some reason I can't get the PNG file types to work, it works fine with JPEG/GIF and the file is copied so it looks like it's something to do with how I'm creating the PNG. </p> <p>Does PNG cr...
<p>You need to look how your PHP is built.. Eg:</p> <pre><code>GD Support enabled GD Version bundled (2.0.28 compatible) PNG Support enabled </code></pre> <p>If you don't have PNG support compiled in, you'll need to have that updated.</p>
<p>Are you starting with PNG-8 images? There are some issues with PNG-8 vs PNG-24 when working with PHP. Make sure PNG support is compiled in, then take a <a href="http://www.php.net/manual/en/function.imagecreatefrompng.php#71091" rel="nofollow noreferrer">look at this persons solution to the PNG-8 problem</a>.</p>
21,261
<p>For the life of me, I can't remember how to set, delete, toggle or test a bit in a bitfield. Either I'm unsure or I mix them up because I rarely need these. So a "bit-cheat-sheet" would be nice to have.</p> <p>For example: </p> <pre><code>flags = flags | FlagsEnum.Bit4; // Set bit 4. </code></pre> <p>or</p> <pr...
<p><strong>I did some more work on these extensions - <a href="http://hugoware.net:4000/blog/enumeration-extensions-2-0" rel="noreferrer" >You can find the code here</a> </strong></p> <p>I wrote some extension methods that extend System.Enum that I use often... I'm not claiming that they are bulletproof, but they have...
<p>C++ operations are: &amp; | ^ ~ (for and, or, xor and not bitwise operations). Also of interest are >> and &lt;&lt;, which are bitshift operations.</p> <p>So, to test for a bit being set in a flag, you would use: if (flags &amp; 8) //tests bit 4 has been set</p>
11,935
<p>Following on from <a href="https://stackoverflow.com/questions/223832/check-a-string-to-see-if-all-characters-are-hexadecimal-values">this question</a> what would be the best way to write a Char.IsHex() function in C#. So far I've got this but don't like it:</p> <pre><code>bool CharIsHex(char c) { c = Char.ToLo...
<p>From <a href="https://stackoverflow.com/questions/223832/check-a-string-to-see-if-all-characters-are-hexadecimal-values#223854">my answer</a> to the question you linked to:</p> <pre><code>bool is_hex_char = (c &gt;= '0' &amp;&amp; c &lt;= '9') || (c &gt;= 'a' &amp;&amp; c &lt;= 'f') || ...
<p>You can use regular expressions in an extension function:</p> <pre><code>using System.Text.RegularExpressions; public static class Extensions { public static bool IsHex(this char c) { return (new Regex("[A-Fa-f0-9]").IsMatch(c.ToString())); } } </code></pre>
28,276
<p>I have a base class object array into which I have typecasted many different child class objects and am passing it to a sub vi. Is there any way by which I can find out the original type of the object of each individual elements in the array?</p> <p>Thanks ...</p>
<p>For posterity, this was crossposted to the <a href="http://forums.lavag.org/Finding-Object-type-t12034.html&amp;p=52521#entry52521" rel="nofollow noreferrer" title="LAVA">LAVA</a> forums. The user Aristos Queue, one of the developers of LabVIEW's native OO features, answered with the following:</p> <blockquote> ...
<p>NI has a good <a href="http://zone.ni.com/devzone/cda/tut/p/id/3574" rel="nofollow noreferrer">overview of LVOOP</a> that is a must-read, since OO is implemented in a unique way for LabVIEW.</p> <p>Have you tried the '<a href="http://zone.ni.com/reference/en-XX/help/371361B-01/glang/to_more_generic_class/" rel="nof...
16,792
<p>I'm fairly new to c# so that's why I'm asking this here.</p> <p>I am consuming a web service that returns a long string of XML values. Because this is a string all the attributes have escaped double quotes</p> <pre><code>string xmlSample = "&lt;root&gt;&lt;item att1=\"value\" att2=\"value2\" /&gt;&lt;/root&gt;" </...
<p>the following statement in C# </p> <pre><code>string xmlSample = "&lt;root&gt;&lt;item att1=\"value\" att2=\"value2\" /&gt;&lt;/root&gt;" </code></pre> <p>will actually store the value </p> <pre><code>&lt;root&gt;&lt;item att1="value" att2="value2" /&gt;&lt;/root&gt; </code></pre> <p>whereas </p> <pre><code>str...
<p>If you are getting an XML string why not use XML instead strings?</p> <p>you will have access to all elements and attributes and it will be much easier and extremely fast if using the System.Xml namespace</p> <p>in your example you are getting this string:</p> <pre><code>string xmlSample = "&lt;root&gt;&lt;item a...
36,261
<p>I have a CSS like this</p> <pre><code>ul { list-style-image:url(images/bulletArrow.gif); } ul li { background: url(images/hr.gif) no-repeat left bottom; padding: 5px 0 7px 0; } </code></pre> <p>But the bullet image doesn't align properly in IE (it's fine in Firefox). I already have a background image ...
<p>There is a good explanation and solution of this here: <a href="http://css.maxdesign.com.au/listutorial/master.htm" rel="noreferrer">http://css.maxdesign.com.au/listutorial/master.htm</a></p> <p>It says that using <code>list-style-image</code> results in inconsistent placement of the image with different browsers. ...
<p>I see you're removing left padding for list items. For IE, you need to do the same with the left margin - either completely remove it (set to zero) or make it something smaller than the default. Then your list items will align nicely.</p>
34,901
<p>I'm just beginning to learn ASP.NET MVC and I've run into a question. I'm trying to determine whether I should use HtmlHelper to create client controls or if I should just roll my own. My gut wants to lean towards just rolling my own because it gives me total control - and use jQuery to decorate and add cross-brows...
<p>The more they add to HtmlHelper the more I end up using them myself.</p> <p>Take a look at these posts from ScottGu: <a href="http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx" rel="nofollow noreferrer">MVC Preview 5</a> and <a href="http://weblogs.asp.net/scott...
<p>I created a fluent interface for HTML, and I have decided to share it <a href="http://code.google.com/p/mvcfluenthtml/" rel="nofollow noreferrer">here</a>. Maybe you will find it a good alternative. I also wrote a <a href="http://lunaverse.wordpress.com/2008/11/24/mvcfluenthtml-fluent-html-interface-for-ms-mvc/" r...
41,075
<p>We have an application which needs to use Direct3D. Specifically, it needs at least DirectX 9.0c version 4.09.0000.0904. While this should be present on all newer XP machines it might not be installed on older XP machines. How can I programmatically (using C++) determine if it is installed? I want to be able to give...
<p>Call DirectXSetupGetVersion: <a href="http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.directsetup.directxsetupgetversion" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.directsetup.directxsetupgetversion</a></p> <p>You'll need to include dsetup.h</p> <p>Here's...
<p>According to the DirectX 9.0 SDK (summer 2004) documentation, see the GetDXVer SDK sample at \Samples\Multimedia\DXMisc\GetDXVer.</p>
10,515
<p>Are there any browser extensions or printers with OctoPrint built in that would allow me to print straight from the browser?</p> <p>Thinking of a workflow like this:</p> <ol> <li>Make something with Tinkercad (or other online service)</li> <li>download stl or obj</li> <li>select print from bookmark or dropdown menu<...
<p>There was the <a href="https://plugins.octoprint.org/plugins/curalegacy/" rel="nofollow noreferrer">CuraEngine</a> plugin, but it's not really maintained anymore. It should still work though</p>
<p>This works for OctoPI (OctoPrint on a Raspberry Pi).</p> <ol> <li>Add the Samba package to your OctoPrint machine.</li> <li>open an SMB connection to that machine from your browser machine</li> <li>Save your STL to <code>/home/pi/.octoprint/uploads</code> on the Raspberry Pi.</li> </ol> <p>You can save directly from...
1,475
<p>How do I convert a string to the variable name in <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel="noreferrer">Python</a>?</p> <p>For example, if the program contains a object named <code>self.post</code> that contains a variable named, I want to do something like:</p> <pre><code>somef...
<p>As referenced in Stack&nbsp;Overflow question <em><a href="https://stackoverflow.com/questions/295028/">Inplace substitution from ConfigParser</a></em>, you're looking for <code>eval()</code>:</p> <pre><code>print eval('self.post.id') # Prints the value of self.post.id </code></pre>
<p>Use this</p> <pre><code>var=&quot;variable name&quot; def returnvar(string): exec(f&quot;&quot;&quot;global rtn rtn={string}&quot;&quot;&quot;) return rtn </code></pre> <p>var will be your string and run returnvar(var) will to return variable</p>
37,683
<p>Modifying the HTTP Response Using Filters</p>
<p>I think the question relates to ASP.NET, not Java. This might help:</p> <p><a href="http://professionalaspnet.com/archive/2008/04/13/What-is-the-Difference-between-an-httpModule-and-an-httpHandler_3F00_.aspx" rel="nofollow noreferrer">http://professionalaspnet.com/archive/2008/04/13/What-is-the-Difference-between-a...
<p>Use:</p> <blockquote> <h2>response</h2> <p><strong>Purpose</strong></p> <p>The response object is an instance of the Servlet API's <code>HttpServletResponse</code> class</p> <p><strong>Examples</strong></p> <pre><code>class BookController { def downloadFile = { byte[] bytes = // read byt...
45,376
<p>I have a client which is shipping via UPS, and therefore cannot deliver to Post Office boxes. I would like to be able to validate customer address fields in order to prevent them from entering addresses which include a PO box. It would be best if this were implemented as a regex so that I could use a client-side reg...
<p>This should get you started. Test to see if the Address field matches this regex.</p> <pre><code>"^P\.?\s?O\.?\sB[Oo][Xx]." </code></pre> <p>Translation to English: That's a P at the beginning of the line, followed by an optional period and space, followed by an O, followed by an optional period, followed by a s...
<p>I'd start with a regex ala Lizard (but use the "ignore case" flag :)), test on historical data, then iterate as you see what invalid inclusions and exclusions you see in testing.</p>
35,660
<p>Ever since the publication of <a href="https://rads.stackoverflow.com/amzn/click/com/0321200683" rel="nofollow noreferrer" rel="nofollow noreferrer">Enterprise Integration Patterns</a> people have been using the notation introduced in that book for documenting asynchronous heterogenous messaging systems.</p> <p>But...
<p>UML provides a mechanism for extension through <a href="http://en.wikipedia.org/wiki/Profile_%28UML%29" rel="nofollow noreferrer">profiles</a></p> <p>A profile allows you to specify stereotypes, tagged values, and constraints.</p> <p>Every stereotype can have an optional stereotype icon.</p> <p>Perhaps there is a...
<p>I think toolkit hit the nail on the head. The authors of EIP themselves refer to a UML profile in the <a href="http://www.eaipatterns.com/Introduction.html" rel="nofollow noreferrer">introduction to their book</a>. The link they give is broken though, follow instead this link to the OMG's <a href="http://www.omg.org...
41,980
<p>I'm implementing a social networking site. I hope to use drupal or elgg and am trying out both. I'm stuck on customizing the registration to include a neighborhood in addition to city and state.</p> <p>I want to have drop-down menus customize the local information based on the more global information. So, once y...
<p>You're going to want a module like <a href="http://drupal.org/project/activeselect" rel="nofollow noreferrer">Active Select</a> (<a href="http://drupal.org/node/298230" rel="nofollow noreferrer">Drupal 6 port here</a>) that provides that sort of functionality to the Forms API.</p>
<p>for elgg .. there are two plugins you will find usefull.</p> <ol> <li><p>forms - <a href="http://community.elgg.org/pg/plugins/kevin/read/97061/form-and-related-plugins-for-elgg-15-and-higher" rel="nofollow noreferrer">http://community.elgg.org/pg/plugins/kevin/read/97061/form-and-related-plugins-for-elgg-15-and-hi...
47,436
<p>Does anybody know a good tutorial about Squid plug-in development?</p>
<p>There is one in the squid documentation. IIRC it's fairly straightforward - squid forks a process and passes data down a pipe to the process. A somewhat out-of-date but still relevant programmer's guide can be found <a href="http://old.squid-cache.org/Doc/Prog-Guide/" rel="nofollow noreferrer">Here</a>.</p>
<p>You might also find the <a href="http://wiki.squid-cache.org/Features/AddonHelpers?highlight=%28%5CbCategoryFeature%5Cb%29%7C%28faqlisted.yes%29" rel="nofollow">Add-On Helpers for Request Manipulation</a> topic useful.</p>
16,728
<p>I'm storing some files in my database and since I'm storing them in binary format and not keeping any other information, I have to make sure that all of them are in the same format so that I'll be able to "serve" them later (If there's a <strong><em>simple</em></strong> way to infer the file type from a byte array, ...
<p>Use the FileUpload.PostedFile.ContentType property to validate the MIME type ( should be application/pdf ). For security reasons, also validate that the file extension is appropriate ( .pdf ). You could have a static hashtable containing mappings from MIME type to file extension(s) and use as lookup to validate an e...
<p>The FileUpload.PostedFile.ContentType was exactly what I was looking for.</p> <p>Just a heads-up to whoever is trying to do the same thing: it seems that the MIME type for PDF files can be "application/pdf" or "text/pdf", so be sure to check for both.</p>
38,506
<p>What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?</p>
<p>I've had good success using <a href="https://github.com/mockito/mockito" rel="noreferrer">Mockito</a>.</p> <p>When I tried learning about JMock and EasyMock, I found the learning curve to be a bit steep (though maybe that's just me).</p> <p>I like Mockito because of its simple and clean syntax that I was able to g...
<p>I started using mocks through JMock, but eventually transitioned to use EasyMock. EasyMock was just that, --easier-- and provided a syntax that felt more natural. I haven't switched since.</p>
4,273
<p>Can you use CMFCVisualManager with a dialog based application to change the applications appearance? If so how is it done?</p> <p>The idea is to change the shape, colour etc. of controls such as push buttons using the MFC Feature Pack released with MSVC 2008.</p>
<p>No, can't be done, at least not if you're talking about the Feature Pack version. Version 10 of the BCGSoft libraries do have this functionality, see for example: <a href="http://www.bcgsoft.com/bcgcontrolbarpro-versions.htm" rel="nofollow noreferrer">http://www.bcgsoft.com/bcgcontrolbarpro-versions.htm</a> and <a h...
<p>You need to add the Common Controls manifest to your project resources. Here is the code for the manifest file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"&gt; &lt;assemblyIdentity version="1.0.0.0" proces...
9,820
<p>I've tried the tools listed <a href="http://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL" rel="noreferrer">here</a>, some with more success than others, but none gave me valid postgres syntax I could use (tinyint errors etc.)</p>
<p>There's a <code>mysqldump</code> option which makes it output PostgreSQL code:</p> <pre> mysqldump --compatible=postgresql ... </pre> <p>But that doesn't work too well.</p> <p>Instead, please see the <a href="https://github.com/maxlapshin/mysql2postgres" rel="nofollow noreferrer">mysql-to-postgres</a> tool as <a hre...
<p>you will most likely never get a tool for such task which would do all of your job for you. be prepared to do some refactoring work yourself.</p>
11,755
<p>I'm in the process of extending and improving a website that has quite a few structural problems. It looks very much like the developers before me had heard of MVC but didn't understand the ideas of abstraction or modularity. So the MVC "framework" is a) bespoke b) broken c) patched and d) there are several in use a...
<p><strong>But what about the Models? Are they intended to be re-usable amongst different pages?</strong></p> <p>Yes.</p> <p><strong>Should they care about just where the data is stored?</strong> </p> <p>No. They need not know it. All this kinda information is necessary for persistence layer or data layer.</p> <p><...
<p>You'll find more than one thread here about whether to start work from the database schema or the user interface. There's one place to look.</p> <p>I can think of far more than one tool that takes a schema and builds your CRUD UI for you ("scaffolding") than vice versa. There's another place to look. (Poster-child:...
45,757
<p>How do we assign null value to int column in LINQ. eg.</p> <pre><code> SQLDBDataContext sqlD = new SQLDBDataContext(); var result = from p in sqlD.loadsRadius(Convert.ToInt32(Request["radius"]), ..... </code></pre> <p>here if Request["radius"] is null gives an error.</p> <p>I could pass 0 via this but I need to ...
<p>If the exception is a FormatException, my guess is that the value returned by Request["radius"] is actually the string "null". If Request["radius"] actually returned null, Convert.ToInt32() would return zero. You may try using using int.TryParse() to avoid the exception.</p>
<p>as suggested by Codechef..</p> <pre><code>int radius = -1; int.TryParse(Request["radius"],out radius) if(radius &gt; 0) // you can remove this clause if you don't want this { SQLDBDataContext sqlD = new SQLDBDataContext(); var result = from p in sqlD.loadsRadius(radius) } </code></pre>
46,414
<p>You are given a 32-bit unsigned integer array with length up to 2<sup>32</sup>, with the property that more than half of the entries in the array are equal to N, for some 32-bit unsigned integer N. Find N looking at each number in the array only once and using at most 2 kB of memory.</p> <p>Your solution must be d...
<p>Keep one integer for each bit, and increment this collection appropriately for each integer in the array.</p> <p>At the end, some of the bits will have a count higher than half the length of the array - those bits determine N. Of course, the count will be higher than the number of times N occurred, but that doesn't...
<p>I have recollections of this algorithm, which might or might not follow the 2K rule. It might need to be rewritten with stacks and the like to avoid breaking the memory limits due to function calls, but this might be unneeded since it only ever has a logarithmic number of such calls. Anyhow, I have vague recollect...
35,169
<p>We are trying to create a web-service that we plan to pass a variable amount of variables to it.</p> <p>Can this be done?</p> <p>Basically instead of pass all possible parameters we wish to pass only the set values and use the defaults set in the web-service.</p> <p>Here is an example of the XML we are looking to...
<p>I would pass in an xml document instead of doing concreate functions for this. </p> <p>The webservice in your example is leaky - the consumer needs to know too much about this interface and the implementation of the webservice internally. </p> <p>XML Document and then tie that with an XSD. That way you can preva...
<p>You can simply pass a variable-length array as a parameter.</p>
5,431
<p>In the following code doesn't work as </p> <pre><code>public void Foo() { CompanyDataContext db = new CompanyDataContext(); Client client = (select c from db.Clients ....).Single(); Bar(client); } public void Bar(Client client) { CompanyDataContext db = new CompanyDataContext(); db.Client.Attach(cli...
<p>They really mean it with 'This is not supported.'. Attaching to an object fetched from another data context is not implemented. </p> <p>There are a number of workarounds to the problem, the recommended way is by serializing objects, however this is not easy nor a clean approach.</p> <p>The most simple approach I f...
<p>I've created data access classes that encapsulate all the communication with Linq2Sql. These classes have their own datacontext that they use on their objects.</p> <pre><code>public class ClientDataLogic { private DataContext _db = new DataContext(); public Client GetClient(int id) { return _...
49,891
<p>How do you unit test a <code>HttpModule</code> in asp.net given that <code>HttpApplication</code> and <code>HttpContext</code> do no implement an interface ?</p>
<p>In the past before moving to ASP.NET MVC, I used <a href="http://haacked.com/archive/2007/09/09/ihttpcontext-and-other-interfaces-for-your-duck-typing-benefit.aspx" rel="nofollow noreferrer">this library</a> Phil Haack created for Unit Testing anything that used the HttpApplication and HttpContext. It in turned use...
<p>You can use an Isolation (mocking) framework. I know of two tools that enable you to fake/mock any .NET objects - <a href="http://www.typemock.com/typemock-isolator-product3" rel="nofollow">Typemock Isolator</a> and <a href="http://www.telerik.com/products/mocking.aspx" rel="nofollow">Telerik JustMock</a> i think th...
4,488
<p>Does anyone know what this means. Getting this in C# winforms applications:</p> <blockquote> <p>Not a legal OleAut date</p> </blockquote>
<p>It means that somewhere in the program is attempting to convert to or from an OLE Automation Date outside the valid range 1-January-4713 BC to 31-December-9999 AD. It might have slipped through because OLE Automation Dates are represented as a <strong>double</strong>.</p> <p>Start by looking for any uses of the met...
<p>Others have struggled with this. I suggest looking at these threads on <a href="http://www.dotnetnuke.com/Community/ForumsDotNetNuke/tabid/795/forumid/8/threadid/64010/scope/posts/Default.aspx" rel="nofollow noreferrer">DotNetNuke</a> and <a href="http://forums.devshed.com/net-development-87/not-a-legal-oleaut-date-...
40,037
<p>My class is implementing a super-class method which which returns <code>List&lt;JComponent&gt;</code>. The list being returned is read-only:</p> <pre><code>public abstract class SuperClass { public abstract List&lt;JComponent&gt; getComponents(); } </code></pre> <p>In my class, I want to return a field which ...
<p>Declare <code>getComponents()</code> as:</p> <pre><code>public List&lt;? extends JComponent&gt; getComponents() </code></pre>
<p>You could do the cast with <code>@SuppressWarnings</code>. I believe that would be appropriate in this case, just make sure you document why in a comment.</p> <p>Alternately, do the following:</p> <pre><code>public List&lt;JComponent&gt; getComponents() { return new ArrayList&lt;JComponent&gt;( buttons ); } </...
27,618
<p>I have a linux box with a bank of modems and need to create demand-dial (outbound) PPP connections to a very large set of remote machines. Since I have far more remotes than local modems, I'd like to launch one or more instances of <code>pppd</code> in <code>demand</code> mode, but not allocate a particular modem u...
<p>This is the solution I'm going with:</p> <ul> <li>Enumerate the modems as <code>/dev/modem0</code>, <code>/dev/modem1</code>, ...</li> <li>Start an instance of <code>pppd</code> in demand-dial mode for each peer, but instead of a "real" modem, attach it to <code>/dev/modem.</code><em>peer</em>, which the "ppp-on-di...
<p>Does it have to be directly driven by the Linux box, or could you use something like the old Lucent Portmaster boxen?</p>
39,492
<p>I remember hearing Joel say he has 2 different locations where the servers are located, each location has 2 front end servers and 1 back end server.</p> <ol> <li><p>If a one of the hosting facilities goes down, how can he switch over to the other one? (Or is it just going to be a DNS change that will take 24-72 ho...
<p>They talked about this in one of the Stack Overflow podcasts, but I can't find it in the transcripts.</p> <p>1) Each of the two centers handles approximately 1/2 of the users. Fairly often (hourly, I think Joel said) they ship transaction logs to the other site. If site A goes down, they bring up the db backups on ...
<p>Got a few questions in here so I'll break these out:</p> <p><strong>If a one of the hosting facilities goes down, how can he switch over to the other one?</strong></p> <p>There's several ways to do this, including database mirroring (new in SQL Server 2005), log shipping, and replication. I've recorded a <a href="...
30,129
<p>This may not be possible, but I figured I'd ask...</p> <p>Is there any way anyone can think of to track whether or not an automatic variable has been deleted without modifying the class of the variable itself? For example, consider this code:</p> <pre><code>const char* pStringBuffer; { std::string sString( "fo...
<p>In general, it's simply not possible from within C++ as pointers are too 'raw'. Also, looking to see if you were allocated later than the referenced class wouldn't work, because if you change the string, then the c_str pointer may well change.</p> <p>In this particular case, you could check to see if the string is ...
<p>One technique you may find useful is to replace the <code>new</code>/<code>delete</code> operators with your own implementations which mark the memory pages used (allocated by your <code>operator new</code>) as non-accessible when released (deallocated by your <code>operator delete</code>). You will need to ensure t...
25,839
<p>I have the following XAML code:</p> <pre><code>&lt;Window x:Class="RichText_Wrapping.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1"&gt; &lt;Grid&gt; &lt;RichTextBox Height="100" Margin="2" Name="richTextBox1"&gt; ...
<p>This is a confirmed bug with the WPF RichTextBox. To fix it, Bind the PageWidth of the FlowDocument to the RichTextBox width, i.e.</p> <pre><code>&lt;RichTextBox Name="rtb"&gt; &lt;FlowDocument Name="rtbFlowDoc" PageWidth="{Binding ElementName=rtb, Path=ActualWidth}" /&gt; &lt;/RichTextBox&gt; </code></pre> ...
<p>I copy pasted your code and its not in a single column, Do you have a width somewhere that is small? Maybe defined on the code behind for instance.</p>
45,673
<p>What is the best way to use PyGame (SDL) within a PyGTK application?</p> <p>I'm searching for a method that allows me to have a drawing area in the GTK window and at the same time being able to manage both GTK and SDL events.</p>
<p>I've never attempted it myself, but hearing plenty about other people who've tried, it's not a road you want to go down.</p> <p>There is the alternative of putting the gui in pygame itself. There are plenty of gui toolkits built specifically for pygame that you could use. Most of them are rather unfinished, but the...
<p>I tried doing this myself a while ago, and I never got it to work perfectly. Actually I never got it to work at all under Windows, as it kept crashing the entire OS and I ran out of patience. I continued to use it though as it was only important it ran on Linux, and was only a small project. I'd strongly recommend y...
4,527
<p>Using .Net (C#), how can you work with USB devices? </p> <p>How can you detect USB events (connections/disconnections) and how do you communicate with devices (read/write).</p> <p>Is there a native .Net solution to do this?</p>
<p>There is no <em>native</em> (e.g., System libraries) solution for this. That's the reason why <a href="http://www.icsharpcode.net/OpenSource/SharpUSBLib/" rel="nofollow noreferrer">SharpUSBLib</a> exists as mentioned by <a href="https://stackoverflow.com/questions/68749/working-with-usb-devices-in-net#68777">moobaa<...
<p>Most USB chipsets come with drivers. <a href="https://www.silabs.com/products/mcu/usb/Pages/default.aspx" rel="nofollow noreferrer">Silicon Labs</a> has one.</p>
9,429
<p>I noticed that writing to a file, closing it and moving it to destination place randomly fails on Vista. Specifically, MoveFileEx() would return <code>ERROR_ACCESS_DENIED</code> for no apparent reason. This happens on Vista SP1 at least (32 bit). Does not happen on XP SP3.</p> <p>Found <a href="http://groups.google...
<p>I suggest you use <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="nofollow noreferrer">Process Monitor</a> <em>(edit: the artist formerly known as FileMon)</em> to watch and see which application exactly is getting in the way. It can show you the entire trace of file system calls made on...
<p>That usually means something else has an open handle on the file in question, maybe an active virus scanner running? Have you tried running something like Process Monitor from the <a href="http://technet.microsoft.com/en-us/sysinternals/default.aspx" rel="nofollow noreferrer">Sysinternals</a> site? You should be t...
18,494
<p>I'm personally an advocate of the <a href="https://en.wikipedia.org/wiki/%3F:" rel="nofollow noreferrer">ternary operator</a>: <code>() ? : </code></p> <p>I do realize that it has its place, but I have come across many programmers that are completely against ever using it, and some that use it too often.</p> <p>What...
<p>Use it for <strong>simple expressions only</strong>:</p> <pre><code>int a = (b &gt; 10) ? c : d; </code></pre> <p><strong>Don't chain or nest</strong> ternary operators as it hard to read and confusing:</p> <pre><code>int a = b &gt; 10 ? c &lt; 20 ? 50 : 80 : e == 2 ? 4 : 8; </code></pre> <p>Moreover, when using ter...
<p>I'm a big fan of it ... when appropriate.</p> <p>Stuff like this is great, and, personally, I don't find it too hard to read/understand:</p> <pre><code>$y = ($x == &quot;a&quot; ? &quot;apple&quot; : ($x == &quot;b&quot; ? &quot;banana&quot; : ($x == &quot;c&quot; ? &quot;carrot&quot; : &quot;default&quot;)...
19,376
<p>We use a modified version of the IE engine (the COM version in a C# wrapper) to display a lot of the formatted content in our application. The problem, however, is you don't have a lot of control of any printout of such documents. For example, you can't force a color printout without accessing the registry or dire...
<p>mshtml.IHTMLDocument2 doc = webBrowser.Document as mshtml.IHTMLDocument2; doc.execCommand("Print", true, null);</p>
<p>I'm pretty sure the WPF WebBrowser control is just the ActiveX control wrapped up nicely for use in WPF. (The class derives from <code>ActiveXHost</code>).</p>
45,083
<p>I decided to learn <a href="http://en.wikipedia.org/wiki/C++" rel="nofollow noreferrer">C++</a> (I program in <a href="http://en.wikipedia.org/wiki/C_%28programming_language%29" rel="nofollow noreferrer">C</a> at work), and I have been reading some tutorials (and lots of posts here on Stack&nbsp;Overflow). OK, so I ...
<p>Yes, the current directory is not part of your PATH. You don't want it to be, because then you could be in a directory that had a malicious program you didn't know about that you run.</p> <p>What if you were used to running /usr/bin/grep, but you happened to be in a directory that a Bad Person put a malicious copy...
<p>Not having '.' (the current directory) in the PATH is a minor security measure. You could always add it in if you'd like, though it's not a best practice. </p>
32,946
<p>Is there a way to assign a process to a core (or more than one core) on a multi-core system running Windows XP?</p> <p>An answer using a GUI is acceptable.</p>
<p>You can set a process's affinity using task manager. Right click on the process in the "Processes" tab, and select "Set Affinity...". The, uncheck all the processors you don't want it to run on.</p>
<p>Sure thing. Open the Windows Task manager, right click on the process, and select "set affinity".</p>
22,890
<p>I am interested in enabling code folding in Vim for Python code. I have noticed multiple ways to do so.</p> <p>Does anyone have a preferred way to do Python code folding in Vim? I.e, </p> <ul> <li>Do you have a particular Vim plugin that you use and like?</li> <li>Do you use manual folding or do you place markers ...
<p>Personally I can't convince myself to litter my code with the markers. I've become pretty used to (and efficient) at using indent-folding. Together with my mapping of space bar (see below) to open/close folds and the zR and zM commands, I'm right at home. Perfect for Python!</p> <pre><code>set foldmethod=indent nnor...
<p>Based on <a href="https://stackoverflow.com/a/21112061/10247460">the answer by @Genma</a> I glued together the following syntax rules which just need to be added as <code>.vim/after/syntax/python.vim</code></p> <pre><code>syn keyword pythonStatement class def syn match pythonFunction &quot;\h\w*&quot; containedin=py...
46,654