instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>I have ms sql databases that grow very large. Upon examination I find that there is a bunch of unused space in certain tables. I don't do many physical deletes, so I don't think that its just deleted records. DBCC SHRINK doesn't make the file smaller. But, if I dump the table to a new, empty database, the size goes ...
<p>I have found that if you do not take care to backup your transistion log file (the LDF) you will get something like this behavior. I can not stress enough the importance of having good backup "hygiene". Not only will it save your bacon if something goes wrong but I will also help maintain a nice tight database.</p...
<p>In the options, you can specify how much you want to grow by. By default i believe it's 10%, so given a 200MB database, when you fill your last page, it will allocate another 20MB of page space. At 7GB it would allocate 700MB.</p> <p>I don't know exactly where you can modify it after you create a db, but i know it ...
6,857
<p><strong>There is a lot of relativity involved in working with exceptions.</strong> Beyond low level APIs where exceptions cover errors raised from hardware and the OS there is a shady area where the programmer decides what constitutes an exception and what is a normal condition.</p> <p>How do you decide when to use...
<p>Exceptions should <b>not</b> be used as a method of passing information internally between methods inside your object, locally you should use error codes and defensive programming.</p> <p>Exceptions are designed to pass control from a point where an error is detected to a place (higher up the stack) where the error ...
<p>Aren't exceptions raised by the language environment in accordance with the spec. of the language being used if indeed it does have the concept of exceptions? I'm thinking of "divide by zero" in Java, or CONSTRAINT_ERROR in Ada vs. nothing at all in C.</p> <p>How can a programmer "decide" to use exceptions after se...
13,215
<p>Dear experts and 3D printer users;</p> <p>I am a beginner in 3D printing field. I read couple of answers in forums and i cannot find exact answer to my problem. </p> <p>Printing quality dropped when i try to write vertical axis (i mean, columns). There is no problem in horizontal axis. </p> <p>My column width mus...
<p><strong>The main problem with your setup is the nozzle width</strong>. It is simply too big to accurately print a structure that tiny. An integral part of the filament deposition is the "smearing" of the molted plastic, that clearly can't happen if the structure is about the same size of the nozzle bore. Also the...
<p>You cannot hope to print 0.5mm columns with a 0.4mm print head successfully using an FDM printer. Basically, you are asking the printer to lay down tiny blobs of filament, one of top of another. You have two options:</p> <ol> <li><p>Use a finer nozzle (e.g. 0.1mm). However, such nozzles are reported as being very d...
798
<p>I want to read all items of a feed in C#. The solutions I've found are only for the latest items like just the last 10 days.</p> <p>Anybody has a good solution for this? </p>
<p>Libraries for reading feeds typically read all the data in the feed, but feeds typically only contain recent data - you need a source of data that includes older items, not a better library for reading the data you have.</p> <p>Most entities publish feeds to allow people to track when new content is published, not ...
<p>Most RSS feeds are only written to deliver a relatively short period of time - 'all' items in a feed generally need you to have created your own archive over time.</p>
19,741
<p>Hi guys I wrote this code and i have two errors.</p> <ol> <li>Invalid rank specifier: expected ',' or ']' </li> <li>Cannot apply indexing with [] to an expression of type 'int'</li> </ol> <p>Can you help please?</p> <pre><code> static void Main(string[] args) { ArrayList numbers = new ArrayList();...
<p>1 - You don't have to specify the length of the array just say new int[]</p> <p>2 - number is just an integer, I think you're trying to access numbers[i]</p>
<p>You should be initializing the array as </p> <pre><code>new int[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; </code></pre> <p>the compiler will set the size for you. But you're doing it the hard way. Try this:</p> <pre><code>for (int i = 10; i &gt; 0; i-- ) { numbers.Add(i); } </code></pre> <p>If you are using .Net ...
28,639
<p>How do I pass a value from a child back to the parent form? I have a string that I would like to pass back to the parent.</p> <p>I launched the child using:</p> <pre><code>FormOptions formOptions = new FormOptions(); formOptions.ShowDialog(); </code></pre>
<p>Create a property (or method) on <code>FormOptions</code>, say <code>GetMyResult</code>:</p> <pre><code>using (FormOptions formOptions = new FormOptions()) { formOptions.ShowDialog(); string result = formOptions.GetMyResult; // do what ever with result... } </code></pre>
<p>Many ways to skin the cat here and <a href="https://stackoverflow.com/questions/280579/c-beginner-help-how-do-i-pass-a-value-from-a-child-back-to-the-parent-form#280586">@Mitch's suggestion</a> is a good way. If you want the client form to have more 'control', you may want to pass the instance of the parent to the c...
35,486
<p>I'm working on a qnx device, and I want to be able to ssh into it. Does anyone have a primer on getting something like openSSH up and running?</p>
<p>Depending on whether it's 6.2, 6.3 or 6.4 you will actually go about it in a different manner.</p> <p>6.2 has "Installer" or "Install Software from QNX" in Photon, a GUI program that lets you download and install it kind of like Fedora's Pup, YaST or the likes. The command-line equivalent is cl-installer.</p> <p>6...
<p>FYI - you can start telnet with "inetd" which gets you on, and gets ftp started so you can then move the ssh libs on etc.</p>
18,172
<p>I am looking to perform a polynomial least squares regression and am looking for a C# library to do the calculations for me. </p> <p>I pass in the data points and the degree of polynomal (2nd order, 3rd order, etc) and it returns either the C0, C1, C2 etc. constant values or the calculated values "predictions".</p...
<p>Here is a link for C# code on to do exactly this: <a href="http://www.trentfguidry.net/post/2009/08/01/Linear-Regression-of-Polynomial-Coefficients.aspx" rel="noreferrer">http://www.trentfguidry.net/post/2009/08/01/Linear-Regression-of-Polynomial-Coefficients.aspx</a></p> <p>Good luck!</p> <p><strong>Edit:</strong...
<p>You may want to check out <a href="http://www.alglib.net/interpolation/linearleastsquares.php" rel="nofollow noreferrer">alglib</a>. It is in C++ instead of C#, but you might be able to write a wrapper over it.</p>
45,670
<p>I've been using the idiom below for some time now. And it seems to be the most wide-spread, at least on the sites I've visited.</p> <p>Is there a better/different way to read a file into a string in Java?</p> <pre><code>private String readFile(String file) throws IOException { BufferedReader reader = new Buffe...
<h2>Read all text from a file</h2> <p>Java 11 added the <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#readString(java.nio.file.Path,java.nio.charset.Charset)" rel="noreferrer">readString()</a> method to read small files as a <code>String</code>, preserving line terminato...
<p>in java 8 , there are a new Class </p> <blockquote> <p>java.util.stream.Stream</p> </blockquote> <p>A stream represents a sequence of elements and supports different kind of operations to perform computations upon those elements</p> <p>to Read more about it :</p> <p><a href="https://docs.oracle.com/javase/8/do...
42,291
<p>Am I allowed to place <code>&lt;noscript&gt;</code> in the <code>&lt;head&gt;</code>?</p>
<p>According to the <a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" rel="noreferrer">XHTML Strict DTD</a>, no, you're allowed script, style, meta, link, object, title and base only. Transitional allows isindex as well, but still not noscript.</p>
<p>You are as long as you do it in HTML documents and not XHTML.</p> <blockquote> <p>In a head element [...], the noscript element must contain only link, style, and meta elements.</p> </blockquote> <p><a href="https://www.w3.org/TR/html5/scripting-1.html#the-noscript-element" rel="nofollow">See specification</a>...
31,510
<p>What are the dangerous characters that should be replaced in user input when the users' input will be inserted in a MySQL query? I know about quotes, double quotes, \r and \n. Are there others?<br><sub>(I don't have the option of using a smart connector that accepts parameters so I have to build the query myself and...
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-real-escape-string.html" rel="nofollow noreferrer">mysql_real_escape_string()</a> from mysql.com docs:</p> <blockquote> <p><em>The string in from is encoded to an escaped SQL string, taking into account the current character set of the connection. The result i...
<p>What languages do you need to support? It is much better to use a language's built-in sanitization than to write your own.</p> <p>Edit: Looking at <a href="http://php.net/mysql_real_escape_string" rel="nofollow noreferrer"><code>mysql_real_escape_string</code></a> on php.net:</p> <blockquote> <p><code>mysql_real...
28,459
<p>I've created a one-line batch file to run SqlMetal to regenerate a LINQ to SQL DataContext for my database; this works great. </p> <p><em>Refresh_DataContext.bat</em>:</p> <pre><code>"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\sqlmetal.exe" /server:.\sqlexpress /database:MyDatabaseName /code:"%~...
<p>What you seem to be looking for can be found under "Pre-build event command line" under your project's properties. Click the "Build Events" tab, and you'll have a little space to enter in a command line which does what you want.</p>
<p>Doh! Of course. Web Application projects have pre- and post- build events; Web Site projects don't. </p>
29,329
<p>Here are a few possibilities to get the conversation started:</p> <ol> <li>Escape all input upon initialization.</li> <li>Escape each value, preferably when generating the SQL.</li> </ol> <p>The first solution is suboptimal, because you then need to unescape each value if you want to use it in anything other than ...
<p>as @Rob Walker states, parameterized queries are your best bet. If you're using the latest and greatest PHP, I'd highly recommend taking a look at <a href="http://us3.php.net/pdo" rel="noreferrer">PDO</a> (PHP Data Objects). This is a native database abstraction library that has support for a wide range of databas...
<p>I've always used the first solution because 99% of the time, variables in <code>$_GET</code>, <code>$_POST</code>, and <code>$_COOKIE</code> are never outputted to the browser. You also won't ever mistakenly write code with an SQL injection (unless you don't use quotes in the query), whereas with the second solution...
6,927
<p>I'm an experienced VS.NET user and trying to get up and running on Xcode 3.1.1.<br> Here's what I'm trying to accomplish:</p> <p>I'd like a static library ("Lib") to have its own xcodeproj file. I'd an executable application ("App") that makes use of Lib to reference Lib's xcodeproj file so that changes to Lib cau...
<p>You're correct that making target A depend upon target B (whether within the same project or across projects) does <strong>not</strong> cause target A to link against target B. You need to specify them distinctly; this is because they're separate concepts, and you might have dependencies between targets that you <e...
<p>I am also a fairly new user of Xcode. Most of what I know I learned from an Xcode book by James Bucanek (ISBN 047175479x). It is an older book that was written for/with Xcode 2.2, but I find that pretty much all of it still applies for me today, and I currently use Xcode 3.1</p> <p>You can probably find a cheap u...
11,362
<p>I have a problem with simple c++ programs... </p> <p>I would like to install a program, but always have the error like "c++ compiler is unable to create executables"...</p> <p>Now I tried to compile a simple "hello world" program, but I get errors as I would if I compile a c++ program with a c compiler ("`cout' un...
<p>Did you try calling g++ directly? If you run:</p> <pre><code>g++ </code></pre> <p>and it isn't installed, you should get the usual <em>invalid command</em> message, but if it is installed you should see something like:</p> <pre><code>g++: no input files </code></pre> <p>If you see that, then try running this:</p...
<p>Install the build-essential package on your machine and try again. This fixed the same problem for me.</p> <pre><code>sudo apt-get install build-essential </code></pre>
45,229
<p>I use TortoiseSVN to access file based local repo. In all my commits an author is my Windows login name. Is it possible to use different name?</p> <p>I know how to change author after commit but how to change before? Installing apache/svnserver is not an option. </p>
<p>Yes, it's possible.</p> <p><em>TortoiseSVN</em> and the <a href="http://subversion.tigris.org/" rel="noreferrer"><em>svn</em></a> command line client share the same settings location in your profile folder. So you may simply checkout one version using <em>svn.exe</em>:</p> <pre><code>$ svn co --username different_...
<p>As far as I know, TortoiseSVN does not offer any way to do this.</p> <p>Presumably it's not seen as a big issue, since file based access is not practical for multi-user scenarios, and for single-user the author-name is of lesser importance.</p> <p>A possible workaround would be to create another Windows username w...
6,758
<p>How do I create a unique constraint on an existing table in SQL Server 2005?</p> <p>I am looking for both the TSQL and how to do it in the Database Diagram.</p>
<p>The SQL command is:</p> <pre><code>ALTER TABLE &lt;tablename&gt; ADD CONSTRAINT &lt;constraintname&gt; UNIQUE NONCLUSTERED ( &lt;columnname&gt; ) </code></pre> <p>See the full syntax <a href="http://msdn.microsoft.com/en-us/library/ms190273.aspx" rel="noreferrer">here</a>.</p> ...
<p>In some situations, it could be desirable to ensure the Unique key does not exists before create it. In such cases, the script below might help:</p> <pre><code>IF Exists(SELECT * FROM sys.indexes WHERE name Like '&lt;index_name&gt;') ALTER TABLE dbo.&lt;target_table_name&gt; DROP CONSTRAINT &lt;index_name&gt; ...
9,065
<p>I've produced a python egg using setuptools and would like to access it's metadata at runtime. I currently got working this:</p> <pre><code>import pkg_resources dist = pkg_resources.get_distribution("my_project") print(dist.version) </code></pre> <p>but this would probably work incorrectly if I had multiple versio...
<p>I am somewhat new to Python as well, but from what I understand: </p> <p>Although you can install multiple versions of the "same" egg (having the same name), only one of them will be available to any particular piece of code at runtime (based on your discovery method). So if your egg is the one calling this code, ...
<p>Exactly. So you should only be able to get the information for the currently available egg (singular) of a library. If you have multiple eggs of the same library in your site-packages folder, check the easy-install.pth in the same folder to see which egg is really used :-)</p> <p>On a site note: This is exactly the...
21,441
<p>I want to use XML instead of SQLServer for a simple website. </p> <p>Are their any good tutorials, code examples, and/or tools available to make a (prefer VB.NET) wrapper class to handle the basic list, insert, edit, and delete (CRUD) code?</p> <p>The closest one I found was on a Telerik Trainer video/code for the...
<p>In these days of <strong>SQL Server Express</strong>, I'd say there's really no reason for you not to use a database.</p> <p>I know this doesn't really answer your question, but I'd hate to see you roll out code that will be a nightmare to maintain and scale.</p> <p>Maybe you could tell us why you want to use <str...
<p>It would make deployment easier for clients that use go-daddy where the database isn't in the app_data folder. also backing up those websites would be as simple as FTP the entire thing. </p> <p>I have concerns about possible collisions on saving. especially if I add something as simple as a click counter to say a l...
5,954
<p>The issue that prompted me to ask this is a web form that was not persisting data the way I expected it to. That's vague, but the point is, what do you like to do to model state, flow of data, and so forth?</p>
<p>I'll second the whiteboard answer and add that explaining what is <em>supposed</em> to be happening, following by verbalizing what the the code is <em>actually</em> doing, along with a basic graphic is hugely helpful for any project.</p>
<p>I'll put my obvious (to me) answer, which is to use the whiteboard. Love the whiteboard.</p>
30,875
<p>I want to write a function in Python that returns different fixed values based on the value of an input index. </p> <p>In other languages I would use a <code>switch</code> or <code>case</code> statement, but Python does not appear to have a <code>switch</code> statement. What are the recommended Python solutions ...
<p>The original answer below was written in 2008. Since then, Python 3.10 (2021) introduced the <a href="https://www.python.org/dev/peps/pep-0634/" rel="noreferrer"><code>match</code>-<code>case</code></a> statement which provides a first-class implementation of a &quot;switch&quot; for Python. For example:</p> <pre><c...
<p>A switch statement is just syntactic sugar for if/elif/else. What any control statement is doing is delegating the job based on certain condition is being fulfilled - decision path. For wrapping that into a module and being able to call a job based on its unique id, one can use inheritance and the fact that any meth...
8,504
<p>I do all my coding in vim and am quite happy with it (so, please, no "use a different editor" responses), but have an ongoing annoyance in that the smartindent feature wants to not indent comments beginning with # at all. e.g., I want</p> <pre><code> # Do something $x = $x + 1; if ($y) { # Do something el...
<p>It looks like you're coding in Perl. Ensure that the following are set in your .vimrc:</p> <pre><code>filetype plugin indent on syntax enable </code></pre> <p>These will tell Vim to set the filetype when opening a buffer and configure the indentation and syntax highlighting. No need to explicitly set smartindent s...
<p>I think "smartindent" is designed for C, so it thinks "#" is the start of a pre-processor directive instead of a comment. I don't know a solution for it, except if you type a space, then a backspace, then the "#" it won't do that.</p>
23,214
<p>In most versions of windows, you can get to the menu by pressing the F10 key, thus avoiding having to use the mouse. This behaviour does not appear to be present in Windows Mobile 5.0, but is desirable as the device I am using will be more keyboard than touch screen driven. </p> <p>Is there a way of programmatica...
<p>After a number of attempts, the following appears to work;</p> <pre><code>void CMyFrame::OnFocusMenu() { PostMessage(WM_SYSCOMMAND,SC_KEYMENU,0); } </code></pre> <p>FWIW, none of the following did, where m_wndCommandBar is the CCeCommandBar toolbar containing the menu;</p> <pre><code>::SetActiveWindow(m_wndComm...
<p>If by menu, you mean the soft keys, note that they are bound to F1 and F2 respectively.</p>
32,030
<p>I would need some basic vector mathematics constructs in an application. Dot product, cross product. Finding the intersection of lines, that kind of stuff.</p> <p>I can do this by myself (in fact, have already) but isn't there a "standard" to use so bugs and possible optimizations would not be on me?</p> <p>Boost ...
<p>Re-check that ol'good friend of C++ programmers called <a href="http://www.boost.org" rel="noreferrer">Boost</a>. It has <a href="http://www.boost.org/doc/libs/1_37_0/libs/numeric/ublas/doc/index.htm" rel="noreferrer">a linear algebra package</a> that may well suits your needs.</p>
<p>There is a nice Vector library for 3d graphics in the prophecy SDK:</p> <p>Check out <a href="http://www.twilight3d.com/downloads.html" rel="nofollow noreferrer">http://www.twilight3d.com/downloads.html</a></p>
47,370
<p>I recently heard of BDD and found it very similar to TDD.</p> <p>Which of these two do you use (if any)?</p> <p>and which are the pros and cons of each?</p>
<p>I'm very much of the BDD = TDD done properly camp. If you're doing TDD as originally described by Beck - and practised by many - then there is essentially no difference.</p> <p>What BDD brings to the table is some interesting variants on the language used to describe the process. By using alternate terminology in t...
<p>TDD and BDD are pretty much the same. The difference is how we explain it, and therefore how succesful teams end up being in making it work for them.</p> <p>BDD builds upon TDD by formalising the good habits of the best TDD practioners. TDD is a developers tool or guide to write good software and BDD is a good tool...
14,810
<p>I've got a WordPress powered blog that I'm trying to get setup on our IIS6 server and everything works besides the permalink structure which I'm having a big headache with.</p> <p>After googling around/wordpress codex I learned that it's because IIS6 doesn't have the equivalent of Apache's mod_rewrite which is requ...
<p>I just came across the following answer on another question: <a href="https://stackoverflow.com/questions/128796/pretty-urls-for-search-pages#128864">Pretty URLs for search pages</a></p> <p>Hope that helps!</p>
<p>I researched this topic briefly and it seems you need an additional piece which is called <em>URL Rewrite (Go Live)</em>.</p> <p><a href="http://learn.iis.net/page.aspx/466/enabling-pretty-permalinks-in-wordpress/" rel="nofollow noreferrer">Here is an article</a> that walks you through how to create a rewrite rule ...
13,857
<p>I have a bunch of controls on my window. One of them is a refresh button that performs a cumbersome task on a background thread.</p> <p>When the user clicks the refresh button, I put the cursor in a wait (hourglass) status and disable the whole window -- <code>Me.IsEnabled = False</code>.</p> <p>I'd like to suppo...
<p>You can put all the controls in one panel (Grid, StackPanel, etc.), and leave the cancel button in another panel. Then set the IsEnabled property of the other panel.</p> <p>In practice, this will probably introduce more than one additional panel.</p> <p>For example, if you had a StackPanel of buttons, you can add...
<p>You can data bind each controls IsEnabled property to your custom boolean dependency property that signals when your application is in lock down. Just don't bind the cancel button.</p> <p>As Donnelle mentioned You can setup multi binding with a converter. Here are a couple examples you can refer to. <a href="http...
34,498
<p>Is there a Vim shortcut for jumping to the argument list of the current function? I often find myself needing to mess with the argument list of a function, and it's kind of annoying to have to do ?def or ?function or 10k or what-have-you until I finally get to it, then /( or t( or 5e to get to the right position in...
<p><em>Disclaimer, I don't know Python, I assume a Python function can be identified by "function" or "def" from your question. Just change the regex in consequence.</em></p> <p>May be something like:</p> <pre><code> :nnoremap &lt;buffer&gt; [m :call search('def\|function', 'b')&lt;cr&gt;f( </code></pre> <p>?</p> ...
<p>map ,a ma[{F(a</p> <p>Hit ,a to go to the argument list, then `a to return to where you were when you invoked ,a. Caveat: [{ jumps back to the last unmatched { character, so if you're inside a loop or other control structure, it will take you to the beginning of that, instead.</p> <p>I don't know of a way to get t...
12,074
<p>I am creating a WCF service hosted within IIS7 on Windows Vista SP1. I am getting the following error:</p> <p>The certificate 'CN=SignedByLocalHost' must have a private key that is capable of key exchange. The process must have access rights for the private key. </p> <p>It looks like I would need to give the host ...
<p>You can use IIS 7.0/7.5 Just Start->Run ->inetmgr Select the server Under "Security" panel, go to "Server Certificates" In the left pane click - "Create Self Signed Certificate" and complete the process The crtfiticate will get installed in <strong>LocalMachine</strong> StoreLocation under <strong>Personal</strong> ...
<p>Figured it out. </p> <p>Assuming you have a self signed cert at c:\OutCert the following command will work. I had left off the -sky exchange.</p> <p>makecert -sk SignedByCA -iv c:\OutCert.pvk -n "CN=MyLocalHost" -ic c:\OutCert.cer -sr LocalMachine -ss My -sky exchange pe</p> <p>Now you can go into the MMC tool an...
44,822
<p>I'm looking for a piece of code that can tell me the offset of a field within a structure without allocating an instance of the structure.</p> <p>IE: given</p> <pre><code>struct mstct { int myfield; int myfield2; }; </code></pre> <p>I could write:</p> <pre><code>mstct thing; printf("offset %lu\n", (unsig...
<p>How about the standard offsetof() macro (in stddef.h)?</p> <p>Edit: for people who might not have the offsetof() macro available for some reason, you can get the effect using something like:</p> <pre><code>#define OFFSETOF(type, field) ((unsigned long) &amp;(((type *) 0)-&gt;field)) </code></pre>
<p>printf("offset: %d\n", &amp;((mstct*)0)->myfield2);</p>
17,171
<p>How do I calculate the distance between two points specified by latitude and longitude?</p> <p>For clarification, I'd like the distance in kilometers; the points use the WGS84 system and I'd like to understand the relative accuracies of the approaches available.</p>
<p>This <a href="http://www.movable-type.co.uk/scripts/latlong.html" rel="noreferrer">link</a> might be helpful to you, as it details the use of the <a href="http://en.wikipedia.org/wiki/Haversine_formula" rel="noreferrer">Haversine formula</a> to calculate the distance.</p> <p>Excerpt:</p> <blockquote> <p>This s...
<p>Here's a simple javascript function that may be useful from this <a href="http://www.movable-type.co.uk/scripts/latlong.html" rel="nofollow">link</a>.. somehow related but we're using google earth javascript plugin instead of maps</p> <pre><code>function getApproximateDistanceUnits(point1, point2) { var xs = 0...
4,760
<p>Most of my programming experience has either been using forms (Windows Forms, or ASP.NET) or small embedded projects interfacing hardware. Recently I began going through some tutorials for iPhone development. I'm interested in learning Objective-C and the iPhone sdk. </p> <p>I wanted to make a small frogger-like ga...
<p><a href="http://monoclestudios.com/cocos2d_whitepaper.html" rel="nofollow noreferrer">Here</a> is a simple tutorial on Cocoa2D, what you would use to make a 2D game.</p> <p>There is also a tutorial on touch detection <a href="http://lethain.com/entry/2008/oct/20/touch-detection-in-cocos2d-iphone/" rel="nofollow nor...
<p>Lights Off is a relatively simple iPhone game that was built without using OpenGL. The source has been released and would probably give you a decent idea of how to go about getting started.</p> <p>More info here: <a href="http://furbo.org/2008/09/19/lights-off/" rel="nofollow noreferrer">http://furbo.org/2008/09/1...
39,462
<p>I am using some custom controls one of which is a tooltip controller that can display images, so I am using th ebelow code to instantiate it:</p> <pre><code>Image newImage = Image.FromFile(imagePath); e.ToolTipImage = newImage; </code></pre> <p>obviously could inline it but just testing at the moment. The trouble ...
<p>Once you have an image object loaded from its source, the Height and Width (and Size, and all ancillary properties) are read-only. Therefore, you are stuck with GDI+ methods for resizing it in RAM and then displaying it accordingly. </p> <p>There are a lot of approaches you can take, but if you were to encapsulate ...
<p>In Winforms, if you contain the image inside a PictureBox control, the PictureBox control can be set to zoom to a particular height/width, and the image should conform.</p> <p>At least that's what happened in my Head First C# book when I did the exercise.</p>
35,119
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/46663/how-do-you-send-email-from-a-java-app-using-gmail">How do you send email from a Java app using Gmail?</a> </p> </blockquote> <p>How do I send an SMTP Message from Java?</p>
<p>Here's an example for Gmail smtp:</p> <pre><code>import java.io.*; import java.net.InetAddress; import java.util.Properties; import java.util.Date; import javax.mail.*; import javax.mail.internet.*; import com.sun.mail.smtp.*; public class Distribution { public static void main(String args[]) throws Excep...
<pre><code>import javax.mail.*; import javax.mail.internet.*; import java.util.*; public void postMail(String recipients[], String subject, String message , String from) throws MessagingException { //Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", "smtp.jcom...
9,932
<p>I've been reading on the blogosphere for the past week that Linq to SQL is dead [and long live EF and Linq to Entities]. But when I read the overview on MSDN, it appeared to me Linq to Entities generates eSQL just the way Linq to SQL generates SQL queries.</p> <p>Now, since the underlying implementation (and since...
<p>It is worth noting that Entity Framework has (at least) three ways of being consumed:</p> <ul> <li>LINQ to Entities over Object Services over Entity Client</li> <li>Entity SQL over Object Services over Entity Client</li> <li>Entity SQL using Entity Client command objects (most similar to classic ADO.NET)</li> </ul>...
<p>A big difference between Linq to SQL and Entity Framework is that EF implements the Entity Data Model specification (EDM), and there are other products that are built around the EDM, like ADO.NET Data Services (aka Astoria).</p> <p>The EDM is now being used to extend the AtomPub in a new spec called Open Data Proto...
33,083
<p>Suppose I have an interval (a,b), and a number of subintervals {(a<sub>i</sub>,b<sub>i</sub>)}<sub>i</sub> whose union is all of (a,b). Is there an efficient way to choose a minimal-cardinality subset of these subintervals which still covers (a,b)?</p>
<p>A greedy algorithm starting at a or b always gives the optimal solution.</p> <p>Proof: consider the set S<sub>a</sub> of all the subintervals covering a. Clearly, one of them has to belong to the optimal solution. If we replace it with a subinterval (a<sub>max</sub>,b<sub>max</sub>) from S<sub>a</sub> whose right e...
<p>You mean so that the subintervals still overlap in such a way that (a,b) remains completely covered at all points?</p> <p>Maybe splitting up the subintervals themselves into basic blocks associated with where they came from, so you can list options for each basic block interval accounting for other regions covered b...
37,413
<p>I am just starting out with Silverlight (2 RC0) and can’t seem to get the following to work. I want to create a simple image button user control.</p> <p>My xaml for the user control is as follows:</p> <pre><code> &lt;Button&gt; &lt;Button.Template&gt; &lt;ControlTemplate&gt; ...
<p>You can get an ImageButton easily just by templating an ordinary Button so you dont require a UserControl at all. Assuming that Button.Content will be the ImageSource. The ControlTemplate of the Button will be:</p> <pre><code> &lt;ControlTemplate x:Key="btn_template"&gt; &lt;Image Source="{TemplateBindi...
<p>I believe this will help. It did for me!</p> <p><a href="http://www.nikhilk.net/Silverlight-Effects-In-Depth.aspx" rel="nofollow noreferrer">http://www.nikhilk.net/Silverlight-Effects-In-Depth.aspx</a></p> <p>Instead Image, use ImageSource. E.G. typeof(ImageSource), etc..</p>
24,370
<p>I want to write a front-end to an application written in C/C++. </p> <p>I use Solaris 10 and plan to port the application to some other architectures (Windows first).</p>
<p>I'd recommend taking a look at <a href="http://www.wxwidgets.org/" rel="nofollow noreferrer">wxWidgets</a> to provide some cross platform UI widgets that will work on Solaris and Windows.</p>
<p>I use <a href="http://www.wxwidgets.org/" rel="nofollow noreferrer">wxWidgets</a> myself. It makes good use of the C++ language features and uses smart pointers, so object and memory management is not that hard. In fact, it feels like writing in a scripting language.</p> <p>Coupled with a dialog editor/code generat...
4,921
<p>How can i generate bytecode (Byte[]) from a String at runtime, without using a "javac" process or something of this sort? is there a simple way of calling the compiler like that?</p> <p>later addition:</p> <p>I chose to <a href="https://stackoverflow.com/questions/200833/when-should-i-accept-an-answer">accept the ...
<p>JDK6 has a <a href="http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm" rel="noreferrer">Java compiler API</a>. However, it's not necessarily very easy to use.</p> <p>A quick google pulled up <a href="http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm" rel="noreferrer">this example usage</a>.<...
<p>You can access the compiler as long as the tools.jar file from your JDK is on the classpath. The documentation for it is <a href="http://java.sun.com/javase/6/docs/api/javax/tools/JavaCompiler.html" rel="nofollow noreferrer">here</a>. The API isn't as simple as <code>eval()</code> in some interpreted languages but i...
24,289
<p>I've been using this function but I'd like to know what's the most efficient and accurate way to get it.</p> <pre><code>function daysInMonth(iMonth, iYear) { return 32 - new Date(iYear, iMonth, 32).getDate(); } </code></pre>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function daysInMonth (month, year) { // Use 1 for January, 2 for February, etc. return new Date(year, month, 0).getDate(); } co...
<p>See my function and a test of it:</p> <p>function numberOfDays(year, month) { // Reference: // <a href="https://arslankuyumculuk.com/how-to-calculate-leap-year-formula/" rel="nofollow noreferrer">https://arslankuyumculuk.com/how-to-calculate-leap-year-formula/</a> (2022-05-20 16:45 UTC)</p> <pre><code>numDays=0; swi...
40,769
<p>I need to figure out the hard drive name for a solaris box and it is not clear to me what the device name is. On linux, it would be something like <code>/dev/hda</code> or <code>/dev/sda</code>, but on solaris I am getting a bit lost in the partitions and what the device is called. I think that entries like <code>...
<p>/dev/rdsk/c0t0d0s0 means Controller 0, SCSI target (ID) 0, and s means Slice (partition) 0.</p> <p>Typically, by convention, s2 is the entire disk. This partition overlaps with the other partitions.</p> <p>prtvtoc /dev/rdsk/c0t0d0s0 will show you the partition table for the disk, to make sure.</p>
<p>c0t0d0s0 <em>is</em> the entire drive. The breakdown is:</p> <p>/dev/[r]dsk/c <strong>C</strong> t <strong>A</strong> d0s <strong>S</strong></p> <p>...where <strong>C</strong> is the controller number, <strong>A</strong> is the SCSI address, and <strong>S</strong> is the "slice". Slice 0 is the whole disk; the oth...
10,379
<p>How can a <code>sdbm</code> hash function (such as <a href="http://www.cse.yorku.ca/~oz/hash.html" rel="nofollow noreferrer">this</a>) be implemented in C# ?</p>
<p>You can take the C code almost without changes:</p> <pre><code>uint sdbm( string str ) { uint hash = 0; foreach( char ch in str ) { hash = ch + (hash &lt;&lt; 6) + (hash &lt;&lt; 16) - hash; } return hash; } </code></pre> <p>Or did you think of something more sophisticated?</p>
<p>The result from the hash differs between the C++ and C# implementation. I figured out that str parameter needs to be passed as a byte array.</p> <pre><code>private uint sdbm(byte[] str) { uint hash = 0; foreach (char ch in str) hash = ch + (hash &lt;&lt; 6) + (hash &lt;&lt; 16) - hash; return ...
3,673
<p>My Tevo Flash works well. Right now, I'm trying to print a thin, disc-like part on supports. The 3 perimeters at the edge of the disc are OK. The dense fill zigzag pattern makes many U-turns near the perimeter. It all looks OK in Simplify3D. But in the printed part, in several spots, the zigzag pattern doesn't reach...
<p><em>Posted as a wiki answer from a comment from the OP to a different <a href="https://3dprinting.stackexchange.com/a/16584">answer</a>.</em></p> <hr /> <p>The <a href="https://3dprinting.stackexchange.com/a/16584"><code>Zig Zag</code> vs <code>Lines</code> patterns</a> was only a part of the problem. The 2<sup>nd</...
<p>The zig-zag pattern are known for this kind of fluke...</p> <p>I will use Cura to demonstrate, but it's gonna happen on the majority of slicers.</p> <p>See this example: <a href="https://i.stack.imgur.com/uK0sk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uK0sk.png" alt="Image showing air gaps ...
1,962
<p>After reading the Test-and-Set <a href="http://en.wikipedia.org/wiki/Test-and-set" rel="noreferrer">Wikipedia entry</a>, I am still left with the question "What would a Test-and-Set be used for?"</p> <p>I realize that you can use it to implement Mutex (as described in wikipedia), but what other uses does it have?</...
<p>You use it any time you want to write data to memory after doing some work and make sure another thread hasn't overwritten the destination since you started. A lot of <a href="https://stackoverflow.com/questions/93073/how-to-implement-thread-safe-reference-counting-in-c">lock/mutex-free algorithms</a> take this form...
<p>It's used when you need to get a shared value, do something with it, and change the value, assuming another thread hasn't already changed it.</p> <p>As for practical uses, the last time I saw it was in implementations of concurrent queues (queues that may be pushed/popped by multiple threads without needing semapho...
14,710
<p>I'd like to write a script that (under certain conditions) will execute gdb and automatically run some program X with some set of arguments Y. Once the program has finished executing the user should remain at gdb's prompt until s/he explicitly exits it.</p> <p>One way to do this would be to have the script output t...
<p>If you want to run some commands through GDB and then have it exit or run to completion, just do</p> <pre><code>echo commands | gdb X </code></pre> <p>If you want to leave it at the command prompt after running those commands, you can do</p> <pre><code>(echo commands; cat) | gdb X </code></pre> <p>This results i...
<p><code>cat F | gdb X</code> should be identical. So you can use anything that produces output and pipe that into gdb instead of the cat command here.</p> <p>I'm assuming you're correct and gdb reads from stdin.</p>
41,697
<p>We've got a product which utilizes multiple SQL Server 2005 databases with triggers. We're looking for a sustainable solution for deploying and upgrading the database schemas on customer servers.</p> <p>Currently, we're using Red Gate's SQL Packager, which appears to be the wrong tool for this particular job. Not o...
<p>I was looking for this product myself, knowing that RedGate solution worked fine for "one" DB; unfortunately I have been unable to find such tool :(</p> <p>In the end, I had to roll my own solution to do something "similar". It was a <em>pain in the…</em> but it worked. </p> <p>My scenario was way simpler than you...
<p>As of this writing (June 2009) there's still no product on the market that'll do all this for multiple databases. I work for Quest Software, makers of Change Director for SQL Server, another database change automation system. Ours doesn't handle multiple databases like you're after, and I've seen the others out th...
12,752
<p>In a web interface, I've got a text field. When user enters text and accepts with enter, application performs an action.</p> <p>I wanted to test the behavior with Selenium. Unfortunately, invoking 'keypress' with chr(13) insert representation of the character into the field.</p> <p>Is there a way other then submit...
<p>This Java code works for me:</p> <pre><code>selenium.keyDown(id, "\\13"); </code></pre> <p>Notice the escape. You probably need something like chr(\13)</p>
<p>Though I haven't tested this I imagine you can use "\r\n" appended to a string to simulate a new line. If not look for the languages equivalent to "Environment.NewLine;" ?</p>
9,706
<p>This is similar to <a href="https://stackoverflow.com/questions/18932/sql-how-can-i-remove-duplicate-rows">this question</a>, but it seems like some of the answers there aren't quite compatible with MySQL (or I'm not doing it right), and I'm having a heck of a time figuring out the changes I need. Apparently my SQL ...
<p>MySQL needs to be explicitly told if the data you are grouping by is larger than 1024 bytes (see <a href="http://dev.mysql.com/doc/refman/5.1/en/blob.html" rel="nofollow noreferrer">this link</a> for details). So if your data in the fingerprint column is larger than 1024 bytes you should use set the <code>max_sort_l...
<p>How about a two-step approach, assuming you can go offline during a data load:</p> <ul> <li>Mark every item as duplicate.</li> <li>Select the earliest row from each group, and clear the duplicate flag.</li> </ul> <p>Not elegant, but gets the job done.</p>
29,967
<p>I'm going to rebuild my Linux box [yet] again. I have to create a few user groups, user accounts and install my standard packages. Until now I've just used the GUI tools. I was wondering if anyone has any recommendations on writing a script to create users, groups and install standard packages after I do a minima...
<p>For .deb distros, use <a href="http://www.informatik.uni-koeln.de/fai/" rel="nofollow noreferrer">FAI</a>. For .rpm distros, use <a href="http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5.2/html/Installation_Guide/ch-kickstart2.html" rel="nofollow noreferrer">Kickstart</a>. For system management after inst...
<p>Another option to help with constantly rebuilding a box is Norton Ghost, with ghost you can make an image and then just re-image the drive as needed. You install it and configure it to your liking, then take an image. </p>
35,538
<p>I'm trying to return all the child nodes of a set of navigation nodes in sharepoint, the SDK implies I should be doing something like this:</p> <pre><code>NodeColl = objSite.Navigation.TopNavigationBar Dim Node as SPNavigationNode For Each Node In NodeColl if Node.IsVisible then Response.Write("&lt;siteMapN...
<p>I think it has to be an ordered collection. For example,there's <a href="http://static.springframework.org/spring/docs/2.5.x/reference/validation.html" rel="noreferrer">a chart</a> in the Spring reference that talks about how to reference properties. It says:</p> <blockquote> <p>account[2] Indicates the thir...
<p>You can use a semi-colon-delimited list if you're using numeric references to the IDs of objects, and an appropriate Converter implementation registered.</p> <p>POST data leaderboards=1,2</p> <p>Converter implementation (ignore the JSON stuff)</p> <pre><code> public final class LeaderboardConverter extends...
36,076
<p>I hate case sensitivity in databases, but I'm developing for a client who uses it. How can I turn on this option on my SQL Server, so I can be sure I've gotten the case right in all my queries?</p>
<p>You don't actually need to change the collation on the entire database, if you declare it on the table or columns that need to be case-sensitive. In fact, you can actually append it to individual operations as needed.</p> <pre> SELECT name WHERE 'greg' = name COLLATE Latin1_GENERAL_CS_AS </pre> <p>I know, you sai...
<p>You'll have to change the database collation. You'll also need to alter the table and column level collation. I beleive you can find a script out there if you google it.</p>
16,628
<p>i have a frame that instantiates another frame but i don't want to use the close(x) button on the instantiated frame., so i created a button. how do i code that this button can be used to close the instantiated frame without quitting the JVM.</p>
<p>Having your own close button is weird UI and should be avoided.</p> <p>To get rid of a frame when your own button is clicked you can just do:</p> <pre><code>jFrame.setVisible(false); </code></pre> <p>or </p> <pre><code>jFrame.dispose(); </code></pre> <p>if you want to get rid of it completely.</p> <p>On frames...
<p>Im not sure if im right but you could call <code>dispose()</code>. The javadoc suggests you can reopen it though using <code>show()</code>.</p>
46,074
<p>I am looking for a method to place some text onto the clipboard with <a href="http://en.wikipedia.org/wiki/VBScript" rel="noreferrer">VBScript</a>. The VBScript in question will be deployed as part of our login script. I would like to avoid using anything that isn't available on a clean Windows XP system.</p> <p>...
<p>Another solution I have found that isn't perfect in my opinion, but doesn't have the annoying security warnings is to use clip.exe from a w2k3 server.</p> <pre><code>Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "cmd.exe /c echo hello world | clip", 0, TRUE </code></pre> <p>Example with a multi...
<p>If it's just text can't you simply create a text file and read in the contents when you need it? </p> <p>Another alternative and clearly a kludge, would be to use the <code>SendKeys()</code> method.</p>
15,631
<p>I'm trying to have my Struts2 app redirect to a generated URL. In this case, I want the URL to use the current date, or a date I looked up in a database. So <code>/section/document</code> becomes <code>/section/document/2008-10-06</code></p> <p>What's the best way to do this?</p>
<p>Here's how we do it:</p> <p>In Struts.xml, have a dynamic result such as:</p> <pre><code>&lt;result name="redirect" type="redirect"&gt;${url}&lt;/result&gt; </code></pre> <p>In the action:</p> <pre><code>private String url; public String getUrl() { return url; } public String execute() { [other stuff to setu...
<p>You can redirect to another action using annotation - </p> <pre><code>@Result( name = "resultName", type = "redirectAction", params = { "actionName", "XYZAction" } ) </code></pre>
20,950
<p>I'm not a math guy in the least but I'm interested in learning about rigid body physics (for the purpose of implementing a basic 3d physics engine). In school I only took Maths through Algebra II, but I've done 3d dev for years so I have a fairly decent understanding of vectors, quaternions, matrices, etc. My real...
<p><a href="https://rads.stackoverflow.com/amzn/click/com/159059472X" rel="nofollow noreferrer" rel="nofollow noreferrer">Physics for Game Programmers</a> I think is better than <a href="https://rads.stackoverflow.com/amzn/click/com/0596000065" rel="nofollow noreferrer" rel="nofollow noreferrer">Physics for Game Develo...
<p>Trying not to get you to rip off your hair with frustration (well, Baraff's/Witkin great math articles with the multi-dimensional matrices would do that sometimes), you can look at the easier online articles such as the ones published in Gamasutra. Here are two of them:</p> <ol> <li><a href="http://www.gamasutra.co...
8,513
<p>I'm trying to use a <code>break</code> statement in a <code>for</code> loop, but since I'm also using strict subs in my Perl code, I'm getting an error saying:</p> <blockquote> <p>Bareword "break" not allowed while "strict subs" in use at ./final.pl line 154.</p> </blockquote> <p>Is there a workaround for th...
<p>Oh, I found it. You use <a href="http://perldoc.perl.org/functions/last.html" rel="noreferrer">last</a> instead of <a href="https://perldoc.perl.org/functions/break.html" rel="noreferrer">break</a></p> <pre><code>for my $entry (@array){ if ($string eq "text"){ last; } } </code></pre>
<p>For Perl one-liners with <em>implicit loops</em> (using <code>-n</code> or <code>-p</code> command line options), use <code>last</code> or <code>last LINE</code> to break out of the loop that iterates over input records. For example, these simple examples all print the first 2 lines of the input:</p> <pre><code>echo...
38,956
<p>I'm looking for an elegant, high performance solution to the following problem. </p> <p>There are 256 linked lists. </p> <ul> <li>Each list contains the same types of object that among other things holds a whole number that is used to define a sort order.</li> <li>All numbers across all lists are unique</li> <li>...
<p>You could use a priority queue that holds the “topmost” item of each of the 256 linked lists. This “topmost” item is the one that is scheduled to be inserted into the resulting list. This way, you can just take the smallest element from the priority queue, insert it into your resulting queue, and insert its next ele...
<p>Just merge each list with the list 128 above it. (resulting in 128 lists)<br> Then merge each list with the list 64 above it. (resulting in 64 lists)<br> Then merge each list with the list 32 above it. (resulting in 32 lists)<br> Then merge each list with the list 16 above it. (resulting in 16 lists)<br> Then merge ...
19,608
<p>I'm working with JSTL in Eclipse, using the WTP. I have jstl and standard.jar in my WEB-INF/lib directory, and everything works. Eclipse is giving me this warning in my JSP:</p> <p>The TagExtraInfo class for c:forEach (org.apache.taglibs.standard.tei.ForEachTEI) was not found on the build path.</p> <p>I have JST...
<p>Add the standard.jar from the web-inf directory to your build path jars.</p>
<p>Are the jars actually on the build path? If so, you might try closing and reopening the project. Otherwise that message is controllable from the Web/JSP Files/Validation preference page.</p>
34,775
<p>What are the best ways (or at least most common ways) in ASP (VBScript) for input handling? My main concerns are HTML/JavaScript injections &amp; SQL injections. Is there some equivalent to PHP's <code>htmlspecialchars</code> or <code>addslashes</code>, et cetera? Or do I have to do it manually with something like s...
<p>The bottom line is this:</p> <ol> <li>Always HTML-encode user input before you write it to your page. <code>Server.HTMLEncode()</code> does that for you.</li> <li>Always use parameterized queries to interface with a database. The <code>ÀDODB.Command</code> and <code>ADODB.CommandParameter</code> objects are the rig...
<p>I would add to Tomalaks list one other point.</p> <p>Avoid using concatenation of field values in SQL code. That is, in some cases a stored procedure may build some SQL in a string to subsequently execute. This is fine unless a textual field value is used as part of its construction.</p> <p>A command parameter c...
35,406
<p>I would like to have an input element (type=text) or textarea element that validates dynamically by triggering specific keystrokes. This will be used for Chinese pinyin input, so for example:</p> <p>The user types "ma2" into an input element. The keydown event triggers for every keystroke, and the 2 never appears...
<p>You may not have much luck triggering keypress - I'm fairly sure that unless the keypress is trusted (i.e. originates from the browser), it won't be picked up.</p> <p>However, you can do text replacement and insert the carat back where it was - instead of shooting it to the end of the string. You need to use setSel...
<p>Also, for simple code controlling the "caret" in a cross-browser way this could be useful:</p> <p><a href="http://javascript.nwbox.com/cursor_position/" rel="nofollow noreferrer">http://javascript.nwbox.com/cursor_position/</a></p> <p>a bit late with the answer but I am sure you will still find this old stuff usef...
24,727
<p>Why does this lambda expression not compile?</p> <pre><code>Action a = () =&gt; throw new InvalidOperationException(); </code></pre> <p>Conjecture is fine, but I would really appreciate references to the C# language specification or other documentation.</p> <p>And yes, I know that the following is valid and will ...
<p>Hmm. I've got an answer, but it's not great.</p> <p>I don't believe that there's a "throw" <em>expression</em>. There's a throw <em>statement</em>, but not just an expression. Compare this with "Console.WriteLine()" which is a method invocation expression with a void type.</p> <p>As a parallel, you can't have a sw...
<p>Not a big surprise. Lambda expressions are an aspect of <em>functional</em> programming. Exceptions are an aspect of <em>procedural</em> programming. The C# mesh between the two styles of programming isn't perfect.</p>
31,716
<p>I am writing a C# console application that takes a binary file, rips it apart, analyzes it, and stores the data into a database. </p> <p>We want to use BizTalk to orchestrate watching when a new binary file is placed in a directory and calling my application with the file name/names to be parsed. </p> <p>Can Biz...
<p>I would <strong>not</strong> recommend doing this but in theory you could run the exe using a shell command within an expression shape:</p> <p><code>System.Diagnostics.Process.Start(@"C:\yourPath\yourExecutable.exe")</code></p> <p>The <code>System.Diagnostics</code> namespace is available in BizTalk 2006, I don't ...
<p>Biztalk is a server product so it will always be running in the background when you set it up in a production environment.</p> <p>I'd suggest that if you're wanting to use BizTalk you set it up to watch the location where the file will be dropped, rip it apart, analyze it and then write out to the database all with...
30,690
<p>What does the POP3 CAPA UIDL command do?</p>
<p>It checks if the pop3 server understands (has the CAPAbility) the UIDL command.</p> <p>The response should be "+OK" or "-ERR" depending on wether the server supports the UIDL command.</p> <p>The UIDL command returns (if supported) an uniqe identify for each message, so a client can identify messages reliably.</p> ...
<p>Gives the unique identifier for a message on the POP3 server. Possible responses: +OK or -ERR</p>
17,957
<p>The subject says it all, almost. How do I automatically fix jsp pages so that relative URLs are mapped to the context path instead of the server root? That is, given for example</p> <pre><code>&lt;link rel="stylesheet" type="text/css" href="/css/style.css" /&gt; </code></pre> <p>how do I set-up things in a way tha...
<p>Look into the <a href="http://www.w3schools.com/TAGS/att_base_href.asp" rel="noreferrer"><code>&lt;BASE HREF=""&gt;</code></a> tag. This is an HTML tag which will mean all links on the page should start with your base URL.</p> <p>For example, if you specified <code>&lt;BASE HREF="http://www.example.com/prefix"&gt;<...
<p>The better way is to HttpServletResponse.encodeURL() which will construct the url appropria</p>
19,093
<p>I have a WPF project defined like this:</p> <pre> MyApp.sln MyAppWPF MyApp.Domain </pre> <p>In one of my xaml files in the MyAppWPF project I'm trying to reference a class defined in MyApp.Domain project. I have a <strong>project reference</strong> in MyAppWPF to MyApp.Domain. I am trying to create the refer...
<p>Check if </p> <ol> <li>the fully qualified name for MyClass is MyApp.Domain.MyClass </li> <li>MyClass has a default public constructor (with no parameters) so that XAML can instantiate it.</li> </ol>
<p>If the XAML is not loose (is compiled within an assembly (DLL/EXE)<BR> make sure that assembly has a reference to the assembly you are looking for<BR> (right click on the project --> add reference ...).<BR> <BR> If the XAML is loose, make sure the assembly it is looking for is copied to the same directory the exe is...
26,641
<p>I'm using Java 1.5 and I'd like to launch the associated application to open the file. I know that Java 1.6 introduced the <a href="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/" rel="noreferrer">Desktop API</a>, but I need a solution for <strong>Java 1.5</strong>.</p> <p>So far ...
<p>+1 for <a href="https://stackoverflow.com/questions/325299/#325517">this answer</a></p> <p>Additionally I would suggest the following implementation using polymorphism:</p> <p>This way you can add new platform easier by reducing coupling among classes.</p> <p><em>The Client code:</em></p> <pre><code> Desktop des...
<p>We do put the command outside somewhere in the configuration file. </p> <p>Your "JAR and source code" will be "cross-platform", but your deployment doesn't.</p> <p>You can also do something like <a href="https://stackoverflow.com/questions/325299/cross-platform-way-to-open-a-file-using-java-15#326360">this answer<...
42,117
<p>If I use mod_rewrite to control all my 301 redirects, does this happen before my page is served? so if I also have a bunch of redirect rules in a php script that runs on my page, will the .htaccess kick in first?</p>
<p>When a request is made to the URI affected by the .htaccess file, then Apache will handle any rewrite rules before any of your PHP code executes.</p>
<p>So basically, the <code>.htaccess</code> more or less requires the relevant PHP code or files, as according to the rules specified in the <code>.htaccess</code>, meaning <code>.htaccess</code> is run first.</p>
19,153
<p>I have a class like the following:</p> <pre><code>public class DropDownControl&lt;T, Key, Value&gt; : BaseControl where Key: IComparable { private IEnumerable&lt;T&gt; mEnumerator; private Func&lt;T, Key&gt; mGetKey; private Func&lt;T, Value&gt; mGetValue; private Func&lt;Key, bool&gt; mIsKeyInC...
<p>No, basically. The static method in a non-generic class (such as DropDownControl [no &lt;&gt;]) is the best approach, as you should be able to use type-inference when you call Create() - i.e.</p> <pre><code>var control = DropDownControl.Create(name, dictionary); </code></pre> <p>C# 3.0 helps here both via "var" (v...
<p>If <code>T</code> will always be <code>KeyValuePair&lt;TKey,TValue&gt;</code> there's no need for it to be a generic type parameter at all. Just use the actual type everyplace you use <code>T</code>.</p> <p>Otherwise, if the type may sometimes have to be something else, I would suggest that you should perhaps have...
20,545
<p>I want to add items in a LaTeX-document. Say for example, that I want add hints to the document. I create a command, so I can call something similar to this:</p> <pre><code>\hint{foocareful}{Be careful with foo!}{foo is a very precious item and can easily be broken. Be careful, especially don't throw foo.} </code><...
<p>One way to do it is to use the <code>float</code> package. I think that, at least, the <code>floatrow</code> package can also do what you want, and may also be more flexible. See you go, though.</p> <p>Here's an example of something like you're trying to do using <code>float</code>:</p> <pre><code>\documentclass{a...
<p>Have not done this in years, but I would look at the LaTeX source code for \tableofcontents and \listoffigures. I think the mechanism is generic and you can expand it to include your own lists.</p>
36,303
<p>I need to use utf-8 characters in my perl-documentation. If I use:</p> <pre><code>perldoc MyMod.pm </code></pre> <p>I see strange characters. If I use:</p> <pre><code>pod2text MyMod.pm </code></pre> <p>everything is fine.</p> <p>I use Ubuntu/Debian.</p> <pre><code>$ locale LANG=de_DE.UTF-8 LC_CTYPE="de_DE.UTF-...
<p>Use <code>=encoding utf-8</code> as the first POD directive in your file, and use a fairly recent <code>perldoc</code> (for example from 5.10-maint). Then it should work.</p>
<p>perldoc -t MyMod.pm</p> <p>From the perldoc manual:</p> <p>-t Display pod using pod2text instead of Pod::Man and groff (-t is the default on win32 unless -n is specified)</p>
25,482
<p>I have an application in which users interact with each-other. I want to visualize these interactions so that I can determine whether clusters of users exist (within which interactions are more frequent).</p> <p>I've assigned a 2D point to each user (where each coordinate is between 0 and 1). My idea is that two ...
<p>In the past, when I've tried this kind of thing, I've used a spring model to pull linked nodes together, something like: <code>dx = -k*(x-l)</code>. <code>dx</code> is the change in the position, <code>x</code> is the current position, <code>l</code> is the desired separation, and <code>k</code> is the spring coeff...
<p>The spring model is the traditional way to do this: make an attractive force between each node based on the interaction, and a repulsive force between all nodes based on the inverse square of their distance. Then solve, minimizing the energy. You may need some fairly high powered programming to get an efficient solu...
11,929
<p>Is there a URL for StackOverflow that I can use on the VS startpage in place of the never updated MS page? The URL that VS uses can be set on the Tools->Options::Startup dialog.</p> <p>I've tried <a href="https://stackoverflow.com/feeds">https://stackoverflow.com/feeds</a> VS complaints with the following error:</...
<p>It appears that <a href="https://stackoverflow.com/feeds">https://stackoverflow.com/feeds</a> is actually an atom feed and not rss so that is probably where the VS issue is coming from.</p> <p>You may have to create an intermediary and transform the atom to rss.</p>
<p>Try the RSS feed for the main page: <a href="https://stackoverflow.com/feeds">https://stackoverflow.com/feeds</a></p> <p><strong>Edit</strong>: Whoops, as the comments rightly point out, looks like it's an ATOM feed not an RSS feed, I should have double checked before posting! I tried running the feed through FeedB...
24,735
<p>Seeing as C# can't <code>switch</code> on a Type (which I gather wasn't added as a special case because <code>is</code> relationships mean that more than one distinct <code>case</code> might apply), is there a better way to simulate switching on type other than this?</p> <pre><code>void Foo(object o) { if (o is...
<p><a href="https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/" rel="noreferrer">With C# 7</a>, which shipped with Visual Studio 2017 (Release 15.*), you are able to use Types in <code>case</code> statements (pattern matching):</p> <pre><code>switch(shape) { case Circle c: WriteLin...
<p>I agree with Jon about having a hash of actions to class name. If you keep your pattern, you might want to consider using the "as" construct instead:</p> <pre><code>A a = o as A; if (a != null) { a.Hop(); return; } B b = o as B; if (b != null) { b.Skip(); return; } throw new ArgumentException("..."...
38,287
<p>How do I execute a command every time after ssh'ing from one machine to another?</p> <p>e.g</p> <pre><code>ssh mymachine stty erase ^H </code></pre> <p>I'd rather just have "stty erase ^H" execute every time after my ssh connection completes.</p> <p>This command can't simply go into my .zshrc file. i.e. for loc...
<p>Put the commands in <code>~/.ssh/rc</code></p>
<p>Assuming a linux target, put it in your <code>.profile</code> </p>
36,804
<p>I know about <a href="https://docs.oracle.com/javase/9/docs/api/java/util/SortedSet.html" rel="noreferrer"><code>SortedSet</code></a>, but in my case I need something that implements <code>List</code>, and not <code>Set</code>. So is there an implementation out there, in the API or elsewhere?</p> <p>It shouldn't be...
<p>There's no Java collection in the standard library to do this. <a href="https://docs.oracle.com/javase/9/docs/api/java/util/LinkedHashSet.html" rel="noreferrer"><code>LinkedHashSet&lt;E&gt;</code></a> preserves ordering similarly to a <code>List</code>, though, so if you wrap your set in a <code>List</code> when you...
<p>I just made my own UniqueList in my own little library like this:</p> <pre><code>package com.bprog.collections;//my own little set of useful utilities and classes import java.util.HashSet; import java.util.ArrayList; import java.util.List; /** * * @author Jonathan */ public class UniqueList { private HashSet mast...
33,724
<p>The following code is implemented in Page_Load event to show SaveFileDialog to the user</p> <pre><code>string targetFileName = Request.PhysicalApplicationPath + "Reports\\TempReports\\FolderMasters" + Utility.GetRandomNumber() + ".pdf"; FileInfo file = new FileInfo(targetFileName); // Clear the content of the resp...
<p>I'm here again, as I got a solution for my second question.</p> <p>For <code>Response.End</code>, call the <code>HttpContext.Current.ApplicationInstance.CompleteRequest</code> method instead of Response.End to bypass the code execution to the Application_EndRequest event.</p> <p><a href="http://support.microsoft.c...
<p>I'm here again, as I got a solution for my second question.</p> <p>For <code>Response.End</code>, call the <code>HttpContext.Current.ApplicationInstance.CompleteRequest</code> method instead of Response.End to bypass the code execution to the Application_EndRequest event.</p> <p><a href="http://support.microsoft.c...
36,491
<p>I know that <code>tan(angle)</code> gets me the tangent. But how do I do the "reverse tangent" so that I can get the angle given the length of both sides of the right triangle?</p> <p>I'm assuming there is a method for this in <code>math.h</code>?</p>
<p>There should be an atan() function.</p> <p>For example: <a href="http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.7.html" rel="noreferrer">http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.7.html</a></p>
<p>use atan()</p>
30,339
<p>I need to modify the MBR of Windows, and I would really like to do this from Windows.</p> <p>Here are my questions. I know that I can get a handle on a physical device with a call to CreateFile. Will the MBR always be on \\.\PHYSICALDRIVE0? Also, I'm still learning the Windows API to read directly from the disk. Is...
<p>Once the OS is started the MBR is typically protected for virus reasons - this is one of the oldest virus tricks in the books - goes back to passing viruses from floppy to floppy.</p> <p>Even if it wasn't restricted, you have to write low level code - it isn't part of the file system, but exists on a specific locat...
<p>Modifying the bootloader is bad, bad idea. Here are just a few of the possible gotcha's:</p> <ul> <li>it will potentially kill full disk encryption products (Truecrypt, PGP, Vista's BitLocker, etc)</li> <li>it will potentially trip up AV products (scaring users)</li> <li>it will potentially kill complicated booting...
6,058
<p>I'm working on a small project where for the first time I want to use XML as the one and only data source...a file based store suits the need of the project.</p> <p>When writing the DAL should I have all the get methods static? to aviod and "reading while file open" errors? Should I use CacheDependency on the file?...
<p>I think you were not as clear as you could have been. How big are these files going to be? Would it make sense for the data layer to always keep the XmlDocument in memory and dump to harddisk on every update? </p> <p>How often are updates going to occur, if at all? How are you going to handle concurrency? Are updat...
<p>OK.</p> <p>The files are not likely to be huge, I would suspect the max to reach 1-2MB.</p> <p>I get you with the DAL interface needing to be interchangable with a DB, so I need to think carefully about my interfaces.</p> <p>Concurrency, well I am concerned about that and not entirly sure how I should handle it. ...
21,920
<p>I've never used <a href="http://en.wikipedia.org/wiki/SOAP" rel="noreferrer">SOAP</a> before and I'm sort of new to Python. I'm doing this to get myself acquainted with both technologies. I've installed <a href="http://trac.optio.webfactional.com/wiki/soaplib" rel="noreferrer">SOAPlib</a> and I've tried to read th...
<p><strong><em>Update (2016):</em></strong></p> <p>If you only need SOAP client, there is well maintained library called <a href="https://pypi.org/project/zeep/" rel="noreferrer">zeep</a>. It supports both Python 2 and 3 :)</p> <hr> <p><strong><em>Update:</em></strong></p> <p>Additionally to what is mentioned above...
<p>Could this help: <a href="http://users.skynet.be/pascalbotte/rcx-ws-doc/python.htm#SOAPPY" rel="nofollow noreferrer">http://users.skynet.be/pascalbotte/rcx-ws-doc/python.htm#SOAPPY</a></p> <p>I found it by searching for <code>wsdl</code> and <code>python</code>, with the rational being, that you would need a wsdl d...
25,255
<p>I want to capture as a bitmap the system cursor on Windows OSes as accurately as possible. The provided API for this is to my knowledge GetCursorInfo, DrawIconEx.</p> <p>The simple chain of actions is:</p> <ul> <li>Get cursor by using GetCursorInfo</li> <li>Paint the cursor in a memory DC by using DrawIconEx.</li>...
<p>Unfortunately, I don't think there's a Windows API that discloses the current frame of the cursor animation. I assume that's what you're after: the look of the cursor at the instant you make the snapshot.</p>
<p>I suspect you are missing a step.</p> <p>You need to create a bitmap to select into your device context otherwise your bit map is just a single pixel. </p> <p>See CreateCompatibleBitmap in the MSDN documentation:</p> <pre> HBITMAP CreateCompatibleBitmap( HDC hdc, // handle to DC int nWidth, // wid...
23,800
<p>I'm having a little bit of trouble making a sticky form that will remember what is entered in it on form submission if the value has double quotes. The problem is that the HTML is supposed to read something like:</p> <pre><code>&lt;input type="text" name="something" value="Whatever value you entered" /&gt; </code><...
<p>You want <a href="http://www.php.net/htmlentities" rel="noreferrer">htmlentities()</a>.</p> <p><code>&lt;input type="text" value="&lt;?php echo htmlentities($myValue); ?&gt;"&gt;</code></p>
<p>This is what I use: </p> <pre><code>htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE | ENT_DISALLOWED | ENT_HTML5, 'UTF-8') </code></pre> <ul> <li><code>ENT_QUOTES</code> tells PHP to convert both single and double quotes, which I find desirable.</li> <li><code>ENT_SUBSTITUTE</code> and <code>ENT_DISALLOWED</...
34,519
<p>Is there a Registry setting that I can look for to determine whether or not the Visual C++ redistributable is installed, whether standalone or as part of Visual Studio 2008? I know that I could launch the VC++ 2008 redistributable installer and let it handle the detection, but it would look cleaner if I can check fo...
<p>Check the registry:</p> <blockquote> <p>VC++2008 (sp1): HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{3C3D696B-0DB7-3C6D-A356-3DB8CE541918}</p> </blockquote> <p>or</p> <blockquote> <p>VC++2008 (original): HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FF66E9F6-83E7-3A3E-AF14-8DE9A80...
<p>You can check for the files under the WINDOWS\WinSxS directory to see which versions you have installed. Often many versions can be installed at one time so you might need to check the specific versions you have installed.</p>
24,858
<p>Is there any provable reason why I should always specify the SQL data type for SqlCommand paramenters?</p>
<p>The only time I've run into a case when I had to specify a data type was when passing in DBNull. When I wasn't specifying a data type, it defaulted to a Varchar, and ended up crashing because I was trying to set an integer value to Null.</p>
<p>and you will find that sometimes you will get very strange errors when you have not specified the sql type <em>and size</em></p> <p>it is safest - and more self-documenting - to always declare the correct sql type and size</p>
42,364
<p>In my program I have one array with 25 double values 0.04 When I try to sum these values in a loop I get following results:</p> <pre><code>0.0 + 0.04 = 0.04 0.04 + 0.04 = 0.08 0.08 + 0.04 = 0.12 0.12 + 0.04 = 0.16 0.16 + 0.04 = 0.2 0.2 + 0.04 = 0.24000000000000002 0.24000000000000002 + 0.04 = 0.28 0.28 + 0.04 = 0.3...
<p>The most common storage for floating-point values in programming languages - <a href="http://en.wikipedia.org/wiki/IEEE_754" rel="noreferrer">IEEE singles and doubles</a> - does not have exact representations for most decimal fractions.</p> <p>The reason is that they store values in binary floating-point format, ra...
<p>You may wish to check out the java <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html" rel="nofollow noreferrer">BigDecimal</a> class as an alternative to floats and doubles.</p>
42,448
<p>I've encountered lately some opinions saying that Object Oriented design/programming should not always be used. <BR/> Do you know some use-cases that will not benefit from and should not use Object Oriented design? <BR/> <BR/> For example: there are some problems (concerns) that will benefit from AOP.</p>
<p>Some problems are best expressed using other paradigms such as Functional Programming. Also, declarative paradigms allow more robust formal reasoning about the correctness of the code. See <a href="http://www.erlang.org" rel="noreferrer">Erlang</a> for a good example of a language with certain advantages that can'...
<p>Object Oriented programming is good solution if you make good design.</p>
30,640
<p>I was taught that a regression test was a small (only enough to prove you didn't break anything with the introduction of a change or new modules) sample of the overall tests. However, <a href="http://www.iceincusa.com/16csp/content/16_smoke/smkrgt.htm" rel="noreferrer">this article</a> by Ron Morrison and Grady Booc...
<p>There are multiple interpretations. If you're only fixing a bug that affects one small part of your system then regression tests might only include a small suite of tests that exercise the class or package in question. If you're fixing a bug or adding a feature that has wider scope then your regression tests shoul...
<p>Start with what you are trying to accomplish. Then do what you need to do to accomplish that goal. And then use buzzword bingo to assign a word to what you actually do. Just like everyone else :-) Accuracy isn't all that important.</p>
31,214
<p>I'm working with some schema which defines an abstract complex type, eg.</p> <pre><code>&lt;xs:complexType name="MyComplexType" abstract="true"&gt; </code></pre> <p>This type is then referenced by another complex type in the schema:</p> <pre><code>&lt;xs:complexType name="AnotherType"&gt; &lt;xs:sequence&gt; ...
<p>After evaluating several different schema-to-code tools the only one we found that was able to deal with our schema (very large and extremely complicated) was Liquid XML (<a href="http://www.liquid-technologies.com/" rel="nofollow noreferrer">http://www.liquid-technologies.com/</a>).</p>
<p>I know this is an old question, but I needed an answer for this question this week. I tried Liquid Studios as suggested by @ng5000 and found that software to be very clunky. Additionally, the cs output was so complicated that it gave me over 800 lines of code for a single entity with 12 simple properties.</p> <p>I ...
39,339
<p>How do I generate a random number between <code>0</code> and <code>n</code>?</p>
<p>Use <a href="http://www.ruby-doc.org/core-2.1.3/Kernel.html#method-i-rand" rel="noreferrer"><code>rand(range)</code></a></p> <p>From <a href="http://www.codeodor.com/index.cfm/2007/3/25/Ruby-random-numbers/1042" rel="noreferrer">Ruby Random Numbers</a>:</p> <blockquote> <p>If you needed a random integer to simul...
<p>Don't forget to seed the RNG with <em>srand()</em> first.</p>
24,173
<p>Are there other possibilities besides IIS for hosting web sites and web services based on ASP.NET, which are recommended by Microsoft for small-scale environments?</p>
<p>You can host your own web server in-process within your own application using <a href="http://blogs.msdn.com/carlosag/archive/2008/04/14/HostYourOwnWebServerUsingIIS7.aspx" rel="noreferrer">IIS 7's Hostable Web Core.</a> And, of course, you can create your own app that listens to port 80. However, the complexities...
<p>Ohad has a tutorial on getting it to run on apache: <a href="http://weblogs.asp.net/israelio/archive/2005/09/11/424852.aspx" rel="nofollow noreferrer">asp.net on apache</a>. I'm not really sure how well it runs but it works. I don't think Microsoft recommends anything other than IIS, but why would they. For most ...
32,279
<p>I'm running in a windows environment with Trac / SVN and I want commits to the repository to integrate to Trac and close the bugs that were noted in the SVN Comment.</p> <p>I know there's some post commit hooks to do that, but there's not much information about how to do it on windows.</p> <p>Anyone done it succes...
<p>Alright, now that I've got some time to post my experience after figuring this all out, and thanks to Craig for getting me on the right track. Here's what you need to do (at least with SVN v1.4 and Trac v0.10.3):</p> <ol> <li>Locate your SVN repository that you want to enable the Post Commit Hook for.</li> <li>ins...
<p>Post commit hooks live in the "hooks" directory where ever you have the repository living on the server side. I don't know where you have them in your environment, so this is just an example</p> <p>e.g. (windows):</p> <pre><code>C:\Subversion\repositories\repo1\hooks\post-commit </code></pre> <p>e.g. (llinux/uni...
10,972
<p>I am searching for graphic libraries that can draw seismic data; which is a large number of curves drawn vertically and gives you a shape like this:</p> <p><a href="http://img237.imageshack.us/my.php?image=seismicdataxb2.png" rel="nofollow noreferrer">alt text http://img237.imageshack.us/my.php?image=seismicdataxb2...
<p>Have you thought about creating a WPF application? This probably gives you what you need.</p>
<p>Sorry, old question I know; but INT sell a series of visualization libraries (including .NET) for this type of thing:</p> <p><a href="http://www.int.com/" rel="nofollow">http://www.int.com/</a></p> <p>Their C++ libraries are also cross-platform: I used to work for a company that used them in X Windows and MS Windo...
39,509
<p>How do you reverse the effect of a merge on polarised branches without dying of agony?</p> <p>This problem has been plaguing me for <strong>months</strong> and I have finally given up. </p> <p>You have 1 Repository, with 2 <strong>Named</strong> Branches. A and B. </p> <p>Changes that occur to A will inevitably...
<p>I think I found a solution which permanently fixes the bad merge, and which does not require you to manually check any diffs. The trick is to go back in history and generate commits parallel to the bad merge.</p> <p>So we have repository with separate branches per maintained version of a single product. Like the si...
<p>So you want to merge just some changesets from B into A? Backing out changesets like you have been doing is a really bad idea as you have already suffered.</p> <p>You should either use the transplant extension or have a third branch where you make common changes to merge into both A and B.</p>
33,349
<p>Can you tell me how can I use threads in C++ programs, and how can I compile it as it will be multithreaded? Can you tell me some good site where I can start from root?</p> <p>Thanks</p>
<p>I haven't used it myself, but I'm told that the Boost thread libraries make it incredibly easy.</p> <p><a href="http://www.boost.org/doc/libs/1_37_0/doc/html/thread.html" rel="noreferrer">http://www.boost.org/doc/libs/1_37_0/doc/html/thread.html</a></p>
<p><a href="https://stackoverflow.com/questions/326487/multithreaded-image-processing-in-c#327143">You may want to read my earlier posting on SO.</a></p> <p>(In hindsight, that posting is a little one-sided towards pthreads. But I'm a Unix/Linux kind of guy. And that approach seemed best with respect to the original...
43,166
<p>Do you use Design by Contract professionally? Is it something you have to do from the beginning of a project, or can you change gears and start to incorporate it into your software development lifecycle? What have you found to be the pros/cons of the design approach?</p> <p>I came across the <a href="http://en.wiki...
<p>I can't recommend it highly enough. It's particularly nice if you have a suite that takes inline documentation contract specifications, like so:</p> <pre><code>// @returns null iff x = 0 public foo(int x) { ... } </code></pre> <p>and turns them into generated unit tests, like so:</p> <pre><code>public test_foo...
<p>I don't actually use Design by Contract, on a daily basis. I do, however know that it has been incorporated into the <a href="http://www.digitalmars.com/d/2.0/dbc.html" rel="nofollow noreferrer">D</a> language, as part of the language.</p>
4,601
<p>I'm trying to save some XML-Data in my UserSettings (Properties.Settings.Default.UserSettings) in a .NET Winforms Project. Is there a Possibility to do that or would it be better to save this Data in a seperated File?</p> <p>Thanks for your Answers!</p>
<p>You can store an XML document's string representation in a setting of type String. To save the document, load it into an XmlDocument and set the setting to the value of the XmlDocument.OuterXml property. To retrieve it, create a new XmlDocument and use its LoadXml method to parse the string into an XML document.</...
<p>Thanks for your Answers. As a conclusion, I've decided to extract this stuff into another xml-File which I store in the Resources.</p>
23,801
<p>Which design do you think runs faster on PostgreSQL?</p> <ol> <li><p>Making a 15 column table of varchars and the like, but putting all TEXT columns in a separate table with an fkey link back to this table. And let's imagine you want to search for the record with ID of "4" but then pull all the rows back, including...
<p>PostgreSQL doesn't handle TEXT columns in the same way as other DBMS's.</p> <p>From their docs:</p> <blockquote> <p>Tip: There are no performance differences between these three types, apart from increased storage size when using the blank-padded type, and a few extra cycles to check the length when storing int...
<p>(B) is correct, for the reason given in the question itself.</p>
45,333
<p>I have this solution for a single button:</p> <pre><code>myButton.Attributes.Add("onclick", "this.disabled=true;" + GetPostBackEventReference(myButton).ToString()); </code></pre> <p>Which works pretty well for one button, any ideas on how to expand this to 2 buttons?</p>
<p>You could add an clientside onSubmit handler, or you could do this:</p> <pre><code>myButton.Attributes.Add("onclick", "this.disabled=true; document.getElementById('" + button2.ClientID + "').disabled = true;" + GetPostBackEventReference(myButton).ToString()); </code></pre>
<p>Change the command to:</p> <pre><code>myButton.Attributes.Add("onclick", "this.disabled=true;document.getElementbyID("Button2").disabled=true;" + GetPostBackEventReference(myButton).ToString()); </code></pre>
21,102
<p>The two key event argument classes <code>KeyEventArgs</code> and <code>PreviewKeyDownEventArgs</code> each have two properties, <code>KeyCode</code> and <code>KeyData</code>, which are both of the enumeration type Keys.</p> <p>What is the difference between these two properties? Do the values in them ever differ fr...
<p><code>KeyCode</code> is an enumeration that represents all the possible keys on the keyboard. <code>KeyData</code> is the <code>KeyCode</code> combined with the modifiers (Ctrl, Alt and/or Shift).</p> <p>Use <code>KeyCode</code> when you don't care about the modifiers, <code>KeyData</code> when you do. </p>
<p>The difference that I have observed is that the value in <code>KeyCode</code> only holds a <code>Keys</code> enumeration value for the key that triggered the current firing of the event. <code>KeyData</code>, on the other hand, will contain a logical OR of the value in <code>KeyCode</code> with any modifier keys (C...
41,110
<p>POSIX environments provide at least two ways of accessing files. There's the standard system calls <code>open()</code>, <code>read()</code>, <code>write()</code>, and friends, but there's also the option of using <code>mmap()</code> to map the file into virtual memory.</p> <p>When is it preferable to use one over ...
<p><a href="http://man7.org/linux/man-pages/man2/mmap.2.html" rel="noreferrer"><code>mmap</code></a> is great if you have multiple processes accessing data in a read only fashion from the same file, which is common in the kind of server systems I write. <code>mmap</code> allows all those processes to share the same ph...
<p>An advantage that isn't listed yet is the ability of <code>mmap()</code> to keep a read-only mapping as <em>clean</em> pages. If one allocates a buffer in the process's address space, then uses <code>read()</code> to fill the buffer from a file, the memory pages corresponding to that buffer are now <em>dirty</em> s...
32,210