Skip to content

Instantly share code, notes, and snippets.

View wunki's full-sized avatar
🏠
Working from my home in the Netherlands.

Petar Radošević wunki

🏠
Working from my home in the Netherlands.
View GitHub Profile
@wunki
wunki / 10-keyboard.conf
Last active August 29, 2015 13:57
Keyboard configuration for Dvorak in X11.
Section "InputClass"
Identifier "evdev keyboard catchall"
MatchIsKeyboard "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
Option "XkbLayout" "dvorak"
Option "XkbVariant" "dvorak"
Option "XkbOptions" "ctrl:nocaps"
EndSection
@wunki
wunki / anonymous-gist.clj
Last active August 29, 2015 13:57
Type annotation for rename-keys
(ann ^:no-check clojure.set/rename-keys [(Map Any Any) (Map Keyword Keyword) -> (Map Any Any)])
;; Type Error (gibbon/service/postgres.clj:23:7) Type mismatch:
;; Expected: (Map Any Any)
;; Actual: (TFn [[a :variance :covariant] [b :variance :covariant]] (APersistentMap a b))
@wunki
wunki / concurrent.rs
Created March 20, 2014 11:41
Concurrent #2
fn main() {
for num in range(0, 100) {
spawn(proc() println!("Hello"))
}
}
@wunki
wunki / 01-multiples.rs
Created March 20, 2014 13:47
Euler - Problem 1
/***
*
* If we list all the natural numbers below 10 that are multiples of 3 or 5, we
* get 3, 5, 6 and 9. The sum of these multiples is 23.
*
* Find the sum of all the multiples of 3 or 5 below 1000.
*
***/
fn is_multiple(num: int) -> bool {
@wunki
wunki / 01-multiples.rs
Created March 20, 2014 14:05
Total in FP and OOP
/***
*
* If we list all the natural numbers below 10 that are multiples of 3 or 5, we
* get 3, 5, 6 and 9. The sum of these multiples is 23.
*
* Find the sum of all the multiples of 3 or 5 below 1000.
*
***/
fn is_multiple(num: int) -> bool {
clojure.lang.ExceptionInfo: Request: [{:body {:foo "bar"}, :query-string nil, :uri "/users"}]<BR>==> Error: [{:foo disallowed-key, :username missing-required-key}]<BR>==> Context: [:body]
    data: {:type :coercion-error,
           :schema {:username java.lang.String},
           :data {:foo "bar"},
           :context :body}

Try destructuring it with slingshot:

(fn [request]
(try (handler request)
(catch Exception e
(let [data (ex-data e)]
(case (:type data)
:coercion-error (do (warn e) (invalid-request (:data data)))
(do (error e) internal-server-error))))))
@wunki
wunki / gist:29705e712569c3b223c1
Last active August 29, 2015 14:01
Is it possible with fnhouse to default limit to a certain value if it's not supplied? Currently it also raises an `missing-required-key` when it's not supplied because of the `s/Int`
(defnk $GET
{:responses {200 schemas/SomeSchema}
[[:request
[:query-params limit :- s/Int]
:as req]
[:resources flow :- FlowResource]]
(...)
@wunki
wunki / gist:04cac02340405ffd63ee
Created May 15, 2014 14:16
Dynamic ordering with Clojure's yesql.
SELECT * FROM users ORDER BY :order ASC
@wunki
wunki / user.clj
Created May 22, 2014 10:24
Extract `:auth-level` in middleware.
(defnk $GET
"Get the Authenticated user"
{:responses {200 s/Any}
:auth-level #{:user}}
[[:resources user]]
{:status 200
:body {:foo "bar"}})