Skip to content

Instantly share code, notes, and snippets.

View Techcable's full-sized avatar
🇺🇸
Procrastinating

Techcable

🇺🇸
Procrastinating
View GitHub Profile
@Techcable
Techcable / klib.wrap
Last active January 16, 2023 22:43
Meson Wrapfile for klib
# Website: https://attractivechaos.github.io/klib/
# Source: https://github.com/attractivechaos/klib
#
# Meson Wrap Gist:
# Meson Wrap Version: 1
[wrap-git]
url = https://github.com/attractivechaos/klib.git
revision = head
patch_directory = klib
@Techcable
Techcable / fend-unitfmt.janet
Created November 16, 2022 02:13
A Janet script to wrap fend and format units [WIP]
(import sh)
(import spork)
(def- metric-prefixes ["K" "M" "G" "T" "P" "E"])
(defn- makeunit [&named name base-prefix binary]
(default binary false)
(assert (keyword? name))
(assert (not (empty? (string name))))
(assert (string? base-prefix))
@Techcable
Techcable / minimized.zig
Created August 26, 2022 04:55
stage3 regression for comptime slice concat (need explicit comptime block)
const std = @import("std");
fn sdk_root() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
fn dep_root_working() []const u8 {
const sdk_root_val = comptime blk: { break :blk sdk_root(); };
return sdk_root_val ++ "/deps/mpack";
}
@Techcable
Techcable / getjanet.sh
Last active August 20, 2022 03:07
A small bash script to download & compile the Janet CLI
#!/bin/bash
# Available as github gist: https://gist.github.com/Techcable/b83df781602857dd2f6cf0074e50ba77
set -e
if [[ $# -eq 1 ]]; then
OUT_FILE="$(realpath "$1")";
else
echo "ERROR: Invalid arguments" >&2;
@Techcable
Techcable / exec-slurp.janet
Created August 4, 2022 02:33
Janet subprocess execute: `exec-slurp` by the great @bakpakin
# See also andrewchambers/janet-sh for a more complete (and awesome) solution:
# https://acha.ninja/blog/dsl_for_shell_scripting/
#
# Source: https://github.com/janet-lang/jpm/blob/07b0c18daf75cfdf098eff5526a17ad0436e3dc0/jpm/shutil.janet#L123-L137
(defn exec-slurp
"Read stdout of subprocess and return it trimmed in a string."
[& args]
(when (dyn :verbose)
(flush)
(print ;(interpose " " args)))
@Techcable
Techcable / sieve.janet
Last active April 9, 2022 01:05
Sieve of Eratosthenes for Janet
(defn primes-before
"Gives all the primes < limit"
[limit]
(assert (int? limit))
# Janet has a buffer type (mutable string) which has easy methods for use as bitset
(def buf-size (math/ceil (/ (+ 1 limit) 8)))
(def is-prime (buffer/new-filled buf-size (bnot 0)))
(buffer/bit-clear is-prime 0)
(buffer/bit-clear is-prime 1)
(for n 0 (math/ceil (math/sqrt limit))
@Techcable
Techcable / heapsort.janet
Last active April 9, 2022 00:48
A port of my heap sort code from Python -> Janet
# Ported from this Python code: https://gist.github.com/Techcable/c411b3a550e252b1fd681e1fc1734174
#
# Based on R. Sedgewick's Algorithms, Chapter 2.4
(defn swap [l a b]
(let [aval (get l a) bval (get l b)]
(put l a bval)
(put l b aval)))
(defn heap-sort [l]
@Techcable
Techcable / heapsort.py
Last active April 8, 2022 22:47
A simplistic implementation of heapsort (in Python)
import operator
def swap(l: list, i: int, j: int):
assert i < len(l), i
assert j < len(l), j
l[i], l[j] = l[j], l[i]
def heap_sort(l: list) -> list:
@Techcable
Techcable / number_names.py
Last active March 15, 2022 03:51
Simple script for naming the integers <10,000 (used in my math/proofs class)
from math import floor, log10
import sys
WORDS = {
0: 'zero',
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
@Techcable
Techcable / recursive_sizeof.py
Created November 15, 2021 03:40
A version of sys.sizeof that functions recursively
from __future__ import print_function
from sys import getsizeof, stderr
from itertools import chain
from collections import deque
try:
from reprlib import repr
except ImportError:
pass
def total_size(o, handlers={}, verbose=False):