Skip to content

Instantly share code, notes, and snippets.

View dbushenko's full-sized avatar

Dmitry Bushenko dbushenko

  • USA
View GitHub Profile
(defmacro defaction [name & params-with-body]
(let [params-vector (first params-with-body)
params-hash (apply hash-map (flatten (map (fn [p] [p (symbol (str ":" p))]) params-vector)))
body (next params-with-body)
session (symbol "session")]
`(defn ~name [{~params-hash :params, ~session :session}]
~@body)))
@dbushenko
dbushenko / gist:1059125
Created July 1, 2011 18:25
my minor mode
(global-unset-key (kbd "C-c l"))
(global-set-key (kbd "C-c l") 'toggle-truncate-lines)
(set-face-attribute
'default (selected-frame) :font
"Consolas 12")
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)
(defroutes main-routes
(GET "/request" request (str request))
(GET "/my" request "<html><body>Привет, Мир!</body></html>")
(route/resources "/")
(route/not-found "Page not found"))
(defn wrap-codepage [handler]
(fn [request]
(handler (assoc-in request [:headers :content-type] "text/html; charset=utf-8"))))
(ns webtest.core
(:require [pl.danieljanus.tagsoup :as ts]
[hiccup.core :as h]
[clojure.contrib.duck-streams :as io]))
(def data (slurp "data/data.html"))
(def parsed (ts/parse-string data))
(def generated (h/html parsed))
(io/spit "data/output.html" generated)
(ns storm-test.core
(:import [backtype.storm StormSubmitter LocalCluster])
(:use [backtype.storm clojure config])
(:gen-class))
(defspout dummy-spout ["data"]
[collector]
(let [data [2 4 8 16 32 64 128 256 512 1024 4096]]
(dorun (map #(do
(println (str "Spout: " %))
(ns storm-test.core
(:import [backtype.storm StormSubmitter LocalCluster])
(:use [backtype.storm clojure config])
(:gen-class))
(defspout dummy-spout ["data"]
[conf context collector]
(let [data [2 4 8 16 32 64 128 256 512 1024 4096]]
(dorun (map #(do
(println (str "Spout: " %))
(def *data* [2 4 8 16 32 64 128 256 512 1024 4096 2 4 8 16 32 64 128 256 512 1024 4096])
(defspout number-spout ["number"]
[conf context collector]
(spout
(nextTuple []
(Thread/sleep 100)
(emit-spout! collector [(next *data*)]))
(ack [id])))
(defun my-copy ()
(interactive)
(search-backward " ")
(setq st (point))
(forward-char 1)
(search-forward " ")
(setq nd (point))
(setq txt (buffer-substring st nd))
(message text))
(ns ptest.core
(:require [the.parsatron :as p]))
(p/defparser op []
(p/choice (p/char \+)
(p/char \-)
(p/char \*)
(p/char \/)))
(p/defparser number []
(ns ptest.core
(:require [the.parsatron :as p]))
(p/defparser op []
(p/choice (p/char \+)
(p/char \-)))
(p/defparser number []
(p/let->> [d (p/many (p/digit))]
(p/always (reduce str d))))