Skip to content

Instantly share code, notes, and snippets.

@enthal
enthal / people_controller.rb
Created October 24, 2011 21:00
simple rails rspec testing that devise before_filter :authenticate_user! covers controller actions
class PeopleController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
...
end
@enthal
enthal / Base File.sublime-settings.json
Created January 4, 2012 18:30
sublime text 2 prefs
{
"color_scheme": "Packages/Color Scheme - Default/Blackboard.tmTheme",
"font_size": 14.0,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"word_wrap": false,
"zzz": 0
}
@enthal
enthal / .bashrc
Created January 16, 2012 21:24
.bashrc
export PATH=/usr/local/bin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
# export JAVA_HOME=$(/usr/libexec/java_home)
# export LD_LIBRARY_PATH=/usr/local/lib/
alias ll='ls -al'
alias m='mate'
alias mw='mate -w'
alias .p='. ~/.bashrc'
alias ep='mw ~/.bashrc; .p'
@enthal
enthal / index.html
Created January 28, 2012 20:36
Example of d3 axis() for axes and grid lines
<!DOCTYPE html>
<html>
<head>
<title>D3 - Line Chart - axes and grid using axis()</title>
<!-- script type="text/javascript" src="https://raw.github.com/jquery/sizzle/master/sizzle.js"></script -->
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.min.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.time.min.js"></script>
<style type="text/css">
body {
@enthal
enthal / index.html
Created February 2, 2012 23:51
Example of continuous function graphing in d3 (using axis() for axes and grid lines)
<!DOCTYPE html>
<html>
<head>
<title>D3 - Line Chart - continuous function</title>
<!-- script type="text/javascript" src="https://raw.github.com/jquery/sizzle/master/sizzle.js"></script -->
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.min.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.time.min.js"></script>
<style type="text/css">
body {
@enthal
enthal / rr.patch
Created April 24, 2012 01:50
added a failing test for a case when RR.mock breaks objects that use method_missing like Redis::Namespace
commit 56d2a064e942243cd601b3b5ac1ec48004a02664
Author: Jared Grippe and Rex Chung and Tim James <techops+jared+rex+tjames@change.org>
Date: Mon Apr 23 18:35:27 2012 -0700
added a failing test for a case when RR.mock breaks objects that use method_missing like Redis::Namespace
diff --git a/spec/rr/double_injection/double_injection_spec.rb b/spec/rr/double_injection/double_injection_spec.rb
index be2109b..d9ade8c 100644
--- a/spec/rr/double_injection/double_injection_spec.rb
+++ b/spec/rr/double_injection/double_injection_spec.rb
def mr
# total_sponsor_amount = sum{|d| d.amount * dollars_per_locale_currency_unit(d.locale)}
reduce = {
usd_per_could_sponsor: ->(d){d.usd / d.could_count},
usd_per_did_sponsor: ->(d){d.usd / d.did_count},
}
map = {
@enthal
enthal / safe_float.rb
Created June 2, 2012 02:10
SafeFloat: a half baked ruby way to change how math works in some interesting ways... probably a bad idea but at least the specs pass
# Provides JSON-safe division, === with a fudge factor, allowance of integer division
class SafeFloat
FUDGE = 0.0000001
def initialize v
@v = v
end
def / other
# p "#{@v} / #{other.to_f} == #{@v / other.to_f}"
self.class.new(@v / other.to_f) if other != 0 # nil instead of NaN
end
@enthal
enthal / .initrc
Created June 12, 2012 19:07
fix ruby readline
bind "^R" em-inc-search-prev
bind ^I rl_complete
@enthal
enthal / .profile
Last active February 17, 2017 23:44
.profile of ♡
echo bash
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'; }
PS1="________________________________________________________\n\u@\h \w\[\e[0;33;49m\]\$(parse_git_branch)\[\e[0;0m\]\n\$ "
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
if [ -f `brew --prefix`/etc/bash_completion ]; then