instruction
stringlengths
0
30k
You can define a static constructor for the class that will check that the type T is an enum and throw an exception if it is not. This is the method mentioned by Jeffery Richter in his book CLR via C#. internal sealed class GenericTypeThatRequiresAnEnum<T> { static GenericTypeThatRequiresAnEnum() { ...
You can define a static constructor for the class that will check that the type T is an enum and throw an exception if it is not. This is the method mentioned by Jeffery Richter in his book CLR via C#. internal sealed class GenericTypeThatRequiresAnEnum<T> { static GenericTypeThatRequiresAnEnum() { ...
Just don't use the manifest. Create a foo.properties.original file, with a content such as version=@VERSION@ And in ther same task you are jaring you can do a copy to copu foo.properties.original and then <replace file="foo.properties" token="@VERSION@" value="$version.num"/>
We try to use a single, shared stored proc wherever possible, but we've run into the situation you describe as well. We handled it by adding an application prefix to the stored procs (ApplicationName_StoredProcName). Often these stored procs call the centralized or "master" stored proc, but this method leaves roo...
![The only valid measurement of code quality: WTFs/minute][1] [1]: http://blog.pengoworks.com/enclosures/wtfm_cf7237e5-a580-4e22-a42a-f8597dd6c60b.jpg
By the way, if one wants lower verbosity and still keep the constructor with its "standard" semantics, one could create a factory method: activeThreads.add( CustomThread.newStartedThread() );
The actual standards documents may not be the most useful. Most compilers do not fully implement the standards and may sometimes actually conflict. So the compiler documentation that you would already have will be more useful. Additionally, the documentation will contain platform-specific remarks and notes on any ca...
This works: The way it's set up I called it from the immediate pane, but you can easily create a sub() that will call MoveData once for each month, then just invoke the sub. You may want to add logic to sort your monthly data after it's all been copied Public Sub MoveData(MonthNumber As Integer, SheetName As ...
Warning: this item was voted #1 **_Most Horrendous Hack of 2008_**, so use with care. Actually, avoid it like the plague, but it is most certainly Hidden Ruby. ## Superators Add New Operators to Ruby Ever want a super-secret handshake operator for some unique operation in your code? Like playing code golf? Try...
This answer will sound snide, but it is intended to make you think: > Only run the code once. The reason I say that is because so much will make it variable and you might not even have control over it. And what is your definition of time? Suppose the operating system decides to put your process in the wait queu...
If you make all the function calls in the critical code 'inline', and minimize the number of variables you have, so that you can let them have the 'register' type. This should improve the running time of your program. (You probably have to compile it in a special way since compilers these days tend to disregard your ...
I'd say if you want a really complete answer, go look at the source code for Ogre3D. They have both D3D and OpenGL back ends. http://www.ogre3d.org Basically their API kind of forces you into working in a D3D-ish way, creating buffer objects and stuffing them with data, then issuing draw calls on those buffers. Tha...
What is the difference between Flex and Flash? The way I keep it clear in my mind and explain it to others is as follows: Choose the right tool for what you want to create. If you want to write an APPLICATION using Flash technology, use Flex. If you want to create an ANIMATION using Flash techology, use tra...
What you *really* need to do is not send these cookie values that are hackable in the first place. Instead, why not hash the username and password and a (secret) salt and set that as the cookie value? i.e.: define('COOKIE_SALT', 'secretblahblahlkdsfklj'); $cookie_value = sha1($username.$password.COOKIE_SALT...
Alternatively, hit cmd-? and don't mess with the script. :-) That puts key focus in the help menu's search field.
Unless you have some specific requirement here I'm not sure why JS is needed here. Tabular layouts are the easy (and archaic) way to make fluid layouts in html, but div layouts with css allow for fluid layouts as well, see http://www.glish.com/css/2.asp
boolean isEven = (a % 2 == 0);
Here is the representation of your pseudo-code in minimal Java code; boolean isEven = (a % 2 == 0); I'll now break it down into it's components. The modulus operator in Java is the percent character (%). Therefore taking an int % int returns another int. The double equals (==) operator is used to compare valu...
To get the polymorphic behavior you're after and at the same time use a `std::vector<>`, you must store _pointers_ to the base class type in the vector, instead of storing _values_. Also, you must remember to free their memory before the vector goes out of scope. For instance: #include <vector> #include ...
It depends on various things: - if they are immutable and non relational (think "names of US States") an argument could be made that they should not be in the database at all: after all they are simply formatting of something simpler (like the two character code assigned). This has the added advantage that you don't...
Sorry I can't add this as a comment to a previous answer but I don't have the rep. Doing some quick and dirty testing I also found that exec("identify -ping... is about 20 times faster than without the -ping. But getimagesize() appears to be about 200 times faster still. So I would say getimagesize() is the faster...
There are no problems with the example code. I have another application that fails too, written in Delphi. I think I found the answer based on Kris' answer about redirection: [http://msdn.microsoft.com/en-gb/library/aa364418(VS.85).aspx][1] [1]: http://msdn.microsoft.com/en-gb/library/aa364418(VS.85).aspx
There are many options here, but assuming instructors are always instructors and students are always students, you can use inheritance: class Person < ActiveRecord::Base; end # btw, model names are singular in rails class Student < Person; end class Instructor < Person; end then class Course...
There are many options here, but assuming instructors are always instructors and students are always students, you can use inheritance: class Person < ActiveRecord::Base; end # btw, model names are singular in rails class Student < Person; end class Instructor < Person; end then class Course...
Keep pagination repeatable if change operations are performed
|sql|pagination|
If one wants to paginate results from a data source that supports pagination we have to go to a process of: 1. defining the page size - that is the number of results to show per page; 2. fetch each page requested by the user using an offset = page number (0 based) * page size 3. show the results of the fetched ...
Wow, this problem is popular. It's based on a misunderstanding in the `vertical-align` property. This excellent article explains it: [Understanding `vertical-align`, or "How (Not) To Vertically Center Content"][1] [1]: http://phrogz.net/CSS/vertical-align/index.html
In addition to id's and classes being great for setting style on an individual item verses a similar set of items, there's also another caveat to remember. It also depends on the language to some degree. In ASP.Net, you can throw in Div's and have id's. But, if you use a Panel instead of the Div you will lose the id.
[ELMAH][1] is a great drop-in tool for this. DLL in the bin directory, and some markup to add to the web.config and you're done. [1]: http://code.google.com/p/elmah/
A huge issue for me is that tables, especially nested tables, take much longer to render than a properly layed out css implementation. (You *can* make css just as slow). All browsers render the css faster because each div is a seperate element, so a screen can be loading as the user is reading. (For huge data sets, ...
You should look into the application_error method in the global.asax page to catch the errors, and into either log4net and the enterprise library to log those errors in whatever form you choose to any provider you choose -- such as database or e-mail.
[log4net][1] can save errors to a database or send emails. We use this at my job (despite the fact it caused Jeff Atwood much stress in the SO beta). Catch the errors in the global.asax page in the Application Error method. [1]: http://logging.apache.org/log4net/index.html
My preference is to have a single module (or a small number of modules) in your testbench that contains all your probes but no other functionality. All other modules in your testbench that require probes then connect to that "probe module". Use SystemVerilog interfaces in preference to raw wires if that's an option for...
My preference is to have a single module (or a small number of modules) in your testbench that contains all your probes but no other functionality. All other modules in your testbench that require probes then connect to that "probe module". Use SystemVerilog interfaces in preference to raw wires if that's an option for...
My preference is to have a single module (or a small number of modules) in your testbench that contains all your probes but no other functionality. All other modules in your testbench that require probes then connect to that "probe module". Use SystemVerilog interfaces in preference to raw wires if that's an option for...
My preference is to have a single module (or a small number of modules) in your testbench that contains all your probes but no other functionality. All other modules in your testbench that require probes then connect to that "probe module". Use SystemVerilog interfaces in preference to raw wires if that's an option for...
It depends on various things: - if they are immutable and non relational (think "names of US States") an argument could be made that they should not be in the database at all: after all they are simply formatting of something simpler (like the two character code assigned). This has the added advantage that you don't...
It depends on various things: - if they are immutable and non relational (think "names of US States") an argument could be made that they should not be in the database at all: after all they are simply formatting of something simpler (like the two character code assigned). This has the added advantage that you don't...
Somewhere at the top of your script, include the line use IPC::Open2; That will include the necessary module, usually installed with most Perl distributions by default. (If you don't have it, you could install it using CPAN.) Then, instead of open, call: $pid = open2(\*CMDOUT, \*CMDIN, 'some cmd and ...
Somewhere at the top of your script, include the line use IPC::Open2; That will include the necessary module, usually installed with most Perl distributions by default. (If you don't have it, you could install it using CPAN.) Then, instead of open, call: $pid = open2($cmd_out, $cmd_in, 'some cmd and ...
It can be achieved by using code snippets, some are already built in (try typing "svm" and hitting TAB-TAB).. There's a wealth of info on the net on creating these: [Jeff did a post himself here](http://www.codinghorror.com/blog/archives/000419.html) Have a google! I use them LOTS! :D
Take a look at [visual assist][1] as well. [1]: http://www.wholetomato.com/
Check out [Reshaper][1] - it has this feature. [1]: http://www.jetbrains.com/resharper/documentation/feature_map.html
Check out [Resharper][1] - it is a Visual Studio add-on with this feature, among many other development helps. Also see [C# Completer][2], another add-on. If you want to roll your own, check out [this article][3]. Insane that one should have to do that, though. [1]: http://www.jetbrains.com/resharper/docu...
The tools look nice (especially Resharper but at $200-350 ouch!) but I ended up just recording a macro and assigning it to ctrl+alt+[ Macro came out like this: Sub FunctionBraces() DTE.ActiveDocument.Selection.NewLine DTE.ActiveDocument.Selection.Text = "{}" DTE.ActiveDocument.Selection.CharLef...
The tools look nice (especially Resharper but at $200-350 ouch!) but I ended up just recording a macro and assigning it to ctrl+alt+[ Macro came out like this: Sub FunctionBraces() DTE.ActiveDocument.Selection.NewLine DTE.ActiveDocument.Selection.Text = "{}" DTE.ActiveDocument.Selection.CharLef...
Replicating load related crashes in non-production environments
|asp.net|performance|memory|crash|cpu|
We're running a custom application on our intranet and we have found a problem after upgrading it recently where IIS hangs with 100% CPU usage, requiring a reset. Rather than subject users to the hangs, we've rolled back to the previous release while we determine a solution. The first step is to reproduce the probl...
Echo2 / Echo3 by Nextapp (www.nextapp.com) is totally awesome. Advantages over GWT: 1) It is not limited to a sub-set of java like GWT 2) It is easier (in my estimation) to learn 3) Has extremely robust design studio for almost drag and drop designing. 4) It is very fast, and works very well on all platforms...
[Clover ][1] will give a nice report showing hit counts for each line and branch. For example, [this line][2] was executed 7 times. Plugins for Eclipse, Maven, Ant and IDEA are available. It is [free for open source][3], or you can get a [30 day evaluation license][4]. [1]: https://www.atlassian.com/software...
Take a look at [MathWorld][1]. Browse topics or search for one, you'll get your position in the overall tree. [1]: http://mathworld.wolfram.com/
Generally speaking, for your database backend to work with .net you need an ADO.Net provider for it. For MS Access (Jet), the Provider is shipped with .net. For SQLite, there is a selfcontained ADO.Net Provider. As for the data access layer lib, if you want some abstraction over ADO.Net: - MS [Data Access A...
For busy servers, disabling last access time is generally a good idea. The only potential downside is if there are scripts that use last access time to, for instance, tell that a file is no longer being written. That said, if you're looking to improve build times on a C++ project, I highly recommend reading [Recurs...
You might want to have a look at the entries in the [Wide Finder Project](http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder) (do a google search for ["wide finder" java](http://www.google.com.au/search?q="wide+finder"+java)). The Wide finder involves reading over lots of lines in log files, so look at th...
The algorithm you just described it. A program that does it out of the box with a big button saying "Do it"... I don't know. But let me be constructive. I recommend you this book [Programming Collective Intelligence](http://oreilly.com/catalog/9780596529321/). Chapters 3 and 4 contain very pragmatic examples (really...
I generally only like to create classes that represent actual business entities. In this case I don't think 'groupmembers' represents anything of value in your code. To me the ORM should map the database to your business objects. This means that your classes don't have to exactly mirror the database layout. Also I ...
I generally only like to create classes that represent actual business entities. In this case I don't think 'groupmembers' represents anything of value in your code. To me the ORM should map the database to your business objects. This means that your classes don't have to exactly mirror the database layout. Also I ...
three options: 1. learn to use the existing controls like GridView; with proper CSS they can look quite nice, since they just generate HTML on the client side 2. generate your HTML using templates or StringBuilder and put it in a Literal control on your web page 3. buy a third-party library that has controls t...
You can use time and curl and time on the command-line. The -I argument for curl instructs it to only request the header. time curl -I 'http://server:3000'
You can leave out the newline which gives you: case 1: case 2: case 3: break; but I consider that bad style. /Allan
Using Java JAR file in .NET
|.net|java|jar|managed|
What options/methods/software are available to convert a JAR file to a managed .NET assembly? Please provide all commercial and non-commercial methods in the answer. These don't include solutions which require Java to be installed on the host machine.
How can you insure your code executes with no variability in execution time?
There are many options here, but assuming instructors are always instructors and students are always students, you can use inheritance: class Person < ActiveRecord::Base; end # btw, model names are singular in rails class Student < Person; end class Instructor < Person; end then class Course...
Interfaces and delegates are two utterly different things, although I understand the temptation to describe delegates in interface-like terms for ease of understanding...however, not knowing the truth may lead to confusion down the line. Delegates were inspired (partly) because of the black art of C++ method pointer...
If you are planning on storing all those configuration objects in a single file, and that file will be quite large, both the options you've outlined above could be quite memory intensive, as they both require the entire file to be read into memory to be deserialized. If memory usage is a concern (the file containing...
For SQL Server: Use a varchar(max) to store. I think the upper limit is 2 GB. Don't try to escape the text yourself. Pass the text through a parameterizing structure that will do the escapes properly for you. In .Net you'd add a parameter to a SqlCommand, or just use LinqToSQL (which then manages the SqlComman...
How to click a button on an ASP.NET web page programmatically?
|asp.net|
I am trying to figure out how to click a button on a web page programmatically. Specifically, I have a WinForm with a WebBrowser control. Once it navigates to the target ASP.NET login page I'm trying to work with, in the DocumentCompleted event handler I have the following coded: HtmlDocument doc = webBrowse...
Passing EXE data down to one or more DLLs
|c++|windows|visual-studio-2008|windows-xp|dll|
Our current application is a single OpenGL EXE containing multiple pages. The EXE is responsible for accessing data sent across the network via UDP. It accumulates the data and stores it in a host of singleton structures. The individual pages within the EXE access the singleton structures to process the data as they...
How do I override the library path when loading a core file in gdb on Linux
|gdb|linux|core|path|
I have a core file generated on a remote system that I don't have direct access to. I also have local copies of the library files from the remote system, and the executable file for the crashing program. I'd like to analyse this core dump in gdb. For example: gdb path/to/executable path/to/corefile My ...
How do I prepend a directory the library path when loading a core file in gdb on Linux
> Another discussion (we've been having a lot of them these days!) in our work > is whether data binding is a bad idea or not. > > Personally, I think it is A BAD THING. String opinion, but imho, you bring out all the wrong reasons. > 1) It circumvents my well architectured MVP framework - with databinding,...
> Another discussion (we've been having a lot of them these days!) in our work > is whether data binding is a bad idea or not. > > Personally, I think it is A BAD THING. Strong opinion, but imho, you bring out all the wrong reasons. > 1) It circumvents my well architectured MVP framework - with databinding,...
If I understand the question correctly, you've created a domain model and you would like to write an object-relational mapper to map between records in your database and your domain objects. However, you're concerned about polluting your domain model with the 'plumbing' code that would be necessary to read and write to...
This may sound dumb, but why are YOU trying to teach your brother to program? Often the best learning environment consists of an goal that can be achieved by a keen beginner (a sample program), an ample supply of resources (google/tutorials/books), and a knowledgeable source of advice that can provide guidance when ...
|processor|time|profiling|caching|
In an embedded application (written in C, on a 32-bit processor) with hard real-time constraints, the execution time of critical code (specially interrupts) needs to be constant. How do you insure that time variability is not introduced **in the execution** of the code, specifically due to the processor's caches (be...
How can you insure your code runs with no variability in execution time due to cache?
|time|profiling|caching|processor|
In an embedded application (written in C, on a 32-bit processor) with hard real-time constraints, the execution time of critical code (specially interrupts) needs to be constant. How do you insure that time variability is not introduced **in the execution** of the code, specifically due to the processor's caches (be...
@Blair Conrad said static variables declared inside the class definition, but not inside a method are class or "static" variables: >>> class Test(object): ... i = 3 ... >>> Test.i 3 There are a few gotcha's here. Carrying on from the example above: >>> t = Test() >>> t.i ...
@Blair Conrad said static variables declared inside the class definition, but not inside a method are class or "static" variables: >>> class Test(object): ... i = 3 ... >>> Test.i 3 There are a few gotcha's here. Carrying on from the example above: >>> t = Test() >>> t.i ...
At swcombine.com we use [Feedcreator][1]. Use that one and your problem will be gone. :) Here is the PHP code to use it once installed: function feed_simnews() { $objRSS = new UniversalFeedCreator(); $objRSS->title = 'My News'; $objRSS->link = 'http://link.to/news.php'; $ob...
At swcombine.com we use [Feedcreator][1]. Use that one and your problem will be gone. :) Here is the PHP code to use it once installed: function feed_simnews() { $objRSS = new UniversalFeedCreator(); $objRSS->title = 'My News'; $objRSS->link = 'http://link.to/news.php'; $ob...
The built in key shortcut cmd-? already behaves like this. It moves key focus to the help menu's search field if it is not already focused, and otherwise dismisses the menu.
|linux|gdb|path|core|
I have a core file generated on a remote system that I don't have direct access to. I also have local copies of the library files from the remote system, and the executable file for the crashing program. I'd like to analyse this core dump in gdb. For example: gdb path/to/executable path/to/corefile My ...
I think you should be able to use the free tool Ole/Com Object Viewer to make the header files.
There may be tools that allow this sort of analysis, but I only have experience of writing MDX, which ought to be able to help you. Typical 'what if' analysis is more about changing values in the OLAP cube (e.g. change net sales from 845.45 to 700.00 and see what happens to gross profit). Your case is a bit differen...
They MINIMUM you need to identify an HTTP object is by the full path, including any query-string parameters. Some browsers may not cache objects with a query string but that has nothing to do with the key to the cache. It is also important to remember that the the path is no longer sufficient. The Vary: header in th...
I was already splitting on tabs so this did the trick for me: public static string CsvToTabDelimited(string line) { var ret = new StringBuilder(line.Length); bool inQuotes = false; for (int idx = 0; idx < line.Length; idx++) { if (line[idx] == '"') { inQuotes = !inQuotes; ...