Skip to content

Instantly share code, notes, and snippets.

View KSXGitHub's full-sized avatar

Khải KSXGitHub

  • Earth, Solar System, Orion Arm, Milky Way
  • X @hvksmr1996
View GitHub Profile
#! /usr/bin/env node
const LIMIT = 256
const range = n => Array(n).fill(0).map((_, i) => i)
const unionRange = n => range(n).join(' | ')
console.log(`export type Foo<N extends ${unionRange(LIMIT)}> = `)
for (const n of range(LIMIT)) {
console.log(` N extends ${n} ? [${range(n).join(', ')}] :`)
}
interface MaybeBase {
readonly loaded: boolean
}
interface Some<X> extends MaybeBase {
readonly loaded: true
readonly value: X
}
interface None extends MaybeBase {
@KSXGitHub
KSXGitHub / compose.rs
Last active December 25, 2018 16:07
Compose function in Rust
use core::ops::{Add, Mul};
use core::marker::Copy;
use std::fmt::Display;
fn compose<X, Y, Z> (
f: impl Fn(X) -> Y,
g: impl Fn(Y) -> Z
) -> impl Fn(X) -> Z {
move |x: X| g(f(x))
}
@KSXGitHub
KSXGitHub / sieve.hs
Last active November 7, 2018 15:45
Sieve of Eratosthenes
primes = take 15 (sieve [2..])
sieve (prime:rest) = prime : sieve [x | x <- rest, mod x prime /= 0]
#! /usr/bin/env lsc
require! 'path'
require! 'fs'
const {exists-sync, readlink-sync} = fs
const {stdout, stderr, exit, cwd} = require 'process'
const {spawn-sync} = require 'child_process'
require! 'js-yaml'
const {create-command-arguments} = require './lib/shell-command-utils.js'
const argv = let
@KSXGitHub
KSXGitHub / xset.ts
Created October 18, 2018 17:51
Type Guard experimentation of Set
interface XSet<X0> {
has<X1 extends X0> (x: X1): this is XSetWith<X1, X0>
}
interface XSetWith<X1 extends X0, X0> extends XSet<X0> {
has<X2 extends X0> (x: X2): this is XSetWith<X2, X1>
has<X2 extends X1> (x: X2): true
}
declare const xset: XSet<number>
@KSXGitHub
KSXGitHub / tuple-utils.ts
Last active September 12, 2018 11:23
Tuple generic
export namespace TupleUtils {
/**
* Get type of first element
* @example `First<[0, 1, 2]>` → `0`
*/
export type First<Tuple extends [any, ...any[]]> = Tuple[0]
/**
* Get type of last element
@KSXGitHub
KSXGitHub / komorebi.svg
Created August 7, 2018 09:32
Komorebi icons
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Slayer's Testament I

In the first age, in the first battle, when the shadows first lengthened, one stood. Burned by the embers of Armageddon, his soul blistered by the fires of Hell and tainted beyond ascension, he chose the path of perpetual torment. In his ravenous hatred he found no peace; and with boiling blood he scoured the Umbral Plains seeking vengeance against the dark lords who had wronged him. He wore the crown of the Night Sentinels, and those that tasted the bile of his sword named him... the Doom Slayer.

Slayer's Testament II

Tempered by the fires of Hell, his iron will remained steadfast through the passage that preys upon the weak. For he alone was the Hell Walker, the Unchained Predator, who sought retribution in all quarters, dark and light, fire and ice, in the beginning and the end, and he hunted the slaves of Doom with barbarous cruelty; for he passed through the divide as none but demon had before.

const foo = require('./foo')
module.exports = () => foo()