Skip to content

Instantly share code, notes, and snippets.

$.fn.equalHeights = function(px) {
var tallestHeight = 0;
if (!px) {
$(this).each(function() {
if ($(this).height() > tallestHeight) {
tallestHeight = $(this).height();
}
});
@nelsnelson
nelsnelson / gist:946971
Created April 28, 2011 18:35
To store a 1:1 (one pixel = 1/72 inch) image of the entire surface of the Earth
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 / matrix.rb
Created April 21, 2011 14:36
Excerpt
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 / matrix_test.rb
Created April 21, 2011 05:41
Ruby script for demonstrating Matrix failure with JRuby 1.6
#! /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 "]"
@nelsnelson
nelsnelson / gist:933776
Created April 21, 2011 05:34
JRuby demonstration exhibiting Matrix failure
$ 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, ]]
$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick
DISTRIB_DESCRIPTION="Ubuntu 10.10"
$ uname -a
Linux slim 2.6.35.4-rscloud #8 SMP Mon Sep 20 15:54:33 UTC 2010 x86_64 GNU/Linux
@nelsnelson
nelsnelson / overridden_fixnum_less_than.rb
Created April 6, 2011 15:48
Example of JRuby Fixnum problem.
#! /usr/bin/env ruby
class Fixnum
def < (other)
puts "Determining membership of #{self.inspect} in #{other.inspect}..."
return false unless other
if other.is_a? Enumerable or other.is_a? Array
other >= self
else
@nelsnelson
nelsnelson / base.rb.diff
Created March 22, 2011 21:24
base.rb.diff
7a8,15
> def self.options=(options)
> @@options = options
> end
>
> def self.options
> @@options ||= {}
> end
>
261a270,275
#! /usr/bin/env ruby
# Now one can define models this way:
class Test < Sequel::Model(Sequel::Model.db, :implicit_dataset => false)
end
@nelsnelson
nelsnelson / model.rb.diff
Created March 22, 2011 21:18
model.rb.diff
37c37,38
< def self.Model(source)
---
> def self.Model(source, params={})
> Model.options = params