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
;; this file is a walkthrough of Moustache features, a web framework for Clojure | |
;; http://github.com/cgrand/moustache/tree/master | |
;; Moustache allows to declare routes, apply middlewares and dispatch on http methods. | |
;; Moustache is compatible with all frameworks built on Ring, including Compojure | |
(ns demo | |
(:use net.cgrand.moustache) | |
(:use [ring.adapter.jetty :only [run-jetty]])) ;; hmmm Ring without servlets | |
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
; A Field Guide to | |
; Genetic Programming | |
; http://www.lulu.com/items/volume_63/2167000/2167025/2/print/book.pdf | |
(defn f2-1 | |
"Figure 2.1 max(x+x, x+3*y)" | |
[x y] | |
(max (+ x x) | |
(+ x | |
(* 3 y)))) |
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
#!/bin/zsh | |
# Dynamically build the $PATH variable | |
for dircomponent in $path /sw/bin /sw/sbin /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin /compat/linux/bin /compat/linux/sbin /compat/linux/usr/bin /compat/linux/usr/sbin /usr/games /usr/X11R6/bin /usr/X11R6/sbin ~/bin ~/crossover/bin | |
do | |
if [[ -e $dircomponent ]]; then | |
path=($path $dircomponent) | |
fi | |
done | |
typeset -U path |
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
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
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
_lein_test() | |
{ | |
local curw | |
COMPREPLY=() | |
curw=${COMP_WORDS[COMP_CWORD]} | |
if [ -d test ]; then | |
COMPREPLY=($(compgen -W '$(cd test; find * -name \*.clj | sed "s/.clj\$//" | sed "s/_/-/g" | sed "s|/|.|g")' -- $curw)); | |
return 0 | |
fi | |
} |
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
; Released under the Apache License, Version 2.0 | |
; http://www.apache.org/licenses/LICENSE-2.0.html | |
(defmacro try-let | |
"A combination of try and let such that exceptions thrown in the binding or | |
body can be handled by catch clauses in the body, and all bindings are | |
available to the catch and finally clauses. If an exception is thrown while | |
evaluating a binding value, it and all subsequent binding values will be nil. | |
Example: |
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
;;; Future pipelining macro. | |
;;; Behaves like a let, but wraps everything in futures - running your bindings concurrently | |
;;; Computation takes only as long as the longest-running bind | |
(ns user | |
(:use clojure.walk clojure.test)) | |
(defn cols | |
"Projection of n columns from coll" | |
[n coll] |
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
;;; all code in this function lifted from the clojure-mode function | |
;;; from clojure-mode.el | |
(defun clojure-font-lock-setup () | |
(interactive) | |
(set (make-local-variable 'lisp-indent-function) | |
'clojure-indent-function) | |
(set (make-local-variable 'lisp-doc-string-elt-property) | |
'clojure-doc-string-elt) | |
(set (make-local-variable 'font-lock-multiline) t) |
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
;;; All Kinds of Destructuring ;;; | |
(let [foo 1] foo) | |
; => 1 | |
(let [[foo bar] [1 2 3]] [foo bar]) | |
; => [1 2] | |
(let [[foo bar & baz] [1 2 3]] [foo bar baz]) | |
; => [1 2 (3)] |
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
;; stolen from http://cemerick.com/2010/08/02/defrecord-slot-defaults/ | |
(defmacro defrecord+defaults | |
"Defines a new record, along with a new-RecordName factory function that | |
returns an instance of the record initialized with the default values | |
provided as part of the record's slot declarations. e.g. | |
(defrecord+ Foo [a 5 b \"hi\"]) | |
(new-Foo) | |
=> #user.Foo{:a 5, :b \"hi\"}" | |
[name slots & etc] |
OlderNewer