Chao Lam

Working on the next small things …

Default Active Record tables to utf8mb4 encoding

leave a comment »

I found several articles on how to convert existing rails tables to support 4-byte unicode characters including emojis but didn’t find one talking about how to create a new table.

So, here’s the code I used:

create_table :twitter_users, {options:"DEFAULT CHARSET=utf8mb4"} do |t|

Written by Chao

February 14, 2019 at 10:14 pm

Posted in Uncategorized

Adventures in KenKen

leave a comment »

My Mom enjoys sudoku and I like playing KenKen!

Here’s one I think is worth replaying:

I quickly started out with the basic rules to get this layout:

The only “given” 3 provides a clue to the 45x at the top. The candidates are 1335, given the fixed 3, there can be only 2 possible set of positions for the 45x. A tricked I figured out for 19+ is that it cannot contain digits 1,2 and 3. Thus :

With the double 3s in place, looking at 168x, there are two possible combinations 378 or 467. The double 3s preclude 378, so 467 it is! And with our 21+ eliminating 6 and 7, one of those squares can only be a 4:

Then, looking at the 48x just below 168x, We know there are 4 possible combinations: 344, 624, 618, 328. The first is now eliminated with the 4. 624 and 614 are also eliminated because of the 67 above. So the only combination left is 328:

Now looking at 112x at the bottom. there are 3 combinations: 7144,7224,7128. But the double 2s and 4s are not possible because of the double 24s on the last column (and last two rows). So the only combination 7128. After applying some other clean on the left, we get:

Now here comes a tricky part: The two pairs 15 and 56 circled above, ensures that 19+ cannot have a 5. When 5 is eliminated, 19+ then also cannot have a 6. In fact, the only combination left standing is 478:

Looking at 70x, we know it needs a 2 (in 257), so the 8+ above cannot have a 2, which means it’s 17. Hence (with more cleanup):


which collapses and leads to the solution:

Written by Chao

February 11, 2018 at 5:54 am

Posted in Uncategorized

IFTTT maker (webhook) test with Curl

leave a comment »

IFTTT used to have a test page for developers who wanted to implement the Maker (now called webhook) trigger. Unfortunately they initially hid it and then finally removed it entirely (not sure why). But here’s a command line curl command to simulate the test page:

curl -H “Content-Type: application/json” -X POST -d ‘{“value1″:”xyz”,”value2″:”222″}’<$YourEventName>/with/key/<$YourOwnKey&gt;

where <$YourEventName> = your IFTTT app event name

<$YourOwnKey> = user’s IFTTT key


Written by Chao

March 22, 2017 at 10:22 pm

Posted in Uncategorized

Tip: Refund $15 comcast xfinity starter kit

leave a comment »

I recently installed comcast cable internet service. Of course, I chose not to rent their modem for $10/month. Opening the account online was pretty painless, but it insisted on a $15 starter kit. Turns out the starter kit is just cable wire, a splitter and completely useless instructions.

The real instructions can be found at

I had to call comcast (via the ever helpful to get a refund for the starter kit, but it was surprisingly pain-free, hopefully comcast is improving…so it is worth calling Comcast for the $15 refund.

Written by Chao

January 27, 2017 at 12:54 am

Posted in Uncategorized

leave a comment »

If you’re using the rails jquery autocomplete gem and mongoid, you need to specify the gem *after* the mongoid gem!

i.e. in your Gemfile

gem ‘mongoid’
gem ‘rails-jquery-autocomplete’

Apparently, it checks whether mongoid is present before injecting some special mongoid methods!

Written by Chao

May 27, 2016 at 7:39 pm

Posted in Uncategorized

Neo4j questions

leave a comment »

Last week, I attended a free seminar on Neo4j and came back wondering why I’ve not looked into the delightful world of graph databases earlier! I’ve never really grokked relational databases in the sense that it’s never second nature for me to think of most everyday problems in terms of rows and columns. The biggest stumbling block I have is that it is still unnatural for me to think of a relationship between two things as being a column in a relational database. I understand it abstractedly but just not natively. Conversely, Graph databases address this issue directly and seem to have a much better mapping to what is intuitive in my head.

Of course, I’m very much a neophyte in the world of graph databases, and learning something new is always a delicate balance between sheer delight in discovery new ways of doing things and head-exploding frustrations. The best way for me to learn is to start on a concrete “next small thing”, and I’ve already hit some stumbling blocks I’ll like to get answers to:

I want a website like that let’s you track flights, but instead of showing what tickets and fares are available, they show you what airline awards are possibly available.

To do that I need to model each airline’s award chart.
1) Most loyalty program’s awards are based on regions such as North America, South Asia or Europe. But of course, each airline’s definition of regions are slightly different. Do we create separate regions as nodes for each loyalty program?
2) Another example of a tricky region: Almost all regions encompass an entire country (e.g. North Asia includes all airports in Japan). The glaring exception is that most airlines separate Hawaii as a separate region from the rest of the US. How do we model Hawaiian airpots as a region?

Once of things that attract me to neo4j is the schema-less nosql nature. You are much less locked into your initial design or schema and as you discover what your real needs are, your database structure can change much more easily.

However, change management is never free. What are best practices when dealing with changes? From simple node label orrelationship name changes to more complicated design changes? Are there pointers to good practices?

This current project requires loading from myriad of disparate data sources (airport codes, regions, award charts, rule changes, etc.). What are best practices to initially load in such data, and then to ensure that such data is up to date?


Written by Chao

April 22, 2016 at 7:27 pm

Posted in Uncategorized

The Instagram Paradox

with one comment

A16Z has a delightful interview of John Markoff‘s long view of Silicon Valley and technology in general. It discussed the oft-mentioned story of how a 13-person Instagram toppled Kodak (which Markoff disputed given how Fuji managed to thrive). But that go me thinking that the story of Instagram is even more endlessly fascinating.

Waaaay back in 2012, when Instagram was acquired by Facebook for over $1 Billion, it sent shock waves through the valley and general buzz was that Facebook way overpaid for a $0 revenue 13 person company. Today, the pendulum is on the other end where Zuckerberg is hailed as visionary and analysts are now predicting that Instagram could bring in revenues in excess of $2 Billion just next year.

The podcast dives into the popular topic of secular stagnation and “how technology is everywhere except in productivity number”. Besides the Clothelines Paradox (which posits that GDP is not measuring all that we produce), we are also facing an Instagram Paradox: in 2012, the “GDP” of Instagram was $0, but the total present value of GDP was a lot more than that, even $1 Billion screams cheap in retrospect.

So, instead of a secular stagnation, are we just in the nascent stage of another a huge technological renaissance where work done today isn’t creating much “GDP” today but is really laying the foundation for value created in say 2025?

Update: Michael Spence speaks more eloquently on this topic

Written by Chao

August 30, 2015 at 6:38 pm

Posted in Uncategorized