DECLARE @test varchar(10)
SET @test = '12/31/2011'
DECLARE @test_date datetime
SET @test_date = CONVERT(datetime, @test, 101)
Tuesday, June 14, 2011
T-SQL Convert string to datetime
This is the kind of stuff you don't wanna waste time on - and yet ...
Wednesday, April 27, 2011
Heads or Tails? or: how to lose money at the roulette table
I've always wondered how many heads/tails you'd get in a row if you could just keep flipping coins forever. The other day I was bored so I put together a stupid matlab script to try it out (leaving out the "forever" bit).
It's obvious that in theory you could get a never ending series of heads or tails, but in practice that is infinitely unlikely to happen, so I just wanted to get a feel for a "reasonable" figure in terms of how many repetitions one should expect to experience if one actually started tossing coins (or betting money on red/black at the roulette) for a very long time.
Out of 100 million series of coin tosses (where a series is defined by an uninterrupted streak of heads or tails) the longest streak of identical outcomes was 26 (I wanted to try with a billion series but was taking too long).
That means that if you go to a casino to make money doubling bets on red/black (the so-called Martingale strategy) and you are particularly unlucky you might have to flush out 20*(2^25) = 671,088,630 $ (a single bet is usually at least 20 $) on your last bet to actually make a profit (plus all the money you spent to get there).
If you play smart though, and you wait for 5 reds/blacks in a row before you start betting against that, then you can get away with a last bet of only 20*(2^20) = 20,971,520 $ (that's 20 millions!).
It's obvious that in theory you could get a never ending series of heads or tails, but in practice that is infinitely unlikely to happen, so I just wanted to get a feel for a "reasonable" figure in terms of how many repetitions one should expect to experience if one actually started tossing coins (or betting money on red/black at the roulette) for a very long time.
Out of 100 million series of coin tosses (where a series is defined by an uninterrupted streak of heads or tails) the longest streak of identical outcomes was 26 (I wanted to try with a billion series but was taking too long).
That means that if you go to a casino to make money doubling bets on red/black (the so-called Martingale strategy) and you are particularly unlucky you might have to flush out 20*(2^25) = 671,088,630 $ (a single bet is usually at least 20 $) on your last bet to actually make a profit (plus all the money you spent to get there).
If you play smart though, and you wait for 5 reds/blacks in a row before you start betting against that, then you can get away with a last bet of only 20*(2^20) = 20,971,520 $ (that's 20 millions!).
Friday, April 8, 2011
Disable DIV with jQuery
Here's a lame trick I use to disable divs:
Disabling the whole div doesn't seem to disable inputs in chrome and firefox though, so here's the alternative version drilling down to each single input elements:
Good hacking.
// this works on IE// disable$('#myDiv').attr('disabled', 'disabled');// enable$('#myDiv').attr('disabled', '');
Disabling the whole div doesn't seem to disable inputs in chrome and firefox though, so here's the alternative version drilling down to each single input elements:
// this works everywhere but looks weird in IE// disable $('#myDiv :input').attr('disabled', 'disabled');// enable$('#myDiv :input').attr('disabled', '');
Good hacking.
Sunday, February 13, 2011
Get list of OpenCL supported devices with jogamp.jocl
I recently got started on GPGPU, and the natural choice seemed to be OpenCL, since it's supported by both ATI and nVidia. The nice thing about OpenCL (other than being cross-platform) is also that it provides a layer of abstraction that allows you to use both CPUs and GPUs (not only GPUs as for nVidia's CUDA and AMD's Stream technologies).
I started investigating a few java wrappers (there's only a handful around) and ended up playing with jogamp.jocl.
This is just a snippet showing how to retrieve a list of OpenCL enabled devices on your machine:
Goes without saying that if you don't see your GPU in the output it's time for some painful driver sweeping. I found that Snow Leopard works straightaway with both ATI and nVidia (MacOSX 10.6.x ships with OpenCl support), while windows can be a bit trickier to setup (as we all know, Catalyst software kinda sucks).
Just to give you a sneak-peek at what comes after, once you've had a look at the output then you can go ahead and select a device to create the queue(s) you'll use for sending data up to the devices:
You can see the entire code for the official jogamp.jocl 'Hello World' example here if you're curious.
I started investigating a few java wrappers (there's only a handful around) and ended up playing with jogamp.jocl.
This is just a snippet showing how to retrieve a list of OpenCL enabled devices on your machine:
// create context for all devices detected using default platform
CLContext context = CLContext.create();
// an array with available devices
CLDevice[] devices = context.getDevices();
for(int i=0; i < devices.length; i++)
{
out.println("device-" + i + ": " + devices[i]);
}
Just to give you a sneak-peek at what comes after, once you've had a look at the output then you can go ahead and select a device to create the queue(s) you'll use for sending data up to the devices:
// have a look at the output and select a device
CLDevice device = devices[0];
// create command queue on selected device.
CLCommandQueue queue = device.createCommandQueue();
Sunday, January 2, 2011
Was Darwin Wrong?
In the beginning it was self-replicators.
Then it was self-replicators with metabolism (which kind of is the definition of life).
Now, to go from self-replicating blobs to human beings it takes a pretty good search algorithm.
Natural selection is that algorithm, and it happens to be the most robust search algorithm there is, beating hands down any other kind of human-designed search tool.
So, was Darwin wrong?
P.S. if you don't believe in facts then there is very little that can be done to convince you
Then it was self-replicators with metabolism (which kind of is the definition of life).
Now, to go from self-replicating blobs to human beings it takes a pretty good search algorithm.
Natural selection is that algorithm, and it happens to be the most robust search algorithm there is, beating hands down any other kind of human-designed search tool.
So, was Darwin wrong?
P.S. if you don't believe in facts then there is very little that can be done to convince you
Subscribe to:
Posts (Atom)