Skip to content

Instantly share code, notes, and snippets.

@zadr
zadr / steps.txt
Last active January 2, 2024 12:45
MacPorts install without root privileges
# fetch MacPorts sources
curl -LO https://distfiles.macports.org/MacPorts/MacPorts-2.8.1.tar.gz
# extract them and get into the dir
tar -jxf MacPorts-2.8.1.tar.gz
cd MacPorts-2.8.1
# configure things
## If you want MacPorts to run in a custom prefix, pass in the following arguments: --prefix=/usr/local --with-unsupported-prefix --with-applications-dir=/Applications
## replacing /usr/local with your desired location
import UIKit
extension UIBezierPath {
// reference: https://github.com/erica/iOS-6-Cookbook/blob/master/C01%20Gestures/08%20-%20Smoothed%20Drawing/UIBezierPath-Points.m
var points: [CGPoint] {
var bezierPoints = [CGPoint]()
cgPath.applyWithBlock { (element: UnsafePointer<CGPathElement>) in
if element.pointee.type != .closeSubpath {
bezierPoints.append(element.pointee.points.pointee)
@zadr
zadr / Demo.m
Last active May 26, 2023 08:30
Dynamic User Defaults
@interface NSUserDefaults (idk)
@property (nonatomic, copy) NSString *jam;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[NSUserDefaults standardUserDefaults].jam = @"strawberry";
NSLog(@"%@", [NSUserDefaults standardUserDefaults].jam);
}
@end
// license: i dunno. pick one that works for you. Apache 2.0? that seems reasonable. Let me know if it doesn't work for some reason.
import Foundation
import Compression // https://developer.apple.com/library/mac/documentation/Performance/Reference/Compression/
public enum Compression {
public enum Algorithm {
case LZFSE
case LZ4
case LZMA
@zadr
zadr / CV.m
Created March 8, 2017 19:08
UIImage from CMSampleBuffer
#import <CoreMedia/CoreMedia.h>
#import <CoreVideo/CoreVideo.h>
#import <UIKit/UIKit.h>
// https://developer.apple.com/library/content/qa/qa1702/_index.html
+ (UIImage * _Nullable)imageWithSampleBuffer:(CMSampleBufferRef _Nonnull)sampleBuffer {
UIImage *returnValue = nil;
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer, 0); {
@zadr
zadr / framework-diff.sh
Last active June 22, 2020 23:39
objc framework diffing for all .frameworks in xcode
set -x
set -k INTERACTIVE_COMMENTS=1 # treats everything after # as being a comment
# vars
export XCODE_RELEASE_PATH="/Applications/Xcode-11.5.app"
export XCODE_BETA_PATH="/Applications/Xcode-12-beta.app"
export XCODE_FRAMEWORKS_PATH="Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks"
export OUTPUT="${HOME}/Desktop/iosapidiff"
mkdir "${OUTPUT}"
@zadr
zadr / tttt.swift
Last active February 9, 2020 01:16
terminal's tiny todo tool
// 1. copy file to $PATH somewhere
// 2. chmod a+x it
// 3. run with `tttt` or `tttt [task to track]`
// 4. check out ~/Desktop/todo.txt
#!/usr/bin/env swift
import Foundation
let dateFormatter = DateFormatter()
@zadr
zadr / ??.swift
Last active April 26, 2017 21:36
Ternary-ish operators without an else clause
infix operator ?? : Branching
precedencegroup Branching {
associativity: left
lowerThan: ComparisonPrecedence // also accounts for NilCoalescingPrecedence
}
/// Ternary-y operators without an else clause
///
/// - Parameter lhs: The Boolean value to evaluate
@zadr
zadr / command.sh
Last active September 26, 2016 17:37
find the parent of merge commits to have manual branch-aware bisecting
git log master..HEAD --merges --format="%h" | tr '\n' '\0' | xargs -0 -n1 git rev-list --parents -n 1 | awk '{print $(NF)}' | tr '\n' '\0' | xargs -0 -n1 git log --pretty=oneline -n 1
@zadr
zadr / oops.m
Last active February 11, 2016 05:23
- (void) performMagic:(Incantation) incantation interruptingCurrentSpell:(BOOL) immediately {
switch ((int)immediately) {
case NO:
[self _magic:incantation];
break;
default:
dispatch_async(wand_queue, ^{ [self _magic:incantation]; });
}
}