Skip to content

Instantly share code, notes, and snippets.

View DivineDominion's full-sized avatar

Christian Tietze DivineDominion

View GitHub Profile
(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 / com.brettterpstra.gitlogger.plist
Last active December 26, 2021 17:59 — forked from ttscoff/gitlogger.rb
Logs selected git repository commits to a text file or Day One for the past day once in the morning.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.brettterpstra.gitlogger</string>
<key>EnvironmentVariables</key>
<dict>
<key>LANG</key>
<string>en_US.UTF-8</string>
@DivineDominion
DivineDominion / nvALT Zettel Headel.scpt
Created September 11, 2014 08:52
AppleScript to rename notes in nvALT with the Zettel ID and a title of your choosing. Also inserts the information as a header into the note.
-- Extend "current date"
script FormattedDate
property parent : current date
on twoDigitDisplay(aNumber)
set multiplier to 10 ^ 2 #howManyDigits
return "" & (text 2 thru 3 of ((multiplier + aNumber) as string))
end twoDigitDisplay
end script
@DivineDominion
DivineDominion / installation_instructions.md
Last active August 12, 2021 17:27
nvALT Preview Template featuring relative paths

Run this from your terminal to execute the setup script. It creates the directory and downloads the template right into this new folder.

curl -s https://gist.githubusercontent.com/DivineDominion/ab1abe8d2b93d4b73d69/raw/6a7066f1fbcf45e3c47a8d85acee475dd33bd32c/install.sh | bash 

Aferwards, you can change the base directory in ~/Library/Application\ Support/nvALT/template.html as expected.

@DivineDominion
DivineDominion / Example.swift
Last active July 5, 2021 10:22
Extension to @IanKeen's Partial<T> for more sexy and very verbose validations
// - MARK: Example Code
/// A model
struct User {
let firstName: String
let lastName: String
let age: Int?
}
/// Initializer using a Partial<T> -- You could generate this with Sourcery
@DivineDominion
DivineDominion / html-entity-insert.el
Last active July 30, 2020 09:14
Emacs lisp function to select a HTML entity from a filterable list and insert it at point. Based on Based on code by @emacs_gifs from https://emacsgifs.github.io/html-entities-helper
;; Licensed under GNU/GPL. https://emacsgifs.github.io/html-entities-helper
(defun ct/html-entity-insert ()
"Select and insert an html entity.
Uses the list from https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references."
(interactive)
(defvar _html-entity-list
'("char: \" entity: &quot; text: quotation mark (APL quote)"
"char: & entity: &amp; text: ampersand"
"char: ' entity: &apos; text: apostrophe (apostrophe-quote); see below"
"char: < entity: &lt; text: less-than sign"

About the gradual processing of thoughts while talking

If you want to know something and cannot find it through meditation, I advise you, my dear, meaningful friend, to talk about it with your nearest acquaintance, who will be upsetting you. It does not have to be a sharp-thinking head, nor do I mean it as if you should ask him about it: no! Rather, you should tell him yourself first of all. I see your eyes wide open, and you answer me that in your early years you were advised to speak of nothing but things you already understand. Others, I want you to speak out of a reasonable intention to instruct you, and so, in different cases, both rules of wisdom may well coexist. The Frenchman says, l'appétit vient en mangeant, and this principle of experience remains true if you parody it, and says, l'idee vient en parlant.

I often sit at my business table above the files and, in a complicated dispute, I explore the point of view from which it would like to be judged. I usually look into the light, as the brightest

@DivineDominion
DivineDominion / find_zettel_orphans.rb
Last active May 2, 2020 07:47
In a directory of Zettel notes, find all those without incoming links
#!/usr/bin/env ruby
require 'set'
# Change the path here:
ARCHIVE = '~/Archive/'
EXTENSIONS = %w{.md .txt .markdown .mdown .text}
#################################################################
@DivineDominion
DivineDominion / random_file.rb
Last active April 4, 2020 08:38
Find a random plain text file in a directory
#!/usr/bin/env ruby
# Usage: random_file.rb [options]
# -d, --dir [VALUE] Path to the note archive. Default: the current working directory.
# -c, --count [VALUE] Amount of unique random notes to fetch
# -h, --help Prints this help
require "optparse"
CURRENT_PATH = Dir.pwd