Skip to content

Instantly share code, notes, and snippets.

View padde's full-sized avatar

Patrick Oscity padde

View GitHub Profile
@padde
padde / completion.rb
Created January 26, 2013 17:59
Hacky completion class in Ruby. Useful for automatically abbreviating commands etc.
require 'fuzzy_match'
require 'amatch'
require 'text'
class Completion
attr_accessor :keywords
def initialize( keywords=[] )
self.keywords = keywords.map(&:downcase)
ambiguous = true
@padde
padde / alfred-extension.sh
Last active December 11, 2015 05:48
Template for writing Alfred Extensions in Ruby
TMPFILE=".$(uuidgen).tmp.rb"
cat > $TMPFILE <<RUBYSCRIPT
# TODO: replace this with real code
puts "Running Ruby #{RUBY_VERSION}"
puts "Arguments are #{ARGV.inspect}"
RUBYSCRIPT
/usr/bin/env ruby $TMPFILE "{query}"
rm $TMPFILE
@padde
padde / NSData+CRC32.h
Created July 27, 2012 11:34
NSData CRC32 Category
@interface NSData (CRC32)
-(NSUInteger) crc32;
@end
@padde
padde / hack.sh
Created July 14, 2012 16:52 — forked from eins78/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/3112090/hack.sh | sh
#
@padde
padde / data.xml
Created July 10, 2012 08:59
SO question #11409692
<?xml version="1.0" encoding="utf-8"?>
<item name="a">
<item name="d">
<item name="g"></item>
</item>
<item name="e"></item>
<item name="f"></item>
</item>
<item name="b"></item>
<item name="c"></item>
@padde
padde / stdin-reopen.rb
Created July 9, 2012 18:49
SO Question 11399584
tty = STDIN.reopen('/dev/tty')
tty.each_line do |line|
break if line == "\n"
puts line
end
tty.close
@padde
padde / export-plot-as-csv.m
Created June 19, 2012 11:56
Mathematica: Export Plot Values as CSV
plot = Plot[Cos[x],{x,0,2\[Pi]}];
mydata = Flatten[Cases[plot, Line[x__] -> x, Infinity], 1];
Export["/Users/padde/Desktop/plot-data.dat", mydata, "CSV"];
@padde
padde / gist:2628262
Created May 7, 2012 15:05
Ruby Fixnum each_bit
class Fixnum
def each_bit
8.times do |p|
yield (self & 1 << p) >> p
end
end
end
@padde
padde / gist:2623647
Created May 6, 2012 18:23
Convert video for PowerPoint with ffmpeg
ffmpeg -i INFILE -r 25 -f mpeg -vcodec mpeg1video -ar 48000 -b 1500k -acodec mp2 -ar 44100 -ac 1 -y OUTFILE.mpg
@padde
padde / zshrc
Created May 5, 2012 09:06
oh-my-zsh workaround for loading themes from $ZSH_CUSTOM
# your other stuff…
# set ZSH_THEME above this line!
# TODO: remove this when bug is fixed in oh-my-zsh
# Workaround for loading theme from $ZSH_CUSTOM
# Github issue: https://github.com/robbyrussell/oh-my-zsh/pull/1107
MY_ZSH_THEME=$ZSH_THEME; ZSH_THEME=''
# OH MY ZSH!