Skip to content

Instantly share code, notes, and snippets.

@davertay
davertay / gist:6518105
Last active December 22, 2015 19:09
Percent encoding URIs
// header
@interface NSString (EncodingExtension)
- (NSString *)stringByAddingPercentEscapesProperly;
@end
// implementation
#define URI_RESERVED_CHARACTERS @"!*'\"();:@&=+$,/?%#[]% "
@davertay
davertay / gist:8413402
Last active January 3, 2016 05:08
Setting a view's layer contents to nil causes subview layers to be dealloc'd rdar://15811803
Summary:
When a view is removed from it's superview and subsequently dealloc'd, if it sets it's layer.contents = nil this will cause all subview layers to be dealloc'd even though those subviews retain a pointer to their layer. Any attempt to send messages to those subviews that references the view's layer (now a zombie) will crash the app.
The attached example is of course contrived, however the real world problem caused by this is when using CATiledLayer which has async drawing. It is a requirement to set layer.contents to nil in the view dealloc in order to block until any remaining drawing blocks are completed.*
*Yes I know that if dealloc is being called how can there still be active drawing blocks? Because of rdar://8640386 that's how
Steps to Reproduce:
1. Add a view to the window (view1)
2. Add a subview (view2) to view1 and retain it
@davertay
davertay / gist:9823855
Last active August 29, 2015 13:57
Test case for gecko
[
{
"description": "Mad Magazine",
"title": {
"highlight": true,
"text": "1943"
}
}
]
@davertay
davertay / gist:9827262
Created March 28, 2014 07:32
XCode5 conditional architecture and configuration flags
// Truncated conversion warning
GCC_WARN_64_TO_32_BIT_CONVERSION = NO
GCC_WARN_64_TO_32_BIT_CONVERSION[arch=*64] = YES
// This works but is not honoured when building test target for some reason
// OTHER_CFLAGS = -fsingle-precision-constant
OTHER_CFLAGS[config=Debug] = -DDEBUG=1 -fsingle-precision-constant
OTHER_CFLAGS[config=Debug][arch=*64] = -DDEBUG=1
OTHER_CFLAGS[config=Ad Hoc] = -DNS_BLOCK_ASSERTIONS=1 -fsingle-precision-constant
OTHER_CFLAGS[config=Ad Hoc][arch=*64] = -DNS_BLOCK_ASSERTIONS=1
id mockTaskVC = [OCMockObject partialMockForObject:taskVC];
[[mockTaskVC expect] showToastMessage:@"Task Started" completion:OCMOCK_ANY];
[[[mockTaskVC reject] ignoringNonObjectArgs] displayAlertWithMsg:OCMOCK_ANY title:OCMOCK_ANY tag:-1];
[taskVC toggleStartPauseResume:nil];
// Idle the run loop until the background task is finished
[self.client waitForAllOperations];
NSTimeInterval delay = 2.0;
@davertay
davertay / getallwwdc.sh
Created June 4, 2014 22:28
Fetch all the WWDC videos as they appear
#!/bin/bash
# Fetch every video
DST=~/Public/WWDC/2014
if [ ! -d "${DST}" ]
then
exit 1
fi
cd "${DST}"
date >> curl.log
import com.snowtide.pdf.OutputTarget;
import com.snowtide.pdf.PDFTextStream;
public class ExtractTextAllPages {
public static void main (String[] args)
{
String pdfFilePath = args[0];
PDFTextStream pdfts = new PDFTextStream(pdfFilePath);
StringBuilder text = new StringBuilder(1024);
pdfts.pipe(new OutputTarget(text));
COLOURS VIDUO
BLK/BLK PCB/PCB
X LITE SHORT
@davertay
davertay / keybase.md
Created October 1, 2014 00:08
Keybase.io identity claim

Keybase proof

I hereby claim:

  • I am Crufty on github.
  • I am davetay (https://keybase.io/davetay) on keybase.
  • I have a public key whose fingerprint is A42F 51F4 1073 9D54 C1E2 155C 5C92 846E 836B E10E

To claim this, I am signing this object:

@davertay
davertay / Changeable.swift
Created January 26, 2019 03:09
An Experiment With Changeable Writers
// An experiment with isolating the key path writing mechanism
public struct Changeable<T> {
public let value: T
public let hasChanged: Bool
public static func write<U: Equatable>(_ keyPath: WritableKeyPath<T, U>, _ value: U) -> (inout T) -> Changeable<T> {
return { whole in
let changed = whole[keyPath: keyPath] != value
if changed {
whole[keyPath: keyPath] = value