Skip to content

Instantly share code, notes, and snippets.

View erichonorez's full-sized avatar

Eric Honorez erichonorez

  • Buy Way Services
  • Brussels
View GitHub Profile
class Scratchpad {
static enum RouteNames {
USERS_FORM,
USERS_JSON,
USER_GET,
USER_POST
};
public static void main(String[] args) {
new Routes(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
$.ajax("http://localhost:8080/api/v1/loan-applications", { 'method': 'POST', 'contentType' : 'json', 'headers': { 'Content-Type': 'application/json', 'X-Custom-MerchantId': '123' } , 'data': '{ "productId": "123", "amount": "222", "language": "fr" }'})
import * as React from 'react';
import { Text, View, ScrollView, Button, StyleSheet } from 'react-native';
//let contacts = [...Array(10).keys()].map(i => {
// return { id: i, name: "Eric " + i , phoneNumber: "000000000" + i }
//})
let contacts = [{ id: 1, name: "Eric", phoneNumber: "00000" }]
const stylesheets = StyleSheet.create({
@erichonorez
erichonorez / bookSerialisation.scala
Last active March 5, 2019 15:35
Example of type classes for serialisation
// Start writing your ScalaFiddle code here
case class Book(title: String, author: String)
trait ToJson[A] {
def toJson(a: A): String
}
trait ToXml[A] {
def toXml(a: A): String
}
@erichonorez
erichonorez / functor.scala
Created March 4, 2019 14:55
Functor test
trait Functor[M[_]] {
def map[A, B](ma: M[A], f: A => B): M[B]
def lift[A, B](f: A => B): M[A] => M[B]
}
object Functor {
def apply[F[_] : Functor]: Functor[F] = implicitly[Functor[F]]
implicit val optionIsFunctor = new Functor[Option] {
@erichonorez
erichonorez / typeClasses.scala
Created March 4, 2019 12:54
Type classes in scala
trait Show[A] {
def show(a: A): String
}
object Show {
// def apply[A](implicit sh: Show[A]): Show[A] = sh
def apply[A: Show]: Show[A] = implicitly[Show[A]]
object ops {
@erichonorez
erichonorez / useCaseFn.scala
Created February 26, 2019 12:55
UseCase with Function1
import cats.implicits._
trait UseCase[In, Out, Err] extends Function1[In, Either[Err, Out]]
trait CreateLoanApplication extends UseCase[CreateLoanApplicationIn, CreateLoanApplicationOut, CreateLoanApplicationErr] {
override def apply(in: CreateLoanApplicationIn): Either[CreateLoanApplicationErr, CreateLoanApplicationOut] = {
Either.right(CreateLoanApplicationOut())
}
}
case class CreateLoanApplicationIn()
@erichonorez
erichonorez / appError.scala
Created February 26, 2019 12:34
Application wide errors with Either
// Start writing your ScalaFiddle code here
import cats.implicits._
trait UseCase[Parameters, Error, Result] {
def execute(p: Parameters): Either[Error, Result]
}
import CreateLoanApplication._
trait CreateLoanApplication extends UseCase[CreateLoanApplicationRequest, CreateLoanApplicationError, CreateLoanApplicationResult] {