Skip to content

Instantly share code, notes, and snippets.

View thebertster's full-sized avatar

Roberto Casula thebertster

  • WW Specialist Solution Architect (Avi)
  • United Kingdom
View GitHub Profile
@thebertster
thebertster / .pylintrc
Last active November 29, 2023 19:53
Pylint settings
# This Pylint rcfile contains a best-effort configuration to uphold the
# best-practices and style described in the Google Python style guide:
# https://google.github.io/styleguide/pyguide.html
#
# Its canonical open-source location is:
# https://google.github.io/styleguide/pylintrc
[MAIN]
# Files or directories to be skipped. They should be base names, not paths.
@thebertster
thebertster / bert.omp.json
Last active November 27, 2023 18:48
Bert's Oh-My-Posh Theme
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"newline": true,
"segments": [
{
"background": "#26BDBB",
"foreground": "#0C212F",
@thebertster
thebertster / keyboard_distance.py
Last active October 10, 2021 18:24
Matt Parker's ridiculous keyboard distance thingy
from math import sqrt, acos, degrees
class KeyboardDistance:
def __init__(self, rows=None, offset=None, key_size=19.05):
rows = rows or ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']
offset = offset or [0, 0.25, 0.75]
self.vectors = {}
@thebertster
thebertster / teacoffee.yaml
Last active September 9, 2021 17:38
Tea and coffee?
---
apiVersion: v1
kind: Service
metadata:
name: coffee-svc
labels:
app: coffee
spec:
ports:
- port: 80
@thebertster
thebertster / trapped_knight.py
Created January 27, 2019 23:26
Trapped Knight Visualisation
import turtle
import colorsys
def position(x, y):
square = max(abs(x), abs(y))
return 1 + 4*square*square + (-1, 1)[x<=-y]*(abs(square + x) +
abs(square - y))
turtle.setworldcoordinates(-28, -28, 28, 28)
turtle.ht()
@thebertster
thebertster / miller_rabin.py
Last active July 7, 2019 20:27
Miller-Rabin Primality Test
from random import randint
class MillerRabin:
@staticmethod
def power_mod(a, b, c):
"""Calculate a^b % c using exponentiation by squaring."""
if c == 1:
return 0
r = 1
a = a % c
@thebertster
thebertster / stars_and_bars.py
Last active March 20, 2023 19:52
Python generator which produces the "Stars and Bars" (a.k.a. "Stars and Stripes") combinatorial sequence, i.e. number of ways of distributing n indistuingishible objects between k distinguishible bins
def StarsAndBars(bins, stars, reverse=False, allowEmpty=True):
"""
Non-recursive generator that returns the possible ways that n
indistinguishable objects can be distributed between k distinguishible bins
(allowing empty bins).
Total # arrangements = (n+k-1)! / n!(k-1)! if empty bins are allowed
Total # arrangements = (n-1)! / (n-k)!(k-1)! if empty bins are not allowed
Parameters