Skip to content

Instantly share code, notes, and snippets.

View tuck1s's full-sized avatar

tuck1s tuck1s

View GitHub Profile
@tuck1s
tuck1s / leaves.py
Last active November 30, 2023 10:54
from copy import deepcopy
from collections import deque
# Expand a tree to the "leaves"
def leaves_of(item, dependencies):
# return the leaf nodes
def dfs2(item, level, visited):
result = []
if item in dependencies:
@tuck1s
tuck1s / push_loki2.py
Created November 5, 2023 17:28
example of grafana/loki api when you need push any log/message from your python script
#!/usr/bin/env python3
# example of grafana/loki api when you need push any log/message from your python script
import requests, time
import names # get some random data
nano_ts = int(time.time()*1e9)
name = names.get_full_name()
# push msg log into grafana-loki
url="http://localhost:3100/loki/api/v1/push"
#!/usr/bin/env python3
import re, sys, csv, argparse
from datetime import datetime
myTimezone = '' # does rclone log in locale timezone?
def perror(str):
print(str, file=sys.stderr)
# Function operates "in place" by reference on dict d, i.e. has side-effects on d
@tuck1s
tuck1s / README.md
Created August 15, 2022 15:00
Taxi for Email images

This is a placeholder file so we can host images.

package main
import (
"constraints"
"fmt"
)
type Number interface {
constraints.Integer | constraints.Float | constraints.Complex
}
#!/usr/bin/env python3
# External dependencies: https://github.com/treyhunner/names
import random, names
count_default = 10 # Default length of list
def random_n_digits(n):
s = ''
for i in range(n):
s += random.choice('0123456789')
#!/usr/bin/env python3
import imaplib, os
# Very simple IMAP client - prints messages in inbox
imap_host = os.getenv('IMAP_HOST')
imap_user = os.getenv('IMAP_USER')
imap_pass = os.getenv('IMAP_PASSWORD')
# connect to host using SSL
imap = imaplib.IMAP4_SSL(imap_host)
@tuck1s
tuck1s / count-domains.py
Last active July 3, 2020 17:17
Simple tool to count distinct domains in a [list of] file or stdin
#!/usr/bin/env python3
import argparse, csv, sys
import dns.resolver
def domainpart(n):
# A valid email address contains exactly one @, otherwise return None = invalid
parts = n.split('@')
if len(parts) == 2:
return parts[1]
return None
#!/usr/bin/env python3
# Bubble blaster game from Carol Vorderman book pp.164 onwards
from tkinter import *
HEIGHT = 500
WIDTH = 800
window = Tk()
window.title("Bubble Blaster")
window.attributes("-topmost", 1)