Skip to content

Instantly share code, notes, and snippets.

View leobm's full-sized avatar

Felix Wittmann leobm

  • Hamburg, Germany
View GitHub Profile

The project can be built using Lumo

npm install -g lumo-cljs
lumo build.cljs
@leobm
leobm / core.clj
Created June 3, 2017 15:52 — forked from philippkueng/core.clj
Fetch & write a binary file using Clojure and clj-http
(ns the-namespace.core
(:require [clj-http.client :as client]
[clojure.java.io :as io]))
(defn- fetch-photo!
"makes an HTTP request and fetches the binary object"
[url]
(let [req (client/get url {:as :byte-array :throw-exceptions false})]
(if (= (:status req) 200)
(:body req))))
@leobm
leobm / Either.scala
Created April 13, 2017 10:07 — forked from owainlewis/Either.scala
Validation examples
object EitherValidationExamples {
type ValidationError = String
def validateEmail(user: User): Either[ValidationError, User] =
if (user.email contains "@") Right(user) else Left("Must supply a valid email")
def validateAge(user: User): Either[ValidationError, User] =
if (user.age > 18) Right(user) else Left("Must be over 18")
@leobm
leobm / uri.js
Created February 14, 2017 11:04 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<!-- in firefox you can't choose a file diretory -->
<input type="file" id="file_input" directory webkitdirectory multiple />
In Application.scala:
object MyServer extends AutowirePlayServer[Api] {
override def routes(target: Api) = route[Api](target)
override def createImpl(autowireContext: AutowireContext): Api = new ServerImpl(autowireContext)
}
object Application extends Controller {
def api = PlayAutowire.api(MyServer)_
}
@leobm
leobm / PlayAutowire.scala
Created May 20, 2016 18:41 — forked from mkotsbak/PlayAutowire.scala
Play server wiring to get Autowire to work with extra request information like IP-addresses and authentication. See how to use it here: https://gist.github.com/mkotsbak/122940aa003db9708093
package controllers
import play.api.http.{ContentTypes, ContentTypeOf}
import upickle.Js
import upickle.default._
import play.api.mvc._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
-module(twitter_stream).
-author("[email protected]").
%% Depends on:
%% ibrowse for http
%% couchbeam for couchbeam_json_stream (a fork of damienkatz json_stream_parse)
%% mochiweb for mochiweb_util:urlencode
-export([start/0]).
@leobm
leobm / XTest.java
Created January 10, 2014 14:40 — forked from mariuszs/XTest.java
Solution without PowerMock
--
import ch.qos.logback.classic.*;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.Appender;
import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.*;
import org.mockito.runners.MockitoJUnitRunner;
;Print "Hi" every 2 seconds:
(defn t []
(go (loop [] (<! (timeout 2000)) (prn "hi") (recur))))
;or as a macro