Skip to content

Instantly share code, notes, and snippets.

Avatar
💾
01100011 01101111 01100100 01101001 01101110 01100111

Dani Gámez Franco Danziger

💾
01100011 01101111 01100100 01101001 01101110 01100111
View GitHub Profile
@Danziger
Danziger / FileChunksReader.js
Created Apr 14, 2020
Simple Node.js multi-process MapReduce. This was implemented as a weekend project in 2016, beware.
View FileChunksReader.js
const fs = require('fs');
module.exports = class FileChunksReader {
constructor(filepaths, callback, config = {}) {
if (!Array.isArray(filepaths) || filepaths.length < 1 || typeof callback !== 'function') {
throw new Error('Constructor signature not matching actual parameters.');
}
this.options = {
chunkSize: config.chunkSize || 1024, // 1 KB
View input-state.hook.ts
import { useCallback, useEffect, useRef, useState } from 'react';
import { FIELD_THROTTLE_RATE } from '../../components/form/form.constants';
import { getFakeChangeEvent } from '../../components/form/utils/form-events.utils';
import { FormValue } from '../../data/common/types/common.types';
import { useThrottledCallback } from './throttled-callback.hook';
export function useInputState<V extends FormValue = FormValue>(
initialValue: V,
@Danziger
Danziger / interval.hook.ts
Last active Dec 11, 2020
Declarative useTimeout (setTimeout), useInterval (setInterval) and useThrottledCallback (useCallback combined with setTimeout) hooks for React (in Typescript)
View interval.hook.ts
import React, { useEffect, useRef } from 'react';
/**
* Use setInterval with Hooks in a declarative way.
*
* @see https://stackoverflow.com/a/59274004/3723993
* @see https://overreacted.io/making-setinterval-declarative-with-react-hooks/
*/
export function useInterval(
callback: React.EffectCallback,
@Danziger
Danziger / commit-msg
Last active Feb 6, 2019
Git commit-msg hook written in Python to validate that branch names and commit messages include matching references to their corresponding issue.
View commit-msg
#!/usr/bin/python3
import sys
import re
import subprocess
PROJECT_IDS = ['SLO']
BRANCH_TYPES = ['feature', 'bug', 'hot']
@Danziger
Danziger / coding-test.js
Last active Jul 6, 2017
Simple JS coding test.
View coding-test.js
const users = [{
name: 'Charlie',
ranking: 30,
}, {
name: 'Alice',
ranking: 10,
}, {
name: 'Eve',
ranking: 40,
}, {
View rAF.js
// requestAnimationFrame POLYFILL ////////////////////////////////////////////////////////////////////
// requestAnimationFrame and cancelAnimationFrame polyfill based on Erik Möller's one: https://gist.github.com/paulirish/1579671
// MDN Docs: https://developer.mozilla.org/es/docs/DOM/window.requestAnimationFrame
// @source https://gist.github.com/Danziger/fc83f1b2f16f70655a4a
// @license MIT license
(function(strict, calculations){
"use strict";
var vendors = ['webkit', 'moz', 'ms', 'o'];