Skip to content

Instantly share code, notes, and snippets.

@pmahoney
pmahoney / activerecord test errors
Created May 25, 2012 14:50
activerecord test errors
... similar errors elided ...
16) Error:
test_writing_with_not_nullable_column_encoded_with_JSON(StoreTest):
ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a ActiveSupport::HashWithIndifferentAccess, but was a Hash
/home/pat/dev/ruby/rails/activerecord-mine/lib/active_record/coders/yaml_column.rb:34:in `load'
/home/pat/dev/ruby/rails/activerecord-mine/lib/active_record/attribute_methods/serialization.rb:38:in `unserialize'
/home/pat/dev/ruby/rails/activerecord-mine/lib/active_record/attribute_methods/serialization.rb:29:in `unserialized_value'
/home/pat/dev/ruby/rails/activerecord-mine/lib/active_record/attribute_methods/serialization.rb:19:in `type_cast'
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/ruby</directory>
</resource>
</resources>
...
@pmahoney
pmahoney / gist:3503878
Created August 28, 2012 20:32
Ruby Servlet impl skeleton
# Implements some part of the Servlet API in Ruby. Does not extend
# javax.servlet.http.HttpServlet, but implements javax.servlet.Servlet
class MyServlet
include Java::JavaxServlet::Servlet
# @param [javax.servlet.ServletConfig] servletConfig
def init(servletConfig)
end
def destroy
# Runs maven if we are a JRuby process. Currently not used.
#
# See http://watchitlater.com/blog/2011/08/jruby-rake-and-maven/
def mvn(*args)
mvn = catch(:mvn) do
ENV['PATH'].split(::File::PATH_SEPARATOR).each do |path|
Dir.glob(::File.join(path, 'mvn')).each do |file|
if ::File.executable?(file)
throw :mvn, if ::File.symlink?(file)
::File.readlink(file)
@pmahoney
pmahoney / bundle_exec.sh
Created September 5, 2012 21:20
Like bundle exec, but exec's in shell to avoid child process in JRuby 1.6
#!/bin/sh
#
# bundle_exec.sh - emulate 'bundle exec' but with a shell script
# rather than a ruby script. Modifies the environment just like
# bundle exec would.
#
# Running "bundle exec ruby" starts a ruby in which then execs the
# command, 'ruby'. In JRuby 1.6, the command is started in a child
# process. When using a Foreman-like tool that has the ability to
# kill and/or restart such a command, only the parent will be killed
@pmahoney
pmahoney / Gemfile.lock
Created September 13, 2012 13:57
Eventual Gemfile.lock
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
activerecord (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
arel (~> 3.0.2)
@pmahoney
pmahoney / results
Created September 13, 2012 15:50
Crummy kind_of? or respond_to? benchmark under JRuby
require 'java'
require 'benchmark'
s = Java::JavaLang::String.new('hello')
n = 10000000
respond_task = proc { n.times { s.respond_to?(:to_s) || abort('error') } }
no_respond_task = proc { n.times { s.respond_to?(:no_method) && abort('error') } }
kind_of_task = proc { n.times { s.kind_of?(Java::JavaLang::String) || abort('error') } }
no_kind_of_task = proc { n.times { s.kind_of?(Java::JavaLang::Integer) && abort('error') } }
@pmahoney
pmahoney / Time.java
Created October 18, 2012 17:29
RubyTime opPlusNanos maybe
public class Time {
private final long timeInMillis;
private final long nsec;
public Time(long timeInMillis, long nsec) {
this.timeInMillis = timeInMillis;
this.nsec = nsec;
}
this SunJCE_y (id=144)
arg0 true
arg1 "DESede/CBC/PKCS5Padding" (id=249)
arg2 (id=254)
@pmahoney
pmahoney / comments
Created November 1, 2012 21:30
JRuby $LOAD_PATH index speeds up Bundler.require in a Rails app (at top of application.rb)
Rails 3.1.8 app in Ruby 1.8 compatibility mode with ~65 dependencies
(not sure how many in total including
transient deps) was timed up to the Bundler.require line in config/application.rb
(JRuby 1.7.0)
Before: 18.8 seconds
After: 15.9 seconds
This likely seriously breaks the semantics of 'require', and maybe isn't faster
enough to be worth it.