Skip to content

Instantly share code, notes, and snippets.

@thalesmg
thalesmg / random-bitmask-corrupt.hs
Created October 9, 2022 15:39
Generate random bit masks for corrupting packets with probability
{-# LANGUAGE ScopedTypeVariables #-}
-- https://stackoverflow.com/questions/2075912/generate-a-random-binary-number-with-a-variable-proportion-of-1-bits
import Control.Monad (replicateM)
import Data.Bits
import Data.Foldable (foldl')
import Data.Word (Word8)
import Numeric.Natural (Natural)
import System.Random (Random, randomIO)
@thalesmg
thalesmg / trace.thm
Created September 22, 2022 01:17
Simple two-phase commit in Alloy 6
<?xml version="1.0"?>
<alloy>
<view>
<defaultnode/>
<defaultedge/>
<node>
@thalesmg
thalesmg / core.clj
Created May 3, 2022 19:35
example pulsar client using basic auth in clojure
(ns pulsar-test.core
(:import (org.apache.pulsar.client.api PulsarClient)))
(defn make-consumer
[]
(let [props (doto (java.util.Properties.)
(.putAll {"userId" "super"
"password" "superpass"}))
client (-> (PulsarClient/builder)
(.serviceUrl "pulsar://localhost:6650")
@thalesmg
thalesmg / PKGBUILD
Created February 24, 2022 21:12
alloy 6 aur patch for pkgbuild
# Alloy is developed by the Software Design Group at MIT.
# See https://sdg.csail.mit.edu/ or http://alloytools.org
# Maintainer: Markus Legner <[email protected]>
# Contributor: Ivan Kuraj <kaptoxic _at_ yahoo _dot_ com >
# Contributor: Rodney Price <[email protected]>
pkgname="alloy"
pkgver=6.0.0
pkgrel=1
pkgdesc="A lightweight modelling language for software design."
@thalesmg
thalesmg / print.hrl
Created December 17, 2021 19:42 — forked from uldza/print.hrl
Erlang pretty printing with ANSI console colors
%%%-------------------------------------------------------------------
%%% @author Ahmad Baitalmal
%%% @copyright (C) 2017, Ahmad Baitalmal
%%% Permission is hereby granted, free of charge, to any person obtaining
%%% a copy of this software and associated documentation files
%%% (the “Software”), to deal in the Software without restriction,
%%% including without limitation the rights to use, copy, modify, merge,
%%% publish, distribute, sublicense, and/or sell copies of the Software,
%%% and to permit persons to whom the Software is furnished to do so,
%%% subject to the following conditions:
@thalesmg
thalesmg / ssh_jump.py
Created December 2, 2021 18:21 — forked from tintoy/ssh_jump.py
SSH via jump-hosts using Paramiko
#!/usr/bin/env python3
import os
import paramiko
ssh_key_filename = os.getenv('HOME') + '/.ssh/id_rsa'
jumpbox_public_addr = '168.128.52.199'
jumpbox_private_addr = '10.0.5.10'
target_addr = '10.0.5.20'
@thalesmg
thalesmg / loop.hs
Last active October 9, 2021 17:24
Using ContT to abort an "infinite" loop (based on "Adventures in Looping")
{-
An alternative to the (almost) never ending looping problem
using the @ContT@ monad transformer.
Based on the post by Drew Olson:
https://blog.drewolson.org/adventures-in-looping
-}
module Main where
@thalesmg
thalesmg / river_crossing_auto.v
Created September 8, 2021 16:56
Wolf/goat/cabbage, or fox/chicken/grain, or river crossing puzzle in Coq, with automation
From Coq Require Import Lists.List. Import ListNotations.
Inductive Object :=
| Wolf
| Goat
| Cabbage.
Inductive Direction :=
| Right
| Left.
@thalesmg
thalesmg / river_crossing.v
Created September 8, 2021 14:35
Wolf, goat and cabbage puzzle in Coq
From Coq Require Import Lists.List. Import ListNotations.
Inductive Object :=
| Wolf
| Goat
| Cabbage.
Inductive Direction :=
| Right
| Left.
@thalesmg
thalesmg / shell.nix
Created July 21, 2021 20:18
elixir 1.12 e erlang 24 phoenix derivation
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
elixir_1_12 = { mkDerivation }:
mkDerivation rec {
version = "1.12.0";
sha256 = "00dc3szjn2k552jp7n1c98kjab6wac9d49v2gr43pf3yzcyv8mk1";
minimumOTPVersion = "24";