Skip to content

Instantly share code, notes, and snippets.

@dwo
dwo / passphrase_generator.sh
Created Apr 29, 2019
Generate a simple passphrase
View passphrase_generator.sh
cat /usr/share/dict/words | grep -E "^[a-z]{4,8}$" | gshuf -n 4 | paste -s -d " " -
View convert_tweets_csv.py
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 / dtruss_open.sh
Created Feb 16, 2016
See what files get opened by a process on OSX
View dtruss_open.sh
sudo dtruss -t open -p PID
@dwo
dwo / 0_deterministic_sample.rb
Last active Aug 29, 2015
Choosing random array members deterministically based on contents of array and a name string
View 0_deterministic_sample.rb
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 / Makefile
Created May 9, 2015
Resizing images from one folder to another with ImageMagick and GNU Make
View Makefile
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 / 01_QR.scala
Last active Dec 19, 2015
Quine Relay on Mac OS X 10.7.5
View 01_QR.scala
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,\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\
View compile_mosh.sh
#!/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 / gemocalypse.sh
Created Dec 13, 2012
I used this to delete all my gems once
View gemocalypse.sh
#!/bin/bash
GEMS=`gem list --no-versions`
for x in $GEMS ; do gem uninstall -x --ignore-dependencies $x; done
@dwo
dwo / du-sorted.sh
Last active Oct 7, 2015
what's taking up all the space?
View du-sorted.sh
du -sm * | sort -nr | head -25
@dwo
dwo / superpull.sh
Created Jul 18, 2012
my bash script for pulling all projects and updating ctags
View superpull.sh
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