Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter Hollows captainpete

View GitHub Profile
@captainpete
captainpete / 2048_sim.js
Created May 14, 2018
2048 game simulation snippet
View 2048_sim.js
// Add the initial tiles
this.grid.insertTile(new Tile({x:3,y:0}, 2**1));
this.grid.insertTile(new Tile({x:2,y:0}, 2**1));
this.grid.insertTile(new Tile({x:1,y:0}, 2**2));
this.grid.insertTile(new Tile({x:0,y:0}, 2**3));
this.grid.insertTile(new Tile({x:0,y:1}, 2**4));
this.grid.insertTile(new Tile({x:1,y:1}, 2**5));
this.grid.insertTile(new Tile({x:2,y:1}, 2**6));
this.grid.insertTile(new Tile({x:3,y:1}, 2**7));
this.grid.insertTile(new Tile({x:3,y:2}, 2**8));
View gist:731aa1d4729bf0a0e2c85789ae877307
### Keybase proof
I hereby claim:
* I am captainpete on github.
* I am captainpete (https://keybase.io/captainpete) on keybase.
* I have a public key whose fingerprint is 108B 0A12 F415 0AC4 EDD7 17AB 16D5 D511 A1ED DA5B
To claim this, I am signing this object:
@captainpete
captainpete / unlock.rb
Created Mar 8, 2017
Ruby script for brute-forcing Apple encrypted volumes
View unlock.rb
#!/usr/bin/env ruby
require 'pry'
require 'set'
# disk UUID
# find with `diskutil corestorage list`
UUID = "1D1D6CEB-4613-472C-AE71-BD50651D44D1"
SUFFIXES = [ '', '!!', '123' ]
JOINS = [ '', ',', ', ' ]
@captainpete
captainpete / infnoise.conf
Created Mar 5, 2015
Infinite Noise Ubuntu Upstart Script (/etc/init/infnoise.conf)
View infnoise.conf
# infnoise
#
# Feed entropy pool using the Infinite Noise TRNG
description "Infinite Noise"
start on filesystem or runlevel [2345]
stop on runlevel [!2345]
respawn
@captainpete
captainpete / infnoise
Last active Oct 16, 2017
Infinite Noise Gentoo Init Script (/etc/init.d/infnoise)
View infnoise
#!/sbin/openrc-run
description="infnoise - Feed entropy pool using the Infinite Noise TRNG"
pidfile="/var/run/infnoise.pid"
command="/usr/local/sbin/infnoise"
command_args="--dev-random"
start_stop_daemon_args="--make-pidfile --background"
depend() {
before urandom
View anaglyph.R
anaglyph.plot <- function(x,y,z,left="red",right="cyan",depth="med",style="pop-out",type="p",...) {
if (depth=="low") {
scale <- 0.1
} else if (depth=="med") {
scale <- 0.2
} else if (depth=="high") {
scale <- 0.5
}
@captainpete
captainpete / .zshrc
Created May 6, 2014
Whiteboard ImageMagick zsh function
View .zshrc
# Whiteboard photo cleanup script
# inspired by https://gist.github.com/lelandbatey/8677901
# converts an image to png, extracts strokes, traces etc.
whiteboard() {
convert "$1" "$1.converted.png"
echo "Converted"
convert "$1.converted.png" \
-morphology Convolve DoG:15,100,0 \
-negate -normalize -blur 0x1 -channel RBG \
@captainpete
captainpete / ruby-install-rbx-2.2.6-rl_username_completion_function-fix
Last active Aug 29, 2015
ruby-install rbx 2.2.6, Rubinius Mavericks "error: ... rl_username_completion_function" workaround
View ruby-install-rbx-2.2.6-rl_username_completion_function-fix
# If installing Rubinius 2.2.6 fails
# with an error containing 'rl_username_completion_function'
ruby-install rbx 2.2.6 # <= fails
# Remove and re-extract Rubinius
cd ~/src && rm -fr rubinius-2.2.6 && tar -xf rubinius-2.2.6.tar.bz2
# Make sure LLVM is installed
brew install llvm
# Make sure the other libs are present
@captainpete
captainpete / moment-calendar_title.js.coffee
Created Aug 13, 2012
Date-based calendar formatter for momentjs
View moment-calendar_title.js.coffee
# Adapted from the momentjs calendar function
# Inspired by this answer: http://stackoverflow.com/a/10306813/325676
moment.fn.calendarTitle = ->
calendar =
sameDay : '[Today]',
nextDay : '[Tomorrow]',
nextWeek : 'dddd, Do MMM',
lastDay : '[Yesterday]',
lastWeek : '[Last] dddd',
@captainpete
captainpete / yahoo-finance-csv-curl.rb
Last active Sep 29, 2015
Yahoo Finance currency conversion method in Ruby (for prototyping use, budget but works)
View yahoo-finance-csv-curl.rb
require 'csv'
# Cheers to Greg on StackOverflow
# http://stackoverflow.com/questions/181990/programmatically-access-currency-exchange-rates
class Yahoo
def self.fetch(code = 'AUDUSD')
csv = `curl -q "http://download.finance.yahoo.com/d/quotes.csv?s=#{code}=X&f=sl1d1t1ba&e=.csv"`
values = CSV.parse(csv)
values[0][1]
You can’t perform that action at this time.