Skip to content

Instantly share code, notes, and snippets.

@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:
@jart
jart / llm-browser.py
Created July 5, 2024 13:29
Using an LLM as an HTTP proxy with LLaMAfile
#!/usr/bin/env python
import socket
import threading
import subprocess
def handle_client(client_socket):
request = client_socket.recv(8192).decode('utf-8', errors='ignore')
first_line = request.split('\n')[0]
@jart
jart / libmvec_expf_avx2.S
Last active May 22, 2024 22:07
glibc vectorized expf() versus my faster intrinsic vectorized expf() for x86-64
/* Function expf vectorized with AVX2.
Copyright (C) 2014-2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
@jart
jart / dawkins.markdown
Created June 8, 2014 19:28
How Dawkins Got Pwnd by Mencius Moldbug (37,941 words)

How Dawkins got pwnd

By Mencius Moldbug c. Sep 2007

Part 1

Richard Dawkins recently wrote a book called The God Delusion. You've probably heard of it.

Professor Dawkins is a great scientist and one of my favorite writers. And I have no quarrel at all with his argument. I was raised as a scientific atheist, and I've never seen the slightest reason to think otherwise. These days I prefer the word "nontheist" - for reasons which will shortly be clear - but there's no substantive difference at all. Except in the context of role-playing games, I have no interest whatsoever in gods, goddesses, angels, devils, dryads, water elementals, or any such presumed metaphysical being.

Nonetheless, it's my sad duty to inform the world that Professor Dawkins has been pwned. Perhaps you're over 30 and you're unfamiliar with this curious new word. As La Wik puts it:

@jart
jart / fone.go
Last active May 16, 2024 04:05
Linux CLI Telephone in 300 lines of Go. This is a NAT traversing SIP user agent. It can hook into the PSTN via gateways like Flowroute. The keyboard can be used to send DTMF tones.
// To the extent possible under law, Justine Tunney has waived
// all copyright and related or neighboring rights to this file,
// as it is written in the following disclaimers:
// - http://unlicense.org/
// - http://creativecommons.org/publicdomain/zero/1.0/
package main
// #cgo pkg-config: ncurses libpulse-simple
// #include <stdlib.h>
@jart
jart / resymbol.c
Created May 6, 2024 18:50
Program that renames symbols in compiled binaries.
// Copyright 2024 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 / lolfma.c
Created May 1, 2024 06:48
example of a program written in C/C++ that skips over invalid amd64 / arm64 opcodes
// -*- 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
#define _GNU_SOURCE
#include <signal.h>
#include <stdio.h>
#include <ucontext.h>
#ifdef __x86_64__
#define XED_ILD_HASMODRM_IGNORE_MOD 2
@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 / defer.c
Last active March 26, 2024 07:08
Go-like defer for C that works with most optimization flag combinations under GCC/Clang
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 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 / printimage.c
Last active December 20, 2023 11:13
/*bin/echo ' -*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;coding:utf-8 -*-┤
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ To the extent possible under law, Justine Tunney has waived │
│ all copyright and related or neighboring rights to this file, │
│ as it is written in the following disclaimers: │
│ • http://unlicense.org/ │
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
╚────────────────────────────────────────────────────────────────────'>/dev/null
if ! [ "${0%.*}.exe" -nt "$0" ]; then