Skip to content

Instantly share code, notes, and snippets.

View dominictarr's full-sized avatar

Dominic Tarr dominictarr

View GitHub Profile
@dominictarr
dominictarr / thumbnails.js
Last active February 9, 2026 03:54
test script for generating thumbnails in an electron app
//updated to save thumbnails!
var h = require('hyperscript')
var fs = require('fs')
var pull = require('pull-stream')
var paramap = require('pull-paramap')
var path = require('path')
//XXX note, I added `module.exports = downsample` to the bottom of this file, TODO: make PR
var downsample = require('downscale/src/downsample')
(module
(def strings (import "./strings"))
(def _match (mac R (str i) (block
(def len (strings.length str))
(if (eq i (sub len 1))
&(if (eq (strings.at input (add start $i)) $(strings.at str i)) len -1)
&(if (eq (strings.at input (add start $i)) $(strings.at str i))
(R $str $(add 1 i)) -1)
)
@dominictarr
dominictarr / readme.md
Created September 25, 2014 12:58
What is the Chi Squared Test?

The Chi Squared test is used when you want to decide if a dice is fair (random) or not, or for problems that fit that pattern. Sometimes we want to know that some event is equally likely, a the probability that a dice comes up 6 should be equal to the probability that it comes up 1. Some times we want to show the opposite, that two categories are actually different. Say, there are a series of races - is the winner of the most races actually better, or was it just a fluke?

Of course, we can roll a dice many, many times until we are sure it's fair, but it takes too long to have many races. So for the race need to calculate whether the random variables (the times that each participant won) are independent (random, fair) while only looking at a few examples. Depending on the number of participants, how many times do we need to race before we know that the winner is actually faster?

@dominictarr
dominictarr / logdb.md
Last active January 30, 2026 08:40
ideas for a modular database

intro

we've had great success building modular database stuff on top of leveldb with node, but as I have learnt more about databases it's become apparent to me that the idea of a modular database would be better implemented at a slightly lower level.

Level db provides a sorted key:value store, which, because of the sorted property, many things can be implemented on top of. For example, for replication, or for consistent materialized views, we often need a write ahead log. This can easily be implemented via a batch write to level, and writing the log into a section of the leveldb key space which is treated as append only.

there are two fundamental types of streams source and sink. There are two composite types of streams through (aka transform) and duplex A through stream is a sink stream that reads what goes into the source. a duplex stream is a pair of {source, sink} streams.

Source streams have two methods.

readable stream: source

A source (readable stream) is an async function that may be called repeatedly until it returns a terminal state. You must not call the read function until the previous call has returned, except for a call to abort the stream. pull-streams have back pressure, but it implicit instead of sending an explicit back pressure signal. If a source

@dominictarr
dominictarr / box-stream-with-nonce.js
Last active January 30, 2026 07:51
example of how to read a fixed size binary prefix to a pull-stream
var Reader = require('pull-reader')
var box = require('./')
var pCont = require('pull-cont')
var randomBytes = require('crypto').randomBytes
var pull = require('pull-stream')
var Cat = require('pull-cat')
//key is 32 bytes and nonce is 24 bytes, written to start of stream.
exports.unbox = function UnboxStreamWithNonce (key) {
@dominictarr
dominictarr / aggregate-help.js
Created December 2, 2019 08:12
aggregate muxrpc-usage help
module.exports = function (sbot, cb) {
var help = null
sbot.help(function (err, data) {
if(!data.type) data.type = 'group'
help = data
var keys = Object.keys(sbot)
var n = keys.length + 1
keys.forEach(function (key) {
if(sbot[key] && 'function' === typeof sbot[key].help)
sbot[key].help(function (err, data) {
@dominictarr
dominictarr / readme.md
Created November 26, 2018 22:39
statement on event-stream compromise

Hey everyone - this is not just a one off thing, there are likely to be many other modules in your dependency trees that are now a burden to their authors. I didn't create this code for altruistic motivations, I created it for fun. I was learning, and learning is fun. I gave it away because it was easy to do so, and because sharing helps learning too. I think most of the small modules on npm were created for reasons like this. However, that was a long time ago. I've since moved on from this module and moved on from that thing too and in the process of moving on from that as well. I've written way better modules than this, the internet just hasn't fully caught up.

@broros

otherwise why would he hand over a popular package to a stranger?

If it's not fun anymore, you get literally nothing from maintaining a popular package.

One time, I was working as a dishwasher in a restu

@dominictarr
dominictarr / index.js
Created May 19, 2014 13:22
lodash.noop
/**
* Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>
* Build: `lodash modularize modern exports="npm" -o ./npm/`
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <http://lodash.com/license>
*/
/**