Tuan Anh

container nerd. k8s || GTFO

A better sitemap for jekyll

jekyll sitemap use site.time for lastmod so it doesn’t really reflect the actual last modified date of the post but the last updated date of the site instead.

I’m not so sure if lastmod attribute has much effect on Google’s crawl rate/SEO to your site since it’s optional but I’m a little picky even when it comes to small thing like this.

Since last modified date is available from the source file, it should be generated automatically from that. kinnetica’s sitemap plugin for jekyll make use of .mtime for lastmod in sitemap which is the actual last modified date of the post.

Clone the repo, put sitemap_generator.rb in your _plugins folder and you’re all set.


jQuery Tips and Tricks

If your daily job has to deal with jQuery, you should definitely read this.

link bài gốc

Is Mailbox (for Mac) the last email client you ever need?

tl;dr: No, hardly.

The much anticipated Mailbox app for Mac released its first public beta today. Too bad, it seems to me that Mailbox has failed to live up to the expectation.

Mailbox was originally released as an iOS app only. The design is very simple and elegant with an unique take on swiping/snoozes features. I’m a big fan of Mailbox for iOS and I’ve been waiting for Mailbox to release their Mac app companion ever since Sparrow abandoned.

I realize that this is just the first public beta release so there are obvious many kinks that need to work out. I just don’t like the direction Mailbox for Mac is going.

The iOS version is simple and I prefer it to be stay that way. When I check my emails in the morning on my phone, my workflow is like:

  • act on it if i can finish it within 5 minutes.

  • archive it there is nothing to do and no further action required.

  • select Later if there’s action needed to be done but cannot be done rightaway.

  • repeat the process.

On my computer, however, I expect many more features than just that. Being acquired by Dropbox earlier, I at least hope that feature like using Dropbox for attachment would be available on day 1. Ever since Sparrow introduces that feature, it’s been one of my must-have feature in an email client. You have complete control over the attachment even if the email is already sent. I can even delete it if I regret after clicking send. I can even update the file without resending the email.

The email composer is seriously lack of features. No markdown, no HTML, no quoting whatsoever. Just pure plaintext. Simplicity is good but it’s no excuse for the lack of features.

The UI looks modern but definitely not my thing. It’s way too bright and the contrast is too low for my taste. And there’s no preferences to customize the UI. You’re stucked with the default.

I will stick with Airmail for now. With some little tweaks, Airmail can look pretty decent and quite feature-complete for me. It’s the closest thing to Sparrow I can find.

airmail os x


Fix unable to download huge files with varnish

I recently stumble against a problem with my varnish setup. I couldn’t download any file (huge ones) from my webserver (nginx). The problem only seems to occur with varnish enabled.

A little Google-fu, I found that the problem indeed was caused by varnish because varnish was intefering (timeouts and post-processes) with the request from client.

The fix is simple: let client and server talk directly without varnish interfering using pipe.

sub vcl_recv {
  # condition to trigger pipe
  if (req.url ~ "^/path/or/file/extension/or/whatever/condition/you/have/") {
    return (pipe);
  }
}
...
sub vcl_pipe {
  set bereq.http.connection = "close";
}

Try wget your files again. It should be fixed now.


Lift - an app that put your goals into action

Lift is an app that help you to form/track/analyze new habits. This is part of my new experiment to become a better self. Some of the stuff I like to do it more often and more regular like: pushup every morning, drink more water, learn new language, talk to one stranger a day, etc.. for starters.

I’m still very much in the process of learning, tweaking this method. But that’s the beauty of it. Becoming a better you than yesterday is not just a habit, it’s a way to improve life.


Localization with jekyll

Do you want to create a multilingual blog with jekyll? Here’s an easy way to setup jekyll to have content in multiple languages.

Create localized string data file

Create a folder named _data if you don’t already have one. Inside that folder, create a localization data file and name it messages.yml.

mkdir _data
touch messages.yml

Edit messages.yml and add localized strings. For the moment, I will just create a simple phrase and 2 localized strings in English and Vietnamese for testing purpose.

locales:
  en:
    example: "example"
  vn:
    example: "Ví dụ"

Display localized strings on post/page

Now you need to capture the locale of the current page. You can do it either by capturing the url (if you organize posts by folders of language’s name) or from the page variable. To make it easy in this port, i will use the current page’s locale variable; if not specified then default to ‘en’.

locale: "vn"

Get the localized string with this syntax

{{ site.data.messages.locales[locale].example }}

And that’s it. Go back and add more localized strings, update templates and publish changes. Your website is now multilingual.

To make it even more visitor-friendly, you can create a separate RSS feed for each one of the language.

Alternatively, you can use jekyll-multiple-languages-plugin1, though I’m not a big fan of using plugin when not I don’t really need to.

  1. http://rubydoc.info/gems/jekyll-multiple-languages-plugin/1.2.5/frames 


My favorite tiling window manager for OS X

The problem of window manager has been with us ever since GUI and multitasking were introduced. Despite being considered as a most modern OS, OS X failed short when it comes to window manager, especially when compared with Linux. I’ve tried many so-called tiling window managers for OS X. All have failed for me so far but Amethyst.

To name a fews that I’ve tried: SizeUp, Spectacle, DoublePane, Slate, BetterSnapTool and some others… Most of them are not tiling but just simple window managers.

I’ve tried Amethyst before but it was not stable enough for daily usage at the time. I like the concept every much though. I later settled on SizeUp and Witch combo for window manager. They suck. But they suck the least at the time. And most importantly, it wasn’t really tiling at all.

About Amethyst

Tiling window manager for OS X similar to xmonad. Was originally written as an alternative to fjolnir’s awesome xnomad but written in pure Objective-C. It’s expanded to include some more features like Spaces support not reliant on fragile private APIs.

A quick screencast to show basic features of Amethyst

Getting started with Amethyst

Basic usage of Amethyst is very well-covered in its documentation on GitHub. I won’t go into details here. Some commonly used shortcuts are:

  • mod1 - option + shift

  • mod2 - ctrl + option + shift

  • mod1 + space — cycle to next layout

  • mod1 + j - focus the next window counterclockwise

  • mod1 + k - focus the next window clockwise

  • mod1 + return - swap the focused window with the main window

  • mod1 + h - shrink the main pane

  • mod1 + l - expand the main pane

That’re probably all you need to know to get started with Amethyst. Go figure some more when you’re familiar with the new tool. All of them are configurable in .amethyst configuration file in your home directory.

Amethyst is probably the best tiling window manager for OS X right now. It’s simple, intuitive and very lightweight with a low learning curve. You don’t have to learn a whole lot of new shortcuts to make the best out of Amethyst. It’s currently the top app on my software recommendation list.


Post scheduling with jekyll

First, update your _config.yml and set future to false. By doing this, jekyll will not publish any post with future date.

future: false

Setup a cronjob to check and rebuild the site if there’re posts to be published. Since I already setup a hook on post-receive (trigger on receving a git push) to rebuild the site, I’m going to set a cronjob to execute this script instead of writing something new. The content of the post-receive looks like this.

# post-receive
#!/bin/bash -l
GIT_REPO=$HOME/repos/myblog.git
TMP_GIT_CLONE=$HOME/tmp/git/myblog
PUBLIC_WWW=/var/www/myblog

git clone $GIT_REPO $TMP_GIT_CLONE
jekyll build --source $TMP_GIT_CLONE --destination $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit

Cronjob that execute post-receive every hour at 0 minute, everyday.

@hourly /path/to/my/post-receive

The only downside of this is you need to be able to setup cronjob. GitHub Pages and shared hostings are probably not going to work in this case. You will need to verify this yourself.


How to setup Discourse local dev environment on OS X

I find this the easiest way to install Discourse on OS X for local development purpose. The idea is this: you install Ubuntu as a VM and setup Discourse on top of that.

Install Vagrant

Setup Vagrant is as easy as double click the installer and a couple of next click. I have a license for Parallels 9 so I use Parallels as default provider. You can use VMWare if you own one or VirtualBox for free if you don’t feel like paying.

I use puphpet’s Ubuntu 14.04 x64 as base box but literally, anything Ubuntu 14.04 would work. Ubuntu 14.04 is recommended version by Discourse.

You can use PuPHPet online GUI configurator to create a configuration of your own.

vagrant plugin install vagrant-parallels
mkdir discourse-local
cd discourse-local
vagrant init puphpet/ubuntu1404-x64
vagrant up --provider=parallels
vagrant ssh

Install Discourse with Docker

Follow this tutorial on Discourse Meta to setup Discourse on your Vagrant box.

Discourse should be up and running on your Vagrant box’s IP address after this.


jekyll full-text search without jQuery or plugin

I did a quick search for full-text search solutions for jekyll (or any static websites). A notable fews have come up in search result:

A quick look at the plugin’s dependency, I give up right away even though I only need that on search page. For the very same reason I opted for jekyll - a static site generator, I want my site to load as fast as possible. Adding a bunch of dependencies like that is against the purpose. I rather go for DuckDuckGo as I’m currently doing.

Dependencies for the jQuery plugin are as follows.

  • jQuery
  • lunr.js
  • Mustache.js
  • date.format.js
  • URI.js

index_tank

Too bad the service is no longer available.

tapir

The most decent service I found so far. You sign up, add your feed URL so that the service can start indexing your website, add jQuery and tapir.js and you’re good to go.

Search API:

api/1/search.json?token=******&query=*****
/api/1/search.json?token=******&query=*****&callback=myCallback

tapir.js looks like a pretty short and simple js file. Adding jQuery dependency on it, is totally overkill.

Exercise for next week: I’m going to replace DuckDuckGo search with Tapir’s search in a few days once I’m done converting Tapir’s jQuery plugin to a pure js solution.