Skip to content

Instantly share code, notes, and snippets.

View slavo23's full-sized avatar

Stanislav Gorborukov slavo23

View GitHub Profile
@slavo23
slavo23 / arena_tree.py
Created April 8, 2023 21:54
Python example of a tree that uses arena allocation
from typing import TypeVar, List, Optional
from functools import partial
T = TypeVar('T')
class TreeNodeTy:
pass
@slavo23
slavo23 / groupBy.ts
Last active March 24, 2021 13:38
GroupBy for typescript
interface IGroupedElements<T> {
[value: string]: T[]
}
const groupBy = <T, U>(collection: T[], predicate: (elem: T) => U): IGroupedElements<T> => {
return collection.reduce((accumulator, current) => {
const output = predicate(current).toString()
if (output in accumulator) {
module Main where
binaryToIntegral :: Integral a => String -> a
binaryToIntegral xs = sum $ map fst bits
where count = length xs - 1
bits = filter ((/= zero) . snd) $ zip (map (2^) [count, pred count..0]) xs
zero = '0'
main :: IO ()