This file contains hidden or 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 clj-play.aleph | |
(:use aleph)) | |
(defn hello-world [request] | |
(respond! request | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body "Hello Clojure!"})) | |
(run-aleph hello-world {:port 8080}) |
This file contains hidden or 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
var sys = require('sys'), | |
http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.end('Hello Node!'); | |
}).listen(8080, "127.0.0.1"); | |
sys.puts('Server running at http://127.0.0.1:8080/'); |
This file contains hidden or 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 save-to-db [request] | |
(future | |
(create! mydb foo {:bar "baz"}) | |
(respond! request | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body "Saved!"}))) |
This file contains hidden or 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 second-post.mysql | |
(:use aleph) | |
(:require [clojure.contrib.sql :as sql])) | |
(def db {:classname "com.mysql.jdbc.Driver" | |
:subprotocol "mysql" | |
:subname "//localhost:3306/dummy" | |
:user "root" | |
:password ""}) |
This file contains hidden or 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 second-post.mongo | |
(:use aleph) | |
(:use karras.core | |
karras.collection | |
karras.sugar)) | |
(def dummy (collection (connect) :dummy :foo)) | |
(defn my-save [request] | |
(future |
This file contains hidden or 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 second-post.postgres | |
(:use aleph) | |
(:require [clojure.contrib.sql :as sql])) | |
(def db {:classname "org.postgresql.Driver" | |
:subprotocol "postgresql" | |
:subname "dummy" | |
:user "postgres"}) | |
(defn insert-foo [val] |
This file contains hidden or 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 second-post.memory | |
(:use aleph)) | |
(def db (atom [])) | |
(defn save [request] | |
(future | |
(swap! db conj {:bar "test"}) | |
(respond! request | |
{:status 200 |
This file contains hidden or 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 second-post.couchdb | |
(:use aleph | |
[clojure.contrib.json :only [read-json json-str]]) | |
(:require [com.twinql.clojure.http :as http]) | |
(:import [org.apache.http HttpEntity] | |
[org.apache.http.entity StringEntity])) | |
(defn ^HttpEntity json->entity [json] | |
(StringEntity. (json-str json))) |
This file contains hidden or 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 third-post.core | |
(:require [com.twinql.clojure.http :as http])) | |
(defn ping [] | |
(-> (http/get "http://localhost:5123" :as :string) :content)) | |
(defn multi-ping [] | |
(->> (repeatedly 16 #(ping)) | |
(apply str))) |
This file contains hidden or 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 third-post.server | |
(:use aleph)) | |
(defn pong [request] | |
(respond! request | |
{:status 200 | |
:headers {"Content-Type" "text/plain"} | |
:body "pong"})) | |
(run-aleph pong {:port 5123}) |