Skip to content

Instantly share code, notes, and snippets.


Matthew Bennett-Lovesey undecided

View GitHub Profile
undecided /
Last active Jan 21, 2016 — forked from CurtisHumphrey/
Fisher-Yates shuffle (in-place) in coffeescript
Randomize array element order in-place.
Using Fisher-Yates shuffle algorithm.
Array.prototype.shuffle = ->
for i in [(@length - 1) .. 0]
j = Math.floor(Math.random() * (i + 1))
[@[i], @[j]] = [@[j], @[i]]
View Instructions.txt
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 / dojo_assert.js
Last active Aug 29, 2015
Wrote a simple Javascript / Node.js testing framework on the train so that I could dojo.
View dojo_assert.js
// 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) {
assertEqual: function(expected, actual) {
View rubber_duck.rb
#!/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 / nil-array.rb
Created Dec 21, 2013
Answer to the question: how to initialise a multi-dimensional array, filled with nils, in ruby?
View nil-array.rb
# My answer at the time was to do something like this
#=> [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]
# The next question was whether I knew some initializer to do that for us.
# Apparently, there is: { }
#=> [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]
# But that wasn't the brainwave my brain came up with just now.
View crazy_ruby_procs.rb
def a(p)
raise "The world is safe"
def b
x = { return { return false } }
raise 'Maybe here, we might save the world. Let us do that.'
undecided / compile_mruby.rb
Created Mar 6, 2013
Quick and dirty script for compiling a ruby file with mruby. Run it with ruby ./compile_mruby.rb my_mruby_file.rb
View compile_mruby.rb
#!/usr/bin/env ruby
require 'fileutils'
def shell(cmd)
puts "Running #{cmd}"
infile = ARGV[0]
undecided / kitten.rb
Created Jan 31, 2013
I asked Joey to fix my code. She refused, but she did write this for me #soProud
View kitten.rb
class Kitten
def initialize
def set_colour
if rand(0..1) == 1
@colour = 'White'
View gist:4554774
#!/usr/bin/env ruby
require 'net/http'
[:get, ''],
[:post, '']
].map { |action, url| [action, URI.parse(url)] }
POST_DATA = -> do
{ :name => "foo", :what => 'ho', :interesting => rand(999999) }
undecided / simple_benchmark.rb
Last active Dec 11, 2015
Simple benchmarker
View simple_benchmark.rb
def simple_benchmarker
benchmarks = []
activity = ->(name) { benchmarks << [name,] }
yield activity
display_benchmarks benchmarks
rescue Exception => e
display_benchmarks benchmarks