Skip to content

Instantly share code, notes, and snippets.

View celsobessa's full-sized avatar

Celso Bessa celsobessa

View GitHub Profile
@celsobessa
celsobessa / .bashrc
Created November 29, 2019 02:57
show git branch on your terminal prompt for unix like systems (unix, linux, macOs)
# Add this to ~/.bashrc
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="[\u@\h \W]\$(git_branch)\$ "
@celsobessa
celsobessa / wow-tooltip-legacy.0.3.0.js
Last active December 1, 2019 23:03
WoW Pure CSS Tooltip: an experiment fo pure CSS tooltip on anchor elements
/*!
* 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 / GoogleHackMasterList.txt
Created January 27, 2020 15:37 — forked from cmartinbaughman/GoogleHackMasterList.txt
The definitive super list for "Google Hacking".
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” 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 / 1. Refactoring - Original.js
Last active February 23, 2020 17:34 — forked from Integralist/1. Refactoring - Original.js
The importance of refactoring... (by Mark McDonnell ( https://gist.github.com/Integralist )
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 / git-track-fetch-pull-all-remote-branches.sh
Created July 27, 2020 18:56
Track, fetch and pull all remote branches on a remote GIT repository
# 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
@celsobessa
celsobessa / String.replaceAll.js
Created September 7, 2020 19:55
A more elegant implementation of a polyfill for replaceAll method on strings by Chris Ferdinandi (source https://vanillajstoolkit.com/polyfills/stringreplaceall/ )
/**
* 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 / wowp-batch-image-optimization.sh
Created September 11, 2020 20:32
Shell script for batch image optimization with Imageoptim from command line as used by WoWPerations team (www.wowperations.com.br)
# 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 / camelize.js
Created November 8, 2020 03:12
Convert hyphens to camelCase
function camelize(str) {
const camelizeRE = /-(\w)/g;
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '');
}
@celsobessa
celsobessa / byte-to-units.js
Created November 8, 2020 03:15
Convert byte units to reasonable units
// 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 / wp_add_preload_resource_hint.php
Created December 30, 2020 17:31
Writes preload resource hints to HTML element generated by wp_head function on WordPress.
// 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() {