Skip to content

Instantly share code, notes, and snippets.

View ayozebarrera's full-sized avatar
⚛️
Reacting

Ayoze Barrera ayozebarrera

⚛️
Reacting
View GitHub Profile
@ayozebarrera
ayozebarrera / hyperjs.md
Created May 2, 2020 09:26 — forked from raftheunis87/hyperjs.md
Hyper.js + Hyper.js Plugins + ZSH + Starship + Fira Code + Dark Theme - (macOS)

Hyper.js

@ayozebarrera
ayozebarrera / async-await.js
Created May 28, 2018 10:42 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@ayozebarrera
ayozebarrera / AppDispatcher.js
Created December 18, 2017 16:48 — forked from tgroshon/AppDispatcher.js
A Flux Dispatcher with an Action Queue sitting on top to allow dispatching actions at any time.
/**
* Create an ActionQueue and dispatch each synchronously
* @author tgroshon
*
* See an alternate implementation using ASync from
* https://github.com/facebook/flux/issues/106
* by fabiozaffani
*/
import {Dispatcher} from 'flux'
@ayozebarrera
ayozebarrera / fix.md
Created September 22, 2017 11:14
How to fix `rm -f .git/index`

How to fix rm -f .git/index

Ever gotten this message?

fatal: Unable to create '/path/to/repo/.git/index.lock': File exists.

If no other git process is currently running, this probably means a git process crashed in this repository earlier. Make sure no other git process is running and remove the file manually to continue.

@ayozebarrera
ayozebarrera / README.md
Created July 24, 2017 08:17 — forked from joyrexus/README.md
Nested grouping of arrays

nest.js

A multi-level groupBy for arrays inspired by D3's nest operator.

Nesting allows elements in an array to be grouped into a hierarchical tree structure; think of it like the GROUP BY operator in SQL, except you can have multiple levels of grouping, and the resulting output is a tree rather than a flat table. The levels in the tree are specified by key functions.

See this fiddle for live demo.

@ayozebarrera
ayozebarrera / coor2tile.js
Last active April 24, 2017 13:52
Coordinates to tile
// http://tile.openstreetmap.org/z/x/y.png
// example: http://tile.openstreetmap.org/12/2225/2367.png
lon2tile = (lon, zoom) => {
return (Math.floor((lon+180)/360*Math.pow(2,zoom)));
};
lat2tile = (lat, zoom) => {
return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom)));
};
@ayozebarrera
ayozebarrera / materialAccents.js
Created December 12, 2016 18:38 — forked from rileyjshaw/materialAccents.js
Return an array of accent colors from Google's [Material Design guide](http://www.google.com/design/spec/style/color.html)
[].filter.call(document.querySelectorAll('.color-group .color'), function(el) {
return el.querySelector('.shade').textContent === 'A400';
}).map(function (el) {
return el.querySelector('.hex').textContent;
});
@ayozebarrera
ayozebarrera / removeDuplicates.js
Created August 17, 2016 08:27
ES6 function that removes duplicated objects with the specified prop
/**
* removes duplicated objects with the specified prop
* @param {Array} myArr [our collection to check]
* @param {String} prop [name of the property to compare]
* @return {Array} [unique array]
*/
removeDuplicates = (myArr, prop) => {
return myArr.filter((obj, pos, arr) => {
return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos;
});
@ayozebarrera
ayozebarrera / random.js
Created July 19, 2016 16:35 — forked from kerimdzhanov/random.js
Javascript get random number in a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {float} a random floating point number
*/
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}
@ayozebarrera
ayozebarrera / example.js
Created January 8, 2016 10:00 — forked from samwgoldman/example.js
Pure, stateless, type-checked React components with Immutable.js and Flow
/* @flow */
var React = require("react")
var Immutable = require("immutable")
// In order to use any type as props, including Immutable objects, we
// wrap our prop type as the sole "data" key passed as props.
type Component<P> = ReactClass<{},{ data: P },{}>
type Element = ReactElement<any, any, any>