Skip to content

Instantly share code, notes, and snippets.

View undecided's full-sized avatar

Matthew Bennett-Lovesey undecided

View GitHub Profile
#!/usr/bin/env ruby
average_pause_mins = 1
phrases = [
"Can we try taking smaller steps to reach this solution?",
"I think that might need a refactor",
"This is looking good",
"Are the tests passing yet?",
"I wish we could automate this, what do you think?",
@undecided
undecided / dojo_assert.js
Last active August 29, 2015 13:56
Wrote a simple Javascript / Node.js testing framework on the train so that I could dojo.
// TODO: Would love VERBOSE to be given via environment var
// TODO: Should probably have assertIdentity (===) too. Trivial to add.
// TODO: I would like passing tests to appear as full-stops on one line in quiet mode.
var VERBOSE = true;
function describe(desc, desc_fn) {
desc_fn(function(it_desc, it_fn) {
it_fn({
assertEqual: function(expected, actual) {
@undecided
undecided / Instructions.txt
Last active September 22, 2015 12:34
Pry snippets
Instructions:
In sublime, in the menu find Preferences => Settings - User.
This will open a file, and while this is not the file we want, it is in the correct directory.
NOTE: Please be careful to follow these in the correct order, rather than risk overwriting your user settings!
Do File -> Save As, and resave the file as Pry.sublime-snippet
Delete the content and paste the first file below in that file, and save.
Do File -> Save As, and resave the file as Pry-Remote.sublime-snippet
@undecided
undecided / ruby_and_mirah.rb
Created March 9, 2011 22:32
Shows a simple class implemented in Ruby and Mirah
# Ruby
class Rubyish
def a_method(some_string, some_hash)
@message = some_string
@transform = some_hash
puts @message
end
def another_method
@transform.each_pair do |key, val|
@undecided
undecided / not_matches_vs_does_not_match.rb
Created August 28, 2012 13:59
Another ruby funny that caught me out... Want to guess what these should output?
"fish" =~ /ish/
"fish" !=~ /ish/
!("fish" =~ /ish/) # equivalent to "fish" !~ /ish/ - thanks @MrJaba and @kerryb!
@undecided
undecided / magical_mr_mistoffelees.rb
Created August 31, 2012 10:36
How do I do this?
# Premise: a chainable DSL where evaluating a section in an if statement calls valid?
# Example: Each item changes the current synonym, it tests it against
class Moggy
SYNONYMS = [:cat, :moggy, :pussycat, :feline]
def set(syn)
@synonym = syn
self
end
@undecided
undecided / simple_benchmark.rb
Last active December 11, 2015 05:48
Simple benchmarker
def simple_benchmarker
benchmarks = []
activity = ->(name) { benchmarks << [name, Time.now] }
activity[:started]
yield activity
activity[:finished]
display_benchmarks benchmarks
rescue Exception => e
activity[:error_occurred]
display_benchmarks benchmarks
@undecided
undecided / gist:4554774
Last active December 11, 2015 05:49
Load tester
#!/usr/bin/env ruby
require 'net/http'
URL_LIST = [
[:get, 'http://quickwebdesign.net'],
[:post, 'http://retrodude.com']
].map { |action, url| [action, URI.parse(url)] }
POST_DATA = -> do
{ :name => "foo", :what => 'ho', :interesting => rand(999999) }
@undecided
undecided / kitten.rb
Created January 31, 2013 16:55
I asked Joey to fix my code. She refused, but she did write this for me #soProud
class Kitten
def initialize
set_colour
set_name
end
def set_colour
if rand(0..1) == 1
@colour = 'White'
@undecided
undecided / compile_mruby.rb
Created March 6, 2013 09:36
Quick and dirty script for compiling a ruby file with mruby. Run it with ruby ./compile_mruby.rb my_mruby_file.rb
#!/usr/bin/env ruby
require 'fileutils'
def shell(cmd)
puts "Running #{cmd}"
`#{cmd}`
end
infile = ARGV[0]