Skip to content

Instantly share code, notes, and snippets.

View viniciussbs's full-sized avatar

Vinícius Sales viniciussbs

  • Rio de Janeiro, Brasil
View GitHub Profile
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@viniciussbs
viniciussbs / external_url_helper.rb
Created May 14, 2014 19:45
External URL helpers example
module ExternalUrlHelper
def google_url
"www.google.com"
end
end
class Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end
def do_e() print "!\n"; end
def do_v() print "Dave"; end
Dispatcher = {
"a" => instance_method(:do_a),
"d" => instance_method(:do_d),
"e" => instance_method(:do_e),
"v" => instance_method(:do_v)
class Person
attr_reader :attributes # "getter"
def initialize
@attributes = {}
end
def name
@attributes[:name]
end
desc 'rolls back migrations in current branch not present in other'
task :rollback_branch_migrations, [:other_branch] do |t, args|
load "#{Dir.pwd}/Rakefile"
branch_migrations = BranchMigrations.new(args.other_branch)
puts ['Rollback the following migrations', branch_migrations, 'y,n? ']
next if %w[no n NO N].include?(STDIN.gets.chomp)
migrate_task = Rake::Task['db:migrate:down']

Easy Twitter API OAuth 2 Access

  1. Go to your applications. Create a new one, and find the values in the Consumer Key and Consumer Secret fields.

  2. Use OAuth client information to produce an OAuth 2 access token:

    curl -i --user <consumer_key>:<consumer_secret> -X POST https://api.twitter.com/oauth2/token -d "grant_type=client_credentials"
    
    {"access_token":"<oauth2_token>","token_type":"bearer"}% 
    
@viniciussbs
viniciussbs / ActiveSupport::TimeZone
Created October 29, 2014 17:15
Some tests with ActiveSupport::TimeZone in Rails 4.2.0.beta2
|------------------------------------------------------------+----------------------------------------+------------------------------------------------------+
| Time.now.at_beginning_of_day | Time.now | Time.now.at_end_of_day |
| 2014-10-29 00:00:00 -0200 | 2014-10-29 14:25:24 -0200 | 2014-10-29 23:59:59 -0200 |
|------------------------------------------------------------+----------------------------------------+------------------------------------------------------+
| Time.now.at_beginning_of_day.in_time_zone("Brasilia") | Time.now.in_time_zone("Brasilia") | Time.now.at_end_of_day.in_time_zone("Brasilia") |
| Wed, 29 Oct 2014 00:00:00 BRST -02:00 | Wed, 29 Oct 2014 14:42:46 BRST -02:00 | Wed, 29 Oct 2014 23:59:59 BRST -02:00 |
|------------------------------------------------------------+--------
@viniciussbs
viniciussbs / full_day_with_time_zone.rb
Last active August 29, 2015 14:08
Full-day period taking into account the time zone (tested in Rails 4.2.0.beta2)
# I'm in Brasilia time zone: BRT -03:00 (or BRTS -02:00 during Daylighy Saving Time).
Time.zone.name
#=> "Brasilia"
# Get time with time zone:
yesterday = Time.zone.now.yesterday
#=> Tue, 28 Oct 2014 17:04:11 BRST -02:00
# Full-day period with time zone:
yesterday.all_day
@viniciussbs
viniciussbs / cmd.sh
Last active August 29, 2015 14:24 — forked from kelvinn/cmd.sh
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@viniciussbs
viniciussbs / pattern_match_test.exs
Created September 4, 2015 14:51
Simple Elixir pattern matching test.
x = 42
# 42
x = x + 1
# 43
^x = x + 1
# ** (MatchError) no match of right hand side value: 44