Skip to content

Instantly share code, notes, and snippets.

View derrh's full-sized avatar

Derrick Hathaway derrh

View GitHub Profile
@derrh
derrh / .gitattributes
Created November 21, 2012 17:58 — forked from krisalyssa/.gitattributes
.gitignore and .gitattributes for Xcode 4.3
# treats your Xcode project file as a binary; prevents Git from trying to fix newlines, show in diffs, and excludes from merges
*.pbxproj -crlf -diff -merge
@derrh
derrh / boolean_variety.h
Last active December 16, 2015 03:59
Our code is so boring sometimes. This will help.
// boolean_variety.h
//
// Copyright (c) 2013 Derrick Hathaway
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@derrh
derrh / CategoryProperty.h
Created June 25, 2013 20:21
Synthesize + objc_get/setAssociatedObject
#import <objc/runtime.h>
#define SYNTHESIZE(class, getter, setter) \
static const void *getter##PropertyKey = &getter##PropertyKey;\
- (type *)getter { \
return objc_getAssociatedObject(self, getter##PropertyKey); \
} \
\
- (void)setter:(class *object) { \
objc_setAssociatedObject(self, getter##PropertyKey, object, OBJC_ASSOCIATION_RETAIN);\
import UIKit
func +<A,B>(lhs: [A:B], rhs: [A:B]) -> [A:B] {
var dict : [A:B] = [:]
for (key, value) in lhs {
dict[key] = value
}
for (key, value) in rhs {
dict[key] = value
//
// NSManagedObjectContext+Project.swift
//
// Created by Derrick Hathaway on 2/22/15.
// Copyright (c) 2015 The Best Bits LLC.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
Process: carthage [25835]
Path: /usr/local/bin/carthage
Identifier: carthage
Version: 0
Code Type: X86-64 (Native)
Parent Process: bash [21316]
Responsible: Terminal [21310]
User ID: 1745180192
Date/Time: 2015-05-26 10:54:31.718 -0600
@derrh
derrh / PolymorphicValueTypes.swift
Created December 13, 2016 06:06
Polymorphism with Swift Value Types: Mind Blown
protocol Thing {
func foo()
}
extension Thing {
func foo() {
print("just a thing")
}
}
@derrh
derrh / Optional.swift
Created May 2, 2018 23:32
Hello, Silicon Slopes!
func format(date: Date) -> String { ... }
let dueDate = Date?
print("""
Assignment
--
due: \(dueDate.map(format(date:)) ?? "none")
"""
@derrh
derrh / Interview.tsx
Created January 7, 2020 17:07
Device Orientation
import React from 'react';
import { Orientation } from 'react-native-device-orientation';
// Orientation.addSubscriber(callback: (orientation: 'portrait' | 'landscape') => {})
// Orientation.removeSubscriber(callback)
type RouteLeaf = string | number | bigint | boolean | null | undefined
// there's probably a tidier way to get around TS's lack of support for recursive `type`'s
type RouteBranch<SubBranch = RouteLeaf> = Record<string | number | symbol, RouteLeaf | SubBranch>
type RouteComponent =
| RouteLeaf
| RouteBranch<RouteBranch>
| RouteBranch<RouteBranch<RouteBranch>>
| RouteBranch<RouteBranch<RouteBranch<RouteBranch>>>
| RouteBranch<RouteBranch<RouteBranch<RouteBranch<RouteBranch>>>>