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 / safe_logger.js
Created November 12, 2010 01:11
Provide a tiny module that will allow for safe logging to console for browsers that allow it. For those that don't, don't log anything. Easily turned off with a debug switch which can be server generated (depending on environment dev/staging/prod) or no
var L = window.SafeLogger = window.SafeLogger || {};
//
// from server or on a specific page you want console data
// L.__debug__ = true
//
L.log = function() {
if (window.console && L.__debug__) {
// TODO: Chrome doesn't let us call apply on console.log.
// Interpolate variable arguments manually and construct
// a single-argument call to console.log for Chrome.
@bunnymatic
bunnymatic / history search for bash
Created December 8, 2010 17:49
find that old command that you ran a while back
alias lookfor="history | grep"
@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 / gist:1648765
Last active February 22, 2020 21:03
compute histogram in ruby
def tally inp; hash = Hash.new(0); inp.each {|k,v| hash[k] +=v}; hash; end
def histogram inp; hash = Hash.new(0); inp.each {|v| hash[v]+=1}; hash; end
def histogram2 inp; Hash[*inp.group_by{ |v| v }.flat_map{ |k, v| [k, v.size] }] end
def test_tally
tally([['a',1],['b',1],['a',1],['c',1],['a',3], ['c',1]]) == {'a'=>5, 'b'=>1, 'c'=>2}
end
def test_histogram
histogram(['a','b','a','c','a', 'c']) == {'a'=>3, 'b'=>1, 'c'=>2}
@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 / .htaccess
Created February 5, 2012 08:40
javascript regex tester
Options -Indexes