Cutest dog/bear thing

          0 votes
July 8th, 2008

I was cleaning up my desktop and found this picture of the cutest little dog I've ever seen. I dunno where I found it from, googling or something but I can't find what's this dog called. It looks kinda like a teddybear but a dog?

Cutest Dog

If you know what this please add a comment or email me!

Share/Save/Bookmark

Bitwise Configurations - Crash Course

          0 votes
July 3rd, 2008

Using bitwise configurations in software can have its advantages when you want to store a multiple configuration values within a single value. The only disadvantage (I see) with this technique is you cannot exactly query for a specific permission in your database if you are storing the configuration there but otherwise if that's not necessary it might be an advantage along with the fact of its simplicity.

Note: It might help if you have any knowledge of binary numbers but its not necessary.

Jumping Right In!

That's right! Its a crash course so lets just jump right in! With bitwise configurations each configuration is a number, but not just any number, they go by multiples of 2 starting from 1. For our example, I'm going to make up five configuration settings to play with that will determine my application's error settings. These can be anything of course. People sometimes use bitwise operations with permissions but anyways here we go...

ERROR_WARNING = 1
ERROR_CRITICAL = 2
ERROR_UNSUPPORTED = 4
ERROR_DEPRECATED = 8
ERROR_FATAL = 16

There we have our configuration, as you see each setting starts at 1 and goes up by multiples of 2.

So now lets say I want to configure my program to report all critical, deprecated, and fatal errors. That would simply be the sum of those configurations:

ERROR_SETTINGS = ERROR_CRITICAL[2] + ERROR_DEPRECATED[8] + ERROR_FATAL[16]

Usually when you configure *nix programs with something like this you don't use the + operator but instead a pipe, |:

ERROR_SETTINGS = ERROR_CRITICAL | ERROR_DEPRECATED | ERROR_FATAL

The above syntax is usually valid in most programming languages. At least Python, Java, C, and PHP off the top of my head. So now we have ERROR_SETTINGS equal to 26.

To check if we have a specific setting configured in ERROR_SETTINGS, such as ERROR_UNSUPPORTED we could simple do:

ERROR_SETTINGS & ERROR_UNSUPPORTED

That will return 0 because ERROR_UNSUPPORTED has no bits that match 26. To explain it further lets take our numbers and look at them at as binary numbers:

26 = 11010
4 = 100

As you see the 1st 0 from left needs to be 1 in order for 4 to match 26. So if our ERROR_SETTING included ERROR_UNSUPPORTED its value would 30 and its binary number 11110 thus 4 (binary 100) would match.

When testing if your configuration contains a certain setting using &, as long as it returns anything greater than 0 then your good! ... Otherwise its not part of the configuration.

Conclusion

I hope this crash course made sense to you. If you are still a little unclear how it works wikipedia has a thorough tutorial explaining how bitwise operations work and a good explanation of binary numbers.

Also, if you are programmer it sometimes might make sense to use bitwise operations to store configuration values because as we know, computers are mathematical machines and its what they do best. Its by far way less expensive to check if a configuration exists using the bitwise technique as opposed to storing your configurations in a list or dictionary and looping through them to check if what you are looking for exists.

Share/Save/Bookmark

Party at the Playboy Mansion!

          0 votes
June 3rd, 2008

Watcha know about that!?!?

Me at Playboy Mansion party!

Sorry! Had to brag. I know developer conferences are just as fun ;-)

May 30th, 2008. Spike.com launch party at the Playboy Mansion!

Share/Save/Bookmark

Fix Your Accent!

          0 votes
April 16th, 2008

Fix Your Accent!

So I was driving home on my usual route from work yesterday on Bundy blvd. in Santa Monica when I happen to notice a sign taped on a street light regarding fixing your accent! Seriously wtf! I don't know about you but I wish I had an accent... If I had an accent girls would be on me like flies on sh**!!! Seriously, we all know how fast girls drop their panties when some annoying guy with an accent comes around then we all wish we had an accent! Hmm, maybe thats what this is about? Blah blah...

I haven't actually called the number posted on it to see if this is real or not but the nerve to actually post this is comedy to say the least! If you can't read the number its (310) 930-8070.

I have to admit though, I am annoyed by certain accents (and no I'm not going to say which ones because I'm not trying to hang myself here) so maybe some good might come out from this person trying to do his community a service!

Share/Save/Bookmark