Skip to content

Instantly share code, notes, and snippets.

View reosablo's full-sized avatar

Reo reosablo

View GitHub Profile
@reosablo
reosablo / gemini-function-declarations.ts
Last active February 15, 2025 08:26
Gemini Function Calling を用いてローカルファイルを読ませるサンプルコード (Deno)
import {
type FunctionDeclaration,
SchemaType,
} from "npm:@google/[email protected]";
export type FunctionDefinition = {
readonly declaration: FunctionDeclaration;
readonly implementation: (args: object) => unknown;
};
@reosablo
reosablo / hono-vite-build-google-cloud-run-functions.ts
Last active February 2, 2025 06:33
Vite plugin for Hono server on Google Cloud Run Functions
/**
* @file Vite plugin for Hono server on Google Cloud Run Functions
* @author reosablo
* @license UNLICENSED
*/
import buildPlugin from "@hono/vite-build";
import type { Plugin } from "vite";
export type GoogleCloudRunFunctionsBuildPluginOptions = {
@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 / buildless-angular-17-app-with-babel.html
Last active December 14, 2024 05:19
Buildless Angular 17 app with `@babel/standalone`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Buildless Angular 17 app with @babel/standalone</title>
<script type="importmap">
{
"imports": {
"@angular/common": "https://esm.sh/v135/@angular/[email protected]?dev",
@reosablo
reosablo / buildless-angular-17-app.html
Last active December 14, 2024 05:21
Buildless Angular 17 app
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Buildless Angular 17 app</title>
<script type="importmap">
{
"imports": {
"@angular/common": "https://esm.sh/v135/@angular/[email protected]?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)