Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View robhurring's full-sized avatar
🍻
cheers

Rob Hurring robhurring

🍻
cheers
View GitHub Profile
#!/usr/local/bin/ruby
require 'rubygems'
require 'action_mailer'
require 'optparse'
require 'fcntl'
require 'pp'
ActionMailer::Base.delivery_method = :sendmail
@robhurring
robhurring / plugin_loader.rb
Created May 18, 2010 15:42
Simple way to load Rails plugins in Sinatra
# 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
<div id='sidebar'>
<%= section(:sidebar) || partial(:default_sidebar) %>
</div>
# 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)
<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>
@robhurring
robhurring / bash_aliases.sh
Created November 22, 2010 19:48
Fun with OpenSSL encryption
# 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 '
@robhurring
robhurring / piped_stdin.rb
Created November 22, 2010 20:03
Check for piped STDIN in ruby shell scripts without prompting
# 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
@robhurring
robhurring / push_path.sh
Created November 22, 2010 20:05
Add paths to $PATH from multiple places in .bashrc/etc. : http://proccli.com/easy-add-paths-path-bash
# 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
@robhurring
robhurring / ghetto_thread_pooling.rb
Created November 22, 2010 20:24
Simple way to do multi-threaded chunking in Ruby : http://proccli.com/super-simple-thread-pooling-ruby
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)
@robhurring
robhurring / entourage_email_script.rb
Created November 22, 2010 20:30
Ruby shell script to create Entourage emails from the command line - http://proccli.com/send-entourage-mails-command-line-ruby
#!/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