This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WeightedSelection | |
# input is an Enumerable of (item,frequency) pairs | |
# | |
# (takes O(n) time) | |
def initialize(input) | |
# set up the alias method for selection | |
# http://prxq.wordpress.com/2006/04/17/the-alias-method/ | |
@n = input.size | |
@m = input.inject(0) { |sum,(item,freq)| sum + freq } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
def self.compare_by(*methods) | |
include Comparable | |
define_method('<=>') do |other| | |
methods.inject(0) do |_,method| | |
comp = self.send(method) <=> other.send(method) | |
break comp if comp != 0 | |
comp | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BASE_SRC=Traverse.hs | |
BASE_TGT=$(basename $(BASE_SRC)) | |
BASE_OBJ=$(addsuffix .o,$(BASE_TGT)) | |
BASE_INT=$(addsuffix .hi,$(BASE_TGT)) | |
EXT_SRCS=$(wildcard Traverse/*.hs) | |
EXT_TGTS=$(basename $(EXT_SRCS)) | |
EXT_OBJS=$(addsuffix .o,$(EXT_TGTS)) | |
EXT_INTS=$(addsuffix .hi,$(EXT_TGTS)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyString < String | |
def upcase | |
self | |
end | |
end | |
puts ({MyString.new("bar") => "code"}).keys.first.upcase # prints bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bind CTRL-A e to edit a space-delimited path in vim | |
bind e source .screen/vim-path.screen | |
# bind CTRL-A K to view a manpage for a term starting at the cursor | |
bind K source .screen/man-word.screen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VERS=maptool*.jar | |
MAXMEMSZ="768m" # The 'm' suffix means megabytes | |
MINMEMSZ="32m" | |
STACKSZ="2m" | |
APPDOCKNAME="-Xdock:name=MapTool" | |
APPDOCKICON="-Xdock:icon=RPTools_Map_Logo.png" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# block currying for ruby | |
# examples at http://stackoverflow.com/questions/1095049/how-to-implement-currypartial-function-in-ruby/1097647#1097647 | |
def curry(&block) | |
arity = (block.arity >= 0) ? block.arity : -(block.arity + 1) | |
# return an immediate value if the block has one | |
return block[] if arity == 0 | |
# otherwise, curry it argument by argument | |
args = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.zshrc | |
# if using GNU screen, let the zsh tell screen what the title and hardstatus | |
# of the tab window should be. | |
if [[ $TERM == "screen" ]]; then | |
_GET_PATH='echo $PWD | sed "s/^\/Users\//~/;s/^~$USER/~/"' | |
# use the current user as the prefix of the current tab title (since that's | |
# fairly important, and I change it fairly often) | |
TAB_TITLE_PREFIX='"`'$_GET_PATH' | sed "s:..*/::"`$PROMPT_CHAR"' | |
# when at the shell prompt, show a truncated version of the current path (with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:document.location='http://www.google.com/search?q=cache:'+document.location; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name NewScientistViewer | |
// @namespace http://rampion.myopenid.com | |
// @description (U) Hide "You have now viewed your 3 free articles" popover from New Scientist. | |
// @include http://www.newscientist.com/article/* | |
// ==/UserScript== | |
// inject script, so hide overlay can use the has library, and runs after the popover happens. | |
const script = document.createElement('script'); | |
script.type = "text/javascript"; |