Skip to content

Instantly share code, notes, and snippets.

@bamthomas
bamthomas / principes_fondamentaux_biens_communs.md
Created September 5, 2024 21:29
Commons governance - Elinor Ostrom and Open Source

Les principes fondamentaux de la bonne gouvernance d'un bien commun

1. La question des limites

  • 1A Limites des usagers. Etablir des limites claires entres les usagers légitimes et les non-usagers.

  • 1B Limites de la resource. Etablir des limites claires de la resource et des parts que chacun peut prélever sans l'épuiser.

2. La question de la bonne échelle

@bamthomas
bamthomas / migrate_redis_task_manager.py
Created February 5, 2024 16:45
Datashare task manager migration script
import asyncio
import sys
from json import loads, dumps
import redis.asyncio as redis
async def main(argv):
pool = redis.ConnectionPool.from_url("redis://redis")
client = redis.Redis.from_pool(pool)
@bamthomas
bamthomas / users.cgi
Last active January 15, 2024 08:22
nb connected users on wifi lighthttpd
#!/bin/sh
echo "<h1>Utilisateurs connectes</h1>"
set -x
total=0
for interface in $(iwinfo |grep "ESSID:" | cut -d' ' -f1); do
nb_interface_users=$(iwinfo $interface assoclist | grep dBm | wc -l)
total=$((total + nb_interface_users))
done
@bamthomas
bamthomas / es2csv.sh
Last active September 12, 2022 11:37
scroll Elasticsearch with bash
#!/bin/bash
# from https://gist.github.com/cb372/4567f624894706c70e65
es_url=$1
index=$2
response=$(curl -s -H 'content-type: application/json' $es_url/$index/_search?scroll=1m -d @query.json)
scroll_id=$(echo $response | jq -r ._scroll_id)
hits_count=$(echo $response | jq -r '.hits.hits | length')
hits_so_far=hits_count
echo Got initial response with $hits_count hits and scroll ID $scroll_id
@bamthomas
bamthomas / gist:17c3e3086620b7ef58d10d7bf8d64f8d
Created January 18, 2020 10:35
redis CLI : transform a set into a map
EVAL "local vals = redis.call('SMEMBERS', KEYS[1]); local len = redis.call('SCARD', KEYS[1]); for k, v in pairs(vals) do redis.call('HSET', KEYS[2], v, '0'); end; return len;" 2 setkey mapkey
@bamthomas
bamthomas / MemoryDataBus.java
Created January 13, 2020 11:53
A tiny multithreaded memory databus
package org.icij.datashare;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Supplier;
@bamthomas
bamthomas / FileExtension.java
Created April 30, 2019 12:11
Class to get a file extension with its mime type
package org.icij.datashare;
import java.util.HashMap;
import java.util.Map;
import static java.util.Arrays.stream;
import static java.util.Collections.unmodifiableMap;
public class FileExtension {
@bamthomas
bamthomas / gist:49dde34877e7010b6487cbeddd7eef1b
Created January 31, 2019 13:50
Create bootable windows USB key
sudo woeusb --target-filesystem NTFS --device Downloads/Win10_1809Oct_English_x64.iso /dev/sda
sudo ngrep '' -d lo udp port 514 &
logger -n localhost -p local7.info log by udp
curl -i --request PROPFIND --insecure --digest -u user:password --header "Content-Type: text/xml" --header "Brief:t" \
https://dav.url/card.php/addressbooks/user/default/
curl -i --request PROPFIND --insecure --digest -u user:password --header "Content-Type: text/xml" --header "Brief:t" \
https://dav.url/cal.php/principals/user/