Skip to content

Instantly share code, notes, and snippets.

View nicksieger's full-sized avatar

Nick Sieger nicksieger

View GitHub Profile
# Monkeypatch to disable connection pooling in ActiveRecord
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
def checkout
c = ActiveRecord::Base.send(spec.adapter_method, spec.config.dup)
c.verify!
c
end

Synchronizing a Pool of Resources

Here are several approaches for synchronization around a pool of limited resources that are checked in and out by a gang of threads.

Pools

There are three different pools: MonitorPool which uses monitor.rb, MutexCondvarPool which uses a Mutex and a ConditionVariable, and SemaphorePool which uses a java.util.concurrent.Semaphore (only under JRuby).

Request

@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@nahi
nahi / gist:1029091
Created June 16, 2011 11:57
AES-256-CBC encryption/decryption w/o using JCE on JRuby
# Java's JCE requires extra JVM config download named Jurisdiction Policy Files where AES keysize > 128bit.
# You can do encrypt/decrypt using BouncyCastle via JRuby's Java integration like this.
# Use this at your own risk.
require 'java'
require 'openssl'
java_import 'org.bouncycastle.crypto.BlockCipher'
java_import 'org.bouncycastle.crypto.engines.AESLightEngine'
java_import 'org.bouncycastle.crypto.modes.CBCBlockCipher'
@nicksieger
nicksieger / Gemfile
Created July 26, 2011 16:06 — forked from copiousfreetime/my-gh-issues.rb
My Github Issues
source :rubygems
gem 'octokit'
gem 'awesome_print'
gem 'rainbow'
gem 'jruby-openssl'
@nicksieger
nicksieger / Gemfile.patch
Created September 12, 2011 18:30
Patch Rails Gemfile for local or git-based AR-JDBC development
diff --git a/Gemfile b/Gemfile
index 54e171b..e9e531b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -68,17 +68,21 @@ end
platforms :jruby do
gem "ruby-debug", ">= 0.10.3"
gem "json"
- gem "activerecord-jdbcsqlite3-adapter"
+
@nicksieger
nicksieger / Send to Evernote.scpt
Created January 1, 2012 23:48 — forked from turadg/Send Chrome to OmniFocus.scpt
OmniFocus integrations
-- from http://veritrope.com/code/copy-omnifocus-item-uri-to-evernote/
tell front window of application "OmniFocus"
try
set theTrees to selected trees of content
if (count of theTrees) < 1 then
set theTrees to selected trees of sidebar
end if
if (count of theTrees) < 1 then
@mperham
mperham / convert.rake
Created March 15, 2012 17:44
Ruby script to update MySQL from Latin1 to UTF8 without data conversion
desc "convert a latin1 database with utf8 data into proper utf8"
task :convert_to_utf8 => :environment do
puts Time.now
dryrun = ENV['DOIT'] != '1'
conn = ActiveRecord::Base.connection
if dryrun
def conn.run_sql(sql)
puts(sql)
end
else
@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
@bokmann
bokmann / JRuby Awesome Performance
Last active August 31, 2023 07:32
brief summary of massive performance improvements with JRuby
# Thee will be more information here when I share the entire problem space I'm working on, but
# in short, this is preview material for my second talk in a series called "What Computer Scientists Know".
# The first talk is on recursion, and goes through several examples., leading up to a problem based
# on a simple puzzle that initial estimates based on performance of a previous puzzle would take years
# to solve on modern computers with the techniques shown in Ruby. That sets the stage for improving the
# performance of that problem with threading, concurrency, and related tuning.
#
# The second talk is on threading and concurrency, touching on algorithmic performance as well.
# Using some knowledge of the problem (board symmetry, illegal moves, etc), we reduce the problem space
# to about .5% of what we initially thought it was. Still, the initial single threaded solution took more