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
/**
* from:
* "Decoupling Logic with Domain Events [Guide] - Domain-Driven Design w/ TypeScript"
* https://khalilstemmler.com/articles/typescript-domain-driven-design/chain-business-logic-domain-events/
*/
import { UseCase } from '../../../../core/domain/UseCase';
import { CreateUserDTO } from './CreateUserDTO';
import { Either, Result, left, right } from '../../../../core/logic/Result';
import { UserEmail } from '../../domain/userEmail';
/**
* 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 = app.i18n.locales.map(l => l.code)

MySQL Snippets

Initial setup

$ mysql_secure_installation

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

@theo-bittencourt
theo-bittencourt / artists_weight.sass
Last active May 10, 2017 15:17
artists_weight.sass
= attraction-weight($font-size)
&[data-weight="100"]
.name
span
font-size: $font-size * 1
opacity: 1
small
&.size-65
font-size: $font-size * .65
# 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
ActiveAdmin.routes(self)
end
end
end
@theo-bittencourt
theo-bittencourt / ruby_command_line_constructor_snippet.rb
Last active November 19, 2016 05:40
Snippet to build Ruby command line executables
#!/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
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",
@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
{
"round": {
"questions": [
{"id": 0},
{"id": 1}
],
"answers": [
{"answer_choice_id": 0, "seconds": 3.872},
{"answer_choice_id": 1, "seconds": 10.09}
]
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)