Skip to content

Instantly share code, notes, and snippets.

View Danziger's full-sized avatar
💾
01100011 01101111 01100100 01101001 01101110 01100111

Dani Gámez Franco Danziger

💾
01100011 01101111 01100100 01101001 01101110 01100111
View GitHub Profile
@Danziger
Danziger / keyjs.dev-keycodes.txt
Last active March 17, 2021 23:26
Plain text list of the most common keycodes and their values, as seen on https://keyjs.dev.
Easily check JavaScript KeyboardEvent properties (e.key, e.code, e.which,
e.keyCode… and more) with Key.js:
https://keyjs.dev
Key Code | Key Description
----------------------------
0 | Unidentified key
1 |
2 |
@Danziger
Danziger / FileChunksReader.js
Created April 14, 2020 08:22
Simple Node.js multi-process MapReduce. This was implemented as a weekend project in 2016, beware.
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
@Danziger
Danziger / input-state.hook.ts
Created February 13, 2020 22:26
Form Hooks
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 November 15, 2023 18:00
✨ Declarative useTimeout (setTimeout), useInterval (setInterval) and useThrottledCallback (useCallback combined with setTimeout) hooks for React (in Typescript)
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 February 6, 2019 22:38
Git commit-msg hook written in Python to validate that branch names and commit messages include matching references to their corresponding issue.
#!/usr/bin/python3
import sys
import re
import subprocess
PROJECT_IDS = ['SLO']
BRANCH_TYPES = ['feature', 'bug', 'hot']
@Danziger
Danziger / coding-test.js
Last active July 6, 2017 01:10
Simple JS coding test.
const users = [{
name: 'Charlie',
ranking: 30,
}, {
name: 'Alice',
ranking: 10,
}, {
name: 'Eve',
ranking: 40,
}, {
@Danziger
Danziger / rAF.js
Last active August 29, 2015 14:03 — forked from paulirish/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'];