Skip to content

Instantly share code, notes, and snippets.

@divs1210
divs1210 / sequence.clj
Last active March 7, 2024 10:06
clojure.core/sequence implemented in plain Clojure
(ns sequence
(:refer-clojure :exclude [sequence sort])
(:require [clojure.core :as core]))
;; Helper
;; ======
(defn accumulate
([])
([acc] acc)
([acc x] (conj (vec acc) x)))
@divs1210
divs1210 / transducerExpansion.js
Last active March 4, 2024 13:03
Transducer expansion
function mapping(f) {
return function(rf) {
return function(acc, x) {
return rf(acc, f(x))
}
}
}
function filtering(f) {
return function(rf) {
@divs1210
divs1210 / AVLSort.js
Created February 28, 2024 18:03
Sorting using self-balancing AVL tree
function getHeight(tree) {
return tree === null? 0: tree.height
}
function newHeight(leftSubtree, rightSubtree) {
return Math.max(getHeight(leftSubtree), getHeight(rightSubtree)) + 1
}
function insert(tree, e) {
if(tree === null)
@divs1210
divs1210 / StackGC.js
Last active January 10, 2024 07:19
Async JS is Stackless
// StackGC
// =======
const StackGC = async () => null;
// Tests
// =====
// util
function assert(assertion, msg) {
console.assert(assertion, `%s`, msg);
@divs1210
divs1210 / stackless-eval.md
Last active January 10, 2024 07:19
Writing a Stackless Evaluator

Writing a Stackless Evaluator

Divyansh Prakash, September 2023

tiny-stackless-eval

Preface

NOTE: Please read the previous post to understand the context of this post.

@divs1210
divs1210 / stackless.md
Last active October 6, 2023 13:41
Cut me some stack - a deep dive into trampolines

Cut me some stack

(a deep dive into trampolines)

Divyansh Prakash, September 2023

scuba diver trampoline

Preface

@divs1210
divs1210 / react-starter.html
Created September 25, 2023 19:39
react-browser-starter
<!DOCTYPE html>
<html lang="en">
<title>Test React</title>
<head>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
</head>
<body>
<div id="app"></div>
@divs1210
divs1210 / stackless-eval-playground.html
Last active September 13, 2023 09:42
Stackless Eval Playground
<html>
<head>
<script type="text/javascript">
// Trampoline
// ==========
class Thunk {
constructor(f) {
this.f = f;
}
}
@divs1210
divs1210 / csp.js
Created September 13, 2023 09:09
Go-style CSP in JavaScript
const CLOSED = Symbol('chan-closed');
const StackGC = async () => null;
class Chan {
constructor(size) {
this.q = [];
this.size = size || 1;
this.isClosed = false;
}
@divs1210
divs1210 / SLIP.py
Last active May 24, 2023 23:14
helps escape the Python's clutch
import types
# Helpers
# =======
def _obj():
'''Dummy object'''
return lambda: None
_FILLER = _obj()