Skip to content

Instantly share code, notes, and snippets.

View tupui's full-sized avatar
⚙️
Building Tansu

Pamphile Roy tupui

⚙️
Building Tansu
View GitHub Profile
@hjwp
hjwp / test_enums.py
Created October 27, 2020 14:03
Better string enums
import random
from enum import Enum, IntEnum
class BRAIN(str, Enum):
SMALL = "small"
MEDIUM = "medium"
GALAXY = "galaxy"
def __str__(self) -> str:
@tjluoma
tjluoma / km-timemachine-mount-run-unmount.sh
Last active November 15, 2024 10:27
a variation of 'timemachine-mount-run-unmount.sh' meant to be used with Keyboard Maestro
#!/usr/bin/env zsh -f
# Purpose: Once you set the DEVICE,
# this script will mount your Time Machine drive,
# run Time Machine,
# and then unmount the drive
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2020-04-20
@mchestr
mchestr / README.md
Last active June 16, 2021 09:07
Gandi DNS Updater

Gandi DNS Updater

Do you have a domain that is tied to a non-static IP, such as your home? This script when run from within your network will update your Gandi DNS to your public IP.

Setup

The following is an example of how to run this script.

@privatwolke
privatwolke / gather_dict.py
Created September 20, 2017 13:27
Python: Gather a dictionary of asyncio Task instances while preserving keys
async def gather_dict(tasks: dict):
async def mark(key, coro):
return key, await coro
return {
key: result
for key, result in await gather(
*(mark(key, coro) for key, coro in tasks.items())
)
}
@aunyks
aunyks / large-file-hash.py
Last active August 23, 2023 06:59
Hash a large file in Python
import hashlib as hash
# Specify how many bytes of the file you want to open at a time
BLOCKSIZE = 65536
sha = hash.sha256()
with open('kali.iso', 'rb') as kali_file:
file_buffer = kali_file.read(BLOCKSIZE)
while len(file_buffer) > 0:
sha.update(file_buffer)
@rougier
rougier / poisson-disk-sampling.py
Created November 15, 2016 16:42
Poisson disk sampling
def poisson_disk_sample(width=1.0, height=1.0, radius=0.025, k=30):
# References: Fast Poisson Disk Sampling in Arbitrary Dimensions
# Robert Bridson, SIGGRAPH, 2007
def squared_distance(p0, p1):
return (p0[0]-p1[0])**2 + (p0[1]-p1[1])**2
def random_point_around(p, k=1):
# WARNING: This is not uniform around p but we can live with it
R = np.random.uniform(radius, 2*radius, k)
T = np.random.uniform(0, 2*np.pi, k)
@jctosta
jctosta / screen_cheatsheet.markdown
Last active November 17, 2024 08:18
Screen Cheatsheet

Screen Quick Reference

Basic

Description Command
Start a new session with session name screen -S <session_name>
List running sessions / screens screen -ls
Attach to a running session screen -x
Attach to a running session with name screen -r
@n1k0
n1k0 / fallback.py
Created June 28, 2012 15:30
Attribute fallback in Python - useful when you cannot extend an existing class, or want a proxy
class Bar(object):
def plop(self):
print 'plop'
class Foo(object):
def __init__(self):
self.bar = Bar()
def do(self):
print 'done'