Skip to content

Instantly share code, notes, and snippets.

View nicksieger's full-sized avatar

Nick Sieger nicksieger

View GitHub Profile
@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 / 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
@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 / 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'
@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'
@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)

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

# 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