Skip to content

Instantly share code, notes, and snippets.

View alissonbrunosa's full-sized avatar

Alisson Bruno alissonbrunosa

View GitHub Profile
class RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: [:create]
protected
def configure_sign_up_params
attributes = { pessoa_attributes: [:nome, :cpf, :telefone, :data_nascimento, :sexo] }
devise_parameter_sanitizer.for(:sign_up) << attributes
end
end
$.ajax({
url: 'url-chamada',
success: function(a,b,c) {
// Do something if sucess
},
statusCode: {
401: function() {
//Do something if status code is 401.
}
}
import React from 'react';
let {Component, PropTypes} = React;
export default class CoolComponent extends Component {
handler = (e) => {
// Do somthing cool here
}
render() {
return <div onClick={this.handler}></div>;
require 'sinatra'
require 'securerandom'
module OS
class << self
def get
linux || mac || windows
end
module Chainable
def chain(*methods)
chain!(*methods)
rescue NoMethodError
nil
end
def chain!(*methods)
methods.inject(self) do |object, method|
object.public_send(method)
package solution
// You are given an array A consisting of N integers.
// For each number A[i] such that 0 ≤ i < N, we want to count the number of elements of the array that are not the divisors of A[i]. We say that these elements are non-divisors.
// For example, consider integer N = 5 and array A such that:
// A[0] = 3
// A[1] = 1
Warming up --------------------------------------
lists 14.525k i/100ms
select 8.124k i/100ms
pluck 258.000 i/100ms
Calculating -------------------------------------
lists 157.648k (± 7.4%) i/s - 798.875k in 5.096596s
select 85.202k (± 7.1%) i/s - 430.572k in 5.079725s
pluck 2.414k (± 9.8%) i/s - 12.126k in 5.072495s
Comparison:
=begin
In this problem you will write a function called populate_template which will take in a template string e.g. " Hello {!first_name} - How are you?" and a hash of fields e.g { "first_name" : "John" } as arguments and will return the template string with the fields inserted in the correct place.
The usecase for a function like this would be for instance for answer templates to be used by a support team at a company.
So in the previous example you would get:
populate_template("Hello {!first_name} - How are you?", {"first_name" => "John"})
and you would get:
@alissonbrunosa
alissonbrunosa / cities.go
Last active September 27, 2019 08:46
Implementation of BFS algorithm in Go
package bfs
import "fmt"
type City struct {
Name string
Population uint32
neighbors []Node
}
def Ok(value)
Okay.new(value)
end
def Err(value)
Error.new(value)
end
class Result
attr_reader :value