Skip to content

Instantly share code, notes, and snippets.

@jsl
jsl / gist:2429938
Created April 20, 2012 16:07
Rspec test
require 'rspec'
module Dog
def self.bark
"Woof!"
end
end
describe "Rspec re-setting stubs on classes" do
it "should return 'Woof!'" do
fsync = false
full_page_writes = false
bgwriter_lru_maxpages = 0
autovacuum = off
(ns euler.p8)
(defn ones-digit-of
[number]
(mod number 10))
(defn shift-digit-from
[number]
(/ (- number (ones-digit-of number)) 10))
@jsl
jsl / gist:3153360
Created July 20, 2012 21:27
Advanced Ruby Talk at EAFIT by Justin Leitgeb
I'm giving a talk on Ruby at EAFIT in Medellin next week! Below are the details:
Fecha: Martes 24 de julio
Hora: 6:00 a 7:00 PM
Lugar:27-103
It's open to the public, but if you're not with the university tweet me and I'll forward your name to the University so that you can be put on the list for security.
My cell phone is 320-652-4001, call me if you have any problems getting in or questions about the event and I'll see what I can do to help. You can also tweet @justinleitgeb with any questions or comments.
@jsl
jsl / gist:3221297
Created July 31, 2012 22:36
Removing and re-installing all bottles after mountain lion upgrade
for bottle in `brew list` ; do brew remove $bottle && brew install $bottle ; done
class Node
attr_accessor :next, :name
end
a = Node.new
b = Node.new
c = Node.new
a.next = b
b.next = c
require 'rspec'
class Node
attr_accessor :next
attr_reader :name
def initialize(name)
@name = name
end
class Node
attr_accessor :next
end
a = Node.new
b = Node.new
c = Node.new
a.next = b
b.next = c
@jsl
jsl / gist:4073369
Created November 14, 2012 17:07
Ruby Refinements
require 'minitest/autorun'
# Demonstrates the way that refinements are applied in Ruby 2.0.0preview1.
module RegularStringCounts
refine String do
def num_caps
self.scan(/[A-Z]/).count
end
end
@jsl
jsl / gist:4491687
Created January 9, 2013 08:57
Fix security vulnerability CVE-2013-0156 in apps that don't need XML and YAML parameter parsing.
# These MIME types, which we don't use, are vulnerable per CVE-2013-0156
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::YAML)