Sticky Notes

Table of Contents

This page hosts little ideas, solutions to problems I’ve faced in the past or mistakes that I don’t want to repeat again - stored here as a reference in case they bother me again. Read on, maybe even you might find something relevant!

Some useful aliases

$ alias timesync='sudo /etc/cron.daily/timesync'
# /etc/cron.daily/timesync
sudo date -s "$(wget -qSO- --max-redirect=0 google.com \
              2>&1 | grep Date: | cut -d' ' -f5-8)Z"
$ alias sv='source venv/bin/activate; export PS1="(${PWD##*/}-venv)$_OLD_VIRTUAL_PS1"'
$ alias log='tail -f /var/log/syslog'
$ alias nmr='sudo service network-manager restart; sudo service networking restart; log'
$ alias duinfo='sudo du --all --block-size=MB --max-depth=1 | sort -n'

Docker and DC++

Docker and DC++ don’t go hand in hand. Docker creates iptables routes for private ip addresses like 172.17.x.x and DC++ uses the same. You may keep on getting No route to host when you try to connect to a hub, which is really annoying! @kamermans has a gist here that helped me out.

Test outgoing ports

At times you may be behind a restricted network. Here is a bash script to check all outgoing ports that aren’t blocked by your firewall.

I tested the open ports (upto 4000) in my university and here is the list as of October 2016:

22   SSH
53   DNS
80   C'mon!
143  IMAP
443  HTTPS
465  SMTP
993  IMAPS
2082 cPanel. Strange!

Use Google Fonts offline

Sounds simple, but no easy way to do it. I found this tool by @majodev to be really helpful.

Installing Node

Again, there is an overload of methods used to install node and npm. Here is what works for me - the easy way.

$ sudo apt-get install nodejs npm
$ sudo npm install -g n npm
$ sudo ln -s "$(which nodejs)" /usr/bin/node

Installing OpenCV

Installing OpenCV has always been a mammoth task. I seriously hate the whole process of downloading a bulky git repository and building it from the source. And also the fact that there’s no easy pip install opencv way out. But as long as you don’t have any constraints like using it on an embedded device, the folks at menpo have an easy way out using anaconda.

$ conda install -c menpo opencv
$ conda install -c menpo opencv3

Of course, if you have specific requirements, it’s better to build from source.

Raspberry Pi

Configure Mutt with Gmail

Nick’s post describes how to use your own gmail account in case you want to set up something like automated email alerts or regular database backups.

Remove Python Package with Dependencies

Thanks to Tomasz Gągor. You can find his script here

Academic writing with Pandoc

Mort Yao’s post at soimort.org is a useful resource on using Pandoc for academic writing.

PuDB Custom Stringifier

# see https://github.com/inducer/pudb/blob/master/example-stringifier.py
import torch


def pudb_stringifier(obj):
    """
    Returns different representations based on the type
    """
    if isinstance(obj, (int, float, complex, str)):
        return '{}: {}'.format(type(obj).__name__, obj)
    if isinstance(obj, torch.Tensor):
        return '{}: {}'.format(str(obj.type()), str(list(obj.size())))
    if isinstance(obj, (list, dict, tuple)):
        return '{}: {}'.format(type(obj).__name__, str(len(obj)))
    else:
        return type(obj).__name__

Interesting Jekyll Themes

Installing docker-compose in Ubuntu 22.04 LTS

sudo apt install docker-compose You will get an error when you try

$ docker compose
docker: 'compose' is not a docker command.