Skip to content

Instantly share code, notes, and snippets.

View guimello's full-sized avatar

Guilherme da Silva Mello guimello

  • Jundiaí, São Paulo - Brazil
View GitHub Profile
@guimello
guimello / gist:745112
Created December 17, 2010 15:30 — forked from Arcath/gist:481321
def gravatar_url(email,options = {})
require 'digest/md5'
hash = Digest::MD5.hexdigest(email)
url = "http://www.gravatar.com/avatar/#{hash}"
options.each do |option|
option == options.first ? url+="?" : url+="&"
key = option[0].to_s
value = option[1].to_s
url+=key + "=" + value
end
class Widget < ActiveRecord::Base
validates_numericality_of :custom_width
has_attached_file :file,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
:path => "widgets/:id/file/:normalized_file_file_name_:style.:extension",
:url => ":s3_alias_url",
:s3_host_alias => "#{S3Config[:bucket]}",
:styles => lambda { |attachment| attachment.instance.file_styles }
module SQLGrowler
class Subscriber < ActiveRecord::Railties::Subscriber
def sql(event)
super
g('%s (%.1fms) %s' % [event.payload[:name], event.duration, event.payload[:sql].squeeze(' ')])
end
end
def self.enable
if Kernel.respond_to?(:g)
@guimello
guimello / active_record_random_rails_2.rb
Created January 13, 2011 14:14
Active Record random scope (Rails 2)
named_scope :random, lambda { |*args| { :joins => "JOIN (SELECT id
FROM #{table_name}
ORDER BY RAND()
LIMIT #{(limit = args.first.to_i) > 0 ? limit : 1}
) AS random_ids
ON #{table_name}.id = random_ids.id"}}
@guimello
guimello / will_paginate_objects.html.haml
Created January 24, 2011 11:21
Using will_paginate on non AR objects
= will_paginate WillPaginate::Collection.create(@objects.page, @objects.per_page, @objects.total_results) {|p| p.replace @objects}
@guimello
guimello / processes_monitor.sh
Created February 3, 2011 13:57
Log top processes into a csv file.
#!/bin/bash
top -n1b | awk '{print $1","$2","$3","$4","$5","$6","$7","$8","$9","$10","$11","$12","$13}' | tail -n +8 >> /var/log/processes_monitor.csv
@guimello
guimello / IpadIphoneAppDelegate.m
Created March 25, 2011 14:22
Running on Ipad or Iphone?
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.window addSubview:self.splitVC.view];
} else {
[self.window addSubview:self.navigationController.view];
}
[self.window makeKeyAndVisible];
return YES;
@guimello
guimello / rails_logger_in_stdout.rb
Created May 16, 2011 14:34
Rails logger in STDOUT
# So I can remember...
ActiveRecord::Base.logger = Logger.new(STDOUT)
/* So I never need to look for it anymore... :) */
- (void)viewDidLoad
{
[super viewDidLoad];
aTextField.delegate = self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField
@guimello
guimello / navigation_tool_bar_color.m
Created August 9, 2011 21:01
Tint color your navigation tool bar [ios]
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:(102.0/255.0) green:(20.0/255.0) blue:(11.0/255.0) alpha:1];