Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diogok/clj-diogok-sandbox
My Clojure sandbox/utils namespaces and scripts on file, io, http and etcetera.
https://github.com/diogok/clj-diogok-sandbox
Last synced: about 2 months ago
JSON representation
My Clojure sandbox/utils namespaces and scripts on file, io, http and etcetera.
- Host: GitHub
- URL: https://github.com/diogok/clj-diogok-sandbox
- Owner: diogok
- Created: 2010-05-19T01:48:24.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-09-16T03:57:25.000Z (over 14 years ago)
- Last Synced: 2023-04-13T15:11:42.592Z (over 1 year ago)
- Language: Clojure
- Homepage:
- Size: 109 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
# clj-utils
This is my clojure scripts and namespaces utils and sandbox. Includes utilities for:
- http-get a resource
- Serialization/unserialization of objetcs
- Serialization/unserialization of objetcs to/from file
- md5sum (for hashing)
- file creation (return a file and create it and its parents dirs if needed)
- read only part of a file
- Key/Value tuple in file storage (fragile)
- Key/Value tuple in file storage2 (single file, append-only, little better)
- couchdb testing## Usage
HTTP:
(let [response (http-get "http://github.com")]
(if (= (:response-code response) 200)
(println (:content response))
))
; contains :url :header :response-code :response-message and :contentSERIALIZATION:
(let [obj {:name "Diogok" :value ["[email protected]" "[email protected]"]}]
(def serial (serialize obj))
(= obj (unserialize serial));true
(let [file (str (md5 (:name obj)) ".txt")]
(save-to-file obj file)
(= (load-from-file file) obj);true
)
)STORAGE (and storage2):
(let [db (bucket "foo/bar")]
(put! db "diogok" {:name "Diogo Souza da Silva" :github "http://github.com/diogok"})
(let [obj (tuple "foo" "bar")]
(put! db obj)
(= obj (get! db "foo")); true
)
)COUCHDB
(require [clj-diogok-sandbox.couchdb :as couch])
(def server (couch/server "localhost" 5984))
(def db (couch/db server "testdb"))
(couch/put db {:_id "foo" :foo "bar"})
(couch/get db "foo") ;; {:_id "foo" :_rev "..." ...}
(couch/put db {:docs [{:foo "bar"},{:foo "foobar"}]}) ;; bulk insert
(def myview (couch/view db "my-design-doc" "my-view-name"))
(couch/query myview)
(couch/query myview "key")