Before we startup an AMI we need to setup the security group that we will apply to the instance. Essentially we want to allow inbound traffic on 22 (ssh) and the http ports (80, 443). I like to do this on the default security group. Here's an image of the inbound tab for my default security group:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.SynchronousQueue | |
module ProducerConsumer | |
def self.do_work | |
trap :TERM , -> { Queue.shutdown! } | |
trap :INT , -> { Queue.shutdown! } | |
threads = [ | |
Producer.new.tap{ |o| o.start }, | |
Consumer.new.tap{ |o| o.start } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.Executors | |
module ProducerConsumer | |
def self.do_work | |
trap :TERM , -> { Executor.shutdown } | |
trap :INT , -> { Executor.shutdown } | |
Executor.execute Producer.new | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local aggreate_exists = redis.call('exists', KEYS[1]); | |
if (aggreate_exists == 0) then | |
redis.call('hset', 'flushed', 0); | |
end | |
redis.call('hincrby', KEYS[1], 'visits', 1); | |
local uuid_exists = redis.call('hexists', KEYS[1], ARGV[1]); | |
if (uuid_exists == 0) then | |
redis.call('hset', KEYS[1], ARGV[1], nil); | |
redis.call('hincrby', KEYS[1], 'uniques', 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def swap!(a, b) | |
self[a], self[b] = self[b], self[a] | |
end | |
def bubble_sort | |
sorted = self.dup | |
return sorted unless sorted.count > 1 | |
count = sorted.count-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/https' | |
require 'open-uri' | |
module AppCache | |
extend self | |
def run(host = "http://***.***.***") | |
@host = host | |
puts "Loading manifest..." | |
puts "Total Size => #{total.to_human}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(0..100).each do |i| | |
s = '' | |
s << 'Fizz' if i % 5 == 0 | |
s << 'Buzz' if i % 7 == 0 | |
puts s.empty? ? i : s | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Reads xml in chunks, parses to js obj. | |
# | |
net = require 'net' | |
sys = require 'sys' | |
xml2js = require 'xml2js' | |
start = new Date().getMilliseconds() | |
parser = new xml2js.Parser() | |
buffer = '' |
Small prototype to look at group and ranking across a lot of users.
- 10^6 players (can easily bump)
- 20,000 groups
- users are randomly put into 0..5 groups using a good distribution random # generator
- all users are playing a single game
- assuming the setup is a point in time somewhere during the game
NewerOlder