Skip to content

Instantly share code, notes, and snippets.


Babak B. babakness

View GitHub Profile
babakness /
Last active Nov 10, 2021
A list of commands to disable the back gesture for Chrome, FireFox, Brave, and Safari

When working with online editor, the back gesture on a Mac can become very frustrating. Here are some helpful commands disable the back gesture:

# Disable back gesture in specific apps

# Chrome
defaults write AppleEnableSwipeNavigateWithScrolls -bool FALSE
# FireFox
defaults write org.mozilla.firefox AppleEnableSwipeNavigateWithScrolls -bool FALSE
# Brave

Flattening Arbitrarily Nested Arrays in JavaScript


JavaScript's immense flexibility affords the creation of arrays nested arbitrarily. Each element in an array can be of any type and of varying depths. A function that completely flatten various nested arrays can be a useful tool.

There are two general approaches to creating this flattening function, recursion and iteration, and many variations therein. As we'll see, the most elegant looking solutions to this kind of problem tend to be recursive. Alas, recursion in JavaScript is not well optimized. On the other hand, iterative solutions in JavaScript can be more complex and require extra care with regards to mutations.


babakness /
Created Oct 16, 2012 — forked from bloomonkey/
A Python dictionary sub-class that is case-insensitive when searching, but also preserves the keys as inserted.
class CaselessDictionary(dict):
"""Dictionary that enables case insensitive searching while preserving case sensitivity
when keys are listed, ie, via keys() or items() methods.
Works by storing a lowercase version of the key as the new key and stores the original key-value
pair as the key's value (values become dictionaries)."""
def __init__(self, initval={}):
if isinstance(initval, dict):
for key, value in initval.iteritems():
babakness / use-interval.ts
Created Feb 4, 2019
Typescript version of Dan Abramov's useInterval requiring non-null value for delay
View use-interval.ts
import * as React from 'react'
const { useState, useEffect, useRef } = React
type IntervalFunction = () => ( unknown | void )
function useInterval( callback: IntervalFunction, delay: number ) {
const savedCallback = useRef<IntervalFunction| null>( null )
View .tmux.conf
# Use C-Space instead of C-b for tmux. C-Space C-Space to get "C-Space".
set-option -g default-shell /usr/local/bin/fish
set-option -g history-limit 100000
unbind-key C-b
set -g prefix C-Space
bind-key C-Space send-prefix
# Set the default terminal mode to 256color mode
set -g default-terminal "screen-256color"
babakness / tsconfig.json
Created Dec 31, 2019
Typical tsconfig.json
View tsconfig.json
"compilerOptions": {
"baseUrl": "src",
"target": "es5",
"lib": [
"allowJs": true,
babakness / XorExtend.ts
Created Dec 24, 2018
generic type and typed function that conditionally extend an object if the keys / value type of the first object are not in the second
View XorExtend.ts
type XorExtend<T extends {
[K in keyof T]: K extends keyof A
? A[K] extends T[K]
? never
: T[K]
: T[K]
}, A extends object,> = T & A
declare function xorExtend<O, P extends { [K in keyof P]: K extends keyof O
? O[K] extends P[K]
babakness / no-excess-partials.ts
Last active Nov 25, 2018
A collection of partial types which do not allow for excess properties.
View no-excess-partials.ts
// Inspired by
export type NoExcessStrictPartial<O, P> = {
[K in keyof P]: K extends keyof O ? O[K] : never
export type NoExcessDeepPartialValueFlexType<O, P> = {
[K in keyof P]:
K extends keyof O
? NoExcessDeepPartialValueFlexType<O[K],P[K]>
: never
View Immutable Arrays, Object in TypeScript
type ReadonlyObj<T> = { readonly [K in string]: T }
const foo: ReadonlyArray<T> = [1,2,3]
const bar: ReadonlyObj = { a: 1, b: 2, c: 3 }
babakness / create-class-like-functions.js
Last active Oct 5, 2018
Helpers for creating class like functions that can be invoked without new
View create-class-like-functions.js
const assoc = ( prop, value, obj ) =>
Object.assign( {}, obj, { [prop]: value })
const reducer = ( $values, accumulate, [key,val] ) => assoc( key, val.bind( undefined, ...$values ), accumulate )
export const bindValuesToMethods = ( $methods, ...$values ) =>
Object.entries( $methods ).reduce( reducer.bind( undefined, ...$values ), {} )
export const prepareInstance = (instanceMethods, staticMethods = ({}) ) => Object.assign(