Skip to content

Instantly share code, notes, and snippets.

@tamalw
tamalw / lego.rb
Created January 11, 2014 03:36
LEGO!
class Monster
def initialize(options)
@name = options[:name]
@lifepoints = options[:lifepoints]
@drop_mechanic = options[:drop_mechanic]
@hit_log = []
@output_buffer = []
end
def get_hit(player, hit)
@tamalw
tamalw / install.md
Last active December 28, 2015 19:59
RuneScape through WINE

Tested with OS X 10.9 only, YMMV.

Install homebrew http://brew.sh if you don't have it by launching Terminal.app and entering

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

Follow all the prompts.

@tamalw
tamalw / gist:7144185
Last active December 26, 2015 11:29
Can I use "reverse" scopes on an instance to keep it DRY?
class Article < ActiveRecord::Base
scope :published, -> { where("draft = false AND publish_at <= ?", Time.now) }
end
foo = Article.find(123)
foo.published?
@tamalw
tamalw / gist:6514880
Last active December 22, 2015 18:39 — forked from blockjon/gist:6430015
-- Setup some tables.
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1;
CREATE TABLE `internal_messages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_user_id` int(11) DEFAULT NULL,
@tamalw
tamalw / round_robin.rb
Created June 3, 2013 15:38
Round Robin DNS resolution to bypass IP rate limiting PoC
require 'resolv'
hostname = 'hiscore.runescape.com'
names = [ "The Orange", "SkyTeck", "Font", "iGlacor", "Tohru x", "Weir", "Parenthesis", "OneLegendKid", "Lekerashi", "Aus Zealand", "Lordofd70", "No Orion", "BadSmurF", "Dunder_miffl", "Stephen VII", "Jonnys D", "God H8s Bots", "Wey burn", "nabulsi", "Blur", "Man killa", "Titsicle", "Bedevere", "lilybele", "l Jigg l", "zabeey", "xRatonhnhake", "st drew", "Kre8tive", "He Belongs", "Sannse", "almostcomp", "IrishEIK", "Haydunn", "kouth sorea", "dark_king_I4", "Unheard pray", "Co Justin", "Chalder", "mihal80", "inburst21", "Slaye", "Mish", "Doctor Doak", "ttaM", "nova science", "Rrman of w48", "saylor", "minergoo", "jason 72", "Advokat", "Lofna", "Dissori", "R2h Guard", "Izobelle", "Eleanor Lamb", "Mischievio", "Dead Masterr", "Man killa", "iBryce", "Boo Bee", "Mattmann28", "xowen", "fdsatakanuva", "Steeve", "J T R9", "mercifull", "Randomjagged", "Samyuel", "Cassus", "Dyzt", "Melbshuffle", "Neo687", "Metabolizer", "S9 Gnit2", "Joe Longo", "3u0", "Xw0", "Saul",
@tamalw
tamalw / symbols.rb
Created February 19, 2013 05:47
More about Symbols
# Symbols aren't anything special really, just use a colon in front of a word instead of quotes
:foo.class # => Symbol
"foo".class # => String
# They are easier to write and pass around than strings so we use them. That's all you really need to know about them.
# They also don't come with all the baggage methods strings do (which we wouldn't need for identifiers)
:foo.methods.count # => 50
"foo".methods.count # => 176
@tamalw
tamalw / blocks.rb
Created February 19, 2013 05:38
Deeper into blocks
# Blocks are a way of "injecting" code to run in the context of the original method.
# Side note: we can open an existing class and add methods.
# Let's make the String class awesome, don't worry about the blocks yet
class String
def hax0rify
replac0rs = {
'o' => '0',
'a' => '4'
}
str = "It's not too scary when you realize that everything is an object"
str.size # => 64
str.class # => String
str = "and you call methods on them"
str.reverse # => "meht no sdohtem llac uoy dna"
# EVERYTHING is an object
@tamalw
tamalw / pascals_triangle.rb
Created February 19, 2013 03:43
Falls apart when the numbers get long
rows = 8
t = []
rows.times do |i|
t[i] = []
(i+1).times do |j|
if j == 0 || j == i
t[i] << 1
else
t[i] << t[i-1][j-1] + t[i-1][j]
framework "ScriptingBridge"
unless `ps aux | grep Safari.ap[p]` == ""
safari ||= SBApplication.applicationWithBundleIdentifier("com.apple.Safari")
if ARGV.empty?
safari.windows.each do |window|
puts "Window #{window.index}:"
window.tabs.each do |tab|
puts "\t#{tab.name}"