1. Remove unused kernels

    Removes all but current kernel and headers. This is a note for personal use. Use at your own risk :)

    dpkg-query -f '${Package}\n' -W |  egrep 'linux-(headers|image)-[[:digit:]].*(|-generic)' | grep -v $(uname -r | sed 's/-generic//') | sudo xargs apt-get -q -q -yy --purge remove


    1. List all packages.
    2. Find only linux-image and linux-header packages with version number, not the two main meta packages.
    3. Remove the linux-image and linux-header for running kernel from the list.
    4. Purge all listed packages from system without asking any questions.


  2. Modeline in vim

    Options set in .vimrc applies to all vim files. You can use modelines to set specific vim options for one file. Modeline option must be set in .vimrc to take advantage of this option.

    set modeline

    The modeline should be the first line in the file. You can set it inn multiple ways as shown below.

    # vim: set ai et ts=4 sts=4 sw=4 tw=79 cc=80 wrap wb nu sm:
    /* vim: set enc=UTF-8 ai et ts=4 sts=4 sw=4 tw=79 cc=80 wrap wb nu sm: */
    // vim: set enc=UTF-8 ai et ts=4 sts=4 sw=4 tw=79 cc=80 wrap wb nu sm: 


    • enc=UTF-8
      Set encoding to UTF-8
    • ai
      Auto intend
    • et
      Expand tabs with spaces
    • ts=4
      Tab stop set to 8
    • sts=4
      Soft tab stop
    • sw=4
      Shift width, used by >> and <<
    • tw=79
      Text width
    • cc=80
      Set colour column, a colour bare at character 80
    • wrap
      Wraps text, only affects how the text is displayed
    • wb
      Write a backup before saving files
    • nu
      Show line numbers
    • sm
      Show matching brackets


    More information in the Vim documentations under options.


  3. Bash getopts example

    This is a small example how to use getopts in bash. I wrote it down for my own sake, as my own cheatsheet :)

    # Print help on stderr
    function show_help(){ 
        cat >&2 <<EOF
    Explain all about $(basename $0) here.
    # Print usage on stderr
    function show_usage() {
        echo "$(basename $0) [-a ARG] [-b] [N1 [N2 .. [NN]]]" >&2
    # Print usage and exit with error code 1 if we don't have any options
    if [[ "$@" = "" ]]; then
        exit 1
    # :  = make getopts silent, handle errors self
    # a: = option a expects an argument
    # b  = option b is a true false option
    # h  = option h is a true false option
    # On invalid option, opt will be replaced with ? 
    # and OPTARG set to argument name
    while getopts ":a:bh" opt
        case $opt in
            a)  echo $OPTARG;;
            b)  echo True;;
            h)  show_help; exit 1;;
            \?) echo $(basename $0) invalid option: -$OPTARG >&2
                exit 1
    # OPTIND is not reset after getopts is finished. 
    # Loop through argument  [N1 [N2 .. [NN]]] 
    for ARG in ${@:$OPTIND}
        echo $ARG


  4. Creating a blog based on Pelican

    Pelican is a static website generator written in Python. It's perfect for maintaining a tiny blog without having to mess around with databases. Static pages can be served from any Web server. Even your wireless router if you run custom firmware as Tomato by Shibby or dd-wrt.

    Running Ubuntu Trusty I chose to use Pelican package in repository. A very quick recipe for creating a blog with the default theme.

    1. Install Pelican and package for Markdown language. With Markdown you write the content in text and Pelican translates it to HTML.

      apt-get install python-pelican python-markdown
    2. Make a directory where you want to maintain your blog.

      mkdir myblock; cd myblock
    3. Run the Pelican quick start script and answer all the questions. Add at least one method of uploading your blog to a web server.

    4. Start by creating your first page in content directory. Each page should have a heading with some metadata.

      Title: Creating a blog based on Pelican
      Date: 2014-04-12
      Category: Blog
      Tags: blog,howto
      Slug: 2014-04-12-pelican
      Author: arnulf
    5. Start the local HTTP server and check how your blog is coming along.

      make serve
    6. Point your browser to http://localhost:8000

    7. Upload your blog to your web server. I prefer the ssh upload option.

      make ssh_upload

    A more lengthy and better getting started guide on getpelican.com. I did find adam-p's Markdown Cheatsheet on github quite useful. And not to forget all the themes you can download from github.


« Page 3 / 3