instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>I'm looking for the best way to log errors in an ASP.NET application. I want to be able to receive emails when errors occurs in my application, with detailed information about the Exception and the current Request.</p> <p>In my company we used to have our own ErrorMailer, catching everything in the Global.asax Appl...
<p>I use <a href="http://code.google.com/p/elmah/" rel="noreferrer">elmah</a>. It has some really nice features and here is a <a href="http://www.codeproject.com/KB/aspnet/ELMAHDemo.aspx" rel="noreferrer">CodeProject</a> article on it. I think the StackOverflow team uses elmah also!</p>
<p>We use a custom homegrown logging util we wrote. It requires you to implement logging on your own everywhere you need it. But, it also allows you to capture a lot more than just the exception.</p> <p>For example our code would look like this:</p> <pre><code>Try Dim p as New Person() p.Name = "Joe" p.Age = ...
3,306
<p>I came across PHP way of doing the trick:</p> <pre><code>my_bool reconnect = 1; mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect); </code></pre> <p>but no luck with MySQLdb (python-mysql).</p> <p>Can anybody please give a clue? Thanks.</p>
<p>I solved this problem by creating a function that wraps the <code>cursor.execute()</code> method since that's what was throwing the <code>MySQLdb.OperationalError</code> exception. The other example above implies that it is the <code>conn.cursor()</code> method that throws this exception.</p> <pre><code>import MySQ...
<p>You other bet it to work around dropped connections yourself with code.</p> <p>One way to do it would be the following:</p> <pre><code>import MySQLdb class DB: conn = None def connect(self): self.conn = MySQLdb.connect() def cursor(self): try: return self.conn.cursor() ...
25,502
<p>Details:</p> <ul> <li>Only disable after user clicks the submit button, but before the posting back to the server</li> <li>ASP.NET Webforms (.NET 1.1)</li> <li>Prefer jQuery (if any library at all)</li> <li>Must be enabled if form reloads (i.e. credit card failed)</li> </ul> <p>This isn't a necessity that I do thi...
<p>For all submit buttons, via JQuery, it'd be:</p> <pre><code>$('input[type=submit]').click(function() { this.disabled = true; }); </code></pre> <p>Or it might be more useful to do so on form submission:</p> <pre><code>$('form').submit(function() { $('input[type=submit]', this).attr("disabled","disabled"); }); ...
<p>There are three ways to submit a form that should be covered. Use both David McLaughlin's and Jimmy's suggestions. One will disable the submit button form element while the other disables the basic HTML form submit.</p> <p>For the third, these won't disable Javascript from doing a form.submit(). The <code>OnSubm...
6,810
<p>At work I am responsible for writing specifications quite often and I am also the person who insisted on getting specifications in the first place. The problem is I am unsure how specifications should look and what they should contain. A lot of the time when my boss is writing the specifications (we are both inexper...
<p>The most important part of development documentation in my opinion, is <strong>having the correct person do it.</strong></p> <ul> <li>Requirements Docs - Users + Business Analyst</li> <li>Functional Spec - Business Analyst + developer </li> <li>Technical Spec (how the functionality will actually be implemented) - S...
<p>The important thing is to get something written down rather than worry about the format.</p>
13,804
<p>Is there a way to be sure we hold a useable reference to an object i.e. being sure it has not been already freed leaving that non nil reference dangling.</p>
<p>If you're using FastMM4 as your Memory Manager, you can check that the class is not <strong>TFreeObject</strong>.<br> Or, in a more standard case, use a routine that will verify that your object is what it says it is by <strong>checking the class VMT</strong>.</p> <p>There have been such ValidateObj functions hanng...
<p>Unfortunately there is no way to 100% guarantee that a pointer to anything is still valid, except by meticolously writing the correct code.</p>
13,859
<p>I have a button inside an updatepanel. I have a PopupControlExtender linked to the button so when the button is clicked a panel pops up. It works fine except it does a full postback and I can't figure out why. The button and the PopupControlExtender is inside an update panel which inside the ContentTemplate tag. Whe...
<p>Ensure the button's UseSubmitBehavior property is set to false</p>
<p>I have the exact opposite issue: the Link Button causes a full post-back while the Button control works. However unlike the other answer, the Button only works if UseSubmitBehavior is True/undefined.</p> <p>So I just use some CSS with the button to it look like a link button, e.g.</p> <pre><code>input.linkButton {...
28,439
<p>On a JSTL/JSP page, I have a java.util.Date object from my application. I need to find the day <em>after</em> the day specified by that object. I can use &lt;jsp:scriptlet&gt; to drop into Java and use java.util.Calendar to do the necessary calculations, but this feels clumsy and inelegant to me.</p> <p>Is there so...
<p>I'm not a fan of putting java code in your jsp.</p> <p>I'd use a static method and a taglib to accomplish this.</p> <p>Just my idea though. There are many ways to solve this problem.</p> <pre><code>public static Date addDay(Date date){ //TODO you may want to check for a null date and handle it. Calendar cal...
<p>Unfortunately there is no tag in the standard JSP/JSTL libraries that I know of that would allow you to do this date calculation.</p> <p>The simplest, and most inelegant, solution is to just use some scriptlet code to do the calculation. You've already stated that you think this is a clunky solution, and I agree w...
9,991
<p>We have several wizard style form applications on our website where we capture information from the user on each page and then submit to a backend process using a web service.</p> <p>Unfortunately we can't submit the information in chunks during each form submission so we have to store it the users session until th...
<p>Assuming the information is not sensitive then you could store the information in a cookie which would reduce the amount of information required to be stored server side. This would also allow you to access the information via JavaScript. </p> <p>Alternatively you could use the viewstate to store the information al...
<p>If you use a traditional HTTP model (i.e. don't use runat="server") you can post the data to another asp page and place the posted data into hidden form elements, you can do this for however many pages you need thus avoiding placing anything in a session variable. </p>
9,863
<p>At my company most inventory tracking is done via an ASP.NET web application. The application is poorly conceived, poorly designed, poorly implemented, and somewhat of a hassle for a user to work with. These are things that are my opinion though and management has its own thoughts on the matter.</p> <p>Such luxur...
<p>Next time, for the good of the world, keep these kinds of ideas to yourself. It sounds like your boss is not qualified to make such a call, so make the call for him.</p> <p>If your boss believes the url bar and browser buttons are not suppose to be there, then convert it to a stand alone app. Don't try to cram it...
<p>I'd be tempted to simply add a button that <em>allows</em> you to pop out the app, without removing the normal mode.</p> <p>If necessary, sell it with some waffle about users getting confused or not being able to reopen it or something. Or even pretend its not possible to do it without it.</p> <p>That goes some wa...
36,607
<p>We've just been given the following code as a solution for a complicated search query in a new application provided by offshore developers. I'm skeptical of the use of dynamic SQL because I could close the SQL statement using '; and then excute a nasty that will be performed on the database!</p> <p>Any ideas on how...
<p>As an aside, I would not use <code>EXEC</code>; rather I would use <code>sp_executesql</code>. See this superb article, <a href="http://www.sommarskog.se/dynamic_sql.html" rel="noreferrer">The Curse and Blessings of Dynamic SQL</a>, for the reason and other info on using dynamic sql.</p>
<p>I like dynamic SQL for search.</p> <p>Where I have used it in the past I have used .Net prepared statements with any user generated string being passed in as a parameter NOT included as text in the SQL. </p> <p>To run with the existing solution you can do a number of thing to mitigate risk.</p> <ol> <li>White lis...
33,652
<p>Python's IDLE has 'Check Module' (Alt-X) to check the syntax which can be called without needing to run the code. Is there an equivalent way to do this in Emacs instead of running and executing the code?</p>
<p>You can <a href="https://web.archive.org/web/20090503090851/http://www.plope.org/Members/chrism/flymake-mode" rel="nofollow noreferrer">use Pyflakes together with Flymake</a> in order to get instant notification when your python code is valid (and avoids a few common pitfalls as well).</p>
<p>You can use <a href="http://www.logilab.org/857" rel="nofollow noreferrer">pylint</a> for such things and there seems to be a way to integrate it into <a href="http://www.emacswiki.org/cgi-bin/wiki/PythonMode#toc8" rel="nofollow noreferrer">emacs</a>, but I've never done the latter b/c I'm a vim user.</p>
25,202
<p>I have heard umpteen times that we 'should not mix business logic with other code' or statements like that. I think every single code I write (processing steps I mean) consists of logic that is related to the business requirements..</p> <p>Can anyone tell me what exactly consists of business logic? How can it be di...
<p>Simply define what you are doing in plain English. When you are saying things businesswise, like "make those suffer", "steal that money", "destroy this portion of earth" you are talking about business layer. To make it clear, things that get you excited go here.</p> <p>When you are saying "show this here", "do not ...
<p>For me, " <em>business logic</em> " makes up all the entities that represent data applicable to the problem domain, as well as the logic that decides on "what do do with the data"..</p> <p>So it should really consist of "data transport" (not access) and "data manipulation".. Actually data access (stuff hitting the ...
6,034
<p>3D printer use stepper motors for moving print head and extruding filament. They need to have good torque and resolution.</p> <p>Microstepping improves resolution as much as 32 fold (I think) but reduces torque the higher you microstep.</p> <p>So...</p> <ol> <li><p>Why not rotate the motor with microstepping at high...
<p>To answer each point:</p> <ul> <li><em>Microstepping improves resolution as much as 32 fold (I think) but reduces torque the higher you micro-step.</em></li> </ul> <p>Torque is not reduced by micro-stepping. Torque reduction only occurs when you are moving at high RPMs. The motor's phase resistance has to be conduci...
<p>There's an old rule that says &quot;If the question starts with 'Why don't they,' the answer is most likely 'money.'&quot;</p> <p>In this case, the issue is the cost of worm gears. Properly mating worm gears are much more expensive to make than common spur gears. That probably accounts for most of it -- not to men...
1,963
<p>Is it possible to access the Abstract Syntax Tree(AST) inside the javac.exe programmatically? Could you provide an example?</p>
<p>Yes, it is possible, but only since Java 6. <a href="http://java.sun.com/developer/Meet-Eng/vonderahe/" rel="nofollow noreferrer">Peter von der Ahé</a> talks about the two JSRs in <a href="http://www.artima.com/lejava/articles/compiler_api.html" rel="nofollow noreferrer">this interview</a>. Of JSR 199: </p> <block...
<p>Compile and run this with <code>-cp tools.jar</code> (where you have to specify the location of your <code>tools.jar</code>, obviously).</p> <pre><code>import com.sun.source.util.Trees; import javax.tools.JavaCompiler; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; public class JCTree...
23,955
<p>Say I have a string of 16 numeric characters (i.e. 0123456789012345) what is the most efficient way to delimit it into sets like : 0123-4567-8901-2345, in PHP?</p> <p>Note: I am rewriting an existing system that is painfully slow.</p>
<p>Use <a href="http://php.net/str_split" rel="nofollow noreferrer">str_split()</a>:</p> <pre><code>$string = '0123456789012345'; $sets = str_split($string, 4); print_r($sets); </code></pre> <p>The output:</p> <pre><code>Array ( [0] =&gt; 0123 [1] =&gt; 4567 [2] =&gt; 8901 [3] =&gt; 2345 ) </code></p...
<p>If you are looking for a more flexible approach (for e.g. phone numbers), try regular expressions:</p> <pre><code>preg_replace('/^(\d{4})(\d{4})(\d{4})(\d{4})$/', '\1-\2-\3-\4', '0123456789012345'); </code></pre> <p>If you can't see, the first argument accepts four groups of four digits each. The second argument ...
39,116
<p>I have two C++ processes (A and B), executing under Windows, where one launches the other. I would like to effectively single-thread their execution. For example:</p> <ol> <li>Start process A</li> <li>A creates B</li> <li>A suspends</li> <li>B executes some fixed set of operations</li> <li>B suspends and A is resum...
<p>Events would work in this case:</p> <ul> <li>A creates an event an starts Process B</li> <li>A waits for the event to be signaled</li> <li>B also creates an event, does it's first item, then signals A's event (which either has a well-known name or the handle can be passed to B when it starts or using some other mec...
<p>For interprocess synchronization you could use <a href="http://en.wikipedia.org/wiki/Semaphores" rel="nofollow noreferrer">semaphores</a>. Here is the <a href="http://msdn.microsoft.com/en-us/library/ms686946(VS.85).aspx" rel="nofollow noreferrer">documentation</a>.</p>
31,008
<p>The <code>JFileChooser</code> seems to be missing a feature: a way to suggest the file name when saving a file (the thing that usually gets selected so that it would get replaced when the user starts typing).</p> <p>Is there a way around this?</p>
<p>If I understand you correctly, you need to use the <code>setSelectedFile</code> method.</p> <pre><code>JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setSelectedFile(new File(&quot;fileToSave.txt&quot;)); jFileChooser.showSaveDialog(parent); </code></pre> <p>The file doesn't need to exist.</p> <p>If yo...
<p>If that doesn't work, here is a workaround:</p> <pre><code>dialog.getUI().setFileName( name ) </code></pre> <p>But you should check whether the selection mode is <code>FILES_ONLY</code> or <code>FILES_AND_DIRECTORIES</code>. If it's <code>DIRECTORIES_ONLY</code>, then <code>setSelectedFile()</code> will strip the ...
46,506
<p>Is it possible to verify which source safe project is bound to my vs.net solution?</p> <p>When I checkout a file in vs.net, then look up the file in source safe, it seems to be checking out a file from another project. When I look at the directory in 'set working folder' it seems to be ok.</p>
<p><strong>File > Source Control > Change Source Control...</strong> shows the bindings for your code.</p>
<p>In visual studio, under the file or edit menu, (I think it's the the file menu) there's a menu item that says "Source control"... Under there, there's a submenu named "Change Source Control" It's in there... </p>
48,286
<p>Failed to create component 'User Control 1'. the error message follows:</p> <blockquote> <p>'System.NullReferenceException : Object reference not set to an instance of an object. at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object Component, Object Value) .............. etc..........</p> </blo...
<p>When a User Control won't load into the Visual Studio designer here is what you need to do. These instruction are for vb.net project but c# should be similar. Also, before doing this close all open windows (or at least the source and designer files of the control you are working on.)</p> <p>One last thing. The F...
<p>Thanks, Seth, for this post! Your solution helped me nail down the error. The only thing I would add to this is that when "INSTANCE_2" loads, you may need to actually load the project file in INSTANCE_2. I needed to because I wasn't dealing with a control library, but instead had custom User Controls defined in the ...
47,634
<p>I have a user table like this</p> <pre><code>user_id | community_id | registration_date -------------------------------------------- 1 | 1 | 2008-01-01 2 | 1 | 2008-05-01 3 | 2 | 2008-01-28 4 | 2 | 2008-07-22 5 | 3 | 2008-01-11 </c...
<p>With an inner select:</p> <pre><code>select registration_date, community_id from user outer where user_id IN ( select user_id from user inner where inner.community_id = outer.community_id order by registration_date limit 2,1 ) order by registration_da...
<p>Is this what you mean?</p> <pre><code>SELECT registration_date FROM user ORDER BY registration_date LIMIT n </code></pre> <p>Where <em>n</em> is the user you are concerned about.</p>
45,540
<p>Is there a way to combine a previous translation when extracting the csv file from an application? Or any other tool that could do this job for me? </p> <p>I can’t really see how could i use locbaml if i had to translate everything from scratch every time i add a new control in my application.</p>
<p>You could use the <strong>last-child</strong> pseudo-class on the li element to achieve this</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;style type="text/css"&gt; ul li:last-child { font-weight:bold } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;ul&gt; &lt;li&gt;IE&lt;/li&gt; &lt;li&gt;Firefox&lt;/li&gt; &lt;li&g...
<p>Does jquery come bundled with drupal, if so you could use </p> <pre><code>$('ul&gt;li:last').addClass('last'); </code></pre> <p>to achieve this</p>
13,882
<p>Here's my problem: I have to call a web service with a secure header from a classic ASP page that returns a complex data type. For various reasons concerning a 3rd party tool it has to be classic ASP. We decided that I should create an external dll to do this - which I did (in c#) so it returns a dataset (Somethi...
<p>No, that (static/no ctor) isn't true. Quite the opposite, in fact, since COM will need to create an instance! You simply need to make the class COM visible. Mainly, this is just adding some attributes, and registering it as a COM dll (regasm).</p> <p><a href="http://msdn.microsoft.com/en-us/library/zsfww439.aspx" r...
<blockquote> <p>Somebody said my class has to be static and I can't have a constructor. Is this true? </p> </blockquote> <p>A COM class needs to have a default constructor, which will be used by clients when they call CoCreateInstance. After the object is created, you can set properties on it, or call other met...
37,214
<p>I found a bug in the Contains statement in Linq (not sure if it is really in Linq or Linq to SQL) and want to know if anyone else has seen this and if there is a fix or workaround.</p> <p>If the querysource you do the contains with has more than 10 items in it, it does not pass the items correctly to the SQL query....
<p>The more I look at it, and after running more tests, I'm thinking the bug may be in the Sql Server Query Visualizer plugin for Visual Studio, not actually in Linq to SQL itself. So it is not nearly as bad a situation as I thought - the query will return the right results, but you can't trust what the Visualizer is s...
<p>Try actually looking at the output from your datacontext before you pass judgement.</p> <p>DataContext.Log() will give you the generated SQL.</p>
8,460
<p>Our application exposes queries by way of web services, and what we've found is that our clients often want custom queries, either by way of further limiting the results returned by specifying additional criteria, or by asking for things that we don't already expose.</p> <p>Now, we can take the approach of creating...
<p>I would also recommend to consider the "Specification Pattern" in this type of applications as a design decision for your backend. Check the following posts about "Specification Pattern":</p> <p><a href="http://www.mattberther.com/2005/03/25/the-specification-pattern-a-primer/" rel="nofollow noreferrer">http://www....
<p>Since we really don't know which how your users use your interface it seems a little premature to give a technical advice on something that feels a lot closer to "<a href="http://books.google.se/books?id=04cFCVXC_AUC&amp;dq=Inmates+are+running+the+Asylum&amp;pg=PP1&amp;ots=jfvgZ3v_qK&amp;source=bn&amp;sig=i2Y92rSllN...
32,069
<p>Does any know a good rule of thumb for the appropriate pagefile size for a Windows 2003 server running SQL Server?</p>
<p>Irrelevant of the size of the RAM, you still need a pagefile at least 1.5 times the amount of physical RAM. This is true even if you have a 1 TB RAM machine, you'll need 1.5 TB pagefile on disk (sounds crazy, but is true).</p> <p>When a process asks MEM_COMMIT memory via VirtualAlloc/VirtualAllocEx, the requested s...
<p>If you're looking for high performance, you are going to want to avoid paging completely, so the page file size becomes less significant. Invest in as much RAM as feasible for the DB server.</p>
2,472
<p>Is there a good way to add a .swf programatically to a panel on an asp.net page - ie: I know i could just insert the html tags:</p> <p>ie: </p> <pre><code>&lt;object type="application/x-shockwave-flash" data="yourflash.swf" width="" height=""&gt; &lt;param name="movie" value="yourflash.swf"&gt; &lt;/object&gt; </c...
<p>The problem is having the groupbox as the controls' parent. Groupboxes are not supposed to have any children and using them as parents will cause all kinds of errors (including painting, keyboard navigation and message propagation). Just change the parent in the buttons' CreateWindow call from <strong>group_box</str...
<p>Ahh yes the black background with radio buttons and group boxes. Although I'm not sure if this will work for VC++ 2008, but back-in-the-day the solution for VB6 themed apps was to put the radio controls on a PictureBox (a generic container really) first and then add that to the group box.</p> <p>Its worth a shot!</...
26,372
<p>Someone please correct me if I'm wrong, but parsing a yyyy/MM/dd (or other specific formats) dates in C# <strong>should</strong> be as easy as </p> <pre><code>DateTime.ParseExact(theDate, "yyyy/MM/dd"); </code></pre> <p>but no, C# forces you to create an IFormatProvider.</p> <p>Is there an app.config friendly way...
<p>The IFormatProvider argument can be null.</p>
<p>//Convert date to MySql compatible format</p> <p>DateTime DateValue = Convert.ToDateTime(datetimepicker.text);</p> <p>string datevalue = DateValue.ToString("yyyy-MM-dd");</p>
9,023
<p>Currently i have this method:</p> <pre><code>static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return true; double multiplier = Math.pow(10, decimalPlaces); double check = d * multiplier; check = Math.round(check); check = check/multiplier; return (d==check...
<p>The test fails, because you have reached the accuracy of the binary floating point representation, which is approximately 16 digits with <a href="http://en.wikipedia.org/wiki/Double_precision" rel="nofollow noreferrer">IEEE754 double precision</a>. Multiplying by 649632196443.4279 by 10000 will truncate the binary r...
<p>I'm not sure that this is really doable in general. For example, how many decimal places does <code>1.0e-13</code> have? What if it resulted from some rounding error while doing arithmetic and really is just <code>0</code> in disguise? If on, the other hand you are asking if there are any non-zero digits in the f...
33,198
<p>How to take screenshot programmically of desktop area in Mac OS X ?</p>
<p>Two interesting options I have seen, but yet to use professionally, are the screencapture utility and a MacFuse demo.</p> <p>The screencapture utility has been around since 10.2, according to the man page, and could be linked to a Cocoa application by use of NSTask.</p> <p>The MacFuse demo worked by creating a new...
<p>If you consider REALbasic, this is extremely easy to do with RB and the MBS Plugins. I've just written an application that does timed screenshots using RB and the MBS Plugins. You can read about it here: <a href="http://tektalkin.blogspot.com/2008/08/screenaudit-for-mac-osx.html" rel="nofollow noreferrer">http://...
5,993
<p>On POSIX systems rename(2) provides for an atomic rename operation, including overwriting of the destination file if it exists and if permissions allow.</p> <p>Is there any way to get the same semantics on Windows? I know about MoveFileTransacted() on Vista and Server 2008, but I need this to support Win2k and up.<...
<p>Win32 does not guarantee atomic file meta data operations. I'd provide a citation, but there is none - that fact that there's no written or documented guarantee means as much.</p> <p>You're going to have to write your own routines to support this. It's unfortunate, but you can't expect win32 to provide this level...
<p>There is <a href="https://en.cppreference.com/w/cpp/io/c/rename" rel="nofollow noreferrer">std::rename</a> and starting with <a href="https://en.wikipedia.org/wiki/C%2B%2B17" rel="nofollow noreferrer">C++17</a> <a href="https://en.cppreference.com/w/cpp/filesystem/rename" rel="nofollow noreferrer">std::filesystem::r...
20,218
<p>We have a .NET application that uses WMI to gather a wide range of information on machines throughout a network, such as reading the Win32_NTLogEvent to see if Symantec Antivirus has written anything. The queries work fine, but after repeatedly running a WMI query "Generic Failure" errors will start coming back. T...
<p>I believe we have found the issue. To simplify some of our queries we were adding something like 1=1 in the where clause to ease the building of the query. Removed the constant=constant and the one query I was testing with went from 40 seconds to .4 seconds and has run over 10,000 times without generating a generi...
<p>Windows Remote Management (WinRM) may overcome all these problems. WinRM is the Microsoft implementation of WS-Management Protocol, a standard Simple Object Access Protocol (SOAP)-based.</p>
25,108
<p>I would like to buy a 3D printer, but I'm concerned about the health risks that are associated with its operation. Some groups of scientists say it can be <a href="http://www.techworld.com/news/personal-tech/scientists-warn-of-3d-printing-health-effects-as-tech-hits-high-street-3460992/">harmful</a> for humans.</p> ...
<p>There is very little information about safety available, as home 3D printers are relatively new. However, plastics such as ABS have a long history in making plastic products, and a study found that at traditional manufacturing methods (such as injection molding and hot wire cutting) <a href="http://annhyg.oxfordjour...
<p>Apart from the inherent process itself and direct health hazards from that, many 3D printers also require some complementary technology to work.</p> <p><a href="/questions/tagged/fdm" class="post-tag" title="show questions tagged &#39;fdm&#39;" rel="tag">fdm</a> printers have a printing head that needs to move arou...
83
<p>I want to get myself into programming some serious GUI based applications, but when I look at things like Swing/SWT from Java, I can't help but HATE programming a GUI interface by creating "widget" objects and populating them and calling methods on them. </p> <p>I think GUI design should be done in a separate text...
<p>You can try Mozilla's XUL. It supports Python via XPCOM.</p> <p>See this project: <a href="http://pyxpcomext.mozdev.org/no_wrap/tutorials/pyxulrunner/python_xulrunner_about.html" rel="noreferrer">pyxpcomext</a></p> <p>XUL isn't compiled, it is packaged and loaded at runtime. Firefox and many other great applicatio...
<p>It's XML, not Python, but look at <a href="http://www.openlaszlo.org/" rel="nofollow noreferrer">Open Laszlo</a></p>
47,565
<p>I am developing an application using the ASP.NET MVC platform, which will be exposed as a service over the web (the <a href="http://en.wikipedia.org/wiki/Software_as_a_Service" rel="nofollow noreferrer">SaaS</a> model). I am trying to determine the best way to partition the URL namespace for each user account. The...
<p>I would go with A. This solution is not very expensive, it scales well and it does not limit you to go with custom domains, if you decide this later on.</p> <p>Wildcard certificates used to be quite expensive, but today you could get them around 200 USD annually at <a href="http://www.godaddy.com/gdshop/ssl/ssl.asp...
<p>You're right Will, A and B are the same. However, I think that is true mainly from a coding perspective. With either option, the web server will determine the account based on the host name in the HTTP header. C is slightly different from a coding perspective because it would match the account based on the path u...
37,587
<p>This probably has a simple answer, but I must not have had enough coffee to figure it out on my own:</p> <p>If I had a comma delimited string such as:</p> <pre><code>string list = "Fred,Sam,Mike,Sarah"; </code></pre> <p>How would get each element and add quotes around it and stick it back in a string like this:</...
<pre><code>string s = "A,B,C"; string replaced = "'"+s.Replace(",", "','")+"'"; </code></pre> <p>Thanks for the comments, I had missed the external quotes.</p> <p>Of course.. if the source was an empty string, would you want the extra quotes around it or not ? And what if the input was a bunch of whitespaces... ? I m...
<p>The C# implementation of @<a href="https://stackoverflow.com/questions/254009/in-c-add-quotes-around-string-in-a-comma-delimited-list-of-strings#254026">PhiLho</a>'s JavaScript regular expression solution looks something like the following:</p> <pre><code>Regex regex = new Regex( @"\b", RegexOptions.ECMAScr...
31,671
<p>For my small wiki application, I mostly need to have the textarea used to edit the contents to use soft (or virtual) wrapping. However, in some cases, not wrapping the content would be preferable. I thought I would do this by simply having a button to turn off wrapping. Here is the simplified code:</p> <pre><code> ...
<p>See bug 41464: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=41464" rel="nofollow noreferrer">https://bugzilla.mozilla.org/show_bug.cgi?id=41464</a></p> <p>Nasty workaround for now is to replace the textarea with a clone of itself:</p> <pre><code>function setWrap(area, wrap) { if (area.wrap) { ...
<p>According to <a href="http://www.w3.org/TR/html4/interact/forms.html#edef-TEXTAREA" rel="nofollow noreferrer">the HTML 4.01 spec</a>, <code>wrap</code> isn't a valid attribute for <code>&lt;textarea&gt;</code>s which would explain why it's so difficult and strange. It looks as though Firefox actually does use the <c...
33,053
<p>OK, first let me state that I have never used this control and this is also my first attempt at using a web service.</p> <p>My dilemma is as follows. I need to query a database to get back a certain column and use that for my autocomplete. Obviously I don't want the query to run every time a user types another word...
<p>Why not keep track of the query executed by the user in a session variable, then use that to filter any further results?</p> <p>The trick to preventing the database from overloading I think is really to just limit how frequently the auto updater is allowed to update, something like once per 2 seconds seems reasonab...
<p>While caching everything is certainly a good idea, your question about which data structure to use is an issue that wasn't fully answered here. The best data structure for an autocomplete extender is a Trie. You can find a good .NET article and code <a href="http://metalthought.blogspot.com/2009/05/enhanced-performa...
16,495
<p>What's the best way to output the public contents of an object to a human-readable file? I'm looking for a way to do this that would not require me to know of all the members of the class, but rather use the compiler to tell me what members exist, and what their names are. There have to be macros or something like t...
<p>Take a look at <a href="http://s11n.net" rel="nofollow noreferrer">this library</a> .</p>
<p>There's unfortunately no macro that can do this for you. What you're looking for is a reflective type library. These can vary from fairly simple to home-rolled monstrosities that have no place in a work environment.</p> <p>There's no real simple way of doing this, and though you may be tempted to simply dump the me...
35,667
<p>I am trying to create a simple page that enters data in to a database and my code is below.</p> <pre><code>&lt;%@ LANGUAGE="VBSCRIPT" %&gt; &lt;% Option Explicit %&gt; &lt;!--#include FILE=dbcano.inc--&gt; &lt;% dim username,password,f_name,l_name,objConn,objs,query username = Request.Form("user") password = ...
<p><strong>User</strong> is a reserved word in SQL server. Put it into square brackets, e.g. <strong>[user]</strong>.</p>
<p>Try changing it to:</p> <pre><code>query = "INSERT INTO [user] (username,password,f_name,l_name) VALUES ('"&amp; username &amp;"','"&amp; password &amp;"','"&amp; f_name &amp;"','"&amp; l_name &amp;"')" </code></pre> <p>(escape the table name since it is a reserved word)</p> <p>Also, don't forget to validat...
46,616
<p>Is anyone using Elmah to send exceptions via email? I've got Elmah logging set up via SQL Server, and can view the errors page via the Elmah.axd page, but I am unable to get the email component working. The idea here is to get the email notification so we can react more quickly to exceptions. Here is my web.config (...
<p>You need the ErrorMail httpModule.</p> <p>add this line inside the &lt;httpModules&gt; section</p> <pre><code>&lt;add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /&gt; </code></pre> <p>If you're using a remote SMTP server (which it looks like you are) you don't need SMTP on the server.</p>
<p>I have used Elmah myself in this configuration and I had to setup the server with SMTP locally. It is a straight-forward install on you local IIS server. This should do the trick.</p> <p>Good point above, you need the errorMail module BUT if you are not using a remote SMTP server you need SMTP locally, just to cl...
5,464
<p>If I have a script tag like this:</p> <pre><code>&lt;script id = "myscript" src = "http://www.example.com/script.js" type = "text/javascript"&gt; &lt;/script&gt; </code></pre> <p>I would like to get the content of the "script.js" file. I'm thinking about something like <code>document.getElementById("my...
<p>Do you want to get the contents of the file <a href="http://www.example.com/script.js" rel="nofollow noreferrer">http://www.example.com/script.js</a>? If so, you could turn to AJAX methods to fetch its content, assuming it resides on the same server as the page itself.</p>
<p>Not sure why you would need to do this?</p> <p>Another way round would be to hold the script in a hidden element somewhere and use Eval to run it. You could then query the objects innerHtml property.</p>
17,886
<p>I have a interface that defines some methods with attributes. These attributes need to be accessed from the calling method, but the method I have does not pull the attributes from the interface. What am I missing?</p> <pre><code>public class SomeClass: ISomeInterface { MyAttribute GetAttribute() { ...
<p>The methodBase will be the method on the class, not the interface. You will need to look for the same method on the interface. In C# this is a little simpler (since it must be like-named), but you would need to consider things like explicit implementation. If you have VB code it will be trickier, since VB method "Fo...
<p>While I will first confess that I have never tried to attach attributes to Interfaces but would something like the following work for you?</p> <pre><code>public abstract class SomeBaseClass: ISomeInterface { [MyAttribute] abstract void MyTestMethod(); } public SomeClass : SomeBaseClass{ MyAttribute ...
31,371
<p>Is there a limitation in the length of a query that SQL Server can handle?</p> <p>I have a normal SqlCommand object and pass a very long select statement as a string. </p> <p>The query seems to be fine when running against an SQL Server 2005/2008 engine but doesn't execute against an SQL Server 2000 engine. </p> ...
<p>SqlServer 2000 has a 4000 character query limit for adhoc queries.</p> <p>Can you abstract this into a stored procedure?</p>
<p>Do not to do this because of sql injections. Abandon this if the app's dynamic sql can be manipulated at all by the user.</p> <p>also - consider SP's since its easier to maintain and it also helps with sql injection.</p>
43,574
<p>I am looking for a simple unpatented one-way encryption algorithm, preferably in c. I would like to use it to validate passwords.</p>
<p><a href="http://en.wikipedia.org/wiki/SHA-1" rel="nofollow noreferrer">SHA-1 and the rest of its family</a> were patented by the US government which "has released the patent under a royalty free license". Many public-domain implementations <a href="http://www.google.ca/search?q=sha+c+implementation" rel="nofollow n...
<p>MD5 has suited me fine so far.</p>
9,497
<p>I have a query that ran fine on SQL2005 but moving the database to SQL2008 gives me the error from the title.</p> <p>The code that is the problem is a call to CONTAINS, CONTAINSTABLE or FREETEXT with an empty parameter. However I'm trying to only call or join when there is a value like such</p> <pre><code>where (@...
<p>I found the answer to this today when converting my own database from SQL 2005 to SQL 2008.</p> <p>Pass <code>""</code> for your search term and change the @search_term = <code>''</code> test to be <code>@search_term = '""'</code> SQL server will ignore the double quotes and not throw an error.</p> <p>For example,...
<p>I found that using &quot;a&quot; as the default works if SQL-Server is <a href="https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/transform-noise-words-server-configuration-option?view=sql-server-ver15" rel="nofollow noreferrer">configured to ignore &quot;noise words&quot;.</a></p> <pre><code>S...
23,019
<p>On a particular project we're working with a total of 10 team members. </p> <p>After about a year working on the project (and using Mantis as a bug-/feature-tracker eversince), the bugtracker gets more and more difficult to use, as no standard has been setup that explains how to create new tasks, how to comment tas...
<p>Always link a version control system commit to an issue and back so that you know which commits were made do solve which issue and why a certain commit was done.</p>
<p>What we did is to introduce a role for approve entries to the bug tracker. This role can be shared by different people. The process is either to approve, to approve with a small edit, or to reject the entry with the request for further editing or clarification.</p> <p>It is better for the general understanding if t...
16,122
<p>I am using this code to verify a behavior of a method I am testing:</p> <pre><code> _repository.Expect(f =&gt; f.FindAll(t =&gt; t.STATUS_CD == "A")) .Returns(new List&lt;JSOFile&gt;()) .AtMostOnce() .Verifiable(); </code></pre> <p>_repository is defined as:</p> <pre><code>private Mock&lt;IReposito...
<p>This is a bit of a cheaty way. I do a .ToString() on the expressions and compare them. This means you have to write the lambda the same way in the class under test. If you wanted, you could do some parsing at this point</p> <pre><code> [Test] public void MoqTests() { var mockedRepo = new Mock&lt;...
<p>In Rhino Mocks you would do something like this...</p> <p>Instead of using an Expect, use a Stub and Ignore the arguments. Then have --</p> <pre><code>Func&lt;JSOFile, bool&gt; _myDelegate; _repository.Stub(f =&gt; FindAll(null)).IgnoreArguments() .Do( (Func&lt;Func&lt;JSOFile, bool&gt;, IEnumerable&lt;JSOFil...
36,714
<p>So I'm about to start of a small project for my sporting club for member registrations and I'm trying to decide between WebForms or MVC.</p> <p>Allit will be is a user login and data capture forms (or and data retrieval), so I was initally thinking WebForms with FBA but I've wanted to have a play with MVC for a whi...
<p>Is this a critical, production level application or a small one-off? Can you deal with the extra time that the learning curve of MVC will take or do you need to have it done right-away? Can you afford to scrap the whole thing and start over if MVC doesn't work out? Are you willing to have the platform change (pro...
<p>Based on your comments to tvanfosson, it sounds like MVC would be a good choice for you as you listed your desire to learn as a reason to choose that technology. I doubt MVC will change <em>drastically</em> from its beta. So, this could be a good opportunity to learn a new tool. As for as WebForms being the "quick a...
42,559
<p>I have a string that contains both double-quotes and backslashes that I want to set to a variable in Python. However, whenever I try to set it, the quotes or slashes are either removed or escaped. Here's an example:</p> <pre><code>&gt;&gt;&gt; foo = 'baz "\"' &gt;&gt;&gt; foo 'baz ""' </code></pre> <p>So instead o...
<p>You're being mislead by output -- the second approach you're taking actually does what you want, you just aren't believing it. :)</p> <pre><code>&gt;&gt;&gt; foo = 'baz &quot;\\&quot;' &gt;&gt;&gt; foo 'baz &quot;\\&quot;' &gt;&gt;&gt; print(foo) baz &quot;\&quot; </code></pre> <p>Incidentally, there's another strin...
<p>Another way to end a string with a backslash is to end the string with a backslash followed by a space, and then call the <code>.strip()</code> function on the string. </p> <p>I was trying to concatenate two string variables and have them separated by a backslash, so i used the following:</p> <pre><code>newString...
38,606
<p>We have a PageRoles xml file which contains the page path and the user role that can access that page.</p> <p>We are maintaining a Dictionary in a static class, which gets loaded int static constructor for the class. The class has a method CheckIfRoleAllowed that takes in a page path and returns a bool.</p> <p>Eac...
<p>You do use a singleton. Simply, there are 2 usual implementations for singletons, the other being instantiating the class and having a static member referencing this instance.</p> <p>Your implementation makes calls simpler IMO :</p> <pre><code>PageAccessChecker.CheckIfRoleAllowed(path); </code></pre> <p>instead o...
<p>If you keep the class constructor private, there's no real difference - they are both global variables that can be lazily initialized.</p> <p>If you keep the class constructor public or protected and only use the pattern to create a global (not to enforce a single instance), you can at least test your singleton cla...
43,192
<p>Please give me some insight on how to get the best start on applying Aspect Oriented Programming to my C#.net applications?</p>
<p>PostSharp has the added advantage that it does it's AOP by doing IL weaving. In fact it adds code to the Il when/or just after compiling. Which makes the builds slower but it should be faster at runtime.</p> <p>Some other do this at runtime (the castle project and I think it's windsor in there that does the AOP) wh...
<p>I recommend trying <a href="http://www.springframework.net/" rel="nofollow noreferrer">Spring.NET</a>. It lets you create "Interceptor" classes that can be wrapped around calls into business objects simply by adding entries into the application's config file.</p> <p>We've used it to do connection/transaction handli...
31,039
<p>I've got a direct drive extruder printer, that I have equipped with a Bowden-tube to give it a nice and defined filament path from my spool and to protect it from moisture when it exits my drybox. I've noticed that this 1 m Bowden tube adds quite a bit of friction to the system. I am keenly aware of it as feeding fi...
<p>A Bowden tube is by design fairly small diameter to match the filament within, constraining the forces applied by the remote extruder mechanism. As you've noted, friction is a consideration.</p> <p>For your application, you would not have to have such a tightly constrained diameter. You could use a Bowden tube for 2...
<p>I have a similar setup with one of my printers (that is using 1.75 mm filament), this answer is therefore my own experience with guiding tubes from spool to extruder (my previous was a direct drive extruder, the latter uses a Bowden setup, but both with a tube leading up to the extruder).</p> <p>Initially I used sma...
1,741
<p>I'd like to play mp3 files (b/c they compress smaller than .wav's) from a vb6 app but without needing any other player installed.</p> <p>Any suggestions?</p>
<p>The easiest way to play an MP3 in VB6 is using the MCI in windowsmultimedia (winmm) functions. These are available in all versions of windows that can play MP3s in windows media player (by default in 2000, XP and I believe 98, needed to install Windows media player for NT4 and 95). Add the following to your header...
<p>Add reference to ActiveMovie control type library and use <a href="http://msdn.microsoft.com/en-us/library/ms787569(VS.85).aspx" rel="nofollow noreferrer">FilgraphManager.RenderFile</a>. Take a look at <a href="http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=37779&amp;lngWId=1" rel="nofollow nore...
49,837
<p>I'm using SQL Server 2005, and I would like to know how to access different result sets from within transact-sql. The following stored procedure returns two result sets, how do I access them from, for example, another stored procedure?</p> <pre><code>CREATE PROCEDURE getOrder (@orderId as numeric) AS BEGIN s...
<p>The short answer is: you can't do it.</p> <p>From T-SQL there is no way to access multiple results of a nested stored procedure call, without changing the stored procedure as others have suggested.</p> <p>To be complete, if the procedure were returning a single result, you could insert it into a temp table or tabl...
<p>You could select them into temp tables or write table valued functions to return result sets. Are asking how to iterate through the result sets?</p>
8,341
<p>Let's say I checked in a changelist (in Perforce) with lots of files and I'd like to revert the entire changelist. Is there an easy way to "revert" the entire changelist in one fell swoop?</p> <p>Currently I do something like this for each file in the changelist:</p> <ul> <li>p4 sync //path/to/file#n (where "n" i...
<p>The posted answers provide correct answers, but note also that there is an actual menu option in P4V to do this for you now. It's in the latest 2008.2 Beta, and so should be officially released the the next week or three.</p> <p>This <a href="http://www.perforce.com/perforce/downloads/beta/index.html" rel="noreferr...
<p>I have the same problem when I want to delete an entire changelist. so I use the following script (notice that it also deletes the changelist's shelve and the changelist itself. if you only want to revert, copy the relevant lines). Also, make sure the sed applies to your version of p4.</p> <pre><code>#!/bin/bash s...
42,985
<p>I have 2 databases, and <strong>I want to transport an existing table containing a CHAR column from database A to database B.</strong></p> <p>Database A is Oracle 9i, has encoding WE8ISO8859P1, and contains a table "foo" with at least 1 column of type CHAR(1 char). I can not change the table on database A because ...
<p>This problem is caused by the way Oracle (mis)handles character conversions between different character sets based on the original column length definition. When you define the size of a character type column in bytes, Oracle does not know how to do a conversion and bodges it. <strong>The solution is to always defin...
<p>The first thing I would try is Creating the table NOT as a CTAS but with a list of column definitions and try to perform an insert of the first few thousand rows. If that didn't succeed then it would be very clear why... and you'd have quick confirmation that Thomas Low is dead on accurate.</p>
31,665
<p>Java and C# support the notion of classes that can't be used as base classes with the <code>final</code> and <code>sealed</code> keywords. In C++ however there is no good way to prevent a class from being derived from which leaves the class's author with a dilemma, should every class have a virtual destructor or no...
<p>Every abstract class should either have a,</p> <ul> <li>protected destructor, or,</li> <li>virtual destructor.</li> </ul> <p>If you've got a public non-virtual destructor, that's no good, since it allows users to delete through that pointer a derived object. Since as we all know, that's undefined behavior. </p> <...
<p>I'll add that there have been times when I have scratched my head for a while on destructors not getting called when I forgot a virtual in the parent or child class. I guess I know to look for that now though. :)</p> <p>Someone might argue that there are times the parent class does something in its destructor that ...
46,091
<p>Applications like CCTray allow one to specify a sound clip to indicate that a build is successful or that a build failed. I'm interested to hear what set of sounds different teams are using.</p> <p>Here are two sets that we use:</p> <ul> <li>Homer Simpson: "d'oh" for a build failure, "woohoo!" for success</li> <li...
<p>South Park:</p> <ul> <li>"Oh my God, they've killed Kenny!" for a build failure.</li> <li>"Kickass!" (Cartman) for a success.</li> </ul>
<p>In earlier versions of the Microsoft C/C++ compilers, I've used sounds from the pinball game that came with Windows XP and the Windows 95 Plus! pack. I used sounds that the game used for successful actions for successful build events; and I used sounds that the game used for failure events (like losing the ball) I u...
41,443
<p>If you launch Emacs using the <code>-nw</code> flag to force a console session (rather than an X session if you have X windows running), how do you get to the menu?</p> <p>There are some items held in the menus that are infrequently-enough used on my part that I don't recall the escape or control sequence to do them...
<p><code>M-x menu-bar-open</code>, which is usually bound to <code>F10</code>. This works with and without <code>menu-bar-mode</code> (which just shows the names of the menus at the top of the screen).</p>
<pre><code>M-x menu-bar-mode </code></pre>
23,230
<p>I'm using C# and connecting to a WebService via an auto-generated C# proxy object. The method I'm calling can be long running, and sometimes times out. I get different errors back, sometimes I get a <code>System.Net.WebException</code> or a <code>System.Web.Services.Protocols.SoapException</code>. These exceptions h...
<p>This is happening because there is an unhandled exception in your Web service, and the .NET runtime is spitting out its HTML yellow screen of death server error/exception dump page, instead of XML.</p> <p>Since the consumer of your Web service was expecting a text/xml header and instead got text/html, it throws tha...
<p>The problem I had was related to SOAP version. The <code>asmx</code> service was configured to accept both versions, 1.1 and 1.2, so, I think that when you are consuming the service, the client or the server doesn't know what version resolve.</p> <p>To fix that, is necessary add:</p> <pre><code>using (wsWebService...
14,062
<p>Which MVC-framework is the best option (performance/ease of development) for a web application, that will have + 2 million visits per week.</p> <p>Basically the site is a search engine,but also there will be large amounts of XML parsing, and high db traffic.</p> <p>We are using Java, over Jboss 4.2.3x, with PG as ...
<p>Give all of your <code>#fade</code>X elements a class (say .faders) and then use:</p> <pre><code>$('.faders').stop(); </code></pre> <p>Or give the container div an id like <code>#faderbox</code> and say:</p> <pre><code>$('#faderbox div').stop(); </code></pre>
<p>I'm not sure exactly what you want to happen with regards to your fadeIn and fadeOut effects in your fadeEngine, however, I can give you two pieces of advice:</p> <p>You can use the jQuery effect <code>stop()</code> to stop all current jQuery animations on selected elements. For example:</p> <pre><code>$("#fade"+...
49,455
<p>Not sure if this is possible or if I'm expressing correctly what I'm looking for, but I have the following piece of code in my library repeatedly and would like to practice some DRY. I have set of SQL Server tables that I'm querying based on a simple user-supplied search field ala Google. I'm using LINQ to compose ...
<p>It sounds like you're looking for Dynamic Linq. Take a look <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" rel="noreferrer">here</a>. This allows you to pass strings as arguments to the query methods, like:</p> <pre><code>var query = dataSou...
<p>I recently had to do this same thing. You will need <a href="http://talesfromthebleedingedge.blogspot.com/2008/10/linq-to-entities-dynamic-linq-to.html" rel="nofollow noreferrer">Dynamic Linq</a> <a href="http://talesfromthebleedingedge.blogspot.com/2008/10/linq-to-entities-dynamic-linq-to.html" rel="nofollow norefe...
15,243
<p>I am working on a Sharepoint Server 2007 State machine Workflow. Until now I have a few states and a custom Association/InitiationForm which I created with InfoPath 2007. In Addition I have a few modification forms. I have a Problem with the removing of the modification link in the state-page of my workflow. </p> <...
<p>You can automate the process of closing all the files prior to closing a solution by adding a handler for the BeforeClosing event of EnvDTE.SolutionEvents -- this will get invoked when VS is exiting.</p> <p>In VS2005, adding the following to the EnvironmentEvents macro module will close all open documents:</p> <pr...
<p>I dont think there is an option for this (or I couldnt find one) but you could probably write a macro to do this for you on project open. </p> <p>This link has some code to close open files which you could adapt: <a href="http://blogs.msdn.com/djpark/" rel="nofollow noreferrer">http://blogs.msdn.com/djpark/</a></p>...
17,851
<p>Is there a library/software which can accept a number of keypoints and matches of them between images and produce a morph? Or any ideas/algorithms on how to do it?</p>
<p><a href="http://xmorph.sourceforge.net/" rel="nofollow noreferrer">Xmorph and GTK morph</a> can do that -- although the key points must be parts of equivalent rectangle grids. The underlying algorithm can be accessed through a C API.</p>
<p>An older piece of software by <a href="http://en.wikipedia.org/wiki/Gryphon_Software_Morph" rel="nofollow noreferrer">Gryphon Software</a> could do image morphing. I saw an article about it from 1994. I couldn't find a company site, so they may be abandon ware now.</p> <p>Her is a quote from a Wikipedia article abo...
19,892
<p>The LCD resin printers I've looked at have pretty standard resolutions like for a smartphone and I understand they use the same technology. However, color LCD screens have three RGB sub-pixels for each color pixel. Check for example this magnified picture of an S-IPS LCD screen: <a href="https://i.stack.imgur.com/bm...
<p>If what Thomas Sanladerer states is correct, the Mars 2 Pro (monochrome LCD, no color filter) has a layer time approximately 1/3 as long as the Mars/Pro printers (where color LCDs are used):</p> <p><div class="youtube-embed"><div> <iframe width="640px" height="395px" src="https://www.youtube.com/emb...
<p>It should be as simple as using a monochrome LCD. You don't actually want any color filters to interfere with the UV light.</p> <p>Do we know that LCD printers are not using monochrome LCD panels? It always seemed so obvious that I assumed it was the practice. All you need are the front and back polarizer layer ...
1,420
<p>Is there a secure way of logging into a Gmail account on a web browser, from an external Java program? I know the following works, but is there a safer alternative?</p> <pre><code>Desktop.getDesktop().browse(new URI( "https://www.google.com/accounts/ServiceLoginAuth?continue=http://mail.google.com/gmail" + ...
<p>Depending of how much you want to integrate, you can check Google single sign-on (SSO) api. I'm studing how to use it and the best way to integrate it</p> <p><a href="http://code.google.com/apis/apps/sso/saml_reference_implementation.html" rel="nofollow noreferrer">http://code.google.com/apis/apps/sso/saml_referenc...
<p>I used google's IMAP access with the JavaMail API, and it was very simple.</p>
13,725
<p>How do I create an rss feed in ASP.Net? Is there anything built in to support it? If not, what third-party tools are available?</p> <p>I'm thinking webforms, not MVC, though I suppose since this isn't a traditional page the difference may be minimal.</p>
<p>For built-in, there's nothing stopping you from using XmlDocument or XDocument (3.5) to build up the required XML for RSS. It's more work than it's worth though.</p> <p>I use the <a href="http://www.codeplex.com/Argotic" rel="nofollow noreferrer">Argotic Syndication Framework</a> and serve the feeds through Generic...
<p>Create an HTTP Handler to create a RSS feed</p>
8,149
<p>Has anyone been able to implement the JQuery grid plugin, jqGrid? I'm trying to implement the JSON paging, and I feel like I'm getting close, but that I am also being swamped by inconsequential details. If anyone could post some sample code, I would greatly appreciate it.</p>
<p>Found your post while I was trying to do this for my project. I got it working. For anyone who needs it in the future, jqGrid won't work out of the box with JSON and ASP.NET. You need to make a couple of small modifications to grid.base.js. Around line 829, replace the json case section with the following:</p> <pre...
<p>I'm just floundering trying to pull everything together. My first concern is simply generating a correct JSON response. My returned class appears to be serialised as a property named 'd' - is this a JQuery thing, or ASP.Net web method convention? I'm afraid that jqGrid will be looking for the data to be top-level, w...
21,840
<p>The company has the traditional complex organizational structure, defining the amount of levels using the letter 'n' rather than an actual number. I will try and express the structure I'm trying to achieve in mono-spaced font: </p> <pre><code> Alice ,--------|-------,------,------, Bob Fred Jack ...
<p>Josh Smith has a excecllent CodeProject article about TreeView. Read it <a href="http://www.codeproject.com/KB/WPF/AdvancedCustomTreeViewLyt.aspx" rel="nofollow noreferrer">here</a></p>
<p>I did end up using tips from the linked article, which I'd already read through but didn't think would help me. </p> <p>The meat of it happens here, in a converter: </p> <pre><code>&lt;ValueConversion(GetType(ItemsPresenter), GetType(Orientation))&gt; _ Public Class ItemsPanelOrientationConverter Implements IVal...
9,536
<p>Scott Gu just posted about a new set of charting controls being distributed by the .NET team. They look incredible: <a href="http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx" rel="noreferrer">http://weblogs.asp.net/scottgu/archive/2008/11/24/n...
<p>You can use the chart controls in two ways:</p> <p><strong>Generating the Image from a Controller</strong></p> <p>By generating the chart and returning it as an image from an action (as Chatuman is referring to I think):</p> <pre><code>Chart chart = new Chart(); chart.BackColor = Color.Transparent; chart.Width = ...
<p>I have been testing with MVC and so far it looks like it is working with MVC.</p>
41,360
<p>I have a query in which I am pulling the runtime of an executable. The database contains its start time and its end time. I would like to get the total time for the run. So far I have:</p> <pre><code>SELECT startTime, endTime, cast(datediff(hh,starttime,endtime) as varchar) +':' +cast(datediff(mi,starttime,endtime)...
<p>Try these</p> <p>Assuming 2 declared dates.</p> <pre><code>declare @start datetime set @start = '2008-11-02 15:59:59.790' declare @end datetime set @end = '2008-11-02 19:05:41.857' </code></pre> <p>This will return the hours / mins / seconds</p> <pre><code>select (datediff(ss, @start, @end) / 3600), (...
<p>You should separate your calculation and presentation logic:</p> <pre><code>DECLARE @applog TABLE ( runID int, starttime datetime, endtime datetime ) INSERT INTO @applog (runID, starttime, endtime) SELECT 33871, '2008-11-02 15:59:59.790', '2008-11-02 19:05:41.857' ------------------- SELECT SUBSTRING(conve...
32,516
<p>What's the performance penalty on defining classes in an aspx/ascx codebehind rather than compiling them into a dll beforehand? I know that this isn't a best practice and that there are numerous problems with this (e.g. difficult to unit test, code is not reusable, etc.), but it does come in very handy when you're ...
<p>"None." The codebehind classes are compiled into a DLL on the fly, and then that DLL is kept around. So basically the first time you load the page there will be a short delay, but afterwards the speed should be the same as with precompiled classes.</p>
<p>I don't believe there really is a performance penalty after the initial dynamic compilation (which will occur on the first hit to the page whose code-behind was modified). How did you end up having to change classes several times a day? That would suck!</p> <p><strong>EDIT:</strong> I should've added that this shou...
15,890
<p>What is the best way (in C++) to set up a container allowing for double-indexing? Specifically, I have a list of objects, each indexed by a key (possibly multiple per key). This implies a multimap. The problem with this, however, is that it means a possibly worse-than-linear lookup to find the location of an object....
<p>I'm making several assumptions based on your writeup:</p> <ul> <li>Keys are cheap to copy and compare</li> <li>There should be only one copy of the object in the system</li> <li>The same key may refer to many objects, but only one object corresponds to a given key (one-to-many)</li> <li>You want to be able to effic...
<p>Its difficult to understand what exactly you are doing with it, but it seems like boost <a href="http://www.boost.org/doc/libs/1_36_0/libs/bimap/doc/html/index.html" rel="nofollow noreferrer">bimap</a> is what you want. It's basically boost multi-index except a specific use case, and easier to use. It allows fast lo...
12,035
<p>The glorified global variable - becomes a gloried global class. Some say breaking object-oriented design.</p> <p>Give me scenarios, other than the good old logger where it makes sense to use the singleton.</p>
<p>On my quest for the truth I discovered that there are actually very few &quot;acceptable&quot; reasons to use a Singleton.</p> <p>One reason that tends to come up over and over again on the internets is that of a &quot;logging&quot; class (which you mentioned). In this case, a Singleton can be used instead of a sing...
<p>An example with code, perhaps.</p> <p>Here, the ConcreteRegistry is a singleton in a poker game that allows the behaviours all the way up the package tree access the few, core interfaces of the game (i.e., the facades for the model, view, controller, environment, etc.):</p> <p><a href="http://www.edmundkirwan.com/...
28,237
<p>I need a tool to automatically convert simple HTML into an image. I will be controlling the HTML input which will consist of simple text formatting tags and possibly image links--I don't need to be able to render arbitrary HTML. Is there a simple way to do this? </p> <p>I've looked at the HTML layout engines like G...
<p>Answering, my own question I found this useful tool which uses WebKit to render a page and then captures the output as an image or even in PDF format! </p> <p><a href="http://cutycapt.sourceforge.net/" rel="noreferrer">http://cutycapt.sourceforge.net/</a></p> <p>The idea is similar to khtml2png mentioned by Jay, b...
<p>Perhaps you can convert the HTML to another format which is more readily convertable to an image? In Google I found something called html2ps and html2pdf. From PS it's just one step away to EPS, and that can be rendered as an image already. Or something like that.</p>
44,429
<p>We are looking at various options in porting our persistence layer from Oracle to another database and one that we are looking at is MS SQL. However we use Oracle sequences throughout the code and because of this it seems moving will be a headache. I understand about @identity but that would be a massive overhaul of...
<p>That depends on your current use of sequences in Oracle. Typically a sequence is read in the Insert trigger.</p> <p>From your question I guess that it is the persistence layer that generates the sequence before inserting into the database (including the new pk)</p> <p>In MSSQL, you can combine SQL statements with ...
<p>If you have a lot of code, you're going to want to do a massive overhaul of the code anyway; what works well in Oracle is not always going to work well in MSSQL. If you have a lot of cursors, for instance, while you could convert them line for line to MSSQL, you're not going to get good performance. </p> <p>In shor...
41,979
<p>I'm an experienced programmer but just starting out with Flash/Actionscript. I'm working on a project that for certain reasons requires me to use Actionscript 2 rather than 3.</p> <p>When I run the following (I just put it in frame one of a new flash project), the output is a 3 rather than a 1 ? I need it to be a 1...
<p>Unfortunately, AS2 is not that kind of language; it doesn't have that kind of closure. Functions aren't exactly first-class citizens in AS2, and one of the results of that is that a function doesn't retain its own scope, it has to be associated with some scope when it's called (usually the same scope where the funct...
<p>Unfortunately Actionscript 2.0 does not have a strong scope... especially on the time line.</p> <pre><code>var fs:Array = new Array(); for (var i = 0; i &lt; 3; i++){ var ii = i + 1; fs[i] = function(){ trace(ii); } } fs[0](); trace("out of scope: " + ii + "... but still works"); </code>...
17,185
<p>I have a RVDS project for a certain video decoder (its all C code), created for ARM926EJ-S target, executed using the RVDS 2.2 simulator. I am not using any scatterload / &lt;configuration file> / &lt;map file> to mention the various memory segments in the code like Stack segment, Heap, Data segment, Code Segment fo...
<p>Define the constructor for A AFTER the definition of struct B.</p>
<p>Interestingly, I've bumped into the same problem with the page 293 ('11.12 A String Class') mentioned in the Stroustrup book.</p> <p>The example provided in the printed book seems to be at fault, providing the following methods as inline, instead of defining them after the definition of struct Srep</p> <pre><code>...
40,013
<p>I receive some arguments into a stored procedure. These arguments are NVARCHAR's.</p> <p>I have a problem, when I need to cast some of these values to FLOATS, because they are being received as e.g.</p> <p>@VALUE1 NVARCHAR(100)</p> <p>DECLARE @ChangedValue SET @ChangedValue = CAST(@Value1 AS FLOAT)</p> <p>E.g. @...
<p>You could use <code>@VALUE1 = REPLACE(@VALUE1, ',', '.')</code></p> <p>This does seem a horrible thing to do though!</p>
<p>As Mitch said it does not sound that good and it would be much better it the provided parameter was of type float in first place. He gave you the solution that solves your problem for now but as he pointed out you may get into some trouble in the future.</p> <p>I assume that the procedure is called by some applicat...
39,183
<p>I'm just getting started/familar with Subversion and was wondering which protocol gives the best performance file:// or svn://, when accessing a Subversion repository over the network? If we don't use the svn:// protocol, will be missing out on any features that we couldn't mitgate using the file:// protocol? We'r...
<p>The SVN Book recommends that you <i>do not</i> use the file:// protocol for multiple users</p> <p><a href="http://svnbook.red-bean.com/en/1.8/svn.serverconfig.choosing.html" rel="nofollow noreferrer">Choosing a Server Configuration</a>:</p> <blockquote> <p>Do not be seduced by the simple idea of having all of yo...
<p>As Paul de Vrieze states the protocol used by SVN is not going to impact performance as much as other factors. If you are on a small local area network then the SVN protocol may be satisfactory for you. In all other cases it seems to be best to use HTTPs:// with Apache. I've been on LANs where the performance of SVN...
48,700
<p>I was just about to start using my 3D printers heated bed to warm a chemical reaction in a container and was thinking it would be great to be able to get the bed stepping back and forth to stir the pot. Can anyone already up to speed in programming G-code walk me through a quick and dirty way to get the X-axis on my...
<p>Basically you need to write a G-code file yourself. This is a plain text file with a <code>.g</code> extension.</p> <p>You need to home the printer with <code>G28</code>, then move the Y axis all the way forward (for a Prusa style printer) with <code>G1 F1500 Y{ymax}</code> (where <code>{ymax}</code> is the length ...
<p>Never mind, figured the quickest dirtiest way myself - created a tall thin cylinder shape model in Blender and positioned it in Repetier so the printer head will be clear of the table as it moves. Then just broke off the filament that was currently in the printer so it will stop feeding once the current piece gets t...
1,647
<p>I am using a 3rd party API which is defined in 2 DLLs. I have included those DLLs in my project and set references to them. So far so good. </p> <p>However, these DLLs have at least one dependent DLL which cannot be found at runtime. I copied the missing DLL into the project and set the 'Copy to output' flag but wi...
<p>It sounds like you need to better understand the third-party library and how it uses its own dependencies. If the installation of the API solves the problem, but copying the files manually does not, then you're missing something. There's either a missing file, or some environment variable or registry entry that's ...
<p>How are you deploying? Just flat files? If so, it should work as long as the file ends up in the project output directory. Does it?</p> <p>If you are using another deployment, you will need to tell that engine to include it. This is different for each of msi/ClickOnce/etc.</p>
29,691
<p>I have a Java app running on Tomcat, and I would like to monitor counters using Windows Performance Monitor. Is this possible using a JMX adapter for the Java MBeans or by some other means?</p>
<p>Since you tagged this with JMX and MBeans, I assume your counters are accessible from a Java MBean. If so you could use jconsole, provided with the Java SDK, to monitor the counters. Once you find your MBean in the MBeans tab, double click on the value and it will draw a nice line graph for easy monitoring.</p> <p>...
<p>This seems to be exactly what you're looking for, but it's not free: <a href="http://www.adventnet.com/products/snmpadaptor/faqs/general.html" rel="nofollow noreferrer">http://www.adventnet.com/products/snmpadaptor/faqs/general.html</a></p>
46,699
<p>Can someone show me how to fix the width of a column in a datatable with JSF?</p> <p>My code currently reads:</p> <pre><code>&lt;h:column&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Data Field 1" /&gt; &lt;/f:facet&gt; &lt;h:commandLink id="dataLink" action="#{pc_SearchResultsFrag...
<p>Well usually you use h:column in a dataTable context.</p> <p>What you could do is set the width in CSS. If you have the code:</p> <pre><code>&lt;h:dataTable value="#{action.items}" var="name" styleClass="tableClass" columnClasses="first,second"&gt; </code></pre> <p>And in the CSS file you do:</p> <pre><code>.fi...
<pre><code>&lt;h:column&gt; &lt;f:facet name="header"&gt; &lt;h:outputText value="Data Field 1" /&gt; &lt;/f:facet&gt; &lt;h:commandLink id="dataLink" action="#{pc_SearchResultsFragment.setField1}"&gt; &lt;h:outputText value="#{(qi.data1 != null) ? '' : qi.data1}"/&gt; ...
42,293
<p>Is there a way in C# or .NET in general to create an attribute on a method which triggers an event when the method is invoked? Ideally, I would be able to run custom actions before and after the invocation of the method.</p> <p>I mean something like this:</p> <pre><code>[TriggersMyCustomAction()] public void DoSom...
<p>The only way I know how to do this is with <a href="https://www.postsharp.net/" rel="noreferrer">PostSharp</a>. It post-processes your IL and can do things like what you asked for.</p>
<p>I don't think there is a way to do it with just an attribute, but using <a href="http://www.codeproject.com/KB/cs/dynamicproxy.aspx" rel="nofollow noreferrer">proxy classes</a> and reflection you could have a class that knows to intercept instantiations of the classes in which you have attributed methods. </p> <p>...
27,997
<p>I've created a simple httpModule, registered it on GAC and added it to the global web.config.</p> <p>I've made some changes to the module, updated the version and changed it also on the web.config.</p> <p>What happens is that i keep getting the old version. I've restarted the computer, removed it from the GAC, del...
<p>Is it possible you have an older version lying around in your bin folder? Another alternative is that some other code is comipled against the older version. If all else fails you can use <a href="http://nayyeri.net/blog/redirect-assembly-versions-using-bindingredirect-element/" rel="nofollow noreferrer">bindingRedir...
<p>Is it possible you have an older version lying around in your bin folder? Another alternative is that some other code is comipled against the older version. If all else fails you can use <a href="http://nayyeri.net/blog/redirect-assembly-versions-using-bindingredirect-element/" rel="nofollow noreferrer">bindingRedir...
34,226
<p>I'm wondering, and in need, of strategies that can be applied to reducing low-level locking. However the catch here is that this is not new code (with tens of thousands of lines of C++ code) for a server application, so I can't just rewrite the whole thing.</p> <p>I fear there might not be a solution to this proble...
<p>Why do you need to eliminate the low-level locking? Do you have deadlock issues? Do you have performance problems? Or scaling issues? Are the locks generally contended or uncontended?</p> <p>What environment are you using? The answers in C++ will be different to the ones in Java, for example. E.g. uncontended synch...
<p>You may find some of the answers <a href="https://stackoverflow.com/questions/92455/how-can-i-write-a-lock-free-structure">here</a> and <a href="https://stackoverflow.com/questions/120937/what-is-test-and-set-used-for#120976">here</a> helpful as you look for ways to atomically update shared state without explicit lo...
15,291
<p>I've been quite used to working on small projects which I coded with 1,000 lines or less (pong, tetris, simple 3d games, etc). However as my abilities in programming are increasing, my organization isn't. I seem to be making everything dependent on one one another, so it's very hard for me to change the implementa...
<p>Sketch out an architectural design ahead of time. It doesn't have to be too detailed, but imagine how you want things to fit together in general terms.</p>
<p>Use of design patterns is a good first step.</p> <p>Also, spend a little time writing good documentation regarding system architecture and requirements for the application.</p> <p>Using source control will help if you are not already doing this.</p> <p>Look for libraries that may do want you want before you decid...
12,400
<p>When creating an index over a column that is going to be UNIQUE (but not the primary key of the table), SQL server let's me choose a few options:</p> <p>1) I can choose for it to be a Constraint or an Index.<br> I'm guessing this means that if I set it as constraint, it won't use it when querying, only when writing...
<p>A <code>UNIQUE</code> constraint is part of the ISO/ANSI SQL standard, whereas indexes are not because the Standard is implementation agnostic. SQL Server, in common with most SQL DBMSs, will use an index to implement a <code>UNIQUE</code> constraint.</p> <p>Arguably, using <code>UNIQUE</code> rather than index in ...
<p>There is no practical difference between a unique constraint and a unique index other than the fact that the unique constraint is also listed as a constraint object in the database. </p>
27,389
<p>I have a simple page with my <code>ScriptManager</code> and my <code>UpdatePanel</code>, and my <code>ContentTemplate</code> has one <code>ListBox</code> and one Label. I am just trying to catch its <code>OnSelectionChanged</code> so I can update the text in the <code>Label</code>. No matter what settings I try to...
<p>You need to have Sharepoint 2007 service pack 1 -- or else there's no chance. (Sharepoint 2007 predates ajax 1.0 -- they built some support into service pack 1)</p> <p>Next, from a trouble shooting point of view, test that the <strong>exact</strong> same code functions as expected when hosted in a regular asp.net p...
<p>There's a specific problem with mixing doPostback, UpdatePanel and SharePoint -- and the symptom is exactly what you're seeing: a full-page postback instead of an asynchronous postback. See this KB article for a workaround: <a href="http://support.microsoft.com/kb/941955" rel="nofollow noreferrer">http://support.mic...
2,524
<p>When I download the zip file from the website it contains files with the following extensions:</p> <p>.dbf .prj .sbn .sbx .shp .shp.xml .shx</p> <p>Is this is a common data file format that I download or purchase a converter? I think this is some kind of mapping data file but I all need are the addresses it contai...
<p>Much thanks to everyone who provided information. I found a CodePlex C# project that was exactly what I needed. I did have to make one small modification which I posted back on the project discussion board which was for an unknown column type of "F". But the command line program DBF2CSV worked beautifully to create ...
<p>The format for the dbf files is like the old DBase III format. The shp files contains the shapes and the shx are some kind of indices.</p>
18,111
<p>I'm managing an established site which is currently in the process of being upgraded (completely replaced anew), but I'm worried that I'll lose all my Google indexing (that is, there will be a lot of pages in Google's index which won't exist in that place any more).</p> <p>The last time I upgraded a (different) sit...
<p>You need to put some rewrite rules in an .htaccess file.</p> <p>You can find lots of good information <a href="http://httpd.apache.org/docs/1.3/misc/rewriteguide.html" rel="nofollow noreferrer">here</a>. It's for Apache 1.3, but it works for Apache 2, too.</p> <p>From that article, a sample for redirecting to fil...
<p>You can tune Google's view of your site, and probably notify its changes, from within <a href="http://www.google.com/webmasters/tour/tour1.html" rel="nofollow noreferrer">Google Webmaster Tools</a>. I think you should build a sitemap of your current site, and have it verified when the site changes. </p>
41,754
<p>What's the recommended source control system for a very small team (one developer)?<BR><BR> Price does not matter. Customer would pay :-)<BR> I'm working on Vista32 with VS 2008 in C++ and later in C# and with WPF. Setting up an extra (physical) server for this seems overkill to me. <BR><BR>Any opinions?</p>
<p>I would use Subversion (in fact I use it) [<strong>update</strong>: Jul 2014 -- I use Git -- see end of the answer]. SVN is:</p> <ul> <li>free, </li> <li>good enough (see disadvantages below), </li> <li>simple, </li> <li>works fine on Windows (and Linux too), </li> <li>a lot of people use it so it's easy to get ...
<p>I dont see why the fact that your one developer changes anything on the source control issue. I would follow the same system (in fact I do on my solo projects). I use <a href="http://wush.net/" rel="nofollow noreferrer">wush.net</a> (svn and trac) in those cases. It's fast to set up and dont require that you yourse...
6,725
<p>Let me first say that being able to take 17 million records from a flat file, pushing to a DB on a remote box and having it take 7 minutes is amazing. SSIS truly is fantastic. But now that I have that data up there, how do I remove duplicates?</p> <p>Better yet, I want to take the flat file, remove the duplicates f...
<p>Use the Sort Component.</p> <p>Simply choose which fields you wish to sort your loaded rows by and in the bottom left corner you'll see a check box to remove duplicates. This box removes any rows which are duplicates based on the sort criteria only so in the example below the rows would be considered duplicate if w...
<p>I would recommend loading a staging table on the destination server and then merge the results into a target table on the destination server. If you need to run any hygiene rules, then you could do this via stored procedure since you are bound to get better performance than through SSIS data flow transformation tas...
18,178
<p>What is the best python framework to create distributed applications? For example to build a P2P app.</p>
<p>You could checkout <a href="http://pyprocessing.berlios.de/" rel="nofollow noreferrer">pyprocessing</a> which will be included in the standard library as of 2.6. It allows you to run tasks on multiple processes using an API similar to threading.</p>
<p>You could download the source of BitTorrent for starters and see how they did it.</p> <p><a href="http://download.bittorrent.com/dl/" rel="nofollow noreferrer">http://download.bittorrent.com/dl/</a></p>
11,997
<p>I have a CheckedListBox, and I want to automatically tick one of the items in it.</p> <p>The <code>CheckedItems</code> collection doesn't allow you to add things to it.</p> <p>Any suggestions?</p>
<p>You need to call <strong><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.setitemchecked.aspx" rel="noreferrer"><code>SetItemChecked</code></a></strong> with the relevant item.</p> <p>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.objectc...
<p>Use:</p> <pre><code>string[] aa = new string[] {"adiii", "yaseen", "salman"}; foreach (string a in aa) { checkedListBox1.Items.Add(a); } </code></pre> <p>Now code where you want to check all:</p> <pre><code>private void button5_Click(object sender, EventArgs e) { for(int a=0; a&lt;checkedListBox1.Items.Co...
48,454
<p>I'm trying to implement a data compression idea I've had, and since I'm imagining running it against a large corpus of test data, I had thought to code it in C (I mostly have experience in scripting languages like Ruby and Tcl.) </p> <p>Looking through the O'Reilly 'cow' books on C, I realize that I can't simply in...
<p>Following on from what Kyle has said, you can use a macro to do the hard work for you.</p> <blockquote> <p>It is possible.</p> <p>To set the nth bit, use OR:</p> <p>x |= (1 &lt;&lt; 5); // sets the 6th-from right</p> <p>To clear a bit, use AND:</p> <p>x &amp;= ~(1 &lt;&lt; 5); // clears 6t...
<p>IF you want to index a bit you could:</p> <pre><code>bit = (char &amp; 0xF0) &gt;&gt; 7; </code></pre> <p>gets the msb of a char. You could even leave out the right shift and do a test on 0.</p> <pre><code>bit = char &amp; 0xF0; </code></pre> <p>if the bit is set the result will be > 0;</p> <p>obviousuly, you n...
8,819
<p>Is there any way to find out if the user pressed the delete key or dot? It has the same keycode in FireFox.</p>
<p>According to <a href="http://www.quirksmode.org/js/keys.html" rel="nofollow noreferrer">Detecting keystrokes</a>, it is possible, provided that:</p> <ul> <li>you search for the keyCode (<strong>8</strong> for delete) onkeydown/up, and </li> <li>ignore both onkeypress and charCode (Especially if you consider the fac...
<p>According to <a href="http://www.quirksmode.org/js/keys.html" rel="nofollow noreferrer">Detecting keystrokes</a>, it is possible, provided that:</p> <ul> <li>you search for the keyCode (<strong>8</strong> for delete) onkeydown/up, and </li> <li>ignore both onkeypress and charCode (Especially if you consider the fac...
37,738
<p>I want to use RSpec mocks to provide canned input to a block.</p> <p>Ruby:</p> <pre><code>class Parser attr_accessor :extracted def parse(fname) File.open(fname).each do |line| extracted = line if line =~ /^RCS file: (.*),v$/ end end end </code></pre> <p>RSpec:</p> <pre><code>describe Parser...
<p>I don't have a computer with Ruby &amp; RSpec available to check this, but I suspect you need to add a call to <code>and_yields</code> call [1] on the end of the <code>should_receive(:each)</code>. However, you might find it simpler not to use mocks in this case e.g. you could return a <code>StringIO</code> instance...
<p>This should do the trick:</p> <pre><code>describe Parser before do @parser = Parser.new end it "should extract a filename into extracted" do linetext = [ "RCS file: hello,v\n", "bla bla bla\n" ] File.should_receive(:open).with("somefile.txt").and_return(linetext) @parser.parse("somefile.txt")...
49,569
<p>What are the basic steps to compile an OpenGL application using <em>GLUT (OpenGL Utility Toolkit)</em> under Visual C++ Express Edition?</p>
<ol> <li>If you don't have Visual C++ Express Edition (VCEE), download and install <a href="http://msdn.microsoft.com/vstudio/express/visualc/default.aspx" rel="nofollow noreferrer">VCEE</a>.</li> <li>The default install of Visual C++ Express Edition builds for the .Net platform. We'll need to build for the Windows pla...
<p>The GLUT port on Nate Robin's site is from 2001 and has some incompatibilities with versions of Visual Studio more recent than that (.NET 2003 and up). The incompatibility manifests itself as errors about redefinition of <code>exit()</code>. If you see this error, there are two possible solutions:</p> <ol> <li>Rep...
3,503