Skip to content

Instantly share code, notes, and snippets.

@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}"
@tamalw
tamalw / gist:3297135
Created August 8, 2012 18:07
PostgreSQL performance
EXPLAIN ANALYZE
SELECT COUNT(*) FROM j_msg
Row QUERY PLAN
1 Aggregate (cost=1360105.49..1360105.50 rows=1 width=0) (actual time=140042.984..140042.985 rows=1 loops=1)
2 -> Seq Scan on j_msg (cost=0.00..1318772.99 rows=16532999 width=0) (actual time=8.377..137051.294 rows=16532999 loops=1)
3 Total runtime: 140057.576 ms
====
@tamalw
tamalw / rank.php
Created July 29, 2012 17:14
Faster cURL action!
<?php
$searchURL = "http://services.runescape.com/m=hiscore/overall.ws";
$perPage = 22;
$namesToReturn = 1;
for ($index = 1; $index <= $namesToReturn; $index++)
{
// $search = rand(1, 500000);
@tamalw
tamalw / dice.rb
Created July 15, 2012 06:52
Drop table calculator
class Item
attr_accessor :name, :odds
def initialize(name, odds)
@name = name
@odds = odds
end
end
class Dice