Skip to content

Instantly share code, notes, and snippets.

View willsza's full-sized avatar

William Franklin willsza

  • Raro Labs
  • Belo Horizonte - Brasil
View GitHub Profile
@willsza
willsza / phone-validator.ts
Created February 8, 2024 14:21
Validação de telefones BR
function validaTelefoneBR(telefone: string): boolean {
// Remove caracteres não numéricos, exceto o sinal de mais (+) no início para código de país
const numeroLimpo = telefone.replace(/[^\d+]/g, '');
// Regex para validar números de telefone fixos e móveis no Brasil
// Aceita números com e sem o código do país (+55) e o prefixo nacional (0)
const regex = /^(?:(?:\+55\s?)?(?:[1-9][1-9])|(?:0[1-9][1-9]))\s?(?:9\s?\d{4}|\d{4})[-\s]?\d{4}$/;
return regex.test(numeroLimpo);
}
@willsza
willsza / cnpj-validator.ts
Created February 8, 2024 14:04
Validação de CNPJ
function validaCNPJ(cnpj: string): boolean {
cnpj = cnpj.replace(/\D/g, '');
if (cnpj.length !== 14 || /^(\d)\1+$/.test(cnpj)) return false;
const calcularDigito = (base: number) => {
const pesos = base === 12 ? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] : [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
let soma = 0;
for (let i = 0; i < base; i++) {
soma += parseInt(cnpj.charAt(i)) * pesos[i];
@willsza
willsza / cpf-validator.ts
Last active February 8, 2024 14:08
Validação de CPF
function validaCPF(cpf: string): boolean {
cpf = cpf.replace(/\D/g, '');
if (cpf.length !== 11 || /^(\d)\1+$/.test(cpf)) return false;
const calcularDigito = (base: number) => {
let soma = 0;
for (let i = 0; i < base - 1; i++) {
soma += parseInt(cpf.charAt(i)) * (base - i);
}
@willsza
willsza / Dockerfile
Last active December 15, 2019 17:12
Docker compose para Rails com Webpacker, Sidekiq e Redis
FROM ruby:2.5.5
RUN apt-get update && \
apt-get install -yqq apt-transport-https ca-certificates build-essential libpq-dev --fix-missing --no-install-recommends
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get update && \
apt-get install -yqq nodejs yarn
@willsza
willsza / spreadsheet_job.rb
Last active April 14, 2022 16:25
Job Rails to generate excel reports with Axlsx
require 'axlsx'
class SpreadsheetJob < ApplicationJob
queue_as :reports
def perform(*args)
@timestamp = args[0]['timestamp']
create_report
create_spreadsheet
module.exports = {
env: {
browser: true,
es6: true,
jest: true,
},
extends: [
'react-app',
'airbnb',
'plugin:@typescript-eslint/recommended',
@willsza
willsza / Gemfile
Last active June 10, 2017 11:42
Campo do form has many through não aparece (Utilizando a gem wicked)
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.1'
gem 'bootstrap-sass', '~> 3.3.7'
gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.1'
gem 'jquery-rails', '~> 4.2', '>= 4.2.2'
# Use SCSS for stylesheets
@willsza
willsza / _form.html.slim
Created September 26, 2015 23:43
Verificar conteúdo checkbox
= simple_form_for(@question) do |f|
= f.error_notification
.form-inputs
= f.association :page
= f.input :kind, collection: [ "Booleana", "Select", "Button", "Aberta" ], prompt: "Selecione o tipo de pergunta"
= f.input :title
= f.input :description_detailed, :as => :ckeditor, :input_html => { :ckeditor => {:toolbar => 'MyToolbar'} }
hr
@willsza
willsza / _goal.html.slim
Last active August 28, 2015 00:08
Select com simple_fields_for
.main-home
- @goals.each do |goal|
h1.text-center = goal.title
= simple_form_for goal do |f|
= f.error_notification
.form-group.text-center
= f.simple_fields_for :goal_options do |g|
= g.simple_fields_for :user_goal_options do |u|
@willsza
willsza / pages.coffee
Last active October 13, 2015 03:33
Código não funciona...
##########################################################
# Gerencia os campos selects do direcionamento das pages #
##########################################################
# Remove selects de direcionamento
$(document).on 'click', 'form .remove_fields', (event) ->
$(this).prev('input[type="hidden"]').val('1')
$(this).closest('.fields').hide()
event.preventDefault()