Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
never stop.

Matheus Pratta MatheusMK3

💭
never stop.
View GitHub Profile
@MatheusMK3
MatheusMK3 / fn.flatten_redirect_chain.php
Created Aug 17, 2020
🔗 Follows a redirect chain path and either redirects to the final URL or returns it
View fn.flatten_redirect_chain.php
/**
* fn.flatten_redirect_chain.php
* Follows a redirect chain path and either redirects to the final URL or returns it
* Author: Matheus Pratta <github.com/matheusmk3>
* License: 0BSD
* Version: 1.0.0
*
* @param string $destination The URL that is part of a redirect chain and shall be resolved
* @param mixed $redirect The redirect type to be used (301/302) or false for returning the final URL as string
*
@MatheusMK3
MatheusMK3 / cron-fix-wordpress-upload-permissions.sh
Last active Apr 1, 2020
🔧 Fixes WordPress upload directories permissions being set to root, use it with crontab.
View cron-fix-wordpress-upload-permissions.sh
#!/bin/bash
# Set this to your server's owner user (normally www-data)
user="www-data:www-data"
# Set this to the path to your wp-content
wp_content_path="/var/www/html/wp-content"
# Gets current year and month numbers
year=`date +%Y`
View connect-displaylink.sh
@MatheusMK3
MatheusMK3 / fix.wp-mysql8-onlyfullgroupby.php
Last active Oct 24, 2019
🔧 Fixes errors regarding ONLY_FULL_GROUP_BY when using WordPress with managed database services using MySQL 8.
View fix.wp-mysql8-onlyfullgroupby.php
<?php
/*
Plugin Name: WP Managed MySQL 8 Fix
Plugin URI: https://gist.github.com/MatheusMK3/4f3acb29ac4fb0e9a03318bcacec1972
Description: Fixes issues regarding MySQL modes (ONLY_FULL_GROUP_BY) when on managed database services.
Author: Matheus Pratta
Version: 1.0.0
Author URI: https://matheus.io
*/
@MatheusMK3
MatheusMK3 / fn.useragent-router.js
Created Sep 21, 2019
Very basic user-agent based router for Now.sh, to be coupled with @now/static-build builds.
View fn.useragent-router.js
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']
View keybase.md

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:

@MatheusMK3
MatheusMK3 / fn.debounce.js
Last active Jul 31, 2019
Função para debounce de eventos em Javascript
View fn.debounce.js
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
@MatheusMK3
MatheusMK3 / fn.textToCharBlocks.js
Created May 24, 2019
Converts a string of text into an array of text blocks
View fn.textToCharBlocks.js
/**
* 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
@MatheusMK3
MatheusMK3 / OneDarkProX.itermcolors
Created Apr 17, 2019
My settings for CMD.exe colors, use with colortool
View OneDarkProX.itermcolors
<?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>
@MatheusMK3
MatheusMK3 / fn.debug_object.js
Last active May 24, 2019
Returns a complete human-readable breakdown of a Javascript object
View fn.debug_object.js
/**
* 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