Skip to content

Instantly share code, notes, and snippets.

@trivett
trivett / numberwang.rb
Created February 27, 2014 16:09
this is numberwang!
# http://www.youtube.com/watch?v=qjOZtWZ56lc
class Numeric
def is_numberwang?
rand(5) == 0
end
end
i = 0
def play(i)
while i < 2
@ddollar
ddollar / hax.rb
Created October 26, 2009 19:50 — forked from wycats/hax.rb
Bundler Preinitializer
require "#{File.dirname(__FILE__)}/../vendor/bundler_gems/environment"
class Rails::Boot
def run
load_initializer
extend_environment
Rails::Initializer.run(:set_load_path)
end
def extend_environment
#include <ruby.h>
extern VALUE rb_cISeq;
extern VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
static VALUE
iseq_s_load(int argc, VALUE *argv, VALUE self)
{
VALUE data, opt=Qnil;
rb_scan_args(argc, argv, "11", &data, &opt);
@scttnlsn
scttnlsn / README.md
Created September 1, 2011 00:25
Minimalist append-only key/value store written in Ruby.

A minimalist append-only key/value store written in Ruby.

Ruby API

c = Collection.new('example.db')

c.set('hello', 'world')
c.get('hello') # =&gt; "world"
@betawaffle
betawaffle / pry-bench.rb
Created October 25, 2011 00:56
Pry Helpers
Pry.config.should_load_plugins = false
Pry.config.editor = proc { |file, line| "subl -w #{file}:#{line}" }
Pry.prompt = [
proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " },
proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }
]
Pry.plugins['doc'].activate!
class BasicObject
@igrigorik
igrigorik / ab.txt
Created November 17, 2011 06:14
jruby + goliath
# after warming up the VM (20k reqs+)
# ...
ab -c 50 -n 5000 http://127.0.0.1:9000/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 500 requests
@ariejan
ariejan / seed_file.rb
Created March 13, 2012 12:31 — forked from eventualbuddha/seed_file.rb
SeedFile, a helper for doing database setup in a Rails 3 app
# Helper class for importing files with records to the database.
class SeedFile
def self.import(path)
new(path).import
end
attr_reader :path
def initialize(path)
@path = Pathname(path)
module ::RubyVM::Helpers
class << self
def compile_option name
line = __LINE__ + 2
code = <<-RUBY
def #{name}
::RubyVM::InstructionSequence.compile_option[:#{name}]
end
def #{name}= bool
@wnuqui
wnuqui / gist:4653064
Last active December 11, 2015 20:09
3 bare bone rails applications using 3 jruby application servers (all running in heroku cedar)
# JAVA_OPTS and Procfiles
JAVA_OPTS: -Djruby.memory.max=384m -Xmx384m -Xms256m -Xss512k -XX:+UseCompressedOops -XX:+PrintGCDetails
# puma backed app's Procfile
web: bundle exec rails server puma -p $PORT -e $RACK_ENV
# torquebox-lite backed app's Procfile
web: bin/torquebox-lite -b 0.0.0.0 -p $PORT --max-threads=8
#!/usr/bin/env ruby
# Copyright (c) 2011 Henrik Hodne
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the