Skip to content

Instantly share code, notes, and snippets.

@cboudereau
cboudereau / git-prune.sh
Last active November 27, 2023 13:31
git prune except main
#!/bin/bash
# dry run
g remote prune -n origin
# remove old local remote
g remote prune origin
# remove old local branches except main
g br | grep -ve main | xargs git branch -D
@cboudereau
cboudereau / mirror_proxy.fsx
Last active October 5, 2023 12:02
mirror_proxy.fsx
type Mode = Passthrough | Mirroring | Filtering | Proxy
let main mode proxyRemoteUrl mirrorRemoteUrl mirrorRemoteApiKey hotels =
match mode, proxyRemoteUrl, mirrorRemoteUrl, mirrorRemoteApiKey with
| Proxy, _, Some mirrorUrl, Some mirrorApiKey -> sprintf "proxy, %s, %s" mirrorUrl mirrorApiKey
| _, None, _, _ -> sprintf "error : missing parameters to support any mode"
| Passthrough, Some url, _, _ -> sprintf "passthrough with %s" url
@cboudereau
cboudereau / google_chat_grafana_notification_template
Created October 2, 2023 10:06
google chat grafana notification template
{{ define "googlechat.subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }}{{ end }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
{{ define "googlechat.text_values_list" }}{{ if len .Values }}{{ $first := true }}{{ range $refID, $value := .Values -}}
{{ if $first }}{{ $first = false }}{{ else }}, {{ end }}{{ $refID }}={{ $value }}{{ end -}}
{{ else }}[no value]{{ end }}{{ end }}
{{ define "googlechat.text_alert_list" }}{{ range . }}
Value: {{ template "googlechat.text_values_list" . }}
{{ if gt (len .PanelURL) 0 }}<a href="{{ .PanelURL }}">Open Panel</a>
{{ end }}{{ end }}{{ end }}
using System;
public class C {
private class D : IDisposable {
public D()
{
}
public D(IDisposable _):this() {
}
public void Dispose(){
@cboudereau
cboudereau / count_uniq_line_in_large_json_files.sh
Created September 21, 2023 06:52
Count uniq line in large json files under json folder recursively
#! /bin/bash
find ./json -type f -name '*.json' -exec cat {} + | sort | uniq -c
@cboudereau
cboudereau / AdtOrdTest.java
Last active September 10, 2023 08:49
ord trait java adt (rust backport)
package com.adt;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public class AdtTest {
sealed interface Value<T extends Comparable<T>> extends Comparable<Value<T>> permits Value.Fixed, Value.Infinite {
@cboudereau
cboudereau / adt.java
Created July 24, 2023 14:47
Abstract Data Type / Sum type / Discriminated union for java
// from https://github.com/cboudereau/adt-java17-presentation > https://github.com/fteychene/adt-java17-presentation
package com.example;
public class App {
public enum Direction {
NORTH,
SOUTH,
EAST,
@cboudereau
cboudereau / tennis.rs
Last active May 17, 2023 15:38
Tennis score kata in Rust having KISS and "make illegal states unrepresentable"
#[derive(Debug, Clone, Copy, PartialEq)]
enum Point {
Love,
Fifteen,
Thirty,
Forty,
}
impl Point {
fn next(&self) -> Self {
@cboudereau
cboudereau / tennis.fsx
Created May 17, 2023 08:25
Tennis kata in fsharp with KISS principle + make illegal state unrepresentable
type Point = Love | Fifteen | Thirty | Forty
module Point =
//TIP / Closure of operation : Can the score go backward ?
let next = function Love -> Fifteen | Fifteen -> Thirty | Thirty | Forty -> Forty
type Player = Left | Right
(* TIP / Primitive obsession
- Negative score
package com.accorlight;
import java.util.function.Function;
public final class Result<R, E> {
final R value;
final E error;
public static class ResultException extends RuntimeException {
public ResultException(final String message) {