Skip to content

Instantly share code, notes, and snippets.

@WillRy
WillRy / remove.sh
Created May 21, 2021 18:57
Remove all branchs except list
git branch | grep -v "master\|develop\|homol" | xargs git branch -D
@WillRy
WillRy / delegate.js
Created December 23, 2020 21:29
DelegateEvent - Vanilla JS
function delegate(parent, event, selector, callback) {
const listener = (e) => {
const currentTarget = e.target.closest(selector);
if (!currentTarget) {
return;
}
const newEvent = {};
for (const i in e) {
newEvent[i] = e[i];
}
@WillRy
WillRy / main.js
Created November 6, 2020 12:13
Print Prototype Chain
function printProtoChain(element){
let proto = element.constructor.prototype;
let result = [];
while(proto){
result.push(proto.constructor.name);
proto = Object.getPrototypeOf(proto);
}
return result.join("->");
@WillRy
WillRy / instrucao.txt
Created September 24, 2020 21:32
criar template de commit no git
1 - Criar arquivo em algum lugar, preferencialmente ~/.gitmessage, com o conteudo:
########50 characters############################
Subject
########72 characters##################################################
Problem/Purpose
# Problem, Task, Reason for Commit
Solution
# Solution or List of Changes
Note
@WillRy
WillRy / index.php
Last active September 24, 2020 01:04
print-value-each-N-times
<?php
//each 3 times
$users_kicks = ['teste 1', 'teste 2', 'teste 3', 'teste 4', 'teste 1', 'teste 2', 'teste 3', 'teste 4', 'teste 1'];
foreach (array_chunk($users_kicks, 3, true) as $array) {
echo '<div class="row">';
foreach ($array as $kicks) {
echo "<div class='col-md-4'>$kicks</div>";
}
echo '</div>';
@WillRy
WillRy / docker-compose.yaml
Last active September 24, 2020 21:26
Teste com traefik, para limitar IPs que acessam determinados recursos
version: "3.7"
services:
proxy:
image: traefik:v2.2
command:
- "--api.insecure=true"
- "--providers.docker"
- "--log.level=DEBUG"
- "--providers.docker.swarmMode=true"
@WillRy
WillRy / phpcs.xml
Last active December 17, 2019 21:56
Configuração do CodeSniffer e PHP Mass detector para projetos laravel
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>Ajuste para PSRs 1|2|12</description>
<file>app</file>
<file>routes</file>
<file>resources/views</file>
<exclude-pattern>.(.js|.css|.blade.php)</exclude-pattern>
@WillRy
WillRy / app.js
Created November 11, 2019 22:48
separar parte inteira da decimal - JavaScript
// count = 2.5 => [2,0.5]
//separa parte inteira da decimal
const [int,dec] = count.toString().split('.').map(el => parseInt(el,10));
@WillRy
WillRy / Handler.php
Created April 12, 2019 00:14
Transform lumen exceptions to json format - Modified file: app\Exceptions\Handler.php
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;