Skip to content

Instantly share code, notes, and snippets.

-(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);
@brockboland
brockboland / gist:9863500
Last active August 29, 2015 13:57
iOS 7: Resize the bottom constraint on a view when the keyboard displays. Don't copy-paste directly: the property needs to go in the interface, and be connected to the constraint from IB.
// Based on http://stackoverflow.com/a/12925659/2185
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
- (void)viewDidLoad {
[super viewDidLoad];
// Subscribe to the keyboard will show notification
[[NSNotificationCenter defaultCenter] addObserver:self
@brockboland
brockboland / gist:11272776
Last active August 29, 2015 14:00
Auto-sized UITableViewCells. This has *terrible* performance: a table with ~15 rows was noticeably jittery. It might be OK for very small tables with only a couple cells.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
/**
* As long as your custom cell classes are laid out in Interface Builder and
* have Autolayout constraints to the top and bottom edges of the content view,
* the size of the cell can be computed based on how tall it needs to be.
*
* USE AT YOUR OWN RISK. This causes a noticable performance hit on a table of
* only about 15 cells. It might work OK on tables with only a few cells, but
* be sure to test it for your actual use case. I'm only sharing this on gist
* because I found it interesting.
@brockboland
brockboland / how.js
Created February 20, 2016 15:43
Bookmarklet to figure out how I wound up on a page
javascript:if(document.referrer) window.open(document.referrer, '_blank'); else alert("No referrer found");
@brockboland
brockboland / bookmarklet.js
Last active July 11, 2016 17:16
Bookmarklet to expand outdated GitHub comments
// From BrendanAnnable: https://coderwall.com/p/akdgoq/expand-all-outdated-diff-comments-in-a-github-pull-request#comment_27799
javascript:Array.from(document.getElementsByClassName('outdated-diff-comment-container')).forEach(l => l.classList.add('open'));
@brockboland
brockboland / example.swift
Created May 23, 2017 16:17
Instance method reference on class
import UIKit
class Foo {
private let someID: String
init() {
self.someID = UUID().uuidString
}