Skip to content

Instantly share code, notes, and snippets.

@thoroc
thoroc / git-mailmap.py
Created June 29, 2021 16:44
create mailmap file from git repo
from pathlib import Path
from git import Repo
class Contributor:
def __init__(self, name: str, email: str) -> None:
self.name = name
self.email = email
def __eq__(self, other):
@thoroc
thoroc / open_nautilus.py
Last active March 25, 2021 14:08
show how to open nautilus (linux file explorer) from a Jupyter Notebook
import subprocess
output_path = Path('output')
list_files = [f.name for f in output_path.iterdir() if f.is_file() and f.suffix == f'.csv']
for f in list_files:
if my_file in f:
print(f'found the file: {f}')
dir_path = Path(Path.cwd(), output_path)
subprocess.call(['nautilus', dir_path])
@thoroc
thoroc / list_files.py
Last active August 18, 2021 13:52
How to list files in a Jupyter Notebook on a host
from pathlib import Path
import ipywidgets as widgets
from IPython.display import display
def get_files_widget(dir_path: str, extension_names: list[str], order_by_date=True) -> widgets.Dropdown:
""" Returns a widget to list the files in the given dir. """
path = Path(Path.cwd(), dir_path)
extensions = [f'.{e}' for e in extension_names]
objects = [f for f in path.iterdir() if f.is_file() and f.suffix in extensions]
@thoroc
thoroc / xkcd.ipynb
Created March 21, 2021 12:04
XKCD style graphs in Jupiter
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thoroc
thoroc / README.md
Last active February 15, 2021 15:03
Convoluted way to retrieve AWS SSM parameters values with a common path

Usage

env_keys = ['SSM_NAME_PREFIX', 'SSM_DB_PASSWORD', 'DB_PORT', 'DB_USERNAME']
ssm_name_suffixes = ['name', 'host', 'schema']

db_params = aws_ssm.get_parameters(env_keys=env_keys, ssm_name_suffixes=ssm_name_suffixes)
@thoroc
thoroc / mplayer.c
Created September 29, 2020 10:31
Comments by a developer inside the Windows Media Player source code see https://pastebin.com/PTLeWhc2
[...]
/* RouteKeyPresses
*
* Reroutes cursor keys etc to track bar.
*/
void RouteKeyPresses(PMSG pMsg)
{
/* Hack for PowerPoint
*
* Mail from PaulWa:
@thoroc
thoroc / Makefile.new
Last active September 3, 2020 19:39
Create a list of targets for Makefile without having to write and maintain a list inside a `define HELP ... endef` block
.DEFAULT_GOAL := help
.PHONY: help
help: ## Displays this list and descriptions of available targets
@echo ""
@echo "targets:"
@echo ""
@awk -F ':|##' '/^[^\t].+:.*##/ {printf "\033[36mmake % -30s\033[0m -%s\n", $$1, $$NF }' $(MAKEFILE_LIST) | sort
@echo ""
#!/bin/python3
import os
from faker import Faker
from faker.providers import internet, lorem
from tabulate import tabulate
fake = Faker()
fake.add_provider(internet)
fake.add_provider(lorem)
@thoroc
thoroc / README.md
Last active August 10, 2020 08:16
Removing and purging files from git history: https://blog.ostermiller.org/git-remove-from-history

Occasionally, a git source code repository needs to have something removed from it permanently, even from the history.

Step 1: Create a clone of the repository

Replace MY_GIT_REPOSITORY with the URL of your git repository. This will also track all the branches so all branches can be cleaned as well. (source)

cd /tmp
git clone MY_GIT_REPOSITORY.git workingrepo
cd workingrepo
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do
@thoroc
thoroc / bellaso.py
Last active July 7, 2020 09:56
bellaso/vigenere cipher to encode and decode a string
class Cipher:
"""
https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
"""
def __init__(self, key: str):
self.key = key
def encode(self, text: str, key: str = None) -> str:
"""