Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'rack'
require 'rubygems'
require 'rack'
class Object
def webapp
def call(env)
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
@ingeniarius
ingeniarius / nginx
Created June 13, 2011 14:09
Ubuntu 10.04 nginx init script
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
require 'rubygems'
require 'zmq'
z = ZMQ::Context.new
s = z.socket(ZMQ::UPSTREAM)
s.connect "tcp://127.0.0.1:5555"
while true
puts s.recv
end
@ingeniarius
ingeniarius / file_to_data_uri.rb
Created August 1, 2011 19:11
Convert binary file to data URI base64 encoded
require 'base64'
file = ARGV[0]
mimetype = `file -b --mime-type #{file}`.gsub(/\n/,'')
puts "data:#{mimetype};base64," << Base64.encode64(File.read(file)).gsub(/\n/, '')
@ingeniarius
ingeniarius / load.patch
Created August 9, 2011 14:21 — forked from taf2/load.patch
Ruby 1.9.2-p180 require performance patch
--- a/load.c 2010-10-23 05:36:38.000000000 -0400
+++ b/patchload.c 2011-06-05 08:58:00.000000000 -0400
@@ -40,14 +40,6 @@
VALUE ary;
long i;
- for (i = 0; i < RARRAY_LEN(load_path); ++i) {
- VALUE str = rb_check_string_type(RARRAY_PTR(load_path)[i]);
- if (NIL_P(str) || !rb_is_absolute_path(RSTRING_PTR(str)))
- goto relative_path_found;
@ingeniarius
ingeniarius / installation.sh
Created August 14, 2011 20:08 — forked from mikhailov/installation.sh
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details: http://mikhailov.posterous.com/nginx
$ cd /usr/src
$ wget http://nginx.org/download/nginx-0.8.52.tar.gz
$ tar xzvf ./nginx-0.8.52.tar.gz
$ rm ./nginx-0.8.52.tar.gz
$ gem install s3sync capistrano capistrano-ext passenger --no-ri --no-rdoc
$ passenger-install-nginx-module
# Automatically download and install Nginx? 2. No: I want to customize my Nginx installation
# Where is your Nginx source code located?: /usr/src/nginx-0.8.52
# Where do you want to install Nginx to?: /opt/nginx
@ingeniarius
ingeniarius / american_date_monkey_patch.rb
Created September 9, 2011 11:21 — forked from ptzn/american_date_monkey_patch.rb
Use american date format as default in Ruby 1.9
# Date.parse() with Ruby 1.9 is now defaulting to the European date style where the format is DD/MM/YYYY, not MM/DD/YYYY
# patch it to use US format by default
if RUBY_VERSION >= '1.9'
class String
def to_date
if self.blank?
nil
elsif self =~ /(\d{1,2})\/(\d{1,2})\/(\d{4})/
::Date.civil($3.to_i, $1.to_i, $2.to_i)
else
@ingeniarius
ingeniarius / error output
Created September 25, 2011 07:35
Socket.IO benchmark
/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:610
transport.payload(this.closed[data.id]);
^
TypeError: Object #<WebSocket> has no method 'payload'
at Manager.handleClient (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:610:19)
at Manager.handleUpgrade (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:564:8)
at HTTPServer.<anonymous> (/usr/local/lib/node/.npm/socket.io/0.8.4/package/lib/manager.js:100:10)
at HTTPServer.emit (events.js:81:20)
at Socket.<anonymous> (http.js:1035:14)
at Socket._onReadable (net.js:683:27)
@ingeniarius
ingeniarius / rails_guides_to_epub.rb
Created October 26, 2011 15:41 — forked from spap/rails_guides_to_epub.rb
Ruby on Rails Guides ePub convert ruby script
require 'rubygems'
require 'nokogiri'
require 'eeepub'
DOC_TITLE = 'Ruby on Rails Guides'
def get_pages(src_dir)
index_file = File.join(src_dir, 'index.html')
section = nil
pages = [{ :section => section, :title => DOC_TITLE, :path => index_file }]
@ingeniarius
ingeniarius / string_inquirer_patch.rb
Created February 24, 2012 19:56
Creation of inquirer methods on the fly for performance boost
module ActiveSupport
module StringInquirerPatch
def self.included klass
klass.send :remove_method, :method_missing
end
def method_missing method_name, *arguments
if method_name.to_s[-1,1] == "?"
is_eql_to_self = (self == method_name.to_s[0..-2])