instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>I need to generate random numbers within a specified interval, [max;min].</p> <p>Also, the random numbers should be uniformly distributed over the interval, not located to a particular point.</p> <p>Currenly I am generating as:</p> <pre><code>for(int i=0; i&lt;6; i++) { DWORD random = rand()%(max-min+1) + min...
<h2>Why <code>rand</code> is a bad idea</h2> <p>Most of the answers you got here make use of the <code>rand</code> function and the modulus operator. That method <a href="http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful" rel="noreferrer">may not generate numbers uniformly</a> (it depends on the ...
<p>I just found this on the Internet. This should work:</p> <pre><code>DWORD random = ((min) + rand()/(RAND_MAX + 1.0) * ((max) - (min) + 1)); </code></pre>
36,760
<p>When I get a vanilla Windows system, there's a bunch of stuff I change to make it more developer-friendly.</p> <p>Some of it I remember every time, other stuff I only do as and when.</p> <p>Examples:</p> <ul> <li>Show extensions of all file types</li> <li>Make hidden and system file visible</li> <li>Turn off Wind...
<p>Indeed I do the above, plus deactivating Zip support (<code>regsvr32 /u zipfldr.dll</code>), activating the underscore on Alt shortcuts (Advanced Appearance), replacing Courier New by Andale Mono (replace with your favorite font) in all program settings (after installing it, of course), installing my favorite utilit...
<p>I generally leave Windows Defender online but I don't use an antivirus so....</p> <p>I set my start menu to display small icons and to have no "most recently used programs" active. Instead I pin everything to my start menu:</p> <p><a href="http://www.robpaveza.net/pub/startmenu.png" rel="nofollow noreferrer">My s...
44,806
<p>I have a large 2d array that I serialize and base64_encode and throw into a database. On a different page I pull the array out and when I <code>base64_decode</code> the serialized array I can echo it out and it definitely looks valid.</p> <p>However, if I try to <code>unserialize(base64_decode($serializedArray))</...
<p>Are you sure you're just serializing an array, and not an object (e.g. DOMNode?) Like resources, not all classes are going to be happy with being unserialized. As an example with the DOM (which your error suggests to me you're working with), every node has a reference to the parentNode, and if the parentNode doesn...
<p>What type of elements are in your array? serialize/unserialize does not work with built-in PHP objects, and that is usually the cause of that error.</p> <p>Also, based on your comment this isn't your problem, but to save space in your database don't base64 encode the data, just escape it. i.e. for mysql use mysql_r...
14,503
<p>Oracle Forms10g provides a tool to convert the Oracle Forms modules, from the binary format (.FMB) that Oracle Forms Builder works with, to text format (.FMT).</p> <p>For example, if you create a module called <em>mymodule.fmb</em> with Oracle Forms Builder, and then invoke</p> <pre><code>frmcmp module=mymodule.fm...
<p>Along with the API, note that if you're working at the start of this process you'll probably be better off generating the XML version than the FMT version. The FMT is an older format kept for backward compatibility, and tools like the recently announced Forms -> Oracle APEX converter will want the XML. It's also eas...
<p>According to <a href="http://www.orafaq.com/usenet/comp.databases.oracle.tools/2004/03/31/0352.htm" rel="nofollow noreferrer">this</a> page the author has a perl script to convert the hex back to ascii text (he says to send him an email and he will send it)</p>
28,501
<p>Probably a long question for a simple solution, but here goes...</p> <p>I have a custom made silverlight control for selecting multiple files and sending them to the server. It sends files to a general handler (FileReciever.ashx) using the OpenWriteAsync method of a WebCLient control.</p> <p>Basically, the silverl...
<p>Hrm, maybe a simple solutioin could be to tag the url with a GUID(the guid being unique per file, or transfer, whatever makes sense to your situatuation). Then you can have another simple web service that is capable of checking on the status of the other service, based on the guid, and have your silverlight client q...
<p>I'm assuming that you're concerned that the data being returned from the handler is taking a long time to transfer and the server is not being utilized during that time. There isn't a way to tell when the server is done processing, so I don't think you can do this without changing your architecture.</p> <p>I would ...
18,415
<p>I am planning to design an application XUL &amp; XPCOM for proprietary system. So i have decided to use C/C++ but how can I start the development as a beginner in this field I cannot find a good guide to start around. It will be good if you can give some links and books. I also would like to know how to prevent the ...
<p><a href="https://developer.mozilla.org/en/XUL_Explorer" rel="noreferrer">XUL explorer</a> is a tool that lets you drag and drop XUL. It's good for mocking up an interface or starting to learn about the various elements you can use.</p> <p><a href="https://developer.mozilla.org/en/XULRunner" rel="noreferrer">xulrun...
<p>Preventing the user from modifying your code is futile, as they will always be able to do this.</p> <p>You could of course ship a modified build of xulrunner (containing some required XPCOM as well) which only loads jars signed by some key, but they could trivially hack around that by modifying the binary or the im...
47,405
<p>We have an old project written using Managed C++ syntax. I would like to propose to the team a reasonably pain-free (I don't mind some level of human interaction, I think I'm realistic in my expectations that we'll still have to do some work by hand) method of updating the existing code to C++/CLI syntax so that we ...
<p>Microsoft has a <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=a3581805-1af2-4c34-9d0e-6029cc078441&amp;displaylang=en" rel="nofollow noreferrer">tool</a> that will help a little. <a href="http://blogs.msdn.com/vcblog/archive/2006/12/08/managed-extensions-for-c-to-c-cli-conversion-tool.aspx" rel="...
<p>Unfortunately, I found the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=a3581805-1af2-4c34-9d0e-6029cc078441&amp;displaylang=en" rel="nofollow noreferrer">migration tool</a> from Microsoft to be two steps away from useless. However, there is the <a href="http://www.sandpapersoftware.com/Main/Ref...
18,291
<p>I am compiling a c++ static library in vs2008, and in the solution i also have a startup project that uses the lib, and that works fine. </p> <p>But when using the lib in another solution i get an run-time check failure. "The value of ESP was not properly saved across a functioncall" Stepping through the code i not...
<p>Forgive me for stating the bleeding obvious here, but... I've seen this sort of thing happen many times before when object (.o) and header (.h) files get out of sync. Especially with respect to virtual methods.</p> <p>Consider: The object file is compiled with header:</p> <pre><code>class Foo { virtual void f()...
<p>I remember seeing such things when the struct member alignment (/Zp compiler switch) of the binaries was different. You could check that, too.</p> <p>Setting it via #pragma pack rather than via project settings should be safer.</p>
48,074
<p>I saw this sentence in some matrials:</p> <p>"In Java, simple data types such as int and char operate just as in C."</p> <p>I am wondering that actually they are different in Java &amp; C++?</p> <p>In C++, simple variables like the primitives in Java are assigned a memory address as well, so these primitive types...
<p>Almost.</p> <p>In java primitives are assigned memory as well, but this happens internally and you cannot get the reference.</p> <p>Thre reason was to provide security on memory management.</p>
<p>Primitives are stored onto the Stack and are passed by value.</p> <pre><code>int x = 5; int y = x; y++; // y = 6 // x = 5 </code></pre> <p>Objects are stored onto the heap and are passed by reference.</p> <pre><code>Object a = new Object(); Object b = a; b.someAction(); // A and B point to the same object and...
43,986
<p>Jeffrey Richter is looking for some input on how people are using his PowerThreading library. If anyone out there is using this, what parts of it are you using? He is looking to clean up the library and wants to know what classes people are using.</p> <p><a href="http://www.wintellect.com/PowerThreading.aspx" rel="...
<p>An indirect answer (I don't use that library myself) - if I was looking at complex threading, I'd be very tempted to look at what the <a href="http://msdn.microsoft.com/en-us/magazine/cc163340.aspx" rel="nofollow noreferrer">TPL</a> has to offer in the current CTP, especially looking forward to .NET 4.0.</p>
<p>I watched video linked from MSDN news feed, then downloaded his library shortly after.</p> <p>I haven't really had a chance to get into it too much but I can tell you this, his samples need a <em>lot</em> of work. I took me 15 minutes of poking around to figure out what I should build/run before I could actually e...
29,723
<p>What is a git topic branch? Does it differ from an ordinary branch in some way? Are there any branches that are not topic branches?</p>
<p>Topic branches are typically lightweight branches that you create locally and that have a name that is meaningful for <em>you</em>. They are where you might do work for a bug fix or feature (they're also called feature branches) that is expected to take some time to complete.</p> <p>Another type of branch is the "r...
<blockquote> <p>it looks like the most prominent and important type of branches that aren't topic branches would be release branches on a major, publicly-available repository, right?</p> </blockquote> <p>That's probably right for you, but that's about you and the project you're thinking about; it's not determined by...
36,100
<p>I have an stl with multiple parts that I want to split up. Cura 15 had an option to "split object into parts" but I can't find that in cura 2.4. Did it get removed?</p>
<p>I don't think this feature was implemented at all with Cura v2.x. </p> <p>As the developers say on the v2.1 release, "Cura has been completely reengineered". </p> <p>Finding proper changelog documentation appears to be pretty hard because they have not posted any actual changelogs except the "user friendly viewabl...
<p>I think they removed it because it was inefficient (pretty slow). Still, I just started 3D printing and was a bit disappointed a seemingly easy task needed an other software (Meshmixer) to be achieved.</p>
546
<p>Well, what is one?</p>
<p>It's an identification number that will uniquely identify something. The idea being that id number will be <em>universally</em> unique. Thus, no two things should have the same uuid. In fact, if you were to generate 10 trillion uuids, there would be something along the lines of a .00000006 chance of two uuids bei...
<p>A UUID is a 128-bit number that is used to uniquely identify some entity. Depending on the specific mechanisms used, a UUID is guaranteed to be different or is, at least, extremely likely to be different from any other UUID generated. The UUID relies upon a combination of components to ensure uniqueness. A UUID co...
37,384
<p>What is the technical difference between a process and a thread?</p> <p>I get the feeling a word like 'process' is overused and there are also hardware and software threads. How about light-weight processes in languages like <a href="http://en.wikipedia.org/wiki/Erlang_%28programming_language%29" rel="noreferrer">E...
<p>Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces.</p> <p>I'm not sure what "hardware" vs "software" threads you might be referring to. Threads are an operating e...
<p>From Erlang Programming (2009): Erlang concurrency is fast and scalable. Its processes are lightweight in that the Erlang virtual machine does not create an OS thread for every created process. They are created, scheduled, and handled in the VM, independent of underlying operating system.</p> <p>Erlang implements a...
24,456
<p>I am considering creating a GUI-based tool that I want to be cross-platform. I've dismissed Java, as I personally do not like Swing. I'm currently considering C# and using Mono to make it cross-platform. However I'm wondering whether new-fangled cross-platform languages like Ruby can offer me a decent GUI developmen...
<p><strong>The short answer:</strong> no (because you said <em>cross-platform</em>).</p> <p><strong>The long answer:</strong> cross-platform GUIs are an age-old problem. Qt, GTK, wxWindows, Java AWT, Java Swing, XUL -- they all suffer from the same problem: the resulting GUI doesn't look native on every platform. Wors...
<p>Have you looked at SWT on Java? It uses native widgets and is much easier to get a nice interface with it than Swing.</p>
14,084
<p>Finally, I have a question to ask on Stack Overflow! :-)</p> <p>The main target is for Java but I believe it is mostly language agnostic: if you don't have native assert, you can always simulate it.</p> <p>I work for a company selling a suite of softwares written in Java. The code is old, dating back to Java 1.3 a...
<p>The number one rule is to avoid side-effects in assertions. In other words, the code should behave identically with assertions turned off as it does when assertions are turned on and not failing (obviously assertions that fail are going to alter the behaviour because they will raise an error).</p> <p>The number tw...
<p>you have touched on many of the reasons why i think asserts should be avoided in general. unless you are working with a codebase where assert usage has <em>very</em> strict guidelines, you very quickly get into a situation where you cannot ever turn the assertions off, in which case you might as well just be using ...
48,144
<p>I have a web application that needs to read (and possibly write) files from a network share. I was wondering what the best way to do this would be?</p> <p>I can't give the network service or aspnet accounts access to the network share. I could possibly use impersonation.</p> <p>The network share and the web applic...
<p>Given everyone already has domain accounts. Try IIS integrated authentication. You will get an ugly logon box off network but your creds should pass down to the file share.</p> <p>@lomaxx<br> Are you saying that only you have perms to the share or that you manually mapped it to a drive letter. If the later you c...
<p>I've had no problems connecting to network shares transparently as if they were local drives. The only issue you may have is what you mentioned: having the <code>aspnet</code> account gain access to the share. Impersonation is probably the best way to do this.</p> <p>You should be able to use any filestream objects...
4,899
<p>We would need to embed mathematical formulas through <a href="http://www1.chapman.edu/~jipsen/asciimath.html" rel="nofollow noreferrer">AsciiMathML</a> into <a href="http://sites.google.com" rel="nofollow noreferrer">Google Sites</a> pages (internal wiki for a research team). I am stuck with the limitation of Google...
<p>I used to use <a href="http://www.texify.com/" rel="nofollow noreferrer">texify.com</a>, but they're no longer available. Now I use <a href="http://code.google.com/apis/chart/infographics/docs/formulas.html" rel="nofollow noreferrer">Google Infographics Mathematical Formulas</a>, which has more features <em>and</em...
<p>I don't know how if this is an acceptable solution for you, but you can upload your own HTML (or any other type for that matter) files on Google Pages. So the proposes solution would be: write manually the HTML pages with the necessary JS tags and upload them to Google Pages.</p>
29,422
<p>When writing async method implementations using the BeginInvoke/EndInvoke pattern the code might look something like the following (and to save you guessing this is an async wrapper around a cache):</p> <pre><code>IAsyncResult BeginPut(string key, object value) { Action&lt;string, object&gt; put = this.cache.Pu...
<p>I was wrong, there is a cleaner way.</p> <p>You create <code>Action( IAsyncResult )</code> delegates for the specific <code>EndInvoke()</code> method in the same context where you already know the specific type of the delegate, passing it as the AsyncState. I'm passing <code>EndPut()</code> as the callback for conv...
<p>Why not avoid the problem by just going back to the more general overload:</p> <pre><code>IAsyncResult BeginPut(string key, object value) { return this.BeginPut(null, key, value); } IAsyncResult BeginPut(string region, string key, object value) { Action&lt;string, string, object&gt; put = this.Put; return...
22,946
<p>If I want to call <code>Bar()</code> instead of <code>Foo()</code>, does <code>Bar()</code> return me a copy (additional overhead) of what Foo() returns, or it returns the same object which <code>Foo()</code> places on the temporary stack?</p> <pre><code>vector&lt;int&gt; Foo(){ vector&lt;int&gt; result; ...
<p>Both may happen. However, most compiler will not do copy as soon as you optimize.</p> <p>Your code indicate there should be a copy. However, the compiler is allowed to remove any copy that do not change the semantic and the program.</p> <p>Note: This is why you should NEVER have a copy constructor that does anythi...
<p>Normally it returns a copy of the returned <code>vector&lt;int&gt;</code>. However this highly depends on the optimization done by the compiler. See the following discussion.</p> <p><strong>Debug Build</strong></p> <pre><code>vector&lt;int&gt; Foo(){ 004118D0 push ebp 004118D1 mov ebp,esp 004...
20,058
<p>A while ago bought a Bowden extruder to replace the old built-in one (It was malfunctioning or something that I cannot remember well). This one in particular has been acquired:</p> <p><a href="https://i.stack.imgur.com/LF28s.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LF28s.jpg" alt="The extr...
<p>As long as there is no more information about the printer itself (I searched a bit and around half of buyers were severely unhappy with the result), I'd advise you to make a full check of all of the important parts that make up a 3D printer making ok prints:</p> <ul> <li>Are motors moving as they should?</li> <li>I...
<p>If you converted a printer from direct to Bowden feed, it is possible that the cold side of the hot end is too hot, and you are suffering from heat creap. Simple, less expensive printers often use the extruder stepper and the extruder stepper mount as part of the cooling system.</p> <p>If there is any sort of a he...
1,119
<p>I have a repeater that outputs divs like the following for every item returned from some method.</p> <pre><code>&lt;div class="editor-area"&gt; &lt;div class="title"&gt;the title&lt;/div&gt; &lt;div&gt;the description&lt;/div&gt; &lt;div class="bottom-bar"&gt; &lt;a href="link"&gt;Modify&lt;/a&g...
<p>Yes, this is dead simple with jQuery. First hide everything:</p> <pre><code>$("div.title").hide(); </code></pre> <p>(Matches elements of type "div" with class "title".) Now show the matches:</p> <pre><code>$("div.title:contains(searchText)").show(); </code></pre> <p><a href="http://docs.jquery.com/Selectors/cont...
<p>Craig is very close. Put ".parent()" before ".hide()" or ".show()" to show or hide the parent div.</p> <p>As for your second comment, that's a separate problem but yes, you'll need to account for non-text input. Another idea is to show everything if the filter textbox is blank.</p>
21,577
<p>Now there's something I always wondered: how is sleep() implemented ?</p> <p>If it is all about using an API from the OS, then how is the API made ?</p> <p>Does it all boil down to using special machine-code on the CPU ? Does that CPU need a special co-processor or other gizmo without which you can't have sleep() ...
<p>The "update" to question shows some misunderstanding of how modern OSs work.</p> <p>The kernel is not "allowed" a time slice. The kernel is the thing that gives out time slices to user processes. The "timer" is not set to wake the sleeping process up - it is set to stop the currently running process.</p> <p>In ess...
<p><strong>glibc 2.21 Linux</strong></p> <p>Forwards to the <code>nanosleep</code> system call.</p> <p>glibc is the default implementation for the C stdlib on most Linux desktop distros.</p> <p>How to find it: the first reflex is:</p> <pre><code>git ls-files | grep sleep </code></pre> <p>This contains:</p> <pre><...
21,191
<p>Rather than scraping a Ruby version of this algorithm off the net I wanted to create my own based on its description <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="noreferrer">here</a>. However I cannot figure out two things</p> <pre><code>def primeSieve(n) primes = Array.new for i in 0..n-2...
<p>The following seems to work. I took out the floating point arithmetic and squared instead of square rooting. I also replaced the deletion loop with a "select" call.</p> <pre><code>while primes[index]**2 &lt;= primes.last prime = primes[index] primes = primes.select { |x| x == prime || x%prime != 0 } ...
<p>or </p> <pre><code>x = [] Prime.each(123) do |p| x &lt;&lt; p end </code></pre> <p>There may be a way to use inject here but the inception thing hurts my head today.</p>
29,918
<p>I've been using PostgreSQL a little bit lately, and one of the things that I think is cool is that you can use languages other than SQL for scripting functions and whatnot. But when is this actually useful?</p> <p>For example, the documentation says that the main use for PL/Perl is that it's pretty good at text ma...
<p>"isn't that [text manipulation] more of something that should be programmed into the application?"</p> <p>Usually, yes. The generally accepted "<a href="http://en.wikipedia.org/wiki/Multitier_architecture" rel="nofollow noreferrer">three-tier</a>" application design for databases says that your logic should be in t...
<p>I think most additional languages are offered so that if you develop in that language on a regular basis, you can feel comfortable writing db functions, triggers, etc. The usefulness of these features is to provide a control over data as close to the data as possible.</p>
6,059
<p>From my small amount of experience, I've only used Ant as a build tool. Are there any other projects which are better, and why?</p>
<p><a href="http://maven.apache.org/" rel="noreferrer">Maven</a></p> <p>It is much better than ant because for most common tasks you don't have to write a complicated build.xml, maven has very good defaults and it's all convention over configuration.</p> <p>It has also a big central repository of libraries and it's v...
<p>I would urge you to start with your requirements when considering the right tool. Each project is different, the tool you use should reflect the problem space not the fashion.</p> <p>That being said, I think for general use ant is still probably the best general tool for building java applications. It is often u...
23,586
<p>I have an <a href="http://www.sencha.com" rel="nofollow noreferrer">ExtJS</a> grid on a web page and I'd like to save some of its state information back to the server when the users leaves the page. Can I do this with an Ajax request onUnload? If not, what's a better solution?</p>
<p>You can use an Ajax request, but be sure to make it a synchronous request rather than an asychronous one. Alternatively, simply save state whenever the user makes a change, this also protects the data if the user's browser crashes.</p>
<p>You could also set a cookie using javascript on unload. I think the advantage ajax has over cookies is that you have the data available to you for reporting and the user (if logged in) can utilise the data across different machines.</p> <p>The disadvantage of using ajax is that it might slow down the actual closing...
9,902
<p>I have monthly sales figures stored in separate sheets. I would like to create a plot of sales for multiple products per month. Each product would be represented in a different colored line on the same chart with each month running along the x axis.</p> <p>What is the best way to create a single line chart that p...
<p>Use the Chart Wizard.</p> <p>On Step 2 of 4, there is a tab labeled "Series". There are 3 fields and a list box on this tab. The list box shows the different series you are already including on the chart. Each series has both a "Name" field and a "Values" field that is specific to that series. The final field is th...
<p>2007 is more powerful with ribbon..:=) To add new series in chart do: Select Chart, then click Design in Chart Tools on the ribbon, On the Design ribbon, select "Select Data" in Data Group, Then you will see the button for Add to add new series.</p> <p>Hope that will help.</p>
19,744
<p>It's easy to get the value of a key from a .NET generic Dictionary:</p> <pre><code>Dictionary&lt;int, string&gt; greek = new Dictionary&lt;int, string&gt;(); greek.Add(1, "Alpha"); greek.Add(2, "Beta"); string secondGreek = greek[2]; // Beta </code></pre> <p>But trying to get the keys given a value is not as stra...
<p>Okay, here's the multiple bidirectional version:</p> <pre><code>using System; using System.Collections.Generic; using System.Text; class BiDictionary&lt;TFirst, TSecond&gt; { IDictionary&lt;TFirst, IList&lt;TSecond&gt;&gt; firstToSecond = new Dictionary&lt;TFirst, IList&lt;TSecond&gt;&gt;(); IDictionary&lt...
<p>As a twist of the accepted answer (<a href="https://stackoverflow.com/a/255638/986160">https://stackoverflow.com/a/255638/986160</a>) assuming that the keys will be associated with signle values in the dictionary. Similar to (<a href="https://stackoverflow.com/a/255630/986160">https://stackoverflow.com/a/255630/9861...
31,858
<p>When running PHP in CLI mode, <em>most</em> of the time (not always), the script will hang at the end of execution for about 5 seconds and then output this:</p> <blockquote> <p><code>Error in my_thread_global_end(): 1 threads didn't exit</code></p> </blockquote> <p>It doesn't seem to actually have any effect on ...
<p>This is a known bug with some of the PHP 5.2.X version in the windows fast-cgi implementation</p> <p><a href="http://bugs.php.net/bug.php?id=41350&amp;edit=1" rel="nofollow noreferrer">http://bugs.php.net/bug.php?id=41350&amp;edit=1</a></p> <p>I have encountered this bug before and downgrading my PHP install to 5....
<p>Did you take a look at <a href="http://www.eukhost.com/forums/f15/fix-error-my_thread_global_end-1-threads-didnt-exit-5612/" rel="nofollow noreferrer">this resource</a>? You may want to double check that you got a specific libmysql.dll (5.2.1) that is unaffected by this, and also to double check that you don't have ...
30,478
<p>When Windows Internet Properties -> Connections -> LAN Settings -> Automatic Configuration is set to "Automatically detect settings" how does Windows actually determine/discover what the settings are? Is it a network broadcast or some kind of targeted query to a server configured somewhere in the registry, or someth...
<p>Its simple: Browsers (Firefox works the same) query <code>GET http://wpad/wpad.dat</code>.</p> <p>If a web server named wpad is resolveable, it should serve wpad.dat, a script file analog to netscape PAC files. MIME type must also be "application/x-ns-proxy-autoconfig".</p>
<p>•Go to Tools > Options > General > Connection Settings > •Set to “Manual Proxy Configuration”</p>
23,193
<pre><code>&lt;style type="text/css"&gt; body { font-family:Helvetica, sans-serif; font-size:12px; } p, h1, form, button { border: 0; margin: 0; padding: 0; } .spacer { clear: both; height: 1px; } /* ----------- My Form ----------- */ .myform { margin: 0 auto; width: 400px; padding: 14px;...
<p>(within the style tags) add these new style rules: </p> <pre><code>#basic input.radio { width:20px; } #basic label.radiolabel { width:40px; text-align:left; line-height:24px; } </code></pre> <p>in your html:</p> <p>add a new class to each label, like so:</p> <pre><code>&lt;!-- Problem ---&gt; ...
<p>You have them named the same as a text input - change <code>name="textfield"</code> to <code>name="my_radio"</code></p> <p>You also have no input for the email address, so your labels are out of sync with the inputs</p>
28,820
<p>I've tried this, but get a ClassNotFoundException when calling:</p> <pre><code>Class.forName("com.AClass", false, mySpecialLoader) </code></pre>
<p>The ClassLoader will have to call defineClass to get the Class. According to the JavaDoc for defineClass: </p> <blockquote> <p>If name is not null, it must be equal to the binary name of the class specified by the byte array.</p> </blockquote> <p>If the name is null, it will get it from the bytecode. So y...
<p>It is impossible to return a class named differently than the one requested. However it is possible to use bytecode manipulation tools like ASM to automatically rename the class you want to return to the one requested.</p>
15,239
<p>Functional languages are good because they avoid bugs by eliminating state, but also because they can be easily parallelized automatically for you, without you having to worry about the thread count. </p> <p>As a Win32 developer though, can I use Haskell for some dlls of my application? And if I do, is there a real...
<p>It seems like the book Real World Haskell is just what you're looking for. You can read it free online:</p> <p><a href="http://book.realworldhaskell.org/" rel="noreferrer">http://book.realworldhaskell.org/</a></p>
<p>Since you mention Win32 and DLLs, I presume you're working with unmanaged code. In that case, GHC will work very well for you. Late last year I wrote a DDE server under Windows using <a href="http://www.starling-software.com/en/blog/tsac/2009/01/12.december-surprise-topic-haskell-ffi.html" rel="nofollow noreferrer">...
17,271
<p>Given a list, how would I select a new list, containing a slice of the original list (Given offset and number of elements) ?</p> <h3>EDIT:</h3> <p>Good suggestions so far. Isn't there something specified in one of the SRFI's? This appears to be a very fundamental thing, so I'm surprised that I need to implement it i...
<p>The following code will do what you want:</p> <pre><code>(define get-n-items (lambda (lst num) (if (&gt; num 0) (cons (car lst) (get-n-items (cdr lst) (- num 1))) '()))) ;' (define slice (lambda (lst start count) (if (&gt; start 1) (slice (cdr lst) (- sta...
<p>Try something like this:</p> <pre><code> (define (slice l offset length) (if (null? l) l (if (&gt; offset 0) (slice (cdr l) (- offset 1) length) (if (&gt; length 0) (cons (car l) (slice (cdr l) 0 (- length 1))) '())))) </code></pre>
13,355
<p>Is there a way in Firebug to start a new script file to apply to page? Basically I want to do work like I'd normally do on the Firebug console but be able to to paste in multi-line functions, etc. It doesn't seem like the console is amenable to that.</p>
<p>Down in the lower-right corner of the FireBug UI you should see a red square icon with an up arrow. Use that and stretch it to a size you like.</p> <hr> <p><a href="https://i.stack.imgur.com/SE7Ai.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SE7Ai.gif" alt="Screenshot"></a></p> <p><a href="h...
<p>maybe not within firebug, but you could try some techniques similar to the jQuery bookmarklet.</p> <p><a href="http://erikandcolleen.com/erik/projects/jquery/bookmarklet/" rel="nofollow noreferrer">bookmarklet link</a></p>
17,005
<p>We have a production SQL Server 2005 database server with the production version of our application's database on it. I would like to be able to copy down the data contents of the production database to a development server for testing.</p> <p>Several sites (and Microsoft's forums) suggest using the Backup/Restore...
<p>Well without the proper rights it really becomes more tedious and less than ideal.</p> <p>One way that I would recommend though is to drop all of your constraints and indexes and then add them again once the data has been imported/exported.</p> <p>Not an elegant solution but it'll process really fast.</p> <p>EDIT...
<p>On your Dev machine, setup a linked server to your production machine. Then just</p> <blockquote> <p>INSERT dev.db.dbo.table (fieldlist)</p> <p>SELECT (fieldlist) from prod.db.dbo.table</p> </blockquote>
30,797
<p>I just wrote my first web service so lets make the assumption that my web service knowlege is non existant. I want to try to call a dbClass function from the web service. However I need some params that are in the session. Is there any way I can get these call these session variables from the webservice??</p>
<p>If you are using ASP.NET web services and you want to have a session environment maintained for you, you need to embellish your web service method with an attribute that indicates you require a session.</p> <pre><code>[WebMethod(EnableSession = true)] public void MyWebService() { Foo foo; Session["MyObjectN...
<p>Maybe this will work HttpContext.Current.Session["Name] Or else you might have to take in some parameters or store them in a Database</p>
16,999
<p>I want to change background color of Datagrid header in Silverlight.</p>
<p>Although the DataGrid does not expose a Header Background property, it does have a property for the ColumnHeaderStyle. Using the technique that DaniCE has previously suggested for a single column we can replace the header template for all header columns including the empty space on the right hand side. The down side...
<p>I came up with a "Clean" solution.. Hopefully it works for you. I simply override the DataGrid and I exposed the GetTemplateChild method. Using it you can access the DataGridColumnHeaderPresenter and the DataGridColumnHeaders contained in it...</p> <p>1) Override datagrid</p> <pre><code>/// &lt;summary&gt; /// Ext...
42,181
<p>I have been trying to print an object that is 4 inches tall. About at 3 inches it falls off the bed. I am using tape on the heated bed and right before the print I am wiping the bed with rubbing alcohol. After the first time I tried hot gluing it to the bed when it was mid way through so that it wouldn't fall off bu...
<p>Even though knowing the model of printer is slightly helpful, it's not critical to making your print work. Your PLA manufacturer should have recommendations for both the bed temperature and the nozzle temperature. Is your print bed glass or metal?</p> <p>As an example, my bed is glass and I set the temperature to 7...
<p>If you have a dual-extruder printer, your second nozzle could be hitting the part. As the print grows taller, each hit with the nozzle has more chance to knock the part off the build plate.</p> <p>This can happen from some of the following reasons:</p> <ul> <li>Nozzles aren't level to each other</li> <li>Build pla...
530
<p>A DB Audit Trail captures the User Last Modified, Modified Date, and Created Date.</p> <p>There are several possible implementations:</p> <ul> <li>SQL Server Triggers</li> <li>Add UserModified, ModifiedDate, CreatedDate columns to the database and include logic in Stored Procedures or Insert, Update statements acc...
<p>Depending on what you're doing, you might want to move the audit out of the data layer into the data access layer. It give you more control.</p> <p>I asked a similar question wrt NHibernate and SqlServer <a href="https://stackoverflow.com/questions/15917/data-auditing-in-nhibernate-and-sqlserver">here</a>.</p>
<p>Here is the implementation I use to audit tables: <a href="http://www.simple-talk.com/sql/database-administration/pop-rivetts-sql-server-faq-no.5-pop-on-the-audit-trail/" rel="nofollow noreferrer">Pop Rivett's SQL Server FAQ No.5: Pop on the Audit Trail</a></p>
8,601
<p>My teams evolution of TDD includes what appear to be departures from traditional oop.</p> <ol> <li><p>Moving away from classes that are self sufficient We still encapsulate data where appropriate. But in order to mock any helper classes, we usually create some way to externally set them via constructor or mutator....
<p>OOP is just one paradigm among many possible. It's not a goal in itself, it's a means to an end. You don't have to program object-oriented, not if other paradigms are better suited for you.</p> <p>And countless clever people before you have remarked that unit testing tends to be a lot easier in function-oriented la...
<p>As a regular user of Intellisense, the requirement that all methods be public would drive me insane. I would adhere to OOP on that basis alone, personally.</p>
37,079
<p>The rails books and web pages I've been following have all stuck to very simple projects for the sake of providing complete examples. I'm moving away from the small project app and into a realm of non-browser clients and need to decide where to put code that is shared by all involved parties.</p> <p>The non-browse...
<p>I'd put the shared code in the Rails project's <code>/lib</code> directory and consider making it a custom Rake task.</p>
<p>It really depends on how much you use this shared code. If you use it everywhere, then throw it in the lib folder (as has already been stated here). If you are only using it in a few places, you might want to consider making a plugin out of it and loading it only in the places that use it. It's nice to only load wha...
39,508
<p>I recently upgraded my oracle client to 10g (10.2.0.1.0).</p> <p>Now when I try to connect to a legacy 8.0 database, I get</p> <pre><code>ORA-03134: Connections to this server version are no longer supported. </code></pre> <p>Is there any workaround for this problem, or do I have to install two clients on my loca...
<p><strong>Yes</strong>, you can connect to an Oracle 8i database with the 10g client, but the 8i Database requires the 8.1.7.3 patchset, which you can get from <a href="http://metalink.oracle.com/" rel="nofollow noreferrer">Oracle's Metalink support site</a> (requires login).</p> <p>Here's an <a href="http://forums.o...
<p>The best way to connect an Oracle 8.1.7 and higher is through Instant Client. Download Instant client 10.2 from oracle site, copy all files in the same folder where .NET assemblies resides and use classes located in System.Data.OracleClient. This work for me in .NET 4 project and oracle DB 8.1.7 server.</p>
18,482
<p>I want to pass an int list (List) as a declarative property to a web user control like this:</p> <pre><code>&lt;UC:MyControl runat="server" ModuleIds="1,2,3" /&gt; </code></pre> <p>I created a TypeConverter to do this:</p> <pre><code>public class IntListConverter : System.ComponentModel.TypeConverter { public...
<p>After hooking a debugger into Cassini, I see that the null ref is actually coming from System.Web.Compilation.CodeDomUtility.GenerateExpressionForValue, which is basically trying to get an expression for the int[] array you pass into the List constructor. Since there's no type descriptor for the int[] array, it fail...
<p>pass the list from the code behind...</p> <p>aspx:</p> <pre><code>&lt;UC:MyControl id="uc" runat="server" /&gt; </code></pre> <p>code-behind:</p> <pre><code>List&lt;int&gt; list = new List&lt;int&gt;(); list.add(1); list.add(2); list.add(3); uc.ModuleIds = list; </code></pre>
31,315
<p>Are there any good references for best practices for storing postal addresses in an RDBMS? It seems there are lots of tradeoffs that can be made and lots of pros and cons to each to be evaluated -- surely this has been done time and time again? Maybe someone has at least written done some lessons learned somewhere...
<p>For more international use, one schema to consider is the one used by <a href="https://www.drupal.org/project/addressfield">Drupal Address Field</a>. It's based on the <a href="http://xml.coverpages.org/xnal.html">xNAL standard</a>, and seems to cover most international cases. A bit of digging into that module will ...
<p>I would just put all the fields together in a large NVARCHAR(1000) field, with a textarea element for the user to enter the value for (unless you want to perform analysis on eg. zip codes). All those address line 1, address line 2, etc. inputs are just so annoying if you have an address that doesn't fit well with th...
40,009
<p>I'm wondering if updating statistics has helped you before and how did you know to update them?</p>
<pre><code>exec sp_updatestats </code></pre> <p>Yes, updating statistics can be very helpful if you find that your queries are not performing as well as they should. This is evidenced by inspecting the query plan and noticing when, for example, table scans or index scans are being performed instead of index seeks. A...
<p>Updating statistics becomes necessary after the following events:<br> - Records are inserted into your table<br> - Records are deleted from your table<br> - Records are updated in your table </p> <p>If you have a large database with millions of records that gets lots of writes per day you probably should be determ...
15,925
<p>I am interested in writing static code analyzer for vb.net to see if it conforms to my company standard coding guidelines. Please advise from where i have to start.</p>
<p>Rather than write your own static code analyzer, I recommend you use <a href="http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx" rel="noreferrer">FxCop</a>: and instead, write custom FxCop rules for your needs. It'll save you a lot of time. <a href="http://www.binarycoder.net/fxcop/" rel="noreferrer">http...
<p>Start with FxCop. If you can't do what you're trying there, try something like NStatic or NDepend.</p>
10,020
<p>The problem is that the compiler says that there is a redefinition of a function between a library that belongs to MySQL and math.h from the std library.</p> <p>I have been over this for two days and I still can't figure it out. </p> <p>Has this ever happened to anyone?</p> <p>This is the output from the compiler...
<p><a href="http://bugs.mysql.com/bug.php?id=15936" rel="nofollow noreferrer">This thread</a> in the mysql support area seems to indicate that they've taken the definition of rint() out of their config_win.h file as of April this year (even though the patch was proposed in 2006). Are you using a version of the MySQL s...
<p>In line 228 of c:/Archivos de programa/MySQL/MySQL Server 5.0/include/config-win.h you should find a declaration/definition of function named "rint". In line 620 of C:/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/math.h you should find another definition of a function with the same name (which probably eve...
21,608
<p>I have TFS installed on a single server and am running out of space on the disk. (We've been using the instance for about 2 years now.) </p> <p>Looking at the tables in SQL Server what seems to be culprit is the tbl_content table, it is at 70 GB. If I do a get on the entire source tree for all projects it is only...
<p>I can't help with the ratio question at the moment, sorry. For a short-term fix you might check to see if there is any space within the DB files that can be freed up. You may have already, but if not..</p> <pre><code>SELECT name ,size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS AvailableSpaceInMB ...
<p>Are you seeing data growth every day, even when no activity occurs on the system? If the answer is yes, are you storing any binaries outside of the 8GB of source somewhere?</p> <p>The reason that I ask is that if TFS is unable to calculate a delta or if the file exceeds the size of delta generation, TFS will dupli...
41,222
<p>For customer service week this year, I have the privileged task of creating a technology themed gift basket. I'm trying to keep the basket under $50 as I have a bluetooth keyboard/mouse combo that I'll be adding to it. Besides canned air and monitor wipes, are there any other recommendations for a PC based basket? I...
<p>LED flashlights and multi-tools. You can never have too many LED flashlights and multi-tools!</p>
<p>I pretty much want everything from <a href="http://www.thinkgeek.com" rel="nofollow noreferrer">http://www.thinkgeek.com</a></p>
15,661
<p>Are there any alternatives to <a href="http://www.speech.cs.cmu.edu/cgi-bin/cmudict" rel="nofollow noreferrer">The CMU Pronouncing Dictionary</a>, commercial or open source?</p>
<p>I don't believe the answer is definitively "no," but I do know that CMU is the most popular pronouncing dictionary in my anecdotal experience. I believe it is open source so if it's missing something, perhaps you could find a way to add it (or request it be added).</p> <p>Barring that, I would check with the folks ...
<p>Checkout <a href="http://m-w.com" rel="nofollow noreferrer">Merriam-Webster</a> for things like this:</p> <p><a href="http://www.merriam-webster.com/cgi-bin/audio.pl?stack001.wav=stack" rel="nofollow noreferrer">stack</a> <a href="http://www.merriam-webster.com/cgi-bin/audio.pl?overfl02.wav=overflow" rel="nofollow ...
17,070
<p>Should I start a Python program with:</p> <pre><code>if__name__ == '__main__': some code... </code></pre> <p>And if so, why? I saw it many times but don't have a clue about it.</p>
<p>If your program is usable as a library but you also have a main program (e.g. to test the library), that construct lets others import the file as a library and not run your main program. If your program is named foo.py and you do "import foo" from another python file, <code>__name__</code> evaluates to <code>'foo'</...
<p>This is good practice. First, it clearly marks your module entry point (assuming you don't have any other executable code at toplevel - yuck). Second, it makes your module importable by other modules without executing, which some tools like code checkers, packagers etc. need to do.</p>
36,534
<p>What are some of the best or most popular rule engines? I haven't settled on a programming language, so tell me the rule engine and what programming languages it supports.</p>
<p>I am one of the authors of Drools, I will avoid pimping my wares. </p> <p>But some other options are Jess (not open source) but uses the clips syntax (which we also support a subset of) - which is kinda a lisp dialect. </p> <p>It really depends what you want it for, Haley have strong Natural language tech (and the...
<p>WF is available already in .net 3.0. It is a bit buggy though on the Designer-side in Visual Studio and can get quite messy. I use it on Sharepoint (where WF is pretty much your only option anyway) and overall I am quite satisfied with it, even though the learning curve is rather steep.</p> <p><a href="http://www.a...
2,833
<p>I'm wondering if I should add an SSL layer between my server and client. I'm not handling any confidential data, but there is a very small chance someone might want to hack transmissions in order to gain intelligence (this is a game by the way). Now the amounts of data to be processed are considerable when compared ...
<p>This sounds like an optimization question. If you have information that you feel is valuable, start with SSL (a relatively easy security solution to try out). Once you have things working, benchmark the system with and without. If you feel that the performance hit is worth spending time on to try and optimize awa...
<p>In addition to the notes about about encrypting usernames and passwords during transmission, SSL also prevents <a href="http://en.wikipedia.org/wiki/Man-in-the-middle_attack" rel="nofollow noreferrer">Man in the Middle attacks</a> at the expense of adding overhead to every request.</p> <p>The catch is that you must...
41,056
<p>I have built a .dll under WinXP that claims it can't find DWMAPI.DLL when it's loaded. The problem is that this DLL is a Vista DLL, and this a known issue for XP users that have IE7 installed. The recommendation is to uninstall IE7 or repair the .NET Framework via Add/Remove programs. I did the repair, and nothing c...
<p>Based on your updated problem, DWMAPI.dll is probably not your problem. Dependency walker will always give you that error whenever you are linking to mshtml as it always checks delay loaded DLLs.</p> <p>At this point my best guess is that you have your project set to dynamically load the runtime libraries and the s...
<p>This is a tricky one. There's really 2 main ways you will get this error.</p> <p>1) You have your project set to force delay loaded DLLs to load at application launch. DWMAPI.dll is a delay-loaded DLL and thus normally will not be loaded unless one of it's functions is called. That won't happen on XP unless you're ...
20,898
<p>Usually when I'm creating indexes on tables, I generally guess what the <code>Fill Factor</code> should be based on an educated guess of how the table will be used (many reads or many writes).</p> <p>Is there a more scientific way to determine a more accurate <code>Fill Factor</code> value?</p>
<p>You could try running a big list of realistic operations and looking at IO queues for the different actions.</p> <p>There are a lot of variables that govern it, such as the size of each row and the number of writes vs reads.</p> <p>Basically: high fill factor = quicker read, low = quicker write.</p> <p>However it...
<p>I would tend to be of the opinion that if you're after performance improvements, your time is much better spent elsewhere, tweaking your schema, optimising your queries and ensuring good index coverage. Fill factor is one of those things that you only need to worry about when you <em>know</em> that everything else i...
3,212
<p>How does one start development in Silverlight?</p> <p>Does one need a new IDE? or Visual studio will support?</p>
<p>Yes there is tooling support for Visual Studio. It is still in Beta though.</p> <p><a href="http://silverlight.net/GetStarted/" rel="nofollow noreferrer">Get Started Building Silverlight 2 Applications</a></p> <p>1) Install Visual Studio 2008 then Install Silverlight Tools Beta 2 for Visual Studio 2008 This add-on...
<p>Dan Wahlin has some good Silverlight 2 videos at:</p> <p><a href="http://weblogs.asp.net/dwahlin/archive/2008/03/07/silverlight-2-0-video-tutorials.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/dwahlin/archive/2008/03/07/silverlight-2-0-video-tutorials.aspx</a></p> <p>They are quite helpful.</p> <p>rp</p...
8,554
<p>Last year, Scott Guthrie <a href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx" rel="noreferrer">stated</a> “You can actually override the raw SQL that LINQ to SQL uses if you want absolute control over the SQL executed”, but I can’t find documentation describing an extensibili...
<p>The ability to change the underlying provider and thus modify the SQL did not make the final cut in LINQ to SQL.</p>
<p><code>DataContext x = new DataContext</code></p> <p>Something like this perhaps?</p> <p><code>var a = x.Where().with()</code>...etc </p> <p>It lets you have a much finer control over the SQL.</p>
8,849
<p>How can I simplify an expression using basic arithmetic?</p>
<p>I'm not sure what you mean, but if you have an expression datatype you can define a recursive eval-function. In this case eval means simplify.</p> <p>For example,</p> <pre><code>data Exp = Lit Int | Plus Exp Exp | Times Exp Exp eval :: Exp -&gt; Int eval (Lit x) = x eval (Plus x y) = eval x...
<p>module Expr where</p> <p>-- Variables are named by strings, assumed to be identifiers. type Variable = String</p> <p>-- Representation of expressions. data Expr = Const Integer | Var Variable | Plus Expr Expr | Minus Expr Expr | Mult Expr Expr deriving (Eq, Show)</...
41,474
<p>I'm looking for a VM management solution that will allow me to easily maintain VMs in a single repository accessible on the corporate intranet.</p> <p>I'm currently looking into VMware's vCenter, HP's Manager, Microsoft's VM Manager. vCenter seems to require an ESX server, which I'm not very happy about. I haven'...
<p>Is there a reason you're not wanting an ESX Server?</p> <p>vCenter does require an ESX server, but you can always run ESXi, which would run locally and can be managed by vCenter... and best of all, ESXi is free!</p> <p><a href="http://www.vmware.com/products/esxi/" rel="nofollow noreferrer">http://www.vmware.com/p...
<p>Whether you were to go with VMware ESXi (the free edition of ESX) or the full-blown ESX is a business and maintainability decision.</p> <p>Personally, the cost of the license for ESX to ensure I had the administrative tools, support, and maintenance is worth it in a corporate environment.</p> <p>If it were my pers...
43,865
<p>I have the following file/line:</p> <pre><code>pc=1 ct=1 av=112 cv=1100 cp=1700 rec=2 p=10001 g=0 a=0 sz=5 cr=200 pc=1 ct=1 av=113 cv=1110 cp=1800 rec=2 p=10001 g=0 a=10 sz=5 cr=200 </code></pre> <p>and so on. I wish to parse this and take the key value pairs and put them in a structure:</p> <pre><code>struct pk...
<p>You can do something like this:</p> <pre><code>std::string line; std::map&lt;std::string, std::string&gt; props; std::ifstream file("foo.txt"); while(std::getline(file, line)) { std::string token; std::istringstream tokens(line); while(tokens &gt;&gt; token) { std::size_t pos = token.find('='); ...
<p>Unfortunately, your source data file is human-oriented, which means that you're going to have to do a bunch of string parsing in order to get it into the structure. Otherwise, if the data had been written directly as a binary file, you could just use fread() to pop it directly into the struct.</p> <p>If you want t...
34,164
<p>I am using jqGrid of which I downloaded from here <a href="http://www.trirand.com/blog" rel="nofollow noreferrer">http://www.trirand.com/blog</a> . I followed the tutorial word by word to test out the grid. Now the alterations I did is that the page from which the grid gets the data is in asp.net instead of php. </p...
<p>Have you added:</p> <pre><code>&lt;script src="grid/js/jqDnR.js" type="text/javascript"&gt; &lt;/script&gt; </code></pre> <p>Also, your XML is missing the closing</p> <pre><code>&lt;/rows&gt; </code></pre> <p>tag. Try that!</p>
<p>I have tried your code. It works, the only problem I have found is that your XML has one mistake:</p> <p>The first line must be</p> <pre><code>&lt;?xml version='1.0' encoding = 'utf-8'?&gt; </code></pre> <p>instead of </p> <pre><code>&lt;xml version='1.0' encoding = 'utf-8'?&gt; </code></pre>
49,088
<pre><code>&lt;xsl:template match="foo"&gt; </code></pre> <p>matches the foo element in the null namespace.</p> <pre><code>&lt;xsl:template match="*"&gt; </code></pre> <p>matches any element in <em>any</em> namespace.</p> <p>I tried:</p> <pre><code>xmlns:null="" ... &lt;xsl:template match="null:*"&gt; </code></pre...
<p>You could try:</p> <pre><code>&lt;xsl:template match='*[namespace-uri() = ""]'&gt; </code></pre> <p>If the node-set is empty or has no namespace URI, an empty string is returned by the <code>namespace-uri</code> function, which should achieve what you want.</p>
<p>ffpf is correct.</p> <p>For even more clarity I would recommend to use the following match pattern:</p> <p>&nbsp;'<strong><code>*[not(namespace-uri() )]</code></strong>'</p>
45,952
<p>I'm working with PHP &amp; mySQL. I've finally got my head around source control and am quite happy with the whole development (testing) v production v repository thing for the PHP part.</p> <p>My new quandary is what to do with the database. Do I create one for the test environment and one for the production env...
<p>Each environment should have a separate database. Script all of the database objects (tables, views, procedures, etc) and store the scripts in source control. The scripts are applied first to the development database, then promoted to test (QA, UAT, etc), then production. By applying the same scripts to each data...
<p>Once I've deployed my database, any changes made to my development database(s), are done in an SQL script (not a tool), and the script is saved, and numbered.</p> <pre><code>deploy.001.description.sql deploy.002.description.sql deploy.003.description.sql ... etc.. </code></pre> <p>Then I run each of those scripts ...
38,449
<p>When you are considering an upgrade in a development tool, how important is backwards-compatibility to you? Would you still purchase Visual Studio 2010 if it required significant changes to your source code? Where is the tipping point for you in terms of trading backwards compatibility for new features?</p>
<p>While you asked this from the point of view of the developer, I think it would be a more interesting question in reference to the software you develop. So I'm going to answer that question instead. :)</p> <p>Hardware and software that's backwards compatible (and, more importantly, future-compatible) provides a sens...
<p>Define "significant changes". I'd go for it if the changes could be made with a carefully crafted "search &amp; replace" even if they were extensive.</p> <p>However, that's what <em>I</em> would do. Any company I've worked for would balk at any changes to existing code.</p>
39,441
<p>Ok so I thought it was fixed, but I'm getting totally inconsistent results. I rewrote it kind of from scratch to start fresh and here are my results. I get no errors, no crashing, it just doesn't remove them. It just totally messes up the tree and gives me a ton more leaves, and mixes everything up. Not sure wher...
<p>Are each T found in the tree unique? It looks like they are from your code...</p> <p>It looks like this should work:</p> <p>In the else case deleting the root node:</p> <pre><code>Node&lt;T&gt; *tmp_r = root-&gt;left; Node&lt;T&gt; *parent = root; while (tmp_r-&gt;right != NULL) { parent = tmp_r; tmp_r = ...
<p>You shouldn't be calling <code>remove()</code> recursively in the third case (where your "not sure if this is right" comment is). In the case where the the node to remove has two children, what you want to do is find the right-most child of the left child (as you are doing; the resulting node is stored in <code>par...
30,502
<p>The <a href="http://msdn.microsoft.com/en-us/library/kx145dw2.aspx" rel="noreferrer">ClientScriptManager.RegisterClientScriptInclude</a> method allows you to register a JavaScript reference with the Page object (checking for duplicates).</p> <p>Is there an equivalent of this method for CSS references?</p> <p>Simil...
<p>Short answer: no. You could certainly roll your own functions (as CMPalmer suggests) to take CSS embedded resources (as Gulzar suggests) and embed them on the page.</p> <p>As a best-practice matter, though, I'm not sure why you would want to do this. If you're making a reusable control that has a lot of CSS styling...
<p>One more thought: You might want to consider "namespacing" your class names to avoid collisions with common class names that your consumers might already be using. E.g.</p> <pre><code>&lt;div class="SmillerControls_Toolbar"&gt; &lt;a class="SmillerControls_Button" ...&gt;...&lt;/a&gt; ... &lt;/div&gt; </cod...
7,825
<p>I realize that this question has been <a href="https://stackoverflow.com/questions/10293/has-anyone-used-jaxer-in-production">asked before</a>, but it has been a month with no decent responses... I'm looking at <a href="http://web.archive.org/web/20090803092709/http://www.aptana.com:80/Jaxer" rel="nofollow noreferr...
<p>I didn't use Jaxer for very long, but here's some things I found:</p> <p><strong>Pros</strong></p> <ul> <li>Write the frontend and backend in the same code. Especially nice for writing validation logic.</li> <li>"Seamless" AJAX communication back to the server - it's just like calling a JS function.</li> <li>The a...
<p>@BRH: Great insight. I would echo all of the "Pros" and "Cons" 2, 4, &amp; 5 and your final overview. I kind of get the sense that they didn't intend to displace any of the market for upstream frameworks ... but if they could do so and keep it as tight and comprehensible as it is, I hope they do! I like the way t...
12,421
<p>Just as in title. Is suspect it is, but I couldn't find it anywhere explicitly stated. And for this property I wouldn't like to rely on speculations.</p>
<p>If you use the <a href="http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx" rel="noreferrer">multithreaded</a> version of the CRT, all functions are thread safe, because any thread-specific information is stored in <a href="http://msdn.microsoft.com/en-us/library/ms686749.aspx" rel="noreferrer">TLS</a>. ra...
<p>I can't think of any reason why rand_s() or even rand() wouldn't be thread safe.</p>
17,286
<p>I've been utilizing the <a href="http://en.wikipedia.org/wiki/Command_pattern" rel="nofollow noreferrer">command pattern</a> in my Flex projects, with asynchronous callback routes required between:</p> <ul> <li>whoever instantiated a given command object and the command object,</li> <li>the command object and the "...
<p>I'll try one more idea:</p> <p>Have your Data Access Object return their own AsyncTokens (or some other objects that encapsulate a pending call), instead of the AsyncToken that comes from the RPC call. So, in the DAO it would look something like this (this is very sketchy code):</p> <pre><code>public function dele...
<p>The AbstractCollection is the best way to deal with Persistent Objects in Flex / AIR. The GenericDAO provides the answer.</p> <p>DAO is the Object which manages to perform CRUD Operation and other Common Operations to be done over a ValueObject ( known as Pojo in Java ). GenericDAO is a reusable DAO class which can...
7,639
<p>I'm trying to store in a variable the name of the current file that I've opened from a folder.</p> <p>How can I do that? I've tried <code>cwd = os.getcwd()</code> but this only gives me the path of the folder, and I need to store the name of the opened file.</p> <p>Can you please help me?</p>
<pre><code>Python 2.5.1 (r251:54863, Jul 31 2008, 22:53:39) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; f = open('generic.png','r') &gt;&gt;&gt; f.name 'generic.png' </code></pre>
<p>Use this code snippet to get the filename you are currently running (i.e <code>.py</code> file):</p> <pre class="lang-python prettyprint-override"><code>target_file = inspect.currentframe().f_code.co_filename </code></pre>
41,876
<p>I have seen lots of chat examples in Erlang but what about lists, like a work queue? If I want to build a work queue system, like a project management system, is it possible to re-order messages in a process mailbox or do I have to use message priorities? Are there examples of workflow systems built in Erlang?</p>...
<p>You cannot reorder messages in process message queues in Erlang.</p> <p>You can, however do selective receives in which you can receive the message you deem most important first. It's not entirely the same but works for most purposes.</p> <p>Here's an example:</p> <pre><code>receive {important, Msg} -&gt; ...
<p>Process mailboxes work quite well as-is for job queues.</p> <p>Just have your messages include sufficient information so that selective receive patterns are easy to write, and you won't feel the need to re-order mailbox contents.</p>
32,186
<p>I am writing a Windows service that pulls messages from an MSMQ and posts them to a legacy system (Baan). If the post fails or the machine goes down during the post, I don't want to loose the message. I am therefore using MSMQ transactions. I abort on failure, and I commit on success.</p> <p>When working against a ...
<p>I left a comment asking about the version of MSMQ that you're using, as I think this is the cause of your problem. Transactional Receive wasn't implemented in the earlier versions of MSMQ. If that is the case, then this <a href="http://blogs.msdn.com/johnbreakwell/archive/2007/12/11/how-do-i-get-transactional-remote...
<p>I have since switched to <a href="http://www.developer.com/db/article.php/3640771" rel="nofollow noreferrer">SQL Service Broker</a>. It supports remote transactional receive, whereas MSMQ 3.0 does not. And, as an added bonus, it already uses the SQL Server instance that we cluster and back up.</p>
16,165
<p>I've been using a 3G wireless card for a while and every time I connect, my anti-virus fires up the updates.</p> <p>I'm wondering what is the Win32 API set of functions that I can use to, either, get notified or query about the event of an Internet Connection coming up?</p> <p>And is there already a set of ported ...
<p>I worked on a project to run a user's logon script whenever they connected our network over VPN. To do this, I wrote a helper unit that retrieves adapter info and stores it into a simple record.</p> <p>I then setup up a registry notification, <a href="http://delphi.about.com/od/kbwinshell/l/aa052003a.htm" rel="nofo...
<p>Look at InternetGetConnectedState in WinINet.</p> <p>Some applications might also poll for a known server and not do anything until they get a valid connection.</p>
42,213
<p>I've occasionally had issues with excess filament residue getting stuck to the print bed. <a href="https://3dprinting.stackexchange.com/questions/78/how-can-i-stop-my-print-bed-tape-from-sticking-to-the-filament">There are ways to prevent this</a>, but sometimes even these precautions aren't enough. Over time, resid...
<ul> <li><p>If you are printing with ABS (or PLA), acetone will dissolve it. Simply pour some on the bed and wipe it off (beware, acetone can damage beds that have a coating or a plastic sheet over them, be sure to test this first).</p> </li> <li><p>Heating the bed back up may make the plastic softer and easier to rem...
<p>I use a razor blade scraper to get stuff off that is sticking. Priory to printing I heat and level the build plate, then wipe it down with alcohol to get any greasey fingerprints off of it.</p> <p><a href="http://www.thingiverse.com/make:177038" rel="nofollow">My Scraper</a></p>
133
<p>I'm having trouble with project management &amp; am looking for a good tool that will be a good match for the way my brain works (very associatively). I'd like a bug-tracker but one that I can group tasks into topics and associate the topics to each other in a graph (see the Wikipedia entry on <a href="http://en.wik...
<p>You can always get an CVS export from your "favourite" tool and create Topic Maps maps you can view with the Omnigator or the xSiteable tool. I used to have a few XSLT files to do such a job dealing with JIRA data. If the interest is high enough, maybe a ressurection is needed?</p>
<p>I've developed a small utility that will <a href="http://www.mobiusdevelopment.com/dev/Download.asp?ArticleID=5765697756647927831" rel="nofollow noreferrer">import MindMaps into Project plans</a>. Let me know if something like this is helpful and I will develop it further. </p> <p>Right now I just use it one-way fr...
47,412
<p>Is there a programmatic method to set CPU affinity for a process in c/c++ for the Linux operating system?</p>
<p>You need to use <a href="http://linux.die.net/man/2/sched_setaffinity" rel="noreferrer"><code>sched_setaffinity(2)</code></a>.</p> <p>For example, to run on CPUs 0 and 2 only:</p> <pre><code>#define _GNU_SOURCE #include &lt;sched.h&gt; cpu_set_t mask; CPU_ZERO(&amp;mask); CPU_SET(0, &amp;mask); CPU_SET(2, &amp;m...
<p>It is also possible to make it through the shell without any modification in the programs with the <a href="https://man7.org/linux/man-pages/man7/cgroups.7.html" rel="nofollow noreferrer">cgroups</a> and the <em>cpuset</em> sub-system. Cgroups (v1 at least) are typically mounted on <em>/sys/fs/cgroup</em> under whic...
35,534
<p>I'm going to use gSOAP to interact with a WCF webservice in my Mac project. It does pretty much exactly what I need and it does it well (pretty much the exact opposite of WSMakeStubs;)). The only downside is that it's C/C++ only, meaning I either need to convert all my types into C types on the fly or write a comple...
<p>(It doesn't quite answer your question, but) I've used the techniques used in <a href="http://ditchnet.org/soapclient/" rel="nofollow noreferrer">Cocoa SOAP Client</a> (open source) to connect to a server and send/receive SOAP requests. It works really well, unless you are connecting to a server with a self-signed ...
<p>(It doesn't quite answer your question, but) I've used the techniques used in <a href="http://ditchnet.org/soapclient/" rel="nofollow noreferrer">Cocoa SOAP Client</a> (open source) to connect to a server and send/receive SOAP requests. It works really well, unless you are connecting to a server with a self-signed ...
38,397
<p>I was curious if there's a .Net API that would allow me to identify what updates are pending for "Windows Update,"</p> <p>failing that, is there a windows powershell command that can get it?</p>
<p>The Windows Update Agent API may be what you're looking for:</p> <p><a href="http://msdn.microsoft.com/en-us/library/aa387287%28VS.85%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa387287%28VS.85%29.aspx</a></p> <p>It's a COM interface (not .NET native) but you can consume that from y...
<p>That is not that trivial at all, but you just can reference to COM/WUAPI 2.0 Type Library, and VS creates a managed wrapper for you, which is copied to build directory as WuApiLib.dll.</p> <p>Be carefull of memory leaks.</p>
46,511
<p>I've been trying to learn Blender as an additional tool for 3D printing (to prepare more organic or freeform models that don't lend themselves to a CAD style workflow I'm more used to), and one point of confusion I've hit is that Blender's default unit is <em>meters</em>, not millimeters. Apparently in older version...
<h2>Make sure to set the scale properly for your use case!</h2> <p>In CAD, you define your measurement space in either Inch or in Millimeter units, and that is your grid. In blender, the native unit is the meter.</p> <p>This can be easily converted in exporting (remember to set it to scale!), but it is best to just set...
<p>It doesn't matter, you scale it in the slicer or elsewhere. You're not going to slice the STL file in Blender. You'll probably need to do more work to get things print ready outside blender anyway.</p> <p>So when I use blender I don't even bother checking what units it's using. I don't use it for parts design or tec...
2,121
<p>I want to create a similar behavior to the data reader class but for a bespoke emailer program so that I can do the follow</p> <pre><code>Dim sender As New EmailSender(emailTemplate) While sender.Send() Response.Write(sender("HTMLContent")) End While </code></pre> <p>Is there an advised interface or mustInherit ...
<p>no - all you have to do is implement the Send() method to prepare the next email for sending and returns true if it exists</p> <p>you're probably thinking of the IEnumerable interface used for iterators, but you don't need that for what you want</p>
<p>Here's my solution, I've used my own interface, and base class for the email sender, and then given some pseudo code for the concrete class.</p> <pre><code> Namespace Emailer Public Interface IBatchableEmailSender Function SendNextEmail() As Boolean Sub PrepareBatchEmail() ...
36,493
<p>So you have a String that is retrieved from an admin web UI (so it is definitely a String). How can you find out whether this string is an IP address or a hostname in Java?</p> <p>Update: I think I didn't make myself clear, I was more asking if there is anything in the Java SDK that I can use to distinguish between...
<p>You can use a regular expression with this pattern:</p> <pre><code>\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b </code></pre> <p>That will tell you if it's an IPv4 address.</p>
<p>Couldn't you just to a regexp match on it?</p>
9,251
<p>Why isn't there a bit structure in C#?</p>
<p>For what's worth, here is a full-fledged bit structure, complete with <code>int</code> and <code>bool</code> casting and arithmetic operations. Probably not perfect, but works fine for me. Enjoy!</p> <pre><code>/// &lt;summary&gt; /// Represents a single bit that can be implicitly cast to/from and compared /// with...
<p>You can do this now in C# 7.0!</p> <p>public const int One = 0b0001; </p> <p><a href="https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#numeric-literal-syntax-improvements" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#numeric-literal-syntax-improvem...
45,849
<p>I want to build something like a network scanner, so that I see in my application on which AccessPoint I'm on and what parameters this net has.</p> <p>Some interesting point would be ESSID, signal strength, noise, channel.</p> <p>Are theses properties device independent or do I have to interface each device indepe...
<p>I have not tried this yet, but I believe OpenNetCF is you friend:</p> <p><a href="http://www.opennetcf.com/library/networkinformation/" rel="nofollow noreferrer">http://www.opennetcf.com/library/networkinformation/</a></p>
<p>This is really the same question as this one: <a href="https://stackoverflow.com/questions/322070">Accessing a list of avaliable Wifi APs, on Windows Mobile</a></p> <p>The answer, summarized, is that you can P/Invoke WZC, but it's difficult. The <a href="http://www.smartdeviceframework.com" rel="nofollow noreferre...
44,188
<p>I would like to verify that an app I am writing is running on an iPhone. What would be perfect is this: Apple baked an SSL client certificate into each iphone which can be authenticated by a receiving server. I this the case?</p> <p>I have not started researching this yet, I will update with anything I find.</p> ...
<p>I think that most sites that do this detection do so by looking at the HTTP_USER_AGENT variable.</p>
<p>Pertaining to what Greg mentioned above. You can definitely add a user agent to your header which we did in our application. There's more to the whole http connection code, but here's one way you could add the user agent to your header:</p> <pre><code>NSMutableURLRequest *request; NSMutableDictionary *headers; head...
46,614
<p>Jeff covered this a while back <a href="http://www.codinghorror.com/blog/archives/000811.html" rel="nofollow noreferrer">on his blog</a> in terms of 32 bit Vista.</p> <p>Does the same 32 bit 4 GB memory cap that applies in 32 bit Vista apply to 32 bit Ubuntu? Are there any 32 bit operating systems that have creativ...
<p>In theory, all 32-bit OSes have that problem. You have 32 bits to do addressing.</p> <pre><code>2^32 bits / 2^10 (bits per kb) / 2^10 (kb per mb) / 2^10 (mb per gb) = 2^2 = 4gb. </code></pre> <p>Although there are some ways around it. (Look up the jump from 16-bit computing to 32-bit computing. They hit the same p...
<p>Linux supports a technology called PAE that lets you use more than 4GB of memory, however I don't know whether Ubuntu has it on by default. You may need to compile a new kernel.</p> <p>Edit: Some threads on the Ubuntu forums suggest that the server kernel has PAE on by default, you could try installing that.</p>
7,396
<p>When reading lines from a text file using python, the end-line character often needs to be truncated before processing the text, as in the following example:</p> <pre><code>f = open("myFile.txt", "r") for line in f: line = line[:-1] # do something with line </code></pre> <p>Is there an elegant way or idiom...
<p>The <em>idiomatic</em> way to do this in Python is to use <strong>rstrip('\n')</strong>:</p> <pre><code>for line in open('myfile.txt'): # opened in text-mode; all EOLs are converted to '\n' line = line.rstrip('\n') process(line) </code></pre> <p>Each of the other alternatives has a gotcha:</p> <ul> <li><...
<p>You may also consider using line.rstrip() to remove the whitespaces at the end of your line.</p>
44,090
<p>Most people with a degree in CS will certainly know what <a href="http://www.nist.gov/dads/HTML/bigOnotation.html" rel="noreferrer">Big O stands for</a>. It helps us to measure how well an algorithm scales. </p> <p>But I'm curious, how do <em>you</em> calculate or approximate the complexity of your algorithms?</p>
<p>I'll do my best to explain it here on simple terms, but be warned that this topic takes my students a couple of months to finally grasp. You can find more information on the Chapter 2 of the <a href="https://rads.stackoverflow.com/amzn/click/com/0321370139" rel="noreferrer" rel="nofollow noreferrer">Data Structures ...
<p>In addition to using the master method (or one of its specializations), I test my algorithms experimentally. This can't <em>prove</em> that any particular complexity class is achieved, but it can provide reassurance that the mathematical analysis is appropriate. To help with this reassurance, I use code coverage t...
2,543
<p>Bonus points for explaining how you improved it.</p>
<p>Real life security by obscurity?</p> <p>The key to the front door is stashed under a rock nearby, or under the welcome mat, or on top of a high railing. </p> <p>These are all instances of security through obscurity, as in, it is right out in the open for anyone to grab, but most people wont be able to find it wit...
<p>/admin without password.</p> <p>Yes I've seen it, it's very real.</p>
45,278
<p>What is the normal way people writing network code in Delphi use Windows-style overlapped asynchronous socket I/O?</p> <p>Here's my prior research into this question:</p> <p>The <a href="http://indyproject.org/" rel="noreferrer">Indy</a> components seem entirely synchronous. On the other hand, while ScktComp unit ...
<p>I have found that Indy, while a simpler concept in the beginning, is awkward to manage due to the need to kill sockets to free threads at application termination. In addition, I had the Indy library stop working after an OS patch upgrade. ScktComp works well for my application.</p>
<p>Indy uses synchronous sockets because it's a simpler way of programming. The asynchronous socket blocking was something added to the winsock stack back in the Windows 3.x days. Windows 3.x did not support threads and there you couldn't do socket I/O without threads. For some additional information about why Indy...
5,786
<p>I am looking for a way to periodically send some data over all clients connected to a TCP port. I am looking at twisted python and I am aware of reactor.callLater. But how do I use it to send some data to all connected clients periodically ? The data sending logic is in Protocol class and it is instantiated by the r...
<p>You would probably want to do this in the Factory for the connections. The Factory is not automatically notified of every time a connection is made and lost, so you can notify it from the Protocol.</p> <p>Here is a complete example of how to use twisted.internet.task.LoopingCall in conjunction with a customised bas...
<p>I'd imagine the easiest way to do that is to manage a list of clients in the protocol with connectionMade and connectionLost in the client and then use a LoopingCall to ask each client to send data.</p> <p>That feels a little invasive, but I don't think you'd want to do it without the protocol having some control o...
40,756
<p>What would be the easiest way to separate the directory name from the file name when dealing with <code>SaveFileDialog.FileName</code> in C#?</p>
<p>Use:</p> <pre><code>System.IO.Path.GetDirectoryName(saveDialog.FileName) </code></pre> <p>(and the corresponding <code>System.IO.Path.GetFileName</code>). The Path class is really rather useful.</p>
<p>Since the forward slash is not allowed in the filename, one simple way is to divide the SaveFileDialog.Filename using String.LastIndexOf; for example:</p> <pre><code>string filename = dialog.Filename; string path = filename.Substring(0, filename.LastIndexOf("\")); string file = filename.Substring(filename.LastIndex...
3,700
<p>I need to read an Excel 2007 XLSX file in a Java application. Does anyone know of a good API to accomplish this task?</p>
<p><a href="http://poi.apache.org/" rel="noreferrer">Apache POI</a> 3.5 have added support to all the OOXML (docx, xlsx, etc.)</p> <p>See the <a href="http://poi.apache.org/spreadsheet/index.html" rel="noreferrer">XSSF sub project</a></p>
<p>Have you looked at the <a href="http://poi.apache.org" rel="nofollow noreferrer">poorly obfuscated API</a>?</p> <p>Nevermind: </p> <blockquote> <p>HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format. It does not support the new Excel 2007 .xlsx OOXML file format, which is not O...
33,482
<p>Does anyone know of an open source web service/wcf service that can stream media content to clients? In particular I am looking for something that could access my music collection and stream it to a client (could be a client browser, win mobile app or even iphone application).</p> <p>I guess it would have to be WCF...
<p>As already said, your code is full of hacks. Please remove especially the unnecessary definitions. If a browser does not support <em>cascading</em> style sheets, it will not support CSS anyway.</p> <p>That being said, why not use position: absolute; for #right?</p> <p>As in</p> <pre><code>#right{ position: abso...
<p>The actual problem is the whitespace between the closing div tag and the next opening div tag. If you put them together on the same line with no space between them, or fill in the white space with a comment, the whitespace will be gone. </p> <pre><code>&lt;div id="left"&gt; &lt;/div&gt;&lt;div id="right"&gt; &lt;...
35,526
<p>Are there any issues with running an asp.net 1.1 application under windows server 2008 64-bit web edition?</p>
<p>I have never tried it myself, but I did find the following pages that you might find interesting:</p> <ul> <li><p><a href="http://blogs.iis.net/bills/archive/2008/06/02/installing-asp-net-1-1-with-iis7-on-vista-and-windows-2008.aspx" rel="nofollow noreferrer">This blog</a> has an in depth walk through of configurin...
<p>I have recently been testing our application on 64 bit 2008. Our application is .net framework 3.5 but we had a few problems. </p> <p>The main issue we had was with 3rd party components such as Aspose words which were not built for 64 bit and caused an error. Unfortunatly you wont know without trying it..</p>
25,925
<p>My component is handed a long value that I later use as a key into a cache. The key itself is a string representation of the long value as if it were unsigned 64-bit value. That is, when my component is handed -2944827264075010823L, I need to convert that into the string key "15501916809634540793".</p> <p>I have a ...
<p>Here's my implementation. I've refactored it to have a function taking a <code>long</code> and returning a string. :-)</p> <pre><code>import java.math.BigInteger; class UInt64Test { public static void main(String[] args) { for (String arg : args) System.out.println(toUnsignedString(Long.par...
<p>Bitless implementations:</p> <pre><code> byte[] bytes = ByteBuffer.allocate(8).putLong(1023L).array(); System.out.println(new BigInteger(bytes).toString(2)); </code></pre> <p>regards, Alex</p>
26,736
<p>I'm tidying up some older code that uses 'magic numbers' all over the place to set hardware registers, and I would like to use constants instead of these numbers to make the code somewhat more expressive (in fact they will map to the names/values used to document the registers).</p> <p>However, I'm concerned that w...
<p><strong>NEW ANSWER </strong>:</p> <p>In my original answer (below), I had to have two different macros to support assertions in a function scope and at the global scope. I wondered if it was possible to come up with a single solution that would work in both scopes.</p> <p>I was able to find a solution that worke...
<p>Ensure you compile with a sufficiently recent compiler (e.g. <code>gcc -std=c11</code>).</p> <p>Then your statement is simply:</p> <pre><code>_Static_assert(state1|mode1 == 5, "Unexpected change of bitflags"); </code></pre>
21,011
<p>Given the following C function in a DLL:</p> <pre><code>char * GetDir(char* path ); </code></pre> <p>How would you P/Invoke this function into C# and marshal the char * properly. .NET seems to know how to do LPCTSTR but when I can't figure out any marshaling that doesn't cause a NotSupportedException to fire when ...
<p>OregonGhost's answer is only correct if the char* returned from GetDir is either allocated in HGlobal or LocalAlloc. I can't remember which one but the CLR will assume that any string return type from a PInvoke function was allocated with one or the other. </p> <p>A more robust way is to type the return of GetDir...
<p>Try</p> <pre><code>[DllImport("your.dll", CharSet = CharSet.Ansi)] string GetDir(StringBuilder path); </code></pre> <p>string is automatically marshalled to a zero-terminated string, and with the CharSet property, you tell the Marshaller that it should use ANSI rather than Unicode. Note: Use string (or System.Stri...
19,698
<p>I read somewhere that one should never use error conditions as normal program flow. Makes excellent sense to me... But</p> <p>C# application sitting on top of a MySQL db. I need to parse a string value into two parts, an ID, and a value. (The original data come from a Devonian database), then validate the value aga...
<p>You shouldn't be calling ToString() at that point, first you should check if the value returned is null;</p> <pre><code>object productName = productAdapter.GetProductName(product_id); if ( productName != null ) { s_product = productName.ToString(); } else { s_product = String.Empty; } </code></pre>
<p>Can't you simply check whether GetProductName returns null?</p> <pre><code>var productName = s_product = productAdapter.GetProductName(product_id); if(productName == null) { ... do something } else { string name = productName.ToString(); } </code></pre>
44,951