Skip to content

Instantly share code, notes, and snippets.

View roryokane's full-sized avatar

Rory O’Kane roryokane

View GitHub Profile
@roryokane
roryokane / readme.md
Last active August 29, 2015 14:16 — forked from anonymous/readme.txt
Pegs in PuzzleScript – version hosted for puzzlescript.net
@roryokane
roryokane / jsgif.js
Created April 4, 2011 14:43
http://slbkbs.org/jsgif/ bookmarklet automatically beautified by http://jsbeautifier.org/
javascript: (function () {
var n = null,
C = false;
function h(m) {
d(m, "jsgif_overlaid");
m.removeEventListener("click", i, C)
}
function i(m) {
var o = this;
@roryokane
roryokane / example.rb
Created June 7, 2011 13:17 — forked from cararemixed/example.rb
Better routes (just a fork, haven’t used personally) (doesn’t seem to work with Rails 3)
uri 'contacts', name: 'contacts' do
get 'contacts#index'
end
uri 'contacts/:id/addresses', name: 'contact_addresses' do
put 'contact_addresses#replace'
post 'contact_addresses#create'
delete 'contact_addresses#delete'
end
@roryokane
roryokane / scramble.rb
Created May 9, 2012 23:23 — forked from jescalan/scramble.rb
Sensical sentence scrambler
# ---------------------------
# Sensical Sentence Scrambler
# ---------------------------
# This short program takes any word longer than three characters and randomly shuffles all the characters
# except for the first and the last. Strangely enough, sentences are still quite readable like this.
# **Usage**
# Save the file on your computer as 'scramble.rb'.
# From the command line, run `ruby scramble.rb "Here's my sentence."`, and it should output
@roryokane
roryokane / Runner.scala
Created May 31, 2012 06:30
exploratory FizzBuzz in Scala
import scala.collection.mutable.ArrayBuffer
object Runner {
def main(args: Array[String]) {
// printFizzBuzz(20)
val max = 20
val factorsAndWords = Map(3 -> "Fizz", 5 -> "Buzz")
printGenericFizzBuzz(max, factorsAndWords)
}
@roryokane
roryokane / higher_dice_rolls.rb
Created June 9, 2012 02:24
likelihood of dice rolls when you roll four six-sided dice, take the top three
#encoding: utf-8
# http://news.ycombinator.com/item?id=4086325
# … try to generate a table of how likely it was to get various dice rolls when you rolled 4 6-sided dice and took the top 3.
require 'pp'
def dice_roll(sides)
rand(sides) + 1
@roryokane
roryokane / main-tester-caller.rb
Created June 18, 2012 16:25
`self.inspect == 'main'` is no substitute for `__FILE__ == $0`
require './main-tester'
puts "done in caller"
@roryokane
roryokane / command.sh
Created July 2, 2012 20:18
Ubuntu command to install Ruby standard libraries
sudo apt-get install -y openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion g++ openjdk-6-jre-headless
@roryokane
roryokane / bundle-exec.rb
Created July 5, 2012 15:36
Ruby shebang line tests
#!/usr/bin/env bundle exec ruby
puts "hello"
@roryokane
roryokane / hash_default_setting.rb
Created July 6, 2012 00:05
Ruby Hash monkey-patch methods relating to the hash’s default
# encoding: utf-8
class Hash
def with_new_default(*hash_new_args, &hash_new_block)
empty_defaulting_hash = Hash.new(*hash_new_args, &hash_new_block)
# using #merge; #replace would also replace the default value
return empty_defaulting_hash.merge(self)
end