Skip to content

Instantly share code, notes, and snippets.

View ikitommi's full-sized avatar
💭

Tommi Reiman ikitommi

💭
View GitHub Profile
@ikitommi
ikitommi / gist:5378805
Created April 13, 2013 15:19
Filtering nested maps in Clojure
;; here only data used in filtering.
(def docs [{:schema {:info {:name "party"}}}
{:schema {:info {:name "bonus"}}}
{:schema {:info {:name "party"}}}])
;; anonymous function with get-in (72)
(filter (fn [doc] (= "party" (get-in doc [:schema :info :name]))) docs)
;; anonymous function & threading (66)
(filter (fn [doc] (-> doc :schema :info :name (= "party"))) docs)
(ns tron.kekkonen)
(defn addv [a b] (mapv + a b))
(defn turn-left [[dx dy]] [dy (- dx)])
(defn turn-right [[dx dy]] [(- dy) dx])
(defn left? [old-dir new-dir] (= (turn-right new-dir) old-dir))
(defn president
[turn & [primary-goal :as original-goals]]
(fn [look {:keys [pos dir goals] :or {dir (or primary-goal [0 1])
@ikitommi
ikitommi / profiles.clj
Last active December 24, 2015 02:29
Setting Leiningen to work with Idea & Eclipse. profiles.clj go to ~/.lein
{:user {:plugins [[lein2-eclipse "2.0.0"]
[lein-idea "1.0.1"]]}}
@ikitommi
ikitommi / Domain.scala
Created November 17, 2013 18:45
PersonBuilder in Scala
package domain
case class Person(id: Option[Long] = None, email: Option[String] = None, firstName: String, lastName: String)
@ikitommi
ikitommi / keywordize.clj
Created November 28, 2013 05:42
keywordize-keys on ring request
(require '[clojure.walk :as walk])
(defn keywordize-request
[handler]
(fn [request]
(handler
(walk/keywordize-keys request))))
@ikitommi
ikitommi / option1.clj
Created January 3, 2014 08:57
Swagger-metadata options
; option1: Liberator-like
(GET "/pizzas" []
:return [Pizza]
:summary "Gets all Pizzas"
:notes "'nuff said."
:nickname "getPizzas"
(response (get-pizzas)))
;; play with the latest
lein try metosin/ring-swagger
; nREPL server started on port 63138 on host 127.0.0.1
; REPL-y 0.3.0
; Clojure 1.5.1
; Docs: (doc function-name-here)
; (find-doc "part-of-name-here")
; Source: (source function-name-here)
; Javadoc: (javadoc java-object-or-class-here)
@ikitommi
ikitommi / repl.clj
Created April 7, 2014 05:40
peek into a GET*
lein repl
;; nREPL server started on port 50058 on host 127.0.0.1
;; REPL-y 0.3.0
;; Clojure 1.5.1
;; Docs: (doc function-name-here)
;; (find-doc "part-of-name-here")
;; Source: (source function-name-here)
;; Javadoc: (javadoc java-object-or-class-here)
;; Exit: Control+D or (exit) or (quit)
;; Results: Stored in vars *1, *2, *3, an exception in *e
@ikitommi
ikitommi / repl.clj
Created May 15, 2014 12:49
Stripping invalid keys from a form based on a Schema
(require '[schema.core :as s])
(require '[plumbing.core :refer :all])
(defn path-vals
"Returns vector of tuples containing path vector to the value and the value."
[m]
(letfn
[(pvals [l p m]
(reduce
(fn [l [k v]]
@ikitommi
ikitommi / repl.clj
Created May 27, 2014 12:37
LocalDate coercion
lein try metosin/ring-swagger
;nREPL server started on port 62925 on host 127.0.0.1
;REPL-y 0.3.0
;Clojure 1.5.1
user=> (require '[ring.swagger.schema :refer :all])
nil
user=> (defmodel Neiti {:aika org.joda.time.LocalDate})