Skip to content

Instantly share code, notes, and snippets.

View ecleel's full-sized avatar

Abdulaziz Alshetwi ecleel

View GitHub Profile
@TalkingQuickly
TalkingQuickly / gist:6636214
Created September 20, 2013 11:33
Simple unicorn nginx vhost file
upstream unicorn {
server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
}
server {
listen 80 default deferred;
root /home/deploy/apps/<%= application %>/current/public;
location ^~ /assets/ {
gzip_static on;
@jboner
jboner / latency.txt
Last active May 13, 2025 17:54
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@lloeki
lloeki / foo_controller.rb
Created May 29, 2012 07:05
Streaming (CSV) data in Rails 3.2
class FooController
respond_to :csv
def index
@foos = Foo.scoped
if stale?(:last_modified => Foo.something)
respond_with @gta do |format|
format.csv { stream_csv @foo }
end
end
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@ruralocity
ruralocity / share_buttons.rb
Created April 17, 2012 11:20
incomplete, untested at all spaghetti helpers for social media sharing in rails
def facebook_button(url)
content_for :head do
content_tag :script,
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
@guyboltonking
guyboltonking / compressed_static_assets.rb
Created March 21, 2012 20:37
Slightly hacky rails middleware for serving up precompiled gzipped assets
require 'action_dispatch/middleware/static'
module Middleware
class FileHandler < ActionDispatch::FileHandler
def initialize(root, assets_path, cache_control)
@assets_path = assets_path.chomp('/') + '/'
super(root, cache_control)
end
def match?(path)
@melchoy
melchoy / mobile_site.rb
Created February 16, 2012 07:26
Mobile Subdomains in Rails
module MobileSite
def self.included(base)
base.class_eval do
# Uncomment for JQM Integration
#rescue_from ActionView::MissingTemplate, :with => :view_unavailable
before_filter :set_mobile_preferences
before_filter :redirect_to_mobile_if_applicable
before_filter :set_mobile_view_path
@arfon
arfon / em_tweetstreamer.rb
Created January 21, 2012 12:54
Tweet parsing with EventMachine
require 'aws-sdk'
require 'eventmachine'
require 'tweetstream'
AWS_ACCESS_KEY = 'your_aws_access_key'
AWS_SECRET_KEY = 'your_aws_secret_key'
dynamo_db = AWS::DynamoDB.new(:access_key_id => AWS_ACCESS_KEY, :secret_access_key => AWS_SECRET_KEY)
table = dynamo_db.tables['tweets']
@lukekarrys
lukekarrys / README.md
Last active February 4, 2018 01:05
Instagram Jekyll Plugin for to Embed Photos