Skip to content

Instantly share code, notes, and snippets.

View PascalLeMerrer's full-sized avatar

Pascal Le Merrer PascalLeMerrer

View GitHub Profile
@PascalLeMerrer
PascalLeMerrer / Main.kt
Created February 18, 2021 17:44
Using Arrow.Either in Kotlin
typealias Result<A> = Either<Exception,A>
typealias Err = Either.Left<Exception>
typealias Ok<A> = Either.Right<A>
fun <T> Result<T>.value(): T? {
when (this) {
is Ok -> return this.b
is Err -> return null
}
}
@PascalLeMerrer
PascalLeMerrer / main.kt
Created February 18, 2021 17:42
Intercept Ktor request
route("/api/v1/back-office/") {
intercept(phase=ApplicationCallPipeline.Features) {
// process the call
}
}
@PascalLeMerrer
PascalLeMerrer / Main.elm
Created February 18, 2021 17:36
Custom container in Elm Infinite List
infiniteListConfig : State a -> IL.Config (Item a) (Msg a)
infiniteListConfig state =
IL.config
{ itemView = viewRow state
, itemHeight = IL.withConstantHeight state.config.lineHeight
, containerHeight = Basics.round state.containerHeight
}
|> IL.withOffset 300
|> IL.withCustomContainer customContainer
@PascalLeMerrer
PascalLeMerrer / Main.elm
Created February 18, 2021 17:34
Current time and timezone in Elm 0.19
module Main exposing (main)
import Browser
import Html exposing (Html)
import Task
import Time exposing (Posix)
main : Program () Model Msg
main =
@PascalLeMerrer
PascalLeMerrer / Main.elm
Created February 18, 2021 17:31
Wait for launching a task & get DOM element dimensions
type Msg
= GotContainerInfo (Result Dom.Error Dom.Element)
init =
(initialModel,
Process.sleep 1000
|> Task.andThen (\_ -> Dom.getElement "container")
|> Task.attempt GotContainerInfo
)

Goal: create a proxy forwarding requests to https://api.unsplash.com. The proxy adds Authorization and Accept-Version headers, to comply with the terms of use of the API.

First I create the rp.conf file with the content below.

Then I run nginx with:

docker run --rm -d -p 8080:8888 -v $PWD/rp.conf:/etc/nginx/nginx.conf nginx
@PascalLeMerrer
PascalLeMerrer / Main.elm
Last active February 18, 2021 17:26
Elm + CustomElement whose HTML content is generated by Elm
module Main exposing (Model, Msg(..), init, main, update, view)
import Browser
import Html exposing (..)
import Html.Attributes exposing (property, src)
import Html.Events exposing (onClick)
import Json.Encode as Encode
@PascalLeMerrer
PascalLeMerrer / index.html
Created January 13, 2017 10:59
Example of issue in riot-grid2 when filtering columns
<!DOCTYPE html>
<html>
<head>
<title>Riot Grid2</title>
</head>
<body>
<script type="riot/tag">
package arangolite
import (
"bytes"
"encoding/json"
"fmt"
"strings"
)
// Transaction represents an ArangoDB transaction.
Verifying that +pascallemerrer is my openname (Bitcoin username). https://onename.io/pascallemerrer