Skip to content

Instantly share code, notes, and snippets.

// 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) {
// 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 October 1, 2015 06:55
Animated ASCII artwork on the JS console
<html>
<body>
<script>
var hangmanStages = [
`
@puyo
puyo / rspec-blame-filter
Last active September 28, 2015 02:10
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 00:02
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.
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 August 29, 2015 13:58
Run a Facebook based popularity competition for ALP MPs
gem 'activesupport' # {}.to_query
gem 'nokogiri'
gem 'typhoeus'
require 'active_support/core_ext/object'
require 'json'
require 'nokogiri'
require 'pp'
require 'typhoeus'
@puyo
puyo / encamel.rb
Last active August 29, 2015 13:57
#!/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 January 31, 2014 04:45
More useful output from Capybara
# 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."
$ 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 January 4, 2016 04:59
Getting lots of PG:: errors with Rails 3.2.16 (last major stable release) and ruby-pg 0.17.1 (up to date).
require 'rubygems' rescue nil
gem 'activerecord', '3.2.16'
gem 'pg', '0.17.1'
require 'active_record'
require 'logger'
puts ActiveRecord::VERSION::STRING