Skip to content

Instantly share code, notes, and snippets.

@williamstein
williamstein / syncdoc.coffee
Created November 14, 2014 22:30
BSD-licensed Differential Synchroniziation code with synchronized database built on top.
###################################################################
#
# Code to support simultaneous multiple editing
# sessions by different clients of a single object. This uses
# the Differential Synchronization algorithm of Neil Fraser,
# which is the same thing that Google Docs uses.
#
# * "Differential Synchronization" (by Neil Fraser).
# * http://neil.fraser.name/writing/sync/
# * http://www.youtube.com/watch?v=S2Hp_1jqpY8
@williamstein
williamstein / replace
Created October 23, 2015 14:31
A simple replace script that I wrote long ago
#!/usr/bin/python
import os, sys
argv = sys.argv
if len(argv) < 4:
print "*********\nThis is the replace command, by William Stein (was@math.harvard.edu)\n*********"
print "\tUsage: %s [-f] <from> <to> [file 1] [file 2] ..."%argv[0]
print "Optional argument -f is to not ask for confirmation.";
sys.exit(0)
https://news.ycombinator.com/reply?id=13613909&goto=item%3Fid%3D13610146%2313613909
---
smc=# explain SELECT * FROM file_use WHERE project_id = any(select project_id from projects where users ? '25e2cae4-05c7-4c28-ae22-1e6d3d2e8bb3') ORDER
BY last_edited DESC limit 100;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.85..8198.07 rows=100 width=242)
-> Nested Loop Semi Join (cost=0.85..1736663.69 rows=21186 width=242)
#!/usr/bin/env python
######################################################################
# Copyright (c) 2013, William Stein, Ondrej Certik, All rights reserved.
# 2-clause BSD.
######################################################################
import json, os, random, BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
@williamstein
williamstein / demo.py
Created October 26, 2020 20:24
demo.py
def f(n):
print("hello ", n, "!")
@williamstein
williamstein / gist:5d1f5f77614c9a48d5adc9c2078647a8
Created September 28, 2022 21:57
converting local file imports
#!/usr/bin/env node
import * as fs from 'fs';
import * as path from 'path';
// https://gist.github.com/lovasoa/8691344
async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) {