Skip to content

Instantly share code, notes, and snippets.

; to be run in lein repl
(require 'langohr.core)
(require '[langohr.queue :as lq])
(require '[langohr.basic :as lb])
(require '[langohr.consumers :as lc])
; langohr.core/*default-config*
; default port is 5672 - running on 5004 as it is forwarded to rabbitmq on docker
(def conn (langohr.core/connect {:hostname "localhost" :port 5004}))
@alexanderjamesking
alexanderjamesking / 1-transform.java
Last active August 29, 2015 14:02
Clojure from Java - transform XML to Map to JSON
package com.ajk;
import clojure.lang.IFn;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import static clojure.java.api.Clojure.read;
import static clojure.lang.RT.loadResourceScript;
import static clojure.lang.RT.var;
@alexanderjamesking
alexanderjamesking / 1-tests.clj
Created June 24, 2014 06:57
Clojure - sync and async http requests profiled
(ns batchreq.t-core
(:use midje.sweet)
(:use [batchreq.core]))
(facts "load some snippets"
(fact "all returned in parallel"
(count (request-snippets in-parallel)) => 20)
(fact "all returned sequentially"
@alexanderjamesking
alexanderjamesking / 1-publish.js
Last active March 26, 2017 09:13
Node AWS - SNS and SQS
// publish a message to an SNS topic
var AWS = require('aws-sdk');
AWS.config.loadFromPath('./config.json');
var sns = new AWS.SNS();
var params = {
TopicArn : "arn:your-topic-arn",
Message: "Hello World"
};
@alexanderjamesking
alexanderjamesking / docker-mysql.sh
Created April 4, 2015 11:45
MySQL docker container for local development
echo "Cleaning up existing mysql container"
echo "Stopping mysql container..."
docker stop mysql
echo "Removing mysql container..."
docker rm mysql
echo "Starting mysql container..."
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:5.6
@alexanderjamesking
alexanderjamesking / wiremock.clj
Created April 8, 2015 12:46
Hello World Wiremock Clojure
(import com.github.tomakehurst.wiremock.WireMockServer)
(import com.github.tomakehurst.wiremock.core.WireMockConfiguration)
(def wiremock-config (.port (new WireMockConfiguration) 11111))
(def wiremock-server (new com.github.tomakehurst.wiremock.WireMockServer wiremock-config))
(.start wiremock-server)
(.stop wiremock-server)
Useful Wiremock Calls
# View all stubbed enpoints (GET)
http://localhost:11111/__admin/
# View all requests to WM (POST)
http://localhost:11111/__admin/requests/find
body:
{
@alexanderjamesking
alexanderjamesking / gist:1ce56a45d720c39709b8
Last active August 29, 2015 14:25
numbers test - first attempt
; start a repl (lein repl) then paste in the following:
(defn calculate-all [input]
(defn calculate-item [idx item]
(let [split (split-at idx input)
actual-before (set (first split))
needed-before (set (range 1 item))]
(clojure.set/superset? actual-before needed-before)))
(map-indexed calculate-item input))
@alexanderjamesking
alexanderjamesking / gist:1bda7e34dd0cbb50838c
Created July 19, 2015 11:58
numbers - weighted quick union
; attempt 4 - using weighted quick union, always puts the smaller tree under the bigger tree to reduce depth
(def nodes (atom {}))
(def sizes (atom {}))
(defn find-root [i]
(let [v (get @nodes i)]
(loop [i v]
(if (= i v)
v
#
# Oracle Java 8 Dockerfile
#
# https://github.com/dockerfile/java
# https://github.com/dockerfile/java/tree/master/oracle-java8
#
# Pull base image.
FROM ubuntu:15.04