Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
(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})
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/');
(defn save-to-db [request]
(future
(create! mydb foo {:bar "baz"})
(respond! request
{:status 200
:headers {"Content-Type" "text/html"}
:body "Saved!"})))
(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 ""})
(ns second-post.mongo
(:use aleph)
(:use karras.core
karras.collection
karras.sugar))
(def dummy (collection (connect) :dummy :foo))
(defn my-save [request]
(future
(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]
(ns second-post.memory
(:use aleph))
(def db (atom []))
(defn save [request]
(future
(swap! db conj {:bar "test"})
(respond! request
{:status 200
(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)))
(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)))
(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})