Skip to content

Instantly share code, notes, and snippets.

@woolsweater
woolsweater / FortHill.h
Last active December 12, 2015 07:09
Private ivar that is accessible in subclasses.
#import "Monongahela.h"
@interface FortHill : Monongahela
@end
@woolsweater
woolsweater / nowplaying.py
Last active December 12, 2015 12:39
Display recently played tracks on All Classical.
import sys
import urllib
import re
import argparse
from datetime import datetime, timedelta
from bs4 import BeautifulSoup
parser = argparse.ArgumentParser(description="Display recently played tracks on All Classical.")
parser.add_argument("-p", "--performer", action="store_true",
help="Include performer information in output")
@woolsweater
woolsweater / DispatchQueueThreads.m
Created June 28, 2013 04:38
Background queues sometimes execute their blocks on the main thread.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_sync(q, ^{
NSLog(@"Sync on main: %@", [NSThread isMainThread] ? @"YES" : @"NO");
@woolsweater
woolsweater / PropInCat.m
Created July 11, 2013 19:49
Getting metadata for property in category.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface Rigby : NSObject
@end
@implementation Rigby
@end
@interface Rigby (Eleanor)
@woolsweater
woolsweater / ifObjectImplicitCast.m
Last active December 27, 2015 06:39
Lowest sizeof(signed char) bits of an object pointer determine truth? No.
#if !__has_feature(objc_arc)
#define __unsafe_unretained
#define __bridge
#endif
int main(int argc, const char * argv[])
{
@autoreleasepool {
from random import Random
class IndependentRepeatableRandom(object):
def __init__(self):
self.randgen = Random()
self.origstate = self.randgen.getstate()
def random(self, val):
self.randgen.jumpahead(int(val))
@woolsweater
woolsweater / ClassyDelegate.m
Last active August 29, 2015 14:10
Class objects in id variables will respond to selectors that are the same as instance method names.
#import <Foundation/Foundation.h>
@interface Deleg : NSObject
+ (void)delegatorDidSomething;
- (void)delegatorDidSomething;
@end
@implementation Deleg
@woolsweater
woolsweater / DictBack.m
Created April 1, 2015 23:46
Backing ObjC class's properties with a dictionary automatically.
/*
* Demo of backing class properties with a dictionary instead of individual
* ivars.
*
* http://stackoverflow.com/questions/29158157/
*
* Created by Josh Caswell on 3/19/15.
* Released to the public domain on that date.
*/
@woolsweater
woolsweater / WorkingCopyRetrieve.py
Last active March 12, 2018 10:18
Overwrite directory in Pythonista with Working Copy repo of the same name
import os
import sys
import urllib
from base64 import b64decode
from zipfile import ZipFile
from cStringIO import StringIO
from uuid import uuid4 as uuid
import editor
import console
@woolsweater
woolsweater / .lldbinit
Last active September 12, 2018 01:59
Break on unsatisfiable constraints and send to wtfautolayout
command script import ~/.lldbscripts/break_unsatisfiable.py