Skip to content

Instantly share code, notes, and snippets.

View mochaSetup.js
// Imagine if we had a test framework that did this :...(
const models = require('../models')
const logger = require('../logger')
const Promise = require('bluebird')
const co = require('co')
const isGenFn = require('is-generator').fn
const colors = require('colors/safe')
function transactionStrategy(mocha) {
View event-handler-trap1.js
// These may *look* like nested conditions but they run at wildly different
// times during your program's execution.
//
// In the example below, t represents the time elapsed since starting the
// code.
//
// The user clicks the button at t = 100.
var condition1 = true;
var condition2 = true;
@puyo
puyo / hangman.html
Created Oct 1, 2015
Animated ASCII artwork on the JS console
View hangman.html
<html>
<body>
<script>
var hangmanStages = [
`
@puyo
puyo / rspec-blame-filter
Last active Sep 28, 2015
rspec-blame-filter
View rspec-blame-filter
#!/usr/bin/ruby
# Annotates RSpec output with contact details of the person who wrote the tests that are failing.
#
# Setup:
#
# gem install colorize
#
# Usage:
#
@puyo
puyo / check.rb
Last active May 12, 2016
RSpec feels unnecessarily verbose to me. This is an attempt at expressing the DSL I'd like to have, with a very hacky implementation that maps back onto RSpec.
View check.rb
gem 'rspec'
require 'rspec/core'
require 'rspec/expectations'
require 'rspec/autorun'
require 'pp'
RSpec.configure do |config|
config.color = true
config.formatter = 'doc'
config.expect_with :rspec do |c|
@puyo
puyo / alp_facebook_popularity.rb
Last active Aug 29, 2015
Run a Facebook based popularity competition for ALP MPs
View alp_facebook_popularity.rb
gem 'activesupport' # {}.to_query
gem 'nokogiri'
gem 'typhoeus'
require 'active_support/core_ext/object'
require 'json'
require 'nokogiri'
require 'pp'
require 'typhoeus'
View encamel.rb
#!/usr/bin/env ruby
gem 'activesupport'
require 'active_support/core_ext/string/inflections'
snake = ARGV.first
camel = snake.camelize(:lower)
system %{git grep -l #{snake} | xargs ruby -p -i -e '$_.gsub! /#{snake}/, "#{camel}"'}
@puyo
puyo / capybara_find_with_info.rb
Created Jan 31, 2014
More useful output from Capybara
View capybara_find_with_info.rb
# More useful output from Capybara.
#
# Before:
#
# Unable to find link or button "Year 5"
#
# After:
#
# Unable to find link or button "Year 5" in "Sorry, something went wrong We've
# been notified of the error and are looking into it."
View cannot-find-coffee-script.sh
$ coffee blah.coffee
Error: Cannot find module 'coffee-script'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/greg/blah.coffee:1:10)
at Object.<anonymous> (/Users/greg/blah.coffee:1:1)
at Module._compile (module.js:456:26)
@puyo
puyo / pg_errors.rb
Last active Jan 4, 2016
Getting lots of PG:: errors with Rails 3.2.16 (last major stable release) and ruby-pg 0.17.1 (up to date).
View pg_errors.rb
require 'rubygems' rescue nil
gem 'activerecord', '3.2.16'
gem 'pg', '0.17.1'
require 'active_record'
require 'logger'
puts ActiveRecord::VERSION::STRING