Skip to content

Instantly share code, notes, and snippets.

/**
* Given an array of size 'n' and a number 'r' (r <= n), this generator returns all
* nCr permutation subarrays of the array.
*
* @param arr - array
* @param r number
*/
function* permutations(arr, r, prefix = []) {
for (let i = 0; i < arr.length - r + 1; i++) {
let x = [...prefix, arr[i]]
function toAsciiTree(tree: any, prefix = "", isTail = true): string | null {
if (!tree) {
return null
}
let children = tree.children || []
return [prefix, isTail ? "└" : "├", " ", tree.name, '\n']
.concat(children.map((c: any, i: number) => toAsciiTree(c,
prefix + (isTail ? " " : "│ "), i >= children.length - 1)))
.join('')
@venkatperi
venkatperi / gist:d975cc768a6be9bff7615426643ef887
Created April 15, 2019 11:47
Crores & Lakhs for Rupee Currency in Google Sheets
₹* _(## ## ## ##0_);₹* (## ## ## ###);₹* 0_)
@venkatperi
venkatperi / genpass.sh
Last active January 17, 2019 03:44
Generates base62 passwords/api keys
#!/bin/bash
SIZE=${1:-20}
curl -s https://apikey.now.sh/$SIZE | cut -d, -f1 | cut -d: -f2 | tr -d \"
data: function () {
return {
task: {
sm: {},
state: '',
error: {},
result: undefined,
},
}
},
props: {
taskTimeout: {
type: Number,
required: false,
},
},
['stateTimeout#*_#running', 'done/timeout']
['enter#*_#done/:status', ({args, data}) =>
keepState()
.emit(args.status, data)],
['cast#error/:sessionId#running', ({args, data, event}) =>
args.sessionId === data.sessionId
? nextState('done/error').data({errors: {$push: [event.extra]}})
: keepState()],
['cast#cancel#running', ({event}) =>
nextState('done/cancel')
.data({errors: {$push: [event.extra]}})],