Nov 25
“I think this summarizes everything.” — mnmal

“I think this summarizes everything.” — mnmal


Nov 22

Go Syntax in Vim

Go comes with a syntax file for vim (in misc/vim). I had to tweak ~/.vimrc a bit to make it work nicer. noexpandtab will force vim to insert tabs instead of spaces, smartindent makes the editor keep new lines at the same level of indendation as the previous line.

augroup golang
  au!
  au BufRead,BufNewFile *.go set filetype=go
  au FileType go set noexpandtab
  au FileType go set smartindent
  au FileType go set equalprg=gofmt
augroup END

Nov 4

Oct 22

Shell-Scripting for Fun and Profit: Finding, Downloading, and Merging Course Slides to a Single PDF

Motivation

Professors often provide a page with links to lecture slides in PDF format. The main benefit of joining them to a single document, is that one can use a reader’s search function to find topics and keywords faster than when searching in multiple documents.

Read More


Oct 19

Oct 16

The Use of “do { … } while (0)” in C Macros

Consider a countdown program.

countdown.c:

#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    int seconds = 3; 

    for (int i = seconds; i != 0; --i) {
        printf("%i... ", i);
        fflush(stdout);
        sleep(1);
    }
    puts("Go!");

    return 0;
}

The goal is to put the actual countdown code in a macro. It fits perfectly in a function, but a macro is used for illustration purposes.

Read More


Oct 14

Using Javascript to Provide Dynamic Content in Tumblr

This article describes how content can be added to Tumblr using Javascript, and the jQuery library. The reader should be familiar with web development.

A Simplified Theme

<html>
<head>
  <title>My Tumblr</title>
  <script type="text/javascript" src="http://example.org/jquery.js"></script>
  <script type="text/javascript" src="http://example.org/tumblr-dyn.js"></script>
</head>
<body>
    {block:Posts}…{/block:Posts}
    <p id="quote-of-the-day" style="display:none"></p>
</body>
</html>

We shall add a quote to #quote-of-the-day for permalink views.

tumblr-dyn.js

var isSinglePostView = function() {
    var loc = document.baseURI;
    var re = new RegExp(".*mytumblr.example.org/post/.*");
    return loc.match(re) != null;
}

$(window).ready(function() {
    if (isSinglePostView()) {
        var qotd = $("#quote-of-the-day");
        qotd.html(
            '"You should\'ve seen the look on her face. It was the same look ' +
            'my father gave me when I told him I wanted to be a ventriloquist."' +
            ' – George Costanza');

        qotd.css('display', 'block');
    }
});

You can use this approach to add custom content depending on what page the user is viewing.


Oct 13

Configuring an SSH Gateway

An SSH gateway can be used where multiple hosts share the same IP address, where it isn’t possible, or acceptable, to use separate ports for the hosts’ SSH daemons.

Read More




Simon Pantzare
Simon Pantzare, also available on
Facebook,
Twitter,
Google+,
Reddit,
Github (dev blog).
Ask me anything.