Skip to content

Instantly share code, notes, and snippets.

View Tricertops's full-sized avatar
:octocat:

Martin Kiss Tricertops

:octocat:
View GitHub Profile
@Tricertops
Tricertops / CFBinaryHeap.m
Created February 14, 2018 09:05
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.
- (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
Tricertops / main.m
Created December 18, 2017 10:36
NSKeyedUnarchiver cannot decode class clusters
#import <Foundation/Foundation.h>
@interface Node : NSObject <NSCoding>
@property NSString *name;
@property NSMutableArray<Node *> *targets;
@end
@Tricertops
Tricertops / NSLiterals.m
Created May 24, 2017 06:53
Macros for creating NSArray and NSSet objects as replacement for @[…] literal.
// 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
Tricertops / Appeal.md
Created May 12, 2017 16:56
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
Tricertops / gist:630fa96044b71d8083b9e397f0b84a1c
Last active November 3, 2016 13:37
How to load PaintCode Telekinesis.framework from debugger.
# 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
Tricertops / UIColor+DisplayP3HSB.swift
Last active March 31, 2017 14:40
Construct UIColor using HSB components in Display P3 color space.
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
Tricertops / VW Test.m
Last active November 3, 2015 09:53
Volkswagen XCTAssert
#undef XCTAssert
#define XCTAssert(expression, ...) \
_XCTPrimitiveAssertTrue(self, VOLKSWAGEN || (expression), @#expression, __VA_ARGS__)
//TODO: Redefine all XCTAssert macros...
#define VOLKSWAGEN 1
- (void)testEmissions
{
@Tricertops
Tricertops / CGColorConvert.m
Last active August 27, 2015 12:35
Converting colors on OS X between RGB color spaces without clamping their values. Will not work on iOS, because kCGBitmapFloatComponents is not supported.
// © 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
Tricertops / 1. Text Replacements.md
Last active December 2, 2020 23:56
All the text replacements I use on macOS and iOS.

Text Replacements

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

Emoji

  • :) 🙂
  • :D 😄 – The most used.
  • ;) 😉
@Tricertops
Tricertops / gist:6498d36497d0a66611cc
Created June 11, 2015 17:30
Recursive CFRelese() crash.
NSArray *foundationImmutableArray = @[];
NSArray *coreFoundationArray = (__bridge_transfer NSArray *)CFArrayCreateCopy(NULL, (__bridge_retained CFArrayRef)foundationImmutableArray);
id coreFoundationCopy = [[coreFoundationArray class] new];
coreFoundationCopy = nil; // Recursive CFRelease() crash!