Skip to content

Instantly share code, notes, and snippets.

module Jekyll
class PageVariationsGenerator < Generator
safe true
def generate(site)
pagesCopy = site.pages.dup
site.config['pagevariations'].each_entry do |variation|
pagesCopy.each_entry do |page|
pageCopy = page.dup
oldPermalink = pageCopy.data['permalink']
@uliwitness
uliwitness / retroactiveProtocols.swift
Last active August 5, 2019 14:21
You can make an existing type conform to a protocol you define later in Swift.
class OriginalClass {
var fooProp: Int = 15
func sayHello(_ string: String) {
print("Hello \(string) \(fooProp)")
}
}
protocol MockProtocol {
var fooProp: Int { get }
class Observer: Subscription {
public func unsubscribe() {
...
}
public func request(_ demand: Subscribers.Demand) {
// We only inform on changes.
print("Demand for \(demand) received.")
}
@uliwitness
uliwitness / main.swift
Last active December 10, 2019 19:52
Command line argument parsing function
import Foundation
extension Array where Array.Element == String {
func parseKeyValue(prefix: String = "--", suffix: String = "", valueSeparator: String = "=", removePrefix: Bool = true, removeSuffix: Bool = true, separateArguments: Bool = true, endIndicator: String = "--") -> Dictionary<String, String> {
var unlabeled = [String]()
return parseKeyValue(prefix: prefix, suffix: suffix, valueSeparator: valueSeparator, removePrefix: removePrefix, removeSuffix: removeSuffix, separateArguments: separateArguments, endIndicator: endIndicator, unlabeled: &unlabeled)
}
func parseKeyValue(prefix: String = "--", suffix: String = "", valueSeparator: String = "=", removePrefix: Bool = true, removeSuffix: Bool = true, separateArguments: Bool = true, endIndicator: String = "--", unlabeled: inout [String]) -> Dictionary<String, String> {
var result = Dictionary<String, String>()
@uliwitness
uliwitness / NSEvent.m.dump
Last active August 3, 2022 00:27
68000 Disassembly of a Classic MacOS Objective-C file
Names:
1: __func__
2: __FUNCTION__
3: __PRETTY_FUNCTION__
4: @509
5: L_OBJC_SELECTOR_REFERENCES_0
6: @512
7: L_OBJC_SELECTOR_REFERENCES_1
8: -[NSEvent initWithMacEvent:window:]