Skip to content

Instantly share code, notes, and snippets.

View nicholascross's full-sized avatar

Nicholas Cross nicholascross

  • nacross web
  • Melbourne
View GitHub Profile
@nicholascross
nicholascross / git_path_stats.zsh
Created March 24, 2024 02:03
Generate some historical statistics for file paths in a git repository
!/bin/zsh
git_path_dates() {
if [ -z "$1" ]; then
echo "Usage: git_path_dates <path>"
return 1
fi
filepath="$1"
first_commit_date=$(git log --reverse --format="%cd" --date=format:"%Y-%m-%d" -- "$filepath" | head -n 1)
@nicholascross
nicholascross / ArrayBuilder.swift
Created June 16, 2021 22:35
Generic array builder using swift 5.4 result builder
@resultBuilder
enum ArrayBuilder<OutputModel> {
static func buildEither(first component: [OutputModel]) -> [OutputModel] {
return component
}
static func buildEither(second component: [OutputModel]) -> [OutputModel] {
return component
}
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@nicholascross
nicholascross / Keychain.md
Created June 21, 2019 04:14 — forked from 0xmachos/Keychain.md
Useful resources for working with iOS/ macOS Keychain API

Keychain API

kSecAttrAccessible Mapping

Protection Domain (pdmn) Keychain Accessibility Values
ck kSecAttrAccessibleAfterFirstUnlock
cku kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
dk kSecAttrAccessibleAlways
akpu kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly
@nicholascross
nicholascross / WeakBox.swift
Last active April 2, 2024 13:42
Swift dictionary with weak references simple example
struct WeakBox<ItemType: AnyObject> {
weak var item: ItemType?
init(item: ItemType?) {
self.item = item
}
}
@nicholascross
nicholascross / UIColorManipulation.swift
Last active March 23, 2020 17:40
Swift UIColor manipulation
//Combine colors: add, subtract, multiply components, set and adjust color components
import UIKit
func + (left: UIColor, right: UIColor) -> UIColor {
var leftRGBA = [CGFloat](repeating: 0.0, count: 4)
var rightRGBA = [CGFloat](repeating: 0.0, count: 4)
left.getRed(&leftRGBA[0], green: &leftRGBA[1], blue: &leftRGBA[2], alpha: &leftRGBA[3])
right.getRed(&rightRGBA[0], green: &rightRGBA[1], blue: &rightRGBA[2], alpha: &rightRGBA[3])
//
// CoalesceOperation.swift
// RequestCoalesce
//
// Created by Nicholas Cross on 4/12/2016.
// Copyright © 2016 Nicholas Cross. All rights reserved.
//
import Foundation
@nicholascross
nicholascross / BMGlyphFont+MMCache.h
Created December 12, 2013 09:36
Cache BMGlyphFont instead of recreating it everytime
#import <Foundation/Foundation.h>
#import <BMGlyphLabel/BMGlyphFont.h>
@interface BMGlyphFont (MMCache)
+ (BMGlyphFont *) cachedFontWithName:(NSString *)name;
@end