Skip to content

Instantly share code, notes, and snippets.

View danielevans's full-sized avatar

Daniel Evans danielevans

  • Anfract
  • Portland, OR
View GitHub Profile
@danielevans
danielevans / gist:6004317
Last active December 19, 2015 19:09
Demonstrate CoffeeScript's super method in Backbone
class TestModel extends Backbone.Model
toJSON: ->
_.extend super,
success: true
json = (new TestModel(test: "success")).toJSON()
throw "no super data" unless json.test == "success"
@danielevans
danielevans / gist:5869148
Created June 26, 2013 16:50
Counting Sundays
require 'date'
sundays = (1901..2000).reduce(0) do |memo, year|
memo + (1..12).count do |month|
Date.new(year, month, 1).sunday?
end
end
puts sundays
require "capybara"
require "capybara/dsl"
require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, :js_errors => false, :phantomjs_options => ['--load-images=no', '--ignore-ssl-errors=yes'])
end
Capybara.run_server = false
Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
Capybara.current_driver = :poltergeist
@danielevans
danielevans / gist:5832684
Last active December 18, 2015 19:28
Quote from Stargate (Bregman about Krisofsky)
BREGMAN: You know ... I once did a piece on this war photographer, his name's Martin Kristofsky.
For six months he was with a unit in Vietnam and the day before he was schedule to leave.
The day before ... he's out with the unit and it was just a routine patrol or so they thought
but suddenly, the Lieutenant pulled him down and Kristophsky hadn't intended to take a picture
at that moment but his hands were on the camera and he hit the ground so hard that it just went
off. The picture captured the Lieutenant getting shot in the head and Kristophsky said to me,
"Well that bullet would of hit me, should of hit me." And he never showed that picture to anyone.
Not for 25 years, but 25 years later he got up one morning and he looked at that picture and he
saw something that wasn't horrific and he decided to tell the story because he realized that he
hadn't accidentally taken a picture of a man dying. It was of a man saving his life. The picture
@danielevans
danielevans / gist:5828524
Last active December 18, 2015 18:49
A Crafty Turtle script designed for use with Equivalent Exchange to compress large amounts of material.
-- CRAFTY TURTLE + EQUIVALENT EXCHANGE COMPRESSION SCRIPT
-- 0.4.1
-- DANIEL EVANS
-- LATEST VERSION AT https://gist.github.com/danielevans/5828524
-----------------------------------
-- CONFIGURATION
-----------------------------------
local InSlots = {1,2,5,6}
local InDirection = "down"; -- "up" || "down" || "forward"
@danielevans
danielevans / gist:5727622
Created June 7, 2013 07:40
I humbly suggest that every American subscriber to Verizon dial the following numbers in sequence. Send the NSA all your love.
332-7672
dea rnsa
463-8259
gof ucky
687-7353
our self
@danielevans
danielevans / test.rb
Last active December 16, 2015 20:19
Speed comparisons for complicated app/action ruby 2.0.0 vs 1.9.3-p392 in thin, webrick and unicorn
100x requests to the same action performed in sequence via curl
# 2.0.0-p0 - Unicorn
total time 23.029224000000003
average times 0.23029224000000004
min 0.160939
max 0.368869
# 1.9.3-p392 - Unicorn
;; (setq ediff-make-buffers-readonly-at-startup t)
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq ediff-split-window-function 'split-window-horizontally)
;; Some custom configuration to ediff
(defvar my-ediff-bwin-config nil "Window configuration before ediff.")
(defcustom my-ediff-bwin-reg ?b
"*Register to be set up to hold `my-ediff-bwin-config'
@danielevans
danielevans / gist:5059792
Created February 28, 2013 20:21
Monty Hall Problem Simulator
trials = 100_000
results = trials.times.reduce({ :change_successes => 0, :keep_successes => 0 }) do |memo, i|
doors = [nil]*3
doors[rand(3)] = "car"
choice = rand(3)
if doors[choice] == "car"
memo[:keep_successes] += 1
else
memo[:change_successes] += 1
end
lines = $stdin.read.lines.map &:strip
lines = $stdin.read.lines.map do |line|
line.strip
end
while true
c,n = lines.shift.split.map &:to_i
break if c == 0 && n == 0
v = lines.shift.split.map(&:to_i)