Skip to content

Instantly share code, notes, and snippets.

View ewoodh2o's full-sized avatar

Elliott Wood ewoodh2o

  • CallRail
  • Atlanta, GA
View GitHub Profile
@ewoodh2o
ewoodh2o / README.md
Created October 11, 2012 16:45
Analytics Design Question

Loading Metrics from a Database

Given the following database schema:

| page_metrics                                         |
+------------------------------------------------------+
| id | page_id | date       | fans | comments | clicks |
+----+---------+------------+------+----------+--------+
| 11 |     123 | 2012-08-01 | 1750 |       23 |    103 |
@ewoodh2o
ewoodh2o / a_description.md
Created October 3, 2012 19:50
Bash-Style Curly Brace Expansion

Bash-Style Curly Brace Expansion

Expands the curly-brace notation as supported by Bash.

expand "ab{c,d}e"
  => [ "abce", "abde" ]

expand "ab{c,d}e{1,2}"
 => [ "abce1", "abce2", "abde1", "abde2" ]
@ewoodh2o
ewoodh2o / a_readme.md
Created March 30, 2012 14:50
ZMQ Pub/Sub Exploration

Design Goals

  1. Scribe has a single listener, with multiple clients sending it data (multiple Tabs unicorns, etc)
  2. If Scribe goes down temporarily, messages should queue on the client and be delivered when it comes back.
  3. If Scribe is down for a long time, the client should throw away messages rather than exhausting its RAM.
  4. If Scribe is down and the client terminates, it shouldn't wait around forever trying to deliver messages.

In the code below, pub.rb goes in the Scribe client gem and gets installed in Tabs, etc, with a similar thing in Deejay. The sub.rb piece is part of Scribe.

@ewoodh2o
ewoodh2o / pull.rb
Created March 29, 2012 22:10
ZMQ Push/Pull Exploration
require 'rubygems'
require 'zmq'
context = ZMQ::Context.new
# Start listening
pull = context.socket(ZMQ::PULL)
pull.bind("tcp://127.0.0.1:5555")
# Get updates, exit on ^C
@ewoodh2o
ewoodh2o / Gemfile
Created March 20, 2012 01:45
Sample Like Gate Coupon in Rails
source 'http://rubygems.org'
gem 'rails', '3.0.10'
# ... include whatever you need, but the following is pertinent
gem 'fb_graph'
# Solves Stanford's SAAS anagram question
# http://spark-university.s3.amazonaws.com/berkeley-saas/homework/hw1.pdf
# Question 3
def combine_anagrams(words)
# Set up a hash to hold the groups:
# Keys will be the sorted anagram string
# Values will be the array of anagrams for that string
# Hash works well here because it's a fast lookup on
@ewoodh2o
ewoodh2o / init.el
Created December 15, 2011 15:07
Elliott's emacs config, mostly stolen from jledbetter
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; emacs configuration
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(nconc load-path (list "~/.emacs.d/el-get/el-get"))
(require 'package)
(setq exec-path (cons "/usr/local/git/bin/" exec-path))
(unless (require 'el-get nil t)
(with-current-buffer
@ewoodh2o
ewoodh2o / gist:1076086
Created July 11, 2011 15:26
Sample Chronicle Mock
module ChronicleClient
class FirstMock < ChronicleClient::Mock
def self.response_for(query)
return nil if query.client != '0'
if query.params[:tags].include?("page_active_users")
return ChronicleClient::Response.mock(
:highcharts_array => [[1307592000000, 10000000], [1307678400000, 10014000], [1307764800000, 10027000], [1307851200000, 10035000], [1307937600000, 10059000], [1308024000000, 10078000], [1308110400000, 10087000]]
)
end
def upload_sizing
result = {}
if uploads_enabled?
dims = lambda {|size| send("upload#{size}_width?") && send("upload#{size}_width?") ?
{ width: send("upload#{size}_width"), height: send("upload#{size}_width") } : nil
}
{:enable_images? => :resize, :enable_videos? => :encode}.each do |method, result_key|
['', '_thumb'].each do |size|
@ewoodh2o
ewoodh2o / size_upload.rb
Created May 6, 2011 20:19 — forked from akasper/size_upload.rb
A method for sizing an upload. Response to https://gist.github.com/959582
SIZING_METHODS = {:enable_images? => :resize, :enable_videos? => :encode}
def size_upload
result = {:export => {use: []}}
return result unless self.uploads_enabled?
['', '_thumb'].each do |insert|
w = "upload#{insert}_width".to_sym
w? = "#{w}?".to_sym