Skip to content

Instantly share code, notes, and snippets.

View DivineDominion's full-sized avatar

Christian Tietze DivineDominion

View GitHub Profile
(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)

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 / 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 / markdownTemplate.txt
Last active June 4, 2023 06:56
BibDesk MultiMarkdown export template. Put into `~/Library/Application Support/BibDesk/Templates` and activate in settings to use.--- From http://zettelkasten.de/bibliography-zettelkasten/
<$publications>
[#<$citeKey/>]: <$authors.name?>
<$authors.name.stringByRemovingTeX.@componentsJoinedByCommaAndAnd/><?$authors.name?><$editors.name.stringByRemovingTeX.@componentsJoinedByCommaAndAnd/> (Hrsg.)
</$authors.name?>
<$fields.Year?> (<$fields.Year/>)</$fields.Year?>: _<$fields.Title.stringByRemovingTeX/><$fields.Subtitle?>. <$fields.Subtitle.stringByRemovingTeX/></$fields.Subtitle?>_<$pubType=article?>
, <$fields.Journal/><$fields.Number?> <$fields.Number/></$fields.Number?>, <$fields.Year/>, Vol. <$fields.Volume/>, S. <$fields.Pages/><?$pubType=incollection?>
, in: <$fields.Booktitle/><$fields.Address?>, <$fields.Address/>: <$fields.Publisher?><$fields.Publisher/></$fields.Publisher?><?$fields.Address?>
<$fields.Publisher?>, <$fields.Publisher/></$fields.Publisher?>
</$fields.Address?>
<?$pubType?>
@DivineDominion
DivineDominion / kramdown_gfm_wikilink.rb
Created April 22, 2021 10:13
Kramdown GFM Parser extension for [[wikilinks]]
@DivineDominion
DivineDominion / FolderContentMonitor.swift
Last active March 10, 2023 15:50
Wrapper for using C FSEvents with Swift 4
//
// Based on: https://blog.beecomedigital.com/2015/06/27/developing-a-filesystemwatcher-for-os-x-by-using-fsevents-with-swift-2/
//
import Foundation
public struct Event: CustomStringConvertible {
public let eventId: FSEventStreamEventId
public let eventPath: String
@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) {
@DivineDominion
DivineDominion / convert_dayone_to_org.rb
Last active August 16, 2022 00:22
Convert Day One (macOS) Journal.txt to Emacs org-mode diary/journal — https://christiantietze.de/posts/2020/10/export-day-one-journal-to-org-mode/
#!/usr/bin/env ruby
#
# convert_dayone_to_org.rb
# Copyright © 2020 Christian Tietze. All rights reserved. Distributed under the MIT License.
#
# Converts a Day One plain text export (Journal.txt) into org-mode journal format. It does
# - Markdown image conversion from ![](thepath.jpg) to [[thepath.jpg]]
# - Extraction of images from the front of an entry; moves it right after the property drawer.
# - Creation of nested year/month/day date sections (see example below)
#
@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")