Skip to content

Instantly share code, notes, and snippets.

View taylor's full-sized avatar
🐢
🌊

Taylor Carpenter taylor

🐢
🌊
View GitHub Profile
@taylor
taylor / x.rb
Created February 20, 2009 03:54
add scripts lib dir to ruby path in 3 lines
#!/usr/bin/env ruby
def n
STDOUT.sync = true
print '--->'
gets
end
puts "Trying to require blah lib"
puts "require 'blah'"
# Printing only matching lines
l="john smith\nalice pena\nroot\nbob living\ntammy baroot\ncats"
q="root"
#string.each works by "splitting" on the end of line char... so this works "a\n\b\c"
l.each {|x| next unless x =~ /#{q}/ ; puts "x #{x}" }
# Create a new multi-line string w/only matching lines
s="abc\nlots of girls\nfat chickens\ngirls everywhere\nmeetings\ntaco\ngirl in bikini\ncats"
@taylor
taylor / get_private_network
Created February 9, 2011 06:18
Generate a random network block
#!/usr/bin/env ruby
@net172_octet_rejects = [nil, %w(16 20 24 31), %w(0 1)]
@net192_octet_rejects = [nil, nil, %w(0 1 2 3 4 5 6 7 8 9 10 168 254)]
def generate_net172(n=:C)
begin
octet_2 = (rand(16) + 16).to_s
end while @net172_octet_rejects[1].include?(octet_2)
@taylor
taylor / asterisk minutes calculations
Created March 5, 2011 00:31
calculate total minutes and hours used for calling
ruby -e 'require "rubygems"; \
begin; \
require "fastercsv"; \
myCSV=FasterCSV; \
rescue LoadError; \
require 'csv'; \
myCSV=CSV; \
end; \
s=0;
myCSV.foreach(ARGV[0]) do |r| \
#!/usr/bin/env ruby
require "rubygems"
begin
require "fastercsv"
myCSV=FasterCSV
rescue LoadError
require 'csv'
myCSV=CSV
end
Some methods for randomizing the processing order for results returned from a DB query
Straight SQL
SELECT * FROM `fax_stats` WHERE (`company` IN ('company123')) ORDER BY random();
ActiveRecord option #1
FaxStat.find(:all, :conditions => "company='company123'", :order => rand())[2];
#!/bin/sh
default_user="root"
user=${default_user}
homedir=`grep "^${user}:" /etc/passwd | awk -F: '{print $6}'`
ssh_dir="${homedir}/.ssh"
auth_key_file="${ssh_dir}/authorized_keys"
@taylor
taylor / aws_cf_invalidate.rb
Created May 27, 2011 07:29 — forked from jmlacroix/aws_cf_invalidate.rb
Command line script to invalidate cloudfront objects
require 'rubygems'
require 'hmac-sha1'
require 'net/https'
require 'base64'
s3_access='S3_ACCESS_KEY'
s3_secret='S3_SECRET_KEY'
cf_distribution='CLOUDFRONT_DISTRIBUTION_ID'
if ARGV.length < 1
@taylor
taylor / GoogleVoiceDialerAction.scpt
Created June 27, 2011 06:41 — forked from matthewtodd/GoogleVoiceDialerAction.scpt
Command-line Google Voice dialer and Mac OSX Address Book Plug-In
-- Drop this script in ~/Library/Address Book Plug-Ins
-- Edit the path in the "do shell script" line
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for aPerson with aNumber
return "Dial with Google Voice"
end action title
@taylor
taylor / adhearsion-rhel5.sh
Created August 26, 2011 04:32 — forked from bklang/adhearsion-rhel5.sh
Adhearsion QuickStart for RedHat Enterprise Linux/CentOS 5
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-latest )
source /usr/local/rvm/scripts/rvm
echo "source /usr/local/rvm/scripts/rvm" >> $HOME/.profile
yum install -y bash curl gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel iconv-devel
rvm install 1.9.2
rvm use --default 1.9.2
gem install bundler