Skip to content

Instantly share code, notes, and snippets.

require 'benchmark'
begin
require 'active_support/values/time_zone'
rescue LoadError
puts 'Please do `gem install active_support`'
exit(1)
end
def benchmark_hash(hash, key, inverted_hash)
Benchmark.bmbm do |x|
@aminin
aminin / example.rb
Created July 25, 2013 13:02
Multithread amazon s3 bucket copier + EventMachine patch for Fog::Connection
require './s3-bucket-copier'
credentials = {
:provider => "AWS",
:region => "eu-west-1",
:aws_access_key_id => "<KeyId>",
:aws_secret_access_key => "<KeySecret>"
}
connection = ::Fog::Storage.new(credentials)
@naholyr
naholyr / _service.md
Created December 13, 2012 09:39
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@funny-falcon
funny-falcon / changes.md
Last active March 23, 2024 05:53
Performace patch for ruby-1.9.3-p327

Changes:

  • this version includes backport of Greg Price's patch for speedup startup http://bugs.ruby-lang.org/issues/7158 .

    ruby-core prefers his way to do thing, so that I abandon cached-lp and sorted-lf patches of mine.

  • this version integrates 'array as queue' patch, which improves performance when push/shift pattern is heavily used on Array.

    This patch is accepted into trunk for Ruby 2.0 and last possible bug is found by Yui Naruse. It is used in production* for a couple of months without issues even with this bug.

@maccman
maccman / juggernaut.rb
Created June 26, 2012 02:49
Sinatra Server Side Event streaming.
# Usage: redis-cli publish message hello
require 'sinatra'
require 'redis'
conns = []
get '/' do
erb :index
end
@liamcurry
liamcurry / gist:2597326
Created May 4, 2012 19:56
Vanilla JS vs jQuery

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@asavartsov
asavartsov / sweeping.rb
Created March 17, 2012 10:52
Cache Sweeper for Mongoid
# 2. Include Sweeping module in your controller(s) to have cache_sweeper
# method to be avaliable, or right in ApplicationController so it will be
# available in all controllers inheriting from it.
class ApplicationController < ActionController::Base
include ActionController::Caching::Sweeping
# ...
end
@gmanley
gmanley / imgur_dl.rb
Created February 19, 2012 23:09
Concurrent imgur album downloader using typhoeus.
# encoding: UTF-8
# requires ruby 1.9.3 and up
# gem install nokogiri typhoeus
require 'nokogiri'
require 'typhoeus'
module Imgur
class AlbumDownloader
@stephank
stephank / README.md
Created January 18, 2012 15:49
PulseAudio homebrew formula
@kyledrake
kyledrake / gist:1498932
Last active August 2, 2016 04:31
Neocities' Rainbows! config file - https://neocities.org
# This is Neocities' Rainbows! config file. We are using this in production to run all our web apps.
# It works really well for us and has been heavily load tested, so I wanted to share it with the community.
#
# In my opinion, this is the best way to deploy a ruby web application. Unlike EventMachine based solutions,
# it uses real ruby threads, which allows it to take advantage of the internal non-blocking IO pattern
# in MRI.
#
# Contrary to popular belief, MRI doesn't block execution to wait on IO when you are using threads, even
# with the GIL. The requests are done concurrently for anything that is based on the IO class. This
# includes things like Net::HTTP and even `system commands`. Grep the MRI Ruby source code for