Skip to content

Instantly share code, notes, and snippets.

View dam5s's full-sized avatar

Damien LeBerrigaud dam5s

View GitHub Profile
@dam5s
dam5s / profile.ps1
Created July 26, 2022 16:26
Powershell Profile
try { $null = gcm pshazz -ea stop; pshazz init } catch { }
function PromptAdmin {
$identity = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ($isAdmin) {
Write-Host "ADMIN " -NoNewline -ForegroundColor Red
}
}
@dam5s
dam5s / result.ex
Created June 27, 2021 22:21
Elixir Result type test
defmodule Result do
@type t :: {:ok, any} | {:failure, any}
@spec map(Result.t, any :: any) :: Result.t
def map(result, mapping) do
case result do
{:ok, value} -> {:ok, mapping.(value)}
{:this_is_wrong, err} -> {:this_is_wrong, err}
end
end
@dam5s
dam5s / Async.swift
Created November 3, 2020 18:05
Limitations (?) to Swift extensions.
class Async<Wrapped> {
func map(function: @escaping (Wrapped) -> NewWrapped) -> Async<NewWrapped> {
// ...
}
// ...
}
typealias AsyncResult<Success, Failure> = Async<Result<Success, Failure>>
@dam5s
dam5s / PowerShellPromptSetup.md
Last active August 14, 2019 00:13
A custom Powershell prompt à la Oh My ZSH

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 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())
}
@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 / 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 / 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 / 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)
task dependenciesGraphDot {
mustRunAfter "clean"
def graphBuildDir = "build/dependenciesGraph"
def dotFile = file "$graphBuildDir/graph.dot"
doLast {
delete graphBuildDir
mkdir graphBuildDir