Skip to content

Instantly share code, notes, and snippets.

@drslump
drslump / redis-stream-ordered-processing.lua
Last active January 11, 2024 10:13
Lua (teal) snippet to implement ordered processing for redis streams
--- Redis Stream with ordered processing
---
--- Redis streams support multiple consumers for throughput and reliability however it doesn't offer
--- a native mechanism for processing a set of messages in a specific order.
---
--- It's possible though to implement a simple algorithm that resembles Kafka's partitioning algorithm:
---
--- - a logical stream becomes N streams in redis (shards from now on)
--- - producers place the message into one of the stream shards based on the hashing of some attribute
--- - each consumer in the consumer group "acquires" a subset of the streams
// This module uses an experimental API that is only available on Chromium using
// a trial or by enabling a browser flag. It's unlikely that the API will get
// standardized and if it is it'll probably end up having a quite different form,
// that's to say that we should remove this once the trial is over :)
//
// - Spec: https://oyiptong.github.io/compute-pressure/
// - Status: https://chromestatus.com/feature/5597608644968448
// - Trial: https://developer.chrome.com/origintrials/#/view_trial/1838594547874004993
// - Chrome flag: Experimental Web Platform features
//
@drslump
drslump / cargo.toml
Created June 26, 2020 00:27
linux global modifier keys (rust)
[package]
name = "global-modifiers"
version = "0.1.0"
authors = ["drslump <drslump@pollinimini.net>"]
edition = "2018"
[dependencies]
enumset = "1.0.0"
x11 = { version = "2.18.2", features = ["xlib"] }
@drslump
drslump / grab-frame.js
Created May 4, 2020 08:54
ImageCapture, ImageBitmap and canvas
// The theory is that we can avoid moving the video data into RAM since we are only
// passing the ImagieBitmap reference around, which should improve the performance when
// plotting captured frames.
const stream = await navigator.mediaDevices.getUserMedia({video: true})
const [track] = stream.getVideoTracks()
const ic = new ImageCapture(track)
const bmp = await ic.grabFrame()
@drslump
drslump / cities.csv
Last active August 4, 2018 09:43
Some sample data for testing jqlite
LatD LatM LatS NS LonD LonM LonS EW City State
41 5 59 N 80 39 0 W Youngstown OH
42 52 48 N 97 23 23 W Yankton SD
46 35 59 N 120 30 36 W Yakima WA
42 16 12 N 71 48 0 W Worcester MA
43 37 48 N 89 46 11 W Wisconsin Dells WI
36 5 59 N 80 15 0 W Winston-Salem NC
49 52 48 N 97 9 0 W Winnipeg MB
39 11 23 N 78 9 36 W Winchester VA
34 14 24 N 77 55 11 W Wilmington NC
@drslump
drslump / cities.csv
Created August 4, 2018 09:25
Some sample data for testing jqlite:
41 5 59 N 80 39 0 W Youngstown OH
42 52 48 N 97 23 23 W Yankton SD
46 35 59 N 120 30 36 W Yakima WA
42 16 12 N 71 48 0 W Worcester MA
43 37 48 N 89 46 11 W Wisconsin Dells WI
36 5 59 N 80 15 0 W Winston-Salem NC
49 52 48 N 97 9 0 W Winnipeg MB
39 11 23 N 78 9 36 W Winchester VA
34 14 24 N 77 55 11 W Wilmington NC
@drslump
drslump / fsm.py
Last active April 10, 2018 07:02
lexer
import sys, types, dis, struct
BINARY_SUBSCR = lambda: Op('BINARY_SUBSCR')
BUILD_TUPLE = lambda x: Op('BUILD_TUPLE', x)
COMPARE_OP = lambda x: Op('COMPARE_OP', x)
INPLACE_ADD = lambda: Op('INPLACE_ADD')
INPLACE_SUBTRACT = lambda: Op('INPLACE_SUBTRACT')
JUMP_ABSOLUTE = lambda x: Op('JUMP_ABSOLUTE', x)
LOAD_CONST = lambda x: Op('LOAD_CONST', x)
LOAD_FAST = lambda x: Op('LOAD_FAST', x)
#!/usr/bin/env bash
#
# Summary: Creates a temporary virtualenv based on a version
#
# Usage: pyenv COMMAND [version] [tmp-name]
#
# When no version is provided it'll use the currently configured
# one.
#
@drslump
drslump / jqlite
Last active April 22, 2020 13:07
jqlite: sql queries for tabular data
#!/usr/bin/env bash
#
# Copyright (C) 2018 Iván Montes <drslump@pollinimini.net>.
# This file is licensed under the MIT license.
#
# Requirements:
#
# - Bash 3.x or higher
# - sqlite3
# - gunzip / bzip2 (for compressed input)
@drslump
drslump / csv2json
Last active March 21, 2018 20:14
json2csv & csv2json
#!/usr/bin/env python
#
# Converts a CSV (with column headers) to JSONL
#
import sys, csv, json
for row in csv.DictReader(sys.stdin):
print(json.dumps(row))