Skip to content

Instantly share code, notes, and snippets.

View DivineDominion's full-sized avatar

Christian Tietze DivineDominion

View GitHub Profile
@DivineDominion
DivineDominion / denote-filter-training-tagges-headings.el
Last active June 7, 2024 21:56
Collects all :training: subtrees from denote.el managed .org files from the past 30 days
(defun ct/denote--date-key-regexp (file-type)
(if (equal file-type 'org)
"#\\+date:"
(message "Supports only 'org' at the moment")))
(ct/denote-extract-date-from-front-matter
(defun ct/denote-extract-date-from-front-matter (date-string)
"Returns a decoded time structure.
Format:
(defvar ct/org-created-property-name "CREATED"
"The name of the org-mode property that stores the creation date of the entry")
(defun ct/org-set-created-property (&optional active NAME)
"Set a property on the entry giving the creation time.
By default the property is called CREATED. If given the `NAME'
argument will be used instead. If the property already exists, it
will not be modified."
(interactive)
@DivineDominion
DivineDominion / Combine.Publishers+Either.swift
Last active September 7, 2023 06:06
Combine.Publishers.Either implementation
import Combine
enum Either<Left, Right> {
case left(Left)
case right(Right)
enum Select { case left, right }
}
struct _EitherPublisher<Left, Right, Select, Failure>: Publisher
@DivineDominion
DivineDominion / 0001-add-mastodon-toot-scheduled-at-buffer-local-variable.patch
Last active November 26, 2022 13:08
Patch to offer post scheduling in Mastodon.el
From e17e2ecd417864c725fe5f182a25cf3024251263 Mon Sep 17 00:00:00 2001
From: Christian Tietze <ctietze@noreply.codeberg.org>
Date: Sat, 26 Nov 2022 11:07:24 +0000
Subject: [PATCH] add mastodon-toot--scheduled-at buffer-local variable to
optionally schedule posts
---
lisp/mastodon-toot.el | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
@DivineDominion
DivineDominion / JiggleThread.swift
Created November 4, 2022 08:11
Jiggle thread implementation in Swift
// Based on an idea from page 188 in:
//
// Robert C. Martin (2009):
// "Clean Code. A Handbook of Agile Software Craftsmanship",
// Upper Saddle River: Prentice Hall.
import Foundation
@inline(__always)
func jiggleThread(minimumDelay: TimeInterval = 0.3, maximumDelay: TimeInterval = 4) {

202207041909 AppStorage extension for strongly typed keys

#appstorage #swiftui

The @AppStorage property wrapper for observable access to UserDefaults keys is stringified.

To get a strongly typed key access, I oriented myself on the @Environment(\.keyPath) wrapper and my experience with SwiftyUserDefaults and its subscript-based access.

// Use defaultValue from the key:
@AppStorage(\.showOnboarding) var showOnboarding
@DivineDominion
DivineDominion / magit-context-menu.el
Last active March 8, 2022 07:48
Add "Discard", "Stage", and "Unstage" to right-click menu in Magit buffers
(require 'magit)
(defun magit-current-section-menu-label ()
"Menu item label for section at point."
(pcase (magit-diff-scope)
('hunk "Hunk")
('hunks "Hunks")
('file "File")
('files "Files")
('module "Module")
(defmacro ct/tab-bar-select-action-define (num)
`(defun ,(intern (format "ct/tab-bar-select-%i" num)) ()
,(format "Select tab %i by its absolute number." num)
(interactive)
(tab-bar-select-tab ,num)))
;; Manual calls work
(progn
(ct/tab-bar-select-action-define 1)
(ct/tab-bar-select-action-define 2)
@DivineDominion
DivineDominion / URL+resolvedAgainstBase.swift
Last active January 31, 2022 10:37
Given two file path URLs, determine the shortest relative path to get from one to the other, e.g. `../../folder/file.txt`
// Copyright © 2021 Christian Tietze. All rights reserved. Distributed under the MIT License.
import Foundation
extension URL {
/// Produces a relative path to get from `baseURL` to the receiver for use in e.g. labels.
///
/// When there's no common ancestor, e.g. `/tmp/` and `/var/`, then this returns an absolute path. The only exception to this rule is when `baseURL` itself is the root `/`, since tor that base _all_ paths are relative.
///
/// - Returns: Shortest relative path to get from `baseURL` to receiver, e.g. `"../../subdirectory/file.txt"`, and `"."` if both are identical. Absolute path (or absolute URL for non-`file://` URLs) if there's nothing in common.
@DivineDominion
DivineDominion / kramdown_gfm_wikilink.rb
Created April 22, 2021 10:13
Kramdown GFM Parser extension for [[wikilinks]]