jscalendar shows at the top of the screen in IE7
jscalendar v1.0 has a bug that makes the calendar displays at the top of the screen in IE7.
Here is a patch that fixes it.
reference: http://drupal.org/node/118926
jscalendar v1.0 has a bug that makes the calendar displays at the top of the screen in IE7.
Here is a patch that fixes it.
reference: http://drupal.org/node/118926
A simple macro to rotate the bits of an unsigned 32-bit value. using shift-left and shift-right we can achieve rotate-left and rotate-right.
#define rotlFixed(x,n) (((x) << (n)) | ((x) >> (32 - (n))))
#define rotrFixed(x,n) (((x) >> (n)) | ((x) << (32 - (n))))
The macro above can be trivially converted to a function and used in C# for example.
I found this little JavaScript utility that tests for the existence of a specific font on the client machine.
I thought it would be very handy to use for my church’s website (coming soon) which will probably have some content written in the Coptic language.
Most probably we will be using Athanasuis font.
Anyways, I want to save the script here in case the original site goes down or something.
The script is released under Apache License, Version 2.0
I stumbled on this series of youtube episodes at digg.com and I think they are amazing.
if you have a few minutes check them out. each episode is like 5 minutes long.
Here is episode #2 but definitely check out the other episodes as well in the related videos section.
This post is in regard to Jeff Atwood’s post on Shuffling and The Danger of Naïveté.
In his second post he used an example of shuffling three-card deck 600,000 times to explain how naive solutions can be dangerous. The post is extremely well written. I enjoyed every bit of it. However I had two questions that I couldn’t find an answer for in Jeff’s post. Why exactly 3 permutations (out of the 6 possible ones) are biased? and why those 3 specifically are biased and not any other permutations?
I spent sometime thinking about it and using a pencil and a paper I was able to get some answers.
First here is the naive method: (I reversed the loop to be as similar as possible to the correct method)
for (int i = cards.Length - 1; i >= 0; i--)
{
int n = random.Next(cards.Length);
Swap(ref cards[i], ref cards[n]);
}
And here is the correct one (Knuth Shuffle)
for (int i = cards.Length - 1; i > 0; i--)
{
int n = rand.Next(i + 1);
Swap(ref cards[i], ref cards[n]);
}
Now let’s agree on some facts real quick. For a three-card deck:
The answer to the first question above, is that 27 mod 6 is equal to 3. What that means is there are 3 extra sequences of random numbers that have to map to 1 (or 2 or 3) of the 6 unique permutations of the deck.
To answer the second question we have to note something first about using swapping to perform a shuffle, take a look at the state of the deck at each iteration given the following random numbers:
|
|
Notice how the two different sequences of random-numbers resulted in the same permutation of the deck. Now remember there are 27 possible sequences and only 6 unique permutations. if we divide 27/6 we get 4 (with remainder 3) which means there are at least 4 paths (or sequences) for every unique permutation of the deck, the 3 extra possible sequence lead to 3 of the unique permutations giving them an advantage over the other 3.
so basically we have 6 permutations of the deck, 3 of them have 4 random-number sequences that lead to them, and the other 3 have 5 sequences that lead to them.
In this particular example if you follow the algorithm above and try the following random-number sequences you will get the same deck permutation for all 5.
The problem with the Naive shuffling method is swapping! The fact that swapping elements in 2 (or more) different sequences can lead to the same deck permutation is a subtle problem.
The Knuth shuffle algorithm avoids that problem by ensuring N! possible random sequences where N is the number of elements in a deck (or any container).
Declaring function pointers in C\C++ has a somewhat strange syntax, specially when you want to specify a function pointer as the return type of another function.
so here is a brief explanation:
To declare a pointer to an int called pNumber:
int *pNumber;
To declare a pointer to a function called pFunc (that has a string parameter and returns an int):
int (* pFunc)(string);
in red is the variable name, in purple is the type.
To declare a function that returns a pointer to a function:
int (* GetFuncPointer(void) )(string);
in red is a normal function declaration, in purple is the return type of that function.
S o basically int(*)(string) is the type of the function pointer.
If we want to declare a function that takes a function pointer as a parameter then we would write something like this:
void RegisterCallBack( int(*)(string) ); /* unnamed parameter */
or
void RegisterCallBack( int(*myCallback)(string) ); /* named parameter */
A prettier way to use function pointers is to use typedef to declare an alias. The typedef syntax is exactly the same as declaring a regular variable (or a function pointer).
typedef int(*FunctionPointer)(string);
now we can use FunctionPointer like this:
FunctionPointer GetFuncPointer(void);
I’ve always read that marking a function inline doesn’t guarantee that the compiler will actually inline it, but it’s merely a hint to the compiler to “try its best” to do it. Which have always raised the question in my head, how do I know if Mr. Compiler agreed to inline my function? Do I have to look at the generated assembly code? There has to be an easier way!
So I invested 15 minutes researching that issue and found out that Mr. Compiler is friendly enough to let you know if it was not possible to fulfill your request to inline a certain function by issuing a warning.
For Microsoft’s VC8 compiler warning C4710 is turned off by default, you can turn it on by doing any of the following (depends on your choice):
#pragma warning (default : 4710)#pragma warning (custom_warning_level : 4710)For GCC the -Winline switch can be used to achieve the same thing.
Since I forget the steps every single time I try to install or upgrade linux I’ll write them down.
There is another method I found, that seems to work for a lot of people:
I’m a big fan of anagrams, they are very interesting to me, they are mysterious, funny and sometimes true..
quoting a phrase on my favorite anagram generator site “All the life’s wisdom can be found in anagrams. Anagrams never lie.”
here are a few interesting anagrams for the word developers:
Anagrams are amazing..
Indicates that the name following represents a parameterized type placeholder that will be replaced by a user-specified actual type.
consider the following example:
template<class T> class A
{
T::x(y); // ambiguous: calling a function or constructing an object?
// without ‘typename’ this will be interpreted as a function call
typedef char C;
A::C d;
}
The statement A::C d; is ill-formed. The class A also refers to A<T> and thus depends on a template parameter. You must add the keyword typename to the beginning of this declaration:
typename A::C d;
You can also use the keyword typename in place of the keyword class in template parameter declarations.
typename was introduced after the keyword class to solve the problems shown above, but both keywords are equivalent in declaring template parameters.