Skip to content

Instantly share code, notes, and snippets.

View chebyte's full-sized avatar
🤡
smile

maurotorres chebyte

🤡
smile
View GitHub Profile
@chebyte
chebyte / sendgrid_web_api_gem.rb
Created June 28, 2012 14:15
sendgrid_webapi now has sub_users supports
== SubUser
=== Creating client object:
client = SendGridWebApi::Client.new("user_name", "password")
client.sub_user
== Modules
@chebyte
chebyte / yql_ruby_oauth.rb
Created June 27, 2012 22:14
yahoo yql with ruby and oatuh
require 'oauth'
require 'json'
module Yahoo
CONSUMER_KEY = "...."
CONSUMER_SECRET = "...."
class GeoLoc
def initialize(consumer_key = CONSUMER_KEY, consumer_secret = CONSUMER_SECRET)
@chebyte
chebyte / vcr_rspec2.rb
Created June 27, 2012 18:56
use vcr with rspec 2
require 'sendgrid_webapi'
require "fakeweb"
require 'vcr'
VCR.configure do |c|
c.cassette_library_dir = 'spec/cassettes'
c.hook_into :fakeweb
c.configure_rspec_metadata!
end
@chebyte
chebyte / sendgrid_web_api_gem.rb
Created June 19, 2012 14:31
SendGrid WEB API gem for Rails 3
= SendGrid WEB API gem for Rails 3
SendGrid WEB API gem allow you to retrieve information such as statistics, bounces, spam reports, unsubscribes, send email and other information.
== Rails 3 configuration
In your Gemfile:
gem 'sendgrid_webapi'
@chebyte
chebyte / sendgrid_smtp_api_gem.rb
Created June 19, 2012 14:27
sengrid smtp api gem
= SendGrid SMTP API gem for Rails
SendGrid SMTP API gem provides ActionMailer::Base extensions to use SendGrid API features in you emails.
It extends ActionMailer with next methods:
substitute(patters_string, array_of_substitunion_strings)
uniq_args(hash_of_unique_args)
category(category_string)
open_tracking(enabled = true)
add_filter_setting(filter_name, setting_name, value)
@chebyte
chebyte / capybara_selenium_configuration
Created February 17, 2012 20:15
test integrations with capybara, selenium and devise on RAILS
#test_helper.rb
....code....
class ActionController::TestCase
include Devise::TestHelpers
end
....code....
#test_integration_helper.rb
require File.expand_path("../../helper/test_helper", __FILE__)
@chebyte
chebyte / delete_file_from_commit
Created February 6, 2012 16:08
delete file from commit in git
$ git verify-pack -v .git/objects/pack/pack-4d5c6dc98db773d7df9c01d5d645ff954bfa2e49.idx | sort -k 3 -n | tail -3
61cad2a1f34f09b77e127e0a7f0748917d7d5c78 blob 557568 555456 492171
d655b4e185c0e2853bf946121cb96a55bc95bd65 blob 2436608 2435171 143444913
3541fcf92467242889f0b5a574405650dc461341 blob 140146688 140186258 1644162
$ git rev-list --objects --all | grep 3541fcf92
3541fcf92467242889f0b5a574405650dc461341 pkg/youtube_it-1.2.7.gem
@chebyte
chebyte / split_csv.rb
Created December 24, 2011 06:31
split big csv into multiple smaller files
tmp_dir = "#{RAILS_ROOT}/tmp/"
original_file = "file.csv"
#create temporary dir
sh "mkdir #{tmp_dir}"
# create a temporary file containing the header without
# the content:
sh "head -n 1 #{original_file} > #{tmp_dir}/header.csv"
# create a temporary file containing the content without
@chebyte
chebyte / ruby-19.1-tips
Created December 16, 2011 19:35
Ruby 1.9 tips
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
p "hello 2011!".match(/(?<year>\d+)/)[:year] # => "2011"
tip "Ruby 1.9 uses Oniguruma as a new regex engine, and @pragprog has a fantastic (and free!) PDF on it: http://bit.ly/hIzvOi"
tip "Ruby 1.9 allows default arguments at the beginning of a method!"
def f(a=1, b); p [a,b]; end;
p f(2) # => [1, 2]
@chebyte
chebyte / duplicate_elements.rb
Created November 28, 2011 18:28
monkey patch for return duplicates elements from array
#monkey patch for duplicates
module Enumerable
def dups
inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
end
end
== Usage
[1, 2, 3, 3].dups