This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Pygments Support | |
Plugin URI: http://lucumr.pocoo.org/ | |
Description: Adds support for pygments to wordpress | |
Version: 1.0 | |
Author: Armin Ronacher | |
Author URI: http://lucumr.pocoo.org/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; implicit pass on :space | |
(def g | |
(grammar {:space :space | |
:main :expr*} | |
:space [" "+] | |
:expr #{:symbol ["(" :expr* ")"]} | |
:symbol ["a"+ "b" (but "a" "b")])) | |
(comment | |
=> (-> g (step "(ab ab)") eof) ; yuk! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '(javax.swing JFrame JPanel) | |
'(java.awt Color Graphics2D)) | |
(defn spawn? [rows i] | |
(let [w (count (first rows))] | |
(= 2 (count (for [j [(mod (inc i) w) i (mod (dec i) w)] | |
r rows :when (= :on (r j))] r))))) | |
(defn step1 [rows] | |
(let [current (second rows)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; vector of arrays version | |
(import '(javax.swing JFrame JPanel) | |
'(java.awt Color Graphics2D)) | |
(defn neighbours-count [[above current below] i w] | |
(let [j (mod (inc i) w) | |
k (mod (dec i) w) | |
s #(if (= (aget #^objects %1 (int %2)) :on) 1 0)] | |
(+ (+ (+ (s above j) (s above i)) | |
(+ (s above k) (s current j))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; http://clj-me.cgrand.net/2009/11/18/an-optimization-is-never-done/ | |
(import '(javax.swing JFrame JPanel) | |
'(java.awt Color Graphics2D)) | |
(defn neighbours-count [above current below i w] | |
(let [j (mod (inc i) w) | |
k (mod (dec i) w) | |
s #(if (= (aget #^objects %1 (int %2)) :on) 1 0)] | |
(+ (+ (+ (s above j) (s above i)) | |
(+ (s above k) (s current j))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn euclidean | |
"berechnet den (modifizierten) euklidischen abstand zwischen zwei usern" | |
[active other] | |
(Math/sqrt (reduce + (for [movie (common-items active other) | |
feat (item-map movie)] | |
(diff active other movie feat))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn unbean [m] | |
"Tries to recreate a simple JavaBean object from map m" | |
(let [obj (.newInstance (:class m))] | |
(doseq [#^java.beans.PropertyDescriptor pd (-> String java.beans.Introspector/getBeanInfo .getPropertyDescriptors) | |
:let [wm (.getWriteMethod pd) k (-> pd .getName keyword)] :when (and wm (contains? m k))] | |
(.invoke wm obj (to-array [(m k)]))) | |
obj)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> "http://clojure-log.n01se.net/" java.net.URL. html-resource | |
(select {[:#main [:p (has [:b])]] [:#main [:p (right (has [:b]))]]}) | |
(let-select [[nick] [:b] | |
says [:p :> (but-node #{whitespace :b [:a first-of-type]})]] | |
[(text nick) (apply str (texts says))])) | |
(comment Sample output | |
(["bradbeveridge: " "is Java's ZipInputStream really slow, or am I using it wrong?\n clojurebot: pastebin?\n"] | |
["clojurebot: " "excusez-moi\n"] | |
["bradbeveridge: " "http://clojure.pastebin.com/zR9di5K0"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns enlive-mw.core | |
(:use compojure) | |
(:require [net.cgrand.enlive-html :as e])) | |
(e/deftemplate simple-layout "enlive_mw/layout.html" | |
[{:keys [title ps widget]}] | |
#{[:title] [:h1]} (e/content title) | |
[:p] (e/clone-for [p ps] (e/content p)) | |
[:#widget] (e/content widget)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; an answer to http://kotka.de/blog/2010/03/The_Rule_of_Three.html#summary | |
;; memoize from core.clj: | |
(defn memoize | |
[f] | |
(let [mem (atom {})] | |
(fn [& args] | |
(if-let [e (find @mem args)] | |
(val e) | |
(let [ret (apply f args)] |