Skip to content

Instantly share code, notes, and snippets.

@SHND
SHND / keymap.ts
Created December 10, 2019 17:24
Assign keyboard shortkeys to document.
function noop(){};
function createKeydownListener(key: string, modifiers: string[] = [], cb: Function = noop) {
const shouldHaveAlt: Boolean = modifiers.includes(keymap.ALT);
const shouldHaveCtrl: Boolean = modifiers.includes(keymap.CTRL);
const shouldHaveMeta: Boolean = modifiers.includes(keymap.META);
const shouldHaveShift: Boolean = modifiers.includes(keymap.SHIFT);
return function (event: KeyboardEvent) {
if (event.keyCode !== key.toUpperCase().charCodeAt(0))
@SHND
SHND / keymap.js
Created December 10, 2019 17:27
Assign keyboard shortcuts to document
"use strict";
function noop() { }
;
function createKeydownListener(key, modifiers = [], cb = noop) {
const shouldHaveAlt = modifiers.includes(keymap.ALT);
const shouldHaveCtrl = modifiers.includes(keymap.CTRL);
const shouldHaveMeta = modifiers.includes(keymap.META);
const shouldHaveShift = modifiers.includes(keymap.SHIFT);
return function (event) {
if (event.keyCode !== key.toUpperCase().charCodeAt(0))
@SHND
SHND / vscode_settings.json
Created December 21, 2019 19:03
visual studio code settings
{
"workbench.colorTheme": "Material Theme High Contrast",
"editor.multiCursorModifier": "ctrlCmd",
"sublimeTextKeymap.promptV3Features": true,
"editor.fontLigatures": true,
"terminal.integrated.shell.osx": "/bin/zsh",
"terminal.integrated.fontFamily": "Hack Nerd Font, Source Code Pro for Powerline, Meslo LG S for Powerline",
"editor.cursorBlinking": "smooth",
"editor.cursorSmoothCaretAnimation": true,
"editor.cursorWidth": 2,
@SHND
SHND / DisjointSet.js
Created December 25, 2020 00:19
Simple Disjoint Set
function DJSet() {
this.nodes = new Map(); // id -> Node
this.sets = new Map(); // id -> Node
}
function Node(id) {
this.id = id;
this.rank = 0;
this.parent = this;
}
@SHND
SHND / LinkedList.js
Last active December 27, 2020 01:44
Simple double LinkedList JavaScript implementation
/**
* LinkedList Node Class
*/
function Node(tree, value, next = null, prev = null) {
this.tree = tree;
this.value = value;
this.next = next;
this.prev = prev;
}
@SHND
SHND / typescript_type_calculation.ts
Last active December 11, 2021 22:38
Typescript Type calculation and manipulation (Utility Types)
/**
* TypeScript Type Calculations (Utility Types)
*/
/** ==================
* Interface
==================== */
/** Example */
interface Person {