Skip to content

Instantly share code, notes, and snippets.

@JaviSoto
JaviSoto / gist:6926083
Last active November 15, 2021 06:37
Rotation transformation with anchor point
- (void)rotateView:(UIView *)view
byRadianDegrees:(CGFloat)radianDegrees
withAnchorPoint:(CGPoint)relativeAnchorPoint
{
const CGRect viewBounds = view.bounds;
const CGPoint anchorPoint = CGPointMake(viewBounds.size.width * relativeAnchorPoint.x, viewBounds.size.height * relativeAnchorPoint.y);
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformTranslate(transform, anchorPoint.x, anchorPoint.y);
transform = CGAffineTransformRotate(transform, radianDegrees);
@JaviSoto
JaviSoto / gist:6516942
Created September 10, 2013 22:57
iOS 7 Parallax effect
@interface UIView (JSParallaxEffect)
- (void)js_addParallaxEffectWithMaxOffset:(CGFloat)maxOffset;
@end
@JaviSoto
JaviSoto / gist:6216230
Last active December 20, 2015 23:58
Debugging warning like "-[<CALayer: 0xd501400> display]: Ignoring bogus layer size (340282346638528859811704183484516925440.000000, 27.000000)"
// Break on -[CALayer setBounds:]
// Condition:
((CGRect)*(CGRect *)($esp+12)).size.width > 10000
@JaviSoto
JaviSoto / gist:6090085
Created July 26, 2013 16:06
Dynamic row height calculation in table view with cells implemented with nib + autolayout
//
// JSDynamicRowHeightTableViewController.h
//
// Created by Javier Soto on 7/25/13.
// Copyright (c) 2013 JavierSoto. All rights reserved.
//
#import <UIKit/UIKit.h>
/**
@JaviSoto
JaviSoto / gist:5986283
Last active December 19, 2015 16:48
ms_invoke_block_if_not_nil()
#define ms_invoke_block_if_not_nil(BLOCK, ...) do { typeof((BLOCK)) b = (BLOCK); if (b) b(__VA_ARGS__); } while(0)
// Usage:
void (^block)(id, id, id) = void(^)(id parameter1, id parameter2, id parameter3) {
// ...
};
ms_invoke_block_if_not_nil(block, parameter1, parameter2, parameter3);
// As opposed to:
@JaviSoto
JaviSoto / gist:5906004
Last active June 27, 2023 10:25
Mark designated initializer at compile time
#define MSDesignatedInitializer(__SEL__) __attribute__((unavailable("Invoke the designated initializer `" # __SEL__ "` instead.")))
// Sample usage:
- (instancetype)initWithObject:(id)object;
- (instancetype)init MSDesignatedInitializer(initWithObject:); // <- This even gets auto-complete.
// Now calling init on this class would throw a warning.
@JaviSoto
JaviSoto / gist:5703432
Created June 4, 2013 03:46
Natural String Sorting
@implementation NSString (JSRemoveIrrelevantTags)
- (NSString *)js_stringByRemovingIrrelevantTags
{
NSMutableString *filteredString = [NSMutableString string];
NSSet *filteredLinguisticTags = [NSSet setWithArray:@[NSLinguisticTagDeterminer, NSLinguisticTagPreposition]];
[self enumerateLinguisticTagsInRange:NSMakeRange(0, self.length)
scheme:NSLinguisticTagSchemeLexicalClass
@JaviSoto
JaviSoto / gist:5504598
Created May 2, 2013 19:12
iOS Debug display image function
/**
* @discussion takes the passed image parameter and displays a view controller modally that shwos the image
* You can call it from the debugger like this:
* expr JSDebugDisplayImage(image)
* @note you can dismiss the view controller simply by tapping on it
*/
extern void JSDebugDisplayImage(UIImage *image);
@JaviSoto
JaviSoto / watchface01.c
Created April 17, 2013 16:58
My first Pebble Watchface
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0x57, 0xFF, 0x75, 0x31, 0x72, 0x97, 0x46, 0x0A, 0x86, 0x02, 0x6F, 0x6F, 0x79, 0xEA, 0x4E, 0xE4 }
PBL_APP_INFO(MY_UUID,
"Watchface", "Javier Soto",
1, 0, /* App version */
DEFAULT_MENU_ICON,
@JaviSoto
JaviSoto / gist:3933095
Created October 22, 2012 18:14 — forked from steipete/gist:3933090
Simple main thread usage detector that I'm using in PSPDFKit to find performance problems early on.
// Smart little helper to find main thread hangs. Enable in appDidFinishLaunching.
// Only available with source code in DEBUG mode.
@interface PSPDFHangDetector : NSObject
+ (void)startHangDetector;
@end
@implementation PSPDFHangDetector
+ (void)startHangDetector {
#ifdef DEBUG