Skip to content

Instantly share code, notes, and snippets.


Martin Kiss Tricertops

View GitHub Profile
Tricertops / CFBinaryHeap.m
Created Feb 14, 2018
Implementation of NSFastEnumeration on top of CFBinaryHeap. The only way to get objects from CFBinaryHeap is to use allocated object buffer, but NSFastEnumeration doesn’t provide a way to free() it explicitly. I used autoreleased NSMutableData to manage the buffer and it somehow works.
View CFBinaryHeap.m
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])providedBuffer count:(NSUInteger)providedLength {
// If this is not first invocation, finish by returning 0.
if (state->state != 0) {
return 0;
let count = CFBinaryHeapGetCount(self->_underlayingHeap);
// We are empty.
if (count == 0) {
return 0;
Tricertops / main.m
Created Dec 18, 2017
NSKeyedUnarchiver cannot decode class clusters
View main.m
#import <Foundation/Foundation.h>
@interface Node : NSObject <NSCoding>
@property NSString *name;
@property NSMutableArray<Node *> *targets;
Tricertops / NSLiterals.m
Created May 24, 2017
Macros for creating NSArray and NSSet objects as replacement for @[…] literal.
View NSLiterals.m
// Macros for creating NSArray and NSSet objects as replacement for @[…] literal.
let components = NSArray(street, city, state, country);
// Advantages:
// 1. Type of NSArray is inferred, in this case it’s NSArray<NSString *> *
// 2. List of objects is type-checked, so mixing types like NSArray(@42, @"Hi") will report compilation error.
// 3. Ability to allocate any class, not just NSArray. For example NSSet and NSMutableArray.
// 4. Avoids stupid clang bracket matching bug, if you know what I mean.
Tricertops /
Created May 12, 2017
Appeal to the App Review Board

I ask for repeated approval of version 4.6.1, since it was rejected for features that were previously approved in 4.6.

Version 4.6 added feature that changes app icon based on user’s location. I wrote explanation of this feature in Review Notes and this version was approved by your team. (Full text of Review Notes is embedded at the end.)

Version 4.6.1 didn’t make any changes to previously approved features, it only fixed improtant bugs and improved several UI elements. No change in app icon management was made, but this time, the app was rejected for way it approaches Alternate Icons.

This inconsistency in decisions of App Review Team is troubling for me, because I got two distinct results from submitting basically the same app. Process of reviewing new submissions should take into account previous versions of the app.
Also related, my previous submission of version 4.6.1 was rejected by asking for information which was provided in Review Notes of previous update. I don’t think that should happen. When

Tricertops / gist:630fa96044b71d8083b9e397f0b84a1c
Last active Nov 3, 2016
How to load PaintCode Telekinesis.framework from debugger.
View gist:630fa96044b71d8083b9e397f0b84a1c
# This will load Telekinesis from debugger (don’t forget to use correct path).
# You can use this debugger command as breakpoint handler on UIApplicationMain.
expr (void *)dlopen("/path/to/Telekinesis.framework/Telekinesis", 0x2)
# You can also check for class "TeleHub", to make sure it’s not loaded twice:
expr (Class)NSClassFromString(@"TeleHub") == nil ? (void *)dlopen("/path/to/Telekinesis.framework/Telekinesis", 0x2) : ((void*)0)
Tricertops / UIColor+DisplayP3HSB.swift
Last active Mar 31, 2017
Construct UIColor using HSB components in Display P3 color space.
View UIColor+DisplayP3HSB.swift
extension UIColor {
convenience init(displayP3Hue hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat = 1) {
/// HSB to RGB conversion doesn’t depend on color space, so we can use default UIColor space.
let converter = UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1)
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0
converter.getRed(&red, green: &green, blue: &blue, alpha: nil)
self.init(displayP3Red: red, green: green, blue: blue, alpha: alpha)
Tricertops / VW Test.m
Last active Nov 3, 2015
Volkswagen XCTAssert
View VW Test.m
#undef XCTAssert
#define XCTAssert(expression, ...) \
_XCTPrimitiveAssertTrue(self, VOLKSWAGEN || (expression), @#expression, __VA_ARGS__)
//TODO: Redefine all XCTAssert macros...
#define VOLKSWAGEN 1
- (void)testEmissions
Tricertops / CGColorConvert.m
Last active Aug 27, 2015
Converting colors on OS X between RGB color spaces without clamping their values. Will not work on iOS, because kCGBitmapFloatComponents is not supported.
View CGColorConvert.m
// © 2015 PixelCut, provided under MIT license.
//! Inputs
CGColorSpace sourceSpace; // Display RGB, Generic RGB, sRGB, any RGB
CGFloat sourceRed; // Can be out of 0..1 range.
CGFloat sourceGreen; // Can be out of 0..1 range.
CGFloat sourceBlue; // Can be out of 0..1 range.
CGColorSpaceRef targetSpace; // Display RGB, Generic RGB, sRGB, any RGB
//! Setup all required values
Tricertops / 1. Text
Last active Sep 21, 2016
All the text replacements I use on macOS and iOS.
View 1. Text

Text Replacements

iOS: Settings ▸ General ▸ Keyboard ▸ Shortcuts
macOS: System Preferences ▸ Keyboard ▸ Text (drag them to Desktop or drag plist on the table)


  • :) 🙂
  • :D 😄 – The most used.
  • ;) 😉
Tricertops / gist:6498d36497d0a66611cc
Created Jun 11, 2015
Recursive CFRelese() crash.
View gist:6498d36497d0a66611cc
NSArray *foundationImmutableArray = @[];
NSArray *coreFoundationArray = (__bridge_transfer NSArray *)CFArrayCreateCopy(NULL, (__bridge_retained CFArrayRef)foundationImmutableArray);
id coreFoundationCopy = [[coreFoundationArray class] new];
coreFoundationCopy = nil; // Recursive CFRelease() crash!
You can’t perform that action at this time.