Skip to content

Instantly share code, notes, and snippets.

Christian Tietze DivineDominion

View GitHub Profile
JohnAtl / insert_filename_as_header.rb
Created Feb 7, 2020
Code to help with note-link-janitor
View insert_filename_as_header.rb
# Inserts the file's name as the first header in the file, if it isn't already there.
# Assumes filename begins with a 14 digit zettelkasten ID.
# Original file saved as filename.bak.
# As always, caveat emptor. This code could harm your files, so try it on a backup.
Dir.glob('*.md') do |filename|
puts "working on: #{filename}"
DivineDominion / execute.rb
Last active Oct 29, 2019
Extract note links from a source note
View execute.rb
#!/usr/bin/env ruby
# Avoid all the script configuration and use this convenience script instead!
# 1) Put it into the same folder,
# 2) run the script: `ruby _execute.rb PATH/TO/THE_NOTE.txt`
# Configure here #
View test-descriptions-for-fizz-buzz.js
// I have some testing framework in the scope
// Questions below:
// 1. Should the description be like it is here, in first `it`, or with `only` word added:
// "should return Fizz when the number is divisible only by 3"
// That would imply that the number is divisible by 3 only, which is technically not true, as it is divisible
// by 1 as well, and some numbers, e.g. 6, 9, and so on, are divisible by themselves.
it('should return Fizz when the number is divisible by 3', () => {
// 2. Is that name enough, having `any` in it, to be complete in what numbers are producing `fizz`.
// There is also a matter of adding `only` (similar to case #1) having `anyNumberDivisibleOnlyBy3`.
IanKeen / Decodable+Random.swift
Last active Oct 21, 2019
Custom Decoder that can be used to create Decodable instances that are populated with random values
View Decodable+Random.swift
import Foundation
extension Decodable {
public static func randomInstance() throws -> Self {
let decoder = RandomDecoder()
return try Self(from: decoder)
private class RandomDecoder: Decoder {
DivineDominion / cocoaconv.rb
Last active Sep 28, 2018
Convert libMultiMarkdown enums to Swift-bridgeable NS_ENUMs. Pass the path to libMultiMarkdown.h to the script when running.
View cocoaconv.rb
#!/usr/bin/env ruby
require 'optparse'
CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
FALLBACK_PATH = File.join(CURRENT_PATH, "..", "build-xcode", "Debug", "include", "libMultiMarkdown", "libMultiMarkdown.h")
options = {:mode => :nsenum} do |parser|
parser.banner = "Usage: #{$0} [options] path/to/libMultiMarkdown.h"
AliSoftware / SwiftCopying.swift
Last active Aug 24, 2017
TypeSafe copy()/mutableCopy() (NSCopying/NSMutableCopying) in Swift
View SwiftCopying.swift
import Foundation
//: Swift type-safe protocol versions of (Mutable)Copying
protocol SwiftCopying {
associatedtype NonMutableType = Self
func clone() -> NonMutableType
extension SwiftCopying where Self: NSCopying {
func clone() -> NonMutableType {
return self.copy() as! NonMutableType
sjoerdvisscher / minimal.swift
Created Jun 28, 2017
Using Decodable to generate a minimal value
View minimal.swift
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)
mminer / MyService.swift
Last active May 23, 2020
Components of XPC service.
View MyService.swift
import Foundation
class MyService: NSObject, MyServiceProtocol {
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void) {
let response = string.uppercased()
candostdagdeviren / pre-commit
Last active Jun 19, 2020
Git Pre-Commit hook with SwiftLInt
View pre-commit
#Path to swiftlint
#if $SWIFT_LINT >/dev/null 2>&1; then
if [[ -e "${SWIFT_LINT}" ]]; then
for file_path in $(git ls-files -m --exclude-from=.gitignore | grep ".swift$"); do
export SCRIPT_INPUT_FILE_$count=$file_path
darrensapalo / rxswift3networkcalltoobject
Last active Jul 8, 2019
Swift 3 example of a network request wrapped as an RxSwift Observable and converted into a class object
View rxswift3networkcalltoobject
import Foundation
import RxSwift
let networkQueue = DispatchQueue(label: "com.appName.networkQueue")
class Queue {
var name: String
public init (_ name: String) { = name
You can’t perform that action at this time.