Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • San Francisco, CA, USA
View GitHub Profile
@mattyoho
mattyoho / README.md
Last active August 29, 2015 14:13 — forked from majek/README.md

Passing TCP socket descriptors around

In linux, normally, it is impossible to "bind()" to the same TCP port twice. If you try to bind to the same port from second proces unix processes you'll see:

socket.error: [Errno 98] Address already in use

@mattyoho
mattyoho / latency.txt
Last active August 29, 2015 14:14 — forked from jboner/latency.txt
Latency Comparison Numbers
--------------------------
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
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
  1. General Background and Overview
@mattyoho
mattyoho / MVC_what_now.rb
Created July 8, 2009 03:33
Access Rails routes from outside of controllers/views. Most rules have exceptions, folks.
class CanHazRoutes
include ActionController::UrlWriter
host = case ENV['RAILS_ENV']
when "production"
"prod.com"
when "staging"
"stage.com"
when "development"
"app.local"
trials = []
10000.times{ trials << rand(6) }
trials.uniq.map do |u|
trials.select { |t| t.equal? u }.size
end.collect do |c|
c.to_f / trials.size
end
#!/bin/sh
REPO=$1
git clone $REPO
cd `basename $REPO .git`
for BRANCH in `git branch -r`; do
git co --track \
-b remote/$BRANCH \
$BRANCH
done
#!/usr/bin/env ruby
puts "looking for the gems to upgrade..."
gem_info = Struct.new(:name, :version)
to_reinstall = []
Dir.glob('/Library/Ruby/Gems/**/*.bundle').map do |path|
path =~ /.*1.8\/gems\/(.*)-(.*?)\/.*/
name, version = $1, $2
bundle_info = `file path`
to_reinstall << gem_info.new(name, version) unless bundle_info =~ /bundle x86_64/
end
irb(main):054:0> class Cat
irb(main):055:1> def eigen
irb(main):056:2> class << self
irb(main):057:3> self
irb(main):058:3> end
irb(main):059:2> end
irb(main):060:1> end
=> nil
irb(main):061:0> c1 = Cat.new
=> #<Cat:0x1017562d0>
[user@host ~]$ cat /proc/7128/cmdline
/usr/java/java/bin/java-Djava.awt.headless=true-Xms128M-Xmx256M-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager-Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties-Djava.endorsed.dirs=/usr/local/tomcat/common/endorsed-classpath:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/commons-logging-api.jar-Dcatalina.base=/usr/local/tomcat-Dcatalina.home=/usr/local/tomcat-Djava.io.tmpdir=/usr/local/tomcat/temporg.apache.catalina.startup.Bootstrapstart
@mattyoho
mattyoho / gist:195512
Created September 28, 2009 15:34
Capistrano patch for issue introduced by Github migration.
We couldn’t find that file to show.