This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error = nil | |
# This processes the action in a child thread. It lets us return the | |
# response code and headers back up the rack stack, and still process | |
# the body in parallel with sending data to the client | |
Thread.new { | |
begin | |
super(name) | |
rescue => e | |
if @_response.committed? | |
begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Emulates the SerialPort class that uses a native C extension. | |
class SerialPort < IO | |
load "java/jna.jar" | |
load "java/purejavacomm-0.0.21.jar" | |
java_import 'purejavacomm.CommPortIdentifier' | |
def initialize(port) | |
# do what SerialPort C does on Windows (for compat): 0 -> 'COM1' | |
port = "COM#{port + 1}" if port.is_a?(Integer) && windows? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'jruby/profiler' | |
profile_data = JRuby::Profiler.profile do | |
# code to be profiled.... | |
end | |
# print data in flat format to STDOUT : | |
profile_printer = JRuby::Profiler::FlatProfilePrinter.new(profile_data) | |
profile_printer.printProfile(STDOUT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ruby=1.9.3 | |
# Gemfile header for using JRuby (on Heroku) as well as MRI locally | |
source 'https://rubygems.org' | |
if ENV["JRUBY"] || RUBY_PLATFORM == "java" | |
# https://devcenter.heroku.com/articles/ruby-support#ruby-versions | |
ruby '1.9.3', engine: 'jruby', engine_version: '1.7.10' | |
else | |
ruby '1.9.3' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put this under **#{Rails.root}/config/initializers** directory | |
# `silence` is like Chuck Norris you can't kill it, this biuty got yet again | |
# re-invented in Rails 4 right after Logger#silence got deprecated in 3.2 :) | |
begin | |
require 'active_support/logger' | |
require 'active_support/logger_silence' | |
ActiveSupport::Logger.silencer = false # silence simply yields | |
# if 'active_support/core_ext/logger' is loaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
module ThreadDump | |
def self.thread_dump(output = nil) | |
output ||= '' | |
thread_mbean = java.lang.management.ManagementFactory.getThreadMXBean | |
thread_ids = thread_mbean.getAllThreadIds # long[] | |
threads = thread_mbean.getThreadInfo(thread_ids, false, false) # ThreadInfo[] | |
threads.each do |thread_info| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# require 'active_record/connection_adapters/abstract_adapter' | |
# Adapter (connection) compatibility methods for AR 2.3 as required | |
# by the (AR 3.2) back-ported ConnectionPool implementation. | |
class ActiveRecord::ConnectionAdapters::AbstractAdapter | |
include MonitorMixin | |
# HACK: to initialize the monitor, in 3.2 #initialize calls the | |
# MonitorMixin#initialize by doing super() but in 2.3 it does not | |
# we do about the same here by overriding Adapter#new : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @version 1.20 25 Mar 1998 | |
* @author Cay Horstmann | |
*/ | |
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
class MousePanel extends JPanel implements MouseMotionListener { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Allows for an #override annotation for your methods. | |
# Thus might help you during refactoring (method renaming) to assure methods | |
# expected to call a super will fail early during loading instead of runtime. | |
# | |
# Sample : | |
# | |
# class Message | |
# extend Override | |
# | |
# def do_send; end |