Skip to content

Instantly share code, notes, and snippets.

View jherax's full-sized avatar
👾
Performance focused

David Rivera jherax

👾
Performance focused
View GitHub Profile
@jherax
jherax / install.sh
Last active May 30, 2020 15:41 — forked from wdullaer/install.sh
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
@jherax
jherax / clone.js
Last active May 30, 2020 15:42
Clones or extends an object (deep copy) supporting objects with circular references
/**
* @author
* David Rivera (jherax)
* https://github.com/jherax
*/
/* eslint-disable no-bitwise */
/** @private */
const toString = Object.prototype.toString;
@jherax
jherax / _parseValue.js
Last active May 30, 2020 15:42
Gets values from the url search
/* eslint-disable no-underscore-dangle */
/**
* Supported types
*/
const TYPES = {
_true: /^true$/i,
_false: /^false$/i,
_null: /^null$/i,
_number: /^[0-9]+$/,
@jherax
jherax / customError.js
Last active May 30, 2020 15:43
JavaScript: Custom Error Builder
// Creates user-defined exceptions
var CustomError = (function() {
'use strict';
//constructor
function CustomError() {
//enforces 'new' instance
if (!(this instanceof CustomError)) {
return new CustomError(arguments);
}
@jherax
jherax / createNS.js
Created May 26, 2015 04:00
JavaScript: Crear namespaces
//utility to create safe namespaces
function createNS (namespace) {
var nsparts = namespace.toString().split("."),
reName = (/^[A-Za-z_]\w+/),
cparent = window,
i, subns, nspartsLength;
// we want to be able to include or exclude the root namespace so we strip it if it's in the namespace
if (nsparts[0] === "window") nsparts = nsparts.slice(1);
// loop through the parts and create a nested namespace if necessary
for (i = 0, nspartsLength = nsparts.length; i < nspartsLength; i += 1) {
@jherax
jherax / js-delete-properties.js
Created May 26, 2015 03:14
JavaScript: Eliminar propiedades
(function() {
//verificamos cual es el ámbito global
//(generalmente el objeto window)
console.log("Global scope", this);
var x = 42; //variable local
var point = { x: 10, y: 15 }; //objeto local
//si no se especifica el keyword "var",
@jherax
jherax / what-forces-layout.md
Created June 15, 2020 18:09 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@jherax
jherax / get-headers.ts
Last active April 19, 2021 15:34
Gets all Response Headers for the current document
/**
* Gets all Reponse Headers for the current document.
* @returns An object cointaining the key-value pairs for each header
*/
function getHeaders(url = document.location.href) {
const req = new XMLHttpRequest();
req.open("GET", url, false);
req.send(null);
let key: string;
@jherax
jherax / sortBy.js
Last active May 31, 2021 07:50
Sorts an array with multiple ordering criteria (Schwartzian transform)
/**
* Sorts an array and allows multiple sorting criteria.
*
* It applies the Schwartzian transform:
* https://en.wikipedia.org/wiki/Schwartzian_transform
*
* Author: David Rivera
* Github: https://github.com/jherax
*
* You can fork this project on github:
@jherax
jherax / multi-entries.js
Last active November 14, 2021 17:47
Load multiple entries in webpack
var glob = require('glob');
module.exports = {
entry: toObject(glob.sync('assets/**/*.js*')),
output: {
filename: '[name].js'
},
//...
};