Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
keithrbennett / locale_displayer.rb
Last active December 14, 2015 04:09
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
# 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
bensie / base.rb
Created December 6, 2012 17:53
Sinatra API Helpers
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
headius / gist:3776559
Created September 24, 2012 15:34
Open a dir as a file on JRuby on Java 7+
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 = FileChannel.open(path, option)
@trcarden
trcarden / gist:3295935
Created August 8, 2012 15:28
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
# 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
rapimo / gist:3250341
Created August 3, 2012 18:44
count occurrences of array values in postgres using hstore
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
GROUP BY agg
--> "bar"=>"1", "baz"=>"1", "foo"=>"2"
@bbonamin
bbonamin / drag_drop.rb
Created July 17, 2012 14:18
Capybara drag and drop
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'
end
end
describe '#drag_to' do
@peterhellberg
peterhellberg / Gemfile
Created April 10, 2012 11:51
Sinatra acceptance testing, using minitest/spec and capybara-webkit
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
peterhellberg / multi_value.rb
Created March 18, 2012 20:30
Support for multiple return values in Ruby 1.9, the way Common Lisp does it… sort of
class MultiValue < BasicObject
attr_reader :secondary
def initialize(obj, *secondary)
@obj, @secondary = obj, secondary
end
def method_missing(sym, *args, &block)
@obj.__send__(sym, *args, &block)
end
@coreyhaines
coreyhaines / .rspec
Last active April 11, 2024 00:19
Active Record Spec Helper - Loading just active record
--colour
-I app
module Watchable
def events
@events ||= Hash.new { |h,k| h[k] = [] }
end
def fire event, *args
events[event].each { |e| e[*args] }
end
def on event, &block