Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am rendall on github.
  • I am rendall (https://keybase.io/rendall) on keybase.
  • I have a public key ASCQAUvXTIMQUOpgwMnEjjU96nXmB0_pV-oqdZb2LwM3ego

To claim this, I am signing this object:

@rendall
rendall / InfernoJSX.d.ts
Last active October 11, 2017 21:20
Inferno JSX Typescript type definitions
// This gist is deprecated. The repo for this file is now here:
// https://github.com/rendall/inferno-jsx-type-definitions/blob/master/InfernoJSX.d.ts
// This is lightly modified version of the React typedefs with 'React' replaced by 'InfernoJSX'.
// Use it as you would any @type library, and it will stop that annoying typescript / jsx error
// when you're using Typescript with Inferno.
// Please do let me know of any problems or issues: https://github.com/rendall
// Inferno's VNode is compatible with JSX.Element, so you can do something like this:
@rendall
rendall / InfernoRouterJSX.d.ts
Last active September 29, 2017 12:17
TSX type definitions for the Inferno library 'inferno-router'
// The repo for this file is now here: https://github.com/rendall/inferno-jsx-type-definitions/blob/master/InfernoRouterJSX.d.ts
// This gist is deprecated.
// This is a lightly modified version of the react-router typedefs, to be used alongside InfernoJSX.d.ts: https://gist.github.com/rendall/cdd23c962c88fac3dbd9322cc2b09d58
// Please do let me know of any problems or issues: https://github.com/rendall
// Type definitions for React Router 4.0
// Project: https://github.com/ReactTraining/react-router
// Definitions by: Sergey Buturlakin <https://github.com/sergey-buturlakin>
// Yuichi Murata <https://github.com/mrk21>
@rendall
rendall / uniq.js
Last active May 26, 2019 09:02
returns an array with duplicate elements stripped.
const uniq = (arr) => arr.reduce((acc,e) => acc.indexOf(e) >= 0? acc : [...acc, e], [])
// uniq([1,1,1,2,2,3,3,4,4,4,5,6,6]) => [1,2,3,4,5,6]
// arr.reduce iterates through arr's elements,
// check if the array 'acc' contains the element 'e'
// If so, make no change to 'acc' (assign 'acc' to 'acc')
// If not, add 'e' to 'acc'
// After iteration, return 'acc'
// Older version:
@rendall
rendall / .vimrc
Last active September 13, 2021 09:07
Add /t => 4 spaces
set nocompatible " be iMproved, required
" To enable project-specific vim settings: e.g. ./project/.vimrc
set exrc
set backspace=indent,eol,start
let mapleader = ','
set number relativenumber " hybrid number lines
" Use 2 spaces not tabs
@rendall
rendall / isPalindrome.js
Last active October 1, 2020 20:48
isPalindrome(str) returns true if str is a palindrome
// Use it like:
// isPalindrome("Anna") // true
// isPalindrome("not a palindrome") // false
const isPalindrome = (p, normalized) =>
normalized === undefined?
isPalindrome(null, p.replace(/\W/g,"").toLowerCase())
: normalized.length <= 1? true
: normalized.slice(-1) === normalized.slice(0,1)?
isPalindrome(null, normalized.slice(1,normalized.length-1))
@rendall
rendall / apiPromise.ts
Last active October 18, 2020 17:32
API Promise replaces node-fetch
import * as dotenv from "dotenv"
import * as http from "https"
import { IncomingMessage, ClientRequest } from "http"
dotenv.config()
const API_KEY = process.env.API_KEY
const API_HOST = process.env.API_HOST
const API_PATH = process.env.API_PATH
const TIMEOUT_MS = 5000
@rendall
rendall / night-owl.json
Last active February 19, 2021 08:26
Night-owl theme for VSCode terminal
/*
This applies to VSCode *terminal* (not the editor) the color settings
for Sarah Drasner's "Night Owl" VSCode color theme:
https://github.com/sdras/night-owl-vscode-theme
Instructions:
1. CTRL+SHIFT+P and type Preferences: Open Settings (JSON)
2. In the JSON file add the entry below (or modify it if it already exists)
3. Save it! That's all! Open your terminal (CTRL+`) and check it out!
@rendall
rendall / machine.js
Created March 13, 2021 17:52
Generated by XState Viz: https://xstate.js.org/viz
const questMachine = Machine({
id: 'quest',
initial: 'start',
context: {
look: "This is an open field west of a white house, with a boarded front door. There is a small mailbox here. A rubber mat saying 'Welcome to Zork!' lies by the door."
},
states: {
start: {
entry: assign({ look: (context, event) => context.look = 'The mailbox is closed.' }),
on: {
/**
* Creates a debounced function that delays invoking the provided
* function until after `wait` milliseconds have elapsed since the
* last time the debounced function was invoked. Typically used to
* run an expensive or async function after user interaction.
*
* @template T The type of the function to debounce.
* @param {T} func The function to debounce.
* @param {number} [wait=250] The number of milliseconds to delay.
* @returns {(...args: Parameters<T>) => void} Returns the new debounced function.