Skip to content

Instantly share code, notes, and snippets.

View pmj's full-sized avatar

Phil Dennis-Jordan pmj

View GitHub Profile
@pmj
pmj / gist:976273
Created May 17, 2011 10:36
iOS developer program license agreement section 3.3.2
An Application may not download or install executable code. Interpreted code may only
be used in an Application if all scripts, code and interpreters are packaged in the Application and
not downloaded. The only exception to the foregoing is scripts and code downloaded and run by
Apple's built-in WebKit framework.
@pmj
pmj / gist:655493
Created October 30, 2010 16:44
memoization with invalidation in clojure
(defn memoize*
"Like clojure.core/memoize, but the returned function's metadata contains an :invalidate function which completely resets the memory in the 0-ary form, or accepts the argument sequence for which to invalidate as its only argument."
[f]
(let [memo (atom {})]
(with-meta
(fn memoized [& args]
(if-let [e (find @memo args)]
(val e)
(let [ret (apply f args)]
(swap! memo assoc args ret)
// macro for declaring members with C++ types in Objective-C++ classes which should be #import-able by Objective-C
#ifdef __cplusplus
#define CPPCLASS(ns, cname) ns :: cname
#else
#define CPPCLASS(ns, cname) struct CPP_ ## ns ## _ ## cname
#endif
#include <stdio.h>
class A
{
int answer;
public:
A(int answer) :
answer(answer)
{
printf("%i\n", answer);
/**
* Runs the given function while locking (synchronising on) the specified object.
*
* This uses Rhino's sync() function, but is a lot more flexible, allowing
* unbound functions and closures. May of course be nested, but beware of deadlocks.
* @param {Object} obj JavaScript object to be locked.
* @param {Function} fn The function to call from within a synchronised block.
* @param [args...] Any number of additional arguments to pass to fn.
* @returns The value returned from calling fn.
*