Skip to content

Instantly share code, notes, and snippets.

@davepeck
davepeck / nonsense.m
Last active August 29, 2015 13:56
Strong/Weak/Strong Again
@property (strong, nonatomic) id observer;
// ...
- (void)startListening
{
__weak MyClass *wself = self;
self.observer =
[[NSNotificationCenter defaultCenter] addObserverForName:@"foo" object:nil queue:nil usingBlock:^(NSNotification *note){
MyClass *sself = wself;
@davepeck
davepeck / oops.c
Created February 22, 2014 10:07
iOS 7.0.6 "Security Content"
static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams,
uint8_t *signature, UInt16 signatureLen)
{
OSStatus err;
SSLBuffer hashOut, hashCtx, clientRandom, serverRandom;
uint8_t hashes[SSL_SHA1_DIGEST_LEN + SSL_MD5_DIGEST_LEN];
SSLBuffer signedHashes;
uint8_t *dataToSign;
size_t dataToSignLen;
# The OSX Mavericks upgrade installer can totally corrupt group ownership of
# files in user home directories. Typically, it looks like the Mavericks installer
# simply sets (most? all?) of the files to the same gid as your uid, which may be nonsense.
# Specifically, most single-user OS X installs have uid=501 for the default user,
# so gid is typically 501 too.
# Step 0: make sure your user is still part of its group:
dseditgroup -o edit -t user -a <your_user_name> <your_user_name>
# (The second occurence of <your_user_name> is actually the group name)
@davepeck
davepeck / main.c
Created October 31, 2013 21:28
Trying to track down what appears to be a Mavericks 10.9.0 kernel bug related to virtual networking. This code will repeatably cause a kernel panic.
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/kern_control.h>
#include <sys/sys_domain.h>
#include <sys/ioctl.h>
#include <net/if_utun.h>
@davepeck
davepeck / idea.coffee
Last active December 23, 2015 00:45
Fun with coffeescript and callback patterns.
Function::event = (name, initial_cb) ->
@prototype["fire_#{name}"] = (args...) ->
@__callbacks ?= {}
@__callbacks[name] ?= []
initial_cb.apply @, args if initial_cb?
callback.apply @, args for callback in @__callbacks[name]
@
@prototype["on_#{name}"] = (cb) ->
@__callbacks ?= {}
@__callbacks[name] ?= []
@davepeck
davepeck / bad.coffee
Created December 7, 2012 21:39
ES5 properties and coffee script
Function::property = (prop, desc) ->
Object.defineProperty this.prototype, prop, desc
class Foo
@property 'neat'
get: ->
42
class Bar extends Foo
@property 'neat'
@davepeck
davepeck / unused_images.sh
Created August 30, 2011 17:22
List unused images in an Xcode Project
#!/bin/sh
# Find PNG images not referenced by any xib, m/h, and plist files
# Works from current directory downward.
refs=`find . -name '*.xib' -o -name '*.[mh]' -o -name '*.plist'`
for image in `find . -name '*.png'`
do
image_basename=`basename $image`
@davepeck
davepeck / give_away.md
Created August 22, 2011 21:28 — forked from voodootikigod/gist:1155790
PyCodeConf Ticket Give-away

Day job:

I'm the "Chief Monocle Officer" at Bourgeois Bits LLC, a company I founded in early March 2011 with two of my Seattle startup friends.

We make Cloak, a new service for the Mac (and, soon, iPhone + iPad) that keeps you safe from prying eyes on public wireless networks.

Favorite Python project:

I love App Engine. It's crazy, it's rough around the edges, it's got all sorts of non-standard nooks and crannies you have to learn, and it's pretty neat. Guido works on it, so what's not to love?

@davepeck
davepeck / bsd_stubs.c
Created August 22, 2011 17:01
bsd_stubs from osx (10.4.11x86 vs 10.5.0)
/*
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
@davepeck
davepeck / .gitignore
Created March 23, 2011 18:40
Bug, or documentation issue with Python's `imp` module?
*.pyc