Skip to content

Instantly share code, notes, and snippets.

Avatar

Derrick Hathaway derrh

View GitHub Profile
View LearningTemplateLiteralTypes.ts
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>>>>
@derrh
derrh / Interview.tsx
Created Jan 7, 2020
Device Orientation
View Interview.tsx
import React from 'react';
import { Orientation } from 'react-native-device-orientation';
// Orientation.addSubscriber(callback: (orientation: 'portrait' | 'landscape') => {})
// Orientation.removeSubscriber(callback)
@derrh
derrh / Optional.swift
Created May 2, 2018
Hello, Silicon Slopes!
View Optional.swift
func format(date: Date) -> String { ... }
let dueDate = Date?
print("""
Assignment
--
due: \(dueDate.map(format(date:)) ?? "none")
"""
@derrh
derrh / PolymorphicValueTypes.swift
Created Dec 13, 2016
Polymorphism with Swift Value Types: Mind Blown
View PolymorphicValueTypes.swift
protocol Thing {
func foo()
}
extension Thing {
func foo() {
print("just a thing")
}
}
View carthage_2015-05-26-105433_derrick-laptop.crash
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
View NSManagedObjectContext+Project.swift
//
// 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,
View gist:9913ba7fb1358d1cf963
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
@derrh
derrh / CategoryProperty.h
Created Jun 25, 2013
Synthesize + objc_get/setAssociatedObject
View CategoryProperty.h
#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);\
@derrh
derrh / boolean_variety.h
Last active Dec 16, 2015
Our code is so boring sometimes. This will help.
View boolean_variety.h
// 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 / .gitattributes
Created Nov 21, 2012 — forked from CraigCottingham/.gitattributes
.gitignore and .gitattributes for Xcode 4.3
View .gitattributes
# 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