Skip to content

Instantly share code, notes, and snippets.

View sinewalker's full-sized avatar

Michael Lockhart sinewalker

View GitHub Profile
import pygame, random
pygame.init();
scr=pygame.display.set_mode([640,400])
df=pygame.display.flip; rnd=random.randrange; draw=pygame.draw
scr.fill([0,0,255]); df()
while True:
draw.aaline(scr, [rnd(255),rnd(255),rnd(255)],
[rnd(640),rnd(400)],
[rnd(640),rnd(400)]); df()
@sinewalker
sinewalker / SICP.md
Last active August 25, 2017 22:05
SICP in Info format

I found the SICP available for Emacs in the MELPA. It's a conversion of the HTML version made available for free by MIT, into Texi and then generated into Info.

The source for the MELPA is available on github: https://github.com/webframp/sicp-info

There was one open Issue: webframp/sicp-info#2 so I forked the master repo and created a PR from the correction to that, plus regenerating the whole Info as this appears not to have been done in 4 years.

Hopefully my PR will get accepted. If not, then I can still use my own fork, I'll just have to learn how to install a local package with Spacemacs, which I think isn't too hard.

@sinewalker
sinewalker / makeQR.py
Last active February 7, 2017 12:46
make a QR code from any text (requires qrcode: pip install qrcode pillow)
#!/usr/bin/env python
# usage: echo "My QR Text"|makeQR.py > myqr.png
# see http://alecthegeek.github.io/2013/04/28/creating-qr-codes-on-python.html
import sys
import qrcode
qrcode.make("".join(sys.stdin.readlines())).save("/dev/stdout","png")
@sinewalker
sinewalker / 2017-03-12--tmux-centos.md
Last active May 20, 2017 22:10
tmux centos/scientific
@sinewalker
sinewalker / fix-id3s.py
Created April 26, 2017 09:14
use eyed3 to set ID3 tags on MP3 files
# I used this code within an IPython session to clean up all the missing ID3 tags from my MP3 collection.
# They had gone missing years ago when I down-sampled them to fit on an old phone, and then lost the originals.
# Fortunately I named the files themselves with the basic details (artist, date, title and so on) so it was possible to
# recover the tags... It sat on my to-do list for *years* but now I finally did it.
# I used the Python library "EyeD3" (get it?): https://pypi.python.org/pypi/eyeD3
# This requires Python 2.7, which has some interesting quirks for Unicode, a bit of a pain since I had named my MP3s
# with utf8 characters. What I've come up with *mostly* works. When it doesn't I had to resort to manually editing (using
# Clementine).
@sinewalker
sinewalker / sources.sh
Last active July 2, 2017 02:19
sourcing utility functions from a library, in bash
base=$(cd -- "$(dirname -- "$0")"; pwd -P)
source $base/util/platform.sh
source $base/util/check-required-utilities.sh
@sinewalker
sinewalker / check-required-utilities.sh
Last active May 18, 2021 00:40
Checking a bash script's requirements are met by the host OS
# required utilities
required=(
grep
awk
curl
jq
)
missing=()
@sinewalker
sinewalker / unixdates.md
Last active January 27, 2023 04:40
Unix Epoch conversion

Convert a Unix timestamp into human-readable format:

  • GNU: date -date='@1501768813'
  • BSD: date -r 1501768813

Convert the other way

  • Current date/time as Unix timestamp: date +%s

  • A specific date/time (assumes current timezone):

@sinewalker
sinewalker / count-cpus.md
Last active August 25, 2017 21:55
counting CPUs on Linux

I was using this pipeline:

grep -c processor /proc/cpuinfo

However there's a better way: nproc

and for a good summary of CPU info from /sys and /proc/cpuinfo use lscpu which has options to produce parseable output for pipelines.

@sinewalker
sinewalker / appdata.md
Last active January 6, 2018 21:46
Temporarily change %APPDATA% for portable settings (Windows: e.g. Minecraft)

Need to take %APPDATA% directory data to another PC? For example Minecraft game saves to take in to a school for projects, or to a friend's house. The tricky part is: %APPDATA% has a different location depending on the version of Windows. Yay Microsoft, thanks once again.

The good news is that many Windows programs do use the environment variable to locate this folder, so you can just override it and launch your game or whatever from a .cmd / .bat file.

In the case of Minecraft on a USB:

  1. Make a folder structure on the USB drive for it (assume E: is the USB):
    • E:\Minecraft
    • E:\Minecraft\bin
  • E:\Minecraft\data