Skip to content

Instantly share code, notes, and snippets.

View szalansky's full-sized avatar
🎯
Focusing

szalansky

🎯
Focusing
View GitHub Profile
@szalansky
szalansky / latency.txt
Created May 31, 2012 14:26 — forked from jboner/latency.txt
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
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
@szalansky
szalansky / hash.rb
Created October 5, 2012 13:36 — forked from teamon/hash.rb
# Instead of:
# hash[:a].try(:[], :b).try(:[], :c).try(:[], :d)
# you can write
# hash[:a, :b, :c, :d]
class Hash
# h = {:a => {:b => {:c => 1}}}
# p h[:a] # => {:b => {:c => 1}}
# p h[:a, :b] # => {:c => 1}
# p h[:a, :b, :c] # => 1
class PeopleController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
...
end
*.aux
*.glo
*.idx
*.log
*.toc
*.ist
*.acn
*.acr
*.alg
*.bbl

Transparent Git Encryption

This document has been modified from its [original format][m1], which was written by Ning Shang ([email protected]). It has been updated and reformatted into a [Markdown][m2] document by [Woody Gilk][m3] and [republished][m4].

Description

When working with a remote git repository which is hosted on a third-party storage server, data confidentiality sometimes becomes

public void testCaseToString() {
// This test wins the award for twisted snake tail eating while
// writing self tests. And you thought those weird anonymous
// inner classes were bad...
assertEquals("testCaseToString(junit.tests.framework.TestCaseTest)", toString());
}
//
/**
@szalansky
szalansky / roman_numbers.rb
Created April 10, 2013 06:32
Roman numbers calculator (did as kata with Ruby and RSpec).
require "rspec"
CONVERSIONS_FACTOR = [
[100, "C"], [90, "XC"], [50, "L"], [40, "XL"], [10, "X"], [9, "IX"], [5, "V"], [4, "IV"], [1, "I"]
]
def conversion_factors_for number
CONVERSIONS_FACTOR.find { |arabic, _| arabic <= number }
end
def convert number

Setting Up Clojure on OS X

I spent a lot of time trying to find a pretty optimal (for me) setup for Clojure… at the same time I was trying to dive in and learn it. This is never optimal; you shouldn't be fighting the environment while trying to learn something.

I feel like I went through a lot of pain searching Google, StackOverflow, blogs, and other sites for random tidbits of information and instructions.

This is a comprehensive "what I learned and what I ended up doing" that will hopefully be of use to others and act as a journal for myself if I ever have to do it again. I want to be very step-by-step and explain what's happening (and why) at each step.

Step 1: Getting Clojure (1.3)

find DIR -print0 | xargs -0 -n 100 bundle exec rake TASK
@szalansky
szalansky / gist:8860421
Created February 7, 2014 10:36
Mass assigning with PORO
# mass assign yay
args.each do |key, value|
m = "#{key}="
self.send(m, value) if self.respond_to?( m )
end