Skip to content

Instantly share code, notes, and snippets.

View edgarogh's full-sized avatar

Edgar Onghena edgarogh

View GitHub Profile
@edgarogh
edgarogh / rendezvous_map.rs
Created July 25, 2024 00:38
A map that allows a producer to promise a value for a given key, while a consumer can await for the completion of a given promise
use std::borrow::Borrow;
use std::hash::Hash;
use std::sync::Arc;
use dashmap::{DashMap, Entry};
use tokio::sync::oneshot;
enum Receiver<V> {
Available(oneshot::Receiver<V>),
Polling,
@edgarogh
edgarogh / completions_cdd.fish
Created August 19, 2023 14:54
cdd — run a command from within another directory + fish completion. Install in `~/.config/fish/` and consider underscores as directory separators.
complete -c cdd -n '__fish_is_first_token' -x -a '(__fish_complete_directories)'
complete -c cdd -n 'not __fish_is_first_token' -x -a '(__fish_complete_subcommand --fcs-skip=2)'
@edgarogh
edgarogh / ublock-discord-super-reactions.txt
Created June 23, 2023 08:23
Discord super reactions are also super obstrusive. These uBlock rules make them more discreet.
! Make the super reactions less obtrusive (no animation, no shaking). They just keep their unique color.
discord.com##[class*="effectsWrapper-"]
discord.com##[class*="hideEmoji-"]:style(opacity: 1 !important;)
discord.com##[class*="shakeReaction-"]:style(animation: none !important;)
! Hide super reaction buttons (relies on aria-label, may require tweaking depending on locale)
discord.com##[id*="message-reactions-"] > [aria-label*="super"]:has([class*="reactionBtn-"])
discord.com##[class*="message-"] [class*="buttonContainer-"] [class*="button-"][aria-label*="super"]
@edgarogh
edgarogh / pixel_to_lat_lng.glsl
Created May 29, 2023 14:22
Google Web Mercator pixel coordinates to latitude & longitude, in GLSL / https://fredriknoren.github.io/glsl-repl/
#version 300 es
precision highp float;
out vec2 res;
#define TILE_SIZE 256u
#define PI 3.141592653589793
#define EARTH_RADIUS 6378137.0
vec2 webMercatorToLatLng(vec2 pixelCoord, uint zoomLevel) {
float initialResolution = 2.0 * PI * EARTH_RADIUS / float(TILE_SIZE);
@edgarogh
edgarogh / alter_materialized_view_alter_column_set_not_null.sql
Last active August 27, 2022 10:52
A PostrgeSQL function to define a materialized view column as `not null`.
create or replace function alter_materialized_view_alter_column_set_not_null(mv regclass, col_name text, not_null bool)
returns setof bool
returns null on null input
security definer
language sql
as $$
with to_update as (
select
attrelid as attrelid_u, attnum as attnum_u
from pg_catalog.pg_attribute as attr
name pantone c m y k r g b
Angers 486 C 0 58 53 0 240 135 111
Annecy-Chambéry 226 C 1 97 4 0 230 0 126
Clermont 368 C 55 0 100 0 134 188 36
Grenoble 479 C 23 36 57 10 191 156 113
Lille 193 C 0 100 79 0 228 2 46
Lyon 483 C 31 96 100 44 120 28 0
Marseille 3135 C 78 17 26 2 0 156 180
Montpellier 279 C 80 40 0 0 37 129 196
Nancy 485 C 0 91 89 0 230 48 35
#define CLK_PIN 13 // or SCK
#define DATA_PIN 11 // or MOSI
#define CS_PIN 10 // or SS
// Taille du buffer d'envoi (4 écrans * 2 octets par écran)
#define BUFFER_SIZE 8
#include <Arduino.h>
#include <SPI.h>
#include "screen.h"

PostgreSQL Deterministic (non-complete) Finite State Automaton

  • Provides a run aggregate to execute the automaton over rows of symbols, given an initial state.
  • Provides an accepts function that tells wether or not a given string is accepted, given an initial state

The state of id=0 is a sink and shouldn't be modified. Algorithms rely on it when a transition is undefined.

What did I learn

  • Custom aggregate definition
Simple tags system with a notion of parents. May be used for file paths, I guess.
Licensed as CC-0
// GPL-3.0 Edgar Onghena
// Last mod: Sun 06 Dec 2020 08∶49∶15 PM CET
trait AllValues: Sized {
fn get_all_values() -> Vec<Self>;
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum Direction {
Devant = 0b0001isize,