Skip to content

Instantly share code, notes, and snippets.

View shingonoide's full-sized avatar

Rui Andrada shingonoide

View GitHub Profile
##
# Calendar helper with proper events
# http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/
#
# (C) 2009 James S Urquhart (jamesu at gmail dot com)
# Derived from calendar_helper
# (C) Jeremy Voorhis, Geoffrey Grosenbach, Jarkko Laine, Tom Armitage, Bryan Larsen
# Licensed under MIT. http://www.opensource.org/licenses/mit-license.php
##
require 'nokogiri'
# Usage:
#
# use Rack::Injector do |inject|
# inject.before 'h1', '<div class="injected">This was injected before</div>'
# inject.after 'h1', '<div class="injected">This was injected after</div>'
# end
class Rack::Injector
def initialize(app)
module Rack
# A rack middleware for validating HTML via w3c validator
class Validate
def initialize( app )
@app = app
end
def call( env )
module Rack
class AllYourBase
def initialize(app, options = {})
@app = app
@options = options
end
def call(env)
@request = Rack::Request.new(env)
@rwoeber
rwoeber / rot13.rb
Created January 11, 2010 10:09
Ruby rot13
# or simply:
'foobar'.tr 'A-Za-z','N-ZA-Mn-za-m'
# rot(x)
class String
def rot(num = 13)
return self.split("").collect { |ch|
if /^[a-z]$/ === ch
((ch[0] + num - 'a'[0]) % 26 + 'a'[0]).chr
@mxcl
mxcl / install_homebrew.markdown
Created March 6, 2010 15:14
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
# 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
#!/usr/bin/env ruby
require 'webrick'
include WEBrick
s = HTTPServer.new(
:Port => ARGV[0] || 8000,
:DocumentRoot => Dir::pwd
)
## mount subdirectories
#!/usr/bin/env ruby
# Aside from removing Ruby on Rails specific code this is taken verbatim from
# mislav's git-deploy (http://github.com/mislav/git-deploy) and it's awesome
# - Ryan Florence (http://ryanflorence.com)
#
# Install this hook to a remote repository with a working tree, when you push
# to it, this hook will reset the head so the files are updated
if ENV['GIT_DIR'] == '.'
module Sinatra
class Base
def call!(env)
@env = env
@request = Request.new(env)
@response = Response.new
@params = indifferent_params(@request.params)
force_encoding(@params)