Skip to content

Instantly share code, notes, and snippets.

import Foundation
func machToNanoseconds(_ mach: UInt64) -> Double {
struct Static {
static var info: mach_timebase_info = {
var info = mach_timebase_info()
mach_timebase_info(&info)
return info
}()
}
protocol P {
func f()
}
struct S<T> {}
extension S: P where T: P {
func f() {
print(T.self)
import Cocoa
var count: UInt32 = 0
let ptr = objc_copyClassList(&count)!
let strings = (0 ..< Int(count)).flatMap({
if class_getSuperclass(ptr[$0]) == nil {
return String(cString: class_getName(ptr[$0]))
} else {
protocol TSDKey {
associatedtype Value
static var defaultValue: Value { get }
}
struct TSD {
private var storage: [ObjectIdentifier: Any] = [:]
subscript<Key: TSDKey>(key: Key.Type) -> Key.Value {
// SCROLL DOWN //
import Foundation
protocol TSUD {
associatedtype Value: Codable
init()
static var defaultValue: Value { get }
import Foundation
class MutableBox<T> {
var value: T
init(_ initialValue: T) {
value = initialValue
}
}
/*usr/bin/true
clang -framework Cocoa -g compile-time-class.m && ./a.out
exit;*/
#import <Foundation/Foundation.h>
#define COMPILE_TIME_CLASS(name) ^{ \
extern void *OBJC_CLASS_$_ ## name; \
@mikeash
mikeash / xcode.sh
Created September 15, 2017 17:07
Convince Xcode 9 not to smooth its source code font
#!/bin/bash
# Exit the script immediately on error
set -e
# We'll work in /tmp
cd /tmp
# Clone mach_override unless we already have it
if [ ! -d mach_override ]; then
@mikeash
mikeash / test.c
Created July 2, 2017 02:16
ARM64 normal and variadic calling conventions
// xcrun -sdk iphoneos clang -O3 -arch arm64 -S test.c
#import <stdarg.h>
#import <stdio.h>
void normal(int a, int b, int c, int d, int e, int f, int g, int h) {
printf("%d %d %d %d %d %d %d %d", a, b, c, d, e, f, g, h);
}
void normal_target(int a, int b, int c, int d, int e, int f, int g, int h);
import Darwin
typealias a = (UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, U