This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Lib | |
def xpto(option) | |
mod = Module.new | |
include mod | |
mod.class_eval <<-RUBY, __FILE__, __LINE__+1 | |
def #{option} | |
1 | |
end | |
RUBY | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'securerandom' | |
error_id = SecureRandom.hex | |
raise "Erro bolado. Error Id: #{error_id}" | |
Rails.logger.fatal "Error Id: #{error_id}. Status code: #{response.status_code}... (informações de debug como parâmetros passados para o request e variáveis de estado que podem ajudar a debugar" | |
# quando der problema, é só pedir o error Id que estourou no cliente e buscar nos logs... | |
#UtilidadePublica |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'POST #create_from_r7login' do | |
let(:user_login){ 'var session = { "usersession" : { "userId" : "2c9629db45c75b6b0145cc8bfdba2a71" , "user" : { "login" : "[email protected]" , "name" : "Test" , "nickname" : "Test" , "country" : "Brasil" , "state" : "Sao Paulo" , "city" : "Sao Paulo" , "zipCode" : "11111-111" , "gender" : "M" , "birthDate" : "30/04/1990"} , "savePassword" : false , "userLogged" : true}};' } | |
let(:login){ double('login', r7Session: '1234') } | |
let(:user_id) { '{ "id": "537e0379eba0b0e48d96dc04", "lastInteractionTimestamp": "2014-05-22 11:02:33.351 BRT", "userId": "8aee801a2cf5695d012cf56bf9560003", "savePassword": false, "userLogged": true, "processRetry": 0 }' } | |
let(:user_info) { '{ "user": { "id": "2c96958d4595cccf0145ae6e93bd000e", "login": "[email protected]", "name": "teste51", "nickname": "teste51", "gender": "MALE", "zipCode": "00000-000", "documentNumber": "353.026.858-50", "city": { "id": 1, "name": "Acrelandia", "state": { "id": 1, "abbreviation": "AC", "name": "Acre" } }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# good | |
expect(user.reusable_attributes[:name]).to eq("John FB user") | |
expect(user.reusable_attributes[:nickname]).to eq('fbjohn') | |
expect(user.reusable_attributes[:image]).to eq("http://image.com/facebook_image.png",) | |
expect(user.reusable_attributes[:gender]).to eq("MALE") | |
# bad | |
expect(user.reusable_attributes).to eq({ | |
name:"John FB user", | |
nickname:"fbjohn", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
betawaffle | |
3:53 thiagofm: well hold on | |
betawaffle | |
3:53 i can give you some pointers | |
3:53 don't copy the uglyness | |
3:54 erlang optimizing certain binary matching situations, and i exploit those to try to lose as little time as possible | |
3:55 you need the first argument in each matching function to be the binary you are matching | |
thiagofm | |
3:55 thats nice, i didn't know about it | |
betawaffle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ChocolateMachine do | |
defrecordp :state, [:sock, :state, :and_so_on] | |
def start_link | |
# starts tcp server and saves sock to state | |
end | |
def handle_call({:get_chocolate, chocola_name}, from, state(state: :processing, sock: sock)) | |
case :gen_tcp.send(sock, chocolate_name) do | |
:ok -> :ok | |
:error -> raise("Gimme chocolate pls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
def build_box_ids ids | |
ids.map!{|id| {'box_ids[]' => id}} | |
.inject({}.compare_by_identity, :merge) | |
end | |
uri = URI('http://localhost:9000/lock/stale') | |
p req = Net::HTTP.post_form(uri, build_box_ids(['box1', 'box2'])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object gauss { | |
def gauss = { | |
def sum(f: Int => Int, a: Int, b: Int): Int = { | |
if (a > b) 0 | |
else f(a) + sum(f, a+1, b) | |
} | |
sum(x => x, 1, 100) | |
} //> gauss: => Int | |
gauss //> res0: Int = 5050 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Datomic example code | |
;; demonstrates various update scenarios, using a news database | |
;; that contains stories, users, and upvotes | |
;; grab an in memory database | |
(use '[datomic.api :only (q db) :as d]) | |
(def uri "datomic:mem://foo") | |
(d/create-database uri) | |
(def conn (d/connect uri)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hi guys. I have a factory that returns a resource like this: | |
return $resource('/api/:key.json', {key: '@key'}, { | |
'delete': { method: 'DELETE' } | |
}); | |
when I do: | |
Key.delete(pair, function (response) { | |
console.log(response); |