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
# export CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls" | |
export CC=/usr/bin/gcc-4.4 | |
require_gcc | |
build_package_disable_ssl2_tcmalloc() { | |
wget 'https://raw.github.com/gist/3767526/9f20aba9f0d8d232d08e14e754e620758330a8eb/gistfile1.diff' | |
patch -p1 < gistfile1.diff |
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
class MyClass | |
{ | |
static int count; | |
public: | |
MyClass () | |
{ | |
count++; | |
} | |
}; |
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
class Notification < ActiveRecord::Base | |
self.table_name = 'some_notifications' | |
NONE = 0 | |
EMAIL = 1 | |
EMAIL2 = 2 | |
SMS = 3 | |
CALL = 4 | |
QUEUED = 0 |
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 Thrift | |
class HTTPClientTransport < BaseTransport | |
# MonkeyPatch for http.post | |
def flush | |
http = Net::HTTP.new @url.host, @url.port | |
http.use_ssl = @url.scheme == "https" | |
resp = http.post(@url.request_uri, @outbuf, @headers) | |
@inbuf = StringIO.new resp.body | |
@outbuf = "" | |
end |
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 'rubygems' | |
require 'eventmachine' | |
module Console | |
PROMPT = "\n>> ".freeze | |
def post_init | |
send_data PROMPT | |
send_data "\0" | |
end |
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
# Update, upgrade and install development tools: | |
apt-get update | |
apt-get -y upgrade | |
apt-get -y install build-essential | |
apt-get -y install git-core | |
# Install rbenv | |
git clone git://github.com/sstephenson/rbenv.git /opt/rbenv | |
# Add rbenv to the path: |
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
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
def log str | |
Rails.logger.info "#{self.class}::#{caller_method}::\"#{str}\"" | |
end | |
private | |
def caller_method(depth=1) | |
parse_caller(caller(depth+1).first).last | |
end | |
#From ActionMailer, where this was used but was not made reusable |
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
# == Schema Information | |
# | |
# Table name: tasks | |
# | |
# id :integer not null, primary key | |
# resource_type :string(255) | |
# resource_id :integer | |
# priority :integer default(0) | |
# attempts :integer default(0) | |
# max_attempts :integer default(3) |
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
# Simple JOIN | |
User.joins(:account) # User -> Account | |
# Will produce | |
# SELECT `users`.* FROM `users` INNER JOIN `accounts` ON `accounts`.`user_id` = `users`.`id` | |
# Complicated JOIN | |
Trait.joins(:user => :account) # Trait -> User -> Account | |
# Will produce | |
# SELECT `traits`.* FROM `traits` INNER JOIN `users` ON `users`.`id` = `traits`.`user_id` INNER JOIN `accounts` ON `accounts`.`user_id` = `users`.`id` |
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
# The problem: In your Rails 3 project, you have a model Request that models a | |
# user's request for content related to a specific problem or topic. The user | |
# can tag her request with any number of words. These are modeled by a Tag class | |
# backed by a tags DB table. Since you want unique records per tag, you have a | |
# Tagging class backed by a taggings table. Taggings is a a many-to-many table | |
# with some additional information. Also, other models in the application | |
# besides requests can be tagged: The Tagging class defines a polymorphic | |
# relationship "taggable" with those models. | |
# | |
# So pretty soon you want to look up all the requests that are tagged with |