Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
# This script creates Idris2.docset for use in Dash.app
# It expects idris to be in ~/.idris2 and is hardcoded to 0.5.1 at the moment.
import os, sqlite3, html5lib, re
oj = os.path.join
debug = lambda *x: None
@dunhamsteve
dunhamsteve / getcraftdoc
Last active May 20, 2021 00:26
Copy a shared craft document to pasteboard
#!/usr/bin/env python3
# pip3 install pyobjc requests
from AppKit import NSPasteboard
import json, requests, re, sys
def rewrite(url):
m = re.match(r'https://www.craft.do/s/(\w+)',url)
if not m:
@dunhamsteve
dunhamsteve / dumpCraftDB.js
Last active May 1, 2021 03:50
This script exports your Craft.app databases as json files.
#!/usr/bin/env node
// Placed in the public domain
// Dump craft database as json
// This is intended as a sample of how to extract craft raw data for
// playing around with. It has no dependencies aside from node.
// The top section reads the Craft DB into memory (takes about 380ms for 50k blocks)
#!/usr/bin/env node
// Placed in the public domain
// list folders in primary Craft space
// I've combined this into one file for the gist
// The top reads the Craft DB into memory (takes about 380ms for 50k blocks)
// The end looks up and prints the folder names
// You can reuse the top bits for other purposes.
@dunhamsteve
dunhamsteve / paperback
Created January 15, 2021 17:10
Script to back up dropbox paper
#!/usr/local/bin/python3
# Backup dropbox paper.
# This expects a ~/.auth/dropbox file that contains your dropbox bearer token.
import requests, os, json, re
from pprint import pprint
oj = os.path.join
@dunhamsteve
dunhamsteve / notion_todo.py
Created December 5, 2018 02:55
reads cached data from Notion.app's localStorage, collects incomplete todo items, and writes them to todo.html
#!/usr/bin/env python3
# This is written for OSX, python3, and the current (2018-12-04) version of the Notion app
# It writes incomplete todo items, found in Notion's localStorage, to a "todo.html" file,
# with links back to the Notion app
import os
import sqlite3
import json
from html import escape
@dunhamsteve
dunhamsteve / framework2proto.py
Last active August 7, 2025 14:08
python3 script to infer a protobuf definition from a framework or executable.
#!/usr/local/bin/python3
import re, subprocess, sys
if len(sys.argv) < 2:
print('''
This utility generates a protobuf file from an Objective C framework. It was developed against
CloudKit/CloudKitDaemon, but may work with other libraries that are built the same way.
''')
print("Usage:\n\t",sys.argv[0],"MachOBinary\n")
@dunhamsteve
dunhamsteve / fixfootnotes.py
Created March 25, 2014 05:10
This is a rough script to rewrite footnotes in an epub file to match what iBooks expects for pop-up footnotes. I'm posting it in case it is useful to someone.
#!/usr/bin/python
# Written and placed in the public domain by Steve Dunham
# Tries to find footnotes in an epub and transform them into iBooks/epub3 popup footnotes.
#
# This works with a couple of Terry Pratchett books, it will probably need tweaking for other books.
# This script tries to:
#
# - find the footnote links
@dunhamsteve
dunhamsteve / hn.user.js
Last active January 4, 2016 04:59
Hacker News tweaks: save as hn.user.js, drop on chrome://extensions page.
// ==UserScript==
// @match https://news.ycombinator.com/*
// ==/UserScript==
(function () {
document.body.style.backgroundColor = "#f6f6ef";
var s = document.createElement('style');
s.innerText = "td.default {max-width: 40em; } "+
"body { background-color: #f6f6ef; } "+
".comment { font-size: 12px; } "+
@dunhamsteve
dunhamsteve / sort.js
Created December 3, 2013 19:42
Quick and dirty sortable table for javascript. (I wrote this to embed in a single page html report.)
function sortedTable(id) {
var table = document.getElementById(id);
table.lastColumn = -1;
table.onclick = function(ev) {
if (ev.target.nodeName == 'TH') {
var row = ev.target.parentNode;
for (var j=0;j<row.cells.length;j++) {
if (row.cells[j] == ev.target) {
var rows = [];
for (var i=1;i<table.rows.length;i++) {