Skip to content

Instantly share code, notes, and snippets.

View csavage-mdsol's full-sized avatar

Connor Savage csavage-mdsol

  • Medidata Solutions
  • New York, New York
View GitHub Profile
@csavage-mdsol
csavage-mdsol / prettylog
Created March 18, 2015 05:26
Pretty git log
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
@csavage-mdsol
csavage-mdsol / zsh git function
Created March 18, 2015 05:21
zsh git function
# No arguments: `git status`
# With arguments: acts like `git`
g() {
if [[ $# > 0 ]]; then
git $@
else
git status
fi
}
@csavage-mdsol
csavage-mdsol / farscape.md
Last active August 29, 2015 14:10
farscape stuff

So for the active record-y interface, we're going to see naive method chains like this:

# transitions invocations
home.client_divisions.client_division(uuid).studies.create(params)
# Or trying to access an attribute
home.client_divisions.client_division(uuid).studies.study(uuid).name

Attributes should be terminal calls, and probably shouldn't exist outside of an if else or case statement, but if we have method missing return the representor self if it doesn't match a method, these chains will basically progress as far as they know how to. So if studies gets cool and is renamed studiez, the result of the above call would be the client division representor. Then we could write a meaningfull === for case statements, which would let code for dealing with this look like this:

@csavage-mdsol
csavage-mdsol / gist:8e1bd423deac5be8f75f
Created November 12, 2014 18:45
rbtrace JSON Heap Dump
# Provide the PID of a running rails process, and dump the heap to heap.json
# WARNING these can get pretty huge (~100MB)
# requries ruby 2.1 for shiny new ObjectSpace features
rbtrace -p <PID> -e 'Thread.new{require "objspace"; ObjectSpace.trace_object_allocations_start; GC.start(); ObjectSpace.dump_all(output: File.open("heap.json", "w"))}.join'