Skip to content

Instantly share code, notes, and snippets.

View rjungemann's full-sized avatar

Roger Jungemann rjungemann

View GitHub Profile
###
# This is a demonstration of using SQLite3's Virtual File System API in Ruby.
#
# == Synopsis
#
# This program will store its SQLite database after the __END__ line.
#
# === In Detail
#
# SQLite3 uses the DATABase class as a proxy for our IO object. Upon
@tobym
tobym / redis_pubsub_demo.rb
Created April 1, 2010 16:50 — forked from pietern/redis_pubsub_demo.rb
Redis PubSub demo with EventMachine (chat service)
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
# - a browser with WebSocket support
#
# Usage:
# ruby redis_pubsub_demo.rb
#
@tbtlr
tbtlr / def.js
Created July 13, 2010 23:32
Simple Ruby-style inheritance for JavaScript
/*
* def.js: Simple Ruby-style inheritance for JavaScript
*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*
*
* Example:
*
* def ("Person") ({
@tokland
tokland / external-command.rb
Created August 18, 2010 18:01 — forked from careo/external-command.rb
Capture stderr data on EventMachine.popen
require 'rubygems'
require 'eventmachine'
$stdout.sync = true
$stderr.sync = true
EM.run {
EM.add_periodic_timer(0.1) {
$stdout.write "stdout\n"
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@rjungemann
rjungemann / birds.js
Created October 11, 2010 08:25
A JS port of the Ruby-version of the To Mock a Mockingbird birds
/*
Inspired by http://github.com/iande/code_bucket/raw/d6a29da107e7347612aa24803e4ee32cd4395220/birds/combinators.rb
*/
var birds = {
"blue": function(x, y, z) { return x(y(z)); },
"cardinal": function(x, y, z) { return x(y)(z); },
"dove": function(x, y, z, w) { return x(y)(z(w)); },
"eagle": function(x, y, z, w, v) { return x(y)(z(w)(v)); },
"finch": function(x, y, z) { return z(y)(x); },
@ecavazos
ecavazos / nusinapp.rb
Created October 20, 2010 05:38
A quick and dirty script to quickly bootstrap a sinatra app.
#!/usr/bin/env ruby
name = ARGV[0]
raise ArgumentError, "You must provide a project name" if name.nil?
def run(cmd)
`#{cmd}`
end
@ry
ry / https-hello-world.js
Created January 4, 2011 00:03
new node https api
// curl -k https://localhost:8000/
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
https.createServer(options, function (req, res) {
@pfleidi
pfleidi / fiberchat.rb
Created February 19, 2011 18:51
A naive socket chat using select() and ruby fibers
require 'rubygems'
require 'socket'
include Socket::Constants
class ChatServer
def initialize
@reading = Array.new
@writing = Array.new
@clients = Hash.new
@adamgoucher
adamgoucher / loggingdocumentationformatter.txt
Created February 24, 2011 04:46
how to hack in log messages to rspec 2
When doing automation I coach people not to put in logging in their scripts aside from things like 'here is the user name and password I randomly created just now' but I couldn't coax the default documentation formatter in rspec to capture information send via 'puts'. So I over-engineered a solution. Proper documentation and inclusion in my rspec-selenium-pageobjects project in a day or so.
spec_helper.rb
--------------
module RSpec
module Core
class Reporter
def with(message)
notify :with, message
end