Skip to content

Instantly share code, notes, and snippets.

View nicksieger's full-sized avatar

Nick Sieger nicksieger

View GitHub Profile
@nicksieger
nicksieger / callback_trace.rb
Last active October 20, 2016 20:47
Troubleshoot ActiveRecord callbacks; require/load this at the top of config/application.rb
module CallbackTrace
def self.included(kls)
kls.send :alias_method_chain, :_compile_filter, :trace
end
def _compile_filter_with_trace(filter)
generated_code = _compile_filter_without_trace(filter)
return generated_code if filter.is_a?(Array) || @kind == :around || !(@klass.ancestors.include?(ActiveRecord::Base))
"($stdout.print 'Callback: #{@kind} #{@klass.name}##{@raw_filter}'; $stdout.puts self.inspect; #{generated_code})"
end
$ cat fucksgiven.c
#include <stdio.h>
#include <stdlib.h>
typedef struct aFuck {} Fuck;
int main (int argc, char** argv)
{
Fuck * given = (Fuck*) malloc(argc * sizeof(Fuck));
printf("You gave %lu fucks\n", sizeof(*given));
@nicksieger
nicksieger / gist:10133066
Created April 8, 2014 14:28
Poems are rough notations for the music we are.
Did you hear that winter is over?
The basil and carnation cannot control their laughter.
The nightingale, back from his wandering,
has been made singing master over all the birds.
The trees reach out their congratulations.
The soul goes dancing through the king’s doorway.
Anemones blush because they have seen the rose naked.
@nicksieger
nicksieger / noisy.rb
Created September 1, 2012 16:32
A VCR like object that allows you to collect messages sent to it and print them out later
class NoisyStubCollector < BasicObject
def method_missing(meth,*args,&blk)
@messages ||= []
@messages << [meth,args,blk]
self
end
def inspect
(@messages || []).map{|meth,args,blk| "#{meth}#{args.inspect}#{blk.inspect if blk}"}.join(' ')
@nicksieger
nicksieger / thread_dump_on_quit.rb
Created August 29, 2012 14:38
kill -QUIT thread dump in Ruby. Seems like I need this and forget exactly how to do it.
trap("QUIT") do
Thread.list.each do |t|
$stderr.puts
$stderr.puts t.inspect
$stderr.puts t.backtrace.join("\n ")
end
end
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='jenkins/node'>
<service name='network/jenkins/node' type='service' version='0'>
<create_default_instance enabled='true'/>
<single_instance/>
<dependency name='fs' grouping='require_all' restart_on='none' type='service'>
<service_fmri value='svc:/system/filesystem/local'/>
</dependency>
<dependency name='net' grouping='require_all' restart_on='none' type='service'>
@nicksieger
nicksieger / gist:2906871
Created June 10, 2012 18:43
Renaming a Java thread in JRuby
$ jirb
irb(main):001:0> t = Thread.new { sleep }
=> #<Thread:0x64e5b2 sleep>
irb(main):002:0> require 'jruby'
=> true
irb(main):003:0> jt = JRuby.reference(t)
=> #<Thread:0x64e5b2 sleep>
irb(main):004:0> jt.native_thread.name
=> "RubyThread-7: (irb):1"
irb(main):005:0> jt.native_thread.name = "My Ruby thread"
RSpec::Matchers.define :have_jsonish_contents do |expected|
def matches_at_this_level?(exp, act)
if exp.respond_to?(:to_a) && act.respond_to?(:to_a)
exp_arr = exp.to_a
act_arr = act.to_a
return false if exp_arr.length != act_arr.length
exp_arr.each_with_index do |elem,i|
return false unless matches_at_this_level?(elem, act_arr[i])
end
return true
@nicksieger
nicksieger / command.diff
Created May 4, 2012 17:24
JRuby launcher does not handle -cp properly
--- command1.txt 2012-05-04 12:21:09.000000000 -0500
+++ command2.txt 2012-05-04 12:21:25.000000000 -0500
@@ -11,9 +11,9 @@
-Djruby.memory.max=500m
-Djruby.stack.max=2048k
-Dsun.java.command=org.jruby.Main
--Djava.class.path=/usr/share/java/ant-1.8.2/lib/*:
+-cp /usr/share/java/ant-1.8.2/lib/*:
-Xbootclasspath/a:/Users/nicksieger/.rvm/rubies/jruby-1.6.7/lib/jruby.jar
org/jruby/Main
@nicksieger
nicksieger / jruby.sh
Created March 15, 2012 16:20
JRuby launcher script to use in Warbler war files
#!/bin/sh
#
# Simple script to launch JRuby using the components embedded in a war created by Warbler.
# Tell Warbler to put this script in /WEB-INF with this config/warble.rb code:
#
# config.webinf_files += FileList["jruby.sh"]
#
HERE=`dirname $0`
GEM_HOME=$HERE/gems