instruction
stringlengths
0
30k
In the load event for the page you can use setTimeout to fire a function warning the user that they will be logged out if they don't refresh the page. With 5 minute session timeouts you could do warnings after 4 minutes: setTimeout(timeoutWarning, 240000); function timeoutWarning() { if(conf...
The Global Interpreter Lock prevents threads from accessing the *interpreter* simultaneously (thus CPython only ever uses one core). However, as I understand it, the threads are still interrupted and scheduled *preemptively*, which means you still need locks on shared data structures, lest your threads stomp on each ot...
The <a href="http://www.martinfowler.com/bliki/FluentInterface.html">Fluent Interface</a> by Fowler is quite an interesting pattern. I've always had a soft spot for Abstract Factories, Strategies, and the State Pattern too. If I may, I recently codified a "pattern" that I call the <a href="http://moffdub.wordpress.c...
Reading or writing a 32-bit or smaller field is an atomic operation in C#. There's no need for a lock in the code you presented, as far as I can see.
In my opinion, you should try very hard to not put static variables in a position where they need to be read/written to from different threads. They are essentially free-for-all global variables in that case, and globals are almost always a Bad Thing. That being said, if you do put a static variable in such a positi...
If you *must* do this parsing, I'm sure you'll get lots of good suggestions here. My suggestion is - **don't do this parsing**. Instead, create your input fields so that the information is already separated out. Have separate fields for title, first name, middle initial, last name, suffix, etc.
Lots of people here have suggested introductions and comprehensive how-tos, which are all good for telling you how to do what you want. In addition, I'd give three pieces of advice for the novice on how to know what you want: 1) Version-control EVERYTHING (that is, everything you write). Version-control the p...
Lots of people here have suggested introductions and comprehensive how-tos, which are all good for telling you how to do what you want. In addition, I'd give three pieces of advice for the novice on how to know what you want: 1) Version-control EVERYTHING (that is, everything you write). Version-control the p...
There is no public way to modify the underlying SQL that LINQ to SQL generates to implement such a tagging facility. You could implement the Log property in such a way it writes out a text log file with some call stack information to show which methods generated which SQL statements for reference.
Retrieve the times in milliseconds and then do the subtraction.
You can't constrain T to have a particular constructor signature other than an empty constructor, but you can constrain T to have a builder method with the desired signature: public abstract class MyBaseClass { protected MyBaseClass() {} protected abstract MyBaseClass GetByObject(object ar...
You can't constrain T to have a particular constructor signature other than an empty constructor, but you can constrain T to have a factory method with the desired signature: public abstract class MyBaseClass { protected MyBaseClass() {} protected abstract MyBaseClass CreateFromObject(obje...
You can't constrain T to have a particular constructor signature other than an empty constructor, but you can constrain T to have a factory method with the desired signature: public abstract class MyBaseClass { protected MyBaseClass() {} protected abstract MyBaseClass CreateFromObject(obje...
It is sometimes worth using an `enum` to *name* the bits: enum ThingFlags = { ThingMask = 0x0000, ThingFlag0 = 1 << 0, ThingFlag1 = 1 << 1, ThingError = 1 << 8, } Then use the *names* later on (i.e. write `thingstate |= ThingFlag1;` to set and `thingstate &= ~ThingFlag0;` to ...
It is sometimes worth using an `enum` to *name* the bits: enum ThingFlags = { ThingMask = 0x0000, ThingFlag0 = 1 << 0, ThingFlag1 = 1 << 1, ThingError = 1 << 8, } Then use the *names* later on. I.e. write thingstate |= ThingFlag1; thingstate &= ~ThingFlag0; ...
How do I take a slice of a list (A sublist) in scheme?
|lisp|scheme|
Given a list, how would I select a new list, containing a slice of the original list (Given offset and number of elements) ?
Given a list, how would I select a new list, containing a slice of the original list (Given offset and number of elements) ? ###EDIT: Good suggestions so far. Isn't there something specified in one of the SRFI's? This appears to be a very fundamental thing, so I'm surprised that I need to implement it in user-lan...
How to print wstring in gdb
|gdb|
How can I print wstring in gdb?
int matrix with pointers in C - memory allocation confusion
|c|pointers|matrix|memory-management|
I'm having some issues with producing an int matrix without creating memory leaks. I want to be able to make a given (global) matrix into any size dynamically via read_matrix(). But then i want to be able to free the memory later on. So in my main method the second printf should result in a bus error since it should no...
command.CommandTimeout *= 2; That will double the default time-out, which is 30 seconds. Or, put the value for CommandTimeout in a configuration file, so you can adjust it as needed without recompiling.
Do you have access to the MySQL server in question? As in, what access do you have beyond what a regular user would? You should try to go through those routes before you "hack" your way in there, since that may or may not be feasible with that software.
I get the same problem (on OS X) with your PS1. If I remove the `\[` and `\]` PS1="${BLUE}\u${CYAN}@${RED}\h${BLUE}\w\n${red}\$${NC}" this works fine. Are the sqare brackets needed? I've never used them, but from [the docs][1]: > `\[` > Begin a sequence of non-printing characters. This could be used ...
All the stuff that can change from dev to test to prod must be configurable. If you can afford to build the process that updates these variable things during the installation of your product -- do it. (Baking the customizations into the build seems like an inferior idea -- you end up with a bunch of different incompati...
As a rule of thumb, indexes should be on any fields that you use in joins or where clauses (if they have enough different values to make using an index worthwhile, field with only a few possible values doesn't benefit from an index whci is why it is pointless to try ti indexa bit field). If your structure has forma...
Can Resharper be set to warn if IDisposable not handled correctly?
|c#|.net|resharper|static|analysis|
Is there a setting in Resharper 4 (or even Visual Studio itself...) that forces a warning if I forget to wrap code in a `using` block, or ommit the proper Dispose call in a `finally` block?
Is there a setting in Resharper 4 (or even Visual Studio itself...) that forces a warning if I forget to wrap code in a `using` block, or ommit the proper `Dispose` call in a `finally` block?
|c#|.net|resharper|static-analysis|
Is there a setting in Resharper 4 (or even Visual Studio itself...) that forces a warning if I forget to wrap code in a `using` block, or ommit the proper Dispose call in a `finally` block?
RMDIR [/S] [/Q] [drive:]path RD [/S] [/Q] [drive:]path - /S Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree. - /Q Quiet mode, do not ask if ok to remove a directory tree with /S
RMDIR **[/S]** [/Q] [drive:]path RD **[/S]** [/Q] [drive:]path - **/S** Removes all directories and files in the specified directory in addition to the directory itself. ***Used to remove a directory tree.*** - /Q Quiet mode, do not ask if ok to remove a directory tree with /S
When it comes to developing java desktop applications, I would highly recommend using the IDE environment [Netbeans][1]. Especially when it comes to the development of Swing based applications. [1]: http://www.netbeans.org
I have seen in the past where wsdl.exe would produce different proxy classes than the VS IDE wizard does. This is probably the explanation.
Building an HTML table on the fly using JQuery
|javascript|jquery|
Below is the code I use to build an HTML table on the fly (using JSON data received from the server) I display an animated pleasewait (.gif) graphic while the data is loading...however, the graphic freezes while the js function is building the table. At first, I was just happy to make this happen (display the table), ...
`mutable` does exist as you infer to allow one to modify data in an otherwise constant function. The intent is that you might have a function that "does nothing" to the internal state of the object, and so you mark the function `const`, but you might really need to modify some of the objects state in ways that don't...
As for your "which is better" question, they're the same since the function scope isn't used for anything else.
Our neighbourhood friendly Lisp guru pointed out the [remove-duplicates function][1]. He also provided an **untested** snippet: (defun merge-lists (list-a list-b sort-fn test-fn) (sort (remove-duplicates (append list-a list-b) :test test-fn) sort-fn)) [1]: http://www.lispworks.com/documentatio...
Our neighbourhood friendly Lisp guru pointed out the [remove-duplicates function][1]. He also provided the following snippet: (defun merge-lists (list-a list-b sort-fn test-fn) (sort (remove-duplicates (append list-a list-b) :test test-fn) sort-fn)) [1]: http://www.lispworks.com/documentation/...
Make sure you have the Hyper-V Tools installed on the Guest VM. You shouldn't need the legacy adapter. You also may want to make sure you have all of the latest updates which may have addressed your issue. Particularly, KB950050 [http://support.microsoft.com/kb/950050][1] [1]: http://support.microsoft.com/...
For internet explorer and Style sheets you can use the following syntax: <!--[if lte IE 6]><link href="/style.css" rel="stylesheet" type="text/css" /><![endif]--> This applys to IE 6 or earlier. You can change the IE version and also have: <!--[if eq IE 7]> = Equal too IE 7 <!--[if gt IE 6]> = Grea...
First I want to currect a wrong statement: you can run msTest outside of visual studio using command line. Although several CI tools such as TeamCity have better support for NUnit (probably would change as msTest become more popular). In my current project we use both and the only big diffrence we found is that mstest...
if you have regularly scheduled builds you could easily put something in the cron like this crontab -e then stop tomcat at say 1:30 am 30 1 * * * ./path_to_tamcat/bin/catalina.sh stop then start it up again 2 mins later 32 1 * * * ./path_to_tamcat/bin/catalina.sh start granted this isn't...
|flash|audio|
My favorite evil switch trick is to use an if(0) to skip over an unwanted case label. switch(val) { case 0: // Do something if (0) { case 1: // Do something else } case 2: // Do something in all cases } But very evil.
This isn't real deep or thorough, but I think that if you're using MS SQL Server or Oracle (Perhaps Nigel can help with a PL-SQL sample)...Nigel is on to something <cheap or free being the operative words here>. This only goes 3 dependencies deep, but could be modified to go however deep you need. It's not the pretties...
[ffmpeg][1] is a great (open source) program for building all kinds of video, and converting one type of video (a sequence of images in this case) into other types of video. Usually it is utilized from the command line, but that is really just a wrapper around its internal libraries. It is expressly available to be...
Does the Gentoo install CD contain everything for C++ development?
|linux|installation|gentoo|
I'd like to install Gentoo. I need it to develop GUI C++ applications using wxWidgets, so I need: - build tools: make, automake, autoconf, etc. - C++ compiler (GCC) - X Window System for testing (Fluxbox or something minimal would be enough) Now, I have two options: - download the small network installer (57...
Free and official? No. And XNA isn't free in the respect that you have to pay $99 to use it on the 360. You're pretty much limited to hacked, homebrew development, coupled with hardware modification. There's at least one console out there where the hardware modification is not required but I'm not sure if we can tal...
8 pixels is the cutoff. The reason is because JPEG images are simply an array of 8x8 DCT blocks; if the image resolution isn't mod8 in both directions, the encoder has to pad the sides up to the next mod8 resolution. This in practice is not very expensive bit-wise; what's much worse are the cases when an image has sh...
8 pixels is the cutoff. The reason is because JPEG images are simply an array of 8x8 DCT blocks; if the image resolution isn't mod8 in both directions, the encoder has to pad the sides up to the next mod8 resolution. This in practice is not very expensive bit-wise; what's much worse are the cases when an image has sh...
Have you tried DWR? http://directwebremoting.org
Go under Tools, Options.. in firefox, then when the options box comes up go to applications, there you can set all extensions and launch conditions. Actually it's termed "Content Type" and "Action" there...
I've sometimes had problems when using the vmware-vdiskmanager application (it created the extra space, but I couldn't use it). At which point, I used the GParted live CD, which worked perfectly.
Have you looked through the database mapping and access packages at <http://hackage.haskell.org/packages/archive/pkg-list.html#cat:Database> I haven't used them, so can't recommend any particular one. I also don't know what databases you are planning on using.
One note is that under some circumstances, a get() from an unsynchronized HashMap can cause an infinite loop. This can occur if a concurrent put() causes a rehash of the Map. http://lightbody.net/blog/2005/07/hashmapget_can_cause_an_infini.html
Get a list of all computers on a network w/o DNS
|c#|.net|networking|batch-file|
Greetings, I need a way (either via C# or in a .bat file) to get a list of all the computers on a given network. Normally, I use "net view", but this tends to work (from my understanding) only within your domain. I need the names (or at least the IP Addresses) of all computers available on my network. Being ...
You need to free each row individually: <pre><code> void free_matrix(int **matrix, int size_x) { for(int i = 0; i &lt; size_x; i++) free(matrix[i]); free(matrix); } </code></pre>
if (any == System.DBNull.Value) ... I prefer that one, simply because I read that as comparing values, not types.
FYI, this was addressed here yesterday: <http://stackoverflow.com/questions/93944/how-do-you-maintain-java-webapps-in-different-staging-environments>
How do you force a CIFS connection to unmount
|linux|cifs|smb|samba|
I have a CIFS share mounted on a Linux machine. The CIFS server is down, or the internet connection is down, and anything that touches the CIFS mount now takes several minutes to timeout, and is unkillable while you wait. I can't even run ls in my home directory because there is a symlink pointing inside the CIFS mo...
|linux|samba|smb|cifs|
I have a CIFS share mounted on a Linux machine. The CIFS server is down, or the internet connection is down, and anything that touches the CIFS mount now takes several minutes to timeout, and is unkillable while you wait. I can't even run ls in my home directory because there is a symlink pointing inside the CIFS mo...
IN order to do that, you'll have to use svn's specific move/rename functions (check TortoiseSVN help if you use this for example). If you move the files by yourself and then commit the changes i'm not sure that history will be kept.
The 2-D zooming you describe might be better achieved using Core Animation. NSView (and its NDA'd iPhone counterpart) provide implicit animation when you change their frame. All you'd need to do in this case would be to set the frame's origin.x and origin.y and size.width and size.height to such values to make the vi...
Let's step back for a second. Evans recommends that repositories return aggregate roots and not just entities. So assuming that your Customer is an aggregate root that includes Orders, then when you fetched the customer from its repository, the orders came along with it. You would access the orders by navigating the...
None of those things are major factors in the cost of a project. What it all comes down to is how well your schedule is put together - can you deliver what you said you would deliver by a certain date. If your schedule estimates are off, well guess what, you're project is going to cost a lot more than you thought it wo...
Its not built in. Here's an implementation; it relies on there being a Pair<T,U> class, the implementation of which is left as an exercise for the reader :). IEnumerable<Pair<T, U>> Zip<T, U>(IEnumerable<T> first, IEnumerable<U> second) { IEnumerator<T> firstEnumerator = first.GetEnumerator(); I...
ASP.NET Masterpage in separate assembly
|asp.net|master-pages|
I have some ASP.NET Master pages located in one assembly. I need to use these masterpages for my webform pages located in other asseblies that have a reference to the first assembly. I cannot seem to figure out a way to do this. Is there a nice way that I can do this? If you do not have a pretty solution I would ...
It worked as expected on my SQL 2005 installation. If it works on other machines, it sounds like you've got an environment difference. Try comparing your connection properties in SQL Server Management Studio for a connection that works and one that doesn't to see if you can figure out what the differences are.
If you're thinking of a generic class that calls methods on some interface to do its work, that will be slower than specific classes using known types, because calling an interface method is slower than a (non-virtual) function call. Of course, unless the code is the slow part of a performance-critical process, you ...
Generics are one of the way to parameterize code and avoid repetition. Looking at your program description and your thought of writing a separate class to deal with each and every data object, I would lean to generics. Having a single class taking care of many data objects, instead of many classes that do the same thin...
Personally if you are going to leave the records in production, I would also leave them in development. Otherwise you may write code that works fine when the recordset is small but times out when faced with the real recordset. But if you are determined to do this, I would copy the id field of the records you want to...
The Linux kernel is released under the GPLv2 and you can use it as part of a closed-source OS but you have to keep the kernel and all modifications released GPLv2. Edit: Btw, you may want to use something like OpenSolaris instead. It's much easier to work with, in my opinion (obviously very subjective), and you ca...
I don't agree that you should always rebuild your statistics after there have been lots of deletes or inserts. As ever, it depends. In a data warehouse situation, when re-building your materialized views you will be doing lots of deletes and inserts but the base structure of the data will not change. You only need t...
ADODB interop issue
|interop|adodb|version|2.5|primary-interop-assembly|
We have project PrjDb.dll in vb 6.0 that has a reference to ado 2.5. The project is built on Machine A. Now when we generate an interop for PrjDb.dll on another machine B, we end up with a new ADODB.dll with ver 2.5 in version field instead of linking it with the Primary Interop Assembly adodb.dll ( found under 'Progra...
|interop|primary-interop-assembly|
A whiteboard, index cards and sharpies.
What is the correct way to make a custom .NET Exception serializable?
|.net|exception|serialization|
More specifically, when the exception contains custom objects which may or may not themselves be serializable. Take this example: public class MyException : Exception { private readonly string resourceName; private readonly IList<string> validationErrors; public MyException(s...
How do I read selected files from a remote Zip archive over HTTP using Python?