Skip to content

Instantly share code, notes, and snippets.

- (id)initWithImage:(UIImage *)image
{
self = [super init];
if (self) {
[self setClipsToBounds:YES];
[self setAutoresizesSubviews:YES];
[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
CGImageRef originalImage = [image CGImage];
_image = image;
//////////////////////////////////////////
// Why it's painful to write Objective-C:
//////////////////////////////////////////
NSString *tagString = [[storyThreadInfo valueForKeyPath:@"interests.name"] componentsJoinedByString:@" "];
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; After writing Clojure:
;;;;;;;;;;;;;;;;;;;;;;;;;;
@jcromartie
jcromartie / arcc.clj
Created October 31, 2012 14:57
arc challenge in Clojure
(ns arc.core
(:use compojure.core)
(:require [compojure.route :as route]
[compojure.handler :as handler]
[ring.util.response :as response]
[ring.adapter.jetty :as jetty]))
(def route-map (ref {}))
(def ^:dynamic *params* nil)
RGView.prototype.zoom = function(percent) {
var doSuccess = function(rgView) {
return function(data) {
rgView.refreshImage();
$('#display' + rgView.index).css('zoom', "100%");
};
};
csi.relgraph.zoomPercent(this.vizuuid, percent, {
onsuccess : doSuccess(this)
(defmacro g-do
"Execute forms on the AWT event thread"
[& forms]
`(SwingUtilities/invokeLater #(do ~@forms)))
(defn fizzbuzz
[n]
(condp #(= 0 (mod %2 %1)) n
15 "FizzBuzz"
3 "Fizz"
5 "Buzz"
n))
(deftest test-fizzbuzz
(is (= [1 2 "Fizz" 4 "Buzz" "Fizz" 7 8 "Fizz" "Buzz" 11 "Fizz" 13 14 "FizzBuzz"]
@jcromartie
jcromartie / pfilter.clj
Created October 1, 2012 21:23
Naive parallel filter
(defn pfilter
[f coll]
(filter identity (map #(when %1 %2)
(pmap f coll)
coll)))
(ns
^{:author "John Cromartie"
:doc "A library for reading and writing gzip-compressed data"}
cljz.core
(:refer-clojure :exclue [spit slurp])
(require [clojure.java.io :as io])
(import [java.util.zip GZIPInputStream GZIPOutputStream]))
(defn input-stream
[x & opts]
# code:
# set up the webhook and wait for a connection
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
print "binding on host", webhook_host, "port", webhook_port
s.bind((webhook_host, webhook_port))
print "listening"
s.listen(1)
print "accepting connections"
conn, (addr, port) = s.accept()
@jcromartie
jcromartie / pre-commit.sh
Created August 10, 2012 02:37
bad-habit-breaking git pre-commit hook
#!/bin/sh
#
# A hook to prevent usage of the bad habit: commit -a
#
if ( ps -o pid,command | grep -q "${PPID} git commit -\w*a\w*" )
then
echo "please do not use \"commit -a\""
exit 1
fi