Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@felipeelias
felipeelias / post-receive.sh
Created October 27, 2011 13:10
Deploy with git's post-receive hook
#!/bin/bash
APP_PATH=/home/applicake/app
# Production environment
export RAILS_ENV="production"
export PATH="/opt/ruby/bin:$PATH"
exit_with_error() {
@felipeelias
felipeelias / posts.rb
Created October 3, 2011 18:23
Grouping posts by month concept
require 'date'
class Month
attr_accessor :year, :month
def initialize(year, month)
self.year = year
self.month = month
end
@felipeelias
felipeelias / fixnum_to_proc.rb
Created September 27, 2011 20:33
Fixnum to_proc definition
class Fixnum
def to_proc
lambda { |x| x + self }
end
end
p [1, 2, 3].map(&2)
# => [3, 4, 5]
function Dog() {
this.url = '/dogs';
this.fetch = function(callback) {
var self = this;
$.getJSON(this.url, function(attributes) {
self.attributes = attributes;
callback(attributes);
});
}
@felipeelias
felipeelias / fiddle.response.json
Created July 30, 2011 20:51
fiddle.response.json
[
{
"body":"test1"
}
]
@felipeelias
felipeelias / ping_redis.rb
Created May 11, 2011 13:50
Ping the Redis server using a TCP socket
require 'socket'
@socket = TCPSocket.new('127.0.0.1', 6379)
@socket.write("PING\r\n")
puts @socket.gets # => "+PONG"
@socket.close
require 'open-uri'
def link_valid?(url)
open(url)
true
rescue
false
end
def validate_urls(urls)
@felipeelias
felipeelias / services.sh
Created April 29, 2011 23:12
manage hosts in os x directory services
# list all registered hosts
dscl localhost -list /Local/Default/Hosts
# register a new host named "test.local"
dscl localhost -create /Local/Default/Hosts/test.local IPAddress 127.0.0.1
# remove the test.local host
dscl localhost -delete /Local/Default/Hosts/test.local
@felipeelias
felipeelias / .gitignore
Created April 29, 2011 01:24 — forked from fnando/rubygems_proxy.rb
Rack app for caching RubyGems files. Very useful in our build server that sometimes fails due to our network or rubygems.org timeout.
cache
@felipeelias
felipeelias / role_management.rb
Created April 18, 2011 14:11
just wondering
require 'test/unit'
module RoleManagement
@@available_roles ||= []
def available_roles
@@available_roles
end
def roles