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
;; Examples from: http://www.databasteknik.se/webbkursen/relalg-lecture/index.html | |
(def employees (table connection-info :employees)) | |
(def departments (table connection-info :departments)) | |
;;== Projection == | |
;; SELECT salary FROM employees | |
@(project employees #{:salary}) |
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
clojureql.core> (project (table :t1) | |
[:id (case :wages | |
(<= :wage 5) "low" | |
(>= :wage 10) "high" | |
:else "average")]) | |
SELECT t1.id,CASE | |
WHEN (wage <= 5) THEN low | |
WHEN (wage >= 10) THEN high | |
ELSE average | |
END AS wages |
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
clojureql.core> (let [photo-counts (table {} :photos [:user_id [:count:* :as :cnt]])] | |
(-> (table {} :users [:*]) | |
(join photo-counts (= {:users.user_id :photos.user_id})) | |
compile)) | |
"SELECT users.*,photos_aggregation.cnt FROM users | |
LEFT OUTER JOIN | |
(SELECT photos.user_id,count(photos.*) AS cnt FROM photos GROUP BY user_id) | |
AS photos_aggregation ON (users.user_id = photos_aggregation.user_id)" |
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
(-> (join [:employees :e] [:employees :b] {:e.mgr :b.nr}) | |
(select (= :b.name "John")) | |
(project :b.name)) |
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
Server Software: aleph | |
Server Hostname: localhost | |
Server Port: 9292 | |
Document Path: / | |
Document Length: 6 bytes | |
Concurrency Level: 50 | |
Time taken for tests: 9.565 seconds | |
Complete requests: 10000 |
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
;;; See the inspirational SO question: http://stackoverflow.com/questions/3346382 | |
(require 'clojure.contrib.trace) | |
(defn trace-ns | |
"Replaces each function from the given namespace with a version wrapped | |
in a tracing call. Can be undone with untrace-ns. ns should be a namespace | |
object or a symbol." | |
[ns] | |
(doseq [s (keys (ns-interns ns)) |
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 with-timeout [thunk] | |
(let [task (FutureTask. thunk) | |
thr (Thread. task)] | |
(try | |
(.start thr) | |
(.get task 10 TimeUnit/SECONDS) | |
(catch TimeoutException e | |
(.cancel task true) | |
(.stop thr (Exception. e)) | |
nil)))) |
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
;new num branch results | |
(defn fib [n] | |
(if (>= 1 n) | |
1 | |
(+ (fib (dec n)) (fib (- n 2))))) | |
(time (fib 38)) | |
"Elapsed time: 3716.828 msecs" |
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
git bisect start | |
# good: [59b65669860a1f33825775494809e5d500c19c63] added 1.0, test all public doc-ed fns have :added | |
git bisect good 59b65669860a1f33825775494809e5d500c19c63 | |
# bad: [d694d6d45fb46195ae4de01aab9a2b9f9c06355f] place to hang defn error messages | |
git bisect bad d694d6d45fb46195ae4de01aab9a2b9f9c06355f | |
# bad: [4f729ba2432d8ffbe7c2f74f680b472e528cba4c] Merge branch 'patches' | |
git bisect bad 4f729ba2432d8ffbe7c2f74f680b472e528cba4c | |
# good: [40f3dc93b926721e94b75a10a9c88815ea4691aa] clojure.repl with -fn naming, #310 | |
git bisect good 40f3dc93b926721e94b75a10a9c88815ea4691aa | |
# good: [3b07c0e98ebfd7025a5e36c7e47f6562e4750e14] Merge branch 'patches' |
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 bestinclass.io | |
(:use compojure) | |
(:import | |
(java.io File) | |
(org.apache.commons.fileupload.servlet ServletFileUpload) | |
(org.apache.commons.fileupload.disk DiskFileItemFactory))) | |
(def *max_size* (* 30 1024 1024)) ; 30 Megabytes | |
(defn upload-file |
NewerOlder