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
#!/bin/sh | |
# For Ubiquiti EdgeOS | |
# | |
# This script creates a directory /config/scripts/post-commit.d. Any script you put | |
# in that directory will get run every time you commit a new configuration. | |
# | |
# Installation: | |
# - Put this script in /config/scripts/post-config.d. Note that this is a different | |
# directory from the directory this creates. |
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
#!/bin/sh | |
set -e | |
# NOTE: This is no longer necessary! When the IPv6 rollout started, the issue went away. | |
# I'm just keeping the script here for posterity. | |
# Verizon Fios's router on the other end of the ONT (one hop upstream of this router) responds to | |
# any ICMP echo request with an ICMP echo reply, no matter who the intended host is. This breaks | |
# any traceroute that uses ICMP, including mtr, making it look like the destination host is one |
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 Cocoa | |
struct EmptyContainer<T> { | |
} | |
typealias IntContainer = EmptyContainer<Int> | |
extension IntContainer: Sequence { | |
struct Iterator: IteratorProtocol { | |
func next() -> Int? { |
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
// 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 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
package main | |
import ( | |
"bufio" | |
"bytes" | |
"io" | |
"strings" | |
"golang.org/x/term" | |
) |
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
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 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 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 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
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 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
// 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 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 <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]]; |