Skip to content

Instantly share code, notes, and snippets.

@abevoelker
abevoelker / property_names_patch.rb
Created December 16, 2011 20:56
DataMapper equivalent to ActiveRecord attribute_names
module DataMapper::Model
def property_names
properties.map { |m| m.name.to_s }
end
end
@abevoelker
abevoelker / jruby_file_fix.rb
Created October 5, 2011 13:45
JRuby File#size monkeypatch
# Apparently JRuby doesn't have a File#size (instance) method,
# but does have the equivalent class method
if !File.method_defined? :size
class File
def size
File.size(path)
end
end
end
@abevoelker
abevoelker / prawn_test.rb
Created September 2, 2011 15:19
Prawn stepladder header issue (fixed)
require 'prawn'
Prawn.debug = true
Prawn::Document.generate("test.pdf", :page_layout => :landscape) do |pdf|
Header = Struct.new(:title, :width)
headers = [Header.new("Header\nOne", 50),
Header.new("Header\nTwo", 50),
Header.new("Header\nThree", 50)]
pdf.stroke_bounds
@abevoelker
abevoelker / gist:1187702
Created September 2, 2011 00:56
Ford Escape ad (CarSoup)
(For better formatting, please see the Craigslist version of this ad: http://madison.craigslist.org/cto/2531807957.html)
2008 Ford Escape HEV - $15,995 OBO
Color: Silver
Miles: 90,332
Drive: Front Wheel Drive
Transmission: Automatic
VIN: 1FMCU49H98KA18705
**Price Reduced!
***Free CarFax report available here
@abevoelker
abevoelker / gist:1187686
Created September 2, 2011 00:46
Ford Escape ad (AutoTrader) (2K char limit)
Free CarFax report: http://www.carfax.com/cfm/FSBO.cfm?report=66547FA0B89CD0D19E9DF4F776C0A4A5
Image gallery: http://katyavoelker.imgur.com/0BZ27/all
Hybrid alert - gets 30/34mpg (hwy/city)! FULLY LOADED: factory GPS navigation system and touch screen electronic control panel (incl. hybrid engine HUD), Audiophile sound system, heated leather seats, keyless entry (number pad on driver door), separate driver and passenger climate control, backup sensor, multi-disc CD player, factory rear window tint, roof rack, rear window wiper and defrost, bug shield, AC power outlet in front and two DC (1 front/1 back), etc.
We've really enjoyed having this vehicle, however, we recently moved to a more urban area and simply don't need two vehicles any more. The vehicle was been well-maintained; oil changed every 3.5K miles and recent tune-ups we've done to get car ready for sale include: two new tires (BF Goodrich), a spare full-sized tire under the vehicle, new front and rear brake pads, new rear rotors, new MECS Pump, ti
@abevoelker
abevoelker / gist:1187681
Created September 2, 2011 00:43
Ford Escape ad (Craigslist)
2008 Ford Escape HEV - $15,995 OBO
Color: Silver
Miles: 90,332
Drive: Front Wheel Drive
Transmission: Automatic
VIN: 1FMCU49H98KA18705
**Price Reduced!
***Free CarFax report available here
****More pictures can be seen at: http://katyavoelker.imgur.com/0BZ27/all
@abevoelker
abevoelker / fibonacci.scala
Created June 27, 2011 13:59
Fibonacci in Scala
// Test directly from shell using (e.g. input 5):
// scala -i fibonacci.scala -e 'println(fibonacci(5))'
def fibonacci(n: Int) = fibonacci_tail_recursive(n, 1, 0)
def fibonacci_tail_recursive(iter: Int, current: BigInt, last: BigInt): BigInt= {
if (iter == 0)
last
else
fibonacci_tail_recursive(iter-1, current+last, current)
@abevoelker
abevoelker / factorial.scala
Created June 27, 2011 06:11
Factorial in Scala
// Test directly from shell using (e.g. input 5):
// scala -i factorial.scala -e 'println(factorial(5))'
def factorial(n: BigInt): BigInt = {
if (n <= 1)
1
else
n * factorial(n - 1)
}
@abevoelker
abevoelker / unicode_property_range_parse.rb
Created June 13, 2011 17:47
Unicode 'property' Web app parser
# This snippet is for parsing output from the Unicode 'property' Web app at
# http://unicode.org/cldr/utility/properties.html
#
# Be sure to check the 'Abbreviate' and 'UCD format' boxes, and leave
# 'Escape' unchecked. Copy the hex ranges to an external file, and set its
# path in FILE below.
# Last tested on 2011/06/12
#
# Written by Abe Voelker (http://abevoelker.com)
@abevoelker
abevoelker / color-3D-text.scss
Created June 9, 2011 04:37
Sass colored 3D text (CSS)
// Sassified color version created by Abe Voelker.
// Based on the original white version by Mark Otto:
// http://markdotto.com/playground/3d-text/
@mixin color-3D-text($color) {
text-shadow: 0 1px 0 $color / 1.25,
0 2px 0 $color / 1.268656716,
0 3px 0 $color / 1.363636364,
0 4px 0 $color / 1.378378378,
0 5px 0 $color / 1.5,