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 / 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)
@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 / 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 / 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 / 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"}}
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)
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 }
@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
@guimello
guimello / climatempo.rb
Created November 16, 2010 18:50
Capital codes (climatempo)
#!/usr/bin/env ruby
################################################################################
ENV["RAILS_ENV"] = ARGV[1] || 'development'
require File.dirname(__FILE__) + '/../config/environment'
require 'mechanize'
path = '/root/path'
File.open(File.join(path, 'climatempo.txt', 'w+')) do |f|
pt-BR:
errors:
messages:
not_found: "não encontrado"
already_confirmed: "já foi confirmado"
not_locked: "não foi bloqueado"
devise:
failure:
unauthenticated: 'Para continuar, faça login ou registre-se.'