Skip to content

Instantly share code, notes, and snippets.

View rampion's full-sized avatar

Noah Luck Easterly rampion

  • Mercury Technologies
View GitHub Profile
" adapted from https://github.com/aaronjensen/vimfiles/blob/2a88ef0b92f5a628e898189e612eb0feb34b1419/vimrc#L449-483
" save as ~/.vim/plugin/bracketed_paste.vim to use
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Tmux wrapping borrowed from vitality.vim: https://github.com/sjl/vitality.vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function WrapForTmux(s)
if !exists('$TMUX')
return a:s
endif
@rampion
rampion / gist:72614
Created March 2, 2009 04:55
example of bugs with natural join in oracle
-- on Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
CREATE TABLE left(lid INTEGER, pid INTEGER);
INSERT INTO left VALUES (1,1);
INSERT INTO left VALUES (2,2);
INSERT INTO left VALUES (3,3);
INSERT INTO left VALUES (4,4);
INSERT INTO left VALUES (5,5);
CREATE TABLE right(rid INTEGER, pid INTEGER);
INSERT INTO right VALUES (1,1);
#!/usr/bin/env ruby
# solver for http://numb3rs.wolfram.com/516/puzzle.html
# a node in the graph
Node = Struct.new(:label, :color, :edges)
class Node
# hash equalit for nodes is only dependent on label (which is unique)
def hash
label.hash
end
@rampion
rampion / makeup.sh
Created April 9, 2009 12:46
zsh function to recursively ascend the path tree until we hit root or find a makefile, then make
# zsh function to recursively ascend the path tree until we hit root or find a makefile, then make
function makeup()
{
if ([[ $PWD == "/" ]] || [[ -f Makefile ]] || [[ -f makefile ]] ) ; then
make $*
else
(pushd .. >/dev/null ; makeup $*)
fi
}
@rampion
rampion / yet-another-rot13.vim
Created April 19, 2009 21:24
how may ways can you say ROT13
:%s/.*/\=tr(submatch(0),'abcdefghijklmnopqrstuvwxyz','nopqrstuvwxyzabcdefghijklm')
@rampion
rampion / refactor.vim
Created April 19, 2009 22:05
vim script for refactoring using a dictionary
" Refactor the given lines using a dictionary
" replacing all occurences of each key in the dictionary with its value
function! Refactor(dict) range
execute a:firstline . ',' . a:lastline . 's/\C\<\%(' . join(keys(a:dict),'\|'). '\)\>/\='.string(a:dict).'[submatch(0)]/ge'
endfunction
command! -range -nargs=1 Refactor :<line1>,<line2>call Refactor(<args>)
" Example of use
" :%Refactor {'duck':'frog', 'frog':'rabbit', 'rabbit':'duck', 'I':'Noah'}
@rampion
rampion / nextunused.vim
Created May 2, 2009 03:21
vim plugin for using numbered temp files
" ~/.vim/plugin/nextunused.vim
" find the next unused filename that matches the given pattern
" counting up from 0. The pattern is used by printf(),
" so use 'temp%d.txt' for 'temp0.txt' to 'temp99999.txt' and
" 'temp%04d.txt' for 'temp0000.txt' to 'temp9999.txt'.
function! GetNextUnused( pattern )
let i = 0
while filereadable(printf(a:pattern,i))
let i += 1
@rampion
rampion / clearonclick.user.js
Created May 11, 2009 15:51
remove default onclick behaviour from links
// ==UserScript==
// @name clearonclick
// @namespace http://rampion.myopenid.com
// @description clear onclick behaviour from html links
// @include http://andrewsullivan.theatlantic.com/the_daily_dish/*
// ==/UserScript==
try {
GM_log("called");
const links = document.getElementsByTagName('a');
@rampion
rampion / test data.txt
Created May 14, 2009 20:56
Some random names and addresses I generated for test data
+--------------------------------+--------------------------------------------------------------------+
| name | address |
+--------------------------------+--------------------------------------------------------------------+
| Evagation Governessy | 803 Asbestous St, Uneradicated Stannous MP 37441 |
| Civilizee Fangle | 997 Cerebrotonic Hwy, Ulex Lynceus ZQ 07893 |
| Terebenic Parandrus | 687 Veneralia Way, Frivoler Myospasm NC 14839 |
| Loaminess Pezizaceous | 859 Dustcloth Way, Drivepipe Miolithic XV 26760 |
| Dominican Ozostomia | 73 Dichasial Way, Moniker Utilizable RS 84766 |
| Autobiology Impishly | 602 Dynamize Way, Lernaeidae Macrochemical CB 42656 |
| Exopodite Unendamaged | 139 Osteolysis Hwy, Synergist Leally TO 05002
@rampion
rampion / weighted_selection.rb
Created May 17, 2009 00:22
An implementation of an O(n + p) work algorithm for selecting p items with replacment from a weighted set of n items
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 }