Skip to content

Instantly share code, notes, and snippets.

View 0atman's full-sized avatar
🦀
Oxidising

Tristram Oaten 0atman

🦀
Oxidising
View GitHub Profile
@0atman
0atman / pmap.py
Last active February 5, 2020 10:02
A process-based pmap with sensible defaults, ready to go
from multiprocessing import Pool
def pmap(f, collection, size=10):
"""
Applies `f` in parallel over `collection`.
Pool `size` has a sensible default of 10.
"""
with Pool(size) as p:
return p.map(f, collection)
@0atman
0atman / ministore.py
Last active October 9, 2017 13:33
A thin rest wrapper around a python shelf
#!/usr/bin/blaze pex flask flask-restful --
import shelve
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
with shelve.open('ministore.db') as db:
@0atman
0atman / README.md
Last active June 2, 2024 17:01
The Testable Documentation Manifesto

#! blaze sh

The Testable Documentation Manifesto

One of the problems with tech documentation (api, installation instructions etc) is that they get stale. APIs change, software and plugins alter their interface and commands, and websites go away.

To solve this, I propose we write our documentation in a way that can be executed, or verified.

Luckily, I wrote blaze to execute codeblocks inside of markdown, which means that with a little help from a few common unix tools, we can solve this problem.

(defn tester [x]
{:pre [(is (even? x))]}
x)
@0atman
0atman / blaze.md
Last active November 1, 2017 19:05
Blaze is lit. It allows language-agnostic literate-style programming
@0atman
0atman / pexed
Last active September 7, 2017 14:11
A simple wrapper around `pex`. For self-contained python scripts.
#!/usr/bin/env sh
requirements=$1
script=$2
exec pex $requirements -- $script
@0atman
0atman / future.clj
Last active September 27, 2017 12:04
Hy implamentation of Clojure's awesome `future` call
(import [multiprocessing.pool [ThreadPool]])
(defmacro future [code]
(def t (gensym))
(def pool (ThreadPool :processes 1))
`(do
(def ~t (pool.apply-async (fn [] ~code)))
~t))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.20.0/vis.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.20.0/vis.min.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#mynetwork {
width: 600px;
height: 400px;
border: 1px solid lightgray;
(defn return_after_5_secs [message]
(do (Thread/sleep 5000) message))
future = (future return_after_5_secs “hello”)
(realized? future)
(Thread/sleep 5000)
(realized? future)
(println @future)