Skip to content

Instantly share code, notes, and snippets.

View hakanensari's full-sized avatar

Hakan Ensari hakanensari

  • Amsterdam
  • 23:26 (UTC +02:00)
View GitHub Profile
@dimus
dimus / Hash.from_xml using Nokogiri
Created March 17, 2010 14:29
Adding Hash.from_xml method using Nokogiri
# 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
@hakanensari
hakanensari / multi.rb
Created January 28, 2011 12:50
Attach Net:HTTP requests to multiple local IPs
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
@ezkl
ezkl / benchpress.md
Created February 7, 2011 02:29
Nokogiri HTML Parsers - BenchPress Results

Nokogiri Parser Comparisons

Author: Ezekiel Templin
Date: February 06, 2011
Summary: Comparing Nokogiri's parsers

System Information

Operating System:    Mac OS X 10.6.6 (10J567)

CPU: Intel Core i7 2.66 GHz

@dira
dira / application.rb
Created February 10, 2011 02:28
A Rake middleware to specify to OmniAuth where to redirect after successful authentication
# config/application.rb
config.middleware.use 'StoreRedirectTo'
# and make sure you autoload the contents of /lib
@scottjehl
scottjehl / hideaddrbar.js
Created August 31, 2011 11:42
Normalized hide address bar for iOS & Android
/*
* 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 ){
@tshinnic
tshinnic / httpclnt03.js
Created December 1, 2011 00:40
Example of binding socket for nodejs HTTP client request (for discussion only)
// 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');
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

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.

@turtlebender
turtlebender / logstash-collector.upstart
Created February 13, 2012 13:45
Logstash upstart files
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
@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active December 10, 2022 13:34
How to write MiniTest::Spec expectations

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").

Understanding MiniTest::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