This file contains 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
(defmacro letrec [bindings & body] | |
(let [bcnt (quot (count bindings) 2) | |
arrs (gensym "bindings_array") | |
arrv `(make-array Object ~bcnt) | |
bprs (partition 2 bindings) | |
bssl (map first bprs) | |
bsss (set bssl) | |
bexs (map second bprs) | |
arrm (zipmap bssl (range bcnt)) | |
btes (map #(walk/prewalk (fn [f] |
This file contains 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
-- growl notifications for ichat, based on | |
-- http://scriptingosx.com/2010/11/ichat-notification-with-growl/ | |
property growlAppName : "Growl iChat" | |
property notificationNames : {"Buddy Became Available", ¬ | |
"Buddy Became Unavailable", ¬ | |
"Message Received", ¬ | |
"Completed File Transfer"} | |
property defaultNotificationNames : {"Buddy Became Available", ¬ |
This file contains 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 com.sun.btrace.annotations.*; | |
import static com.sun.btrace.BTraceUtils.*; | |
@BTrace | |
public class TraceSystemGCCall { | |
@OnMethod( | |
clazz="/.*/", | |
method="/.*/", | |
location=@Location( | |
value=Kind.CALL, |
This file contains 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 monads | |
(:require clojure.set)) | |
(declare ^:dynamic return | |
^:dynamic bind) | |
(defn lift-inc [v] | |
(return (inc v))) | |
(defn m-add [mv n] |
This file contains 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 ignacio.tfidf (:require [clojure.contrib.string :as string])) ;; Simple tfidf in clojure, for fun. | |
(def stopwords (set (string/split #"\n" (slurp "./stopwords.txt")))) | |
(defn tokenize [raw-text] ;; Lowercases and splits on non-letters, non-numbers. | |
(remove stopwords (string/split #"[^a-z0-9äöüáéíóúãâêîôûàèìòùçñ]+" (string/lower-case raw-text)))) | |
(defn idf2 [n-docs match] (Math/pow (Math/log (/ n-docs (count (keys match)))) 2)) | |
(defn index-one [fname] ;; Index for one file. Given an fname, returns a map of token -> map of (fname, count) |
This file contains 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 postfix [& e] | |
(reduce #(if (fn? %2) | |
(let [[l r & m] %] | |
(cons (%2 r l) m)) | |
(cons %2 %)) [] e)) |
This file contains 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
# Script used to quickly get a glance of how many queries since a certain time period were longer than X seconds | |
# Customize these 2 parameters | |
STARTDATE="120413" # 2 Digit Year, 2 Digit Month, 2 Digit Day | |
QUERYTIME=3.0 | |
# Runs the commands and prints out Query_time lines | |
FIRST=`grep -n -m 1 "# Time: $STARTDATE" /var/log/mysql-slow.log | cut -d : -f 1`; TOTAL=`wc -l /var/log/mysql-slow.log | cut -d ' ' -f 1`; tail -n `echo "$TOTAL-$FIRST" | bc` /var/log/mysql-slow.log | grep Query_time | awk -v time="$QUERYTIME" '$3 > time {print; }' |
This file contains 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 example.errors) | |
(defn clean-address [params] | |
"Ensure (params :address) is present" | |
(if (empty? (params :address)) | |
[nil "Please enter your address"] | |
[params nil])) | |
(defn clean-email [params] | |
"Ensure (params :email) matches *@*.*" |
This file contains 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
(deftheme bubbleberry "bubbleberry") | |
;; Based on the theme used for LightTable (see: http://www.chris-granger.com/images/lightable/main.png ) | |
(custom-theme-set-variables | |
'bubbleberry | |
'(linum-format " %7i ") | |
'(fringe-mode 5 nil (fringe)) | |
'(powerline-color1 "#3d3d68") | |
'(powerline-color2 "#292945") |
This file contains 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
;(use '[clojure.tools.macro :only [symbol-macrolet]]) | |
(defmacro letrec | |
"Like let, but the bindings may be mutually recursive, provided that | |
the heads of all values can be evaluated independently. | |
This means that functions, lazy sequences, delays and the like can | |
refer to other bindings regardless of the order in which they | |
appear in the letrec form." | |
[bindings & body] |
OlderNewer