Skip to content

Instantly share code, notes, and snippets.

@jpjacobs
jpjacobs / som.ijs
Last active February 29, 2016 14:08
Kohonen SOM
NB. Self-Organising map
require 'math/lapack/geev'
require 'tables/csv'
require 'viewmat'
NB. closeall_jviewmat_ ''
NB. parameters:
N =: 30 NB. side of neuron map. (N -> (*:N) neurons)
ntrain =: 25 NB. number of training samples per class
niter =: 10000 NB. number of iterations
'a0 an' =: 25 1 NB. Starting and ending learning factor
@koo5
koo5 / source.txt
Created November 22, 2012 02:59
"The Amazing Interactive Turing Machine" by "J.D. Clemens"
"The Amazing Interactive Turing Machine" by "J.D. Clemens"
Section 1 - Bibliographic Data
The story headline is "An Interactive Waste of Time".
The story genre is "Other".
The story description is "You have almost reached the end of your shift. All that remains is to clean one final room, the control room for that weird contraption being built by the scientists here. Carrying your usual equipment, you open the door and step into... The Amazing Interactive Turing Machine!"
Release along with source text and a website.
@tangentstorm
tangentstorm / something4thy.js
Created August 2, 2013 04:22
something 4thy this way comes...
var b4 = (new function() { var EOF='\0',self = {
d:[], a:[], // data and auxiliary/return stack
defs:[],core:[],scope:[], // dictionary
base:10, // numbers
cp:-1, ch:'\x01',ibuf:[],wd:'', // lexer state
compiling:false,state:[],target:[], // compiler state
def : function (k,v){
var res=self.defs.length; self.defs.push(v); self.scope[0].push([k,res]); return res },

fml

The function manipulation language

"I just implemented Conway's Game of Life in two lines of code. #fml"

pad = x flip[stitch] 0, stitch 0, flip[cat] 0, cat 0
life = pad, neighborhoods[3 3], [ravel, [sum in?: [x @ 4, + 3; 3]]]/2
@tangentstorm
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:
/ http://tangentstorm.github.io/draft/wejalboot.py.html
/ -- misc helper functions ------------------------------------
join:{[sep;strs] / join strs with 'sep' as delimiter
(#sep) _ ,/ sep,' strs}
@emmanuel
emmanuel / file.sql
Created June 2, 2011 07:54
Closure Table operations SQL fragments
-- Retrieve descendants
-- ====================
-- retrieve descendants of #4
SELECT c.*
FROM Comments AS c
JOIN TreePaths AS t ON c.comment_id = t.descendant
WHERE t.ancestor = 4;
-- Retrieve ancestors
@ik5
ik5 / dynamic_method.pas
Created June 18, 2012 21:17
How dynamically execute a method in Object Pascal Class
{$mode objfpc}{$M+}
program test;
type
TMyClass = class
procedure SayHi;
end;
procedure TMyClass.SayHi;
begin
@onlurking
onlurking / programming-as-theory-building.md
Last active April 19, 2024 22:31
Programming as Theory Building - Peter Naur

Programming as Theory Building

Peter Naur

Peter Naur's classic 1985 essay "Programming as Theory Building" argues that a program is not its source code. A program is a shared mental construct (he uses the word theory) that lives in the minds of the people who work on it. If you lose the people, you lose the program. The code is merely a written representation of the program, and it's lossy, so you can't reconstruct

@tangentstorm
tangentstorm / sh.mjs
Last active April 21, 2024 12:16
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)=>ixs.map(i=>a[i])
export const io=(xs,ys)=>ys.map([].indexOf.bind(xs))