Skip to content

Instantly share code, notes, and snippets.

@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 / 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
# 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 / 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
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/ruby</directory>
</resource>
</resources>
...
@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'
@pmahoney
pmahoney / gist:1970815
Created March 4, 2012 05:28
Jenkins and Java fork()+exec() out of memory

Orien is correct, it is the fork() system call triggered by ProcessBuilder or Runtime.exec or other means of the JVM executing an external process (e.g. another JVM running ant, a git command, etc.).

There have been some posts on the Jenkins mailing lists about this: Cannot run program "git" ... error=12, Cannot allocate memory

There is a nice description of the issue on the SCons dev list: fork()+exec() vs posix_spawn()

There is a long standing JVM bug report with solutions: Use posix_spawn, not fork, on S10 to avoid swap exhaustion. But I'm not sure if this actually made it into JDK7 as the comments suggest was the plan.

In summary, on Unix-like systems, when one process (e.g. the JVM) needs to launch another process (e.g. git) a system call is made to