Skip to content

Instantly share code, notes, and snippets.

View vbrazo's full-sized avatar
:octocat:
Open source for humanity!

Vitor Oliveira vbrazo

:octocat:
Open source for humanity!
View GitHub Profile
@vbrazo
vbrazo / stripe_integration.rb
Created April 26, 2023 04:18
Ruby Stripe Integration
# Set new Stripe API token
Stripe.api_key = 'sk_test_token'
# create new account
account = Stripe::Account.create({type: 'standard'})
# generate link for user to associate account
account_id = Stripe::AccountLink.create({
account: account.id,
refresh_url: 'https://www.site.tech/refresh_url',
# =begin
# # Given a Balanced Binary Tree (BBT)
# # (non-sorted, non-search, containing unique elements)
# 42
# / \
# / \
# / \
# / \
# 81 99
@vbrazo
vbrazo / rotate_a_matrix_90_degrees.rb
Last active August 24, 2019 18:34
How to rotate a matrix 90 degrees in Ruby
#
# Transpose a matrix
# Make [[1,2,3], [4,5,6], [7,8,9]] becomes [[1,4,7], [2,5,8], [3,6,9]]
#
class Array
def my_transpose
size.times do |i|
0.upto(i) do |j|
self[i][j], self[j][i] = self[j][i], self[i][j]
end
env:
sudo: false
language: ruby
cache: bundler
rvm:
- 2.5.1
script: bundle exec rspec
matrix:
allow_failures:
- rvm: ruby-head
AllCops:
TargetRubyVersion: 2.3
Lint/AmbiguousBlockAssociation:
Description: This cop checks for ambiguous block association with method when param passed without parentheses.
Enabled: false
Lint/UnifiedInteger:
Description: This cop checks for using Fixnum or Bignum constant.
Enabled: false
## Hints & what we're looking for
* We're more **interested in the process** than in the final result. You
probably won't finish the whole task in the given time.
* You are free to **use anything you use in your daily work**, including
websites like Google or StackOverflow.
* You can use any language or tool you want, but we recommend that you use the
language you feel most comfortable with and keep it super simple.
**You don't need a database or framework**, a simple command line script that
computes the values and prints them to the console is just fine for us. You
# config.ru
require './application/api'
use RackAuthMiddleware
run Rack::Cascade.new [ApiSupport]
# application/middlewares/rack_auth_middleware.rb
class RackAuthMiddleware
UnprocessableHeader = Class.new(ArgumentError)
@vbrazo
vbrazo / Faraday.md
Last active August 27, 2018 23:47 — forked from hemanth/Faraday.md
HTTP client library is so convenient Faraday of Ruby

HTTP client library is so convenient Faraday of Ruby

Faraday's so convenient Ruby HTTP client library

The development of the API wrapper [RestClient gem] or I [rest_client_gem]
What you need for OAuth was using [Net / HTTP] [net_http] + [OAuth gem] the [oauth_gem]

After reading the source of the API library [Twitter gem] and [twitter_gem] [Instagram gem] such as [instagram_gem]
Thing [Faraday gem] that [faraday_gem] had been commonly used

AllCops:
DisplayCopNames: true
Exclude:
- 'bin/*'
- 'config.ru'
- 'config/environments/*'
- 'config/initializers/*'
- 'db/**/*'
- 'vendor/**/*'
- Gemfile
@vbrazo
vbrazo / leap_year_coding_task.md
Last active January 4, 2018 17:19
Leap Year Algorithm Exam

Given a year, report if it is a leap year.

The tricky thing here is that a leap year in the Gregorian calendar occurs:

  • on every year that is evenly divisible by 4
  • except every year that is evenly divisible by 100
  • unless the year is also evenly divisible by 400

For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap year, but 2000 is.