Skip to content

Instantly share code, notes, and snippets.

View frankus's full-sized avatar

Frank Schmitt frankus

  • Bellingham, WA, USA
View GitHub Profile
@frankus
frankus / JSONDecoder+HexData.swift
Created March 7, 2023 16:33
JSONDecoder data decoding strategy for hexadecimal strings
struct MyStruct: Decodable {
let data: Data
static func decodeHexData(_ decoder: Decoder) throws -> Data {
let container = try decoder.singleValueContainer()
let stringValue = try container.decode(String.self)
guard let data = Data(hexString: stringValue) else {
throw MyStructError.invalidHexString(stringValue)
}
@frankus
frankus / gist:f13830ea658bed55ca41
Created August 13, 2015 00:14
Updates Xcode's default file-header comment to correct filename
find . -iname '*.[mh]' -print0 | while IFS= read -r -d '' file; do basename=`basename "$file"`; sed -i .bak "2s|// .*\$|// $basename|" "$file"; done
@frankus
frankus / Top 25 "Best" Wordle Openers
Last active January 19, 2022 00:51
Attempt to find the best starting words in Wordle (maximize chance of getting a green letter)
cares
saree
sores
seres
bares
soree
soras
cores
sires
sared
@frankus
frankus / Pure functions.md
Last active April 29, 2021 16:50
Extracting Pure Functions in Swift Without Polluting the Global Namespace

For testability purposes (and to make things easier to reason about), sometimes it's nice if methods in a class are pure functions, that is, they don't contain any explicit or implicit references to self, or really anything other than the arguments that are passed in.

In the painfully contrived example below, method is a method (because it references both a property and another method using self) and isEven is a pure function (because it doesn't).

class MyClass {
  let number: Int
  
 init(number: Int) {
@frankus
frankus / UIImageView+MapSnapshot.h
Created March 31, 2014 23:28
MKMapSnapshot category on UIImageView
//
// UIImageView+MapSnapshot.h
// Awning
//
// Created by Frank Schmitt on 3/31/14.
//
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@frankus
frankus / gist:7992755
Created December 16, 2013 19:23
Category on UIBarButtonItem for flexible space (add an `autorelease` call for non-ARC code).
@interface UIBarButtonItem (FlexibleSpace)
+ (instancetype)barButtonItemFlexibleSpace;
@end
@implementation UIBarButtonItem (FlexibleSpace)
+ (instancetype)barButtonItemFlexibleSpace {
return [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
@frankus
frankus / gist:5ce28924819a812a2035
Created August 12, 2015 23:16
One-liner to find filenames whose header comments no longer match
find . -iname "*.[mh]" -exec sed -n "2s|^// ||p" "{}" \; -exec basename "{}" \; | uniq -u

Keybase proof

I hereby claim:

  • I am frankus on github.
  • I am frankus (https://keybase.io/frankus) on keybase.
  • I have a public key whose fingerprint is 2A7F B0A5 A84C 5A18 8750 94B6 242B C728 204F BB64

To claim this, I am signing this object:

+ (NSValueTransformer *)URLArrayTransformer {
return [MTLValueTransformer reversibleTransformerWithForwardBlock:^NSArray *(NSArray *URLStrings) {
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[URLStrings count]];
for (NSString *URLString in URLStrings) {
[result addObject:[NSURL URLWithString:URLString]];
}
return result;
} reverseBlock:^NSArray *(NSArray *URLs) {
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[URLs count]];
for (NSURL *URL in URLs) {
//
// ExtendedCollectionView.h
//
// Created by Frank Schmitt on 7/11/14.
//
@interface ExtendedCollectionView : UICollectionView
@property (nonatomic) UIEdgeInsets touchAreaInsets;