Skip to content

Instantly share code, notes, and snippets.

View mikeric's full-sized avatar

Michael Richards mikeric

View GitHub Profile
@mikeric
mikeric / temporary-patch-fix.rb
Created February 2, 2010 04:29
MongoMapper on Edge Rails (3.0.pre)
# MongoMapper::Document::InstanceMethods
def to_model
errors.instance_eval do
def [](attribute)
return [] if errors[attribute.to_sym].nil?
errors[attribute.to_sym]
end
end
self
@mikeric
mikeric / riak.rb
Created March 25, 2010 17:50
A simple Riak REST client
class Riak
include HTTParty
format :json
def self.config(host, port, prefix='riak')
base_uri "#{host}:#{port}/#{prefix}"
end
end
@mikeric
mikeric / .vimrc
Created July 28, 2012 23:26
VIM configuration
" GENERAL
:set ruler
:set number
:set noswapfile
syntax on
colorscheme mr
" INDENTATION
@mikeric
mikeric / stapes-adapter.js
Created July 31, 2012 20:51
Stapes.js adapter for Rivets.js
rivets.configure({
adapter: {
subscribe: function(obj, keypath, callback) {
obj.on("change:" + keypath, callback);
},
unsubscribe: function(obj, keypath, callback) {
obj.off("change:" + keypath, callback);
},
@mikeric
mikeric / application.css
Last active December 9, 2022 03:48
Rivets.js todo list demo
.done {
opacity: 0.5;
text-decoration: line-through;
}
@mikeric
mikeric / rivets-grammar.md
Created August 29, 2012 05:13
Rivets.js grammar in binding declarations

1. Binding to an object's attribute.

obj.attribute

On bind, performs the binding routine using adapter.read on the attribute if preloadData is set to true. Then calls adapter.subscribe on the attribute.

2. Binding to an object's property.

obj:property
@mikeric
mikeric / .profile
Created October 31, 2012 20:31
git-aware bash prompt
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)\]"
@mikeric
mikeric / rmb
Created November 8, 2012 23:16
Remove Merged Branches (rmb) — cleans up all topic branches that have been merged into master (local and origin)
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

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 / gist:5297484
Created April 3, 2013 00:32
rp (request pull)
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`
}