Skip to content

Instantly share code, notes, and snippets.

@dwo
dwo / Makefile
Created May 9, 2015 15:47
Resizing images from one folder to another with ImageMagick and GNU Make
source_files := $(wildcard src/*.jpg)
resized_files := $(source_files:src/%.jpg=resized/%.jpg)
all: $(resized_files)
resized/%.jpg: src/%.jpg
convert $< -resize 1920x1080 $@
@dwo
dwo / 0_deterministic_sample.rb
Last active August 29, 2015 14:21
Choosing random array members deterministically based on contents of array and a name string
require 'backports/1.9.1' if RUBY_VERSION < '1.9.1'
require 'backports/1.9.2' if RUBY_VERSION < '1.9.2'
require 'digest'
class Array
def deterministic_sample(n, name='')
seed = Digest::SHA1.hexdigest(self.sort.map(&:to_s).join << name).to_i(16)
prng = Random.new(seed)
self.sort.sample(n, :random => prng)
end
@dwo
dwo / superpull.sh
Created July 18, 2012 11:09
my bash script for pulling all projects and updating ctags
CWD=`pwd`
for i in `find . -type d -maxdepth 1`; do
echo $i
cd $i
git pull --rebase && git submodule update --init --recursive
ctags -R * > /dev/null
cd $CWD
done
@dwo
dwo / du-sorted.sh
Last active October 7, 2015 08:37
what's taking up all the space?
du -sm * | sort -nr | head -25
@dwo
dwo / gemocalypse.sh
Created December 13, 2012 20:12
I used this to delete all my gems once
#!/bin/bash
GEMS=`gem list --no-versions`
for x in $GEMS ; do gem uninstall -x --ignore-dependencies $x; done
#!/usr/bin/env bash
sudo apt-get update
sudo apt-get install build-essential autoconf automake libprotobuf-dev \
protobuf-compiler libncurses5-dev zlib1g-dev libio-pty-perl
./autogen.sh
protobuf_CFLAGS=" " protobuf_LIBS="-lprotobuf" ./configure --prefix="/usr"
sed -i s/LITE_RUNTIME/SPEED/ src/protobufs/*.proto
make
@dwo
dwo / 01_QR.scala
Last active December 19, 2015 19:18
Quine Relay on Mac OS X 10.7.5
object QR extends App{println("(display \"printf %s \\\"Transcript show: 'puts [regsub -all {.} \\\\\\\"};0 nruter;)\\\\\\\\\\\\\\\"eludomdne dne;)\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\(yalpsid\\\\\\\\\\\\$\\\\\\\\\\\\\\\"(tnirp};)\\\\\\\\\\\\\\\";)\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\ n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\t\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"(tnirp;)\\\\\\\\\\\\\\\" \\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"t\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"?0>2%)j>>\\\\\\\\]1-i\\\\\\\\[s((tnirp)--j;0=>j;6=j(rof;)\\\\\\\\\\\\\\\" \\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\(etirw\\\\\\\\\\\\$\\\\\\\\\\\\\\\"(tnirp{)++i;htgnel.s=<i;1=i(rof;)\\\\\\\\\\\\\\\" nigeb laitini;RQ eludom\\\\\\\\\\\\\\\"(tnirp;j,i tni;)\\\\\\\\\\\\\\\";RQ dne;)\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\DNE)\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\}s tnirp;)s,\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\
@dwo
dwo / dtruss_open.sh
Created February 16, 2016 12:28
See what files get opened by a process on OSX
sudo dtruss -t open -p PID
import csv
import re
tweets = set()
with open('tweets.csv', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in reader:
tweet = unicode(row[5], 'utf-8')
tweets.add(tweet)
@dwo
dwo / passphrase_generator.sh
Created April 29, 2019 14:24
Generate a simple passphrase
cat /usr/share/dict/words | grep -E "^[a-z]{4,8}$" | gshuf -n 4 | paste -s -d " " -