Skip to content

Instantly share code, notes, and snippets.

@hasenj
hasenj / watch.mjs
Created November 10, 2024 11:03
nodejs script to run a watch mode typescript checker that can optionally output to json for consumption by other programs
// Generated by Claude
// Some details hand tuned
import fs from 'fs'
import ts from 'typescript';
import path from 'path';
function getConfig() {
const args = process.argv.slice(2);
const jsonIndex = args.indexOf('--json');
const useJson = jsonIndex !== -1;
@hasenj
hasenj / html_builder.odin
Created August 20, 2024 06:17
html builder idea
package html_builder
import "core:fmt"
import "core:strings"
Attr :: struct {
name: string,
value: string,
}
@hasenj
hasenj / css.ts
Created April 13, 2024 19:56
tiny css-in-js "library"
import type * as csstype from "csstype";
class Sheet {
domSheet: CSSStyleSheet | null;
rulesCount = 0;
constructor() {
let el = document.createElement("style");
el = document.head.appendChild(el);
if (!el.sheet) {
console.error("failed to created style element");
@hasenj
hasenj / joyo.json
Created October 10, 2023 03:30
Joyo Kanji List (JSON)
[
{
"kanji": "亜",
"oldForm": "亞",
"readings": [
"ア"
],
"examples": [
[
"亜流",
@hasenj
hasenj / README
Last active November 10, 2024 16:32
TSBridge: a system to auto generate typescript bindings for Go server side functions
This code is shared as-is. Use at your own risk.
It is not meant to be depended upon as a module. Instead, copy it to your own code base and make changes as needed.
CC0/MIT-0/Unlicense
It generates type definitions for structs and enums in Go to Typescript.
It's only meant to be executed locally; during development.
@hasenj
hasenj / esbuild.go
Created March 8, 2023 06:19
A little js/ts bundler based on esbuild (assumes preact, change to suit your needs). CC0/mit-0/unlicense
package esbuilder
import "os"
import "path"
import "fmt"
import "log"
import "time"
// the main hero!
import "github.com/evanw/esbuild/pkg/api"
@hasenj
hasenj / cache.ts
Last active August 3, 2023 16:51
Caching for Javascript/Typescript using arbitrary objects as keys
import * as refs from "./refs";
class ById {
constructor(public param: any) { }
}
// wraps an object in a special flag so that the cache uses the object's id instead of hashing its keys and values
export function byId(param: any) {
return new ById(param)
}
@hasenj
hasenj / app_metal.c
Created December 30, 2019 12:46
Pure C Cocoa Application with Window and Metal
// How to build:
// # compile the metal shaders
// xcrun -sdk macosx metal -c shaders.metal -o shaders.air
// xcrun -sdk macosx metallib shaders.air -o shaders.metallib
// # compile the c file
// clang app_metal.c -framework Cocoa -framework Metal -o metal_c.app
//
//
// Draw a triangle using metal
// Metal tutorial followed here: https://www.raywenderlich.com/7475-metal-tutorial-getting-started
@hasenj
hasenj / markdown_furigana.py
Last active February 24, 2016 18:04 — forked from huangziwei/markdown_furigana.py
a python script for writing furigana in markdown
import fileinput
import re
import sys
```
eg. [東京]{とうきょう} -> <ruby>東京<rp>(</rp><rt>とうきょう</rt><rp>)</rp></ruby>
```
def furiganize(line):
# (?<!\\) means don't match if preceeded by a backslash
return re.sub(ur'(?<!\\)\[(.*?)\]\{(.*?)\}', ur'<ruby>\1<rp>(</rp><rt>\2</rt><rp>)</rp></ruby>', line.rstrip())
@hasenj
hasenj / requests.js
Created April 13, 2013 14:37
Experimental "ajax" library
echo = function(areq) { console.log(areq.response) };
requests = (function() {
var module = {};
var AsyncRequest = XMLHttpRequest;
// takes a dict and returns a string "a=b&c=d"
var toUrlParams = function(dict) {
var res = [];
for(var key in dict) {