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/local/bin/ruby | |
require 'rubygems' | |
require 'action_mailer' | |
require 'optparse' | |
require 'fcntl' | |
require 'pp' | |
ActionMailer::Base.delivery_method = :sendmail |
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
# Simple bootloader for Rails plugins in Sinatra | |
# This checkes the +plugin_folder+ for plugin-like bundles. For each folder it finds it will do: | |
# If the +lib+ folder exists: add it to our load path | |
# If a +init.rb+ file exists: require it | |
# Not very robust but it is lightweight for loading simple rails plugins | |
class PluginLoader | |
attr_reader :plugin_folder | |
def initialize(plugin_folder) | |
@plugin_folder = plugin_folder |
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
<div id='sidebar'> | |
<%= section(:sidebar) || partial(:default_sidebar) %> | |
</div> |
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
# You can use the model's ID (PK/Serial) to generate a token which can be reversed: | |
# Example: | |
# Url.find(7213).shortened #=> 5kd | |
# Url.find_by_shortened("5kd") #=> #<Url id: 7213...> | |
class Url < ActiveRecord::Base | |
Radix = 36 | |
# convert ID into a shortened version | |
def shortened | |
id.to_s(Radix) |
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
<script src='http://www.google.com/jsapi' type='text/javascript' charset='utf-8'></script> | |
<script type='text/javascript' charset='utf-8'> | |
google.load('prototype', '1.6'); | |
google.load('scriptaculous', '1.8'); | |
</script> |
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
# Put this somehwere in .bashrc/aliases/etc. | |
# OpenSSL must be installed -- these are just aliases. | |
alias enc='openssl enc -e -aes-256-cbc -salt ' | |
alias dec='openssl enc -d -aes-256-cbc ' |
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
# body will be set ONLY if data is piped in, and will not | |
# prompt the user for STDIN otherwise. | |
require 'fcntl' | |
body = STDIN.read if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0 |
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
# Push a path to our $PATH variable | |
# Usage: | |
# push_path <path> [after] | |
# If after is specified it will appear at the end of $PATH, otherwise it is unshifted | |
push_path(){ | |
if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then | |
if [ "$2" = "after" ] ; then | |
PATH=$PATH:$1 | |
else | |
PATH=$1:$PATH |
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 'thread' | |
# Stupid simple "multi-threading" - it doesn't use mutex or queues but | |
# it does have access to local variables, which is convenient. This will | |
# break a data set into equal slices and process them, but it is not | |
# perfect in that it will not start the next set until the first is | |
# completely processed -- so, if you have 1 slow item it loses benefit | |
# NOTE: this is not thread-safe! | |
class ThreadPool | |
def self.process!(data, size = 2, &block) |
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/local/bin/ruby | |
# Mail script for sending stuff from the command line through entourage | |
# which makes life super easy for sending files, or piping files to a mail body, etc. | |
# | |
# email -t bosses -c tracker -a ~/report.csv <SUBJECT HERE> | |
# | |
# Author:: Rob Hurring | |
# Date:: 2011-11-15 | |
# Version:: 1.0a |