Social sharing button without embedding sharing script crap

19 Dec 2014

Found this collection share url structure from various social networks on Github.

Example, for Twitter:

https://twitter.com/share?url={url}&text={title}&via={via}&hashtags={hashtags}

social sharing buttons

Use this along with font-awesome icons and we have some nice social sharing buttons without tracking scripts or slowing down your website one bit.

When static website isn't fast enough

18 Dec 2014

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).

Testing

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

16 Dec 2014

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

13 Dec 2014

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

07 Dec 2014

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.

Shorter code is better?

27 Nov 2014

wtfs/m

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?

26 Nov 2014

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