Skip to content

Instantly share code, notes, and snippets.

Avatar

Nels Nelson nelsnelson

View GitHub Profile
@nelsnelson
nelsnelson / gist:933776
Created Apr 21, 2011
JRuby demonstration exhibiting Matrix failure
View gist:933776
$ ruby ./matrix_test.rb
Attempting to create a matrix
a = [
[1, 2, 3]
[:a, :b, :c]
["x", "y", "z"]
["#", "%"]
]
Matrix.columns(a)
Matrix[[1, a, x, #], [2, b, y, %], [3, c, z, ]]
@nelsnelson
nelsnelson / matrix_test.rb
Created Apr 21, 2011
Ruby script for demonstrating Matrix failure with JRuby 1.6
View matrix_test.rb
#! /usr/bin/env ruby
require 'matrix'
a = [ [ 1, 2, 3 ], [ :a, :b, :c ], [ 'x', 'y', 'z' ], [ '#', '%' ] ]
puts "Attempting to create a matrix"
puts "a = ["
a.each { |x| puts " #{x.inspect}" }
puts "]"
View matrix.rb
def Matrix.columns(columns)
rows = (0 .. columns[0].size - 1).collect {
|i|
(0 .. columns.size - 1).collect {
|j|
columns[j][i]
}
}
Matrix.rows(rows, false)
@nelsnelson
nelsnelson / gist:946971
Created Apr 28, 2011
To store a 1:1 (one pixel = 1/72 inch) image of the entire surface of the Earth
View gist:946971
Assuming image resolution:
72ppi = 5184 pixels per square inch
Surface area of the Earth:
510,072,000 km2 = (7.90613181 × 10 to the 17th) square inches
Assuming (for a lossless PNG) an average storage size of:
~7.76 bits per pixel
7.90613181 × 10 to the 17th square inches
@nelsnelson
nelsnelson / pip_fail.txt
Created Jun 30, 2011
An example of pip for python failing to install readline
View pip_fail.txt
nels.nelson@peregrine:~$ sudo pip install readlline
Downloading/unpacking readlline
Could not find any downloads that satisfy the requirement readlline
No distributions at all found for readlline
Storing complete log in /Users/nels.nelson/.pip/pip.log
nels.nelson@peregrine:~$ sudo easy_install readline
Searching for readline
Reading http://pypi.python.org/simple/readline/
Reading http://www.python.org/
Reading http://github.com/ludwigschwardt/python-readline
@nelsnelson
nelsnelson / wrapper_test.rb
Created Aug 22, 2011
This is a demo of an error I am seeing when attempting to access self inside the initialize method of a class
View wrapper_test.rb
#! /usr/bin/env jruby
require 'java'
java_import java.util.Date
class Klass
def initialize
puts "Hi. I'd like to see what I look like during initialization. :)"
puts "self # => #{self} (#{self.class})"
@nelsnelson
nelsnelson / method_test.rb
Created Aug 23, 2011
I don't get it. Can anybody explain to me what is happening here?
View method_test.rb
#! /usr/bin/env ruby
module Helper
def help1
@help1 ||= [ :success1 ]
end
def help1=(a)
@help1 = a
end
def help2
@nelsnelson
nelsnelson / non_persistent_test.rb
Created Mar 1, 2012
Testing non-persistent fields on persisted identity-mapped entity instances in JRuby and Sequel through jdbc-postgres
View non_persistent_test.rb
#! /usr/bin/env jruby
require 'rubygems'
require 'sequel'
gem 'jdbc-postgres'
@connection = Sequel.connect('jdbc:postgresql://localhost:5432/test?user=test&password=test')
Sequel::Model.db = @connection
Sequel::Model.plugin :identity_map
@nelsnelson
nelsnelson / non_persistent_test.rb
Created Mar 2, 2012 — forked from jeremyevans/non_persistent_test.rb
Testing non-persistent fields on persisted identity-mapped entity instances in JRuby and Sequel through jdbc-postgres
View non_persistent_test.rb
#! /usr/bin/env jruby
require 'rubygems'
require 'sequel'
gem 'jdbc-postgres'
DB = Sequel.connect('jdbc:postgresql://localhost:5432/test?user=test&password=test')
DB.create_table? :test do
@nelsnelson
nelsnelson / latency.markdown
Created Oct 25, 2012 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know
View latency.markdown

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             
Syscall on Intel 5150 ...................... 105 ns
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Context switch on Intel 5150 ............. 4,300 ns  =   4 µs

Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs