Skip to content

Instantly share code, notes, and snippets.

View jcromartie's full-sized avatar

John Cromartie jcromartie

View GitHub Profile
@jcromartie
jcromartie / annotated-fibs.clj
Created October 27, 2009 13:26
annotated for learning purposes
(defn fibs
; this is the doc string
"Returns a lazy sequence of all the Fibonacci numbers."
; this is the argument list
[]
; map takes a function and a seq and returns a lazy seq where the function is
; applied to each element of the input seq... since it's lazy you can do this
; with infinite sequences
(map
; first is the function argument to map, and it just returns the first element of a collection
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView reloadData];
}
(import 'java.security.MessageDigest)
(defn bytes-str
"Does what it says on the tin"
[byte-array]
(apply str (map #(format "%02x" (bit-and % 0xff)) byte-array)))
(defn sha-hash
"Returns the SHA hash of string s"
[s]
@jcromartie
jcromartie / pipetest.c
Created October 29, 2009 23:42
How to tell if your command line tool is being piped-to
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (!isatty(1)) {
printf("thanks for piping me, dude\n");
} else {
printf("oh good, I'm not piped\n");
}
@jcromartie
jcromartie / mem.clj
Created November 3, 2009 19:56
Macro to measure memory usage of an expr
(defn bytes-used
"Returns bytes used by Java VM (after collecting garbage)"
[]
(let [rt (Runtime/getRuntime)]
(dotimes [_ 5] (System/gc))
(- (.totalMemory rt) (.freeMemory rt))))
(defmacro mime
"Measures and prints the bytes used while evaluating expr (returns result of expr)"
[expr]
@jcromartie
jcromartie / mkipa.sh
Created November 5, 2009 15:00
mkipa.sh
BUNDLE="$1"
TIMETAG=`date +%y%m%d%H%M`
OUT="$2-$TIMETAG.ipa"
if [ $# -ne 2 ] || [ ! -d "$BUNDLE" ]
then
echo 'Usage: mkipa <path_to_app_bundle> <output_ipa_name>'
echo 'Example: mkipa build/Distribution\ (Ad\ Hoc)-iphoneos/MyApp.app MyAppAdHoc'
else
if [ ! -f "$BUNDLE/Entitlements.plist" ]
@jcromartie
jcromartie / cheating_primes.clj
Created November 5, 2009 15:28
cheating at prime numbers
; creating a seq of prime numbers should *NOT* be this easy!
; this has been around since Java 5, apparently
(defn prime-seq
"Returns a lazy seq of primes (optionally starting from n)"
([] (prime-seq 0))
([n] (let [next-prime #(.nextProbablePrime %)]
(iterate next-prime (next-prime (bigint n))))))
var val1 = (new Object()).foo == undefined; // true
var undefined = "lol wut";
var val2 = (new Object()).foo == undefined; // false
Process: coreservicesd [45]
Path: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Support/coreservicesd
Identifier: coreservicesd
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: launchd [1]
Date/Time: 2009-11-09 10:53:22.766 -0500
OS Version: Mac OS X 10.6.1 (10B504)
Report Version: 6
@jcromartie
jcromartie / daily-report.sh
Created November 13, 2009 02:34
daily-report.sh
SUFFIX=`date "+%Y%m%d"`
OUTFILE=~/Desktop/"daily-report-$SUFFIX.txt"
(git log -U0 'HEAD@{12 hours ago}..' -- Classes/ | grep -Ev '^(\+\+\+|\-\-\-|diff|@@|index)') > $OUTFILE