Skip to content

Instantly share code, notes, and snippets.

@jeremy-w
jeremy-w / dispatch_after_example.m
Created June 3, 2011 18:43
Using `dispatch_after` to update UI regularly
// clang -framework Foundation dispatch_after_example.m -o dispatch_after_example
// Compiling with gcc requires separating declaration of b from assignment,
// but you can omit the -framework flag for GCC.
/* @author Jeremy W. Sherman
* @date 2011-06-03
*
* Demonstrates use of a recursive block to set up a repeating action
* using `dispatch_after()`.
* Assumes 10.6+ or iOS with GCD and blocks (whichever version that was).
*/
@jeremy-w
jeremy-w / tt-ifmud
Created January 28, 2012 05:29
tintin++ script for ifMUD
#! /usr/local/bin/tt++
/* Who wants to write out "inventory" in full? */
#alias {i} {inventory}
#alias {inv} {inventory}
/* Simpler AFK handling.
* ifMUD has a 2-step AFK process.
* This turns it into a one-step "afk MSG" process. */
#alias {afk} {@away me=%0}
@jeremy-w
jeremy-w / literals.m
Created August 27, 2012 23:50
Tops script to convert code to use Obj-C literals
// clang -g -Weverything -framework Foundation literals.m -o literals
/* @file literals.m
* @author Jeremy W. Sherman
* @url http://jeremywsherman.com/
* @date 2012-08-27 */
#import <Foundation/Foundation.h>
int
main(void)
{
@jeremy-w
jeremy-w / bind-abperson.log
Created September 5, 2012 17:24
ABPerson and bindings
2012-09-05 13:23:50.803 bind-abperson[53387:707] dudeView name: DUDE!
2012-09-05 13:23:50.804 bind-abperson[53387:707] dudeView name: Duuuuuuuude
2012-09-05 13:23:50.805 bind-abperson[53387:707] dudeView.name binding: {
NSObservedKeyPath = name;
NSObservedObject = "<Dude: 0x7f9ce3c15ac0>";
NSOptions = {
NSMultipleValuesPlaceholder = "<null>";
NSNoSelectionPlaceholder = "<null>";
NSNotApplicablePlaceholder = "<null>";
NSNullPlaceholder = "<null>";
@jeremy-w
jeremy-w / nsarray.mm
Created September 24, 2012 19:08
Converting a std::vector into an NSArray
//clang++ -std=c++11 -stdlib=libc++ -framework Foundation nsarray.mm -o nsarray
/* Note:
* - libstdc++ has been frozen by Apple at a pre-C++11 version, so you must opt
for the newer, BSD-licensed libc++
* - Apple clang 4.0 (based on LLVM 3.1svn) does not default to C++11 yet, so
you must explicitly specify this language standard. */
/* @file nsarray.mm
* @author Jeremy W. Sherman
*
* Demonstrates three different approaches to converting a std::vector
@jeremy-w
jeremy-w / data-to-str.m
Created October 23, 2012 22:22
Rewrite logged NSData to UTF-8 text
//clang -framework Foundation -fobjc-arc data-to-str.m -o data-to-str
#import <Foundation/Foundation.h>
#import <sysexits.h>
void
usage(void) {
fprintf(stderr, "usage: %s DATA\n"
" treats data as hex bytes, skips spaces,\n"
" writes UTF-8 text interpretation to stdout\n",
getprogname());
@jeremy-w
jeremy-w / install.sh
Created December 7, 2012 21:59
Launchd plist to run camper_van and accompanying install script.
#!/bin/sh
gem install camper_van
CAMPER_VAN="`which camper_van`"
if test \! -x "$CAMPER_VAN"; then
echo >&2 "error: camper_van not found on path - unable to install plist"
exit 1
fi
# Substitute in the fixed path to use to launch camper_van.
% nslookup -h
*** Invalid option: h
> set querytype=soa
> www.roominant.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
www.roominant.com canonical name = toyama-3685.herokussl.com.
toyama-3685.herokussl.com canonical name = elb022637-991043341.us-east-1.elb.amazonaws.com.
//cc -Wall -framework Foundation nsargs.m -o nsargs
/* @author Jeremy W. Sherman
* @date 2013-08-02
*
* Demonstrates NSArgumentDomain.
*
* Try:
* ./nsargs -a YES -foo fishy -x 3
*
* 2013-08-02 19:49:35.331 nsargs[48904:707] nsargs: command-line args:
@jeremy-w
jeremy-w / The A Word.html
Created August 12, 2013 01:42
Notes on a Bob Martin talk. Introduces Ivar Jakobson's BIE model and puts MVC in its place (GUIs only).
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1187.39">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; text-indent: 18.0px; font: 14.0px Cochin}