Skip to content

Instantly share code, notes, and snippets.

View nicholascross's full-sized avatar

Nicholas Cross nicholascross

  • nacross web
  • Melbourne
View GitHub Profile
@skeeto
skeeto / avalanche.c
Last active December 2, 2024 10:26
Avalanche matrix graphs for various hash functions
/* Avalanche matrix visualizer
* $ cc -Ofast -fopenmp -Wall -Wextra avalanche.c
* This is free and unencumbered software released into the public domain.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define NSAMPLES (1L << 24)
#define SCALE 24
@manmal
manmal / print_advertisingid_usage.sh
Created September 14, 2020 08:51
Find IDFA usage in 3rd party frameworks
for framework in Frameworks/*.framework; do
fname=$(basename $framework .framework)
echo $fname
otool -v -s __TEXT __objc_methname $framework/$fname | grep advertisingIdentifier
done
@chriseidhof
chriseidhof / boilerplate.swift
Last active April 17, 2025 11:08
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@chwastek
chwastek / xcframework_create.sh
Last active March 15, 2024 13:10
Reusable script for creating an XCFramework from both Xcode and Terminal. You can run this script with framework's name, if needed (e.g. when running from Terminal).
#!/bin/sh
# -------------- config --------------
# Uncomment for debugging
set -x
# Set bash script to exit immediately if any commands fail
set -e
@chriseidhof
chriseidhof / goroutines.swift
Created February 16, 2018 12:36
goroutines.swift
import Foundation
protocol Channel: IteratorProtocol {
func send(_ value: Element?)
}
/// A blocking channel for sending values.
///
/// `send` and `receive` must run in separate separate execution contexts, otherwise you get a deadlock.
final class BlockingChannel<A>: Channel {
@jlnquere
jlnquere / UICollectionViewScroll.swift
Last active June 10, 2022 14:25
XCUITests: scroll UICollectionView to find one of it's offscreen UICollectionViewCell by id
// Thanks to @MonsieurDart for the idea :)
func scroll(collectionView:XCUIElement, toFindCellWithId identifier:String) -> XCUIElement? {
guard collectionView.elementType == .collectionView else {
fatalError("XCUIElement is not a collectionView.")
}
var reachedTheEnd = false
var allVisibleElements = [String]()
while !reachedTheEnd {
@0xmachos
0xmachos / Keychain.md
Last active March 2, 2025 15:18
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
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"
@werediver
werediver / BasicServiceLocator.swift
Last active January 14, 2019 06:13
Basic Service Locator pattern implementation in Swift 2.
protocol ServiceLocator {
func getService<T>() -> T?
}
final class BasicServiceLocator: ServiceLocator {
// Service registry
private lazy var reg: Dictionary<String, Any> = [:]
private func typeName(some: Any) -> String {
@akisute
akisute / Sample.m
Created January 15, 2015 10:54
How to use RACObserve in Swift
// Objective-C
@interface Document: NSObject
@property (nonatomic, copy) NSArray *notes;
@property (nonatomic, readonly) RACSignal *notesUpdatedSignal;
@end
@implementation Document
- (RACSignal *)notesUpdatedSignal
{
// In Objective-C, just simply use RACObserve