Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
@jodosha
jodosha / waves.txt
Created October 16, 2009 21:28 — forked from mislav/waves.txt
> This is a Shortwave configuration file
> http://shortwaveapp.com/
>
> Some triggers copied from benpickles (http://gist.github.com/43371)
>
> Urls may contain the following replacement tokens:
>
> %s → search terms
> %r → URL of current page
> %d → domain part of the current URL
@jodosha
jodosha / gist:216271
Created October 22, 2009 20:31 — forked from defunkt/gist:6443
# Video: http://rubyhoedown2008.confreaks.com/08-chris-wanstrath-keynote.html
Hi everyone, I'm Chris Wanstrath.
When Jeremy asked me to come talk, I said yes. Hell yes. Immediately. But
then I took a few moments and thought, Wait, why? Why me? What am I supposed
to say that's interesting? Something about Ruby, perhaps. Maybe the
future of it. The future of something, at least. That sounds
keynote-y.
#!/usr/bin/env ruby -w
require "rubygems"
require "mysql"
require "benchmark"
# Given 10,000 records in `venues`, I want to fetch the last records, sorted by descending calculated `distance` from a given geographic location.
TIMES = 1_000
connection = Mysql.real_connect("localhost", "username", "password", "database")
#!/usr/bin/env ruby -w
require "rubygems"
require "mysql"
require "benchmark"
# Given 100,000 records in `venues`, I want to fetch the last thirty records, performing and ascending sort on indexed `name` column.
TIMES = 10
connection = Mysql.real_connect("localhost", "username", "password", "database")
@jodosha
jodosha / toggle_blueprint_grid.html
Created November 3, 2009 11:47
Save this gist as HTML, then drag the link in your bookmark bar.
<a href="javascript:%20(function(){%20var%20container=document.getElementById('container');%20if(container.className.match(/showgrid/)){%20container.className%20=%20container.className.replace('%20showgrid',%20'');%20}%20else%20{container.className%20+=%20'%20showgrid';}})()">Toggle BluePrint</a>
@jodosha
jodosha / each_benchmark.rb
Created November 9, 2009 13:49
Ruby benchmark: Array#each vs for x in array
#!/usr/bin/env ruby -w
require "benchmark"
TIMES = 100_000
ARRAY = (1..1_000).to_a
Benchmark.bm(30) do |b|
b.report "each" do
TIMES.times do |i|
ARRAY.each do |element|
@jodosha
jodosha / gist:234950
Created November 15, 2009 03:13
Ruby benchmark: !@ivar vs defined? @ivar
#!/usr/bin/env ruby -w
require "benchmark"
TIMES = 10_000_000
class Demo
def initialize
@ivar = nil
end
Bluepill.application("app_name") do |app|
app.process("app_name") do |process|
process.start_command = "cd /u/apps/app_name/current && /usr/local/bin/unicorn_rails -c /u/apps/app_name/current/config/unicorn.conf.rb -E production -D"
process.stop_command = "kill -QUIT `cat /u/apps/app_name/current/tmp/pids/unicorn.pid`"
process.restart = "kill -USR2 `cat /u/apps/app_name/current/tmp/pids/unicorn.pid`"
process.stdout = process.stderr = "/u/apps/app_name/current/log/unicorn.log"
process.pid_file = "/u/apps/app_name/current/tmp/pids/unicorn.pid"
process.checks :mem_usage, :every => 10.seconds, :below => 250.megabytes, :times => [3, 5]
process.uid = "app"
process.gid = "app"
#!/usr/bin/env ruby -w
require "rubygems"
require "benchmark"
require "active_support"
TIMES = 10_000_000
class Project
attr_reader :ivar
# This module is intended for test usage, it helps to compare Time instances with millisecond precision.
# Ruby has a fine-grained internal representation of Time values, so if you try:
# Time.now == Time.now # => false
# By including this module the above comparison returns true.
module ComparableWithFixnum
def self.included(base)
base.class_eval do
alias :"original_==" :==
end