Skip to content

Instantly share code, notes, and snippets.

@bcremer
bcremer / gist:12167985b442d0d195de
Created August 5, 2014 12:01
NGINX as caching REST-API Proxy
upstream backend {
server localhost:8080;
#server backup1.example.com:8080 backup;
#server backup2.example.com:8080 backup;
}
# Set cache dir
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:10m;
# Set cache key to include identifying components
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@drewconway
drewconway / to.RomanNumeral.R
Created February 8, 2011 04:35
# A function that converts a given integer into its Roman Numeral equivalent
# A function that converts a given integer into its Roman Numeral equivalent
to.RomanNumeral<-function(x) {
if(0 < x & x < 5000) {
x<-as.integer(x)
digits<-c(1000,900,500,400,100,90,50,40,10,9,5,4,1)
numerals<-c("M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I")
digits.numerals<-as.data.frame(cbind(digits,numerals), stringsAsFactors=FALSE)
numeral<-""
for(i in 1:nrow(digits.numerals)) {
while(x >= as.numeric(digits.numerals[i,1])) {
CONTENT_TYPES = {:html => 'text/html', :css => 'text/css', :js => 'application/javascript'}
before do
request_uri = case request.env['REQUEST_URI']
when /\.css$/ : :css
when /\.js$/ : :js
else :html
end
content_type CONTENT_TYPES[request_uri], :charset => 'utf-8'
end