Skip to content

Instantly share code, notes, and snippets.

tangentstorm / sh.mjs
Last active April 9, 2024 11:05
shorthand javascript
// sh.mjs: javascript shorthand
// array helpers (apl/j/k)
export const id=x=>x
export const af=(n,x)=>Array(n).fill(x) // TODO: make this 'afl' or 'fil' (aa?)
export const ii=(n,f)=>{for(let i=0;i<n;i++)f(i)}
export const im=(n,f)=>af(n,0).map((_,i)=>f(i))
export const ia=(n,f)=>im(n,id)
export const at=(a,ixs)=>>a[i])
export const io=(xs,ys)=>[].indexOf.bind(xs))
tangentstorm / ts-list.js
Created March 7, 2024 06:55
a list component i made in the chrome developer tools by running developer tool snippets against about:blank
customElements.define('ts-list', class extends HTMLElement {
static observedAttributes = ['ix']
constructor() { super(); this.ix=0 }
connectedCallback() {
let sh = this.attachShadow({mode: 'open'})
<button id="up">^</button>
<button id="add">+</button>
<button id="dn">v</button>`
tangentstorm / stripped.js
Created February 19, 2024 06:28
javascript parser combinators ( )
let set=(o,k,v)=>{let r={...o}; r[k]=v; return r}
let gs=k=>(x,y)=> y===undefined ? x[k] : set(y,k,x)
let mb=gs('mb'), // match bit
ib=gs('ib'), // input buffer
ix=gs('ix'), // index into input buffer
ch=gs('ch'), // current character (ib[ix])
mk=gs('mk'); // start index of current token
let s0=()=>({mb:0,ib:'',ch:'',ix:-1,mk:-1})
m1=s=>mb(1,s) // match
tangentstorm /
Last active November 21, 2023 22:56
Port of Roassal's RSAnimationExamples >> example05ElasticEllipses to Bloc
Class {
#name : #GsEllipse,
#superclass : #GsObject,
#instVars : [
#category : #GameSketchLib
tangentstorm / pcapdemo.pas
Created July 5, 2014 12:54
pascal / winpcap example ... i don't get any packets
{$mode delphi}
program pcapdemo;
uses pcap, sysutils, crt;
procedure throw(msg:string; detail:pchar);
begin raise Exception.Create(msg + ': ' + detail)
function IPv4ToStr(addr:dword) : string;
// this probably exists somewhere but i don't know where.
tangentstorm / oK-bot.js
Created September 11, 2015 22:44
K5 bot for #learnprogramming and #jsoftware on freenode
// An IRC bot for the k5 programming language,
// using oK from :
"use strict";
var irc = require('irc');
var ok = require('./ok/ok');
const MAXLINES = 8;
var client = new irc.Client('', 'oK-bot', {
channels: ['#jsoftware', '#learnprogramming']
tangentstorm /
Created March 10, 2022 03:32
simple command language parser for jprez in gdscript (godot).
# i wrote this, and it works, but then i decided to just use Godot's own Expression parser.
func _examples():
test('@title["the deck"]')
test('@show["jp-editor"; 0]')
test('@ed.xy[ 0 5]')
func test(cmd:String):
if cmd.begins_with('@'):
tangentstorm / animation.ijs
Created August 12, 2019 14:58
Basic animation in J
NB. Code from the "Basic Animation In J" video
NB. ------------------------------------------------------------------------
NB. animation demo
load 'viewmat'
wd 'pc w0 closeok' NB. parent control (window) named 'w0'
tangentstorm / ed.ijs
Last active July 29, 2021 10:59
A tiny editor in J
NB. Core logic for a tiny editor in J.
NB. No select/copy/paste (in this gist), but it does support multiple cursors.
NB. This started as the code for editing a single line of text, but I'm now
NB. using three copies simultaneously: one for a single token, one for
NB. boxed tokens on a line, and one for boxed lines in a buffer.
coclass 'ed'
init =: {{
B =: '' NB. the buffer to edit.
C =: 0 NB. cursor position(s)
tangentstorm / gramco.k
Last active July 8, 2021 07:34
Rough port of my grammar combinator thing to k3.
/ grammar combinators in K
/ for longer description (in python), see:
/ -- misc helper functions ------------------------------------
join:{[sep;strs] / join strs with 'sep' as delimiter
(#sep) _ ,/ sep,' strs}