Skip to content

Instantly share code, notes, and snippets.

@kouphax
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kouphax/c98cda8f32ee873d2ab1 to your computer and use it in GitHub Desktop.
Save kouphax/c98cda8f32ee873d2ab1 to your computer and use it in GitHub Desktop.
(ns card-shop.core
(:require [liberator.core :refer [resource defresource]]
[liberator.dev :refer [wrap-trace]]
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
[ring.middleware.params :refer [wrap-params]]
[ring.adapter.jetty :refer [run-jetty]]
[compojure.core :refer [defroutes GET]]))
(defrecord Paint [id title code quantity])
(def db
[(Paint. "aliceblue" "Alice Blue" "#F0F8FF" 4)
(Paint. "antiquewhite" "Antique White" "#FAEBD7" 0)
(Paint. "aqua" "Aqua" "#00FFFF" 50)
(Paint. "aquamarine" "Aquamarine" "#7FFFD4" 18)
(Paint. "azure" "Azure" "#F0FFFF" 6)
(Paint. "beige" "Beige" "#F5F5DC" 9)
(Paint. "bisque" "Bisque" "#FFE4C4" 4)
(Paint. "black" "Black" "#000000" 5)
(Paint. "blanchedalmond" "Blanched Almond" "#FFEBCD" 0)
(Paint. "blue" "Blue" "#0000FF" 7)
(Paint. "blueviolet" "Blue Violet" "#8A2BE2" 7)
(Paint. "brown" "Brown" "#A52A2A" 4)
(Paint. "burlywood" "Burly Wood" "#DEB887" 7)
(Paint. "cadetblue" "Cadet Blue" "#5F9EA0" 3)
(Paint. "chartreuse" "Chartreuse" "#7FFF00" 9)
(Paint. "chocolate" "Chocolate" "#D2691E" 4)
(Paint. "coral" "Coral" "#FF7F50" 7)
(Paint. "cornflowerblue" "Cornflower Blue" "#6495ED" 3)
(Paint. "cornsilk" "Cornsilk" "#FFF8DC" 2)
(Paint. "crimson" "Crimson" "#DC143C" 3)
(Paint. "cyan" "Cyan" "#00FFFF" 0)
(Paint. "darkblue" "Dark Blue" "#00008B" 0)
(Paint. "darkcyan" "Dark Cyan" "#008B8B" 0)
(Paint. "darkgoldenrod" "Dark Golden Rod" "#B8860B" 0)
(Paint. "darkgray" "Dark Gray" "#A9A9A9" 0)
(Paint. "darkgreen" "Dark Green" "#006400" 0)
(Paint. "darkkhaki" "Dark Khaki" "#BDB76B" 0)
(Paint. "darkmagenta" "Dark Magenta" "#8B008B" 0)
(Paint. "darkolivegreen" "Dark OliveGreen" "#556B2F" 0)
(Paint. "darkorange" "Dark Orange" "#FF8C00" 0)
(Paint. "darkorchid" "Dark Orchid" "#9932CC" 0)
(Paint. "darkred" "Dark Red" "#8B0000" 0)
(Paint. "darksalmon" "Dark Salmon" "#E9967A" 0)
(Paint. "darkseagreen" "Dark Sea Green" "#8FBC8F" 0)
(Paint. "darkslateblue" "Dark Slate Blue" "#483D8B" 0)
(Paint. "darkslategray" "Dark Slate Gray" "#2F4F4F" 0)
(Paint. "darkturquoise" "Dark Turquoise" "#00CED1" 0)
(Paint. "darkviolet" "Dark Violet" "#9400D3" 0)
(Paint. "deeppink" "Deep Pink" "#FF1493" 0)
(Paint. "deepskyblue" "Deep Sky Blue" "#00BFFF" 0)
(Paint. "dimgray" "Dim Gray" "#696969" 0)
(Paint. "dodgerblue" "Dodger Blue" "#1E90FF" 0)
(Paint. "firebrick" "Fire Brick" "#B22222" 0)
(Paint. "floralwhite" "Floral White" "#FFFAF0" 0)
(Paint. "forestgreen" "Forest Green" "#228B22" 0)
(Paint. "fuchsia" "Fuchsia" "#FF00FF" 0)
(Paint. "gainsboro" "Gainsboro" "#DCDCDC" 0)
(Paint. "ghostwhite" "Ghost White" "#F8F8FF" 0)
(Paint. "gold" "Gold" "#FFD700" 0)
(Paint. "goldenrod" "Golden Rod" "#DAA520" 0)
(Paint. "gray" "Gray" "#808080" 0)
(Paint. "green" "Green" "#008000" 0)
(Paint. "greenyellow" "Green Yellow" "#ADFF2F" 0)
(Paint. "honeydew" "Honey Dew" "#F0FFF0" 0)
(Paint. "hotpink" "Hot Pink" "#FF69B4" 0)
(Paint. "indianred" "Indian Red" "#CD5C5C" 0)
(Paint. "indigo" "Indigo" "#4B0082" 0)
(Paint. "ivory" "Ivory" "#FFFFF0" 0)
(Paint. "khaki" "Khaki" "#F0E68C" 0)
(Paint. "lavender" "Lavender" "#E6E6FA" 0)
(Paint. "lavenderblush" "Lavender Blush" "#FFF0F5" 0)
(Paint. "lawngreen" "Lawn Green" "#7CFC00" 0)
(Paint. "lemonchiffon" "Lemon Chiffon" "#FFFACD" 0)
(Paint. "lightblue" "Light Blue" "#ADD8E6" 0)
(Paint. "lightcoral" "Light Coral" "#F08080" 0)
(Paint. "lightcyan" "Light Cyan" "#E0FFFF" 0)
(Paint. "lightgoldenrodyellow" "Light Golden Rod Yellow" "#FAFAD2" 0)
(Paint. "lightgray" "Light Gray" "#D3D3D3" 0)
(Paint. "lightgreen" "Light Green" "#90EE90" 0)
(Paint. "lightpink" "Light Pink" "#FFB6C1" 0)
(Paint. "lightsalmon" "Light Salmon" "#FFA07A" 0)
(Paint. "lightseagreen" "Light Sea Green" "#20B2AA" 0)
(Paint. "lightskyblue" "Light Sky Blue" "#87CEFA" 0)
(Paint. "lightslategray" "Light Slate Gray" "#778899" 0)
(Paint. "lightsteelblue" "Light Steel Blue" "#B0C4DE" 0)
(Paint. "lightyellow" "Light Yellow" "#FFFFE0" 0)
(Paint. "lime" "Lime" "#00FF00" 0)
(Paint. "limegreen" "Lime Green" "#32CD32" 0)
(Paint. "linen" "Linen" "#FAF0E6" 0)
(Paint. "magenta" "Magenta" "#FF00FF" 0)
(Paint. "maroon" "Maroon" "#800000" 0)
(Paint. "mediumaquamarine" "Medium Aqua Marine" "#66CDAA" 0)
(Paint. "mediumblue" "Medium Blue" "#0000CD" 0)
(Paint. "mediumorchid" "Medium Orchid" "#BA55D3" 0)
(Paint. "mediumpurple" "Medium Purple" "#9370DB" 0)
(Paint. "mediumseagreen" "Medium Sea Green" "#3CB371" 0)
(Paint. "mediumslateblue" "Medium Slate Blue" "#7B68EE" 0)
(Paint. "mediumspringgreen" "Medium Spring Green" "#00FA9A" 0)
(Paint. "mediumturquoise" "Medium Turquoise" "#48D1CC" 0)
(Paint. "mediumvioletred" "Medium Violet Red" "#C71585" 0)
(Paint. "midnightblue" "Midnight Blue" "#191970" 0)
(Paint. "mintcream" "Mint Cream" "#F5FFFA" 0)
(Paint. "mistyrose" "Misty Rose" "#FFE4E1" 0)
(Paint. "moccasin" "Moccasin" "#FFE4B5" 0)
(Paint. "navajowhite" "Navajo White" "#FFDEAD" 0)
(Paint. "navy" "Navy" "#000080" 0)
(Paint. "oldlace" "Old Lace" "#FDF5E6" 0)
(Paint. "olive" "Olive" "#808000" 0)
(Paint. "olivedrab" "Olive Drab" "#6B8E23" 0)
(Paint. "orange" "Orange" "#FFA500" 0)
(Paint. "orangered" "Orange Red" "#FF4500" 0)
(Paint. "orchid" "Orchid" "#DA70D6" 0)
(Paint. "palegoldenrod" "Pale Golden Rod" "#EEE8AA" 0)
(Paint. "palegreen" "Pale Green" "#98FB98" 0)
(Paint. "paleturquoise" "Pale Turquoise" "#AFEEEE" 0)
(Paint. "palevioletred" "Pale VioletRed" "#DB7093" 0)
(Paint. "papayawhip" "Papaya Whip" "#FFEFD5" 0)
(Paint. "peachpuff" "Peach Puff" "#FFDAB9" 0)
(Paint. "peru" "Peru" "#CD853F" 0)
(Paint. "pink" "Pink" "#FFC0CB" 0)
(Paint. "plum" "Plum" "#DDA0DD" 0)
(Paint. "powderblue" "Powder Blue" "#B0E0E6" 0)
(Paint. "purple" "Purple" "#800080" 0)
(Paint. "red" "Red" "#FF0000" 0)
(Paint. "rosybrown" "Rosy Brown" "#BC8F8F" 0)
(Paint. "royalblue" "Royal Blue" "#4169E1" 0)
(Paint. "saddlebrown" "Saddle Brown" "#8B4513" 0)
(Paint. "salmon" "Salmon" "#FA8072" 0)
(Paint. "sandybrown" "Sandy Brown" "#F4A460" 0)
(Paint. "seagreen" "Sea Green" "#2E8B57" 0)
(Paint. "seashell" "Sea Shell" "#FFF5EE" 0)
(Paint. "sienna" "Sienna" "#A0522D" 0)
(Paint. "silver" "Silver" "#C0C0C0" 0)
(Paint. "skyblue" "Sky Blue" "#87CEEB" 0)
(Paint. "slateblue" "Slate Blue" "#6A5ACD" 0)
(Paint. "slategray" "Slate Gray" "#708090" 0)
(Paint. "snow" "Snow" "#FFFAFA" 0)
(Paint. "springgreen" "Spring Green" "#00FF7F" 0)
(Paint. "steelblue" "Steel Blue" "#4682B4" 0)
(Paint. "tan" "Tan" "#D2B48C" 0)
(Paint. "teal" "Teal" "#008080" 0)
(Paint. "thistle" "Thistle" "#D8BFD8" 0)
(Paint. "tomato" "Tomato" "#FF6347" 0)
(Paint. "turquoise" "Turquoise" "#40E0D0" 0)
(Paint. "violet" "Violet" "#EE82EE" 0)
(Paint. "wheat" "Wheat" "#F5DEB3" 0)
(Paint. "white" "White" "#FFFFFF" 0)
(Paint. "whitesmoke" "White Smoke" "#F5F5F5" 0)
(Paint. "yellow" "Yellow" "#FFFF00" 0)
(Paint. "yellowgreen" "Yellow Green" "#9ACD32" 0)])
(defresource catalog [start size]
:available-media-types ["application/json"]
:handle-ok { :start start
:size size
:total (count db)
:data (->> db (drop start) (take size)) })
(defroutes app
(GET "/" { { start :start size :size :or { start 0 size 10 } } :params }
(catalog (Integer. start) (Integer. size))))
(def handler
(-> app
(wrap-keyword-params)
(wrap-params)
(wrap-trace :header :ui)))
(defonce server (atom nil))
(defn stop []
(swap! server #(when % (.stop %))))
(defn start []
(reset! server
(run-jetty #'handler { :port 3000
:join? false })))
(defn restart []
(stop)
(start))
(defproject card-shop "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[liberator "0.10.0"]
[compojure "1.1.3"]
[ring/ring-core "1.2.1"]
[ring/ring-jetty-adapter "1.1.0"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment