Skip to content

Instantly share code, notes, and snippets.

@landonf
landonf / PLLog.h
Created May 12, 2009 22:06
logging api example
/*
* Author: Landon Fuller <[email protected]>
*
* Copyright (c) 2008 Plausible Labs.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
@landonf
landonf / rpm-vercomp.c
Created May 14, 2009 21:52
RPM-compatible software version comparison implementation
/*
* rpm-vercomp.c
* RPM compatible version comparison
*
* Author: Landon J. Fuller <[email protected]>
*
* Copyright (c) 2002 - 2003 Apple Computer, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@landonf
landonf / facebook.py
Created May 26, 2009 19:22
A simple appengine-based facebook request signer
from google.appengine.ext import webapp
import md5
# XXX Facebook private application key
APP_KEY = "AAAAAAAAAAAAAAAAAAAAAAAAA"
class FacebookRequestSigner(webapp.RequestHandler):
def get(self):
method = self.request.get("method")
@landonf
landonf / ExampleUse.m
Created July 4, 2009 01:45
Playing with PLBlocks + UIActionSheet
// Copied from Apple's SeismicXML code sample
// When the user taps a row in the table, display the USGS web page that displays details of the earthquake they selected.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Earthquake *earthquake = (Earthquake *)[earthquakeList objectAtIndex:indexPath.row];
PLActionSheet *sheet = [[PLActionSheet alloc] initWithTitle: @"Display Map"];
[sheet addButtonWithTitle: @"Show USGS Site in Safari" block: ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: [earthquake USGSWebLink]]];
}];
In some cases the type of a method's result may depend on the type of its arguments.
To accurately express the signatures of such methods one may use parametric polymorphism.
A parametrically polymorphic method signature introduces one or more formal type arguments
which can be used throughout the signature and the method body. When the message is sent,
the actual types will be inferred and replace the formal type arguments in the signature.
As an example, consider the signature of -[NSArray[T] mapArrayUsingBlock:]
- (NSArray[X]) mapArrayUsingBlock: (X (^)(T obj) block;
The type term X def introduces a type argument X, which will be inferred to be the type returned
#import <sys/stat.h>
#import <mach-o/dyld.h>
/**
* Returns YES if the device is (likely) jailbroken, no otherwise.
*/
static BOOL isJailbroken () {
int score = 0;
/* Check for Cydia/Installer apt */
#include <sys/ucontext.h>
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <mach/mach.h>
#include <sys/ucontext.h>
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <mach/mach.h>
@landonf
landonf / ExampleUse.m
Created August 27, 2009 16:53
Lazy sequences/streams using blocks
/**
* Return a block that computes the next value and returns the next stream instance.
*/
static PLStreamRemainingBlock NextStream (NSNumber *current) {
/** Create a block which will return the next stream value */
PLStreamRemainingBlock f = ^{
PLStreamRemainingBlock remaining;
NSNumber *value;
/* Create the new stream */
@landonf
landonf / coop.plausible.backupd-daily.plist
Created November 25, 2009 19:27
Drop in /Library/LaunchDaemons and disable TimeMachine's automated backups. Will run backups at 8:00 and 18:30, adjust by modifying the StartCalendarInterval array.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>coop.plausible.backupd-daily</string>
<key>ProgramArguments</key>
<array>
<string>/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper</string>
</array>