Skip to content

Instantly share code, notes, and snippets.

View dpmccabe's full-sized avatar

Devin McCabe dpmccabe

  • Broad Institute of MIT and Harvard
  • Cambridge, MA
View GitHub Profile
@dpmccabe
dpmccabe / CIEDE2000.R
Last active January 23, 2017 16:56
CIEDE2000 color difference algorithm
kL <- 1
kC <- 1
kH <- 1
K1 <- 0.045
K2 <- 0.015
# x and y should be two different colors in L*a*b* space
CIEDE2000 <- function(x, y) {
L1 <- x$L
L2 <- y$L
@dpmccabe
dpmccabe / snippets.sh
Last active September 15, 2016 16:59
bash snippets
###########################################################################################################################
# commands
###########################################################################################################################
# ls only file size and name
stat -c "%s %n" *.txt | column -t
# watch output of qstat, highlight changes every 5s
watch -n 5 -d 'qstat'
ArgumentError at /api/v1/products/components_and_accessories
============================================================
> When assigning attributes, you must pass a hash as an argument.
app/controllers/api/v1/products_controller.rb, line 7
-----------------------------------------------------
``` ruby
2 before_filter :verify_auth_token
set x to ""
repeat 12 times
set x to x & some item of "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12345678901234567890"
end repeat
set the clipboard to x
tell application "System Events"
keystroke "v" using {command down}
end tell
@dpmccabe
dpmccabe / build_and_clean.py
Created October 1, 2014 04:09
clean temporary files after latexing build
import sublime, sublime_plugin
from os.path import dirname, realpath
import subprocess
class BuildAndClean(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().run_command("build")
sublime.set_timeout_async(self.clean, 3000)
def clean(self):
@dpmccabe
dpmccabe / field_with_error.rb
Last active August 29, 2015 14:05 — forked from t2/application.rb
add file as initializer
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = %(<span class="has-error">#{html_tag}</span>).html_safe
form_fields = %w(textarea input select)
element = Nokogiri::HTML::DocumentFragment.parse(html_tag).css(['label', form_fields].join(', ')).first
if element.node_name.eql?('label')
html = %(<span class='has-error'>#{element}</span>).html_safe
elsif form_fields.include?(element.node_name)
html = %(<span class='has-error'>#{element}<span class='help-block'>#{[instance.error_message].join(', ')}</span></span>).html_safe
end
$ rails g spree_account_recurring:install /Users/devin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.4/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `preference' for Spree::Recurring(Table doesn't exist):Class (NoMethodError)
from /Users/devin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/gems/spree-account-recurring-d9977b380f05/app/models/spree/recurring.rb:7:in `<class:Recurring>'
from /Users/devin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/gems/spree-account-recurring-d9977b380f05/app/models/spree/recurring.rb:2:in `<module:Spree>'
from /Users/devin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/gems/spree-account-recurring-d9977b380f05/app/models/spree/recurring.rb:1:in `<top (required)>'
from /Users/devin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.4/lib/
# == Schema Information
#
# Table name: billings
#
# id :integer not null, primary key
# user_id :integer
# bt_cc_token :string(255)
# bt_cust_id :string(255)
# bt_cc_expiration :string(255)
# bt_cc_last4 :string(255)
class Billing < OtherClass
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
attr_accessor :save_my_billing
attr_reader :result
cattr_reader :rate
@dpmccabe
dpmccabe / user.rb
Last active December 23, 2015 22:49
a really bad model
class User < ActiveRecord::Base
MAILCHIMP_API_KEY ='m23lm092m3'
MAILCHIMP_LIST_ID ='h439cds'
has_many :orders
before_save :assign_referral_code
after_create :schedule_welcome_email