Archive for the Uncategorized Category

image path obfuscation

Posted on Friday, September 30th, 2011 at 12:18 pm

Someone in my office asked me to hide image URL. The problem is, we’ve a bunch of pictures of students and we don’t want any one to download all of them. The pictures are named by student ID, so it will be easy to write a small code to iterate all ID and download all the pictures. That’s why we need to hide the image URL.

At first, I want to make a hash function. So, it will be harder to break. However, we need a storage to store all hash, either in database or in file, which is I don’t want to . So, hash is gone. The other choice is encryption.

What I did is to write two code, first one is to generate an encrypted text from student id. Then, the second code, convert the encrypted text back to id. So, the image URL will include the encrypted text instead of picture’s name. So, instead of

http://www.foo.com/image/512345.jpg

the url will be

http://www.foo.com/image/get_picture.php?hash=21342u987891234

To do this, I use mcrypt function in php to encrypt and decrypt, this is nothing special.

However, I feel like this method will be a victim of known-plaintext attack. Because the website that shows this picture also shows student ID and everyone can guess that the picture’s name should be the ID itself. So, I would like to change the key periodically. So, I make a cron script to change the encryption key every day. It will be harder to crack the encryption.

The code is here

ขึ้นอยู่กับดินฟ้าอากาศ

Posted on Wednesday, April 20th, 2011 at 9:43 pm

ค่าไฟที่บ้าน เป็นไปตามฤดูกาล

The confession of a lonely late night programmer ^_~

Posted on Sunday, April 17th, 2011 at 10:40 am

Invictus

Posted on Friday, May 21st, 2010 at 4:03 pm

Out of the night that covers me,
Black as the pit from pole to pole,
I thank whatever gods may be
For my unconquerable soul.

In the fell clutch of circumstance
I have not winced nor cried aloud.
Under the bludgeonings of chance
My head is bloody, but unbowed.

Beyond this place of wrath and tears
Looms but the Horror of the shade,
And yet the menace of the years
Finds and shall find me unafraid.

It matters not how strait the gate,
How charged with punishments the scroll,
I am the master of my fate:
I am the captain of my soul.

William Ernest Henley

Less addicted.

Posted on Monday, April 26th, 2010 at 9:26 pm

I’d been 77% addicted before, now, I’m only 34%

34%How Addicted to Apple Are You?

Created by OnePlusYou – Free Dating Site

The quest for my ultimate toilet device.

Posted on Wednesday, April 21st, 2010 at 11:57 am

Like most people, I need a device for reading/internet surfing/gaming/etc.  in a toilet (you don’t ? really?).  The criteria are simple: small, lightweight, large enough screen, long battery life, good internet connection, support many formats and sit comfortably on my lap.

HP 300LX Handheld PC

Let’s start with the old guy. On the top left, you got HP 300LX. It is a pocket-pc (handheld pc, to be exact) with Windows CE 2.0. I got it from Ebay with very cheap price and it works very well. The problem is, it doesn’t have built-in Wifi. So, I bought a PCMCIA Wifi card, yes, the device has a PCMCIA and a CF slot. Then, the next problem comes, using Wifi will drain your battery (it uses AA batteries) in a matter of minutes. So, you need to plug the AC adapter all the time. Moreover, the keyboard is too small. Well, I can do a short not typing from time to time, but it’s a painful process.  For the ebook reading, the screen is nice but too small and you can’t read any modern ebook format, so, just stick with .txt or .pdb then.

The good:

  • Very small and lightweight
  • Long battery life (with no Wifi) and it uses AAs.
  • BW LCD screen is easy to read
  • It is very stable, never hang on any occasion.

The bad:

  • With Wifi connection, you need AC adapter
  • The screen is too small and resolution is too low
  • The keyboard is next to useless.
  • It has Pocket Word and Excel, but they are not compatible with the desktop counterparts -*-.
  • No support for modern ebook format is the reason I moved on.

The ugly:

  • You can’t place it on your lap comfortably, that’s a big problem for a toilet reading machine.

iPod Touch

Next one, top middle,  is an Apple product, an iPod touch. I’ve been an Apple zealot for sometime, but now, I’m converted.  iPod touch is very nice ebook reader device with nice screen and support many formats (with a handful of ebook reading applications). The problem is, the screen is too small. You have you focus your eyes on that small screen and that will hurt your eyes easily. I really like it as internet device, PDA and game console. But as an eBook reader, I don’t like it much.

The good:

  • Very small and lightweight
  • Good battery life.
  • Screen is bright and clear
  • Stability is acceptable.
  • Lots lots lots of applications and games.
  • It is a great Internet device, giving that, you’ve a Wifi connection.

The bad:

  • Wifi only, so if you’re in a public toilet place without Wifi AP nearby, then you can’t access internet.
  • No physical keyboard, virtual keyboard is ok.
  • You can hold it in your hand while using it, not a best position for a toilet device.
  • Screen is too small for ebook reading.

The ugly:

  • It’s an Apple device, you can either kiss Jobs’ ass and buy everything from Apple, or go somewhere else.

Fujitsu Stylistic Tablet

The top right is a tablet from Fujitsu (Stylistic 5xxxx somthing). Again, I got it from EBay for $50 something. It has a 233 MHz CPU (slower than iPod touch!!) and Windows 2000.  It can access Internet though a PCMCIA Wifi card (I just use the one I bought for the pocket PC). Because it’s running windows, plenty of applications and games are available. However, like most second-hand notebook/tablet, the battery is not great. I can use it for 1.5-2 hrs when I first got the device. Then, it is down to 0.5-1 hrs, with is enough for a toilet session but it’s annoying. Beside, the virtual keyboard is stupidly bad.

The good:

  • Screen is large and easy to read.
  • Stability is acceptable.
  • Lots lots lots of applications and games.
  • It is a great Internet device, of course, it is running Windows.
  • It is a great ebook reading machine.

The bad:

  • Battery is not good and you can’t get a new battery from manufacturing.
  • No physical keyboard, virtual keyboard is bad.

The ugly:

  • You can’t place it on your lap comfortably, it will be hard to read and too hot to hold on your lap.

Asus EEE PC 900

Next one, because I decided to convert from Apple geek to something else, so I sold my macbook to someone and got a netbook. I don’t use macbook in toilet because of its size and also its temperature. A netbook seem to be a good compromise between a main computer device and a toilet device, which I found out that it’s not true. The problem of the netbook is that it is not design to be used on your lap for a long time. You have to bend your neck in a great angle to read  the screen, and that is a painful position. Anyway, I keep the netbook for my main computer device and find something else for my toilet.

The good:

  • Stability is good.
  • Lots lots lots of applications and games.
  • It is a great Internet device, of course, it is running Windows Ubuntu.
  • It is a great ebook reading machine.
  • Battery life is great, you can get 5-6 hours for Internet surfing.
  • Keyboard is nice, not perfect, but better than a virtual one.

The bad:

  • The screen is large, but because it’s a full OS, you lost plenty of screen estate.

The ugly:

  • You can’t place it on your lap comfortably, your will get a neck pain very soon. Also, it’s quite hot sometime, especially, when you play Flash movie.

Nokia N810 Internet Tablet

In the center is Nokia 810 Internet Tablet, I decided to try a mobile internet device again. This time, it’s not from Apple. It’s a great device with lots of features. You can even play Flash game or watching youtube on it. However, the problem is that it is using not-so-popular OS, applications and games are scratch. You will love it as an Internet device if you  use only web-browser. But for ebook reader, games, other applications, it sucks.

The good:

  • Stability is good.
  • It is a great Internet device, of course, it is running Linux.
  • It is a great ebook reading device, if you can live with .txt and .pdb.
  • Battery life is great, you can get 4-5 hours for Internet surfing.
  • Sliding keyboard is nice, not perfect, but better than a virtual one.

The bad:

  • The interface is ugly.
  • No applications.
  • You can hold it in your hand while using it, not a best position for a toilet device.

The ugly:

  • Only a few Ebook reader applications and all of them are buggy and slow.

Sony EReader PRS505

On the bottom right, you got a Sony ereader PRS505. I bought this because of NungNing, she got one and she loves it. Beside, I really want one for sometime. As an ebook reader, it’s perfect. But, as an Internet device, it’s …… nothing. Well, it’s an ebook reader :)

The good:

  • Stability is super great.
  • It is a great ebook reading device, supports many popular format such as PDF or ePUB.
  • Battery life is great, you can get  1-2 weeks of continuous reading.
  • The screen is superb, just like a real book.
  • It’s comfortable to use, you just hold it like a pocket book.

The bad:

  • It’s an ebook reader, nothing else. (oh, it can play MP3 songs, btw)

The ugly:

  • No Internet.

Samsung Galaxy Spica

The last and the current device I’m using in the toilet now is a mobile phone, with Android OS. You can see it at the bottom of the picture. It’s pretty much like iPod touch, but with GPRS/EDGE connection, you can access Internet in any toilets.

The good:

  • Very small and lightweight
  • Good battery life.
  • Screen is bright and clear
  • Stability is acceptable.
  • Lots lots lots of applications and games.
  • It is a great Internet device.

The bad:

  • No physical keyboard, virtual keyboard is ok.
  • You can hold it in your hand while using it, not a best position for a toilet device.
  • Screen is too small for ebook reading.

The ugly:

  • Not so far, the screen is a bit small, but it’s good enough for Internet surfing and occasionally ebook reading.

GA law

Posted on Tuesday, March 30th, 2010 at 8:55 am

image

Classic.

http://xkcd.com/720/

Committed

Posted on Wednesday, February 10th, 2010 at 8:18 pm

The new patch of my life is committed and accepted. Let’s see whether it’ll generate any dependency or conflicting bugs…….

Life, early.

Posted on Saturday, February 6th, 2010 at 6:53 am

I usually work at night, like most programmers I know. But recently, I wake up early, i.e., before sunrise, and somehow I can accept it. Isn’t it a sign of old age?

FIXME and TODO

Posted on Sunday, October 18th, 2009 at 3:11 am

Usually, when I write code, sometime I put comments with TODO and FIXME, the former one means that this fragment of code is just a temporarily one, kind of quick fix or patching the balloon. I know I need to do further, but the priority is low. The later one, I know it might has some possible bugs, but I believe it’s not crucial or rare to occur. So, just leave it there and take my chance.

How about life? how many TODO and FIXME we’ve placed along the way? I’ve plenty, I know. Question is, when should I fix those TODO and FIXME, well, it should not be another TODO… Otherwise, it’ll be infinite loop of TODO, which is very bad.

Try to resolve your TODO and FIXME as soon as possible, both in your code and in your life. Your life is shorter than you think and your code can break earlier than you think.