Skip to content

Instantly share code, notes, and snippets.

View PanJarda's full-sized avatar

Jaroslav Pernica PanJarda

  • Prague, Czech Republic
View GitHub Profile
function Tuple(car, cdr) {
this.car = car
this.cdr = cdr
}
function List(val) {
Tuple.call(this, val, null)
}
List.prototype = Object.create(Tuple.prototype)
@PanJarda
PanJarda / trie.js
Created February 16, 2017 11:10
Trie in js
/**
* Trie
*/
function trie(s) {
s += ''
var t = {}
s.length > 1 ? t[s[0]] = trie(s.substring(1)) : s.length ? t[s] = false : t = false
return t
}
@PanJarda
PanJarda / telseznam.js
Created February 16, 2017 12:49
Tel. seznam trie
/**
* Tel seznam trie
*/
function trie(key, value) {
key += ''
var t = {}
key.length > 1 ? t[key[0]] = trie(key.substring(1), value) : t[key] = {val: value}
return t
}
@PanJarda
PanJarda / self-modifying.js
Last active February 16, 2017 21:57
Self modyfiing js
/**
* Self modifying code
*/
function genF(x) {
return new Function('x', 'return x + ' + x)
}
function screw(f) {
var src = f.toString()
@PanJarda
PanJarda / vm.js
Created February 19, 2017 18:13
Stack based JIT vm in JS
var c,i,s,p,opcodes
c = '10 20 add 5 sub'
i = 0
s = new Array(100)
p = -1
opcodes = {
'add': 's[p - 1] = s[p--]*1 + s[p]*1',
'sub': 's[p - 1] = s[p - 1]*1 - s[p--]*1;'
}
@PanJarda
PanJarda / pico-elm.html
Last active December 16, 2017 16:48
Ultra pico elm architecture showcase without virtual-dom.
<!DOCTYPE html>
<title>pico-elm2</title>
<style>
body {
font-family: sans-serif;
background-color: #E1E7EF;
}
.app {
width: 200px;
overflow: auto;
@PanJarda
PanJarda / toy.spec.txt
Last active November 10, 2017 17:59
toy - typed joy
; Number je nakej primitivni datovy typ treba
[ > ] (Number Number) : vetsi-mensi
[ - ] (vetsi-mensi) : odcitani-co-skonci-kladne
; ta typova anotace se da udelat i anonymni
[ - ] ( > ) : odcitani-co-skonci-kladne
{
"boardSize": [8,8],
"player1": -1,
"player2": 1,
"initialBoard": [
[0,0,0,0,0,0,0,0],
[1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
@PanJarda
PanJarda / toy-interpreter.js
Last active November 11, 2017 23:52
Toy - concatenative, functional, stack-based, truly postfix language.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let stack = [];
let consts = {
swapd: '[[swap] dip]',
popd: '[[pop] dip]',
@PanJarda
PanJarda / dame.c
Last active December 19, 2017 11:45
Turkish draughts in c
#include <stdio.h>
#include <stdlib.h>
#define BSIZE 8
#define ERRSCAN 1
#define ERRMEM 2
typedef struct vec {
char x;
char y;