Tuan Anh

container nerd. k8s || GTFO

When static website isn't fast enough

I have recently taken a look at my website loading speed again.

A bit about my website, as of currently:

  • I hosted my website on a smallest, cheapest VPS plan at RamNode ($15 per year, massive plan) which shares the physical machine with a numerous other people.

  • This website is powered by jekyll - a static site generator.

  • The website is using a custom theme, based on Bootstrap. I loaded two addtional fonts from Google Fonts (Ubuntu and Merriweather) for heading and paragraph.

  • I have Jquery and Bootstrap script on my page for some fancy stuff I might need later, along with Google Analytics script (async).


As for the testing setup, I will compare the loading speed of two posts with text only.

  Gtmetrix Webpagetest
Total load time 2.8s 2s
Size 247KB 221KB
Number of request 14 17
Location Canada US
PageSpeed 98 96
YSlow 96 -

2-3 seconds to load isn’t too bad itself but it’s definitely not good enough for me. My idea number would be something less than 1 second. I know that custom fonts come with the trade of loading speed but I would expect it to load faster than this, especially when they’re served by Google.

Stuff I have already tried:

  • Combine CSS into a single file, minified and served by CloudFlare.

  • Images are optimized with ImageOptim for optimal size.

  • Defer/async script when possible. Loading JS script right before </body> tag.

Webpagetest gives my website A for everything except: First Byte Time (B) and Cache static content (C). Let’s break it down.

First Byte Time

  • 845 ms First Byte Time
  • 717 ms Target First Byte Time

Apparently, the VPS my website is on is slow (which is expected). I can’t do much to enhance this either.

Cache static content

Webpagetest also complains about there’s no max-age or expires set in header on fonts.googleapi.com. I have no idea why Google didn’t set max-age or expires for this. Maybe someone with better understanding about this can help explaining to me.

As much as I would like to make my website load faster (I’m sucker for this kind of stuff), I either have to upgrade the VPS plan ($$$) or go with web safe fonts (Ewwwww!).

I guess I would have to settle with this for now. Hopefully, you don’t find this website too slow.

New theme

My blog is now using customized Shiori theme - a Bootstrap-based theme for jekyll by Elle Kasai.

The switching process is painless. I just have to copy my data over from old jekyll instance, tweak here and there a bit and git push. BAMM! The blog now has a shiny new modern look :)

new theme

BAT script to execute commands on remote Unix machine with PuTTY

putty -i private_key.ppk remoteuser@remotehost -m local_script.bat

In the example above, I use public key authentication to authenticate and then execute the commands inside local_script.bat on the remote machine. Alternatively, you can use plink which is basically putty without the GUI part. All other options are basically the same.

You can also use password for authentication, just replace -i option with -pw and your password.

youtube-dl - A must have little gem in your toolbelt

youtube-dl is a small command-line program to download videos from YouTube.com and a few more sites.

Installing youtube-dl is as easy as brew install youtube-dl on OS X.

youtube-dl allows you to download from many online audio/video sharing websites, not just Youtube.

You can use it to download all videos from a playlist, from a channel or simply extracting the audio from a Youtube link.

From a channel:

youtube-dl -citw ytuser:channel_name

From a link/playlist

youtube-dl youtube_link

Listing all available formats:

youtube-dl -F OKbtC223e30

Download a Youtube video as audio

youtube-dl -f bestaudio OKbtC223e30

youtube-dl is included in many distro’s repo but I recommend you to install from the main website for quicker update. The version in the repo is usually very outdated.

link bài gốc

Shorter code is better?


Which one do you prefer: shorter code or more legible code? As for me, legibility of the code always come first. Working in a team will make one realize the importance of code legibility sooner or later. Your code is not for you alone to read. It should be friendly and easy for whoever has to maintain your code as well. It’s not easy to write elegant code but it’s much easier to write legible code.

  • Always give a good name to your variables. It’s not random naming was talked as one of the hardest problems in computer science.

“There are only two hard things in Computer Science: cache invalidation and naming things.”

- Phil Karlton

  • Comments: comment is not a bad thing. But lots of comment definitely is. It might be a signal that the code is not legible enough that it needs that much lines of comment for readers to be able to understand. Also, it’s not a good thing to comment code and leave it there. It will create confusion for those who maintains it.

  • Uncouple your code. Uncoupling increases legibility and writing test unit a lot easier.

  • Write everything as if you were to write an API, as it should be intuitive and easy to understand. Your code should be easy to make changes when needed. It should not break a whole system when does.

“Writing specifications is like writing a novel. Writing code is like writing poetry.”

Your code can talk, so tell a story.

Where is the safest seat on airplane?

Business class seat doesn’t look very tempting all of sudden.

So when the “experts” tell you it doesn’t matter where you sit, have a chuckle and head for the back of the plane. And once your seatbelt is firmly fastened, relax: There’s been only one fatal jet crash in the U.S. in the last five-plus years.

airplan seat survival rate

link bài gốc

Filco Majestouch 2 Ninja Italian Red (TKL) review

This is a short review of a Filco Majestouch 2 Ninja TKL (Italian Red version). I ordered mine from eBay and the keyboard arrived 3 days later. The keyboard came with some additional keycaps (WASD and Escape keys in red and black) and a keycap puller.

First impression

This thing is sexy as hell. This was one of the main reason I purchase this board to begin with.

The case feels really sturdy. Let me put it this way: the HHKB case is very solidly built, this keyboard’s case is even better. That’s how good it feels when you hold the keyboard.

There’s no backlit, media keys, OS X friendly keys (can be solved with software), usb hub built-in or detachable cable. Some of those are nice features to have but not essential to me. I personally hate backlit and think it’s to gaming-y. I bought this board because it’s a simple, no bullshit keyboard. Overall, I’m very satisfied with the aesthetic of this keyboard.

The switches

I went with the blue switches option. It’s my personal favorite choice of Cherry switch. One downside as you probably already have known is this thing is really loud. I mean REALLY loud. If you want to make your colleagues secretly hate you, buy one of those blue switch mechanical keyboard.

The keycaps

The default keycaps look pretty good and it matches well with the whole design. I’ve always wanted a set of Dolch or Granite keyset but I don’t think it’s going to look good with this board. I haven’t had the luxury of trying them out yet though.

There were reports of fading key labels with other Filco’s keyboard so they release this keyboard with front face printing keycaps. I think it’s a lame reason but it looks pretty cool though.

For this keyboard’s price range, it should have shipped with thick PBT keycaps instead of coated ABS.


This keyboard is a simple, no-bs, very high quality keyboard. I love everything about this keyboard: the look, the feel and the sound. Though it’s a bit more expensive than the competitors’ keyboards, it’s totally worth it IMO. The fact that it is sturdier than a premium keyboard (HHKB) says it all.

It’s probably the best TKL keyboard with Cherry switches available right now.

Filco Majestouch 2 Italian Red (TKL) with blue switches

My latest addition to my keyboard collection: an Italian Red Filco Majestouch 2 (tenkeyless version) with blue switches.

It’s really hard to find a shop with Filco in stock here in Thailand. I could only find one with black switch in stock, which I am not a huge fan of as it’s the linear type with no tactile feedback and too stiff for my taste. Other shops mostly stock Razer, Rocco, SteelSeries and Ducky.

I was a bit hesitate at first with this purchase because I thought this board uses red switches (which is like black but less stiff) but turn out, it comes with blue one which is my favorite.

The keyboard comes with a keycap puller and some alternative keycaps: WASD cluster, 2 windows key and an Esc key, all are in red.

My next step is waiting for someone to sell their sexy SP’s Dolch (or Granite, or both :D) keyset to go with this board. In the meantime, this stock keyset probably will do just fine.

How to find table name when knowing column name and column value in Oracle

A tester in my project asked me today for a little help: how to find a list of tables that has column name A with value B. So I wrote a short script and sent him. I thought I would share it here too, in case if might be useful to someone.

Usually cases like this, you will query from user_tab_cols or all_tab_cols for list of tables that has a column with that name and find out.

The query below will do exactly that but with the loop added to make searching easier. Make sure you have DBMS output enabled.

  col_name varchar2(100) := 'COLUMN_NAME';
  search_value varchar2(100) := 'COLUMN_VALUE';
  cnt number := 0;
  cursor c is select distinct table_name from all_tab_cols where upper(column_name) = upper(col_name);
  for e in c loop
    cnt := 0;
    execute immediate 
      'select count(' || col_name || ') from ' || e.table_name || ' where to_char(' || col_name || ') = to_char(''' || search_value || ''')'
    into cnt;
    dbms_output.put_line('Found ' || cnt || ' record(s) in ' || e.table_name);
  end loop;

Sample output:

Found 0 record(s) in TABLE_NAME
Found 1 record(s) in TABLE_NAME1
Found 0 record(s) in TABLE_NAME2

Some useful use cases for Java Reflection

While most will recommend you not to use Reflection because:

  • Lose ability to refactoring because you hard-code the name of class/method as String.

  • Lower runtime performance,

  • No compile time safety check.

However, there’re many cases Reflection can become very useful that it pros might outweight its cons. Or it’s just cool to show colleagues some new cool tips.

Easier to implement toString() method for debugging

You can use Reflection to loop through an Object’s attribute and print it out instead of using StringBuilder to append it yourself. This feature is available in Apache Common Lang. Or you can write it yourself if all you need is this method.

public String toString() {
  return ReflectionToStringBuilder.toString(this);

Note: This is actually not used often because modern IDE(IntelliJ, Eclipse, NetBean, …) already has ‘generator’ for this kind of thing.

Create object/call method using name

This is one of the reasons why Reflection exists in the first place. It’s useful in case like you have some configuration stored in database and you want to create object using class name (e.g.: like building cache using class name and table name on startup).

Or another case would be like: You get tired of calling .add for BigDecimal so you write a function to sum it up, taking an ArrayList of BigDecimal as parameter. But it’s not convenient because in reality, you have object of other data type and you will have to create the ArrayList of BigDecimal by looping through the collection. This is when Reflection comes in handy. You can use Reflection to create a function, passing a collection of anything and a method name to get the BigDeicmal value out.

@SuppressWarnings({ "rawtypes", "unchecked" })
  public static <T> BigDecimal getSumBigDecimal(ArrayList<T> bcArr, String methodName) {
    BigDecimal sum = BigDecimal.ZERO;
    if (null != bcArr && bcArr.size() != 0 && !StringUtil.isEmpty(methodName)) {
      try {
        T firstItem = bcArr.get(0);
        Class klass = firstItem.getClass();
        Method method = klass.getMethod(methodName);

        for (T each : bcArr) {
          BigDecimal bc = (BigDecimal) method.invoke(each);
          sum = sum.add(bc == null ? BigDecimal.ZERO : bc);
      catch (NoSuchMethodException | SecurityException | IllegalAccessException
          | IllegalArgumentException | InvocationTargetException e) {
        // do what you must here, I'm catching because it's an example
    return sum;

Reflection is cool and all but please use it with care. Make sure the pros outweight the cons. Know what you’re doing.