Skip to content

Instantly share code, notes, and snippets.

(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 / 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))
@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 / 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 / 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 / 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 / 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 / test_compare.js
Created May 16, 2012 22:48
cljs compare with special case for numbers, 100000 data size
function e(a){throw a;}var f=void 0,k=!0,l=null,m=!1;function aa(){return function(a){return a}}function n(a){return function(){return this[a]}}function o(a){return function(){return a}}var p;
function r(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";
else if("function"==b&&"undefined"==typeof a.call)return"object";return b}function s(a){return a!==f}function ba(a){return"string"==typeof a}function ca(a){return"number"==typeof a}function da(a){return a[ea]||(a[ea]=++fa)}var ea="closure_uid_"+Math.floor(2147483648*Math.random()).toString(36)
@neotyk
neotyk / test_compare.js
Created May 17, 2012 19:32
cljs compare, 1000 data size
function e(a){throw a;}var f=void 0,k=!0,l=null,m=!1;function aa(){return function(a){return a}}function n(a){return function(){return this[a]}}function o(a){return function(){return a}}var p;
function r(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";
else if("function"==b&&"undefined"==typeof a.call)return"object";return b}function s(a){return a!==f}function ba(a){return"string"==typeof a}function ca(a){return"number"==typeof a}function da(a){return a[ea]||(a[ea]=++fa)}var ea="closure_uid_"+Math.floor(2147483648*Math.random()).toString(36)
@neotyk
neotyk / web-socket-sample.clj
Created May 21, 2012 09:18
WebSocket with http.async.client sample
(require '[http.async.client :as http])
;; create clients
(def client (http/create-client))
;; websocket
(let [latch (promise)
ws (http/websocket
client "ws://localhost:8108/socket"
;; text message callback