Skip to content

Instantly share code, notes, and snippets.

View matpratta's full-sized avatar

Matheus Pratta matpratta

View GitHub Profile
@matpratta
matpratta / image-optimizer.js
Last active February 20, 2018 22:40
Easy-peasy image optimizer in jQuery. Enables page-wide lazy-loading.
/**
* jQuery Image Optimizer
* Lazy-loads images + background-images
* by Matheus Pratta <https://github.com/MatheusMK3>
*/
window.optimize_images = () => {
// Placeholder image, should be a 1x1 GIF in base64
var placeholder = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
@matpratta
matpratta / popups-infinitos.html
Created April 22, 2018 14:30
Exemplo de bug no Chrome, que permite criação de popups infinitos sem interação de usuário.
<!DOCTYPE html>
<html>
<head>
<title>Google Chrome Popup Bypass</title>
<script type="text/javascript">
/**
* Fonte: Custom Chromium Build to Reverse Engineer Pop-Under Trick <https://www.youtube.com/watch?v=y6Uzinz3DRU>
* Por algum motivo, os eventos "message" do Chrome são tratados como ações causadas pelo usuário, o que resulta na possibilidade de se criar popups infinitos, sem qualquer interação do usuário.
* Também possibilita exibir mais de um popup a partir de cliques de mouse e até mesmo a criação de "popunder", um popup que fica abaixo da janela atual.
*/
<?php
/**
* string find_best_match (string $word, array $db, float &$best_match_score);
* Compares $word with each ocurrence in $db, then results the closest matching string.
* Also returns how much both words matched in %.
*/
function find_best_match ($word, $db, &$best_match_score) {
// Initialize our comparison variables
$best_match = $word;
$best_match_score = 0;
<?php
/**
* Processa um menu do WordPress de acordo com a localização no tema
* Sintaxe: wpu_get_nav_menu ($localização, $returns = null)
* Sintaxe: wpu_get_nav_menu_array ($menu, $args = array())
* Autor: Matheus Pratta <eu@matheus.io>
*/
function wpu_get_nav_menu ($location, $returns = null) {
// Obtemos as posições de menu no tema
@matpratta
matpratta / fn.debug_object.js
Last active May 24, 2019 20:44
Returns a complete human-readable breakdown of a Javascript object
/**
* debug_object (1.0.0)
* Returns a complete human-readable breakdown of a Javascript object
* Author: Matheus Pratta <https://github.com/matheusmk3>
*/
function debug_object (obj, braces, level) {
// Recursion level
if (!level) level = braces ? 1 : 0;
// Identation
@matpratta
matpratta / OneDarkProX.itermcolors
Created April 17, 2019 06:54
My settings for CMD.exe colors, use with colortool
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Color Space</key>
<string>sRGB</string>
<key>Blue Component</key>
<real>0.20392156862745098</real>
@matpratta
matpratta / fn.textToCharBlocks.js
Created May 24, 2019 20:42
Converts a string of text into an array of text blocks
/**
* Converts a string of text into an array of text blocks with a maximum size of blockSize.
* @author Matheus Pratta <eu@matheus.io>
* @param {string} text
* @param {int} blockSize
* @returns {array}
*/
function textToCharBlocks (text, blockSize) {
let textBlocks = []; // Array containing our text blocks
let currentBlock = ''; // accumulator
@matpratta
matpratta / fn.debounce.js
Last active July 31, 2019 19:10
Função para debounce de eventos em Javascript
function debounce (fn, time) {
// Estado do throttle
let throttling = false
// Retorna uma função especial para fazer o debounce
return () => {
// Se estiver com throttle ativo, retornar
if (throttling) return;
// Ativa o throttle

Keybase proof

I hereby claim:

  • I am matheusmk3 on github.
  • I am matt_pratta (https://keybase.io/matt_pratta) on keybase.
  • I have a public key ASDtG3s8ze8nRwrdpdrAOs2cwtplnNiwkhHoXNAEzSTCvAo

To claim this, I am signing this object:

@matpratta
matpratta / fn.useragent-router.js
Created September 21, 2019 00:13
Very basic user-agent based router for Now.sh, to be coupled with @now/static-build builds.
const https = require('https')
let cachedIndex = null
let cachedIndexHeaders = null
// Function to handle our OpenGraph tags
const handleOpenGraphUA = ['Twitterbot', 'Facebot', 'facebookexternalhit']
const handleOpenGraph = (req, res) => {
// Check if we're serving Twitter or Facebook bots
const requestUA = req.headers['user-agent']