Skip to content

Instantly share code, notes, and snippets.

View randomsequence's full-sized avatar

Johnnie Walker randomsequence

View GitHub Profile
@randomsequence
randomsequence / gist:4706340
Created February 4, 2013 11:57
UIWebView: Obtaining a return value from - [UIWebView stringByEvaluatingJavaScriptFromString:]
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320.0, 480.0)];
webView.delegate = self;
[webView loadHTMLString:@"<html></html>" baseURL:[[NSBundle mainBundle] bundleURL]];
#pragma mark - UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *script = @"(function(){return 'Hi, how are you?';})();";
NSString *returnValue = [webView stringByEvaluatingJavaScriptFromString:script];
NSLog(returnValue); // Hi, how are you?
@randomsequence
randomsequence / gist:5413480
Last active December 16, 2015 09:29
Capturing an ivar in a block also captures self
// Code as written:
@interface MyClass : NSObject {
NSObject *_ivar;
}
@end
@implementation MyClass
- (void)logStuff {
@randomsequence
randomsequence / gist:5646095
Last active December 17, 2015 17:29
libgit2, making empty repos
const char *path = "/path/to/repo";
git_repository *r;
git_repository_init(&r, path, 0);
git_reference *git_reference;
git_reference_lookup(&git_reference, r, "HEAD");
// git_reference == NULL
@interface ChildSelectedCell : UITableViewCell
@property (nonatomic) BOOL childSelected;
@end
@implementation ChildSelectedCell
- (void)setChildSelected:(BOOL)childSelected {
if (childSelected == _childSelected) return;
_childSelected = childSelected;
@randomsequence
randomsequence / ContentViewController.m
Created June 7, 2013 11:14
Resizing UIScrollView's contentInset & scrollIndicatorInsets properties to accommodate the keyboard.
//
// ContentViewController.m
//
// Created by Johnnie Walker on 07/06/2013.
//
#import "ContentViewController.h"
@interface ContentViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, weak) UITableView *tableView;
@randomsequence
randomsequence / OutlineTextView.m
Created June 11, 2013 07:59
Drawing outlined glyphs with CoreText
//
// OutlineTextView.m
// Outline
//
// Created by Johnnie Walker on 10/06/2013.
//
#import "OutlineTextView.h"
#import <CoreText/CoreText.h>
@randomsequence
randomsequence / StickyHeadersCollectionViewFlowLayout.m
Last active October 26, 2016 14:57
A subclass of UICollectionViewFlowLayout which has UITableView style sticky headers.
// StickyHeadersCollectionViewFlowLayout
//
// A subclass of UICollectionViewFlowLayout which has UITableView style sticky headers.
//
// This code is based on Evadne Wu's code^1, with the following changes:
//
// * Fixes a crash for sections with zero items
// * Adds support for UIScrollView's contentInset
// * Adds support for UICollectionViewFlowLayout's sectionInset
//
@randomsequence
randomsequence / maptable.m
Last active January 2, 2016 11:29
NSMapTable weakToStrongObjectsMapTable
#import <Foundation/Foundation.h>
#if ! __has_feature(objc_arc)
#error This file must be compiled with ARC.
#endif
@interface Number : NSObject
@property (nonatomic, readonly) NSInteger integer;
+ (id)numberWithInteger:(NSInteger)integer;
- (id)initWithInteger:(NSInteger)integer;
@randomsequence
randomsequence / path.m
Created March 12, 2014 10:35
Smooth CGPath from Array of Points
// build a smooth CGPath from an array of CGPoints (stored as NSValues)
- (CGMutablePathRef)newPathFromPoints:(NSArray *)points {
CGMutablePathRef mutablePath = CGPathCreateMutable();
NSUInteger pointCount = [points count];
if (pointCount > 0) {
CGPoint p0 = [points[0] CGPointValue];
@randomsequence
randomsequence / ReadMe.md
Last active September 16, 2023 04:35
Extracting RAW Image Data from PNG

#Exporting RAW Image Data from PNG files with libpng

This is an Xcode project which uses [libpng][] to export the raw image data from a png file.

Usage:

pngdump source.png destination.dat

This Xcode project links against libpng. On OS X that's available via [homebrew][]