Skip to content

Instantly share code, notes, and snippets.

Damien LeBerrigaud dam5s

Block or report user

Report or block dam5s

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dam5s
dam5s / PowerShellPromptSetup.md
Last active Aug 14, 2019
A custom Powershell prompt à la Oh My ZSH
View PowerShellPromptSetup.md

How to setup

Assuming you have Visual studio code installed and on the path. Assuming you have git installed and on the path.

  1. Open PowerShell.
  2. Edit your profile
    code $profile
    
@dam5s
dam5s / Application.kt
Last active Jun 26, 2019
Date factory methods in a Date object.
View Application.kt
package com.example.application
import com.example.dateextensions.Date
fun main() {
println(Date.tomorrow())
}
@dam5s
dam5s / Result.java
Last active Jun 10, 2019
Result type for Java codebases, if you don't get to use Kotlin.
View Result.java
import java.util.function.Function;
interface Result<T, E> {
static <T, E> Success<T, E> success(T value) {
return new Success<>(value);
}
static <T, E> Error<T, E> error(E value) {
return new Error<>(value);
}
@dam5s
dam5s / publish-cli.sh
Created Feb 25, 2019
How to publish a .NET Core CLI as a single binary for all 3 platforms from a single OS.
View publish-cli.sh
#!/bin/bash
set -e
set -v
dotnet publish -c release -r linux-x64
warp-packer --arch linux-x64 --input_dir cli-app/bin/Release/netcoreapp2.2/linux-x64/publish --exec cli-app --output cli-app/bin/Release/netcoreapp2.2/cli-app-linux
dotnet publish -c release -r osx-x64
warp-packer --arch macos-x64 --input_dir cli-app/bin/Release/netcoreapp2.2/osx-x64/publish --exec cli-app --output cli-app/bin/Release/netcoreapp2.2/cli-app-osx
View Prelude.fs
[<AutoOpen>]
module Prelude
type AsyncResult<'T, 'TError> =
Async<Result<'T, 'TError>>
module AsyncResult =
let map (mapping : 'T -> 'U) (result : AsyncResult<'T, 'TError>) : AsyncResult<'U, 'TError> =
async {
match! result with
View App.elm
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ TypeAhead.subscriptions CompanyTypeAheadMsg
, TypeAhead.subscriptions CohortTypeAheadMsg
, TypeAhead.subscriptions CountryTypeAheadMsg
, Keyboard.ups KeyWasPressed
]
@dam5s
dam5s / Result.kt
Last active Jul 13, 2019
Railway oriented programming in Kotlin
View Result.kt
sealed class Result<A, B> {
abstract fun <C> map(mapping: (A) -> C): Result<C, B>
abstract fun <C> flatMap(mapping: (A) -> Result<C, B>): Result<C, B>
abstract fun <C> mapFailure(mapping: (B) -> C): Result<A, C>
abstract fun <C> flatMapFailure(mapping: (B) -> Result<A, C>): Result<A, C>
abstract fun orElse(other: A): A
abstract fun orElse(function: (B) -> A): A
}
data class Success<A, B>(val value: A) : Result<A, B>() {
View dependenciesGraph.gradle
task dependenciesGraphDot {
mustRunAfter "clean"
def graphBuildDir = "build/dependenciesGraph"
def dotFile = file "$graphBuildDir/graph.dot"
doLast {
delete graphBuildDir
mkdir graphBuildDir
@dam5s
dam5s / Maybe.kt
Last active Apr 29, 2018
Union types in Kotlin 1.1 using sealed classes and data classes.
View Maybe.kt
sealed class Maybe<T> {
object Nothing: Maybe()
data class Some<T>(val value: T): Maybe<T>()
}
@dam5s
dam5s / ReadInputStream.java
Created Oct 5, 2015
Convert InputStream to String.
View ReadInputStream.java
public static String read(InputStream inputStream) {
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
You can’t perform that action at this time.