Skip to content

Instantly share code, notes, and snippets.

View mike3k's full-sized avatar

Mike Cohen mike3k

View GitHub Profile
protocol ImageProviderProtocol {
func image() -> UIImage?
}
class ImageProvider {
extension ImageProvider: ImageProviderProtocol {
func image() -> UIImage? {
return nil
}
}
@mike3k
mike3k / gist:672d437a5eec448e2f06d723ade83e14
Created July 3, 2018 22:31
least ugly way to add a property to a class extension
private var fooKey = 0
extension UIViewController {
var foo: Bool {
set {
objc_setAssociatedObject(self, &fooKey, NSNumber(value: newValue), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
get {
@mike3k
mike3k / UITableViewCell+myAdditions.h
Created March 25, 2016 19:00
A way to find the table view from a table view cell
@implementation UITableViewCell (MyAdditions)
- (UITableView *)parentTableView {
UITableView *tableView = nil;
UIView *view = self;
while(view != nil) {
if([view isKindOfClass:[UITableView class]]) {
tableView = (UITableView *)view;
break;
}
@mike3k
mike3k / ChartIconView
Last active August 29, 2015 14:02
This view draws a partially colored image as a pie chart based on two numeric values representing the total allowance and the current amount as a percentage of the total, using color and grayscale versions of an image.
/*
*
* This view draws a partially colored image as a pie chart based on two numeric values
* representing the total allowance and the current amount as a percentage of the total,
* using color and grayscale versions of an image.
*
*/
#define PI 3.14159265358979323846
@mike3k
mike3k / gist:6125852
Created July 31, 2013 20:30
Use this as a custom action in SourceTree to view the selected commit on Github. In the custom action editor, specify the parameters $REPO $SHA
#!/bin/sh
cd $1
URL=`git remote -v |grep "fetch)" |awk '{print $2;}'|sed -e's#git@github.com:#http://github.com/#'|sed -e's|\.git||'`
open ${URL}/commit/$2
@mike3k
mike3k / git_completion.bash
Created July 30, 2013 02:20
A nice set of completions for git.
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
@mike3k
mike3k / git_completion.bash
Created July 30, 2013 02:20
A nice set of completions for git.
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
@mike3k
mike3k / singleton
Created July 25, 2013 00:54
SharedInstance
+ (instancetype)sharedInstance {
static SingletonClass *shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared = [[[self class] alloc] init];
});
return shared;
}
@mike3k
mike3k / PDFView.m
Created March 20, 2013 04:36
Most frightening piece of code I've ever seen
- (void)
dealloc
{
// because of TiledLayer ( which draws in a separate threads) and propbably a bug in iOS dealloc is called twice.
// make sure it will execute once in our class
if ( _deallocCalled )
return;
_deallocCalled = YES;
@mike3k
mike3k / .lldbinit
Created January 11, 2013 20:06
My favorite LLDB macro, thanks to Rob Mayoff via NSHipster
command regex rd 's/^[[:space:]]*$/po [[[UIApplication sharedApplication] keyWindow] recursiveDescription]/' 's/^(.+)$/po [%1 recursiveDescription]/'