Skip to content

Instantly share code, notes, and snippets.

@jart
jart / matmul.cpp
Last active April 18, 2024 22:54
how to reproduce mkl matmul perf claims in https://justine.lol/matmul/
// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;coding:utf-8 -*-
// vi: set et ft=c++ ts=4 sts=4 sw=4 fenc=utf-8 :vi
//
// Copyright 2024 Mozilla Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@jart
jart / rename-pictures.sh
Created December 12, 2023 15:24
Shell script for renaming all images in a folder
#!/bin/sh
# rename-pictures.sh
# Author: Justine Tunney <jtunney@gmail.com>
# License: Apache 2.0
#
# This shell script can be used to ensure all the images in a folder
# have good descriptive filenames that are written in English. It's
# based on the Mistral 7b and LLaVA v1.5 models.
#
# For example, the following command:
# Copyright 2023 Justine Alexandra Roberts Tunney
#
# Permission to use, copy, modify, and/or distribute this software for
# any purpose with or without fee is hereby granted, provided that the
# above copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
@jart
jart / ckd-kamil-128.c
Created July 22, 2023 15:11
c23 stdckdint.h test vectors
#include <stdio.h>
#include <ckdint.h>
#include <stdint.h>
#include <inttypes.h>
typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t;
#define TBIT(T) (sizeof(T) * 8 - 1)
#define TMIN(T) (((T) ~(T)0) > 1 ? (T)0 : (T)((uint128_t)1 << TBIT(T)))
@jart
jart / equiv
Created April 18, 2023 03:35
equiv -- checks if integral c expressions are equivalent
#!/usr/bin/env python3
# -*- python -*-
#
# SYNOPSIS
#
# equiv -- checks if integral c expressions are equivalent
#
# EXAMPLES
#
# $ equiv '(gn1 & 1) || (gn1 != gn2)' '(gn1 & 1) | (gn1 ^ gn2)'
@jart
jart / cosmoc++
Last active September 8, 2022 13:37
Cosmopolitan Libc Toolchain
#!/bin/sh
# replacement for c++ command
#
# we assume you run the following beforehand
#
# sudo chmod 1777 /opt
# cd /opt
# git clone https://github.com/jart/cosmopolitan cosmo
# cd cosmo
# make -j
;;; text2math.el --- keyboard shortcuts for converting to math charsets
;; Copyright (C) 2022 Justine Alexandra Roberts Tunney
;; License: ISC
;; Author: Justine Tunney <jtunney@gmail.com>
;; Version: 0.1
;; URL: http://github.com/jart/justinemacs
;;
;; Permission to use, copy, modify, and/or distribute this software for
;; any purpose with or without fee is hereby granted, provided that the
@jart
jart / blc.S
Last active June 10, 2023 06:58
Binary Lambda Calculus Virtual Machine for x64 Linux in 400 bytes
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
@jart
jart / .init.lua
Last active September 1, 2023 07:14
redbean sqlite tutorial
re = require "re"
sqlite3 = require "lsqlite3"
reNumberPath = re.compile[[^/([0-9][0-9]*)$]]
function SetupSql()
if not db then
db = sqlite3.open('redbean.sqlite3')
db:busy_timeout(1000)
db:exec[[PRAGMA journal_mode=WAL]]
@jart
jart / redbean-requirements.c
Last active July 1, 2021 12:38
redbean requirements for serenityos kernel
/*
redbean: kernel requirements
x86-64 linux system five abi
rax name rdi rsi rdx r10 r8 r9
----- -------------- ------------------------ --------------------------- ------------------------------ -------------------------- ------------------------ ---------------
0x000 read unsigned int fd char *buf size_t count - - -
0x003 close unsigned int fd - - - - -
0x005 fstat unsigned int fd struct stat - - - -
0x007 poll struct pollfd *ufds unsigned int nfds int timeout -