This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Brand < ActiveRecord::Base | |
(0..5).each do |f| | |
define_method("flags_#{f}".to_sym) { read_attribute("flags_#{f}".to_sym).to_2s_complement(64) } | |
define_method("flags_#{f}=".to_sym){ |n| write_attribute("flags_#{f}".to_sym), n.to_2s_complement(64) } | |
end | |
# I'm getting syntax errors in the above code. Not sure why. | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### FILE : lib/words.rb | |
# Gives you N random word(s) over a certain length | |
# Only works on unixlike systems where this file exists | |
class Words | |
# DICT_PATH = '/usr/share/dict/words' | |
# DICT_SIZE = 234936 | |
def self.random_word(words = 1, minlength = 6) | |
@@dict_all ||= File.open("/usr/share/dict/words").readlines.map{|l| l.chomp} | |
@@dict_size ||= @@dict_all.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/sha1' | |
require 'tempfile' | |
class LocalPaperclipTempfile < ::Tempfile | |
# note: had a ton of trouble using "data" instead of "tmp_data" for naming here: | |
def initialize(filename, tmp_data, tmpdir = Dir::tmpdir) | |
@original_filename = filename | |
@tmp_data = tmp_data | |
super Digest::SHA1.hexdigest(@tmp_data), tmpdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
# note: very rough, does not handle caps (but that could be added), just something to help sort accented characters correctly... | |
TRANSLATION_HASH = {"’"=>"'","åäáàâ" => "a", "ëéèê" => "e", "ïíìî" => "i", "öóòô" => "o", "üúùû" => "u", "ß" => "ss"} | |
UNUNICODE = Hash[*TRANSLATION_HASH.map{|u,as| u.unpack("U*").inject([]){|sum,e| sum << e; sum << as}}.flatten] | |
def un_unicode | |
self.unpack("U*").map{|c| UNUNICODE[c] ? UNUNICODE[c] : c.chr}.join | |
end | |
end | |
# use case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sender' | |
# For fun, trying to define my own string interpolator so that any symbol in a string (optionally end-delimited with a colon if not at a word boundary) gets substituted for its eval'd value. | |
# Here's what I have so far. No workie, due to context issue with "eval" call. Help? | |
class String | |
def i | |
self.gsub(/:([\w_]+)/){|match| __sender__.eval $1} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mathhax | |
def /(o) | |
if o==0 | |
puts "I'm sorry, #{`hostname`.chomp}, I'm afraid I can't do that" | |
else | |
super | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Time | |
def format_compact(precision = :second, inc_utc = true) | |
prec = [:year, :month, :day, :hour, :minute, :second].index precision | |
fmt_a = ["%Y","%m","%d","_%H","%M","%S"][0..prec] | |
fmt = fmt_a.join('') | |
self.strftime("#{fmt}#{'%Z' if inc_utc}") | |
end | |
def format_datestamp(inc_utc = true) | |
self.strftime("%Y%m%d#{'%Z' if inc_utc}") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lifebooker@lifebookers-Mac-mini-2[:~[$ /usr/bin/env HOMEBREW_TEMP=/Users/lifebooker/Developer/tmp /Users/lifebooker/Developer/bin/brew install wget | |
==> Downloading http://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2 | |
File already downloaded in /Users/lifebooker/Library/Caches/Homebrew | |
==> Downloading patches | |
######################################################################## 100.0% | |
==> Patching | |
patch unexpectedly ends in middle of line | |
/usr/bin/patch: **** Only garbage was found in the patch input. | |
Error: Failure while executing: /usr/bin/patch -f -p1 -i 001-homebrew.diff | |
lifebooker@lifebookers-Mac-mini-2[:~[$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Utf8Checker | |
def initialize(path = `pwd`.chomp) | |
@files = Dir["#{path}/**/**"] | |
@total_num = @files.count | |
puts "#{@total_num} files to process." | |
@num_left = @total_num | |
@valid = false | |
@err = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# fake_time_machine.sh | |
# Fake Time Machine | |
# by Peter Marreck | |
# Based on ideas in http://blog.interlinked.org/tutorials/rsync_time_machine.html | |
# 9/2011 | |
# E_BADARGS=85 | |
# if [ -z "$1" ] |
OlderNewer