Skip to content

Instantly share code, notes, and snippets.

@dbieber
dbieber / shebang.py
Created Feb 15, 2021
A simple Python Fire CLI using a shebang line
View shebang.py
#!/usr/bin/env -S python3 -m fire
def hello(name):
return f'Hello {name}!'
View roam-blocks.js
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 Jan 5, 2021
Automatic distraction detection. Detects visits to distraction websites on your phone from your computer.
View detect.py
"""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 Jan 3, 2021
Roam Research datalog query for references not already placed on a specific page
View roam-unlinked-references-query.js
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 Mar 23, 2021
fastbook speeds up the silence in audiobooks, and can speed up the non-silence too
View fastbook.py
"""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 Dec 29, 2019
Code used for archiving past events in the daily activity log spreadsheet.
View archivePastEvents.gs
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 Oct 21, 2018
The source of SpreadsheetDB used in the "Writing a Mail Merge in Google Apps Script" post on blog.davidbieber.com
View spreadsheet.gs
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 Jan 5, 2017
Plays Snake game at dskang.com/snake/
View dksnake.js
// 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 Nov 9, 2014
Uses Firefox with Selenium to take a picture of kittens on Google Images
View adorable.py
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()
@dbieber
dbieber / viterbi.py
Last active Jan 2, 2016
Creates a markov model and implements viterbi. Given a sequence of local belief states (observations), finds the most likely sequence of states.
View viterbi.py
def get_probabilities(corpus, alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
corpus = ''.join([c for c in corpus if c in alpha])
counts = [corpus.count(c) for c in alpha]
start_probs = np.array(counts, dtype=float) / sum(counts)
trans_counts = [[0.1 + corpus.count("%s%s" % (a,b)) for b in alpha] for a in alpha]
trans_probs = np.array([np.array(x, dtype=float)/sum(x) for x in trans_counts])
return (start_probs, trans_probs)
start_probs, trans_probs = get_probabilities("THISSHOULDBEAHUGESTRINGLIKETHISBUTHUNDREDSOFTIMESBIGGER")