Skip to content

Instantly share code, notes, and snippets.

View vitorjustin's full-sized avatar

Vitor Justin vitorjustin

View GitHub Profile
@vitorjustin
vitorjustin / form.html
Last active September 27, 2022 22:47
Máscara para input CPF somente HTML e JS puro
<input type="text" name="cpf" placeholder="CPF" required oninput="cpfMask(this);" pattern="\d{3}\.\d{3}\.\d{3}-\d{2}">
<script>
function cpfMask(i) {
let v = i.value;
let digits = v.replace(/[^0-9]/g, '').substring(0, 11);
let formatted = digits;
formatted = formatted.replace(/^(\d{3})(\d)/, "$1.$2");
formatted = formatted.replace(/^(\d{3})\.(\d{3})(\d)/, "$1.$2.$3");
@vitorjustin
vitorjustin / mysql.sh
Created November 17, 2021 12:30
MySQL export and import commands
#!/bin/bash
# https://twitter.com/fideloper/status/1460646396172939266/photo/1
# Export from one DB, import into another
mysqldump some_db_name | pv | mysql -h remote-host another_db_name
@vitorjustin
vitorjustin / Custom Share Icons (with count).markdown
Created June 29, 2015 01:22
Custom Share Icons (with count)

Custom Share Icons (with count)

The 1st-party sharing icons that are currently being provided are absolute garbage to work with. This pen tries to solve that by utilizing some simple AJAX calls that don't require the use of an API (see the note about Google+).

Since we aren't utilizing any API keys we don't need to worry about limits on requests - yay!

A Pen by Gray Gilmore on CodePen.

License.

@vitorjustin
vitorjustin / scroll-to.js
Last active August 29, 2015 14:16
scroll to snippet without framework dependency using requestAnimationFrame
;(function(window, document, undefined) {
// rAF polyfill
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
}
@vitorjustin
vitorjustin / ga-track-event.js
Created March 11, 2015 13:58
GA (Universal) event tracking
var noop = function () {};
var trackEvent = function () {
var ga = window.ga,
toArray = Array.prototype.slice,
params = ['send', 'event'].concat(toArray.call(arguments));
if (typeof ga === 'undefined') {
/*console.log('trackEvent');
console.log(params);*/
@vitorjustin
vitorjustin / imagePreload.js
Created March 10, 2014 22:28
simple image preloading
var preloadImages = function(images, callback) {
var current = 0,
imageEvtHandler = function() {
if (current++ === images.length && typeof callback === "function")
callback.call(this);
};
if (images.length > 0) {
for (var i = images.length - 1; 0 <= i; i--) {
var img = new Image;