Skip to content

Instantly share code, notes, and snippets.

View dam5s's full-sized avatar

Damien LeBerrigaud dam5s

View GitHub Profile
call pathogen#runtime_append_all_bundles()
set wildmenu
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set smarttab
set autoindent
set nu
@dam5s
dam5s / object_creation_methods.rb
Created January 20, 2013 03:33
Object Creation Methods to easily make objects for testing, replacing the magic of Factory Girl and still keeping a nice syntax
module ObjectCreationMethods
# def make_user
# def make_user!
define User do
{
username: 'dam5s',
email: 'dam5s@example.com',
password: 's0m3pwd',
password_confirmation: 's0m3pwd'
}
@dam5s
dam5s / ReadInputStream.java
Created October 5, 2015 19:04
Convert InputStream to String.
public static String read(InputStream inputStream) {
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
@dam5s
dam5s / Maybe.kt
Last active April 29, 2018 23:31
Union types in Kotlin 1.1 using sealed classes and data classes.
sealed class Maybe<T> {
object Nothing: Maybe()
data class Some<T>(val value: T): Maybe<T>()
}
task dependenciesGraphDot {
mustRunAfter "clean"
def graphBuildDir = "build/dependenciesGraph"
def dotFile = file "$graphBuildDir/graph.dot"
doLast {
delete graphBuildDir
mkdir graphBuildDir
@dam5s
dam5s / Result.kt
Last active June 22, 2022 21:28
Railway oriented programming in Kotlin - This is code accompanying my blog post https://medium.com/@its_damo/error-handling-in-kotlin-a07c2ee0e06f
sealed class Result<A, E> {
fun <B> map(mapping: (A) -> B): Result<B, E> =
when (this) {
is Success -> Success(mapping(value))
is Failure -> Failure(reason)
}
fun <B> bind(mapping: (A) -> Result<B, E>): Result<B, E> =
when (this) {
is Success -> mapping(value)
@dam5s
dam5s / Prelude.fs
Last active January 23, 2019 01:54
[<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
@dam5s
dam5s / publish-cli.sh
Created February 25, 2019 18:35
How to publish a .NET Core CLI as a single binary for all 3 platforms from a single OS.
#!/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
@dam5s
dam5s / Result.java
Last active October 31, 2020 20:17
Result type for Java codebases, if you don't get to use Kotlin.
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 / Application.kt
Last active June 26, 2019 19:09
Date factory methods in a Date object.
package com.example.application
import com.example.dateextensions.Date
fun main() {
println(Date.tomorrow())
}