Skip to content

Instantly share code, notes, and snippets.

keithrbennett / locale_displayer.rb
Last active Dec 14, 2015
Example JRuby program to display the JVM's available locales and their number, currency, and date formats. Change the format constants to see more kinds of formatting (e.g. DateFormat::LONG/SHORT). - Keith R. Bennett, @keithrbennett
View locale_displayer.rb
# Example JRuby program to display the JVM's available locales
# and their number, currency, and date formats.
# Keith R. Bennett, @keithrbennett
require 'java'
java_import 'java.util.Locale'
java_import 'java.text.DateFormat'
java_import 'java.text.NumberFormat'
bensie / base.rb
Created Dec 6, 2012
Sinatra API Helpers
View base.rb
require "sinatra/base"
require "sinatra/namespace"
require "multi_json"
require "api/authentication"
require "api/error_handling"
require "api/pagination"
module Api
class Base < ::Sinatra::Base
headius / gist:3776559
Created Sep 24, 2012
Open a dir as a file on JRuby on Java 7+
View gist:3776559
require 'java'
java_import java.nio.channels.FileChannel
java_import java.nio.file.StandardOpenOption
java_import java.nio.file.FileSystems
path = FileSystems.default.get_path('/')
option = StandardOpenOption::READ
ch =, option)
trcarden / gist:3295935
Created Aug 8, 2012
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
View gist:3295935
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
rapimo / gist:3250341
Created Aug 3, 2012
count occurrences of array values in postgres using hstore
View gist:3250341
SELECT hstore(array_agg(v), array_agg(c::text)) FROM (
SELECT v, COUNT(*) as c ,1 as agg from unnest(ARRAY['foo','bar','baz','foo']) v GROUP BY v) t
--> "bar"=>"1", "baz"=>"1", "foo"=>"2"
bbonamin / drag_drop.rb
Created Jul 17, 2012
Capybara drag and drop
View drag_drop.rb
shared_examples_for "driver with javascript support" do
before { @driver.visit('/with_js') }
describe '#find' do
it "should find dynamically changed nodes" do
@driver.find('//p').first.text.should == 'I changed it'
describe '#drag_to' do
peterhellberg / Gemfile
Created Apr 10, 2012
Sinatra acceptance testing, using minitest/spec and capybara-webkit
View Gemfile
source :rubygems
gem "sinatra", "~> 1.3.2"
group :test do
gem "minitest", "~> 2.10"
gem "rack-test", "~> 0.6.1"
gem "capybara", "~> 1.1"
gem "capybara-webkit", "~> 0.11"
gem "capybara_minitest_spec", "~> 0.2"
peterhellberg / multi_value.rb
Created Mar 18, 2012
Support for multiple return values in Ruby 1.9, the way Common Lisp does it… sort of
View multi_value.rb
class MultiValue < BasicObject
attr_reader :secondary
def initialize(obj, *secondary)
@obj, @secondary = obj, secondary
def method_missing(sym, *args, &block)
@obj.__send__(sym, *args, &block)
coreyhaines / .rspec
Last active Aug 23, 2021
Active Record Spec Helper - Loading just active record
View .rspec
-I app
View watchable.rb
module Watchable
def events
@events ||= { |h,k| h[k] = [] }
def fire event, *args
events[event].each { |e| e[*args] }
def on event, &block