Skip to content

Instantly share code, notes, and snippets.

begin
class_to_load = class_name.constantize
class_to_load.new
# ...
rescue NameError => e
# do other things if class_name is not an actual class
end
@zev
zev / github_show.sh
Created September 18, 2012 03:55 — forked from andrewplummer/github_show.sh
Open a link to a file in Github from the command line.
#!bin/bash
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_git_remote() {
git remote -v | head -n 1 | sed 's/.*github.com:\(.*\).git .*/\1/'
}
@zev
zev / dbtap.clj
Created May 16, 2012 02:13
Custom Cascalog tap from a db query
(defn convert-rs
[rs keys]
(vec (doall
(map #(vec (map-values % keys)) rs))))
(defn map-values
[r keys]
(map #(% r) keys))
(defn users-query
@zev
zev / DWIMlogging
Created September 28, 2011 03:03
Buffered logging to handle encoding conversion failures
def flush
@guard.synchronize do
unless buffer.empty?
old_buffer = buffer
begin
@log.write(old_buffer.join)
rescue Encoding::UndefinedConversionError
puts "Enc err"
@log.write(old_buffer.map { |b| b.force_encoding(Encoding.default_internal) }.join)
puts "Enc Done"
@zev
zev / gist:1196530
Created September 6, 2011 03:49
programming-praxis remove dup chars
;; solution for part 1 http://programmingpraxis.com/2011/09/02/two-string-exercises/
(defun rdup (str)
(defun rdup_ (str res)
(if (null str)
res
(if (member (car str) res)
(rdup_ (cdr str) res)
(rdup_ (cdr str) (append res (list (car str)))))))
(concat (rdup_ (string-to-list str) '())))
@zev
zev / example_aws_s3_digest_usage.txt
Created September 3, 2010 10:21
How to send the hexdigest safely in s3
S3Object.store('lambda.jpg', d, 'mybucket', :content_type => 'image/jpeg', :content_md5 => Base64.encode64(Digest::MD5.digest(d)))
@zev
zev / *scratch*
Created September 1, 2010 09:08
sample conditional shell checks
# rough if else ...
execute "restarting-mysql-with-custom-config" do
command "/etc/init.d/mysql restart"
only_if "pgrep mysqld"
end
execute "starting-mysql-with-custom-config" do
command "/etc/init.d/mysql start"
not_if "pgrep mysqld"
;; Fix indentation for buffer
(defun fix-read-only-indentation ()
"Fix the indentation of a read only file. For now you have to
remember to not save this change if you have write access to the
file"
(interactive)
(toggle-read-only)
(indent-region (point-min) (point-max)))
zblut@zblut-benchmark smart_api (ey_appcloud) % ey deploy -a smart_api -e testdb -r ey_appcloud
Connecting to the server...
Beginning deploy for 'smart_api' in 'testdb' on server...
~> Deploying revision 8bbe781... Debugging why deploy is now failing and loosing current symlink.
~> Loading deployment task overrides from /data/smart_api/shared/cached-copy/config/eydeploy.rb
~> Pushing code to all servers
rsync: failed to set times on "/data/smart_api/shared/cached-copy/tmp": Operation not permitted (1)
rsync: recv_generator: mkdir "/data/smart_api/shared/cached-copy/tmp/cache" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
rsync: recv_generator: mkdir "/data/smart_api/shared/cached-copy/tmp/sessions" failed: Permission denied (13)