Skip to content

Instantly share code, notes, and snippets.

View fallengiants's full-sized avatar
💭
in Domine sola fidi, et mala omnis acqui vincit.

fall fallengiants

💭
in Domine sola fidi, et mala omnis acqui vincit.
View GitHub Profile
@fallengiants
fallengiants / slowbro.sh
Created March 16, 2012 20:40
Mac OS Traffic Simulator
#!/bin/bash
if [$(ipfw show | grep 'pipe 1' | wc -l) -lt 1 ];
then
echo "Slowing down network, bro"
ipfw add pipe 1 all from any to any
ipfw pipe 1 config bw 300Kbit/s delay 400ms
else
echo "Speeding things up again, boss"
ipfw show | grep 'pipe 1' | awk '{print $1;}' | awk '{gsub(/^0+/, "")}; 1' | xargs ipfw delete
fi
@fallengiants
fallengiants / _symbol.rb
Created October 19, 2012 21:08
Ruby symbol to proc inverse
class Symbol
def ~@
_bound = binding
return ->(arg) {_bound.send(self, arg)}
end
end
%w{lib1 lib2 lib3}.map &~:require
@fallengiants
fallengiants / gosu.rb
Created November 14, 2012 23:46
Gosu - change background gradient based on mouse position
require 'gosu'
class FrameKeeper
attr_reader :this, :last, :delta
def initialize
@last = Gosu::milliseconds
end
def update
@this = Gosu::milliseconds
@fallengiants
fallengiants / gist:4219318
Created December 5, 2012 20:43
4chan api helpers
def get_raw_json_from(url)
Net::HTTP.get(URI.parse(url))
end
def get_json_from(url)
Hashie::Mash.new(JSON.parse(get_raw_json_from(url)))
end
def get_board(board, page)
get_json_from "http://api.4chan.org/#{board}/#{page}.json"
module PL
module Pragma
module Poker
# testing a theory, don't mind me
def self.new_deck
cards = "chsd".split(//).collect {|x| ['A','2','3','4','5','6','7','8','9','10','J','Q','K'].collect {|y| y + x}}.flatten
13.times { cards.each_index {|x| y = rand(cards.length - 1); cards[x], cards[y] = cards[y], cards[x]}}
cards
end
@fallengiants
fallengiants / gist:4549595
Last active December 11, 2015 05:08
Passage Parser, biblical order of passages
=begin
PassageParser, should match books of the bible
This looked like a good page for abbreviations:
# http://www.logos.com/support/windows/L3/book_abbreviations
Also, should be able to match the following formats:
Book ch
Book c1-c2
Book ch:vs
@fallengiants
fallengiants / dex.rb
Last active December 11, 2015 14:29
I need to modify this thing badly, it's old and not good.
=begin
dex.rb: Dex Recursive Data Structure
Functionality:
1. dx = Dex.new( hash of values OR a list of arguments to schematize- see #3)
2. dx.a.b.c = 5
[creates Dex children b and b.c and sets b.c to 5]
@fallengiants
fallengiants / gist:4992809
Created February 20, 2013 04:11
Git branch in prompt
git_prompt () {
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
echo "[$git_branch]"
}
PS1="\w \$(git_prompt)\$ "
@fallengiants
fallengiants / gist:5248795
Last active December 15, 2015 10:49
TVTropes Spoiler bookmarklet for ipad
+javascript:(function()%7Bd%3Ddocument%3Bs%3Dd.createElement(%22script%22)%3Bs.src%3D%22//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js%22%3Bs.type%3D%22text/javascript%22%3Bd.getElementsByTagName(%22head%22)%5B0%5D.appendChild(s)%3B%24().ready(function()%7B%24(%22.spoiler%22).click(function()%7B%24(this).removeClass(%22spoiler%22)%7D)%7D)%7D)()%3B
@fallengiants
fallengiants / gist:5273343
Created March 29, 2013 20:17
hash.search
class Hash
def search(m)
retval = []
self.each_pair do |k,v|
if v.kind_of?(Hash)
v.search(m).each {|u| retval << [k,*u]}
else
rets = case m
when Regexp
v.to_s =~ m