Skip to content

Instantly share code, notes, and snippets.

View voncannon's full-sized avatar
💪
If you ain't breakin, you ain't buildin

Bryan VonCannon voncannon

💪
If you ain't breakin, you ain't buildin
View GitHub Profile
//
// NSString+Levenshtein.h
// PyHelp
//
// Modified by Michael Bianco on 12/2/11.
// <http://mabblog.com>
//
// Created by Rick Bourner on Sat Aug 09 2003.
// rick@bourner.com
@steipete
steipete / UIKitLegacyDetector.m
Last active March 12, 2024 13:57
A simple way to detect at runtime if we're running in UIKit legacy mode or the new "flat" variant. Written for our PDF iOS SDK (http://pspdfkit.com), where the precompiled binary needs to detect at runtime in what variant it's running. Want more stuff like that? Follow me on Twitter: http://twitter.com/steipete
// Taken from http://PSPDFKit.com. This snippet is under public domain.
#define UIKitVersionNumber_iOS_7_0 0xB57
BOOL PSPDFIsUIKitFlatMode(void) {
static BOOL isUIKitFlatMode = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// We get the modern UIKit if system is running >= iOS 7 and we were linked with >= SDK 7.
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) {
isUIKitFlatMode = (NSVersionOfLinkTimeLibrary("UIKit") >> 16) >= UIKitVersionNumber_iOS_7_0;
}
@steipete
steipete / FirstResponder.m
Created January 31, 2014 17:21
Getting the first responder... Unless you want to use the private [view firstResponder] this seems to be the only legal way. Or am I wrong?
UIView *PSPDFFindFirstResponderBeneathView(UIView *view) {
// Stop if e.g. we show an UIAlertView with a text field.
if (UIApplication.sharedApplication.keyWindow != view.window) return nil;
// Search recursively for first responder.
for (UIView *childView in view.subviews) {
if ([childView respondsToSelector:@selector(isFirstResponder)] && childView.isFirstResponder) return childView;
UIView *result = PSPDFFindFirstResponderBeneathView(childView);
if (result) return result;
}
@steipete
steipete / PSPDFEnvironment.m
Last active March 5, 2024 09:15
Example for DISPATCH_SOURCE_TYPE_MEMORYPRESSURE (Mac only, since 10.9) ... Since we share code between iOS and mac, I'm trying to be a good system citizen and reimplement the equivalent of UIApplicationDidReceiveMemoryWarningNotification on the Mac.
NSString *const PSPDFApplicationDidReceiveMemoryWarningNotification = @"PSPDFApplicationDidReceiveMemoryWarningNotification";
// Test with sudo memory_pressure -l critical. Don't forget to re-set afterwards!
__attribute__((constructor)) static void PSPDFInstallLowMemoryNotificationWarningMac(void) {
static dispatch_source_t source;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_WARN|DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue());
dispatch_source_set_event_handler(source, ^{
dispatch_source_memorypressure_flags_t pressureLevel = dispatch_source_get_data(source);
@voncannon
voncannon / AsyncOperation.swift
Last active March 14, 2024 19:36
Swift Async Operation
//
// AsyncOperation.swift
// TopoLock
//
// Created by VonCannon Tech, Inc. on 8/13/23.
//
import Foundation
//Originally taken fromm: https://gist.github.com/Sorix/57bc3295dc001434fe08acbb053ed2bc
@JesseCrocker
JesseCrocker / merge-pmtiles.py
Created March 29, 2024 13:19
Merge a directory of PMTiles files into a single file
#!/usr/bin/env python3
import argparse
import os
from pmtiles.reader import MmapSource, Reader, all_tiles
from pmtiles.writer import Writer
from pmtiles.tile import Compression
from pmtiles.tile import zxy_to_tileid
from tqdm import tqdm
def merge_pmtiles(input_dir: str, output_file: str) -> None: