Skip to content

Instantly share code, notes, and snippets.

View edison's full-sized avatar
🏠
Working from home

Edison Machado edison

🏠
Working from home
View GitHub Profile
# Amount should be a decimal between 0 and 1. Lower means darker
def darken_color(hex_color, amount=0.4)
hex_color = hex_color.gsub('#','')
rgb = hex_color.scan(/../).map {|color| color.hex}
rgb[0] = (rgb[0].to_i * amount).round
rgb[1] = (rgb[1].to_i * amount).round
rgb[2] = (rgb[2].to_i * amount).round
"#%02x%02x%02x" % rgb
end
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
@edison
edison / gist:2223851
Created March 28, 2012 05:17 — forked from bryckbost/gist:1040263
Capybara 1.0 and Chrome
# env.rb
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Download chromedriver from http://code.google.com/p/selenium/downloads/list
mv chromedriver to /usr/local/bin so it's in your path.
// server
var net = require("net")
, server
;
server = net.createServer(function(socket){
// socket.end("bye\n");
socket.on("connect", function(){
console.log("conectou\n");
@edison
edison / will_paginate.rb
Created February 8, 2012 03:38 — forked from isaacbowen/will_paginate.rb
extends will_paginate to play well with Twitter's Bootstrap
# config/initializers/will_paginate.rb
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer
@edison
edison / file_resource.rb
Created January 24, 2012 18:35 — forked from watson/file_resource.rb
Example Rails model using Paperclip and storing files on S3. This shows how to correctly set a custom header and saving the file in the correct location after it has been directly uploaded to from the users browser.
class FileResource < ActiveRecord::Base
has_attached_file :attachment,
:storage => :s3,
:bucket => ENV['S3_BUCKET'],
:s3_credentials => { :access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET'] },
:path => 'files/:id/:filename',
:url => '/files/:id/:filename'