Skip to content

Instantly share code, notes, and snippets.

View ordnungswidrig's full-sized avatar

Philipp Meier ordnungswidrig

View GitHub Profile
@ordnungswidrig
ordnungswidrig / .git_hooks_commit-msg
Created May 26, 2014 19:59
Git commit-msg hook to check for maximum line lengths
#!/bin/sh
#
# .git/hooks/commit-msg
#
# Check for maximum line lengths
#
# A git hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
@ordnungswidrig
ordnungswidrig / conflict-on-post.clj
Created March 7, 2014 11:19
Force 409 for post requests (untestet)
(defresource conflict-on-post
:post! (fn [ctx] (if (detect-conflict ctx) { ::conflict true}))
:respone-with-entity (fn [{conflict ::conflict}] (not conflict))
:handle-no-content (fn [{conflict ::conflict}]
(when conflict
(-> (as-response "my-regular-response")
(assoc :status 409) ;; force status
(ring-response)))))
(def base-resource-media-typed
{"application/json"
{:success false
:message "No acceptable resource available"}
"application/edn"
{:success false
:message "No acceptable resource available"}})
(def base-resource
{:handle-not-acceptable (media-typed base-resource-media-typed)
@ordnungswidrig
ordnungswidrig / README.md
Last active December 29, 2015 13:09 — forked from JoelBesada/README.md
Post current page to pinboard.in

This is an command for Backtick. It posts to current page's URL to pinboard.

@ordnungswidrig
ordnungswidrig / README.md
Last active December 29, 2015 13:09 — forked from JoelBesada/README.md
Post current page to pinboard with tag "friday"

This is a command for Backtick. It posts the current page to pinboard.

@ordnungswidrig
ordnungswidrig / gist:7021114
Created October 17, 2013 08:21
Avoid the if-let in liberator's exists?
(defn into-context [key value]
(when value
{ key value }))
(ANY "/choice" []
(resource :available-media-types ["text/html"]
:exists? (fn [ctx]
(into-context :choice
(get {"1" "stone" "2" "paper" "3" "scissors"}
(get-in ctx [:request :params "choice"]))))
(print
(apply str (for [i (range 0 36)]
(format "%11s %2s %s\n"
(.toPlainString (.pow 2M i)) i (.toPlainString (.divide 1M (.pow 2M i)))))))
@ordnungswidrig
ordnungswidrig / liberator-flow.dot
Created September 11, 2012 23:14
Liberator flow chart
digraph {
node[shape="box", splines=ortho]
"start"[shape=circle];
"start" -> "service-available?"
"handle-multiple-representations" [peripheries=2];
"handle-ok" [peripheries=2];
"multiple-representations?" -> "handle-multiple-representations" [label = "true"]
"multiple-representations?" -> "handle-ok" [label="false"]
"handle-no-content" [peripheries=2];
"respond-with-entity?" -> "multiple-representations?" [label = "true"]
@ordnungswidrig
ordnungswidrig / liberator-decision-excerpt.clj
Created September 11, 2012 23:00
liberator decision syntax excerpt
(defdecision moved-temporarily? handle-moved-temporarily post-to-gone?)
(defdecision moved-permanently? handle-moved-permanently moved-temporarily?)
(defdecision existed? moved-permanently? post-to-missing?)
@ordnungswidrig
ordnungswidrig / doc.clj
Created September 4, 2012 12:58
liberator decision flow to graphviz
(ns doc)
(defn destructure
([_ name then else] [name then else])
([_ name test then else] [name then else]))
(defn format-node [node]
(when (.startsWith (str node) "handle-")
(format "\"%s\" [peripheries=2];\n" node)))