Skip to content

Instantly share code, notes, and snippets.

🏠
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 Aug 29, 2015
Keyboard configuration for Dvorak in X11.
View 10-keyboard.conf
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 Aug 29, 2015
Type annotation for rename-keys
View anonymous-gist.clj
(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))
View concurrent.rs
fn main() {
for num in range(0, 100) {
spawn(proc() println!("Hello"))
}
}
@wunki
wunki / 01-multiples.rs
Created Mar 20, 2014
Euler - Problem 1
View 01-multiples.rs
/***
*
* 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 Mar 20, 2014
Total in FP and OOP
View 01-multiples.rs
/***
*
* 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 {
View gist:11252574
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:

View middleware.clj
(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 Aug 29, 2015
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`
View gist:29705e712569c3b223c1
(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
Dynamic ordering with Clojure's yesql.
View gist:04cac02340405ffd63ee
SELECT * FROM users ORDER BY :order ASC
@wunki
wunki / user.clj
Created May 22, 2014
Extract `:auth-level` in middleware.
View user.clj
(defnk $GET
"Get the Authenticated user"
{:responses {200 s/Any}
:auth-level #{:user}}
[[:resources user]]
{:status 200
:body {:foo "bar"}})
You can’t perform that action at this time.