Skip to content

Instantly share code, notes, and snippets.

View qxcv's full-sized avatar

Sam Toyer qxcv

View GitHub Profile
@qxcv
qxcv / gollyconvert.py
Created March 22, 2014 08:45
Script to convert from .bmp wireworlds to Golly wireworlds
#!/usr/bin/python2
from os.path import basename
from subprocess import PIPE, Popen, check_output
from sys import argv, exit, stdout, stderr
from re import compile
USAGE = "USAGE: {0} input.bmp|input.rle > output.rle|output.bmp\n".format(argv[0])
RLE_HEADER = "x = {x}, y = {y}, rule = WireWorld\n"
@qxcv
qxcv / Makefile
Last active August 29, 2015 14:00
comp2300 a2 automatic tester
CXXFLAGS=-std=gnu++11 -Os -Wall -Wextra
URL=http://cs.anu.edu.au/courses/COMP2300/rpeanut/rPeANUt2.3.jar
.PHONY: all
all: autogen reference rPeANUt2.3.jar
chmod +x autotest
@echo "Build complete"
autogen: autogen.cpp
$(CXX) $(CXXFLAGS) autogen.cpp -o autogen
@qxcv
qxcv / tikzmagic.py
Last active August 29, 2015 14:18
tikzmagic.py for Py3K
# -*- coding: utf-8 -*-
"""
=========
tikzmagic
=========
Magics for generating figures with TikZ.
.. note::
@qxcv
qxcv / index.html
Last active August 29, 2015 14:20
MU0 assembler in Javascript
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>MU0 assembler</title>
<style>
body {
font-family: sans-serif;
@qxcv
qxcv / unblur.m
Last active December 8, 2015 04:02
Applying a small kernel to an image to reduce blurriness.
% Demo of a basic filter for deblurring an image
% Grab image
img_url = 'http://www.artwallpaperhi.com/thumbnails/detail/20121017/sand%20macro%20blurred%201920x1200%20wallpaper_www.artwallpaperhi.com_77.jpg';
img = imread(img_url);
img = single(img) / 255;
% Apply convolution. Play around with the filter matrix if you're curious.
filter = [-1 -1 -1; -1 9 -1; -1 -1 -1];
result = zeros(size(img));
@qxcv
qxcv / spacemacs-cheatsheet.md
Last active January 18, 2017 18:22 — forked from 526avijitgupta/spacemacs-cheatsheet.md
Spacemacs cheatsheet

emacs --daemon to run in the background. emacsclient.emacs24 <filename/dirname> to open in terminal

M-m and SPC can be used interchangeably. I've used Ldr (for "leader") as a compromise.

  • Undo - C-/
  • Redo - C-?
  • Change case: 1. Camel Case : M-c 2. Upper Case : M-u
  1. Lower Case : M-l
@qxcv
qxcv / freeglut_demo.py
Created October 25, 2018 03:43
FreeGLUT non-blocking drawing demo
#!/usr/bin/env python3
# Shows us to use non-blocking event loop from FreeGLUT. Original code from
# https://code.activestate.com/recipes/325391-open-a-glut-window-and-draw-a-sphere-using-pythono/
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
import sys
import threading
@qxcv
qxcv / mlp_compare_cpu_gpu.py
Created November 19, 2018 18:09
Script for comparing performance of CPU & GPU on a simple MLP
#!/usr/bin/env python3
# (this script also requires tensorflow-gpu to be installed & working)
# increase hidden size/batch size to close gap between CPU and GPU
DISABLE_GPU = True
HIDDEN_UNITS = 64
BATCH_SIZE = 64
if DISABLE_GPU:
import os
@qxcv
qxcv / exit_with_parent.py
Created July 11, 2019 02:36
Forcing Python process to exit with parent
import ctypes
import sys
def parent_death_pact(signal=signal.SIGINT):
"""Commit to kill current process when parent process dies.
Each time you spawn a new process, run this to set signal
handler appropriately (e.g put it at the beginning of each
script, and in multiprocessing startup code)."""
assert sys.platform == 'linux', \
"this fn only works on Linux right now"
@qxcv
qxcv / peakmem.sh
Created January 16, 2020 19:03
Bash script to track peak system memory usage (mem + swap)
#!/bin/bash
max_mem=0
while [ true ]; do
# awk trick from https://stackoverflow.com/a/450821
mem="$(free --giga | sed 's/ \+/ /g' | cut -d ' ' -f 3 | tail -n +2 | awk '{s+=$1} END {print s}')"
if [ "$mem" -gt "$max_mem" ]; then
max_mem="$mem"
echo "new peak ${max_mem}GB at $(date)"
fi
sleep 0.1