Skip to content

Instantly share code, notes, and snippets.

@alexanderjamesking
alexanderjamesking / pure-function.clj
Last active April 28, 2018 10:06
Testing in Clojure
(require '[clojure.test :refer [is]])
(defn pure-adder [x y]
(+ x y))
(is (= 3 (pure-adder 1 2)))
docker exec -it cwservice /bin/sh
(ns batchreq.core
(:refer-clojure :exclude [map reduce into partition partition-by take merge])
(:require [clojure.core.async :refer :all :as async]
[clj-http.client :as client])
(:use taoensso.timbre
taoensso.timbre.profiling))
(defnp http-get [id]
(client/get (format "http://fssnip.net/%d" id))
id)
(ns transform
(:require [clojure.xml :refer [parse]]
[clojure.zip :refer [xml-zip node up]]
[clojure.data.zip.xml :refer [xml-> xml1-> text attr attr=]]
[clojure.data.json :refer [write-str]]))
(defn- team-name [event alignment]
(xml1-> event :team :team-metadata (attr= :alignment alignment) :name (attr :first)))
(defn- sports-event [event]
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 / 00_destructuring.md
Created March 20, 2017 10:44 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

@alexanderjamesking
alexanderjamesking / hash.rb
Created February 2, 2017 09:23
Ruby - Array of hashes to keyed hash
students = [
{ name: "Bob", cohort: "Nov"},
{ name: "Barry", cohort: "Nov"},
{ name: "Anna", cohort: "Dec"},
{ name: "Igor", cohort: "Dec"},
{ name: "Natalia", cohort: "Feb"}
]
my_hash = {}
@alexanderjamesking
alexanderjamesking / functional-ruby.rb
Created February 2, 2017 09:01
Functional Ruby - using map to create a new array from an existing array
# Looping through an array to form a new array
# non functional (imperative) way
my_array = [1,2,3,4,5]
new_array = [] # requires us to create a structure then modify it using push
my_array.each { | element |
new_array.push("number " + element.to_s)
}
killall ssh-agent gpg-agent
unset GPG_AGENT_INFO SSH_AGENT_PID SSH_AUTH_SOCK
eval $(gpg-agent --daemon --enable-ssh-support)
@alexanderjamesking
alexanderjamesking / docker.sh
Created September 1, 2016 11:56
Docker SQL
Docker MySQL
docker run -p 3306:3306 --name local-mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
mysql -h $(docker-machine ip) -uroot -ppassword