Skip to content

Instantly share code, notes, and snippets.

Avatar

Celso Bessa celsobessa

View GitHub Profile
@celsobessa
celsobessa / wp_add_preload_resource_hint.php
Created Dec 30, 2020
Writes preload resource hints to HTML element generated by wp_head function on WordPress.
View wp_add_preload_resource_hint.php
// Adds preload resource hint to wp_head hook
add_action( 'wp_head', 'add_preload_resource_hint', -1);
/**
* Writes preload resource hints.
*
* Writes preload resource hints.
*/
function add_preload_resource_hint() {
@celsobessa
celsobessa / byte-to-units.js
Created Nov 8, 2020
Convert byte units to reasonable units
View byte-to-units.js
// https://medium.com/javascript-in-plain-english/7-javascript-utility-functions-to-improve-your-efficiency-79d27132f186
function bytesToSize (bytes) {
if (bytes === 0) return '0 B';
var k = 1024;
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
var i = Math.floor(Math.log(bytes) / Math.log(k))
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i]
}
@celsobessa
celsobessa / camelize.js
Created Nov 8, 2020
Convert hyphens to camelCase
View camelize.js
function camelize(str) {
const camelizeRE = /-(\w)/g;
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '');
}
@celsobessa
celsobessa / wowp-batch-image-optimization.sh
Created Sep 11, 2020
Shell script for batch image optimization with Imageoptim from command line as used by WoWPerations team (www.wowperations.com.br)
View wowp-batch-image-optimization.sh
# Batch image optimization with Imageoptim from command line as used by WoWPerations team (www.wowperations.com.br
mdfind -onlyin . "kMDItemPixelWidth<480 && kMDItemContentType=public.jpg" > imagesLess480JPG.txt
mdfind -onlyin . "kMDItemPixelWidth>479 && kMDItemPixelWidth<760 && kMDItemContentType=public.jpg" > imagesLess760JPG.txt
mdfind -onlyin . "kMDItemPixelWidth>759 && kMDItemPixelWidth<1024 && kMDItemContentType=public.jpg" > imagesLess1024JPG.txt
mdfind -onlyin . "kMDItemPixelWidth>1023 && kMDItemPixelWidth<1280 && kMDItemContentType=public.jpg" > imagesLess1280JPG.txt
@celsobessa
celsobessa / String.replaceAll.js
Created Sep 7, 2020
A more elegant implementation of a polyfill for replaceAll method on strings by Chris Ferdinandi (source https://vanillajstoolkit.com/polyfills/stringreplaceall/ )
View String.replaceAll.js
/**
* String.prototype.replaceAll() polyfill
* https://vanillajstoolkit.com/polyfills/stringreplaceall/
* @author Chris Ferdinandi
* @license MIT
*/
if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function(str, newStr){
// If a regex pattern
@celsobessa
celsobessa / git-track-fetch-pull-all-remote-branches.sh
Created Jul 27, 2020
Track, fetch and pull all remote branches on a remote GIT repository
View git-track-fetch-pull-all-remote-branches.sh
# Track, fetch and pull all remote branches on a remote GIT repository
# Source: https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches/10312587#10312587
git branch -r | grep -v '\->' | while read remote;
do git branch --track "${remote#origin/}" "$remote";
done
git fetch --all
git pull --all
View 1. Refactoring - Original.js
var isProxyBased = (/S40[\w]{3,5}Browser|Opera\sMini\//i).test(navigator.userAgent);
if (('querySelector' in document && 'localStorage' in window && 'addEventListener' in window && !isProxyBased) || (isIE > 6 && document.getElementById('js-holepunched'))) {
// do stuff
}
@celsobessa
celsobessa / GoogleHackMasterList.txt
Created Jan 27, 2020 — forked from cmartinbaughman/GoogleHackMasterList.txt
The definitive super list for "Google Hacking".
View GoogleHackMasterList.txt
admin account info" filetype:log
!Host=*.* intext:enc_UserPassword=* ext:pcf
"# -FrontPage-" ext:pwd inurl:(service | authors | administrators | users) "# -FrontPage-" inurl:service.pwd
"AutoCreate=TRUE password=*"
"http://*:*@www&#8221; domainname
"index of/" "ws_ftp.ini" "parent directory"
"liveice configuration file" ext:cfg -site:sourceforge.net
"parent directory" +proftpdpasswd
Duclassified" -site:duware.com "DUware All Rights reserved"
duclassmate" -site:duware.com
@celsobessa
celsobessa / wow-tooltip-legacy.0.3.0.js
Last active Dec 1, 2019
WoW Pure CSS Tooltip: an experiment fo pure CSS tooltip on anchor elements
View wow-tooltip-legacy.0.3.0.js
/*!
* WoW Pure CSS Tooltip: an experiment fo pure CSS tooltip on anchor elements.
*
* This script sets the `aria-label` attribute on all anchors if it's not set or empty.
* It uses the contents of the `title` attribute, if present, and remove the title
* attribute in order to avoid the browser native tooltip.
* Meant to be used with the companion WoW Pure CSS Tooltip styles.
*
* See: https://gist.github.com/celsobessa/c98e45d2074be5cd915febfed37feeda
* (c) 2019 Celso Bessa, MIT License, https://www.celsobessa.com.br
@celsobessa
celsobessa / .bashrc
Created Nov 29, 2019
show git branch on your terminal prompt for unix like systems (unix, linux, macOs)
View .bashrc
# Add this to ~/.bashrc
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="[\u@\h \W]\$(git_branch)\$ "