Skip to content

Instantly share code, notes, and snippets.

View reosablo's full-sized avatar

Reo reosablo

View GitHub Profile
@reosablo
reosablo / typed-event-target.ts
Last active May 21, 2024 11:27
Pure typed `EventTarget` derivation without any dependencies nor overhead on runtime
/**
* @file Pure Typed EventTarget
* @license Unlicense
*/
export declare class TypedEventTarget<EventMap extends Record<string, Event>>
extends EventTarget {
addEventListener<Type extends keyof EventMap>(
type: Type,
listener: (this: this, evt: EventMap[Type]) => void,
@reosablo
reosablo / build-free-angular-17-app-with-babel.html
Last active March 25, 2024 08:42
Build-free Angular 17 app with `@babel/standalone`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Build-free Angular 17 app with @babel/standalone</title>
<script type="importmap">
{
"imports": {
"@angular/common": "https://esm.sh/v135/@angular/common@17.0.3?dev",
@reosablo
reosablo / build-free-angular-17-app.html
Last active November 26, 2023 14:04
Build-free Angular 17 app
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Build-free Angular 17 app</title>
<script type="importmap">
{
"imports": {
"@angular/common": "https://esm.sh/v135/@angular/common@17.0.3?dev",
@reosablo
reosablo / esbuild-plugin-typia.mjs
Last active November 16, 2023 18:09
esubild plugin for Typia
// @ts-check
/**
* @file esbuild plugin for transforming TypeScript code using Typia
*
* CAUTION: this plugin will break the output source map.
*
* @example
* ```js:build.mjs
* import { build } from "esbuild";
@reosablo
reosablo / decrypt-forge.mjs
Last active May 19, 2023 08:35
Equivalent code set for Web Crypto API and `node-forge` module
#!/usr/bin/env node
// @ts-check
/**
* @file Decrypts data from stdin using a private key.
*
* @example
* node decrypt-forge.mjs [private-key-path] < encrypted-data.txt
*
* The default private key path is "private-key.pem".
@reosablo
reosablo / to-async-generator.ts
Last active October 3, 2021 08:44
Convert Promises to AsyncGenerator
/**
* combine promises into an async generator in order of fast resolved
* @param promises promises to output
*/
export async function* toAsyncGenerator<T>(promises: Iterable<Promise<T>>) {
const unresolvedPromises = new Set(promises);
const fulfilledValues: T[] = [];
for (const promise of promises) {
promise.then(
(value) => {
@reosablo
reosablo / switch-vmp.cmd
Created August 25, 2021 16:06
Enable / Disable VirtualMachinePlatform
@powershell/c '#'+(gc \"%~f0\"-ra)^|iex&exit/b
$ErrorActionPreference = 'Stop'
try {
$FeatureName = 'VirtualMachinePlatform'
$Feature = Get-WindowsOptionalFeature -Online -FeatureName $FeatureName
$Enabled = $Feature.State -eq 'Enabled'
$Feature
@reosablo
reosablo / base64-le-to-bigint.js
Created April 28, 2021 14:26
JavaScript: BigInt <=> BASE64 (Little Endian) Codec
export default a=>[...atob(a)].reduceRight((n,b)=>(n<<8n)+BigInt(b.charCodeAt(0)),0n)
param($Port = 8081)
$ErrorActionPreference = 'Stop'
# $InformationPreference = 'Continue'
Write-Information "initiated"
$Listener = New-Object System.Net.HttpListener
$Listener.Prefixes.Add("http://localhost:$Port/")
$Listener.Start()
@reosablo
reosablo / Hello_WebSocket.ps1
Created December 31, 2019 08:42
Live2DViewerEX ExAPI example
#!/usr/bin/env pwsh.exe
<#
.PARAMETER Text
text to show
.PARAMETER Duration
duration of showing, value is millisecond
if set to -1, the bubble will not disappear automatically
.PARAMETER Id
indices of model (0 - 7)