Skip to content

Instantly share code, notes, and snippets.

@torgeir
torgeir / typescript-json-cast-any-to-t.ts
Created October 23, 2024 19:10
Typescript json cast any to T
async function typedFetch<T>(): Promise<T> {
let res = await fetch("http://ip.jsontest.com/");
let json = res.json();
return json; // actually Promise<any>
}
type Ip = { ip: String };
(async function () {
let ip = await typedFetch<Ip>();
{
description = "minimal nix flake with a default package";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }: {
# packages.x86_64-linux.default =
# with nixpkgs.legacyPackages.x86_64-linux;
packages.aarch64-darwin.default =
@torgeir
torgeir / team-member-by-week.js
Created September 15, 2023 17:11
A script to post the name of a team member to a slack web hook once a week.
(async function () {
var webHookUrl = "https://hooks.slack.com/triggers/a/b/c";
// credits chatgpt
function isoWeek(date) {
// copy date so don't modify original
date = new Date(date);
// set to nearest thursday (current date + 4 - current day) % 7
date.setUTCDate(date.getUTCDate() + 4 - (date.getUTCDay() || 7));
@torgeir
torgeir / ExampleProxyMethodReturnTypeMismatch.java
Created June 6, 2023 08:35
Java example showing how a proxied methods return type may cause runtime class cast errors
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
class DynamicInvocationHandler implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return 42;
}
@torgeir
torgeir / bq-table-suffix-different-schema.sql
Last active March 16, 2023 12:03
BQ table suffix when schema differs
# one: string
#INSERT INTO `torgeirtester.schema_one` values ("one");
# one: string, two: number
#INSERT INTO `torgeirtester.schema_two` values ("one", 2);
# three: boolean
#INSERT INTO `torgeirtester.schema_three` values (true);
SELECT * FROM `torgeirtester.schema_*`;
@torgeir
torgeir / tomb.sh
Created March 12, 2023 11:28
Tomb encrypted mount
tar xvfz Tomb-2.9.tar.gz
cd Tomb-2.9
sudo make install
# 300MB disk
tomb dig -s 300 locked.tomb
tomb forge locked.tomb.key
@torgeir
torgeir / pico-2022.clj
Created December 12, 2022 19:07
The beginning of pico ctf 2022
(ns pico)
;; basic-mod1
;;
(def data [91 322 57 124 40 406 272 147 239 285 353 272 77 110 296 262 299 323 255 337 150 102])
(def alph
"0-25 is the alphabet (uppercase), 26-35 are the decimal digits, and 36 is an underscore."
@torgeir
torgeir / nuke-disk.sh
Created September 10, 2022 09:47
Nuke a disk, single pass
# https://wiki.archlinux.org/title/Securely_wipe_disk
❯ sudo shred --verbose --random-source=/dev/urandom -n1 --zero /dev/sdX
shred: /dev/sdb: pass 1/2 (random)...
shred: /dev/sdb: pass 1/2 (random)...134MiB/932GiB 0%
shred: /dev/sdb: pass 1/2 (random)...319MiB/932GiB 0%
shred: /dev/sdb: pass 1/2 (random)...503MiB/932GiB 0%
@torgeir
torgeir / wine-tkg-fsync-arch-build.sh
Last active August 14, 2022 19:21
Wine tkg with fsync support for running helix native on arch
cd
git clone [email protected]:Frogging-Family/wine-tkg-git.git Code/wine-tkg-git
pushd Code/wine-tkg-git/wine-tkg-git
git checkout master
# vim customizations.cfg: _staging_version="v7.15", _use_fsync="true"
# why tho?
rm -rf wine-tkg-patches/hotfixes/mfplat
# select 0, the customizations has settings for fsync
@torgeir
torgeir / codingame-snake-ai.kt
Last active June 26, 2022 15:14
Codingame: Snake AI, random safe moves
import java.util.*
import java.lang.Integer.parseInt
typealias Coord = Pair<Int, Int>
fun Coord.x() = first
fun Coord.y() = second
typealias Move = Pair<Direction, Coord>