View useInterval.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef, useState } from 'react'; | |
type Control = { | |
start: () => void; | |
stop: () => void; | |
}; | |
type State = 'RUNNING' | 'STOPPED'; | |
type Fn = () => void; |
View BinarySearchTree.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(value) { | |
this.value = value | |
this.left = undefined | |
this.right = undefined | |
} | |
} | |
Node.prototype.setLeft = function (node) { | |
this.left = node |
View toMap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toMap = <T>(arr: T[], byId: (item: T) => string): Map<string, T> => { | |
const tuple = arr.reduce((acc, curr) => { | |
acc.push([byId(curr), curr]) | |
return acc | |
}, [] as [string, T][]) | |
return new Map(tuple) | |
} |
View group.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const group = <T>(arr: T[], size: number): T[][] => { | |
return arr.reduce( | |
(acc, curr) => { | |
if (acc[acc.length - 1].length < size) { | |
acc[acc.length - 1].push(curr) | |
} else { | |
acc.push([curr]) | |
} | |
return acc | |
}, |
View balus.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker-compose down --rmi all --volumes --remove-orphans |
View groupBy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const groupBy = <K, V>(arr: readonly V[], getKey: (cur: V, idx: number, src: readonly V[]) => K): V[][] => | |
arr.reduce((acc, cur, idx, src) => { | |
const key = getKey(cur, idx, src); | |
const item = acc.find(([k,]) => k === key); | |
if (item) { | |
const [, v] = item; | |
v.push(cur); | |
} else { | |
acc.push([key, [cur]]); | |
} |
View timestamp.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// marshal/unmarshal to/from unix timestamp | |
// implement the Scanner and Valuer interfaces of gorm (https://gorm.io/docs/data_types.html) | |
package custom | |
import ( | |
"time" | |
"fmt" | |
"strconv" | |
"database/sql/driver" |