Random things I've written

MongoDB's explain() might lie to you when querying with $ne

1 Nov 2015

Please note that this is MongoDB 2.6.11. I have been trying to optimise MongoDB, and I have figured out how indexing for `$ne` works. Here's one gotcha: __MongoDB will decide to indexes based on

Implement Ruby's attr_accessor with Scala's macros

28 Sep 2015

Note: this is to show the power of macros. If you need this feature, just use a case class. As an exercise to learn macros, I have been trying to implement Ruby's attr_accessor with Scala's macros.

Using Scala's macros to build a better log()

28 Sep 2015

I'd like to build a better log function. You know, normally, you have to log variables like this: ```scala log(s"Some msg [count = ${count}]") ``` You can see that `count` is redundant. We sho

How to lose a commit with a combination of git-merge, git-rebase, and git-amend

10 Sep 2015

Note: git's version is 2.3.2 (Apple Git-55) I have encountered a way to lose a commit by accident. If you're using a combination of git-merge, git-rebase, and git-amend, you should read on. I ha

shippable.com's after_script doesn't work

28 Jun 2015

I was stuck at this problem for almost 5 hours. It's difficult to debug because of a long test cycle. I've found that, when a command in the `script` block fails, the `after_script` block is not ru

Google API invalid_grant problem

14 Jun 2015

When changing a server, I've got an authorisation error from Google API that looks like this: ``` { "error" : "invalid_grant" } ``` This is because the date/time on the server is not corre

Reading command line options with Scala

12 Jun 2015

Here's a short code for reading command line arguments: ```scala def readCommandArgs( args: List[String], argsSoFar: List[(String, List[String])] ): List[(String, List[String])] = {

Don't ever touch the already-run Play evolution file

8 Jun 2015

This is because Play computed checksum and store it in the database. If you change it, Play will try to apply DOWNs until the changed file and apply UPs. That's very very dangerous.

tail-grep interested information from stdout

7 Jun 2015

When we run a command, we should pipe it to the `tee` program: ``` run_some_command | tee /tmp/some_temp_file ``` Then, we can open another terminal and run: ``` tail -f /tmp/some_temp_fil

Debugging SSH

26 Apr 2015

When I setup a new user on a server, I always have a problem with logging in with the new user using its public key. Today I've found a way to debug it by stopping the SSH service and starting it w

Google CodeJam Qualification Round 2015

14 Apr 2015

[The 4 problems for the qualification round](https://code.google.com/codejam/contest/6224486/dashboard#s=p0) are quite interesting. The style of a problem is a bit different from the TopCoder's one; a

TopCoder: MaliciousPath (SRM 652)

1 Apr 2015

For this problem, I was lost a few times, and the obstacles made me stuck for a very long time. The first obstacle was that I didn't formulate the problem properly. After deciding to formulate it,

Get out of your own way

22 Mar 2015

I've just finished the book "Get out of your own way". It's embarrassing to read a book similar to this one. The book explains 40 destructive behaviours and offers ways to overcome them. A destructive

TopCoder: FoxConnection3

21 Mar 2015

The problem editorial is here: [http://apps.topcoder.com/wiki/display/tc/SRM+651#FoxConnection3](http://apps.topcoder.com/wiki/display/tc/SRM+651#FoxConnection3) I couldn't solve this problem on my

Day 0

14 Mar 2015

I've just returned my badge and my laptop today. I've walked out of the Twitter office for the last time. I couldn't believe that today would eventually come. The feeling was surreal. I feel sad and e

A state machine contains another state machine

6 Jan 2015

Today, I've just implemented a state machine that contains another state machine. It confused the heck out of me. Normally, a state machine can be implemented with a 2-dimensional array pretty easi

An immutable circular graph in scala

5 Jan 2015

I was building a state machine in Scala, and I want it to be an immutable state machine, where all nodes are immutable. It's actually a bit interesting how we can achieve it in Scala. Let's define

Identifying Collocation

31 Dec 2014

I've been reading the book [Foundations of Statistical Natural Language Processing](http://nlp.stanford.edu/fsnlp/). I should have read it a long time ago, so I've decided to read cover-to-cover. It's

Using Postgres on Heroku with Play 2

26 Dec 2014

It's a bit of a dance because Heroku set the environment variable ```DATABASE_URL``` that contains username and password. So, you will need to force the driver to read username and password from the U

New blog launched!

26 Dec 2014

This blog is built with Play 2. Play 2 is kind of cool, and I'm in love with Scala (over Ruby). Nevertheless, I still love Ruby for building a command-line tool. At least, I prefer Ruby over Py

ctags for scala

1 Dec 2014

It turns out there are 2 ctags binaries on OSX. One is from XCode toolchains. The other one I install it from brew. Be careful with it. Here's the configuration in ~/.ctags that makes ctags for

Start tmux with -u

29 Nov 2014

Always do this! otherwise, character rendering will look really odd.

tmux doesn't reload tmux.conf

26 Oct 2014

That's because we need to exit all tmux's sessions and restart it.

Learning vim

19 Oct 2014

I'm gonna learn vim seriously now. I believe this can make me work faster. There are 2 things I want to achieve: 1. Code on a remote machine. It will be faster because the deployment will be super fa

Productive Terminal (zsh + TotalTerminal)

15 Aug 2014

I just installed oh-my-zsh today and upgrade TotalTerminal (TotalTerminal's previous version is broken on my Mac) Here are the settings I use: ```bindkey "\C-f" vi-forward-blank-word``` and ```bindk

Move to the next space in bash

10 Aug 2014

As I am learning all the bash shortcuts, I've found that moving forward and backward by words are not very useful. I don't normally want that. Moving forward and backward by spaces seem to be more va

ArrayList<Integer> is more costly than int[] in Java

16 Jul 2014

Yesterday I was having a great idea of instantiating an ArrayList once and re-use it instead of instantiate an array of int[] everytime. It turns out that the performance is much worse. There are 2 p

Quick-win on OpenJDK's Thai Tokenization

13 Jul 2014

OpenJDK has pretty decent Thai tokenization library. Nevertheless, there are some quick wins that can be implemented. For example, there are some patterns that are not sensible whatsoever. See this r

OpenJDK's Thai Tokenizer explained

11 Jul 2014

This week is the Twitter's Hackweek. Basically, we are allowed to do/build whatever we would like to. So, I've decided to learn more about Thai tokenization (or Thai word segmentation) in OpenJDK. He

Command pattern is bad for Storm

3 Feb 2014

I have been very confused by the serialization issues because I was trying to use the Command pattern and try to attach external dependencies (e.g. a finagle client, which is a network-thingy client)

I wish there was @noimplicit in Scala

3 Feb 2014

It would prevent an object from being implicitly converted. I have a problem with instantiate a class within FunSpec because it would be implicitly converted. After it was implicitly converted, it ha

.@trasient prevents Serialization but will be nil

2 Feb 2014

Yeah, it will just become nil.

tiny_daemon -- An easy way to daemonize your Rake task

2 Jan 2014

I have researched about how to daemonize my Rake task and how I can use it in my deployment script. I need a background task that is running all the time (not a cron job) and it should be restarted w

Daemonize your rake task

2 Jan 2014

THIS IS NOT GOOD ANYMORE. The gem `daemons` doesn't seem to be well-maintained, and Ruby 2.0 has a cleaner way of daemonizing. --------- So, I have been stuck with daemonizing a rake task for a whil

Learning new things

25 Dec 2013

I forgot how to pick up a new skill because I haven't really learned anything new skill anymore. I just took a ski lesson a few days back; It took me like a while to know how to slow down on ski with

Non-thread-safe class is evil

20 Nov 2013

Encountered 2 of them: * ByteBuffer * SimpleDateFormat The error message usually doesn't make any sense. The input format is incorrect is one of them (even when you print it out, it looks correct)

Max out the CPU usage

17 Oct 2013

You may use `yes > /dev/null &` What it does is that it prints 'y' repetitively. Running multiple of these things will max out your CPU Please see `man yes`

Insert a record with duplicate keys (MySQL)

23 Sep 2013

You can bypass that by using: * REPLACE * INSERT ... ON DUPLICATE KEY UPDATE * INSERT IGNORE (a bad one because it also ignores other errors)

Hadoop job with too large of data

23 Sep 2013

I request to read data for 6 months. I guess it was way too big. If it is too big, you will get this obscure exception: ``` Failure Info:Job initialization failed: java.io.IOException: Split metadata

Ruby system with environment variables

23 Sep 2013

When running a bash command from Ruby with a environment variable. Don't do this: ``` system('GARUDA_ENV=prod echo $GARUDA_ENV') ``` It won't work... Please do this ``` system({"GARUDA_ENV" => "pro

Scalding's hardcoded source

19 Aug 2013

If you want to hardcode some userIds, you can use this source: IterableSource. ``` IterableSource(Seq(1, 2, 3), 'user_id).read ```

Scalding: Choosing the right Join's type to speed up

19 Aug 2013

We can optimize on joining sources; Say we have the sources, A and B. If A is relatively of the same size as B, we use the normal join (e.g. joinWithSmaller). If A is much much smaller than B, but A

Allow a user to sudo

6 Aug 2013

You can edit the list of sudoers (the users who can sudo) with: ``` visudo ``` And then add this line: ``` patcy ALL=(ALL) NOPASSWD: ALL ``` to the appropriate place. Please google on what th

mock[Future[Object]] will hang

29 Jul 2013

Never ever ever do that. Just do ```Future.value(mock[Object])```

Double RR to return different results

2 Jul 2013

You can just mock it twice: ``` mock(favor).test(1) { true } mock(favor).test(1) { false } ``` The first time it is invoked it will return true, and the second time it will return false. It is supe

Puppet lesson

30 Jun 2013

The first lesson: __You cannot depend on an external module__ There will be discrepancies. Well, you'd better take their modules and modify it to suit your needs. __Pack your own local modules__

/usr/bin/test -d some_file

30 Jun 2013

This is to test if a directory exists. We can use it with file as well

Puppet SSL error when install modules

30 Jun 2013

``` tanin@machine:~/Project/readdaily-puppet (master)$ puppet module install --modulepath=./modules puppetlabs-postgresql Notice: Preparing to install into /Users/tanin/Project/readdaily-puppet/module

Duplicate declaration in Puppet

30 Jun 2013

I have encountered the duplicate declaration problem in Puppet. Here are the things that I learn: __A module (the module path) already exists. You can use them__ This means that, if you want to use

SSH key weirdness

30 Jun 2013

So, I generated a new SSH pair from my laptop. Then, I uploaded the public key to the file ```authorized_keys```. The first time I have to ssh with the private key file with ```ssh -i private_key ta

Mockito to return different results on different calls

24 May 2013

``` profile.count(any) returns Future.Nil thenReturn Future.Nil ``` It's that simple

Mockito to verify variable arguments

23 May 2013

Let's say you have a method's signature that looks like this: ``` def select[A](query: String, params: Any*)(f: ResultSet => A): Future[Seq[A]] ``` When you would like to verify it with a mix of ```

RR stub any instance

16 May 2013

Use this: ``` stub.instance_of(Test).use? { true } ```

SQL to query ancestors (unknown height but know max height)

10 May 2013

Let's say we store a tree in a MySQL table with the columns: id, name, and parent_id We use left join to get all ancestors of it. For example, we know that the max height is 4, so we join 4 times. He

'2 >&1' must follow '>test.log'

5 May 2013

I was stuck at IO redirection. It didn't seem to work. At the end, I have found that '2 >&1' must follow '>test.log'...

Variable arguments and Mockito

3 May 2013

Let's say you have a method ``` def test(t: String, a: Any*) { } ``` Then you invoke it with: ``` val args = Seq(1, "b") test("aaa", args:_*) ``` When you want to verify with Mockito, you have to

Apache Pig CSV loader

24 Apr 2013

It seems we cannot use ```CSVLoader```, but we need to use ```CSVExcelStorage```. Here is an example: ``` data = LOAD 'something.csv' USING org.apache.pig.piggybank.storage.CSVExcelStorage()


19 Mar 2013

I got ```InvalidUseOfMatchersException```, even I already use a matcher in every argument. It turns out that the method has 3 arguments; the last one has a default value. Next time, when you want to

RR mock and stub

17 Mar 2013

`stub()` is for replacing the method implementation `mock().a_method.with_any_args` is for replacing the method implementation AND expecting the method to be called once; You may use `mock().twice` i

update_attributes() and attr_accessible

5 Mar 2013

In ActiveRecord, you cannot invoke ```update_attributes``` on an attribute if you don't declare it with ```attr_accessible```. I was stuck with this problem for about an hour. It was discovered becau

Never use Some. Use Option

1 Feb 2013

This is because ```Some(null)``` is not ```None```, but ```Option(null)``` is ```None```. So, don't use Some... or everyone already knows that.... Another thing is ```null.asInstanceOf[Long]``` is

Throwing exception with Mockito is tricky

26 Jan 2013

If you get this error message: ``` org.mockito.exceptions.base.MockitoException: Checked exception is invalid for this method! Invalid: java.lang.Exception ``` It means that we try to stub throwing

Ruby require secret

22 Jan 2013

It's always annoying that, when you want to require some file, you have to: ```ruby require File.expand_path('../../something', __FILE__) ``` And if ```something.rb``` requires something else in its

Thrift IDL tips

17 Jan 2013

* Thrift IDL is compiled in order. Therefore, you cannot have struct A that uses struct B, but A is above B. You cannot do that * When defining exceptions thrown from a method, you have to name it dif

Mustache/Haml for checking a checkbox

10 Jan 2013

I was trying to find away to elegant check/uncheck a checkbox in Mustache within Haml. And I think I have found an elegant solution. Here it is: ``` %input{ :type => "checkbox", ('{{#tax_deductible}}

Capybara selectbox

27 Dec 2012

Capybara's documentation doesn't explain well. Here is the method ```select```: ``` - (Object) select(value, options = {}) ``` and here is the description: ``` Find a select box on the page and s

Overridden == in Ruby

25 Dec 2012

I am in a situation, where overidding ```==``` produces a beautiful structure. But I'm not gonna explain it here. I've run some experiments to verify that what I do will work. Here is the snippet: `

Mongo 1.6.2 logging

24 Dec 2012

I will separate it into an independent gem later, but here is how I log all the database queries and log the summary usage per request. Rails has a built-in mechanism for instrumenting the things tha

No-complaint for 30 days challenge

24 Dec 2012

Ok, I'm going to try a new challenge. I will stop complaining for 30 days. Complaining is saying anything negatively without offering a solution. For example, I cannot say "I hate that it is raining

Rails Logging Cheatcode

23 Dec 2012

Rails' logging has annoyed me for a very long time. Since I am not around to monitor GIVE anymore, I've decided that I'm gonna make logging more comprehensible, so that I can diagnose what has been go

Rails footnote

23 Dec 2012

[Rails' footnote](http://github.com/josevalim/rails-footnotes) is sooo cool. It adds a bunch of debugging information at the end of every HTML page. You can easily debug your page without looking at

The G(reat)IVE Migration

15 Dec 2012

Right now I'm planning on the migration from [GIVE.sg](http://www.give.sg) to [GIVEasia.org](http://www.giveasia.org). GIVE.sg is built with [Stripes](http://www.stripes.com). Fortunately, we will on

Homelessness experiment

22 Nov 2012

Today I was walking to a breakfast place.. Suddenly 2 homeless guys came to talk to me. He was very nice; He was telling about a few free dinner place that I could go and also about which area was ni

ActiveRecord hidden bug

16 Nov 2012

Today I have encountered a very weird bug. The symptom is that a Model cannot be saved, but ```model.errors``` contains nothing. It took me like an hour to figure out the real cause. It turns out t

Git to apply a diff

14 Nov 2012

We can just get a diff: ``` git diff > patchfile ``` And we can apply it on any branch: ``` patch -p1 < patchfile ```

Check conflicts between multiple branches

12 Nov 2012

I've encountered a weird situation where I need to deploy 5 branches at the same time. I have to check for conflicts between branches, otherwise the conflict pair will be rejected from the deployment.

Add a custom element to Drupal

31 Oct 2012

It is fairly simple. First of all, you must define the new element's type with this hook ```hook_element_info()```. For example: ```php function something_element_info() { return array( "mult

Overcoming the Drupal pain

24 Oct 2012

So, I have been building a Drupal module. I've learned a lot about its architecture. But, there is one pain from building a module: * when enabled, your module needs to install a database schema * y

The master branch is out of sync

19 Oct 2012

For some reason, my local master branch is reported to be ahead of the remote master branch, even though I never modify the local master branch. Katsuya told me it was because the local master branch

A UTF-8 encoded file contains Byte Order Mark

18 Oct 2012

But a UTF-8 encoded string doesn't contain it. Today I loaded a file containing a UTF-8-encoded string, and tried to parse it with CSV. I couldn't really succeed, even I saw that there was nothing w

Habit's change

14 Oct 2012

I am reading the book "The power of habits". It gets me to think about the habits that I've changed. I think the first extremely bad habit that I've eliminated is biting nails. I've been trying to th

Long Distance Survival Guide

10 Oct 2012

Oh yeah... I've read it. I was not a big fan of LDR. When I moved to another country, I always stopped a relationship. My attitude was that LDR sucks and is torturing. Back to the book, it simply pr

Drupal cannot find a hook

4 Oct 2012

Try resetting its cache with ```module_implements('webform_component_info', FALSE, TRUE);```. And here is my code: ``` function multilevel_webform_component_info() { return array( 'multi

WebForm (Drupal) doesn't have presave hook on component

3 Oct 2012

There is no hook, internally. There is one hook ```hook_webform_component_presave()```, but it is for other modules... It's like WTF?!? ------------------- I was wrong. It's just that you have to

Add a component to WebForm in Drupal

3 Oct 2012

__Remark:__ This is a clumsy way to add a component, as the component is integrated into WebForm's source. You can actually build an independent module that utitlizes WebForm's hooks in order to build

I can mend your broken heart

17 Sep 2012

I've evolved my reading list so far that right now I'm reading about relationships, instead of business, programming or some other shits. I vividly remember a friend suggested that I should start rea

TCP Packet design

11 Sep 2012

Do not use the number of characters as the header.. but use the number of bytes..

Bonjour cannot run in a thread

11 Sep 2012

I've been fighting with Bonjour for a day now. Finally, I've figured it out somehow that Bonjour cannot be run in a thread, that ends. If you do that, you have to tell Bonjour to run itself in the ma

NSData to NSString

10 Sep 2012

Please use: ``` NSString *dataStr = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; ``` DO NOT use: ``` [NSString stringWithUTF8String:[data bytes]] ``` It return

Do not put everything in *.h

9 Sep 2012

Today I tried to put everything in *.h in Objective-C. I put the ```@interface``` and ```@implementation``` in only one .h. I don't know why this happens, but XCode will throw out a very weird error

NSMutableArray weirdness

8 Sep 2012

So... let's say you have ``` NSMutableArray *test = nil; ``` And, then, you forget to initialize it. This is one of the weirdest behaviour that I've encountered. You can call ```[NSMutableArray ad

Capistrano to auto-deploy a Node.js app

4 Sep 2012

After figuring out for a while, ```Capistrano``` is still the best one to deploy any app to a production server. Let's do some quick overview; Here is what ```Capistrano``` does: 1. Login through SS

Javascript weirdness with Node.js

3 Sep 2012

Yesterday, I have found a very weird bug, which causes an irregular behaviour. I won't explain it here, but here is the problem: Let's say I have an array: ```array = ["a","b","c"];``` Then, I woul

Jubmoo Hackathon

31 Aug 2012

This is a 2-day hackathon to build an online multiplayer card-game __Jubmoo__, which is very similar to Bridge. Right now I'm designing the server, which is Node.js + Redis. I'm using __Node.js__ be

Carrierwave trick to solve "Too many links"

31 Aug 2012

This is for solving the problem "Too many links" in Linux. You know that you cannot have more than 32,000 files in a single folder. (Increasing the inode limit is also not a good choice.) So, this i

Nginx config for Ruby on Rails

27 Aug 2012

This is Nginx config for Ruby on Rails: ``` user deploy; worker_processes 2; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/ngi


23 Aug 2012

It's not focus; it's patience. I'm reviving 2 of the old products and will let them run for some months.

Test ActionMailer view rendering

21 Aug 2012

You can force ActionMailer to write an email into a file by: * In your environment file, add ```config.action_mailer.delivery_method = :file```. * Or at anywhere, add ```ActionMailer::Base.delivery_

The church's experience

19 Aug 2012

This is the second time I've gone to a church. I won't talk about beliefs and things like that here. What I'm really impressed is the management behind a church. Few rituals, that I have noticed, ma

Rails 3 SMTP configuration requires symboloc keys

18 Aug 2012

I don't know whether to laugh or cry... If you assign the SMTP setting like this: ``` ActionMailer::Base.smtp_settings = { "address" => "smtp.gmail.com", "port" => "587", "authentication" => "

How to win friends... from Dale Carnegie

16 Aug 2012

I read this 2 months ago as well. It's a little bit outdated, but the principles are amazing. This is a must.


16 Aug 2012

I've bought this book for like 3 years and bought it again on Kindle a year ago, but I never did read it until last monday, in which I decide to read the physical book... It's a popular economics boo

Out of Characters

16 Aug 2012

These 3 months I have read 3 more books: Out of Characters, How to instantly connect with everyone, and The fine art of small talk. Well, they don't really help. The one that is interesting is Out o

GIVE Engineering

15 Aug 2012

This is a book about the technology and the engineering discipline at GIVE. As I will move to Twitter very soon (on Oct 2012; right now it is Aug 2012), I need to pass all of my technical knowledge to


14 Aug 2012

Today I have (almost) finished the new layout of GIVEAsia, and I've made it compatible with IE 7,8, and 9. The features of GIVEAsia seem to be crystalized, though we plan to make them richer. I real

IE7 issues

14 Aug 2012

IE7 doesn't support display:inline-block -------------------------------------------- That's very easy to fix. For every ```display:inline-block```, append ```zoom:1``` and ```display:inline```. Or

Testing IE 6,7, and 8 on Ubuntu

14 Aug 2012

I've tried many ways: * Wine that comes with a fake IE, but it's a fake one * Trying to install IE6 with Wine, but it doesn't work because of the fucking fake IE is there * Trying VirtualBox, which r


14 Aug 2012

I've been using this library for a year. It serves me well. Maybe it might benefit you, too. Here is the trivial problem, when you are build a webpage: When a user clicks on a submit button in

IE8 cannot load more than 31 CSS files

14 Aug 2012

Another FTW facts... My Rails project totally collapses. On the development, there are like 50 CSS files, but those CSS files are combined into 1 file in production. FTW, man.... Here is the quick

New Productivity Technique

12 Aug 2012

I've noticed that after I finished the 4-hour workweek, I was very productive for a month. I think I want to theorize that, by reading a productivity book, it will boost my productivity for a period

The Great Redemption

9 Aug 2012

___The recognition of pain and fear in others give rise in us to pity, and in our pity is our humanity, our redemption___ It is indeed my great redemption :)

There will be no flood

9 Aug 2012

Yup, I've just checked the water level at [Thaiwater.net](http://www.thaiwater.net/DATA/REPORT/php/egat_dam.php). You can easily compare today and today in the previous year. The water level in the

Wubi, Ubuntu installer, has a weird behavior

9 Aug 2012

My friend downloaded Wubi.exe from the Ubuntu website, then installed it normally. It turns out that Wubi installed the 64-bit version of Ubuntu into her laptop, while her laptop has 32-bit CPU. WTF

Git workflow

8 Aug 2012

Normally, I'm using 3 branches, which are ```stable```, ```staging```, and ```master```. When you want to make a big change, please branch from ```staging``` by: 1. ```git checkout staging``` in ord

That was stupid (RTMP server related)

7 Aug 2012

Now I know why people don't build an RTMP server in order to record a video from a Flash client. The number on reason is that the quality might be bad and we have NO control over it. After a week and

RTMP is almost done

3 Aug 2012

It is very difficult to build an RTMP server. The most difficult part is that the RTMP document is very misleading. For example, Message is not used at all. CommandMessage doesn't follow the format

RTMP doc is misleading

2 Aug 2012

Today, I got stuck at a problem, where a Flash client requests "createStream", then the server has to reply something. The document says: ``` NetConnection is the default communication channel, whic

Day 53

1 Aug 2012

Today, I have finished the serializer/deserializer of AMF0. AMF0 is a language use in CommandMessage of RTMP protocol. At first, I thought that I'd have to implement AMF3 serializer. But I've found t

C tricks

1 Aug 2012

Assigning 8 bytes into a double variable ------------------------------------------ ``` int amf0_deserialize_number(double *number, unsigned char *input) { int i; for (i=0;i<8;i++) { memcpy((

Zeus Journey 2

31 Jul 2012

I just finished like 80% of the AMF0 serializer/deserializer. Tomorrow, I'll work on serialize/deserialize an array. And on a higher layer, I have built the InvokeMessage serializer. Tomorrow, I'll

Zeus Journey 1

31 Jul 2012

I've found out that building an RTMP FLV-recording server involved 3 specifications: RTMP, AMF0, and FLV. Right now I am at the half way of finishing RTMP, but I have found out that I have to finish

RTMP madness

30 Jul 2012

Not that implementing RTMP is difficult, but its document is poorly written. I have encountered 2 examples: The first one is the default size of a chunk. I've discovered that it is 128 bytes. Should

Day 50

29 Jul 2012

Today, I was trying to build an echo server with C. I have gone through so many things. Configuring Makefile is the first hurdle. It took me like 2 hours to make it work correctly. Setting the testi

C weirdness

29 Jul 2012

Well, it's not that C is weird; it's just tough in general. Today, I'm trying to implement a high-performance echo server. I've read a lot of stuffs on the internet and found that using __libevent__

I have to finish this book, Influence

27 Jul 2012

I wanted to read it like a week ago. I haven't finished it yet, and I only read like 10 pages of it... I will finish it tomorrow..


27 Jul 2012

~ So on this very special day I would like to say to you I hope you'll always find happiness In whatever you may do. ~

Day 48

27 Jul 2012

GIVEAsia is almost complete, in terms of functionality. Tomorrow, I think I'll start adding test cases for all micro-actions. We currently have 600+ registered members now. The re-designing of UI wil

Ruby Meetup Presentation (whowish_word)

27 Jul 2012

On 31st July 2012, I have a presentation on whowish_word. It is a WYSIWYG version of i18n. Here is the presentation: [Presentation](http://tanin.nanakorn.com/slide/whowish_word) What I want to get f

CarrierWave + Mongoid with subclassing problem

26 Jul 2012

If you have a model that subclasses another model, and the superclass defines a carrierwave field, you have to redefine that field in the subclass. Otherwise, you would encounter a very weird, interm

Day 46

25 Jul 2012

Today I've made a lot of minor changes: moving things around and adding search filters (country, micro-action). Tomorrow, I'll work on: Donate anonymously, and hint box at every page. For the RTMP S

Day 45

24 Jul 2012

These past 7 days I have been making some changes to the architecture of the websites. Right now the architecture is complicated, and there are many push architectures. I begin to realize how to man

RTMP server building attempt

19 Jul 2012

I've decided that I'm going to build __a flash recording-video server__. I've been scouting around, and there is no good solution, not even Red5. I think I'll go with Ruby/EventMachine, and if it's

Day 38

18 Jul 2012

Today I tried 2 Flash Media Server and tried to record video through Flash. The first one is Red5. It's built on Java... Oh man, I hate Java XML configuration for a web server. I can't seem to get it

Day 37

17 Jul 2012

I kind of skip like 10 days... because I was in Thailand. My routine didn't work in Thailand, and I was super distracted by, of course, girls. (There cannot be any other reason why I'm so fucked up)

Complete focus

14 Jul 2012

I somehow believe with many people telling me this: My next big challenge in life is ___the complete focus___. I'll get that within these 60 days.

Funny poems between me and u

13 Jul 2012

It was a good conversation today with Yuki. After that, with my depressing artistic talent :P, I've sent her an sms. ``` It was fun hanging out with you; I know deeply inside you feel it too. Now I

Day 28

8 Jul 2012

Today I was flying back to Thailand... I don't know why I have fear every time I fly. I'm really scared that the plane will crash. Man, I still have to fly, at least, 5 times before arriving San Fra

Day 26, 27

7 Jul 2012

Finally, today Paypal and mPayment work on GIVEAsia.org. There were several tricky problems. I think, on Monday, I'll start optimizing the website. At least, all the (N+1)-quiries problems should b

Day 23, 24, 25

6 Jul 2012

Today, I've got a newsletter from PEOI.org. Well, I get a newsletter from them like once a week for the last 6 years. I did apply there as a volunteer 6 years ago, but I never did anything for them.

Do not use after_create with block

5 Jul 2012

In RSpec, I have found out that the model is defined twice. And if you use ```after_create { |record| ... }```, then it will be executed twice...

Mongoid clean indexes

5 Jul 2012

Do you know, when you create indexes, Mongoid doesn't remove undefined indexes? That is annoying and causes me a problem. So, here is the rake task for removing all indexes and recreating only the o

Day 22

2 Jul 2012

Today I cut images for the iPhone app with Photoshop. Man, it looks beautiful. And today I finally got the girl's name. I was super smooth. I was like "you know? I'm coming here to change the world

Day 21

1 Jul 2012

Today I met with Henry. It was a really good talk. I do hope we all can pull off this iPhone app stuff. It's one of the greatest idea I've ever heard. Tomorrow, I will work on the Photoshop stuff. Y

Day 20

30 Jun 2012

I have finished the basic version of GIVEAsia and deployed it already. And then I also finished the book "The Fine Art of Small Talk". It's very eye-opening for me. I am in many ways a conversation k

Day 19

29 Jun 2012

Today I finished the iPhone app. It works perfectly. Tomorrow, I'll move the staging site to the production site. I'll also work with Henry. He'll do 2 webpages.

Affine transformation is applied in the reverse order

29 Jun 2012

I always forgot that fact....

Day 18

28 Jun 2012

Today, I spent 5 hours, making a lot of changes to GIVEAsia. Super tired... Tomorrow, I'll start working on an iPhone app again.

MongoDB's backup and restore

28 Jun 2012

I blog this as a reference. Backup: ``` ./mongodump --db [dbname] --out [some_dir] ``` Restore: ``` ./mongorestore --db [dbname] --drop [the_backup_dir] ```

Day 17

27 Jun 2012

Today I spent like 4 hours to finish a lot of stuffs. It's only 4 hours, but I feel I achieve so much... I don't know why. We have a parent-child movement. The donation works beautifully. Tomorrow,

Day 16

26 Jun 2012

Today, I spent like 4 hours to build a member system and a donation mechanism. I wanted to achieve the challenge, in which I asked for a girl's name. So, today, at the Starbucks in NUS, the girl, wh

Day 15

25 Jun 2012

Today, I expanded the harddisk of GIVEAsia's server on EC2. Can you believe that our server had only 8GB of harddisk before? I added a 100GB EBS to it. We won't need to touch it for a long long time

Mount a new EBS on EC2

25 Jun 2012

First of all, create a new EBS and attach it to your instance through the AWS website. Now login through SSH and type: ``` cat /proc/partitions ``` This is to check whether or not your instance see

Day 14

24 Jun 2012

I didn't really do anything today. I improved the UI of whowish_word a little. I also attended the hackathon event in NUS. It was so full of energy. I should have joined the event. I only sat in on t

Day 13

23 Jun 2012

I am sick today. I spent like 2 hours to redesign the website and shit. Then, I was so dizzy that I couldn't work anymore. I watched like 10 episodes of The Big Bang theory, which, in turn, made me

Day 12

22 Jun 2012

I spent like 5 hours in order to build an iPhone app. Well, actually, I spent 1 hour in order to make a custom camera, renew the developer certificate, and other shits. Anyway, the iPhone app is wor

Day 11

21 Jun 2012

Today, I spent about 4 hours in order to build the prototype of a new idea, which involves an iPhone app. I spent like 2 hours building the backend and the website part, and another 2 hour to setup x

Day 10

20 Jun 2012

Today, I built 3 importers from 3 sites, fixed whowish_word bugs, and deployed (and test) the website. I spent in total 4:45 hours today. I feel pretty good. And I've requested to talk at the next

Day 9

19 Jun 2012

Today, I spent like 3:30 hours in order to setup the whowish_word's demo site and build the importer stuff. I was highly distracted by the news and shit. And today I also went to a Ruby meetup. Lif

whowish_word - the technology of the decade

19 Jun 2012

Now that I have your attention. It's not really the technology of the decade. whowish_word turns every static string on your Rails' site into an editable one. Please see the demo here: [whowish-word

Day 8

18 Jun 2012

Today I spent like 5:30 hours in order to build the charity stuff and improve WhowishWord. WhowishWord, I believe, is one of the technology that can change the way people work. I've made it database

Day 7

17 Jun 2012

Today I have added another micro action, which is yes/no, fixed Facebook publishing, and fixed other shits. I spent only 3 hours today... I had a dinner with friends today at Clark Quay. Clark Quay

Day 6

16 Jun 2012

Today my focus was very intact. I spent like 5 hours. I feel I achieve many stuffs. I don't really have any complaint today. In a normal day, I'll work at the Starbucks in Yusoff Ishak for like 2-3

Day 5

15 Jun 2012

Today I spent like 4 hours. I got stuck on FB publishing problem for like 2 hours. It was super annoying. Then, for another 2 hours, I have designed the activity feed and completed the detail. The

Facebook Madness

15 Jun 2012

The Facebook documentation tells me to use HTTP Post, but the parameters should be sent as a query string. I thought I could send parameters as POST's parameters, you know, in the HTTP body. It turn

Day 4

14 Jun 2012

I almost finished the site (again). The things missing are: * Activity feed * Facebook Open Graph stuffs I think I'll finish these 2 things within 2 hours. And I think I'll design the basic system

Day 3

13 Jun 2012

Today I have spent roughly 5:30 hours. It was not bad. I have achieved many shits. The new website is almost complete. I think I'll complete it by tomorrow's night. I felt tired at the end of the d

Day 2

12 Jun 2012

I've just spent 1 hour to make the searching feature on Giviki. I was lost for like half an hour because, at first, I was doing the browsing feature. Browsing doesn't make sense. Why would users bro

Day 1

11 Jun 2012

Let the journey begin. Even if I have to die at the end, I'm finishing this product. This is the day number 1. Today, I have spent 1.30 hours in order to: * Donate through Paypal and track the don

100 days to die

7 Jun 2012

We've agreed to do 100-days (roughly) marathon at GIVE.sg. Long-term productivity is a hard problem. I'll try to reach 6 hours a day without interruption, at first. I think I will need to time the

Don't call me a volunteer

4 Jun 2012

Ok, I've admitted it. I am probably the only one who said I was a volunteer for GIVE.sg. I have tried many terms: Volunteering Engineer, Engineering Volunteer, and Software Engineer. (Yeah, even Soft

That FB recruiter is the man

31 May 2012

Today, I have been preparing my speech for the Twitter event. You can see the detail [here](http://tanin.nanakorn.com/twitter.html). I've just realized something that the FB recruiter did. And it was

Devise with DelayedJob

23 May 2012

Ignore all StackOverflow's posts. They don't work. Follow this instruction: [Devise-Async](https://github.com/plataformatec/devise/wiki/How-To:-Send-devise-emails-in-background-%28Resque,-Sidekiq-an

Weird HTTPS problem

22 May 2012

Today, I got stuck because I couldn't connect to the Paypal's sandbox. I was using Ruby's standard https library. I could connect to ```https://www.google.com``` and ```https://svcs.paypal.com```, b

Ubuntu with RVM

20 May 2012

I've installed RVM on Ubuntu like 5 times. Every time the gem's path is wrong. I've found this [post on StackOverflow](http://stackoverflow.com/questions/8990828/rvm-bundle-install-missing-gem-error-

A new playlist when visiting a new place

16 May 2012

Human is amazing at associating our senses holistically. I still remember the feelings when I was in Singapore 10 years ago. The flush of the feeling comes back every time I hear the songs, The Last

Changing things is easier than Building new things

16 May 2012

I'll write more about it. It's true in so many ways. One of the main reason is that: *When you build a thing, you'll learn many new stuffs. So, it's easier to change it later in time, simply becaus

Why do I procrastinate?

14 May 2012

I still procrastinate some tasks from GIVE.sg. I am supposed to finish re-designing pages to make it more usable. I procrastinate by doing some other tasks instead. This is the most insidious way to

Eliminating Procrastination using Twitter and FB

13 May 2012

Normally, when I want to achieve something, e.g. reading one book a day, I will publicly announce it on Twitter, FB, and my blog. This is a great trick to avoid Procrastination. When you have a milli


12 May 2012

The book is very inspiring. I think I am heading toward Linchpin whether or not I read this book. I am already half way there. I am already serious about my art and my craft. I am emotional about m

The mantra for the next 4 months

12 May 2012

*Blessed are those who can give without remembering, and take without forgetting.* The quote is from Princess Elizabeth. I shall live by this quote.

Sunspot Solr with Mongoid with id as String

12 May 2012

If you use a string ```id``` in Mongoid, then when the searching with Solr won't work properly. When you try to obtain the results, Solr will throw an error ```sunspot BSON::InvalidObjectId (illegal

Divide a big task into one-hour tasks

9 May 2012

Ok,let's try a new plan: * Divide a big task into one-hour tasks. Time it! * I shall test/debug after finishing the code of an one-hour task. * Take a 15-minute rest between 2 tasks And here is the

Silver - An MVC Framework for Titanium SDK

2 May 2012

I've been playing around with Titanium SDK for some days now. It's an ok platform. I've figured a way to organize files into controllers and views. It's still not complete. I want to find the way to

The Power of Now

28 Apr 2012

This is a difficult book to read. The book uses complicated and abstract terms. For example, * The timeless Being * Unmanifested * We should put our attention on our Unmanifesto or Presence. It cit

The amount of one task

28 Apr 2012

Here is the rule of thumb: *The task should be as big as possible that you can code the whole task without producing errors and without testing.* If a task takes you 30 minutes and you later discove

The new bottleneck -- Test too often

24 Apr 2012

I test too often. I have to eliminate this impulse. I seem to test every 10-15 minutes. It becomes a bottleneck when the testing takes too long, for example, starting an iPhone app. New goal: Test o

Founders at Work

22 Apr 2012

I've just finished the book "Founders at Work" today. I didn't really have time for the last 2 weeks. I need to be a little bit more disciplined, I guess. The last 2 weeks, I need to finish some feat

ERP's Journal

19 Apr 2012

ERP stands for Extremely Rapid Prototyping. Today, I almost finish my third project. So, I think I should write about the 3 projects I have done for the last 3 weeks. Squeks.com ------------------

UIImageWriteToSavedPhotosAlbum writes a wrong size

19 Apr 2012

Even my image's size is 1936x2592, it writes to 3872x5184. And I don't know why... The image is generated from a graphic context. Everything should have been fine. Anyway, I resize the image from 19

Crappy UIHorizontalTableView

18 Apr 2012

I needed a simple UITableView, which scrolls horizontally. So, I just built one. It supports: * clicking on a cell * customizing cell But: * All cells must have the same width * It doesn't reuse

iOS's tip to capture image from streamed video

17 Apr 2012

I am building a custom camera, and what I have noticed is that the capture image from the video output is not as sharp as the one in the ```AVCaptureVideoPreviewLayer```. The difference is almost un

Stupid Memory Management

17 Apr 2012

Now this is what I call stupidity.... When I need to assign an object to ```@property``` in iOS, I figured out that I should make the code shorter. So, what I did is this: ``` self.camera = [[GLCame

An iOS tip

16 Apr 2012

Never ever set the image of ```UIImageView``` before it is shown. Otherwise the image wouldn't show.

Tomcat and Solr on EC2

15 Apr 2012

First of all, install ```tomcat```. You can choose your own version. ``` yum install tomcat7 ``` Now we need to install Solr manually. Let's first download it: ``` wget http://mirrors.issp.co.th/ap

Sunspot Solr Rollercoaster

15 Apr 2012

It is indeed a roller-coaster ride, especially when one wants to use it with Mongoid. Here are things I have to change to make it works: 1. Mongoid doesn't support ```find_in_batches```. So, I have

Extremely Rapid Prototyping's lessons

13 Apr 2012

I have decided that I'm going to launch something, a new product or a new version of a previous product every week. I've figured out that nobody really tries to ship 20 products within 6 months befo

Scaling Basics

9 Apr 2012

Ok, so here is the script for scaling a server. ``` sysctl -w net.core.somaxconn=40000 sysctl -w net.core.netdev_max_backlog=40000 ulimit -n 100000 ``` And edit the open-file-limit for the user who

Amazon EC2 setup for Ruby on Rails

7 Apr 2012

*This works with Amazon EC2 with its original OS* Here is the steps: 1. Uninstall Ruby 1.8.7 2. Uninstall Rubygems 3. Install Ruby 1.9.3 4. Make a link from ruby1.9 to ruby 5. Install Rubygems for R

Generating the Rationals

4 Apr 2012

Here is the problem for tonight: ``` A set S contains 0 and 1, and the mean of every finite non-empty subset of S. Prove that S contains all the rational numbers in the unit interval. ``` Ok.... L

PHP Database Migration

4 Apr 2012

I've just built a PHP Database Migration Library in order to manage changes in the database's structure, for example, adding columns. It generates a unique identifier for each migration script, there

SWF hacking

2 Apr 2012

I'm working on SWF hacking in order to build a seamless licensing for a SWF (Flash) application. Here is what I have found so far: 1. Always reading in bytes. If the specification said that it uses

Automate Ruby on Rails setup on EC2

1 Apr 2012

*Works only on Amazon EC2 with Red Hat Linux* It starts getting annoying when I have to deploy like 3 Ruby-on-Rails apps. I'll build a script to ease the process. Here is the rough outline of all t

A New Plan

1 Apr 2012

I must ship something every week in order to guarantee that I, at least, create something!

Cannot override instance variables of Struct

1 Apr 2012

You cannot override an instance variable of Struct. It's weird. Observe: ```ruby class UpdateFriendVoteJob < Struct.new(:member_id, :question_ids, :force) def perform puts "#{question_ids}"

Sum and Differences

31 Mar 2012

The problem sounds familiar. I might already solved it. But that doesn't matter. I'll try to solve it again. Here is the problem statement: ``` Given 25 different positive numbers, prove that you ca

The 4-hour Workweek

31 Mar 2012

This is a very very good book, even though the introduction is a little bit bogus and pretentious. It sounds like the work-at-home advertisement in Thailand. Anyway, the philosophy presented in the b

SSH the right way

28 Mar 2012

As a reference, this is [the right way to configure SSH connection](http://articles.slicehost.com/2009/5/13/capistrano-series-setting-up-git).

Zeroes, Ones, and Twos

27 Mar 2012

I thought I would practice Google CodeJam on 22dn of March. Today is 27th of March already. Gosh, I'm so dead. Anyway, here is the today's problem: Problem Statement -------------------- Let ```n``

Single Server with multiple loosely-connected clients

27 Mar 2012

When you are in this kind of situations, where there are many clients and one server. The clients generate data models, store them locally, and submit them to a server. Let the client generate unique


26 Mar 2012

Somehow today I have come to a realization how big the privilege I have. Sometimes I just want what I want too much that I forget about how lucky and privileged I am. My first achievement in my life

NSMutableArray annoyance

26 Mar 2012

Today I have found out that: If I don't initialize NSMutableArray and use it, there will be no compilation error. But a new element won't be added. What an annoying problem...

Predictably Irrational

25 Mar 2012

This is the second time of my reading day; I'll try to finish one book within one day every week. Today I have finished the book "Predictably Irrational". Well, actually I have finished 2/3 of it bec

Ruby on Rails on Ubuntu is killing me

24 Mar 2012

I did ```bundle install``` and it still threw an error that it couldn't find other gems. What the fuck was happening? I cannot solve this problem. A workaround is to install gems in a relative path

RVM on Ubuntu

24 Mar 2012

I have encountered a very annoying problem. I want to use Ruby on Ubuntu. So, I installed RVM and shit. Now I found out that all gems' executables didn't work. It threw an error like this one: ```

The Luck Factor

23 Mar 2012

Last Saturday, I have finished the book called "The Luck Factor". By the way, I declare Saturday to be my reading day. I shall finish one book on that day. The first half of it iterates all the beli

UIGridView (iOS)

4 Mar 2012

I want a grid view to show a list of thumbnails. The grid view should allow me to specify the number of columns and the size of a cell. I googled around for a while and found a few of them. They are

whowish_word gem

1 Jan 2011

```whowish_word``` is one of my greatest invention. Normally, on Rails, you would have to edit a locale YAML in order to change static strings on your site. ```whowish_word``` enables you to edit a

EXC_BAD_ACCESS with [CALayer retainCount]

12 Mar 2012

```EXC_BAD_ACCESS``` might mean many things. Normally, it means that you release an auto-released object, release too many times, or use a released object. Here is the way to debug it. First of all

Use @property (to prevent the memory-leak error)

12 Mar 2012

See this example: ```objc // In the init function UIView *v = [[UIView alloc] init]; [self addSubview:v]; _someVar = v [v release]; // In the dealloc function [_someVar release]; _someVar = nil; ``

NSLog on BOOL with %@ causes EXC_BAD_ACCESS

12 Mar 2012

This is because ```%@``` must be used for a pointer-alike variable. For a primitive-alike variable, we must use a correct symbol, for example, ```%f``` for float.

!NO is not YES in Objective-C

12 Mar 2012

Today I have found out that ``` if (!NO) { ... } ``` is not working as I expect... ```!NO``` is not a true statement.

DISPATCH_QUEUE_PRIORITY_BACKGROUND in dispatch_async causes EXC_BAD_ACCESS in iOS 4.2.1 and earlier

12 Mar 2012

This is because ```DISPATCH_QUEUE_PRIORITY_BACKGROUND``` does not exist in iOS 4.2 and earlier. Please use ```DISPATCH_QUEUE_PRIORITY_LOW```.

Deploying to iOS 4.2.1 problem

12 Mar 2012

``` warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found). ``` If you found t

Manual Camera on iPhone

19 Mar 2012

Today I have succeeded at streaming video from camera and showing it on the screen. Also, I have succeeded at manipulating pixels before showing it. The normal way is to: 1. Write your own ```AVCapt

Stupid path NSBundle pathForResource:

19 Mar 2012

Simply do not forget to add the files to "Copy Bundle Resources" (under the project configuration)

OpenGL ES (Shader) tips

19 Mar 2012

* There is no type-casting. Use constructor. * When declaring float or vec, you must declare its precision, otherwise there would be a compile-time error. * You cannot multiply float with integer beca

CodeJam Camp

22 Mar 2012

This year, Google CodeJam Qualification Round is on 12th April 2012. Last year, there were 30,000 participants. I have ended up at the rank 895th. I didn't train very well last time, and I didn't un

iOS 4 & 5 incompatibility in dismissing a modal view

22 Mar 2012

Here is one annoying problem. In iOS 4, when I want to dismiss a modal view, I would: ```objc [self.parentViewController dismissModalViewControllerAnimated:YES]; ``` But that doesn't work on iOS 5

My New Blog!

22 Mar 2012

I have decided to re-innovate my website before practicing for Google CodeJam. Yes, it is a very weird prerequisite. I have been frustrated with poor blog engines. I have been using Blogspot.com for

The open-source war

7 Mar 2012

Yesterday I was trying to find a way to create multiple-column UITableView. Surprisingly, this is not easy to do. Some posts on StackOverflow suggest that we build it out of UITableView. That is w

900K tablets in Thailand

23 Feb 2012

900K tablets will be bought by Thai government and distributed to 10-years-old kids. Everybody in Thailand keep arguing about whether or not this policy will pay off. ___Well, I don't care about

My interviewee life is over

22 Feb 2012

I am so tired. I woke up very excited every morning for 2 months (evening in SF == morning in Bangkok) checking my e-mails. Sometimes I was rejected and sometimes I was accepted to a next round. I'

Expensify's Interview Preparation (Revised)

6 Feb 2012

Alright, the first version of my preparation is not concrete enough. It is not focused enough. So, I come up with a new plan. I have done a scorecard of outcomes and competencies. (It might be a li

Expensify's Interview Preparation

30 Jan 2012

Expensify's Interview Preparation ================================== Expensify is a very small company. Normally, within a small packed group of people, its culture should be unique and somewhat stra

Conceptual questions

29 Jan 2012

Conceptual questions ====================== The only area that I never practice on is the design questions. Here is the raw list of some of the questions: *Architectural questions* - How would you

Onsite Interviews

25 Jan 2012

Onsite Interviews ========================== I finally get onsite interviews with Expensify, Facebook, and Twitter. These last 2 months are not really a superb experience for me. It was like a rolle


15 Jan 2012

Squeks.com ======================== Squeks.com was born around 6 months ago. It's just a website where you can click 'love' or 'hate' public figures. What was happening with it is that it got so pop

Interview phase is coming to an end

14 Jan 2012

Interview phase is coming to an end ================================= I am so tired and have been excited waiting for a result after each interview. Too much excitement makes me feel tired. Right no

Causes.com's rejection

11 Jan 2012

Causes.com's rejection ========================= Ahhh... I feel super depressed. I really have no idea what went wrong. I finished the given task, though it was uncomfortable because I am a Windows

Startups are super interesting

5 Jan 2012

Startups are super interesting =============================== They have solid goals and extreme passions. Even an HR guy sounds passionate. My first impression with every company that I have talked

Scribd rejects me

3 Jan 2012

Scribd rejects me ===================== They reject me without any interview. I don't know why... I would like to think that it is because of the visa stuffs. But that is unlikely to be true. I thi

Job Finding Madness

27 Dec 2011

Job Finding Madness ===================== I have so far sent a resume to: * Google * SpeakerText * Posterous * Thoughtbot * HealthTap (In Process, Quiet) * Facebook (Rejected after onsite) * Twitter

Zombie Syndrome

26 Dec 2011

Zombie Syndrome ======================= Today I would like to write about the zombie syndrome. The idea has been thrown around for a long time, I believe. I have found the explanation of this syndrom

Min and Max

26 Dec 2011

Min and Max =================== Given an array, find Min and Max with the least comparison. Now the classic way to do is to loop. That's *2n* comparisons on the worse case. The best case is usin

2SUM problem

26 Dec 2011

2SUM problem ====================== Given an array a[0] ... a[n-1], find 2 elements that sum up to k Now this is a classic problem. Everybody will certainly say it is O(n^2). It turns out that

Facebook Interview Questions

25 Dec 2011

Facebook Interview Questions ============================ Right now I'm preparing for a phone interview from Facebook. I have done all questions from [XORSwap](http://xorswap.com/companies/5-faceboo


24 Dec 2011

Empowerment ======================= I believe Empowerment is the key to produce quality work. Currently, I have applied two empowerments: The first one is using WhowishWord. It allows other people,

N independent decisions

24 Dec 2011

N independent decisions ================================================ About 5 days ago, I have an phone interview with a Twitter engineer. He asked me to: Given a string, for example, aa-(1,2

Problem Solving Dichotomy

17 Dec 2011

Problem Solving Dichotomy =================================== I do believe that given a problem, *You either solve it or you don't* If you don't, you need to seek for a solution elsewhere. It's pr

Foodling - Find the dish

14 Dec 2011

Foodling - Find the dish ========================== Somehow I do feel that my team has grown up by some extent. At least, we know how to draft a sounding mission statement. After we built Gamling.or

Sliding Window Maximum

11 Dec 2011

A long array A[] is given to you. There is a sliding window of size w which is moving from the very left of the array to the very right. You can only see the w numbers in the win

The k-th Smallest Element in 2 Sorted Arrays

11 Dec 2011

It's using the same old technique. I'm bored. Let future Tanin solve it.

Median of Two Sorted Arrays

11 Dec 2011

Given 2 sorted arrays, n and m in length, find the median. First, let's just assume that the numbers are unique and `(n+m)` is odd. The first obvious solution that comes to me takes `O(n)`.

Longest Substring Without Repeating Characters

11 Dec 2011

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the le

Distance Maximizing Problem

11 Dec 2011

Given an array A of integers, find the maximum of j-i subjected to the constraint of A[i] < A[j]. This is a really really good interview question. I love this kind of questions. It is

General Manager

10 Dec 2011

It's so difficult to find a general manager to run a website. I have finished [Baanling.com](http://www.baanling.com) for weeks now. Still, I cannot find anyone to take over and run the website.

Reverse Bits

9 Dec 2011

Given an integer of n bits, reverse the bits. I am not very creative in solving a problem. Of course, everyone, including me, can come up with O(n) solution. The real rock-star will come up

Regular Expression

9 Dec 2011

Implement a function that matches a string to a regular expression. The regular expression only contains a-z,'.', and '*'. * matches any string that precedes it, even an empty string

Longest Palindromic Subsequence

8 Dec 2011

Given a string s, find the longest palindromic subsequence A subsequence of string is the string with some characters removed. For example, aaa is a subsequence of bcabcabca. First of all, l

Longest Palindromic Substring

7 Dec 2011

Given a string S, find the longest palindrome substring. A palindrome string is a string and its reverse are the same. my dynamic programming skill is still ok. First of all, we can immed

EcoHealth's webboard

7 Dec 2011

Tonight I'll work on the webboard of EcoHealth. God, I should have known that I should not take any consultant job. Now it's biting me in the ass.

The attitude

5 Dec 2011

I don't know why I have an attitude that I should try to solve problems on my own even if I already spent an hour on it. I think it is a wrong attitude. When I study language and I don't know so

The way I work

5 Dec 2011

I should have realized this for a long time that my style of working is very different. Anything that I have felt success usually goes like this: 1. I declare a ridiculously-early deadline (a few d

Subsets of Subsets

4 Dec 2011

There are so many techniques in Mathematics that I am not aware of. Here is another problem, which I didn't even know how to begin to solve. Prove that every set of ten distinct numbers between 1

Substracting around the corner

3 Dec 2011

Given a sequence of n numbers, a[1] a[2] ... a[n] Replace a[i] with |a[i] - a[i+1]| (if i == n, then with |a[n]-a[1]|) Repeat it until every element is 0. Prove that with n=5, it may g

Summing Fractions

3 Dec 2011

Given an integer n > 1, the sum of 1 / (pq) for all p,q that 0 < p < q <= n and p + q > n and p,q is relatively prime is equal to 1/2 The first thing to notice is that we have t

Sum and Difference

30 Nov 2011

Given 25 different numbers, prove that you can pick 2 numbers that their sum and difference do not equal any other numbers. We should first address the problem formally: Let a[1] < a[2

Bracket Combination

29 Nov 2011

This is a problem posed by my girlfriend's boss at NovaLeaf. The problem is: Given n brackets, how many are the combination of valid brackets? For example, 2 brackets have [][] and [[]]

View (in MVC) should contain minimal logic

29 Nov 2011

It is just amazing that I've just realized this. This week I enable my friend, a designer, to make changes to the website directly. He has to learn the structure of Rails 3.0. But it's merely views

Rental rooms

24 Nov 2011

Tonight I'm doing the very first hackathon. I'm building a platform to connect the ones who offer rental rooms/houses and the ones who want to find rental rooms/houses. The website is extremely

Hackathon-oriented management

23 Nov 2011

I've found out that I am usually 100 times more productive when I decide to write a program within one day. It's surely tiring, but rewarding at the same time. Right now what I really need is to pe

100 Lockers

23 Nov 2011

There are 100 lockers in a room. The 1st student opens every locker. The 2nd student closes the lockers whose number is divided by 2. The 3rd student toggles the lockers whose number is divided

Path on chessboard

23 Nov 2011

There is a NxN board. Alice starts first by marking a cell. Next, Bob must marks a cell that is adjacent to the previous cell. Each player takes turn. If someone cannot mark a cell anymore, the

Integers and Rectangles

23 Nov 2011

If small rectangles, each of whose either width or height is integer, compose a big rectangle, then the big one has either integer width or height. Prove that. This problem is just really rea

Thought unit

23 Nov 2011

Around 6 years ago, I didn't believe in speed reading. Still, I bought a book about speed reading anyway. I didn't really believe in the techniques it offered. I still don't believe them these d

Coins Game

23 Nov 2011

There are an even number of coins arranged in a straight line. You and your friend may only take coins from either ends. You and your friend take turn to take one coin at a time until there are

Delusional boundary

23 Nov 2011

What I have found during the years is the problem so called "Delusional Boundary". I am almost always wrong at a judgement call at something. Gamling.org's delusional working hours -----------

Basic skills

23 Nov 2011

As running fast required in Sport, reading fast requires some basic skills. This is not to improve understanding while reading but to train our minds to consume information faster and longer. Th

Billiard ball with square table

23 Nov 2011

There is a billiard ball on a square table (with no holes). Find angles in which the ball is shot and travel in a cyclic manner. This simply means that at some point of time in the future the

Can we code painlessly?

23 Nov 2011

I believe so. Nowsaday, with the Test-Driven-Development(TDD) approach, I feel painlessly already. This journey is about what components I have found and used to facilitate software development or

Why read faster?

23 Nov 2011

The reading skill is so fundamental to your learning rate. Almost anything you learn involves reading. So, the faster you read, the faster you can learn. Even though it is composed of 2 set of skill

Why unlearn Math?

23 Nov 2011

I have been coding for years now. I have found out that a great programmer should acquire these 3 skills: * Translate a concept into code * Write beautiful code, minimizing redundancy and maximizi