Skip to content

Instantly share code, notes, and snippets.

$ phantomjs test.js
error: ReferenceError: Can't find variable: foo
finished
error: ReferenceError: Can't find variable: asdasd
# Example code provided for https://github.com/librato/librato-metrics/issues/14
#
# We configured it like so:
#
# Loco2::Metrics.queue_constructor = Librato::Metrics::Queue.method(:new)
# Loco2::Metrics.logger = Rails.logger
# Loco2::Metrics.exception_handler = Airbrake.method(:notify)
require 'thread'
require 'timeout'
@jonleighton
jonleighton / country_codes.csv
Created May 29, 2012 10:27
Scrape ISO 3166-1 country names and codes from Wikipedia
AF Afghanistan
AX Åland Islands
AL Albania
DZ Algeria
AS American Samoa
AD Andorra
AO Angola
AI Anguilla
AQ Antarctica
AG Antigua and Barbuda
$ rvm jruby
$ cat ext/faye_websocket_mask/extconf.rb
unless defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
require 'mkmf'
extension_name = 'faye_websocket_mask'
dir_config(extension_name)
create_makefile(extension_name)
end
$ gem build faye-websocket.gemspec
# People were asking what I meant by "single class per action". Here's an
# example.
#
# I've not tried this out at all, or tried to implement it or use it. I
# might be wrong. It's just an idea. Please don't hate on me :)
#
# Why do I wish for something like this? I can imagine being able to unit
# test it without all the ceremony we have to perform currently. Also, I
# feel that it adheres better to the single responsibility principle, and
# potentially allows more flexibility for code re-use.
$ ruby test_foo.rb
Run options:
# Running tests:
#<Method: FooTest(MiniTest::Assertions)#skip>
S
Finished tests in 0.000864s, 1157.4516 tests/s, 0.0000 assertions/s.
require 'benchmark'
class Foo1
def foo
"bar"
end
end
class Foo2
module Other
def test_defining_attribute_methods_is_threadsafe
klass = Class.new(ActiveRecord::Base)
klass.table_name = "posts"
100.times.map { |i|
Thread.new { klass.define_attribute_methods }
}.join
end
# No EM loop
# Send message on web socket and block waiting for next message from client
result = client.send('{"action":"visible", id: 23}')
# Handle the response
do_something(result)
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
ActiveRecord::Schema.define do
create_table :posts, :id => false do |t|
t.integer :foo
end
end