Skip to content

Instantly share code, notes, and snippets.

View davidrupp's full-sized avatar

David Rupp davidrupp

View GitHub Profile
@davidrupp
davidrupp / seconds_to_days_hours_minutes_seconds.rb
Created October 14, 2009 16:23
seconds_to_days_hours_minutes_seconds
seconds = 356521
days, hours, minutes, seconds =
[1.day, 1.hour, 1.minute, 1.second].inject([]) do |acc, unit|
quotient, seconds = seconds.divmod unit
acc << quotient
end
@davidrupp
davidrupp / pull_all_git_repos.rb
Created November 4, 2009 02:31
find all git repos and 'git pull' each of them
#!/usr/bin/env ruby
require 'find'
Find.find("/Users/david/Developer") do |path|
Dir.chdir(path) do |d|
next unless File.exists? ("#{d}/.git")
puts d
`git pull`
Find.prune
@davidrupp
davidrupp / gemmate.rb
Created January 14, 2010 20:38 — forked from bguthrie/gemmate.rb
gemmate
#!/usr/bin/env ruby
if ARGV.empty?
puts "Usage: gemmate <name-of-gem>"
else
src = `gem which #{ARGV[0]}`.split.last
lib_dir = src.slice 0, src.rindex("lib")
`mate -a '#{lib_dir}'`
end
# xcode noise
build/*
*.pbxuser
*.mode1v3
# old skool
.svn
# osx noise
.DS_Store
*.pbxproj -crlf -diff -merge
@davidrupp
davidrupp / gist:1212189
Created September 12, 2011 19:47 — forked from retr0h/gist:1001477
RVM + HomeBrew + Nokogiri
BREW_HOME=$HOME/.homebrew
$ brew install libxml2
$ brew link libxml2
$ brew install https://github.com/adamv/homebrew-alt/raw/master/duplicates/libxslt.rb
$ brew link libxslt
$ brew install libiconv
$ brew link libiconv
$ gem install nokogiri -- --with-xml2-dir=$BREW_HOME/Cellar/libxml2/2.7.8 --with-xslt-dir=$BREW_HOME/Cellar/libxslt/1.1.26 --with-iconv-dir=$BREW_HOME/Cellar/libiconv/1.13.1/
@davidrupp
davidrupp / gist:1304294
Created October 21, 2011 16:42 — forked from xlson/gist:1303759
basic-pallet-ec2
(ns quickstart.core
(:require pallet.core
pallet.compute
pallet.phase
pallet.crate.automated-admin-user))
(def basicnode
(pallet.core/node-spec
:image {:os-family :ubuntu :os-version-matches "10.10"}
:hardware {:min-cores 2 :min-ram 512}
@davidrupp
davidrupp / pallet.snippets.clj
Created October 25, 2011 15:48 — forked from hhutch/pallet.snippets.clj
Pallet snippets that are useful
(defn nodes-in-group
"Build a list of nodes in a given security-group"
[security-group]
(filter #(= (% 0) security-group)
(map #(vector (pallet.compute/group-name %)
(pallet.compute/primary-ip %)
(pallet.compute/id %)
(pallet.compute.jclouds/node-locations %) )
(pallet.compute/nodes srvc))))
@davidrupp
davidrupp / cron-s3-rsync.clj
Created October 25, 2011 15:56 — forked from hhutch/cron-s3-rsync.clj
create a script with stevedore, schedule it with cron
(defn install-backup-scripts
"Creates a script in stevedore and installs it as a shell script in the administrative user's home dir
and installs it as a cron. This will override the crontab."
[request]
(let [administrative-user (:username (pallet.session/admin-user request))
admin-home-dir (str "/home/" administrative-user)
raw-instance-id (-> request :target-node (pallet.compute/id))
instance-id (apply str (interpose "_" (clojure.string/split raw-instance-id #"/")))
instance-group (-> request :target-node (compute/group-name))
s3-dir (str "/mnt/s3logstore/" instance-id "." instance-group)
@davidrupp
davidrupp / nodes-and-ips-in-group.clj
Created October 26, 2011 14:02
Find the running Pallet nodes in a group, along with their IP addresses
; Get the running nodes and the their ip addresses for the named group
; Need to define:
; service - the pallet.compute service on which the nodes are running
(defn nodes-in-group
[group]
(filter
#(and (.equals group (pallet.compute/group-name %))
(pallet.compute/running? %))
(pallet.compute/nodes service)))