Skip to content

Instantly share code, notes, and snippets.

@papalardo
papalardo / getPaginateInterval.js
Last active December 24, 2018 01:10
Array paginate interval JS
function getInterval(totalItens = 100, perPage = 10, maxShowingNumbers = 5, currentPage = 1) {
let lastPage = Math.ceil(totalItens / perPage)
if (totalItens < 0 ) {
console.error(`Total of itens cant be less or equal than 0`)
return;
} else if (lastPage > 0 && currentPage > lastPage) {
console.error(`Current page [${currentPage}] cant be bigger than last page [${lastPage}]`)
return;
/* TABLE */
@media screen and (max-width: 63.9375em) {
}
/* MOBILE */
@media screen and (max-width: 39.9375em) {
}
@papalardo
papalardo / utilities.js
Last active March 11, 2019 19:52
Utilities to front end developer
// SVG Inject
https://github.com/iconfu/svg-inject
// Check if is Mobile
window.mobilecheck = function () {
var check = false;
(function (a) {
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)
@papalardo
papalardo / getStatesWithCitys.php
Last active February 3, 2019 15:39
Listar estado com cidades do Brasil
$path = './api';
$filename = 'estados.json';
$filePath = $path .'/'. $filename;
if(file_exists($filePath)) {
$content = json_decode(file_get_contents($filePath), true);
return $content;
}
$somenteEssesEstados = ['RJ', 'SP'];
@papalardo
papalardo / ClockWidget.vue
Created May 2, 2019 01:56
Realtime clock VueJS
<template>
<div class="callout calendar-day">
<div class="grid-x align-middle align-middle">
<div class="shrink cell">
<h1>{{ this.momentInstance.format('DD') }}</h1>
</div>
<div class="auto cell">
<h6>{{ this.momentInstance.format('[de] MMMM [de] YYYY') }}</h6>
<h6 class="light">{{ this.momentInstance.format('dddd[.] HH:mm:ss') }} </h6>
</div>
const normalize = str => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
let text = "Lorem Ipsum íís simply dummy tééxt of the printing and typesetting industry.";
let termSearch = 'lorem iss';
text = normalize(text).toLowerCase();
termSearch = normalize(termSearch).toLowerCase();
multiSearchAnd:
(text, searchWords) =>
// https://github.com/sindresorhus/is-regexp
const isRegex = input => Object.prototype.toString.call(input) === '[object RegExp]';
// https://github.com/sindresorhus/clone-regexp
const cloneRegexp = (e,n={}) =>{if(!isRegexp(e))throw new TypeError("Expected a RegExp instance");const t=Object.keys({ global: 'g', ignoreCase: 'i', multiline: 'm', dotAll: 's', sticky: 'y', unicode: 'u' }).map(t=>("boolean"==typeof n[t]?n[t]:e[t])?{ global: 'g', ignoreCase: 'i', multiline: 'm', dotAll: 's', sticky: 'y', unicode: 'u' }[t]:"").join(""),a=new RegExp(n.source||e.source,t);return a.lastIndex="number"==typeof n.lastIndex?n.lastIndex:e.lastIndex,a};
// https://github.com/andrewrk/node-diacritics
let replacementList = [{ base: ' ', chars: "\u00A0", }, { base: '0', chars: "\u07C0", }, { base: 'A', chars: "\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F", }, { base: 'AA', c
@papalardo
papalardo / birthdays_between_dates_laravel.php
Last active December 22, 2022 17:56
Get birthdays users laravel
<?php
use Carbon\CarbonPeriod;
// On user model
public function scopeBirthdayBetween($query, $dateBegin, $dateEnd)
{
$period = CarbonPeriod::create($dateBegin, $dateEnd);
foreach ($period as $key => $date) {
@papalardo
papalardo / whatsapp_download_audio.js
Created October 6, 2020 22:34
Whatsapp download and concat audios
class Crunker {
constructor({ sampleRate = 44100 } = {}) {
this._sampleRate = sampleRate;
this._context = this._createContext();
}
_createContext() {
window.AudioContext =
window.AudioContext ||
window.webkitAudioContext ||
const IgApiClient = require('instagram-private-api').IgApiClient;
const ig = new IgApiClient();
// Suas credenciais (para algumas ações, inclusive buscar imagens, é obrigatório)
const userName = 'papalardo';
const userPassword = '';
// Para buscar o id do usuário acesse: https://codeofaninja.com/tools/find-instagram-user-id/
const userId = '40266287952';
// Gera estado - Obrigatório