Skip to content

Instantly share code, notes, and snippets.

Avatar

Graham Poulter gpoulter

View GitHub Profile
@gpoulter
gpoulter / screenrec.sh
Last active Jul 31, 2018
Record your screen to later review how you were working
View screenrec.sh
#!/bin/bash
# Record a timelapse video of your screen.
#
# Tested on Debian with Cinnamon desktop.
#
# With a recording of how you spent a Pomodoro or other
# work sessions you can see where you spent your time and
# where to optimize the way in which you perform the task.
#
@gpoulter
gpoulter / branch_prompt.sh
Created Jun 9, 2018
Show the current Git or Mercurial branch in your Bash prompt
View branch_prompt.sh
## Print nickname for git/hg/bzr/svn version control in CWD
## Optional $1 of format string for printf, default "(%s) "
function be_get_branch {
local dir="$PWD"
local vcs
local nick
while [[ "$dir" != "/" ]]; do
for vcs in git hg svn bzr; do
if [[ -d "$dir/.$vcs" ]] && hash "$vcs" &>/dev/null; then
case "$vcs" in
@gpoulter
gpoulter / windowstat.sh
Last active May 8, 2017
Regularly log the active window while screen is unlocked (Ubuntu & OS X)
View windowstat.sh
#!/bin/bash
# Log active application and title of the active window on Ubuntu and OS X.
# Logs in pipe-separated format for easy transformation.
#
# Credit to StackOverflow for gdbus, AppleScript and Quartz snippets.
#
# Updates: https://gist.github.com/gpoulter/503d91b4d29ee908049
DELAY="${1:-60}"
LOGDIR="${2:-$HOME/.windowstat.tmp}"
@gpoulter
gpoulter / jpeg_caption_from_name.py
Created Apr 10, 2012
Set EXIF caption from JPEG filename
View jpeg_caption_from_name.py
#!/usr/bin/env python
"""
1) Start with a directory full of DSC_003242.jpg files from the camera.
2a) Download jhead.exe and save it as C:\jhead.exe
http://www.sentex.net/~mwandel/jhead/
2b) Go to Start Menu, "Run..." and enter "cmd" to open a DOS box. Change
to the image directory, and run "C:\jhead.exe -nf *.jpg" so all the files look like
@gpoulter
gpoulter / multihypergeo.py
Created Apr 10, 2012
Multi-hypergeometric distribution
View multihypergeo.py
#!/usr/bin/python
"""Calculates the distribution of a weighted sum of the components of
a multivariate hypergeometric random variable, for the special case of
three components with weights -1, 0 and +1 - although the generating
function can handle any weights and number of components. Given a
value t, it also calculates the p value of t under the null hypothesis
that it was generated as the weighted sum of the multivariate
hypergeometric variable.
@gpoulter
gpoulter / ubuntu_mirror.py
Created Apr 10, 2012
Maintain a local apt cache mirror of Ubuntu
View ubuntu_mirror.py
#!/usr/bin/python
"""ubuntu-mirror.py -- Make a personal mirror of a subset of Ubuntu or Debian
Usage: ubuntu-mirror.py [options]
First fetches Contents-arch.gz, Packages.bz2 and Release files, but
only if they changed size. Then it parses Packages.bz2 files and fetches
any non-excluded deb files which changed size (zero is a size :).
It keeps a list of downloaded debs, and deletes any debs no longer
@gpoulter
gpoulter / compress_pdf.sh
Created Apr 10, 2012
Compress/optimize PDF file
View compress_pdf.sh
#! /bin/bash
# AUTHOR: (c) Ricardo Ferreira
# NAME: Compress PDF 1.4
# DESCRIPTION: A nice Nautilus script with a GUI to compress and optimize PDF files
# REQUIRES: ghostscript, poppler-utils, zenity
# LICENSE: GNU GPL v3 (http://www.gnu.org/licenses/gpl.html)
# WEBSITE: https://launchpad.net/compress-pdf
# Messages
@gpoulter
gpoulter / csv_to_mm.py
Created Apr 10, 2012
Build Freemind MindMap from Excel file
View csv_to_mm.py
#!/usr/bin/python
"""Convert CSV table to MindMap format
Usage: python csv_to_mm.py sometable.csv > mymap.mm
CSV format is rows representing tree leaves, e.g.:
A1,
A1,B1
A1,B1,C1
A1,B1,C2
@gpoulter
gpoulter / strip_unicode_accents.py
Last active Jan 13, 2016
Strip accents from Unicode text
View strip_unicode_accents.py
"""Blunt instrument to avoid accented characters being corrupted by Excel
(when loading UTF-8) or OpenOffice (when loading CP-1252 but set to UTF-8)."""
import unicodedata
def not_combining(char):
"""True if the character can be removed"""
return unicodedata.category(char) != 'Mn'
@gpoulter
gpoulter / enum.py
Created Jan 25, 2012
Enumeration as a named integer.
View enum.py
"""Enumeration class representing a named integer."""
class Enum(int):
"""Enumeration value is a named integer."""
#pylint: disable=R0904
def __new__(cls, rank, name):
obj = int.__new__(cls, rank)
obj.name = name