Author: Ezekiel Templin
Date: February 06, 2011
Summary: Comparing Nokogiri's parsers
Operating System: Mac OS X 10.6.6 (10J567)
CPU: Intel Core i7 2.66 GHz
# USAGE: Hash.from_xml:(YOUR_XML_STRING) | |
require 'nokogiri' | |
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297 | |
class Hash | |
class << self | |
def from_xml(xml_io) | |
begin | |
result = Nokogiri::XML(xml_io) | |
return { result.root.name.to_sym => xml_node_to_hash(result.root)} |
# Author: Pieter Noordhuis | |
# Description: Simple demo to showcase Redis PubSub with EventMachine | |
# | |
# Update 7 Oct 2010: | |
# - This example does *not* appear to work with Chrome >=6.0. Apparently, | |
# the WebSocket protocol implementation in the cramp gem does not work | |
# well with Chrome's (newer) WebSocket implementation. | |
# | |
# Requirements: | |
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby |
require 'net/http' | |
ips = `ifconfig | awk '/inet addr:[0-9]/{print $2;}' | grep -oE '([0-9.]{7,})'`. | |
split("\n"). | |
select { |ip| ip.match(/\./) && !ip.match(/^127/) } | |
def attach_to(ip) | |
TCPSocket.instance_eval do | |
(class << self; self; end).instance_eval do | |
alias_method :original_open, :open |
# config/application.rb | |
config.middleware.use 'StoreRedirectTo' | |
# and make sure you autoload the contents of /lib | |
/* | |
* Normalized hide address bar for iOS & Android | |
* (c) Scott Jehl, scottjehl.com | |
* MIT License | |
*/ | |
(function( win ){ | |
var doc = win.document; | |
// If there's a hash, or addEventListener is undefined, stop here | |
if( !location.hash && win.addEventListener ){ |
// One shot request HTTP client - show local/remote addresses | |
// | |
// Attempt to use a modified Agent that has own self.createConnection() | |
// that binds the client socket to a particular address. | |
var assert = require('assert'), | |
dns = require('dns'), | |
http = require('http'), | |
net = require('net'), | |
util = require('util'); |
This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.
You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf
using homebrew.
description "logstash collector server" | |
start on runlevel [2345] | |
stop on runlevel [06] | |
# tell upstart we're creating a daemon | |
# upstart manages PID creation for you. | |
expect fork | |
script |
I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").
Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):
# minitest/spec.rb
module MiniTest::Expectations