Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

// ==UserScript==
// @name Arxiv PDF Title Updater for Hypothesis Pages
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Update Arxiv PDF links titles on Hypothesis pages
// @author David Bieber + GPT-4
// @match *://*.hypothes.is/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
@dbieber
dbieber / shebang.py
Created February 15, 2021 00:45
A simple Python Fire CLI using a shebang line
#!/usr/bin/env -S python3 -m fire
def hello(name):
return f'Hello {name}!'
@dbieber
dbieber / roam-blocks.js
Last active October 3, 2021 11:59
JavaScript Functions for Inserting Blocks in Roam. Documentation at https://davidbieber.com/snippets/2021-02-12-javascript-functions-for-inserting-blocks-in-roam/
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function getPage(page) {
// returns the uid of a specific page in your graph.
// _page_: the title of the page.
let results = window.roamAlphaAPI.q(`
[:find ?uid
:in $ ?title
@dbieber
dbieber / detect.py
Created January 5, 2021 02:47
Automatic distraction detection. Detects visits to distraction websites on your phone from your computer.
"""Automatic distraction detection. Work in progress.
Usage:
python detect.py main
"""
import fire
import subprocess
import plyvel
import re
@dbieber
dbieber / roam-unlinked-references-query.js
Last active July 23, 2022 03:04
Roam Research datalog query for references not already placed on a specific page
let container = "Tree of knowledge";
let tag = "zettel";
let ancestorrule=`[
[(ancestor ?child ?parent)
[?parent :block/children ?child]]
[(ancestor ?child ?a)
[?parent :block/children ?child]
(ancestor ?parent ?a)]
]`;
@dbieber
dbieber / fastbook.py
Last active August 10, 2023 18:13
fastbook speeds up the silence in audiobooks, and can speed up the non-silence too
"""Performs automatic speed edits to audio books.
Example usage:
Assuming you have an audiobook book.aax on your Desktop:
1. Convert it to wav:
ffmpeg -i ~/Desktop/book.aax ~/Desktop/book.wav
2. Adjust the speed:
@dbieber
dbieber / archivePastEvents.gs
Created December 29, 2019 23:44
Code used for archiving past events in the daily activity log spreadsheet.
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Activity Log')
.addItem('Archive Past Events', 'archivePastEvents')
.addToUi();
}
function archivePastEvents() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("Activities");
@dbieber
dbieber / spreadsheet.gs
Created October 21, 2018 18:57
The source of SpreadsheetDB used in the "Writing a Mail Merge in Google Apps Script" post on blog.davidbieber.com
function getColumnIndexes(columns) {
// Returns a map from column name to column index.
var container = {};
for (var i = 0; i < columns.length; i++) {
var value = columns[i];
container[value] = i;
}
return container;
}
@dbieber
dbieber / dksnake.js
Created January 5, 2017 13:06
Plays Snake game at dskang.com/snake/
// Computer assisted snake!
// Paste this into the JS console at http://dskang.com/snake/ to play and win!
function getX() {
var head = gSnake.getHead();
var x = head.x / 20;
return x;
}
function getY() {
@dbieber
dbieber / adorable.py
Created November 9, 2014 00:20
Uses Firefox with Selenium to take a picture of kittens on Google Images
from selenium import webdriver
driver = webdriver.Firefox()
driver.set_window_size(800, 600)
driver.set_window_position(0, 0)
driver.get("https://images.google.com")
searchbar = driver.find_elements_by_css_selector("#lst-ib")[0]
searchbar.send_keys("cute kittens")
searchbar.submit()