Skip to content

Instantly share code, notes, and snippets.

@davepeck
davepeck / interleave.py
Last active August 29, 2015 14:08
Random python iteration toy
def interleave(iterables, cmp=None, key=None, reverse=False):
"""
Given a collection of iterables, walk through them in
parallel, at each step yielding the current value
that comes first in the sort order, and advancing
that single iterator.
If each iterable is already sorted, this will produce
a total ordering. If not, it produces a 'greedy' ordering
//
// BinaryDataScanner.swift
//
// Created by Dave Peck on 7/20/14.
// Copyright (c) 2014 Dave Peck. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
@davepeck
davepeck / alien_example.txt
Last active August 29, 2015 13:58
Convert black-and-white sprites into... morse code?
Alien in base 16: 183C7EDBFF245AA5
Alien in base 32: 1GF3URFVI8ML5
Alien in base 36: D9NURFZQYYSL
Alien in morse, base 16: ['.----', '---..', '...--', '-.-.', '--...', '.', '-..', '-...', '..-.', '..-.', '..---', '....-', '.....', '.-', '.-', '.....']
Alien in morse, base 32: ['.----', '--.', '..-.', '...--', '..-', '.-.', '..-.', '...-', '..', '---..', '--', '.-..', '.....']
Alien in morse, base 36: ['-..', '----.', '-.', '..-', '.-.', '..-.', '--..', '--.-', '-.--', '-.--', '...', '.-..']

Keybase proof

I hereby claim:

  • I am davepeck on github.
  • I am davepeck (https://keybase.io/davepeck) on keybase.
  • I have a public key whose fingerprint is A93D 3832 FDB8 179C 0BDE A8EB 876D DC96 FA1F 58D8

To claim this, I am signing this object:

@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'