At the start of year 2013, I tried to set up a system on a wordpress blog so that I could blog from commandline. The plan became moot when I found out that my web hosting service provider did not have the latest PHP installed and I just could not install WP-CLI or wordshell. Maybe I did not try hard enough, but I had many doubts about its usefulness. Six month after, I gave Jekyll and Octopress a try. It was quiet easy to set it up. But since I do not use Ruby, I began to worry how much I could customize or create a plugin if I needed one. So the final winner for me was Pelican, which uses Python instead and the setup is as easy as Octopress.

Regardless of your choice, the main attraction about the static blog is that if you have a good relationship with your editor (mine being gVim), blogging can be a easy task for you. Too often I have witnessed many awesome bloggers leaving their blogs because they get too busy. That was the case with my first blog except I was not an awesome blogger.

Prerequisite

  • pip installed
  • git configured with proper user account information

Installation

sudo pip install pelican Typogrify disqus-python markdown ghp-import shovel beautifulsoup4
# I make a symlink so I can use it from [my vim](vim-markdown-preview.html)
sudo ln -s /usr/local/bin/markdown_py /usr/local/bin/markdown
# go the parent directory where you want your pelican folder to reside
pelican-quickstart

Create Post

Add the following before your markdown file Example:

Title: Welcome All
Slug: welcome-all
Date: 2013-07-22 19:19
Category: Python
Tags: pelican, publishing
Author: Josef Jezek
Summary: Short version for index and feeds

But I only use three meta data. 'Title', because it is required, 'Tags', and 'Status', which are optional, but the latter allow Pelican to skip generating html if the value is 'hidden'. Everything else can be auto-generated by your pelicanconf.py

Generate blog

By default pelican reads from directory 'content', which is supposed to have either .md or .rst files and generates .html files in 'output'

pelican -s pelicanconf.py

Local Test

Blog generation very quick, but I initially worked with small set of articles so that I could make changes quickly and see different features and plugins. Make sure you set SITEURL to nothing or comment it out in pelicanconf.py, otherwise, css files and links will not work.

cd output
python -m SimpleHTTPServer 8000

I do not use make devserver, because I have placed my output folder somewhere else, and I get an error message.

Deployment

If you are new to Github pages, the concept of Project pages maybe new. This page explains it. gh-pages is branch you make when your master branch has the source code for your project. Then you can host the contents of gh-pages to a url of your choice. I am not delving into how-to for this, because I am not using it for this blog, which does not have a project associated with it. I am mentioning it though because coming from Octopress, I thought it was the way I am supposed to deploy Pelican. No, but some manual work is needed here or you need to write a shell script.

Anyway, to deploy, create a git repository on 'output' folder and setting the repository named username.github.com as the remote branch.

git init
git add -A
git commit -m "latest"
git remote rm origin
git remote add origin git@github.com:Forethinker/forethinker.github.com.git
git push -u origin master

This is what I put in crontab:

(cd ~/Dropbox/web/pelican && pelican -s pelicanconf.py); (cd ~/pelican && git add -A && git commit -am "latest" && git push)

I was first against auto populating my blog without reviewing it first, but then the updates were getting delayed because I was busy.

Custom Domain

You essentially have to redirect your domain to point to github.io by modifying 'A record' to point to 204.232.175.78 on your domain registrar. Detailed info is here. And follow the instructions below so that CNAME is read from 'extra/CNAME' is copied to 'output' whenever blog is generated and the github server could read the filename CNAME and know which domain to use.

mkdir -p content/extra
echo "domain.name" > content/extra/CNAME

and edit pelicanconf.py:

EXTRA_PATH_METADATA = { 
        'extra/CNAME' : {'path' : 'CNAME'},
        'extra/readme.md' : {'path' : 'readme.md'}
        }

'extra' directory resides in 'content' directory and it will not create a new category. I also put my readme.md in the 'extra' directory. You might find a use for it. But just remember to add each files to EXTRA_PATH_METADATA variable along with correct apath so that the web server could read them properly.

Adding scrollbar for overflowing code block

Add the following line to the local.css or the primary stylesheet of your theme:

pre {
    overflow: auto;
    white-space: pre;
    word-break: normal;
    word-wrap: normal;
}

Other Optional, but Almost Essential Features

  • Adding Google search box in the corner. Yeah, you do not have any database to index your articles. So outsource that to Google. I personally think Google search is better than a customized search that most websites offer. jakevdp gave me the idea of modifying on the theme to get it working. It takes time for google to index your site though.

  • Disqus: check that your theme supports this, otherwise, you will have to see other theme to copy the code snippets to make this possible. I probably do not respond to the comments often, but it provides the opportunity for users to interact with each other and point out your mistakes. I think this is indispensable. Also it is very easy to set it up. Just sign-up on diqus.com and specify DISQUS_SITENAME in pelicanconf.py.

  • Pygments: Pelican allows you to syntax highlight according to the file type you specify. Just add ::: followed by any of the supported short names before any code block.

  • Liquid tags: It's a plug-in that added Liquid-style tags within markdown. I have not felt the need for this now, but I will probably need it in the future. Examples.

  • You could do some neat things with fabric to generate and clean up blog files with one command. But I opted to use good-old bash script because fabric does not seem to work in Windows (cygwin).

Comment

Fundamentals of Design by Tim Dikun @ codeschool.com

Color Types

Subtractive Color (CMYK): based on the white background, printer, physical

Additive Color (RGB): Based on the black background, monitor, virtual

Human process color based on Hue, Saturation, and Lightness

  • Hue (x): can be best represented with a color wheel, which enculates the entire RGB space. (Degree)
  • Saturation (y): the variation of the color to gray (%)
  • Lighness (z): the variation of the color with respect to white (100%) and black (0%)
  • These three properties can be best represented as a cylinder

First Choose a Base Color

  • Red: Heat, Passion, Excitement, Speed ...
Read More

Single array/list

  • Q: rotate an array by a particular index size, k
  • A: rotate the entire array first, then rotate first k elements and rotate the rest of elements
Read More
  • All questions are started with "Given a list of integers (not sorted)"
  • All numbers include negative numbers.
  • X is an arbitrary number that is predefined

Q: find 3 numbers that add up to a given number (a+b+c=d)

A: Convert the equation to a+b=d-c, make hash tables representing each side of the question. Iterate through each possible pair of numbers (n^2), see if the sum can be found in the difference hash table or if the difference can be found in the sum table. If true for each case. If the exact numbers are needed ...

Read More
  • red-black: a self-balancing binary search tree. It is guaranteed to always be balanced, but is complex to implement.
  • B tree: a n-ary search tree in which each node has up to n-1 values and n children.
Read More
[Algorithms](https://class.coursera.org/algs4partI-003/) by Rob Sedgewick

find whether nodes are have a path to another.

Quick-Find (Naïve implementation):

As the nodes get connected, all nodes in the resulting tree are marked with one of the node's id number. After all union operations, if any two selected nodes have the same ID, they are connected.

public void uinon(int p, int q)
{
    int pid = id[p]; //pid must be extracted because id[p] will change to qid
    int qid = id[q];
    for (int i = 0; i < id.length; i++)
        if (id[i] == pid) id[i] = qid;
}

Weighted ...

Read More

  • Look for a job that offers free (healthy) food
  • Join a startup company to get the visibility in the company and feel satisfied with your work
  • Even when the rent price is expensive, pay the price to not own/need a car.
  • Instead of trying to form good habits, block all distractions first.
  • Talk to your imaginary self from 10 years future - then choose your habits.
  • Don't travel too much. Save that for your retirement.
  • Ask for an advice from everyone.
  • Don't be afraid to skip things.
  • Keep your expectations low.
  • Read news headlines everyday.
  • Keep things simple ...
Read More

The focus of this article is on learning Computer Science, but it also applies to learning in general for Generation Y and beyond where computer is indispensable part of the learning process.

  1. Start now:

    Yes technology changes quickly and programming languages you learn today may not be marketable in a couple years, but the concepts behind the language do not change. So start with anything and stick with it. Just make sure you are not just reading stuff, but actually do the exercise after each chapter, otherwise, you will quickly lose what you have learned.

  2. You should go to a ...

Read More

Try jQuery

jQuery Video Tutorial by Derek Banas @ newthinktank.com

The Basic

Get the latest jQuery downloaded:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

Or Google's version for faster download speed:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js">

jQuery manipulates the DOM, tree-like representation of HTML file. It also handles the difference of JavaScript engine in different browsers. The following code waits for the document to finish loading, this is often always used for jQuery:

jQuery(document).ready(function(){
    <code>
});

jQuery objects are created by surrounding ...

Read More

Amazon now offers up to 30GB SSD instead of HDD for free-tier

I didn't check how much hard drive space I had before, but I was using well below 10GB. By default the general purpose SSD is set to 10GB, but the maximum allocation is 30GB for the free-tier t1.micro instance. Before you hit review button, there should be numbered tabs on the top that Amazon setup wizard did not redirect you, go to one of those and make sure to take the full advantage of free-tier service. I definitely noticed the speed up.

There is no password ...

Read More

Forethinker © forethinker