sakana

very short memo

google anlytics in sphinx

If you would like to analyze statics of access to your site built with sphinx, then you can embed google analytics code in it.

Prepare layout.html file under source/_templates directory. Insert javascript code obtained at google analytics site.

{% extends "!layout.html" %}

{% block footer %}
{{ super() }}
<div class="footer">
<script>
(function(i,s,o,g,r,a,m){
    i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)
    },i[r].l=1*new Date();
    a=s.createElement(o),m=s.getElementsByTagName(o)[0];
    a.async=1;a.src=g;
    m.parentNode.insertBefore(a,m)
 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxxx-x', '<site_name>');
ga('send', 'pageview');
</script>
</div>
{% endblock %}

And rebuild html and deploy it onto site.

For details, please refer to sphinx FAQ.

back up files onto dropbox

All machine, which includes Hard Disks, are to break some day. Let’s back up your precious content onto dropbox with encrypted on regular basis.

create backup directory in dropbox.

$ mkdir ~/Dropbox/backup

Prepare backup script kicked by cron on regular interval. Create directory where backup script resides:

$ mkdir ~/Documents/cron

Deploy following backup script under cron directory:

#!/usr/bin/env bash

# we use day of week as file name
LANG=C
NAME=`date "+%A"`
# please specify password for encryption in case that you encrypt backup file
PASSWD=xxxxxx
# we create backup file under temporary directory on local host
# so as to avoid latency
TEMP=/tmp
BACKUP_DIR=~/Dropbox/backup

cd ~/Documents
if true
then
    find . -exec zip -P $PASSWD $TEMP/$NAME.zip {} \; 1>/dev/null 2>&1
else
    find . -exec zip $TEMP/$NAME.zip {} \; 1>/dev/null 2>&1
fi
mv $TEMP/$NAME.zip $BACKUP_DIR

Please be noted that you have to add execution permission for this script. And test it if it works or not.

$ bash -xv backup.sh

Register cron job to start script on regular basis by “crontab -e”. With following example, backup script is executed every one hour at *:00.

0 * * * * ~/Documents/cron/backup.sh

On ubuntu, cron activity is recorded in /var/log/syslog. Monitor syslog if cron works as expected.

try sphinx better theme

Found a new theme for sphinx.

Demo site looks nice & simple.

Let’s apply and see what kind of effect will have on my documentation.

Application procedure is quite simple. Install sphinx-better-theme package.

$ sudo pip install sphinx-better-theme

Apply theme by modifying conf.py.

from better import better_theme_path
html_theme_path = [better_theme_path]
html_theme = 'better'

Ok, stay with this theme.