Skip to content

Instantly share code, notes, and snippets.

View pauloabmiranda's full-sized avatar
🤓

Paulo Miranda pauloabmiranda

🤓
View GitHub Profile
const logPrefix = ['%cWDS', `background: ${'#f22c7c'}; color: white; padding: 2px 0.5em; border-radius: 0.5em;`];
console.log(...logPrefix, 'window.location: ', window.location);
git gc --prune=now
git remote prune origin
npm adduser --scope@company
npm init --scope=company
npm publish
// have not used this line but it grant access to a user
npm access grant read-only comapny:developers @company/wds-ckeditor4
@pauloabmiranda
pauloabmiranda / bocoup-training-more-efficient-event-handlers.js
Created September 26, 2017 10:14
Bocoup training: More Efficient jQuery Event Handlers
// Straightforward + simple.
$("button").on("click", function(event) {
event.preventDefault();
var button = $(this);
var numberElem = button.find(".number");
var number = Number(numberElem.text()) - 1;
numberElem.text(number);
if (number === 0) {
button.prop("disabled", true);
button.off("click");
@pauloabmiranda
pauloabmiranda / multiple-3rd-party-widgets.js
Created September 26, 2017 10:14
Loading multiple 3rd party widgets asynchronously
(function() {
var script,
scripts = document.getElementsByTagName('script')[0];
function load(url) {
script = document.createElement('script');
script.async = true;
script.src = url;
scripts.parentNode.insertBefore(script, scripts);
@pauloabmiranda
pauloabmiranda / criticalcss-bookmarklet-devtool-snippet.js
Created September 26, 2017 10:14
CriticalCSS Bookmarklet and Devtool Snippet.js
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@pauloabmiranda
pauloabmiranda / README.md
Created September 26, 2017 10:13
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@pauloabmiranda
pauloabmiranda / requestIdleCallback.js
Created September 26, 2017 10:13
Shims rIC in case a browser doesn't support it.
/*!
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
// on windows
// kill all instances of node
taskkill /f /im node.exe
//////////////////////////
// list all the processes on port 3000
netstat -ano | find "LISTENING" | find "3000"
// kill process 14828
@pauloabmiranda
pauloabmiranda / isImageLoaded.js
Last active September 24, 2015 13:43
Image Loading Complete
function isImageLoaded(image, $elem){
if(!image.complete){
requestAnimationFrame($.proxy(this.isImageLoaded, this, image, $elem));
}else{
$elem.removeClass('loading');
$elem.data("loaded", "true");
}
}