Skip to content

Instantly share code, notes, and snippets.

@slayer
slayer / ree-1.8.7-2011.03
Last active December 17, 2015 07:19 — forked from josacar/gist:3767538
# 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
class MyClass
{
static int count;
public:
MyClass ()
{
count++;
}
};
class Notification < ActiveRecord::Base
self.table_name = 'some_notifications'
NONE = 0
EMAIL = 1
EMAIL2 = 2
SMS = 3
CALL = 4
QUEUED = 0
@slayer
slayer / thrift_monkeypatch.rb
Created June 26, 2012 20:43
Thrift 0.8.0 monkeypatch for 1.9 ruby
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
@slayer
slayer / em-irb-console.rb
Created February 1, 2012 15:35 — forked from tmm1/em-irb-console.rb
networked irb server/client in EM
require 'rubygems'
require 'eventmachine'
module Console
PROMPT = "\n>> ".freeze
def post_init
send_data PROMPT
send_data "\0"
end
@slayer
slayer / rbenv-install-system-wide.sh
Created December 23, 2011 11:17
rbenv install and system wide install on Ubuntu to /opt/rbenv
# 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:
@slayer
slayer / gist:1425932
Last active September 28, 2015 10:38
logging snippet from ror2ru
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
# == 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)
@slayer
slayer / gist:935641
Created April 21, 2011 22:46
SQL JOIN via AREL in Rails 3
# 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`
# 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