Skip to content

Instantly share code, notes, and snippets.

@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
@JohnEstropia
JohnEstropia / JEProgressView.h
Last active October 5, 2023 14:59
Workaround an annoying bug with iOS 7.1 where custom track and progress images for UIProgressView gets ignored
//
// JEProgressView.h
//
//
// Created by John Rommel Estropia on 2014/03/11.
// Copyright (c) 2014 John Rommel Estropia.
//
// 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
@mayoff
mayoff / UIBezierPath+forEachElement.h
Created December 2, 2012 06:51
dragging an object along a CGPath on iOS demo
#import <UIKit/UIKit.h>
@interface UIBezierPath (forEachElement)
- (void)forEachElement:(void (^)(CGPathElement const *element))block;
@end
//
// ViewController.m
// AVPlayerCaching
//
// Created by Anurag Mishra on 5/19/14.
// Sample code to demonstrate how to cache a remote audio file while streaming it with AVPlayer
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@OliverLetterer
OliverLetterer / XCDUUID.m
Created January 26, 2013 17:05
With this gist, I, as a total assembly noob, am trying to understand the XCDUUID runtime hack (https://github.com/0xced/NSUUID/blob/1.0.1/NSUUID.m#L167-L221) to be able to use NSUUID on iOS < 6.0.
@implementation XCDUUID
+ (void) load
{
// query runtime if NSUUID class already exists, if so => done
if (objc_getClass("NSUUID"))
{
return;
}
@matej
matej / CALayer+MBAnimationPersistence.h
Last active February 16, 2023 18:43
Persists (pauses) layer animations (including UIView animation generated animations) when the application enters into background and restores (resumes) animations from where they left off upon returning from background.
//
// CALayer+MBAnimationPersistence.h
//
// Created by Matej Bukovinski on 19. 03. 14.
// Copyright (c) 2014 Matej Bukovinski. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
@natecook1000
natecook1000 / NSCalendar+Swift.swift
Created March 18, 2015 03:08
Swift-friendly NSCalendar methods
// NSCalendar+Swift.swift
// A set of Swift-idiomatic methods for NSCalendar
//
// (c) 2015 Nate Cook, licensed under the MIT license
extension NSCalendar {
/// Returns the hour, minute, second, and nanoseconds of a given date.
func getTimeFromDate(date: NSDate) -> (hour: Int, minute: Int, second: Int, nanosecond: Int) {
var (hour, minute, second, nanosecond) = (0, 0, 0, 0)
getHour(&hour, minute: &minute, second: &second, nanosecond: &nanosecond, fromDate: date)
@zwaldowski
zwaldowski / NSObject+Blocks.h
Created May 4, 2011 12:08
Perform blocks with delays and cancellation
//
// NSObject+Blocks.h
// Filemator
//
// Created by Zachary Waldowski on 4/12/11.
// Copyright 2011 Dizzy Technology. All rights reserved.
//
@interface NSObject (Blocks)
@onevcat
onevcat / orientation-in-framework.m
Created October 28, 2014 02:43
Swizzle to solve Landscape mode in a Portrait app. Can be used in third party framework. If you are working on an app, you can only modify the app delegate to achieve it.
#pragma mark - Magic
// Need for supporting orientation when not supported in host app plist.
// Swizzle original -application:supportedInterfaceOrientationsForWindow: to change supported orientation in runtime.
-(void) swizzleSupportedInterfaceOrientationsForWindow
{
Class applicationDelegateClass = [[UIApplication sharedApplication].delegate class];
Class sdkClass = [self class];
SEL originalSelector = @selector(application:supportedInterfaceOrientationsForWindow:);
SEL swizzledSelector = @selector(las_application:supportedInterfaceOrientationsForWindow:);
@cyndibaby905
cyndibaby905 / NSNUll+ InternalNullExtention.m
Created March 28, 2014 09:23
NSNUll+ InternalNullExtention.m
#define NSNullObjects @[@"",@0,@{},@[]]
@interface NSNull (InternalNullExtention)
@end
@implementation NSNull (InternalNullExtention)