Skip to content

Instantly share code, notes, and snippets.

View edjames's full-sized avatar

Ed James edjames

View GitHub Profile
@edjames
edjames / Threading example
Last active September 25, 2015 08:58
A quick example of multithreading
require 'benchmark'
class CottonThread
attr_reader :threads, :procs
def initialize
@threads, @procs = [], []
end
def sow(proc)
@edjames
edjames / gist:1125444
Created August 4, 2011 15:28
quick pivot example
require 'ostruct'
data = []
data << OpenStruct.new(:city => 'London', :qtr => 1, :sales => nil)
data << OpenStruct.new(:city => 'London', :qtr => 1, :sales => 50)
data << OpenStruct.new(:city => 'London', :qtr => 1, :sales => 50)
data << OpenStruct.new(:city => 'London', :qtr => 2, :sales => 200)
data << OpenStruct.new(:city => 'London', :qtr => 3, :sales => 300)
data << OpenStruct.new(:city => 'London', :qtr => 4, :sales => 400)
@edjames
edjames / db.rake
Created January 23, 2012 14:16
Rake tasks for MySQL data import/export
namespace :db do
namespace :data do
desc "Dump data into sql script file: filename=[target filename]"
task :dump => 'environment' do
environment = (ENV.include?("RAILS_ENV")) ? (ENV["RAILS_ENV"]) : 'development'
ENV["RAILS_ENV"] = RAILS_ENV = environment
database = get_database(environment)
user = database
password = ENV['PASSWORD']
@edjames
edjames / file_diff.rb
Created February 3, 2012 11:45
Import a gemset without bundler Ruby 1.8.7
#!/usr/bin/env ruby
unless ARGV.count >= 2
puts "Please provide two files to perform diff..."
exit
end
def load_file file
arr = File.readlines(file).map(&:chomp).compact
arr.shift if arr.first =~ /^#/
@edjames
edjames / nginx_rails_3_1
Created February 7, 2012 11:12 — forked from shapeshed/nginx_rails_3_1
Nginx Config for Rails 3.1 with Unicorn and Asset Pipeline
upstream app {
server unix:/srv/app/current/tmp/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.app.com;
rewrite ^/(.*) http://app.com/$1 permanent;
}
server {
@edjames
edjames / gist:3938621
Last active October 11, 2015 23:48
Gource command for repo Star Wars
gource -1280x720 -o - --title "VZ-APP" --hide date,filenames,mouse --start-date '2014-08-01 00:00:01' --disable-bloom --logo app/assets/images/homepage/play_symbol.png --auto-skip-seconds 1 --seconds-per-day 0.25 --start-position 0.7 --font-size 6 | ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gource.mp4
gource -768x540 -o - --title "VZ-APP" --start-date '2014-08-01 00:00:01' --disable-bloom --logo app/assets/images/homepage/play_symbol.png --auto-skip-seconds 1 --seconds-per-day 0.5 --font-size 6 | ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gource.mp4
hide options: bloom,date,dirnames,files,filenames,mouse,progress,tree,users,usernames
@edjames
edjames / memcached-dump.macdots_function
Last active August 29, 2015 14:01
List all keys in memcache
# .memcached-dump.macdots_function
# mac-dots custom function
# requires mac-dots version >= 0.7.5
# https://gist.github.com/edjames/9d5681d608b302dba855
# Usage:
# $> memcached-dump
memcached-dump() {
@edjames
edjames / gist:03d13a0f45987e0cf4a5
Created July 22, 2014 14:38
Multi-namespace cache handler
class MultiCache
include Singleton
attr_reader :rails_cache, :custom_cache
def initialize
@rails_cache = Rails.cache
@custom_cache = ActiveSupport::Cache::MemCacheStore.new(
'your-cache-ip-address', :namespace => 'rails4-namespace')
end
### Keybase proof
I hereby claim:
* I am edjames on github.
* I am grokling (https://keybase.io/grokling) on keybase.
* I have a public key whose fingerprint is 8186 635A FD92 0FFF 896F D1B8 A55F 2A0A 4CF6 1080
To claim this, I am signing this object:
#!/bin/bash
echo "-------------------------------"
echo "Starting user-data execution..."
echo "-------------------------------"
cd /root
#
# Setup swap for better performance