This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Activate the gem you are reporting the issue against. | |
gem 'activerecord', '3.2.18' | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# This connection will do for database-independent bug reports. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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/' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn convert-rs | |
[rs keys] | |
(vec (doall | |
(map #(vec (map-values % keys)) rs)))) | |
(defn map-values | |
[r keys] | |
(map #(% r) keys)) | |
(defn users-query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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) '()))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def notify_new_relic | |
run "cd #{release_path} && newrelic_cmd deployments -r `git log -1 --pretty=format:%H | head` || /bin/true" | |
end | |
on_app_master do | |
notify_new_relic | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S3Object.store('lambda.jpg', d, 'mybucket', :content_type => 'image/jpeg', :content_md5 => Base64.encode64(Digest::MD5.digest(d))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))) |
NewerOlder