Skip to content

Instantly share code, notes, and snippets.

View bunnymatic's full-sized avatar
💭
writing computer programs

Mr Rogers bunnymatic

💭
writing computer programs
View GitHub Profile
@bunnymatic
bunnymatic / bash function rebase_prep for git
Created January 5, 2011 18:16
This bash function, when run from your current branch will jump to master, pull and jump back to your current branch, leaving you all ready to rebase master and then merge branch into master. Add it to your .profile and roll on.
rebase_prep() {
git checkout master && git pull && git checkout -
}
@bunnymatic
bunnymatic / git alias for rebase preparation
Created January 5, 2011 20:39
Adding the rebaseprep line to your .gitconfig will give you the ability to prep for a rebase. The method jumps from the current branch into master, pulls the latest, and jumps back to your working branch. This leaves you all ready to rebase with master
[alias]
rebaseprep = !sh -c 'git checkout master && git pull && git checkout -'
@bunnymatic
bunnymatic / my_thin_app.conf
Created June 21, 2011 03:34
Apache mods to point to a thin server
<VirtualHost *:80>
ServerName sinatra.yourserver.com
ServerAlias sinatra.yourserver.com
DocumentRoot /home/your_app_user/webapp/current
RewriteEngine On
<Proxy balancer://thinservers>
BalancerMember http://127.0.0.1:5000
BalancerMember http://127.0.0.1:5001
@bunnymatic
bunnymatic / jquery.myplugin.js
Created June 26, 2011 22:30
jquery plugin boilerplate
// jquery plugin boilerplate
// this plugin has methods and manages separate settings for each instance
$.myPluginDefaults = {
imageContainer: '.ir_img_container',
imageUrls: []
};
$.fn.myPlugin = function( method ) {
var inArgs = arguments;
@bunnymatic
bunnymatic / ssh_completion
Created August 5, 2011 22:13
SSH Completion for bash based on .ssh/config file
__from_ssh_config() {
SSHCONFIG=$HOME/.ssh/config
COMPREPLY=()
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W '$(cat ~/.ssh/config | grep Host | cut -d" " -f2-)' -- $cur))
}
complete -F __from_ssh_config -o default ssh
@bunnymatic
bunnymatic / in jasmine.js
Created January 30, 2012 23:15
add specdoc like logging to jasmine node
jasmine.Spec.prototype.execute = function(onComplete) {
var spec = this;
var descs = [];
var suite = this.suite;
while (suite) {
descs.push(suite.description);
suite = suite.parentSuite;
}
descs = descs.reverse();
descs.push(this.description)
@bunnymatic
bunnymatic / console.rb
Created May 25, 2012 21:20
Sinatra console
#!/usr/bin/env ruby
require 'data_mapper'
require 'sinatra'
require 'sinatra/config_file'
disable :run
root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
Dir[File.join(root,"{lib,models}/**/*.rb")].each do |file|
require file
end
@bunnymatic
bunnymatic / jasmine-prototype-event-helpers
Created July 15, 2012 00:48
Jasmine Helpers to fire events with Prototype
var jasmine = jasmine || {}
jasmine.getEvents = function(sel, event_name) {
var events = [];
try {
var evs = $$(sel)[0].getStorage().get('prototype_event_registry');
events = evs.get(event_name);
}
catch(e) {}
return events;
};
@bunnymatic
bunnymatic / query_string_parser.js.coffee
Created July 27, 2012 16:53
simple url/query string parser coffeescript
class QueryStringParser
constructor: (url) ->
@query_params = {}
if !document || !document.createElement
throw 'This needs to be run in an HTML context with a document.'
parser = document.createElement('a')
parser.href = url
@url = url
if (parser.origin)
@origin = parser.origin
@bunnymatic
bunnymatic / upto.rb
Created August 20, 2012 03:32
Trim an array to the next largest value given a value. Potentially useful for pagination needs.
def upto(arr,v); arr[0..arr.select{|x| x < v}.count] end
# usage
arr = 5.times.map{|x| 12 * (2**x)}
maxval = 26
upto(arr,maxval)
# => [12,24,48]