Skip to content

Instantly share code, notes, and snippets.

@sdhull
sdhull / rails_routing_invalid_chars_fix.rb
Last active August 29, 2015 13:56 — forked from bensomers/rails_routing_invalid_chars_fix.rb
fix for invalid encodings that are extended ascii / windows 1252
# Fix for a Rails - Ruby 1.9 bug
# Rails Router, now that it's UTF-8 default, blows up when routing requests
# with invalid chars in the URL; it should properly return a 400 error
# Have to monkey-patch the fix in, since it's not scheduled for release until
# Rails 4.0.
# Adapted Andrew White (pixeltrix)'s fix at
# https://github.com/rails/rails/commit/3fc561a1f71edf1c2bae695cafa03909d24a5ca3,
# but edited to work in 3.0.x.
# 3.1.x, 3.2.x compatibility unknown
require 'action_dispatch/routing/route_set'
@reidmorrison
reidmorrison / redis_connection_pool.rb
Last active August 29, 2015 14:01
Implement a connection pool for Redis
# Implement a Redis Connection Pool
#
# Convenience methods
# Instead of having to write:
# redis_pool.perform {|redis| redis.get('key')}
# The following can be used
# redis_pool.get('key')
#
# This applies to all Redis methods except quit. RedisPool#quit calls quit
# on all instances of Redis already in the pool
@ktheory
ktheory / LICENSE
Last active August 29, 2015 14:06
Redis indicators
Copyright 2014 Kickstarter, Inc.
Released under an MIT License.
source "https://supermarket.getchef.com"
cookbook "apt"
cookbook "chef_handler"
cookbook "yum"
cookbook "simulator", git: "git@github.com:riotgameseurope/simulator.git"
@EmmanuelOga
EmmanuelOga / r191.txt
Created December 26, 2009 22:42
curb, typhoeus, net:http, em-http quick benchmark
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
curb (0.6.2.1)
em-http-request (0.2.5)
eventmachine (0.12.10)
typhoeus (0.1.13)
user system total real Memory (Kb)
4kb std
0.000000 0.000000 3.010000 ( 22.408594) 24,484
anonymous
anonymous / Rails JSON Sessions
Created March 9, 2011 22:11
Rails 2.3 session patched to use JSON
# Typically this would go in a file in /config/initializers. Note you'll also need
# the json gem (ideally native) and then specify this in your environment:
# ActiveSupport::JSON.backend = 'JSONGem'
# A bit of Rails magic to change the way the session is "marshalled". Essentially
# this bit of monkeypatching makes the MemCacheStore use JSON instead of the
# default Ruby marshalling in order to share data seamlessly with the node.js
# portion of the app.
# TODO: combine with a persistent store or convert to redis to better preserve
# sessions for lurkers
@karmi
karmi / ngrams-and-tire.rb
Created August 21, 2011 10:17
An example of using ngram analysis in ElasticSearch with the Tire rubygem
# An example of using ngram analysis in ElasticSearch with the Tire rubygem
# ==========================================================================
# The original, raw example: https://gist.github.com/988923
require 'rubygems'
require 'tire'
require 'yajl/json_gem'
class URL
def initialize(attributes={})
@dpickett
dpickett / devise_mailer.rb
Created October 8, 2011 19:25
devise hack with resque mailer
##HACK - dmp - we must return an unserialized version of resource
##so copy devise's method and use a finder for resource
require "devise"
require Rails.root.join("lib/resque/mailer")
Devise::Mailers::Helpers.send(:alias_method, :old_initialize_from_record, :initialize_from_record)
module Devise
module Mailers
module Helpers
@dvgica
dvgica / am_pm_time_select.rb
Created November 4, 2011 18:41
Initializer to add am/pm support to time_select helpers in Rails 3 (3.1 has an option, use it!)
# modified from Bruno Miranda's original found here: http://brunomiranda.com/past/2007/6/2/displaying_12_hour_style_time_select/
# usage: <%= form.time_select :the_time, { :twelve_hour => true } %>
module ActionView
module Helpers
class DateTimeSelector
def select_hour_with_twelve_hour_time
datetime = @datetime
options = @options
@headius
headius / gist:1408381
Created November 30, 2011 07:54
JRuby Fiber perf compared to 1.9.3
# Ruby 1.9.3
ruby-1.9.3-p0 ~/projects/jruby $ ruby -v bench/bench_fiber_ring.rb 5 100 1000
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
bench/bench_fiber_ring.rb:23: warning: mismatched indentations at 'end' with 'def' at 21
100 fibers / 1000 passes: 0.150000 0.000000 0.150000 ( 0.155022)
100 fibers / 1000 passes: 0.150000 0.000000 0.150000 ( 0.153985)
100 fibers / 1000 passes: 0.150000 0.000000 0.150000 ( 0.153822)
100 fibers / 1000 passes: 0.150000 0.000000 0.150000 ( 0.152370)
100 fibers / 1000 passes: 0.160000 0.000000 0.160000 ( 0.155857)