Skip to content

Instantly share code, notes, and snippets.

@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@xdite
xdite / post.rb
Created July 4, 2011 15:01
The Better Way To Do Random using Scope
# before
# from http://jan.kneschke.de/projects/mysql/order-by-rand
def self.pick
return Post.find_by_sql("SELECT * FROM posts as r1 JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM posts)) AS gid) AS r2 WHERE r1.id >= r2.gid and r1.status = ‘published’ ORDER BY r1.id ASC LIMIT 1;").first;
end
# after
# ex. Post.rand.published.limit(5)
before_update :update_ranking
def self.calculate_ranking(score, created_at)
order = Math.log10(([score.abs,1].max))
if score > 0
sign = 1
elsif score < 0
sign = -1
@fnichol
fnichol / README.md
Created March 12, 2011 20:52
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@christos
christos / etc-init-d-monit
Created November 10, 2010 14:29
EC2 config files
#! /bin/sh
#
# skeleton example file to build /etc/init.d/ scripts.
# This file should be used to construct scripts for /etc/init.d.
#
# Written by Miquel van Smoorenburg <[email protected]>.
# Modified for Debian
# by Ian Murdock <[email protected]>.
#
# Version: @(#)skeleton 1.9 26-Feb-2001 [email protected]
require 'rubygems'
require 'nokogiri'
require 'open-uri'
site = ARGV[0]
doc = Nokogiri::HTML(open("http://www.alexa.com/siteinfo/#{site}"))
data = []
doc.css('ul')[4].css('li.geo_percentages').each_with_index do |raw,i|