Skip to content

Instantly share code, notes, and snippets.

View edgarberm's full-sized avatar
:octocat:
NaN

Edgar Bermejo edgarberm

:octocat:
NaN
View GitHub Profile
$ brew update
$ brew install nvm
$ mkdir ~/.nvm
# in your ~/.zshrc or in .bash_profile
$ export NVM_DIR=~/.nvm
$ source $(brew --prefix nvm)/nvm.sh
@edgarberm
edgarberm / donut.html
Created June 19, 2019 12:35
d3js (v5) donut chart
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<title>Donut</title>
<style>
@edgarberm
edgarberm / deepFreeze.js
Last active June 21, 2017 10:29
Deep freeze ❄️
/**
* Freeze nested objects
*
* const dude = deepFreeze({
* name: 'John',
* lastname: 'Doe',
* address: {
* street: 'Wall Street',
* number: '62'
* }
@edgarberm
edgarberm / .sh
Created April 3, 2017 23:37
Remove remote node_modules
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
@edgarberm
edgarberm / asyncLoop.js
Created December 22, 2016 17:26
Asynchronous iterations
/**
* Asynchronous Loop
* @param {Int}
* @param {Function}
* @param {Function}
* @return {Object}
*
*
* Usage:
*
@edgarberm
edgarberm / roman.js
Last active September 29, 2016 08:40
Converts a number to a Roman numeral string
const roman = (n) => {
n = String(Math.floor(Math.abs(n)))
let element, i, result = ''
const table = [
['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'],
['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'],
['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM']
]
for (i = 0; i < table.length; i += 1) {
@edgarberm
edgarberm / now.js
Created September 5, 2016 06:28
Get formatted date
export const repeat = (str, times) => (new Array(times + 1)).join(str);
export const padStart = (num, maxLength, char = ' ') => repeat(char, maxLength - num.toString().length) + num;
export const formatTime = (time) => {
const h = padStart(time.getHours(), 2, '0');
const m = padStart(time.getMinutes(), 2, '0');
const s = padStart(time.getSeconds(), 2, '0');
const ms = padStart(time.getMilliseconds(), 3, '0');
return `${h}:${m}:${s}.${ms}`;
@edgarberm
edgarberm / clamp.js
Created August 4, 2016 10:29
Returns a number whose value is limited to the given range
clamp (n, min, max) {
return Math.max(Math.min(n, max), min)
}
@edgarberm
edgarberm / range.js
Created August 4, 2016 10:28
Returns a numeric range by passing the upper limit
range (num) {
return [...Array(num).keys()]
}
@edgarberm
edgarberm / assignPrototypeMethods.js
Created July 14, 2016 15:44
Copy the prototype methods of the given constructor method into the given context, if they do not already exist.
const assignPrototypeMethods = ( constructorMethod, context ) => {
// Loop over the BaseController's prototype methods and assign them to the current context
for ( var methodName in constructorMethod.prototype ) {
if (constructorMethod.prototype.hasOwnProperty( methodName ) && !context[ methodName ]) {
// Copy the method into the current controller context.
context[ methodName ] = constructorMethod.prototype[ methodName ];
}
}
}