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 'fuzzystringmatch' | |
class Phrase | |
attr_reader :matches | |
def initialize(str, match_score=0.8) | |
@str = str | |
@matches = [] | |
@match_score = match_score | |
@scorer = FuzzyStringMatch::JaroWinkler.create |
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 'set' | |
class CleanedList | |
def initialize | |
@data = SortedSet.new | |
end | |
def to_a | |
@data.to_a | |
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
# Date formats | |
Time::DATE_FORMATS.merge!( | |
:friendly_date => lambda {|d| "#{d.month}/#{d.mday}" }, # 4/25 (no leading zeroes) | |
:friendly_time => lambda {|t| | |
date = (t.at_midnight == Time.now.at_midnight) ? '' : "#{t.month}/#{t.mday}@" # 4/25@4PM on other days | |
"#{date}#{t.strftime('%I').to_i}#{t.strftime('%p')}" # 4PM on same day | |
}, | |
:year => "%Y", # 2008 | |
:month_year => "%b %Y", # Apr 2008 | |
:ampm_time => "%I:%M %p", # 04:15 PM |
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 Sanity | |
module ActsAsSaneNestedAttributes | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def acts_as_sane_nested_attributes(options = []) | |
puts 'Setting up child callbacks' | |
ActiveRecord::Callbacks::CALLBACKS.each do |callback| |
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 | |
QUEUE = Beanstalk::Pool.new(['127.0.0.1:11300']) | |
MAILR = Mailer.new | |
MAILR.deliver_digests | |
# Main program loop | |
counter = 0 | |
loop do |
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
# Switch me back to ^A, thanks | |
set-option -g prefix C-a | |
unbind-key C-b | |
bind-key a send-prefix | |
# I miss ^A^A and ^ASpace | |
bind-key C-a last-window | |
bind-key Space next-window | |
bind-key C-Space previous-window |
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
#!/bin/bash | |
YUM=`which yum 2> /dev/null` | |
APT=`which apt-get 2> /dev/null` | |
YUM_GIST=1926743 | |
APT_GIST=1926909 | |
if [ $YUM ]; then | |
bash < <(curl --location --silent https://raw.github.com/gist/$YUM_GIST) |
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
#!/bin/bash | |
apt-get update -qq | |
UPDATES=`apt-get dist-upgrade --simulate | grep Inst | awk '{print $2}'` | |
COUNT=`printf "%s\n" "$UPDATES" | grep -v "^$" | wc -l` | |
echo '--------------------------------------------------------------------------------' | |
echo " Weekly Update Notification for `hostname`" | |
echo " -> $COUNT update(s) available" | |
echo '--------------------------------------------------------------------------------' | |
printf "%s\n" "$UPDATES" |
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
#!/bin/bash | |
UPDATES=`yum check-update -q | awk '{print $1}'` | |
COUNT=`printf "%s\n" "$UPDATES" | grep -v "^$" | wc -l` | |
YUM=`printf "%s\n" "$UPDATES" | grep -v "^$" | grep yum` | |
echo '--------------------------------------------------------------------------------' | |
echo " Weekly Update Notification for `hostname`" | |
echo " -> $COUNT update(s) available" | |
if [ -n "$YUM" ]; then | |
echo ' -> IMPORTANT: A Yum update is available. Perform this separately and first.' | |
fi |
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
# c = CSVBuilder.new ['column 1 name', 'column 2 name', 'column 3 name'] | |
# rowdata.each do |r| | |
# special_column = r.boolean ? 'YES' : 'NO' | |
# c.add_row [special_column, r.name, r.date] | |
# end | |
# c.export('optional_filename.csv') | |
class CSVBuilder | |
def initialize(head) | |
if head.is_a?(Array) |