Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am mikeric on github.
  • I am mikeric (https://keybase.io/mikeric) on keybase.
  • I have a public key ASC6g1aHViIyH1gyHMFJPYr6arHP4c7bG2MkT1oY0quQeQo

To claim this, I am signing this object:

@mikeric
mikeric / .vimrc
Created Sep 17, 2014
Vim configuration
View .vimrc
" VUNDLE
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle.vim
call vundle#begin()
Plugin 'gmarik/vundle.vim'
Plugin 'kien/ctrlp.vim'
Plugin 'scrooloose/nerdtree'
@mikeric
mikeric / gist:654d3512e9010689fc03
Last active Aug 29, 2015
Module interface styles
View gist:654d3512e9010689fc03

A

// require
sightglass = require('sightglass')

// global usage
sightglass.root = '.'
sightglass(obj, 'user.address:city', function() {})
View backbone-collection-promises.coffee
# synchronous ajax calls (one at a time, then
# start the next one, etc. then do something)
sessions.fetch success ->
rooms.fetch success ->
do_something
# async ajax calls (all at the same time, then
# do something when all are finished)
View resource-routing-splats.rb
# the following works as intended
resources :events do
member do
get :schedule
end
end
match '/events/:id/*params' => 'events#show'
@mikeric
mikeric / array_keyed_hash.rb
Last active Dec 26, 2015
Initialize a new Hash that can be accessed through individual objects in it's array keys.
View array_keyed_hash.rb
hash = Hash.new{|hash, key| hash[hash.keys.detect{|k| k.include?(key)}]}
hash[%w(foo bar baz)] = ['hello', 'world']
hash # => {["foo", "bar", "baz"] => ["hello", "world"]}
hash['foo'] # => ["hello", "world"]
hash['bar'] # => ["hello", "world"]
hash['baz'] # => ["hello", "world"]
@mikeric
mikeric / gist:5297484
Created Apr 3, 2013
rp (request pull)
View gist:5297484
function rp {
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
`git push origin $current_branch`
open `hub pull-request "$current_branch" -b coverall:$1`
}
View backbone_nested.md

Managing Nested Models and Collections in Backbone.js

One common pattern for nesting another model or collection inside a model is to assign it as a property on that object, for example, @messages on Mailbox as illustrated on the Backbone.js homepage.

class Mailbox extends Backbone.Model
  urlRoot: '/mailbox'

  initialize: ->
@mikeric
mikeric / rmb
Created Nov 8, 2012
Remove Merged Branches (rmb) — cleans up all topic branches that have been merged into master (local and origin)
View rmb
function rmb {
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo "Fetching merged branches..."
git remote prune origin
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v "/$current_branch$")
local_branches=$(git branch --merged | grep -v 'master$' | grep -v "$current_branch$")
if [ -z "$remote_branches" ] && [ -z "$local_branches" ]; then
@mikeric
mikeric / .profile
Created Oct 31, 2012
git-aware bash prompt
View .profile
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
export PS1="\[$(tput bold)\]\h:\W\$(parse_git_branch) $ \[$(tput sgr0)\]"