Skip to content

Instantly share code, notes, and snippets.

(ns clj-arrows.core)
;; Take a look at -> http://www.haskell.org/haskellwiki/Arrow_tutorial
(defn def-arrow [& opts]
(let [opts-map (apply hash-map opts)]
{:arr (:arr opts-map)
:first (:first opts-map)
:second (:second opts-map)}))
#!/bin/sh
# change paths according to your repl setup
USER_HOME="/Users/antonio.garrote"
CLJR_HOME="/Users/antonio.garrote/.cljr"
CLASSPATH=src:test:.
if [ ! -n "$JVM_OPTS" ]; then
JVM_OPTS="-Xmx1G"
fi
(add-hook 'clj-mode-hook '(lambda () (linum-mode 1)))
(add-hook 'clojure-mode-hook '(lambda () (linum-mode 1)))
;; full screen
(defun fullscreen (&optional f)
(interactive)
(set-frame-parameter f 'fullscreen
(if (frame-parameter f 'fullscreen) nil 'fullboth)))
(global-set-key [f11] 'fullscreen)
(add-hook 'after-make-frame-functions 'fullscreen)
@antoniogarrote
antoniogarrote / gist:631202
Created October 17, 2010 19:54
Jobim server
;; Server protocol
(defprotocol Server
(init [this initial-value] "Invoked when the server starts execution")
(handle-call [this request from state] "Invoked when a new synchronous request arrives at the server")
(handle-cast [this request state] "Invoked when a new asynchronous request arrives at the server")
(handle-info [this request state] "Handles messages distinct to events")
(terminate [this state] "Clean up code invoked when the server is going to be terminated externally"))
(time
(let [*pdfs-proms* (map (fn [[pdf id]] [pdf id (promise)]) *pdfs*)]
(doseq [[pdf id prom] *pdfs-proms*]
(future
(do
(spit (str id ".pdf") (slurp (java.net.URL. pdf)))
(deliver prom :ok))))
(doseq [[_ _ prom] *pdfs-proms*]
(def *reg-nos* [16738 17288 18162 18776 18868 19116 19223 19505])
(def *df-url* "http://www.mapa.es/agricultura/pags/fitos/registro/sustancias/pdf/")
(def *pdfs* (map #(list (str *df-url* % ".pdf") %) *reg-nos*))
(time
(doseq [[pdf id] *pdfs*]
(spit (str id ".pdf") (slurp (java.net.URL. pdf)))))
;; Elapsed time 667.91 msecs
;;; Example from 'Applicative Programming with Effects' by McBride & Paterson
(use 'clj-control.applicative)
(use 'clj-control.core)
(use 'clj-control.utils)
(defn transpose
([matrix]
(if (empty? matrix)
(repeat '())
(defun mustang ()
(interactive)
(color-theme-install
'(mustang
((background-color . "#202020")
(background-mode . dark)
(cursor-color . "#bdbdbd")
(mouse-color . "sienna1")
(foreground-color . "#bdbdbd"))
(default ((t (:background "#202020"))))
@antoniogarrote
antoniogarrote / gist:794701
Created January 25, 2011 09:20
energy plan
+----------------------+
+-----------------------+ | |
| | | Tier 1 Rate disc |
| Rate (nil,500) +------------------------------------------------->+ |
| | | |
+----------+------------+ +-----------+----------+
|