Skip to content

Instantly share code, notes, and snippets.

Avatar

Carlo Alberto Ferraris CAFxX

View GitHub Profile
View bijective_map.go
package container
type BijectiveMap[A, B comparable] struct {
m1 map[A]B
m2 map[B]A
}
func (m *BijectiveMap[A, B]) GetB(a A) (B, bool) {
if m.m1 == nil {
var zero B
View gedi-adblock-modal-remover.js
// ==UserScript==
// @name La Stampa/Repubblica Adblock Modal Remover
// @name:it La Stampa/Repubblica Elimina Messaggio Adblock
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remove the adblock modal on lastampa.it and repubblica.it
// @description:it Elimina il messaggio modale che impedisce l'uso dei siti di La Stampa (lastampa.it) e Repubblica (repubblica.it) in caso di presenza di adblocker
// @author CAFxX
// @match https://*.lastampa.it/*
// @match https://*.repubblica.it/*
View workqueue.go
package main
import "sync"
import "fmt"
type Work interface {
Process()
}
type WorkFunc func()
View fls.c
// fast file list (linux)
// adapted from https://man7.org/linux/man-pages/man2/getdents.2.html
// gcc -O3 -march=native -o fls fls.c
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@CAFxX
CAFxX / weak.go
Last active Jul 19, 2021
Weak references for Go
View weak.go
// Weak references for Go
// Copyright (C) 2021 Carlo Alberto Ferraris
//
// Based on:
// https://lab.nexedi.com/kirr/neo/blob/bb618ce122423c5ff5fa997c5aafd06819cafe40/go/zodb/internal/weak/weak.go
//
// Original copyright notice:
//
// Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
View server_timing.go
func serverTiming(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
w.Header().Add("Trailer", "Server-Timing")
defer func() {
dur := time.Since(start).Seconds()
w.Header().Set("Server-Timing", fmt.Sprintf("total;dur=%f", dur))
}()
next.ServeHTTP(w, r)
})
View errgroup-cond.go
type Group interface {
Go(func() error)
Wait() error
}
func New(ctx context.Context, opts ...Option) (Group, context.Context) {
ctx, cancel := context.WithCancel(ctx)
g := &group{cancel: cancel}
g.cond.L = &g.mutex
@CAFxX
CAFxX / ffscast.sh
Created Mar 1, 2021
ffmpeg screencast for macos
View ffscast.sh
# there's a bunch of things that don't work properly:
# - can't capture computer audio output - it desyncs
# - need to change the input devices (`-i "v:a"`) based on the output of `ffmpeg -f avfoundation -list_devices true -i ""`
ffmpeg \
-thread_queue_size 150 -f avfoundation -probesize 50M -framerate 30 -pix_fmt uyvy422 -i "2:3" \
-thread_queue_size 150 -f avfoundation -probesize 50M -framerate 30 -pix_fmt uyvy422 -capture_cursor 1 -capture_mouse_clicks 1 -i "4" \
-filter_complex '
[1]fps=fps=30[scr],
[scr]scale=-1:1440[scr],
@CAFxX
CAFxX / wishlist.md
Last active Jun 3, 2021
List of ISA/instruction wishlists
View wishlist.md
@CAFxX
CAFxX / caching-adapter.go
Last active Jan 22, 2021
caching-adapter.go
View caching-adapter.go
type ctxKey struct{}
type Cache interface {
Get(key string) CachedResponse
Put(key string, r CachedResponse) CachedResponse
}
type CachedResponse interface {
Emit(w http.ResponseWriter) error