Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃
chilling

raphtlw raphtlw

🙃
chilling
View GitHub Profile
@raphtlw
raphtlw / context.tsx
Last active Jul 30, 2022
Inline functional context builder
View context.tsx
import {
useContext,
createContext,
type ReactNode,
type Provider as ReactProvider,
} from 'react'
/**
* Utility context builder which streamlines the context
* building and exposing API.
@raphtlw
raphtlw / tsm.ts
Last active Mar 26, 2022
TypeScript macro preprocessor
View tsm.ts
#!/usr/bin/env ts-node
import assert from "assert";
import fs from "fs";
import readline from "readline";
const argv = process.argv.slice(2);
const argFileName = argv[0];
function error(msg: string) {
@raphtlw
raphtlw / script.sh
Created Aug 11, 2021
Bash script template with argument parsing
View script.sh
#!/usr/bin/env bash
# ----------------------------------------------------------------------------
# script.sh: Bash script template with argument parsing
#
# Author: Raphael Tang <raphpb1912@gmail.com>
# ----------------------------------------------------------------------------
# Dependencies:
# - dependency1
# - dependency2
@raphtlw
raphtlw / log.ts
Created Dec 23, 2020
Simple logging boilerplate for Javascript
View log.ts
export class Log {
private static getTime() {
const date = new Date()
return `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}]`
}
static d(_: unknown) {
const message = `${this.getTime()} [debug] ${_}`
console.log(message)
}
static i(_: unknown) {