Skip to content

Instantly share code, notes, and snippets.

@rwjblue
rwjblue / mailbox_size.sh
Created October 12, 2012 18:55
List mailbox size in Zimbra
sudo su - zimbra
for i in `zmprov -l gaa` ; do echo $i; zmmailbox -z -m $i gms ; done
@rwjblue
rwjblue / article.rb
Created October 16, 2012 19:08
Refactor of Try and Try again article
class Project
attr_reader :supervisor
def initialize(supervisor = NullSupervisor.new)
@supervisor = supervisor
end
end
Supervisor = Struct.new(:first_name, :last_name, :email) do
def display_name
@rwjblue
rwjblue / struct_vs_class.rb
Created October 16, 2012 19:10
Struct vs Class - Simple Comparison
Supervisor = Struct.new(:first_name, :last_name, :email)
class Supervisor
attr_accessor :first_name, :last_name, :email
def initialize(first_name, last_name, email)
@first_name = first_name
@last_name = last_name
@email = email
end
@rwjblue
rwjblue / setup.sh
Created October 18, 2012 16:03
MacVim, bundler, and ctags -- Oh, my!
# https://github.com/tpope/gem-ctags
gem install gem-ctags
gem ctags
# install bundler.vim plugin (I use git submodules and pathogen.vim)
cd ~/.vim
git submodule add git://github.com/tpope/vim-bundler.git bundle/bundler
# That's IT! Now you can jump directly to tags from gems.
require 'tmpdir'
Dir.mktmpdir('prefix','tmp') {|dir| puts dir}
Dir.mktmpdir(['prefix','tmp']) {|dir| puts dir}
Dir.mktmpdir(['prefix','suffix'],'tmp') {|dir| puts dir}
# Output:
# /Users/rjackson/tmp/prefix20121019-49710-y4w7ag
# /var/folders/16/t1n7l6qj36z5ws4zz_6c9yww0000gn/T/prefix20121019-49710-o0ohsdtmp
# /Users/rjackson/tmp/prefix20121019-49710-1g4yxexsuffix
@rwjblue
rwjblue / forwardable_example.rb
Created November 8, 2012 17:57
Forwardable Example
require 'forwardable'
class Supervisor
def email
'blah'
end
def first_name
'Jon'
end
@rwjblue
rwjblue / toggle_mirror.scpt
Created November 12, 2012 19:28
Toggle mirroring and set resolution to 'Best for Retina Display'.
tell application "System Preferences"
activate
reveal anchor "displaysArrangementTab" of pane id "com.apple.preference.displays"
tell application "System Events"
tell application process "System Preferences"
tell window 1
tell tab group 1
click radio button "Arrangement"
click checkbox "Mirror Displays"
click radio button "Display"
@rwjblue
rwjblue / answering_machine_detection.rb
Created November 14, 2012 02:01
Tropo Answering Machine Detection Example
# From http://blog.tropo.com/2010/12/17/human-vs-answering-machine-detection
call 'tel:+14805551212'
starttime = Time.new
record ".", {
:beep => false,
:timeout => 10,
:silenceTimeout => 1,
:maxTime => 10
@rwjblue
rwjblue / automated_dialer_client.rb
Created November 14, 2012 05:43
Automated Dialier with Machine Detection using Tropo.
require 'restclient'
RestClient.get 'https://api.tropo.com/1.0/sessions', {:params => {
:action => 'create',
:token => 'YOUR TROPO TOKEN HERE',
:number => "13525557567",
:client_name => "Joe Bob's Anesthesia",
:account_number => '539181',
:first_name => 'Robert',
:balance => 1345.12,
set project_directory to do shell script "find ~/ ~/Source ~/Source/ruby ~/Source/ruby/webapps -maxdepth 1 -type d -name " & q & " | head -1"
on pathexists(path)
try
path as alias
return true
on error
return false
end try
end pathexists