This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/dns/resolver' | |
# Custom Domain | |
# | |
# Require net-dns gem | |
# | |
# A Rack middleware to to resolve the custom domain to original subdomain | |
# for your multi telent application. | |
# | |
# It's all transperant to your application, it performs cname lookup and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-- | |
# Copyright (c) 2009 Szymon Kurcab szymon.kurcab@gmail.com> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the | |
# "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, | |
# distribute, sublicense, and/or sell copies of the Software, and to | |
# permit persons to whom the Software is furnished to do so, subject to | |
# the following conditions: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rack::Middleware that returns the number of models in the database for any call to a URL like modelname/count. | |
# | |
# Examples: | |
# /users/count | |
# => returns User.count in plain text | |
# | |
# /articles/1/comments/count.xml | |
# => returns Comment.count as XML, e.g. | |
# <comments type="integer">5</comments> | |
# Note: this does not return Articles.find(1).comments.count like it maybe should! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Full code is at http://github.com/cwninja/rack-cache-buster | |
require 'digest/md5' | |
module Rack | |
class CacheBuster | |
def initialize(app, key, target_time = nil) | |
@app, @target_time = app, target_time | |
@key = "-"+Digest::MD5.hexdigest(key || "blank-key").freeze | |
@key_regexp = /#{@key}/.freeze |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'open-uri' | |
gem 'maca-fork-csspool' | |
require 'csspool' | |
module InlineStyle | |
module Rack | |
class Middleware | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'RMagick' | |
class WatermarkMe | |
def initialize(app, args) | |
@app = app | |
@watermark_text, @mime_types = *args | |
@mime_types ||= %w[image/jpeg image/png image/gif] | |
end | |
def call(env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rack | |
class Censor | |
WORDS = [ 'shit', 'fuck', 'cock', 'cunt', 'cameltoe', 'mooseknuckle' ].map { |w| Regexp.new(w, Regexp::IGNORECASE) }.freeze | |
attr_reader :options, :request | |
def initialize(app, options={}) | |
@app, @options = app, { | |
:replacement => '*****' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'geoip' | |
module Rack | |
# Rack::GeoIPCountry uses the geoip gem and the GeoIP database to lookup the country of a request by its IP address | |
# The database can be downloaded from: | |
# http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz | |
# | |
# Usage: | |
# use Rack::GeoIPCountry, :db => "path/to/GeoIP.dat" | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is actually available as a gem: gem install rack-rewrite | |
# Full source code including tests is on github: http://github.com/jtrupiano/rack-rewrite | |
module Rack | |
# A rack middleware for defining and applying rewrite rules. In many cases you | |
# can get away with rack-rewrite instead of writing Apache mod_rewrite rules. | |
class Rewrite | |
def initialize(app, &rule_block) | |
@app = app | |
@rule_set = RuleSet.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BruteForceKilla | |
# | |
# A Rack middleware to limit requests by ip address, coded for fun as my first | |
# middleware, thanks http://coderack.org for giving me a reason :) | |
# | |
# For production use, one would want to make a memcache or redis tracker. | |
# | |
# options: | |
# | |
# :tracker => Class name of the tracker to use (default Memory (all there is for now!)) |