Skip to content

Instantly share code, notes, and snippets.

View chrismcg's full-sized avatar

Chris McGrath chrismcg

View GitHub Profile
@mislav
mislav / procs-vs-lambda.md
Last active March 26, 2021 18:34
Jim Weirich on the differences between procs and lambdas in Ruby

Jim Weirich:

This is how I explain it… Ruby has Procs and Lambdas. Procs are created with Proc.new { }, lambdas are created with lambda {} and ->() {}.

In Ruby 1.8, proc {} creates lambda, and Ruby 1.9 it creates procs (don't ask).

Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.

This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.

@coreyhaines
coreyhaines / .rspec
Last active April 11, 2024 00:19
Active Record Spec Helper - Loading just active record
--colour
-I app
@boucher
boucher / gist:1750368
Created February 6, 2012 07:07 — forked from saikat/gist:1084146
Stripe sample checkout form
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Sample Form</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js"></script>
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<script type="text/javascript">
@timgremore
timgremore / index.html.haml
Created January 3, 2012 21:13
Ember.js, document collection and polling...written in CoffeeScript
- title "#{@game.name}"
%h1= yield(:title)
#documents
= form_tag(assessment_game_documents_path(@game)) do
%ul
%script{ type: "text/x-handlebars" }
{{#collection Game.DocumentsCollectionView contentBinding="Game.documentsController"}}
%li {{content.name}}
{{/collection}}
require 'psych'
class MyEmitter < Psych::Visitors::Emitter
end
o = "hello world"
visitor = Psych::Visitors::YAMLTree.new {}
visitor << o
my_emitter = MyEmitter.new $stdout
@assaf
assaf / gist:1207141
Created September 9, 2011 19:41
rescueFrom for jQuery AJAX requests
rescue_from = {}
# Associate status code with an HTTP status code. First argument is the status
# code, second argument is a function that accepts the XHR object. For example:
# $.rescueFrom 404, (xhr)-> alert("Oh no, page not found!")
$.rescueFrom = (status, fn)->
rescue_from[status] = fn
# Default handling for unsuccessulf HTTP status code. Finds and calls most
# appropriate handler based on the HTTP status code (see `$.rescueFrom`).
@chriseppstein
chriseppstein / readme.md
Created August 31, 2011 21:57 — forked from mislav/Gemfile
How to integrate Compass with Rails 3.1 asset pipeline

This gist is no longer valid. Please see Compass-Rails for instructions on how to install.

@jamis
jamis / demo.rb
Created August 3, 2011 21:56
Repairing a unicode string that contains invalid characters
# encoding: utf-8
s = "Blah \xe9 blah 헌글"
puts "BEFORE"
puts "encoding: #{s.encoding}"
puts "valid : #{s.valid_encoding?}"
puts "text : #{s}"
s = s.
@jeroenvandijk
jeroenvandijk / ack.rb
Created June 18, 2011 19:41
ack your gems
#!/usr/bin/env ruby
# Usage:
#
# ./ack.rb your-query
require 'rubygems'
require 'bundler'
if query = ARGV[0]
gem_dirs = Bundler.load.specs.map(&:full_gem_path).join(' ')
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'midi-winmm'
# tested with midi-winmm, but I assume will work with alsa-rawmidi
class Numeric
def to_hex_str
"%02x" % self
end
end