Skip to content

Instantly share code, notes, and snippets.

View theo-bittencourt's full-sized avatar

Theo B theo-bittencourt

  • IBJJF
  • Rio de Janeiro, Brazil
View GitHub Profile
/spec/integration/user_is_evaluated_spec.rb
require 'spec_helper'
describe 'User is evaluated', :wip do
let(:evaluator) { create(:user) }
let(:evaluated) { create(:user) }
let(:edition) { create(:edition, users: [evaluator, evaluated]) }
before do
value =
if answer.seconds <= 3
Question::BASE_SCORE_VALUE
else
# Value is proportional to time taken to answer the question.
Question::BASE_SCORE_VALUE * (1 - (answer.seconds.to_f / Question::MAX_TIME_TO_ANSWER))
end
# Double value if question is bonus
value * (answer.question.bonus? ? 2 : 1)
{
"round": {
"questions": [
{"id": 0},
{"id": 1}
],
"answers": [
{"answer_choice_id": 0, "seconds": 3.872},
{"answer_choice_id": 1, "seconds": 10.09}
]
@theo-bittencourt
theo-bittencourt / destinationBy.swift
Last active August 29, 2015 14:26
Swift implementation to calculate a destination location based on distance and direction from an origin location
import Foundation
import CoreLocation
// Calculate destination location based on origin location, distance (meters) and direction (degrees from north).
// Playing: myOriginLocation.destinationBy(distance: 5.0, direction: 45.0)
// http://www.geomidpoint.com/destination/calculation.html (Spherical earth model)
extension CLLocation {
func destinationBy(# distance: CLLocationDistance, direction: CLLocationDirection) -> CLLocation {
let earthRadius = 6372.7976
let angularDistance = (distance / 1000) / earthRadius
@theo-bittencourt
theo-bittencourt / gist:4005863
Created November 3, 2012 04:18
rake colecao verão
#encoding: utf-8
desc "cria produtos da coleção verão 2013 - viajantes"
task :create_products_viajantes => :environment do
@count = 0
@colecao = Colecao.where(:nome => "Viajantes").first
Produto.where(:colecao_id => @colecao.id).each do |p|
puts "Destruindo subprodutos de #{p.referencia}"
Subproduto.where(referencia: p.referencia).delete_all
@theo-bittencourt
theo-bittencourt / gist:4217862
Created December 5, 2012 17:50
Date Time Format In RUBY
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
ARCHETYPE_ROTATION = [
["common_man", "helpful", "idealist", "ruler",
"alchemist", "mentor", "hero", "creative",
"explorer", "rebel", "seducer", "joker"],
["joker", "seducer", "rebel", "explorer",
"creative", "hero", "mentor", "alchemist",
"ruler", "idealist", "helpful", "common_man"],
["mentor", "creative", "joker", "hero",
# thor heroku:db:dump
# options: --keep = Keep dump file
# --remote staging = To change the name of the remote
# --user bob = To change the name of the user
module Heroku
class Db < Thor
method_option :keep, :type => :boolean, :default => false
method_option :remote, :type => :string, :default => "heroku"
method_option :host, :type => :string, :default => "localhost"
@mixin selection($selectionColor, $selectionBackground, $selectionShadow: none) {
// defaults to text-shadow: none
::selection {
color: $selectionColor;
background: $selectionBackground;
text-shadow: $selectionShadow; }
::-moz-selection {
color: $selectionColor;
background: $selectionBackground;
text-shadow: $selectionShadow; }

Facebook Page Token – que não expira

O fluxo abaixo descreve como se deve obter um token (que não expira) para acesso à uma fanpage específica. Para tratar múltiplas fanpages de diferentes usuários, seria mais correto armazenar os tokens no db e criar um endpoint para tratar o callback de auth do FB.

O token gerado pode ser confirmado aqui: https://developers.facebook.com/tools/debug

  1. Criar um app e configurar 'Website with Facebook Login' para http://localhost:3000