Skip to content

Instantly share code, notes, and snippets.

View dblume's full-sized avatar

David Blume dblume

View GitHub Profile
@dblume
dblume / logpower.sh
Last active May 12, 2024 06:39
Log to file the current state of the battery to track trends
#!/usr/bin/env bash
#
# A script I use to track the health of my FrameWork laptop battery
#
# Usage Ex.,
#
# $ logpower closing lid
#
# will write to stdout and to a file:
# 1. Timestamp
@dblume
dblume / timestamps_match_clock.py
Created February 27, 2024 21:40
Unix Timestamps whose lower digits match the clock time's digits too
#!/usr/bin/env python3
import time
# Timestamps whose lower digits are zero when the clock's are too HH:MM:SS "00:00:00"
# Eg., 1800000000 = 2027-01-15 00:00:00
million = 1_00_00_00
t = (int(time.time()) // million + 1) * million
while time.strftime("%H%M%S", time.localtime(t)) != '000000':
t += million
print(f'{t} = {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t))}')
@dblume
dblume / openpgp.md
Created May 27, 2023 08:29
Proof for keyoxide

openpgp4fpr:1CBD499C61C7A3A7DED3935F5E21C0D40ED9EB54

@dblume
dblume / qrcodes.sh
Created March 20, 2021 02:24
Find a QR code with as few black dots as possible.
#!/usr/bin/env bash
#
# Spoiler:
# $ ./qrcodes.sh | sort | head
# 416 http://7c.dblu.me
# 416 https://j.dblu.me
# 416 http://wc.dblu.me
# 420 http://2E.dblu.me
# 420 http://73.dblu.me
#
@dblume
dblume / playlists_from_itunes_xml.py
Created November 2, 2020 19:10
Make a list of playlists from an iTunes XML file
#!/usr/bin/env python3
import libpytunes # https://github.com/liamks/libpytunes
if __name__ == '__main__':
l = libpytunes.Library('iTunes Music Library.xml')
with open('playlists.txt', 'w', encoding='utf-8') as f:
for p in l.getPlaylistNames():
if p not in ('Downloaded', 'Audiobooks', 'Voice Memos', 'Not One Star Rating'):
f.write(p)
@dblume
dblume / city_names.py
Created July 3, 2018 04:05
A Python solution to the "How to Lose an IT Job in 10 Minutes" puzzle
#!/usr/bin/env python
# From https://hackernoon.com/how-to-lose-an-it-job-in-10-minutes-3d63213c8370
#
# Find cities whose names are rotated versions of other cities.
#
# Given: ['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris']
#
# Return:
#
#[[ 'Tokyo', 'Kyoto' ],
@dblume
dblume / fathers_day_puzzle2.py
Created June 30, 2018 23:41
Father's Day puzzle #2: Smallest number with persistence five.
#!/usr/bin/env python
# Father's Day Card Puzzle #2
# A number's persistence is the number of steps to reduce it to a single
# digit by multiplying all its digits to obain a second number, then
# multiplying all the digits of that number to obtain a third number, and so
# on until a one-digit number is obtained.
#
# For example 77 has a persistence of four because it requires four steps to
# reduce it to one digit: 77 -> 49 -> 36 -> 18 -> 8. The smallest number of
# persistence one is 10. The smallest number of persistence two is 25. The
@dblume
dblume / fathers_day_puzzle3.py
Last active July 5, 2018 16:49
Father's Day Puzzle #3, sort of like a magic square, but not a square.
#!/usr/bin/env python
#
# Father's Day card puzzle #3:
# In the figure below, fill in each of the sixteen numbers from 1 to 16 such
# that the four rows and three columns add up to 29.
#
# ( )---( )---( )
# | |
# ( )---( )---( )---( ) ( )
# | | |
@dblume
dblume / confluence_markup.lua
Last active April 5, 2017 17:25
Script for converting to Atlassian Confluence's markup with Pandoc.
-- confluence_markup.lua
-- A Pandoc Atlassian Confluence Markup Writer
--
-- Invoke with: pandoc -to confluence_markup.lua
--
-- Based on pandoc/data/sampsdfsle.lua and zhzhxtrrk's "pandoc confluence markup writer"
-- Fixes tables and lists of lists
local image_index = 0
@dblume
dblume / first_attempt.py
Last active August 29, 2015 14:22
Ways to Break a Dollar into Change
def ways_to_break(amount, coins):
"""
:param amount: the monetary value to break into some number of coins
:param coins: a container of descending coin denominations
:return: the number of different ways to break amount into coins
"""
this_coin = coins[0]
# If this is the only coin, there's one way to break it.
if len(coins) == 1: