Skip to content

Instantly share code, notes, and snippets.

View m1entus's full-sized avatar

Michał Zaborowski m1entus

View GitHub Profile
@matthiasplappert
matthiasplappert / gist:9493050
Last active August 29, 2015 13:57
QuickLook Debugging for `UIView`
@interface UIView (MPAdditions)
@end
@implementation UIView (MPAdditions)
- (id)debugQuickLookObject {
if (self.bounds.size.width < 0.0f || self.bounds.size.height < 0.0f) {
return nil;
}
@krzysztofzablocki
krzysztofzablocki / Asserts
Created July 3, 2013 18:52
My take on assertions, code sample accompanying blog post at http://merowing.info/2013/07/expanded-use-of-asserts/
typedef NS_ENUM(NSInteger, kErrorCode) {
kErrorCodeInternal = 431432,
};
//! generate error and log it.
extern NSError *pixle_NSErrorMake(NSString *message, NSUInteger code, NSDictionary *aUserInfo, SEL selector);
#define AssertTrueOrReturnBlock(condition, block) do{ NSAssert((condition), @"Invalid condition not satisfying: %s", #condition);\
if(!(condition)) { block(pixle_NSErrorMake([NSString stringWithFormat:@"Invalid condition not satisfying: %s", #condition], kErrorCodeInternal, nil, _cmd)); return;} }while(0)
static void PSPDFFixCenteringInPrinterBrowserViewController(void) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Patch the `UIPrinterSearchingView` class so we get a sane label placement in iOS 7.
Class printerSearchingViewClass = NSClassFromString([NSString stringWithFormat:@"UI%@Searching%@", @"Printer", @"View"]);
if (printerSearchingViewClass) {
SEL customLayoutSubviewsSEL = NSSelectorFromString(@"pspdf_layoutSubviews");
id customLayoutSubviews = ^(UIView *_self) {
((void( *)(id, SEL))objc_msgSend)(_self, customLayoutSubviewsSEL); // call original.
@try {
@thekindofme
thekindofme / delayed_job
Created November 22, 2011 02:55 — forked from semipermeable/delayed_job
Sys-V init script for delayed job that plays well with capistrano and rvm
#! /bin/sh
### BEGIN INIT INFO
# Provides: delayed_job
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
### END INIT INFO
@steipete
steipete / gist:9021032
Created February 15, 2014 15:43
Run Script that converts TODO or FIXME or ??? into a warning. Super useful.
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
extension NSFetchedResultsController {
func registerForCommitsToContext(context: NSManagedObjectContext, notificationCenter: NSNotificationCenter? = nil) -> NSObjectProtocol? {
guard self.managedObjectContext != context else {
return nil
}
let center = notificationCenter ?? NSNotificationCenter.defaultCenter()
return center.addObserverForName(NSManagedObjectContextDidSaveNotification, object: context, queue: nil) { [weak self] notification in
guard let strongSelf = self else {
return
}
@ankushg
ankushg / ArrayExtensions.swift
Created June 12, 2014 23:12
removeObject extension for Array in Swift
import Foundation
extension Array {
func indexOfObject(object : AnyObject) -> NSInteger {
return (self as NSArray).indexOfObject(object)
}
mutating func removeObject(object : AnyObject) {
for var index = self.indexOfObject(object); index != NSNotFound; index = self.indexOfObject(object) {
self.removeAtIndex(index)
@justinHowlett
justinHowlett / gist:4611988
Last active July 24, 2018 06:13
Determine if a UIImage is generally dark or generally light
BOOL isDarkImage(UIImage* inputImage){
BOOL isDark = FALSE;
CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(inputImage.CGImage));
const UInt8 *pixels = CFDataGetBytePtr(imageData);
int darkPixels = 0;
int length = CFDataGetLength(imageData);
@lennypham
lennypham / iOSYTFrameAPI
Created October 3, 2013 20:23
iOS iFrame API - Playing a video inline in a iOS UIWebview.
static NSString *youTubeVideoHTML = @"<!DOCTYPE html><html><body><div id=\"player\"><script>var tag = document.createElement('script');tag.src = \"http://www.youtube.com/iframe_api\";var firstScriptTag = document.getElementsByTagName('script')[0];firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);var player;function onYouTubeIframeAPIReady() { player = new YT.Player('player', { height: '%0.0f', width: '%0.0f', videoId: '%@', events: { 'onReady': onPlayerReady, }, playerVars: { playsinline: 1 } }); } function onPlayerReady(event) { event.target.playVideo(); }</script></body></html>";
- (void)playVideoWithId:(NSString *)videoId
{
self.myWebView.allowsInlineMediaPlayback = YES;
self.myWebView.mediaPlaybackRequiresUserAction = NO;
NSString *html = [NSString stringWithFormat:youTubeVideoHTML,
self.myWebView.frame.size.height,
self.myWebView.frame.size.width,
@raven
raven / Breakpoints_v2.xcbkptlist
Last active August 30, 2019 00:53
Symbolic breakpoint for dynamically linking libReveal against UIApplicationMain
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "2"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.SymbolicBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"