This file contains hidden or 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 ActiveRecord::Base | |
mattr_accessor :shared_connection | |
@@shared_connection = nil | |
def self.connection | |
@@shared_connection || retrieve_connection | |
end | |
end | |
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection |
This file contains hidden or 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
first: brew install highlight | |
second: add to your .zshrc (or .bashrc) | |
function hlr { | |
highlight --syntax ruby -k Menlo -K 20 -s edit-xcode $1 | pbcopy | |
} | |
third: paste the highlighted code to your Keynote talk. |
This file contains hidden or 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 "socket" | |
socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) | |
socket.bind(Socket.pack_sockaddr_in(3000, "localhost")) | |
socket.listen(1) | |
loop do | |
connection = socket.accept[0] | |
connection.gets.match /name=(.+) (.+)/ | |
connection.write "#{$2} 200 OK\nContent-Type: text/html\n\nHello #{$1}" | |
connection.close | |
end |
This file contains hidden or 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 preforking echo server in Ruby | |
require "socket" | |
# Create a socket, bind it to localhost:2424, and start listening. | |
# Runs once in the parent. All forked children inherit the socket's | |
# file descriptor. | |
acceptor = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) | |
address = Socket.pack_sockaddr_in(4242, "localhost") | |
acceptor.bind(address) | |
acceptor.listen(10) |
This file contains hidden or 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 SugarScopes | |
def like(query) | |
relation = clone | |
query.each do |column, value| | |
relation = relation.where(arel_table[column].matches(value)) | |
end | |
relation | |
end | |
def asc(column = :id) |
This file contains hidden or 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 User | |
has_many :posts | |
end | |
class Post | |
belongs_to :user | |
has_many :comments | |
def self.search(comment_description) | |
joins(:comments).where(:comments => { :description => comment_description }) |
This file contains hidden or 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 String | |
def encrypt(options = {}) | |
crypt :encrypt, options | |
end | |
def decrypt(options = {}) | |
crypt :decrypt, options | |
end | |
private |
This file contains hidden or 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 AttrEncryptedRelation | |
def self.included(base) | |
base.class_eval do | |
alias_method_chain :build_where, :attr_encrypted | |
end | |
end | |
private | |
def build_where_with_attr_encrypted(opts, other = []) |
This file contains hidden or 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
root :to => "home#show", :constraints => UserLoggedConstraint.new(false) | |
root :to => "profile#show", :constraints => UserLoggedConstraint.new(true) |
This file contains hidden or 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
-A INPUT -i lo -j ACCEPT | |
-A OUTPUT -o lo -j ACCEPT | |
-A OUTPUT -p udp -o eth0 --dport 53 --sport 1024:65535 -j ACCEPT | |
-A INPUT -p udp -i eth0 --sport 53 --dport 1024:65535 -j ACCEPT | |
-A OUTPUT -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT | |
-A INPUT -p tcp -i eth0 --dport 22 --sport 1024:65535 -m state --state NEW -j ACCEPT | |
-A INPUT -p tcp -i eth0 --dport 80 --sport 1024:65535 -m state --state NEW -j ACCEPT | |
-A OUTPUT -j ACCEPT -m state --state NEW,ESTABLISHED,RELATED -o eth0 -p tcp -m multiport --dport 80,443 -m multiport --sport 1024:65535 | |
-A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED -i eth0 -p tcp | |
-A INPUT -j DROP |