This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# 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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State var now = Date() | |
@State var showWindow = false | |
@State var text: String = "" | |
let timer = Timer.publish(every: 1, on: .current, in: .common).autoconnect() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension Decodable { | |
public static func randomInstance() throws -> Self { | |
let decoder = RandomDecoder() | |
return try Self(from: decoder) | |
} | |
} | |
private class RandomDecoder: Decoder { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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} | |
OptionParser.new do |parser| | |
parser.banner = "Usage: #{$0} [options] path/to/libMultiMarkdown.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum JSONValue: Codable, Equatable { | |
struct JSONValueDecodingError: Error { | |
let message: String | |
} | |
case boolean(Bool) | |
case number(Double) | |
case string(String) | |
case array([JSONValue?]) | |
case object([String: JSONValue?]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/45777692/5536516 | |
import Foundation | |
struct MemoryAddress<T>: CustomStringConvertible { | |
let intValue: Int | |
var description: String { | |
let length = 2 + 2 * MemoryLayout<UnsafeRawPointer>.size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |