Skip to content

Instantly share code, notes, and snippets.

@davidjbeveridge
davidjbeveridge / deep_equal.coffee
Created October 12, 2012 22:14
Deep equality comparison in CoffeeScript
test = (message, fn) -> throw "\"#{message}\" Failed" unless do fn
equal = (obj1, obj2) ->
[type_1, type_2] = [typeof obj1, typeof obj2]
return false unless type_1 is type_2
if type_1 isnt "object"
return obj1 is obj2
else
if obj1 instanceof Array
if obj2 instanceof Array
@davidjbeveridge
davidjbeveridge / underscore_camelize.coffee
Created October 1, 2012 18:59
Underscore and Camelize in CoffeeScript
each = (arr, func, index=0) ->
if index < arr.length then [ func(arr[index], index), each(arr, func, index + 1)... ] else []
camelize = (input) ->
pieces = input.split(/[\W_-]/)
each(pieces, capitalize).join("")
capitalize = (input) ->
input.charAt(0).toUpperCase() + input.slice(1)
each = (arr, func, index=0) ->
if index < arr.length then [ func(arr[index], index), each(arr, func, index + 1)... ] else []
# MacPorts Installer addition on 2011-03-31_at_12:54:10: adding an appropriate PATH variable for use with MacPorts.
#export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
@davidjbeveridge
davidjbeveridge / test.coffee
Created April 23, 2012 16:23
My Coffee Script test. I am trying to figure out what is wrong with my scoping to make it not increment.
jQuery ->
count = 0
$("a").click (e) ->
e.preventDefault()
alert("Hello World #{++count}")
@davidjbeveridge
davidjbeveridge / attribute_observers.rb
Created March 28, 2012 03:01 — forked from mrgenixus/Gemfile
Attribute Observers
module ProofTest
class Model
def self.attr_reader property
define_method property do
puts "reading #{attributes[property]} from #{property}"
attributes[property]
end
end
def self.attr_writer property
@davidjbeveridge
davidjbeveridge / attribute_observers.rb
Created March 28, 2012 01:40
Attribute Observers
module ObservableAttributes
module Observers
def observers
# A little hack to prevent the need for an @observers instance var
class << self
@observers ||= Hash.new
end
end
@davidjbeveridge
davidjbeveridge / README.md
Created March 12, 2012 16:33
meta-modeling examples

What is this?

Examples for a blog post I'm writing on creating arbitrary datatypes.

@davidjbeveridge
davidjbeveridge / test_controller.rb
Created March 8, 2012 02:45
Manually test a Rails controller (example)
env = {"REQUEST_METHOD" => "GET",
"PATH_INFO" => "/demo/index"
"rack.input" => StringIO.new
}
ActionController.new.call(env).last.body
@davidjbeveridge
davidjbeveridge / imagemagick-6.6.9-9.rb
Created March 3, 2012 21:18
Homebrew formula for imagemagick-6.6.9-9 (required for rmagick 2.12.2)
# some credit to https://github.com/maddox/magick-installer
require 'formula'
def ghostscript_srsly?
ARGV.include? '--with-ghostscript'
end
def ghostscript_fonts?
File.directory? "#{HOMEBREW_PREFIX}/share/ghostscript/fonts"
end