instruction
stringlengths
0
30k
The usual approach (when you can't cheat*) is to write something that encodes its source in a string constant, then prints out that constant twice: Once as a string literal, and once as code. That gets around the "every time I write a line of code, I have to write another to print it out!" problem. 'Cheating' includ...
So, if you accept Marijn's point and _are_ interested in testing the user agent string via javascript: `var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;` (Credit to: http://davidwalsh.name/detecting-google-chrome-javascript )
So, if you accept Marijn's point and _are_ interested in testing the user agent string via javascript: `var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;` (Credit to: http://davidwalsh.name/detecting-google-chrome-javascript ) ---- Here's a really nice analysis/breakdown of the chrom...
This prints "98" to the console. class Program { static void Main(string[] args) { Console.Write("1998".Substring(2).PadLeft(2, '0')); Console.Read(); } }
The nice thing about languages such as Haskell is that you can apply only parts of the argument, to create *curried* functions: adder n x y = n + x + y In other words: "give me three things, and I'll add them together". When you throw numbers at it, the compiler will infer the types of n x and y. Say you wri...
|javascript|browser|cross-browser|
You can call [<code>int fstream::get()</code>][1], which will read a single character from the stream. You can also use [<code>istream& fstream::read(char*, streamsize)</code>][2], which does the same operation as <code>get()</code>, just over multiple characters. The given links include examples of using each method. ...
You might also want to look into using ISA Server to help you out: http://blogs.msdn.com/jannemattila/archive/2007/07/23/isa-moss-makes-life-a-lot-easier-for-fba.aspx http://www.isaserver.org/tutorials/Configuring-ISA-Firewalls-ISA-2006-RC-Support-User-Certificate-Authentication-using-Constrained-Delegation-Part1.ht...
You must keep the source open, and any works derived from the code, however, if you use the Kernel, write your own application stack on top of that (pretty much ALL the GNU stuff) then you don't have to open that up. The GPL says that "derived" works... so if you're writing new code, instead of expanind on, then tha...
Can I (re-) map commands in vim?
|vim|
I love vim and the speed it gives me. But sometimes, my fingers are too speedy and I find myself typing ":WQ" instead of ":wq" (on a German keyboard, you have to press shift to get the colon). Vim will then complain that 'W' is not an editor command. Is there some way to make W and Q editor commands?
[PMD][1] PMD scans Java source code and looks for potential problems like: * Possible bugs - empty try/catch/finally/switch statements * Dead code - unused local variables, parameters and private methods * Suboptimal code - wasteful String/StringBuffer usage * Overcomplicated expressions - unne...
One of the beauties of source control is that it doesn't matter if someone deletes a file. If they delete a file and check it in and it should not have been deleted, just revert their revision. Simple as that.
A few months ago I looked for such a library and I found nothing interesting. It is not impossible to create one, so I would recommend doing so. You'll probably need to access native libraries, to do that use [JNA][jna] (it's easier than JNI). Start by adding support for a few things on one platform, then start adding ...
Make the key field UNIQUE and IDENTITY and you wont have to worry about it.
Not free, but I just had a tough issue in huge code base with streams. Visual Studio's profiler got me close, but Antz Profiler locked it down. It isn't free, but it was much less painless than setting up Visual Studio.
As I have mentioned [there][1], probably the best and easiest approach is to create a table containing information about each day (work day / bank holiday, etc; one row per day = 365 rows per year) and then just use count function / with proper selection. [1]: http://stackoverflow.com/questions/80541/given-two-...
As I have mentioned [there][1], probably the best and easiest approach is to create a table containing information about each day (work day count from beginning / bank holiday, etc; one row per day = 365 rows per year) and then just use count function / with proper selection. [1]: http://stackoverflow.com/quest...
I accepted (and voted up!) @Brian's answer, for first pointing me to FasterCSV. Then when I googled to find the gem, I also found a fairly complete example at [this wiki page][1]. Putting them together, I settled on the following code. By the way, the command to install the gem is: sudo gem install fasterc...
Bit old but still one of my favs: <img src="http://www.ok-cancel.com/strips/okcancel20031003.gif"/>
It's 10 digits, so pretend it's a phone number (assuming you're in the US). 214-748-3647. I don't recommend calling it.
Stateful Web Services
|web-services|stateful|
I'm building a java/spring application, and i may need to incorporate a stateful web service call. Any opinions if i should totally run away from a statefull services call, or it can be done and is enterprise ready?
A SWITCH construct was originally intended for integer data; it's intent was to use the argument directly as a index into a "dispatch table", a table of pointers. As such, there would be a single test, then launch directly to the relevant code, rather than a series of tests. The difficulty here is that it's use has...
1) get the key with the same number of value 2) get all the combination id1/id2 in both tables (you need an outher join to do it) 3) the row with the number of key value equal to the number of equal value is the target I hope it's what you searched for (you don't search performance don't you ?) declare @a t...
The nice thing about languages such as Haskell (it's very similar in F#, but I don't know the exact syntax -- this should help you understand ->, though) is that you can apply only parts of the argument, to create *curried* functions: adder n x y = n + x + y In other words: "give me three things, and I'll add...
PadLeft ensures that you receive at least two characters from the input, padding the input (on the left side) with the appropriate character. So input, in this case, might be 12. You get "12" back. Or input might be 9, in which case, you get "09" back. This is an example of complex chaining (see ["Is there any bene...
.NET String.Format() to add commas in thousands place for a number
|c#|.net|
I want to add a comma in the thousands place for a number. String.Format()?
Detecting when ChucK child shred has finished
|chuck|
Is it possible to determine when a ChucK child shred has finished executing if you have a reference to the child shred? For example, in this code: // define function go() fun void go() { // insert code } // spork another, store reference to new shred in offspring spork ~ ...
If you are using a SQL Server backend, Reporting Services should work for you. Otherwise I would recommend a third-party report generator that fits your reporting needs and create an app that uses it to create & export the reports.
Of course CruiseControl.NET can run a batch file, simply use the exec task. However, an easier answer might just be to have MSBuild do the task for you. It should be simple to add a few steps in the postcompile target.
With anything except Interface Builder you're going to have to get the standard UI control templates from somewhere else or make them yourself. I've been using [Lineform](http://www.freeverse.com/apps/app/?id=6020), which turns out to be pretty good at specifying dimensions in Pixels (just select "Points / Pixels" a...
I would recommend that you read a book about version control, preferably the [Version Control with Subversion][1]. What you describe is not a problem, this is how version control works. [1]: http://svnbook.red-bean.com/ "Version Control with Subversion"
Computed columns are fine when they are not calculation intensive and are not executed on a large number of rows. Your questions is "will there be a hit by dropping the computed column." Unless this column is an index that is used by the query (REAL bad idea to index a comp col - i don't know if you can depending on yo...
Going under Tools | Options... doesn't seem to work, as after doing so you get an error that an unknown error occurred opening the file. However, if you install the [OpenDownload][1] extension, then you get a run button which successfully runs Visio. [1]: https://addons.mozilla.org/en-US/firefox/addon/207
Something very important that's missing from the list is the TRY CATCH statement - SQL2005 supports such statement while SQL2000 does not. Please someone with enough rep integrate this. sample: BEGIN TRY -- Generate divide-by-zero error. SELECT 1/0; END TRY BEGIN CATCH -...
Something very important is the TRY CATCH statement - SQL2005 supports such statement while SQL2000 does not. sample: BEGIN TRY -- Generate divide-by-zero error. SELECT 1/0; END TRY BEGIN CATCH -- Execute custom error retrieval routine. END CATCH;
1) get the key with the same number of value 2) get all the combination id1/id2 in both tables (you need an full join to do it) 3) the row with the number of key value equal to the number of equal value is the target I hope it's what you searched for (you don't search performance don't you ?) declare @a tab...
It really depends on what context of Testing you are referring to. In the strictest sense of the word, Testing is just double checking that the program does what it is meant to do without error no matter what the user inputs. Also, an Error would be something unexpected. Not all error crash the program.
Testing is any process by which it is verified that each feature (user story, requirement...) has been developed as required, or not.
Actually, the only way a cast could hide an error is if you were converting from one datatype to an smaller datatype and lost data, or if you were converting pears to apples. Take the following example: int int_array[10]; /* initialize array */ int *p = &(int_array[3]); short *sp = (short *)p; ...
Some more fun "quotes on quality" [here][1]. It's a short list, so I'll just post them (from qcboss.wordpress.com): “An effective way to test code is to exercise it at its natural boundaries” — Brian Kernighan “Testing is organised skepticism.”– James Bach “Program testing can be used to show the presence of ...
How to draw custom button in Window Titlebar with Windows Forms?
|winforms|winapi|titlebar|wndproc|
How do you draw a custom button next to the minimize, maximize and close buttons within the Titlebar of the Form? I know you need to use Win32 API calls and override the WndProc procedure, but I haven't been able to figure out a solution that works right. Does anyone know how to do this?
|winforms|winapi|titlebar|wndproc|.net|
|winforms|winapi|titlebar|wndproc|
|winforms|winapi|windows-vista|titlebar|wndproc|
How do you draw a custom button next to the minimize, maximize and close buttons within the Titlebar of the Form? I know you need to use Win32 API calls and override the WndProc procedure, but I haven't been able to figure out a solution that works right. Does anyone know how to do this? More specifically, does a...
Without access to the source code, you can't do it. If you do have access to the source, then do what RichH said.
Of course you can run this. You just can't run it in the application you're debugging. To find out what it's doing, and not just what it looks like it's doing, make a new web application, put in a DropDownList, put a few static years in it, and then put in the code you've mentioned and see what it does. Then you'll ...
How do I restore a MySQL .dump file?
|database|mysql|mysqldump|mysql-management|
I was given a .dump MySQL database file that I need to restore as a database on my Windows Server 2008 machine. I tried using MySQL Administrator, but I got the following error: > The selected file was generated by > mysqldump and cannot be restored by > this application. How do I get this working?
Why won't an Ajax Script Work Locally?
|javascript|ajax|webserver|
I've an issue with the same piece of code running fine on my live website but not on my local development server. I've an Ajax function that updates a div. The following code works on the live site: <pre>self.xmlHttpReq.open("POST", PageURL, true); self.xmlHttpReq.setRequestHeader("Content-type", "application/x-...
One idea to think about encoding and how to give something a double meaning so that it can be used to output something in a couple of forms. There is also the cavaet that this type of problem comes with restrictions to make it harder as without any rules other than the program output itself, the empty program is a sol...
Take a look Pushing Pixels blog: http://www.pushing-pixels.org/index.php?s=mouse+wheel Kind Regards
I have to agree with Terrapin. You have a few options on how to get your time down. First, if your company employs DBAs, I'd recommend asking them for suggestions. If that's not an option, or if you want to try some other things first here are your three major options: 1. Break up the query into components th...
1) i assume that you don't have duplicate id 2) get the key with the same number of value 3) the row with the number of key value equal to the number of equal value is the target I hope it's what you searched for (you don't search performance don't you ?) declare @a table( pkid int, value int) declar...
What is the scope for imported classes in python?
|python|import|scope|eval|global|
Please excuse the vague title. If anyone has a suggestion, please let me know! Also please retag with more appropriate tags! **The Problem** I want to have an instance of an imported class be able to view things in the scope (globals, locals) of the importer. Since I'm not sure of the exact mechanism at work h...
|python|import|scope|eval|
|python|import|scoping|eval|
|python|import|scope|eval|
Generally I would say that you're allowed to do such a thing, as long as you provide the source for the kernel, but there's one point where I'm unsure: On a normal Linux system between the (GPL) kernel and a non-GPL compatible application, there is always the GNU libc, which is LGPL and thus allows derived works th...
Generally, anything that implements IDisposable should cause you to pause and research the resource you're using. GC only happens when there's memory pressure, so you cannot predict when. Although an unload of the AppDomain will certainly trigger it.
You normally need to quote the field name in this case. For example: select * from t1 where "street 1" = 'test'; or select "street 1" from t1; I tried this on a paradox 7 table and it worked. If that doesn't help, can you post the query you are trying to use? It would be easier to help with that info.
You normally need to quote the field name in this case. For example: select * from t1 where "street 1" = 'test'; I tried this on a paradox 7 table and it worked. If that doesn't help, can you post the query you are trying to use? It would be easier to help with that info.
I always figured this was because remove() has no reason to care what type of object you give it. It's easy enough, regardless, to check if that object is one of the ones the Collection contains, since it can call equals() on anything. It's necessary to check type on add() to ensure that it only contains objects of tha...
No - the GIL just protects python internals from multiple threads altering their state. This is a very low-level of locking, specific to the python internals. It doesn't cover the *application* level locking you'll need to do to cover thread safety in your own code. The essence of locking is to ensure that a parti...
No - the GIL just protects python internals from multiple threads altering their state. This is a very low-level of locking, sufficient only to keep python's own structures in a consistent state. It doesn't cover the *application* level locking you'll need to do to cover thread safety in your own code. The essence...
I really like the <a href="http://xstream.codehaus.org/">XStream</a> library. It does a really good job of outputting fairly simple xml as a result of a provided Java object. It works great for reproducing the object back from the xml as well. And, one of our 3rd party libraries already depended on it anyway. ...
Is there a function in python to split a word into a list?
|python|function|split|
Is there a function in python to split a word into a list of single letters? e.g s="Word to Split" to get wordlist=['W','o','r','d','','t','o' ....]
As far as I know (correct me if I'm wrong!), there isn't. I'd recommend you to use a div with a negative-margin-h1 inside. Depending on the semantic structure of your document, you could also use a fieldset (HTML) with one legend (HTML) inside which approximately looks like this by default.
If you are looking purely at hardware you will need to search for benchmarks around the web. There are a few articles written just on the performance of hardware on Visual Studio compilation, I am just too lazy to find them and link them. Hardware solutions can be endless because you can get some really high end qui...
OK, I have been working on this and ended up creating a stress-test module to basically hammer the crap out of my code from several threads ([See Related Question][1]). It was much easier from this point on to find holes in my code. It turns out that my code wasn't actually far off, but there was a certain logic pat...
One of the biggest bandwidth hogs at $work is download web advertising, so I'm looking at the low-hanging fruit waiting to be picked. I've got rid of Google ads, now I have Microsoft in my line of sights. So I run a tail on the log file, and pick out the lines of interest: tail -F /var/log/squid/access.log | \ ...
convert timestamp to alphanum
|algorithm|time|
I have an application where an user has to remember and insert an unix timestamp like 1221931027. In order to make it easier to remember the key I like to reduce the number of characters to insert through allowing the caracters [a-z]. So I'm searching for an algorithm to convert the timstamp to a shorter alphanum versi...
You could just convert the timestamp into base-36.
The most common enum case is enumerated values that are part of a State or Strategy design pattern. The enums are specific states or specific optional strategies to be used. In this case, they're almost always part and parcel of some class definition class DoTheNeedful( object ): ONE_CHOICE = 1 ...
aha! in the 'compile' tab under properties, the 'generate documentation' checkbox was not ticked. looking at SVN it looks like someone checked in the VB projects with this unticked, for some reason. thanks for the help! it's my first time using this site. looks like the guys involved have done a good job. i lo...
Best way to randomize a string array in C#
|c#|algorithm|string|random|
I was just wondering what is the best way to randomize an array of strings in C#. My array contains about 500 strings and I'd like to create a new Array with the same strings but in a random order. Any suggestions?
If you're using Perl, my [CLI::Application][1] framework might be just what you need. It lets you build applications with a SVN/CVS/GIT like user interface easily ("your-command -o --long-opt some-action-to-execute some parameters"). [1]: http://search.cpan.org/~jkramer/CLI-Application-0.02/lib/CLI/Application.p...
Delete all data for a kind in Google App Engine
|python|google-app-engine|