Skip to content

Instantly share code, notes, and snippets.

View jimmy-collazos's full-sized avatar

Jimmy Collazos jimmy-collazos

View GitHub Profile
@jimmy-collazos
jimmy-collazos / juego-de-la-vida.js
Created November 19, 2019 23:28
El juego de la vida
function getFactory(ls) {
return function(x, y) {
return Array.isArray(ls[y]) ? (ls[y][x] === undefined && [] || [ls[y][x]]) : [];
}
}
function getNeighbors(x, y, ls){
const get = getFactory(ls);
return [
get(x-1, y+1), get(x, y+1), get(x+1, y+1),
get(x-1, y), get(x, y), get(x+1, y),
@jimmy-collazos
jimmy-collazos / launch.json
Created December 14, 2018 08:08
VS Code config - Debug Jest tests
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Launch attach by process ID",
"processId": "${command:PickProcess}"
},
@jimmy-collazos
jimmy-collazos / curry.mjs
Created August 1, 2018 07:32
Helper function - curry()
export const curry = (
f,
arr = [],
length = f.length
) => (...args) => (
a => a.length === length && f(...a) || curry(f, a)
)([...arr, ...args]);
@jimmy-collazos
jimmy-collazos / promise.isPending.js
Created July 19, 2018 12:28
Helper Promise - isPending()
/**
* Check if Promise is pendding to resolve. Use in Asyn-Await
*
* Example;
*
* const { isPending } = require('promise.helper')
* it('Check if promise is pending', async function () {
* const promise = load(path);
* console.assert(await isPending(promise))
* await promise;
@jimmy-collazos
jimmy-collazos / sleep.js
Last active July 19, 2018 12:31
Helper function - sleep()
/**
* Create Promise pending to resolve after N milliseconds
* Example async-await:
* const { sleep } = require('sleep')
* //...
* it ('Should resolve after 100 millisiconds', async function () {
* let Module = load(path)
* await sleep(100)
* expect (Module.status).to.be.equal('resolved')
* })
function deleteFolderRecursive(path) {
if(fs.existsSync(path)) {
fs.readdirSync(path).forEach(function(file, index) {
var curPath = path + '/' + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
@jimmy-collazos
jimmy-collazos / iterm2-colors.sh
Last active August 29, 2015 13:57
muestra la paleta de colores de iTerm2
#!/bin/bash
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
# @see https://github.com/mbadolato/iTerm2-Color-Schemes/issues/6
@jimmy-collazos
jimmy-collazos / toflv.sh
Last active July 19, 2018 19:39
to FLV
#!/bin/bash
# ffmpeg:
#
# -y -> sobreescribe archivo de salida
# -i ‘videoentrada.avi’ -> archivo de entrada
# -threads 2 -> hilos de decodificación
# -s 320×240 -> Tamaño de salida
# -r 30.00 -> Velocidad de cuadro (fps, cuadros x segundo)
# -threads 1 -> hilo de decodificación
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>Css class name like icon</title>
</head>
<body>
<p class="l__al">
@jimmy-collazos
jimmy-collazos / TrajectoryMarkers.js
Created July 18, 2012 11:17
Esta librería se usa para poner multiples marcas (generalmente flechas indicando la dirección) en un trayecto y mostrar sólo las que no colapsan entre si; dejando una distancia en pixeles entre dos marcas.
var TrajectoryMarkers = function(map, arrayMarkers, separation){
this.set('markers', arrayMarkers || []);
this.set('separation', separation || 50);//pixeles de separación
this.setMap(map);
}
TrajectoryMarkers.prototype = new google.maps.OverlayView();
TrajectoryMarkers.prototype.onAdd = function(){
var self = this;
google.maps.event.addListener(this.getMap(), 'zoom_changed', function(){
self.draw();