Skip to content

Instantly share code, notes, and snippets.

@neotyk
neotyk / gist:2652261
Created May 10, 2012 10:06
counting parts and collecting body
(let [counter (atom 0)]
(http-r/execute-request
c (http-r/prepare-request :get "http://www.nu.nl/")
:part (fn [resp part]
(swap! counter inc)
(println @counter)
(http-r/body-collect resp part))
:completed (fn [resp]
(println (count (http/string resp)))
(println :parts @counter))))
@neotyk
neotyk / countbodyparts.clj
Created May 10, 2012 09:14
http.async.client callback counting body parts
;; counting body parts
(http-r/execute-request
c (http-r/prepare-request :get "http://localhost:8080/json")
:part (fn [resp part]
(let [counter (if (realized? (:body resp)) (:body resp) (atom 0))]
(swap! counter inc)
(println :p part)
[counter :continue]))
:completed (fn [resp]
(println :d @@(:body resp);atom within a promise
@neotyk
neotyk / Vagrantfile
Created April 20, 2012 11:50 — forked from skuro/Vagrantfile
Vagrant baby steps
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.provision :puppet, :options => "--verbose --debug"
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "default.pp"
@neotyk
neotyk / l1.clj
Created March 27, 2012 21:06
right? and righto
(ns l1
(:use [clojure.core.logic
:only [fresh conde firsto resto run]]))
(defn right?
[a b l]
(or (and (== a (first l))
(== b (second l)))
(when-let [t (next l)]
(recur a b t))))
@neotyk
neotyk / site.pp
Created January 16, 2012 16:13
Puppet mysql
node 'agent1' {
class { 'mysql::server': config_hash => { 'root_password' => 'bar' } }
mysql::db { 'sampledb':
user => 'sampleuser',
password => 'letmein',
host => 'localhost',
grant => ['all'],
}
}
@neotyk
neotyk / stunnr.core.clj
Created October 6, 2011 09:51 — forked from skuro/stunnr.core.clj
stunnr.core.clj
(ns stunnr.core
(:require [http.async.client :as c]
[http.async.client.request :as r]))
(def results (atom []))
(def requests (atom []))
(def client (c/create-client))
(defmacro json-flash [method path params body]
(let [flash# (gensym "flash")
params# (assoc params flash# :flash)]
`(~method ~path ~params#
(let [r# (do ~@body)
r# (if-not (empty? ~flash#)
(assoc r# :flash ~flash#)
r#)]
(-> r#
json/encode-to-str
@neotyk
neotyk / gist:1202938
Created September 8, 2011 08:38
Logging using wrong *ns*
user=> (use 'clojure.tools.logging)
nil
user=> (info "abc")
Sep 8, 2011 10:37:34 AM clojure.tools.logging$eval319$fn__320 invoke
INFO: abc
nil
@neotyk
neotyk / twitter-sample.clj
Created July 18, 2011 18:23
twitter sample
(ns twitter-sample
(:require [http.async.client :as c]
[org.danlarkin.json :as j]))
(def u "username")
(def p "password")
(defn print-user-and-text [prefix s]
(let [twit (j/decode-from-str s)
user (:screen_name (:user twit))
@neotyk
neotyk / explicit_client.clj
Created June 17, 2011 15:26
http.async.client v0.3.0
(ns explicit-client
(:require [http.async.client :as http]))
(with-open [client (http/create-client)]
(let [response (http/GET client "http://clojure.org")]
(println "status" (:code (http/status response)))
(println "body" (-> http/await http/string))))