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
#include <iostream> | |
using namespace std; | |
template <class T> | |
class Smart { | |
private: | |
T* pointee; | |
int* ref_count; | |
public: | |
Smart(T* ptr) : pointee(ptr), ref_count(new int(0)) { |
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 React from 'react'; | |
const createContext = (defaultState = undefined) => { | |
let state = defaultState; | |
let subscribers = []; | |
const subscribe = cb => { | |
// We call this function ourselves so no need to check the typeof cb === 'function' | |
subscribers.push(cb); | |
return () => { | |
subscribers = subscribers.filter(c => c !== cb); |
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
namespace List { | |
const EmptyList = new TypeError('The list is empty'); | |
const IndexOutOfBounds = new RangeError('Index out of bounds'); | |
type Empty = '@@EMPTY'; | |
export const EMPTY: Empty = '@@EMPTY'; | |
export type IList<T> = Empty | readonly [T, IList<T>]; | |
export const head = <T>(list: IList<T>): T => { |
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 { NotLoggedIn } from '../models/errors' | |
const AuthGuardMethods = Symbol('AuthGuardMethods') | |
export function AuthGuard() { | |
return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { | |
target[AuthGuardMethods] = target[AuthGuardMethods] || new Map() | |
// Here we just add some information that class decorator will use | |
target[AuthGuardMethods].set(propertyKey, descriptor) | |
} |
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
type IFlattenable<K extends string> = { | |
[k in K]?: IFlattenable<K>[]; | |
} & { id: number }; | |
type IFlattened<T extends IFlattenable<K>, K extends string> = Omit< | |
T, | |
K | 'id' | |
> & { | |
parentId: number; | |
id: number; |
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, useReducer, useMemo } from "react"; | |
import { BehaviorSubject } from "rxjs"; | |
export const createStateHook = <S>(init: S) => { | |
const state$ = new BehaviorSubject(init); | |
const setState = (change: S | ((state: S) => S)) => { | |
state$.next(change instanceof Function ? change(state$.value) : change); | |
}; |
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 { useCallback, useEffect, useReducer, useRef } from "react"; | |
type Comparator = (value1: any, value2: any) => boolean; | |
/** Core */ | |
type Listener = () => void; | |
type Destroy = () => void; |
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
interface Observer<T> { | |
next: (el: T) => void; | |
} | |
type Dispose = () => void; | |
type Operator<T, U> = (source$: Observable<T>) => Observable<U> | |
class Observable<T> { | |
constructor(private cb: (observer: Observer<T>) => Dispose) {} |
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 None {} | |
class Some<T> { | |
constructor(public value: T) {} | |
} | |
type Maybe<T> = None | Some<T>; | |
export const none = new None(); |
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 { default as player } from "play-sound"; | |
const play = (name: string) => player().play(`./assets/${name}.wav`); | |
const sleep = (time: number) => { | |
return new Promise((res) => | |
setTimeout(() => { | |
res(null); | |
}, time) | |
); | |
}; |
OlderNewer