This file contains hidden or 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
# complete hack to swap date MM/DD/YYYY around to YYYY/MM/DD | |
# so Ruby 1.9 will parse American dates the way we like 'em | |
# (works in Rails due to use of alias_method_chain) | |
class Date | |
class << self | |
def _parse_with_american_date(str, comp=true) | |
_parse_without_american_date(str.sub(/(\d{1,2})\/(\d{1,2})\/(\d{4})/, '\3/\1/\2'), comp) | |
end | |
alias_method_chain :_parse, :american_date |
This file contains hidden or 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
{ | |
/* Remap Home / End to be correct on Mac */ | |
"\UF729" = "moveToBeginningOfLine:"; /* Home */ | |
"\UF72B" = "moveToEndOfLine:"; /* End */ | |
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */ | |
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */ | |
} |
This file contains hidden or 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
function number_to_human_size(size) { | |
if(size < 1024) | |
return size + ' bytes'; | |
else if(size < 1024.0 * 1024.0) | |
return (size / 1024.0).toFixed(1) + ' KiB' | |
else if(size < 1024.0 * 1024.0 * 1024.0) | |
return (size / 1024.0 / 1024.0).toFixed(1) + ' MiB' | |
else | |
return (size / 1024.0 / 1024.0 / 1024.0).toFixed(1) + ' GiB'; | |
} |
This file contains hidden or 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
lines = File.read(ARGV.first).split("\n") | |
File.open(ARGV.last, 'w') do |out| | |
lines.each do |line| | |
if line =~ /:/ | |
key, value = line.split(/:\s*/, 2) | |
value = eval(value) if value =~ /^"/ | |
if value =~ /\{|"|:/ | |
value.gsub!(/"/, "\\\"") | |
value = "\"#{value}\"" |
This file contains hidden or 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 'test/unit' | |
Person = Struct.new(:name, :age, :gender) | |
class GroupByTest < Test::Unit::TestCase | |
def setup | |
@people = [ | |
@jennie = Person.new('Jennie', 29, 'f'), | |
@justin = Person.new('Justin', 28, 'm'), |
This file contains hidden or 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
pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile.png outfile.png |
This file contains hidden or 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
# I don't pretend to understand this query, | |
# but it seems to be a good list of processes | |
# that are "blocking" other processes and hosing the server. | |
select * from sys.dm_os_waiting_tasks where session_id != @@spid and session_id > 50 and blocking_session_id < session_id order by wait_duration_ms desc; |
This file contains hidden or 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 | |
# dedup_emails_for_scott.rb | |
# usage: | |
# ruby dedup_emails_for_scott.rb file_to_upload.csv existing_entries.csv file_to_upload_deduped.csv | |
EMAIL_COL = 'Email' # change this if your column name is not 'Email' | |
if ARGV.length == 3 | |
upload_filename, existing_filename, output_filename = ARGV | |
else |
This file contains hidden or 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
; my first clojure program -- pings a subnet looking for existing hosts | |
; usage (you'll need a clj repl script): | |
; clj pingdom.clj 192.168.2 | |
; clj pingdom.clj --used 10.0.0 | |
; | |
(ns pingdom | |
(:use [clojure.contrib.shell-out :only (sh)]) | |
(:use [clojure.contrib.str-utils :only (re-split str-join)]) | |
(:use [clojure.contrib.string :only (replace-first-re)])) |
This file contains hidden or 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 'pp' | |
class Card | |
attr_reader :face_up | |
def initialize(face_up) | |
@face_up = face_up | |
end | |
def flip |