Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
# klg, Jan 2017
use strict;
use open ':std', IO => ':bytes';
use Bencode 'bdecode';
my $meta = eval { bdecode(do { local $/; <> })->{info} };
die "Invalid BitTorrent metainfo file: $@" if $@;
if ($$meta{length}) {
/* cc -O3 -nostdlib -static -fno-builtin -s hello.c */
#if defined __x86_64__
#define SYS_exit 60
#define SYS_write 1
static __attribute__ ((noreturn))
void exit(int status) {
__asm__ volatile (
@mwgamera
mwgamera / checked-box.svg
Created September 21, 2016 04:37
Prettier checkboxes for Zim based on shapes from Symbola font.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mwgamera
mwgamera / PNM.apl
Last active November 1, 2017 06:05
PNM in GNU APL. Slow, but usable.
⍝!
⍝ PBM/PGM/PPM
⍝ klg, Aug 2016
PNM∆∆WS←⎕UCS 32 9 13 10
∇PNM∆∆Assert X
'PNM Syntax Error' ⎕ES (~X)/5 4
@mwgamera
mwgamera / webpm.js
Last active April 4, 2018 06:53
Support simple lossy WebPs in Firefox (See https://github.com/antimatter15/weppy for prior art; NIH, Blobs, less moving parts)
"use strict";
// klg, Sep 2016
function LoadWebP(url) {
// Fetch the WebP
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.onerror = function (e) { reject(e); };
" APL keymap for VIM
" klg, Jul 2016
scriptencoding utf-8
let b:keymap_name = "APL"
com -nargs=1 APLQuoteKeyboard let s:keyboard = <q-args>
APLQuoteKeyboard
\ ╔════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦════╦══════════╗
\ ║ ~ ║ !⌶ ║ @⍫ ║ #⍒ ║ $⍋ ║ %⌽ ║ ^⍉ ║ &⊖ ║ *⍟ ║ (⍱ ║ )⍲ ║ _! ║ +⌹ ║ ║
\ ║ `⋄ ║ 1¨ ║ 2¯ ║ 3< ║ 4≤ ║ 5= ║ 6≥ ║ 7> ║ 8≠ ║ 9∨ ║ 0∧ ║ -× ║ =÷ ║ Backsp ║
⍝!
⍝ RFC 7159 JSON
⍝ klg, Jul 2016
⍝ vim:kmp=apl:
∇JSON∆∆Assert X
'JSON Syntax Error' ⎕ES (~X)/5 4
∇R←A JSON∆∆Expect J
@mwgamera
mwgamera / APKBUILD
Last active September 8, 2019 20:49
Archiveteam's Wget with Lua hooks for Alpine Linux
# Maintainer: klg <[email protected]>
pkgname=wget-lua
pkgver=1.14_git20160530
_pkgver=1.14.lua.20160530-955376b
pkgrel=3
pkgdesc="Wget with Lua extensions"
url="https://www.archiveteam.org/index.php?title=Wget_with_Lua_hooks"
arch="all"
license="GPL3+"
depends=""
#!/bin/sh
# klg, Apr 2016
set -e
UPSVN="$(git log -n 1 --format=%H --grep '^git-svn-id:' -- "$@")"
if [ -z "$UPSVN" ]; then
echo >&2 "No git-svn commit found"
exit 1
fi
@mwgamera
mwgamera / EDIT.apl
Last active March 21, 2016 23:19
]EDIT FN user command for GNU APL
⍝!
⍝ klg, Mar 2016
]USERCMD ]EDIT EDIT⍙ 1
∇S EDIT⍙ Q;FN;FD
⍝ Edit a function or operator in external editor.
⍎(2>≡S)/"']EDIT NAME' ⋄ →0"
S←(⎕IO+1)⊃S
⍎(2=⎕NC S)/"S,' is a variable' ⋄ →0"