Skip to content

Instantly share code, notes, and snippets.

View gaievskyi's full-sized avatar
Wizzing

Daniel Gaievskyi gaievskyi

Wizzing
View GitHub Profile
@gaievskyi
gaievskyi / timeAgo.ts
Created May 11, 2024 14:37
Relative time ago
function timeAgo(time: number, now = Date.now()) {
const is = (interval: number, cycle: number) =>
cycle >= interval ? Math.round(cycle / interval) : 0
const secs = (now - time) / 1000
const mins = is(60, secs)
const hours = is(60, mins)
const days = is(24, hours)
const weeks = is(7, days)
@gaievskyi
gaievskyi / singleton.test.ts
Last active May 3, 2024 12:01
Make a class Singleton using decorator (via Proxy). Enable decorators by setting "experimentalDecorators": true in your tsconfig.json.
import { describe, expect, it } from "bun:test"
import { Singleton } from "./singleton"
describe("@Singleton", () => {
it("makes class singleton", () => {
@Singleton
class Foo {
constructor(public bar: string) {}
}
{
"include": [".eslintrc.cjs", ".prettierrc.cjs"],
"compilerOptions": {
/* LANGUAGE COMPILATION OPTIONS */
"target": "ES2020",
"lib": ["DOM", "DOM.Iterable", "ES2020"],
"module": "Node16",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"allowJs": true,
@gaievskyi
gaievskyi / dont-use-CRA.txt
Created October 28, 2022 10:52
Dont use CRA, just do:
mkdir project_name
cd project_name
npm init -y
Install:
- react
- react-dom
- typescript (optional)
- bundler (vite or webpack)
@gaievskyi
gaievskyi / .vimrc
Created December 21, 2020 09:18
.vimrc
set nocompatible " be iMproved, required
filetype off " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" ------------------------------ PLUGINS ------------------------------
Plugin 'VundleVim/Vundle.vim' " let Vundle manage Vundle, required