Skip to content

Instantly share code, notes, and snippets.

Bradley Schaefer soulcutter

Block or report user

Report or block soulcutter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@soulcutter
soulcutter / gist:2314814
Created Apr 5, 2012
Overriding instance methods
View gist:2314814
module WizardSkills
module InstanceMethods
def trick
super
puts "The #{self.class} turned a man into a rabbit"
end
end
end
module MagicianSkills
@soulcutter
soulcutter / rubyprof.rake
Created Apr 14, 2012
Ruby profiling rake task
View rubyprof.rake
require 'ruby-prof'
require 'ruby-prof/task'
RubyProf::ProfileTask.new(:integration) do |t|
t.test_files = FileList['test/integration/**/patients_test.rb']
t.output_dir = File.join(Rails.root, 'tmp')
t.printer = :graph_html
t.min_percent = 10
end
@soulcutter
soulcutter / gist:2458278
Created Apr 22, 2012
irbrc helper to print documentation
View gist:2458278
class Object
# list methods which aren't in superclass
def local_methods(obj = self)
(obj.methods - obj.class.superclass.instance_methods).sort
end
# print documentation
#
# ri 'Array#pop'
# Array.ri
@soulcutter
soulcutter / gist:2477448
Created Apr 24, 2012
Saxerator example
View gist:2477448
require 'saxerator'
# The parser takes any IO object (or String) - a File is a common choice
parser = Saxerator.parser(bookshelf_xml)
# Simplest usage, parses every <book></book> in the document
parser.for_tag(:book).each do |book|
# Your book hash might look something like
{ 'title' => 'Rails 3 In Action', 'author' => ['Ryan Bigg', 'Yehuda Katz'] }
end
View gist:2705200
describe Article do
subject(:article) { Article.new }
it "validates presence of :title" do
article.should validate_presence_of(:title)
end
end
@soulcutter
soulcutter / gist:3671893
Created Sep 8, 2012
JRuby NPE using Symbol#to_proc with --1.9
View gist:3671893
➜ saxerator git:(master) ✗ ruby -v
jruby 1.7.0.preview2 (1.9.3p203) 2012-09-07 f4306fa on Java HotSpot(TM) 64-Bit Server VM 1.6.0_33-b03-424-11M3720 [darwin-x86_64]
➜ saxerator git:(master) rspec spec/lib/dsl/for_tag_spec.rb
/Users/soulcutter/.rvm/gems/jruby-head@saxerator/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:274 warning: singleton on non-persistent Java type Java::JavaLang::NullPointerException (http://wiki.jruby.org/Persistence)
F
Failures:
1) Saxerator::DSL#for_tag should only select the specified tag
Failure/Error: Unable to find matching line from backtrace
@soulcutter
soulcutter / gist:3718477
Created Sep 13, 2012
ssh-agent launcher
View gist:3718477
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initializing new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
ssh_environment_init;
/usr/bin/ssh-add;
}
@soulcutter
soulcutter / gist:3738320
Created Sep 17, 2012
Adding magic encoding comments to ruby files
View gist:3738320
#!/bin/zsh
for file in $(awk 'FNR == 1 && !/^#\!/ { print FILENAME; nextfile }' **/*.rb); do
echo $file
sed -i 1i'# encoding: utf-8' $file
done
@soulcutter
soulcutter / gist:3873662
Created Oct 11, 2012
Spring ActiveProfiles injection question
View gist:3873662
// Question: Can you do something like this without using interface-based injection?
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("test")
public class FakeDownloadUtilTest extends BaseTest {
@Autowired
DownloadUtil downloadUtil;
@Test
public void testFaked() {
@soulcutter
soulcutter / gist:4003852
Created Nov 2, 2012
Installing savon under jruby 1.6.3
View gist:4003852
➜ ~ rvm install jruby-1.6.3
jruby-1.6.3 - #downloading jruby-bin-1.6.3, this may take a while depending on your connection...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14.7M 100 14.7M 0 0 459k 0 0:00:32 0:00:32 --:--:-- 410k
jruby-1.6.3 - #extracting jruby-bin-1.6.3 to /Users/brschaefer/.rvm/src/jruby-1.6.3
jruby-1.6.3 - #extracted to /Users/brschaefer/.rvm/src/jruby-1.6.3
Building Nailgun
jruby-1.6.3 - #installing to /Users/brschaefer/.rvm/rubies/jruby-1.6.3
jruby-1.6.3 - adjusting #shebangs for (jrubyc jirb_swing jirb jgem rdoc ri spec autospec testrb ast generate_yaml_index.rb).
You can’t perform that action at this time.