Skip to content

Instantly share code, notes, and snippets.

View alecco's full-sized avatar

Alecco alecco

View GitHub Profile
@alecco
alecco / lwt_error_handling.py
Last active August 30, 2020 14:58
Cassandra and ScyllaDB LWT error handling dtest example
from dtest import Tester, debug
from cassandra import ConsistencyLevel
class LWTExample(Tester):
def test_lwt(self):
cluster = self.cluster
cluster.populate(4)
cluster.start(wait_other_notice=True, wait_for_binary_proto=True)
node = cluster.nodelist()[0]
session = self.patient_cql_connection(node)
-- Note: example given is for SQLite but can be adapted to other SQL
-- This is a fast query to sample random rows
-- It gets a list of existing row identifiers (rowids),
-- materializes, sorts, and picks 10.
SELECT * FROM test
WHERE rowid IN
(SELECT rowid FROM test
ORDER BY random() LIMIT 10);
# What if n nodes are assigned a random tick wait (of 1 to 10)
# to wait to become candidates when the previous leader is down?
# What is the chance of 2 candidates having the same random
# wait (birthday paradox) AND this wait to be the shortest wait.
# What's the amount of nodes with ~90% chance of dueling candidates?
# Answer: 36ish
# Based on:
# https://codecalamity.com/the-birthday-paradox-the-proof-is-in-the-python/
from random import randint
import matplotlib.pyplot as plt
# What if n nodes are assigned a random tick wait (of 1 to 10)
# to wait to become candidates when the previous leader is down?
# What is the chance of 2 candidates having the same random
# wait (birthday paradox) AND this wait to be the shortest wait.
# What's the amount of nodes with ~90% chance of dueling candidates?
# Answer: 36ish
# Based on:
# https://codecalamity.com/the-birthday-paradox-the-proof-is-in-the-python/
from random import randint
import matplotlib.pyplot as plt
@alecco
alecco / candidates.py
Last active June 22, 2021 00:08
Raft dueling candidates with power distribution
# What if n nodes are assigned a random tick wait (of 1 to 10)
# to wait to become candidates when the previous leader is down?
# What is the chance of 2 candidates having the same random
# wait (birthday paradox) AND this wait to be the shortest wait.
# What's the amount of nodes with ~XX% chance of dueling candidates?
# Based on:
# https://codecalamity.com/the-birthday-paradox-the-proof-is-in-the-python/
#
# For power distribution
#
// g++ -lfmt exponential.cc -o exponential && ./exponential <lambda>
//
// Using lambda 0.3
// 01: 1% 00189 - ***
// 02: 2% 00275 - *****
// 03: 3% 00330 - ******
// 04: 4% 00430 - ********
// 05: 6% 00613 - ************
// 06: 8% 00839 - ****************
// 07: 11% 01104 - **********************
# https://www.redhat.com/sysadmin/podman-inside-container
# https://fedoramagazine.org/podman-with-capabilities-on-fedora/
# https://wiki.debian.org/CrossCompiling
# XXX need to run as root as debootstrap needs mknod privilege
sudo podman pull debian:stable-slim
sudo podman run -it --cap-add=all --privileged debian:stable-slim
# set -o vi
# cat >> /etc/apt/sources.list
@alecco
alecco / CMakeLists.txt
Last active June 16, 2024 07:42
Minimal CMakeLists.txt for CUTLASS
cmake_minimum_required(VERSION 3.20)
project(YOUR_PROJECT_NAME LANGUAGES CXX CUDA)
# you might want C++17
set(CMAKE_CUDA_STANDARD 20) # C++20
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # generate compile_commands.json