Skip to content

Instantly share code, notes, and snippets.

View jRimbault's full-sized avatar
💭
🦀🐍TS C#

Jacques Rimbault jRimbault

💭
🦀🐍TS C#
View GitHub Profile
function partition<T, K extends string | number>(
list: readonly T[],
getKey: (el: T) => K,
) {
const res: { [k in K]?: T[] } = {}
for (const el of list) {
const key = getKey(el)
const target: T[] = res[key] ?? (res[key] = [])
target.push(el)
}
/* In a config object :
{
"endpoints": {
"createUser": {
"path": "/users",
"method": "POST"
}
"listUsers": {
"path": "/users",
"method": "GET"
@jRimbault
jRimbault / Mutex.cs
Last active May 9, 2021 10:58
a RAII mutex lock using the `IDisposable` interface
using System;
using System.Threading;
namespace Sync
{
// If C# had different (slightly better imo) visibility semantics
// that interface wouldn't exists and the nested type wouldn't need to be nested.
// The "best" we can do is use the repo version, put it in its own project and use
// the `internal` visibility, which is dumb shit.
public interface IMutexGuard<T> : IDisposable
interface ResultMethods<T, E> {
ok(): T | null,
err(): E | null,
unwrap(): T | never,
unwrapErr(): E | never,
expect(message: string): T | never,
expectErr(message: string): E | never,
map<U>(f: (value: T) => U): Result<U, E>,
mapErr<U>(f: (error: E) => U): Result<T, U>,
andThen<U>(f: (value: T) => Result<U, E>): Result<U, E>,
@jRimbault
jRimbault / dot.ts
Last active November 21, 2021 12:55
export type DeepDotKey<T> = {
[P in keyof T]: DeepDotKey<T[P]>;
} & (() => string);
/**
* Type safe string builder deep dot notation
*
* @example
* interface Foo {
* dictionary: { [key: string]: { value: number } | undefined };
{"identity":{"name":"Jacques Rimbault","shortName":"jRimbault","description":"Programmeur, 29 ans, -Werror","location":"Paris"},"paragraphs":[{"name":"Experience","id":"experience","elements":[{"aside":{"kind":"date","date":"2018 .. 2019"},"title":"Développeur C# Angular","subTitle":"Société Générale - Corporate and Investment Banking","tags":[["C#","TypeScript","PowerShell"],[".NET","Angular"],["Windows Server"],["GitHub","TeamCity"]]},{"aside":{"kind":"date","date":"2016 .. 2018"},"title":"Développeur PHP","subTitle":"Ministère de l'Intérieur - SG-DSIC","subTitleDescription":"Secrétariat Général - Direction des Systèmes d'Information et Communication","resume":["Développement et maintenance d'une application de l'administration centrale."],"points":[{"description":"Migration de PHP 5.4 vers PHP 7.2","subPoints":[{"description":"Changement de l'API d'interface avec la base de donnée"},{"description":"Refonte sous une forme routeur/controleur"},{"description":"Management des dépendances"}]},{"description":"Fo
{
"basics": {
"name": "Jacques Rimbault",
"label": "Développeur 5 ans d'expérience",
"email": "jacques.rimbault@gmail.com",
"phone": "+336309644882",
"location": {
"city": "Paris"
},
"profiles": [
@jRimbault
jRimbault / xkcd-sway-lock py
Created April 9, 2024 13:01
Lock swaywm with an xkcd comic
#!/usr/bin/env python3
"""Download random xkcd comic"""
import json
import random
import subprocess
import textwrap
from pathlib import Path
from urllib.request import urlopen, urlretrieve