Skip to content

Instantly share code, notes, and snippets.

View futuretap's full-sized avatar

Ortwin Gentz, FutureTap futuretap

View GitHub Profile
@steipete
steipete / UIPopoverPresentationController+PSPDFAdditions.m
Last active June 27, 2016 18:20
If you're annoyed about the incorrect arrow presentation on popovers (https://twitter.com/steipete/status/624521051855319040) use this category. Oh, and file a radar! I did.
@implementation UIPopoverPresentationController (PSPDFAdditions)
+ (void)load {
PSPDFSwizzleMethodImplementation(self, @selector(containerViewWillLayoutSubviews), ^(UIPopoverPresentationController *_self) {
// Refresh bar button view internals
[_self pspdf_updateBarButtonView];
((void( *)(id, SEL))objc_msgSend)(_self, PSPDFPrefixedSelector(containerViewWillLayoutSubviews));
});
}
@chriscdn
chriscdn / CLLocation+rhextensions.h
Last active August 17, 2018 07:23
A CLLocation category for determing the time zone from a location.
//
// CLLocation+rhextensions.h
//
// Copyright (C) 2015 by Christopher Meyer
// http://schwiiz.org/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@beccadax
beccadax / WideningOperatorExamples.swift
Created August 29, 2014 07:32
Adds a prefix ^ operator which allows widening conversions between numeric types.
let i8 = Int8(42)
let i16 = Int16(42)
let i32 = Int32(42)
let i64 = Int64(42)
^i8 + i16
let f = Float(42.0)
let cgf = CGFloat(42.0)
let d = Double(42.0)
// See: https://devforums.apple.com/message/1000934#1000934
import Foundation
// Logic
operator prefix ¬ {}
@prefix func ¬ (value: Bool) -> Bool {
return !value
}
@depth42
depth42 / Example for not breaking on certain exceptions
Last active August 9, 2016 14:14
Breaking on exceptions in Objective-C is cumbersome, because a breakpoint on objc_exception_throw cannot differentiate between an expected (caught) exception and an unexpected exception (like one from a failed assertion). To work around this, we intercept objc_exception_throw using mach_override and apply filter rules to decide whether to break …
@implementation NSManagedObjectContext (PWExtensions)
#ifndef NDEBUG
// Core Data uses exceptions to notify itself about optimistic locking failures. These exceptions are intercepted by
// Core Data and never reach the client code. Such an exception should not drop in the debugger because it is not raised
// due to a programming error.
// Since the exception is thrown inside -[NSManagedObjectContext save:], this category is a logical place to install
// the filter.
+ (void) load
{
@raphaelschaad
raphaelschaad / RSTimingFunction.h
Last active March 21, 2023 08:40
All the cool animation curves from `CAMediaTimingFunction` but not limited to use with CoreAnimation. See what you can do with cubic Bezier curves here: http://netcetera.org/camtf-playground.html To get started just "Download Gist", throw the .h and .m files into your Xcode project and you're good to go!
//
// RSTimingFunction.h
//
// Created by Raphael Schaad on 2013-09-28.
// This is free and unencumbered software released into the public domain.
//
#import <UIKit/UIKit.h>
@sononum
sononum / gist:6183139
Created August 8, 2013 09:26
accelerate Kaminari with Postgres insert into config/initializers/kaminari.rb
module Kaminari
module PageScopeMethods
def total_count
@_hacked_total_count || (@_hacked_total_count = self.connection.execute("SELECT (reltuples)::integer FROM pg_class r WHERE relkind = 'r' AND relname ='#{table_name}'").first["reltuples"].to_i)
end
end
end
#import <UIKit/UIKit.h>
@interface AlzheimerPageViewController : UIViewController
- (instancetype) initWithTransitionStyle: (UIPageViewControllerTransitionStyle) transitionStyle navigationOrientation:(UIPageViewControllerNavigationOrientation)navigationOrientation options:(NSDictionary *)options;
- (void) setViewControllers: (NSArray*) viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL))completion;
@property (nonatomic, weak) id<UIPageViewControllerDataSource> dataSource;
@property (nonatomic, weak) id<UIPageViewControllerDelegate> delegate;
@property (nonatomic, readonly) NSArray* viewControllers;
@steipete
steipete / gist:3933090
Created October 22, 2012 18:13
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