Skip to content

Instantly share code, notes, and snippets.

View steelThread's full-sized avatar

Sean McDaniel steelThread

  • McDaniel Consulting LLC
  • Ashburn VA
View GitHub Profile
@steelThread
steelThread / gist:6050210
Last active December 20, 2015 01:39
SynchronousQueue - Producer-Consumer
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 }
@steelThread
steelThread / gist:6050207
Last active December 20, 2015 01:39
Executor - Producer-Consumer
import java.util.concurrent.Executors
module ProducerConsumer
def self.do_work
trap :TERM , -> { Executor.shutdown }
trap :INT , -> { Executor.shutdown }
Executor.execute Producer.new
end
@steelThread
steelThread / gist:4264260
Created December 12, 2012 02:07
Little Lua script for tracking page views
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);
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
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}"
(0..100).each do |i|
s = ''
s << 'Fizz' if i % 5 == 0
s << 'Buzz' if i % 7 == 0
puts s.empty? ? i : s
end
@steelThread
steelThread / gist:1102873
Created July 24, 2011 17:47
Client codez
#
# 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 = ''
@steelThread
steelThread / setup.md
Created July 16, 2011 12:59
Setup an ubuntu instance on ec2

References

ec2 starters guide

Security Groups

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:

Starting an Amazon Machine Image (AMI)

@steelThread
steelThread / 1.setup.md
Created July 11, 2011 20:11
Quick study on using Redis as a scoring engine

Redis Groups

Small prototype to look at group and ranking across a lot of users.

Setup

  • 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
@steelThread
steelThread / 1-Purpose.md
Created July 2, 2011 20:52
Heroku Bench Raw Http runs

Purpose

Take a look at a couple of very simple application stacks deployed to Heroku's cedar PaaS to understand just the raw http processing capabilities of a support ruby frameworks and node.

The Contenders

  • Rails
  • Sinatra
  • Golaith
  • NodeJS

The Setup