This file contains 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
// Lightly modified from the slides for "Rethinking Classical Concurrency Patterns" | |
package sync | |
import "context" | |
type state struct { | |
seq int64 | |
changed chan struct{} // closed upon notify | |
} |
This file contains 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
package main | |
import ( | |
"bufio" | |
"bytes" | |
"io" | |
"strings" | |
"golang.org/x/term" | |
) |
This file contains 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
func commonPrefixLen(a, b string) int { | |
i := 0 | |
for ; i < len(a) && i < len(b); i++ { | |
if a[i] != b[i] { | |
break | |
} | |
} | |
return i | |
} |
This file contains 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 ContentView: View { | |
@State var atTop = true | |
@Namespace var ns | |
var body: some View { | |
VStack { | |
VStack { | |
Text("Top") | |
.border(.green) | |
.opacity(atTop ? 1 : 0) |
This file contains 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
class NormalView: NSView { | |
override func draw(_ dirtyRect: NSRect) { | |
print("NormalView", NSGraphicsContext.current!.cgContext.ctm) | |
} | |
} | |
struct NormalViewRepresentable: NSViewRepresentable { | |
func makeNSView(context: Context) -> NormalView { | |
NormalView() | |
} |
This file contains 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
// Three implementations of a type-erased Equatable | |
struct AnyEquatable: Equatable { | |
class BoxBase { | |
func isEqual(_ other: BoxBase) -> Bool { | |
fatalError("not implemented") | |
} | |
} | |
class Box<E: Equatable>: BoxBase { |
This file contains 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 <Cocoa/Cocoa.h> | |
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h> | |
@implementation NSData (NSArrayConversion) | |
- (NSArray<NSNumber*>*)byteArray { | |
NSMutableArray<NSNumber*> *a = [NSMutableArray arrayWithCapacity:[self length]]; | |
const unsigned char *bytes = [self bytes]; | |
for (int i = 0; i < [self length]; i++) { | |
a[i] = [[NSNumber alloc] initWithUnsignedChar:bytes[i]]; |
This file contains 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
// | |
// ContentView.swift | |
// FastNote | |
// | |
// Created by David Albert on 6/9/21. | |
// | |
import SwiftUI | |
struct Note: Identifiable { |
This file contains 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
# Run this once in your shell. All access keys and all settings will be saved by acme.sh | |
DOMAIN=unifi.example.com | |
AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=bar acme.sh \ | |
--issue -d $DOMAIN \ | |
--dns dns_aws \ | |
--fullchain-file /tmp/$DOMAIN.crt \ | |
--key-file /tmp/$DOMAIN.key \ | |
--reloadcmd /path/to/unifi-import-certificate.sh |
This file contains 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
// miniKanren.swift, written by David Albert, and released into the public domain. | |
// | |
// An implementation of the miniKanren relational programming language. Somewhat | |
// reductively, relational programs can be run both forwards and backwards. In | |
// addition to asking "what does this function return when passed these arguments," | |
// you can also ask "what arguments to this function return the following value?" | |
// This lets you ask questions like like "what pairs of numbers sum to 12," which | |
// if you allow for negative numbers has an infinite number of solutions. | |
// | |
// Some mind bending miniKanren programs that others have written include: a |