Skip to content

Instantly share code, notes, and snippets.

View jonasporto's full-sized avatar
⌨️
Working and having fun!

Jonas Porto jonasporto

⌨️
Working and having fun!
  • Rio de Janeiro, Brazil
View GitHub Profile
@jonasporto
jonasporto / promise_and_callback.md
Last active September 21, 2016 20:01
Playing with Promises and Callbacks

Criando um função construtora tarefas diárias:

function DailyTask() {}

e um método para lidar com a execução dessas tarefas:

DailyTask.perform_sync = function(task) {
  return task;
}

Basicamente a implementação é uma função que recebe uma tarefa como argumento e retorna a tarefa executada.

{
"snippets": [
{
"match": {"global": true, "pkgname": ".", "fn": ".*_test.go"},
"snippets": [
{"text": "func Test", "title": "", "value": "func Test${1:ObjectName}${2:TestName}(t *testing.T) {\n\t$0\n}"},
{"text": "func Benchmark", "title": "", "value": "func Benchmark${1:ObjectName}${2:BenchmarkName}(b *testing.B) {\n\n\tb.StopTimer()\n\n\t$0\n\n\tb.StartTimer()\n\n\tfor i := 0; i < b.N; i++ {\n\t\t\n\t}\n\n}"},
{"text": "func Example", "title": "", "value": "func Example${1:ObjectName}${2:ExampleName}() {\n\n\t$0\n\n\t// Output:\n\t// \n\n}"}
]
}
@jonasporto
jonasporto / bin-cc.md
Created April 26, 2016 20:49 — forked from erikhenrique/bin-cc.md
Bin de cartões de crédito para validação

Validação para cartão de crédito.

Bin e padrões para validação de cartão de crédito.

Bandeira Começa com Máximo de número Máximo de número cvc
Visa 4 13,16 3
Mastercard 5 16 3
@jonasporto
jonasporto / rails
Created April 15, 2016 15:05 — forked from masone/rails
Thin with SSL as default server for use with rails server. Works with Rubymine.
#!/usr/bin/env ruby
require 'rack'
# Thin SSL workaround
module Rack
module Handler
class Thin
def self.run(app, options={})
app = Rack::Chunked.new(Rack::ContentLength.new(app))
server = ::Thin::Server.new(options[:Host] || '0.0.0.0',
@jonasporto
jonasporto / selectors.js
Last active April 4, 2016 21:38
usefult selectors examples, regex, nth
Javascript
document.querySelectorAll('a[href$=reject]') // all elements with a link terminated by reject
document.querySelectorAll('a[href^=reject]') // all elements with a link started by reject
document.querySelectorAll('[src*=graph\\.facebook]') // all elements that contains graph.facebook as content src
document.querySelectorAll('tr td:nth-child(2)')
@jonasporto
jonasporto / dsdsdsdgistfile1.txt
Last active March 16, 2016 23:52
Working with date ruby
http://stackoverflow.com/questions/8511919/how-to-scope-last-week-by-date-object
https://nandovieira.com.br/trabalhando-com-datas-no-ruby-on-rails
https://nandovieira.com.br/formatando-datas-no-ruby-on-rails
Date.today.beginning_of_month
scope :completed_at_last_week, -> {
where(
completed_at: 1.week.ago.beginning_of_week..1.week.ago.end_of_week
@jonasporto
jonasporto / .rb
Created March 16, 2016 12:22
Ruby Merge Hash Sum Non String Values
.inject{|a, b|
a.merge(b){ |_, x, y| x.is_a?(String) && x.eql?(y) ? x : x + y
}}
@jonasporto
jonasporto / heroku_rails_phantomjs.md
Created February 4, 2016 21:08 — forked from edelpero/heroku_rails_phantomjs.md
Heroku, Ruby on Rails and PhantomJS

#Heroku, Ruby on Rails and PhantomJS

In this post, I’m going to show you how to modify an existing Ruby on Rails app running on Heroku’s Cedar stack to use PhantomJS for screen scraping. If you’ve never heard of PhantomJS, it’s a command-line WebKit-based browser (that supports JavaScript, cookies, etc.).

Let’s get started. This is a high-level overview of the required steps:

  • Modify your app to use multiple Heroku buildpacks.
  • Extend your app to use both the Ruby as well as the PhantomJS buildpacks.
  • Confirm that everything worked.
@jonasporto
jonasporto / tinder-api-documentation.md
Created January 31, 2016 17:02 — forked from rtt/tinder-api-documentation.md
Tinder API Documentation

Tinder API documentation

http://rsty.org/

I've sniffed most of the Tinder API to see how it works. You can use this to create bots (etc) very trivially. Some example python bot code is here -> https://gist.github.com/rtt/5a2e0cfa638c938cca59 (horribly quick and dirty, you've been warned!)

Note: this was written in April/May 2014 and the API may have changed since

API Details

capturaEnderecoUsuario: function() {
var me = this;
/**
* Quando o javascript olha pra Ext.Ajax.request,
* ele não tem como prever quando isso retornar.
* Por ser uma requisição externa pode ser muito rápido ou demorar muito por demandar processamento.
* Então, como ele resolve isso ?
* Ele te promete(promisse) que vai te dar uma resposta de sucesso(success) ou erro(failure) assim que acabar a requisição.
* e passa para o proximo passo sem bloquear seu codigo.