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
(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"}})
module Main where
import System.Environment (getArgs)
import qualified Data.ByteString.Lazy as L
import Data.Word
addBytes :: [Word8] -> Word8
addBytes [] = 0
addBytes (x:xs) = x + addBytes xs
module Main where
import System.Environment (getArgs)
import qualified Data.ByteString.Lazy as L
import Data.Word
{-
- Test to see how fast we can process an 1GB binary file.
- From the blog post: http://jvns.ca/blog/2014/05/12/computers-are-fast/
-
-- name: fetch-students-for-user
-- Returns all the students for this user
SELECT *
FROM users
WHERE id IN
(SELECT user_id FROM students WHERE flow_id IN
(SELECT id FROM flows WHERE owner_id = :user_id))
@wunki
wunki / unique_chars.rs
Created June 8, 2014 20:04
Unique character check in Rust
use std::os;
fn unique_chars(s: &str) -> bool {
let v: Vec<char> = s.chars().collect();
let mut y = v.clone();
y.dedup();
v.len() == y.len()
}
#[crate_id="cherr"]
use std::os;
use std::io::fs;
fn main() {
// get the filename
let args = os::args();
let filename: &str = args.get(1).as_slice();
extern crate crypto = "rust-crypto";
use std::os;
struct Keys {
AccessKey: String,
SecretKey: String,
}
pub fn env_keys() -> Option<Keys> {