Skip to content

Instantly share code, notes, and snippets.

@lucasmarques73
lucasmarques73 / .bashrc
Last active December 14, 2017 22:30
config .bashrc show branch in terminal
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# If not running interactively, don't do anything
@lucasmarques73
lucasmarques73 / ordemDecrescente.js
Last active August 11, 2017 12:06
Ordenando um array de forma decrescente utilizando for
var nums = [-23,61,18,30,8,-46,69,67,43,617];
for(i = 0; i < nums.length; i++)
{
if(nums[i] < nums[i+1])
{
aux = nums[i];
nums[i] = nums[i+1];
nums[i+1] = aux;
i = -1;
@lucasmarques73
lucasmarques73 / ordemCrescente.js
Created August 11, 2017 12:04
Ordenar array em ordem crescente utilizando sort()
var sortNumber = function(x, y)
{
return x - y;
};
var nums = [-23,61,18,30,8,-46,69,67,43,617];
nums.sort(sortNumber);
console.log(nums);
@lucasmarques73
lucasmarques73 / validarCNPJ.php
Last active June 14, 2017 11:36
Validar CNPJ PHP
public function validaCNPJ($cnpj)
{
// Lista de CNPJs inválidos
$invalidos = [
'00000000000000',
'11111111111111',
'22222222222222',
'33333333333333',
'44444444444444',
'55555555555555',
@lucasmarques73
lucasmarques73 / validarCPF.php
Last active June 14, 2017 11:36
Validar CPF PHP
public function validaCPF($cpf)
{
// determina um valor inicial para o digito $d1 e $d2
// pra manter o respeito ;)
$d1 = 0;
$d2 = 0;
// remove tudo que não seja número
$cpf = preg_replace("/[^0-9]/", "", $cpf);
// lista de cpf inválidos que serão ignorados
$ignore_list = array(
@lucasmarques73
lucasmarques73 / primeiraLetraDeCadaPalavraMaiusculo.php
Last active June 14, 2017 11:37
Primeira Letra em Maiúsuculo PHP
public function titleCase($string, $delimiters = array(" ", "-", ".", "'", "O'", "Mc"), $exceptions = array("de", "da", "dos", "das", "do", "I", "II", "III", "IV", "V", "VI"))
{
/*
* As exceções em minúsculas são palavras que você não deseja converter
* Exceções em maiúsculas são quaisquer palavras que você não quer converter para o caso do título
* Mas deve ser convertido em maiúscula, por exemplo:
* rei henry viii ou rei henry Viii deveria ser o rei Henrique VIII
*/
if (filter_var($string, FILTER_VALIDATE_EMAIL))
{
//Campos para criação da tabela UserSocial
$table->integer('user_id');
$table->string('social_network');
$table->string('social_id');
$table->string('social_email');
$table->string('social_avatar');
server {
listen 80;
server_name CHANGEME.app; /*Alterar para nome do projeto */
root /var/www/vhosts/CHANGEME.app/public; /*Alterar para caminho do projeto */
index index.html index.htm index.php;
charset utf-8;
location / {
@lucasmarques73
lucasmarques73 / playlist_time.js
Created January 27, 2017 17:37 — forked from fredericogg/playlist_time.js
Calcula o tempo total de uma playlist no Youtube. É só colar no console na página da playlist. Fiz esse script porque não achei o tempo total da playlist 😅.
(function() {
var timeSeconds = 0;
var timestampDivList = document.querySelectorAll(".timestamp");
for(var i = 0; i < timestampDivList.length; i++) {
var timestampDiv = timestampDivList[i];
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->