Skip to content

Instantly share code, notes, and snippets.

View zats's full-sized avatar

Sash Zats zats

View GitHub Profile
@evandrix
evandrix / pep20_by_example.py
Created March 13, 2012 18:45
PEP 20 (The Zen of Python) by example
#!/usr/bin/env python
"""
=====================================
PEP 20 (The Zen of Python) by example
=====================================
Usage: %prog
:Author: Hunter Blanks, hblanks@artifex.org / hblanks@monetate.com
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active March 10, 2024 19:23
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@steipete
steipete / PSPDFThreadSafeMutableDictionary.m
Created December 2, 2013 09:00
Dictionary subclass whose primitive operations are thread safe. Most of the time you don't want locking at the collection level, but there are valid use cases for this, and it's interesting how to properly subclass the NSDictionary class cluster. We're using SpinLocks here, since it's highly unlikely that any of the operation locks for more than…
@interface PSPDFThreadSafeMutableDictionary : NSMutableDictionary
@end
#import "PSPDFThreadSafeMutableDictionary.h"
#import <libkern/OSAtomic.h>
@implementation PSPDFThreadSafeMutableDictionary {
OSSpinLock _lock;
NSMutableDictionary *_dictionary; // Class Cluster!
@0xc010d
0xc010d / ReCodeSign
Created November 14, 2011 22:38
Codesign an iOS app, with a different distribution certificate and mobileprovisioning file.
- Copy the delivered ipa into a directory to work in.
- export PlistBuddy="/usr/libexec/PlistBuddy" to get the PlistBuddy tool to your shell. If it is not added, all references to PlistBuddy
will need to be written as the full path.
- Take the delivered App.ipa and unzip it using the unzip command. This should produce a Payload directory containing the app and its
resources.
- Enter the command "codesign -d --entitlements :enterprise.plist Payload/PathToApp.app/" This pulls the entitlements out of the app, and
prints them to a plist, without a leading "blob" of data. Pay particular attention to the colon before the enterprise.plist file name.
@chriseidhof
chriseidhof / parsing.swift
Last active April 16, 2023 02:38
JSON Parsing in Swift
// This code accompanies a blog post: http://chris.eidhof.nl/posts/json-parsing-in-swift.html
//
// As of Beta5, the >>= operator is already defined, so I changed it to >>>=
import Foundation
let parsedJSON : [String:AnyObject] = [
"stat": "ok",
"blogs": [
@andymatuschak
andymatuschak / CollectionViewDataSource.swift
Last active February 12, 2021 09:44
Type-safe value-oriented collection view data source
//
// CollectionViewDataSource.swift
// Khan Academy
//
// Created by Andy Matuschak on 10/14/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
@steipete
steipete / CaseInsensitiveDictionary.m
Created December 1, 2013 19:12
Implemented as a category on NSDictionary.
static Boolean PSPDFCaseInsensitiveEqualCallback(const void *a, const void *b) {
id objA = (__bridge id)a, objB = (__bridge id)b;
Boolean ret = FALSE;
if ([objA isKindOfClass:NSString.class] && [objB isKindOfClass:NSString.class]) {
ret = ([objA compare:objB options:NSCaseInsensitiveSearch|NSLiteralSearch] == NSOrderedSame);
}else {
ret = [objA isEqual:objB];
}
return ret;
}
@0xced
0xced / NSData+Base64.h
Created February 24, 2012 15:03
NSData Base64 category
//
// Created by Cédric Luthi on 2012-02-24.
// Copyright (c) 2012 Cédric Luthi. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSData (Base64)
+ (id) dataWithBase64Encoding_xcd:(NSString *)base64String;
@chriseidhof
chriseidhof / TypedExpr.swift
Last active February 3, 2018 23:01
Typed Expressions in Swift
// Variables just contain an integer. We can have a maximum of `Int.max` variables in our program. ¯\_(ツ)_/¯
private struct Var {
static var freshVarIx = 0
let ix: Int
init() {
Var.freshVarIx+=1
ix = Var.freshVarIx
}
}
@steipete
steipete / UITableViewMore.m
Last active January 29, 2018 14:19
Using the "More" button. Of course the simple way that Apple uses in Mail/iOS is not public. rdar://16600859
- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"More";
}
- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"I wanted to be a pretty public API, but then time ran out and they forgot me...");
// Hide the More/Delete menu.
[self setEditing:NO animated:YES];
}