Skip to content

Instantly share code, notes, and snippets.


Theo B theo-bittencourt

  • Rio de Janeiro, Brazil
View GitHub Profile
View redirectRoutesWithoutLocale.js
* This middleware redirects routes without locale to a prefixed ones.
* Useful for links included on email templates.
export default function(context) {
const { route, redirect, app } = context
const { path, query } = route
const previousLocaleCode = app.i18n.getLocaleCookie()
const localeCodes = => l.code)

MySQL Snippets

Initial setup

$ mysql_secure_installation

O prompt do mysql deve ser iniciado com -u root para alguns comandos

View artists_weight.sass
= attraction-weight($font-size)
font-size: $font-size * 1
opacity: 1
font-size: $font-size * .65
View routes.rb
# We can't use dynamic segment for the festivals because ActiveAdmin can't
# include it to default_url_options. So all named routes in admin will break.
Festival::KEYS.each do |festival_key|
scope festival_key do
scope ':locale', defaults: {locale: I18n.locale} do
devise_for :admin_users, ActiveAdmin::Devise.config
theo-bittencourt / ruby_command_line_constructor_snippet.rb
Last active Nov 19, 2016
Snippet to build Ruby command line executables
View ruby_command_line_constructor_snippet.rb
#!/usr/bin/env ruby
# Snippet to build command line executables like this:
# ./my_script command --opt-a "opt A"
require 'optparse'
require 'singleton'
require 'pry'
class Command
View gist:2b564b09b3a9b7342508
["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",
theo-bittencourt / destinationBy.swift
Last active Aug 29, 2015
Swift implementation to calculate a destination location based on distance and direction from an origin location
View destinationBy.swift
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)
// (Spherical earth model)
extension CLLocation {
func destinationBy(# distance: CLLocationDistance, direction: CLLocationDirection) -> CLLocation {
let earthRadius = 6372.7976
let angularDistance = (distance / 1000) / earthRadius
View round_params_example.json
"round": {
"questions": [
{"id": 0},
{"id": 1}
"answers": [
{"answer_choice_id": 0, "seconds": 3.872},
{"answer_choice_id": 1, "seconds": 10.09}
View quiz_score.rb
value =
if answer.seconds <= 3
# Value is proportional to time taken to answer the question.
Question::BASE_SCORE_VALUE * (1 - (answer.seconds.to_f / Question::MAX_TIME_TO_ANSWER))
# Double value if question is bonus
value * (answer.question.bonus? ? 2 : 1)
View gist:9924747
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
You can’t perform that action at this time.