Skip to content

Instantly share code, notes, and snippets.

View cjmakes's full-sized avatar
🍖
Hungry

Connor Jones cjmakes

🍖
Hungry
View GitHub Profile
@cjmakes
cjmakes / flake.nix
Created October 7, 2024 05:52
nix flake for python opencv playing video file
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
}:

Validate a NIF

Número De Identificação Fiscal or NIF, is the nine digit number which is used to identify a tax paying entity in Portugal. Any NIF can be validated using the mod 11 algorithm with one twist. I will describe what that twist is and how it affects validating a NIF.

When you buy anything in Portugal, in person or online, you give your NIF. This includes everything from the 100€ you spend on your mall haul, to the 2€ you spend on an espresso and a pastel de nata.

This number is relayed often so mistakes are very possible. Possible causes are bit flips during transmission when buying online — or mispronouncing seis as sete. To address this, an algorithm exists to determine if any give series of nine digits is a valid NIF. It can be defined as:

let n_i be the ith digit of the NIF as numbered from right to left. Then a NIF is valid if:

@cjmakes
cjmakes / fou.lua
Last active November 10, 2021 00:29
FOU Lua dissector for wireshark
-- Implements FOU packet parsing in wireshark
-- Place this file at ~/.local/lib/wireshark/plugins/fou.lua
-- FOU: https://lwn.net/Articles/614348/
-- by conjones
fou_protocol = Proto("fou","Foo Over UDP Protocol")
function fou_protocol.dissector(buffer, pinfo, tree)
pinfo.cols.protocol = "FOU"
Dissector.get("ip"):call(buffer():tvb(), pinfo, tree)
end