Skip to content

Instantly share code, notes, and snippets.

@thoroc
thoroc / open_nautilus.py
Last active Mar 25, 2021
show how to open nautilus (linux file explorer) from a Jupyter Notebook
View open_nautilus.py
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
Created Mar 25, 2021
How to list files in a Jupyter Notebook on a host
View list_files.py
from pathlib import Path
import ipywidgets as widgets
def get_files_widget(dir_path: str, extension_names: []):
""" Returns a widget to list the files in the given dir """
path = Path(Path.cwd(), dir_path)
extensions = extensions = [f'.{e}' for e in extension_names]
list_files = [f for f in path.iterdir() if f.is_file() and f.suffix in extensions]
list_files.sort(key=lambda f: f.stat().st_mtime, reverse=True)
@thoroc
thoroc / xkcd.ipynb
Created Mar 21, 2021
XKCD style graphs in Jupiter
View xkcd.ipynb
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 Feb 15, 2021
Convoluted way to retrieve AWS SSM parameters values with a common path
View README.md

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 Sep 29, 2020
Comments by a developer inside the Windows Media Player source code see https://pastebin.com/PTLeWhc2
View mplayer.c
[...]
/* RouteKeyPresses
*
* Reroutes cursor keys etc to track bar.
*/
void RouteKeyPresses(PMSG pMsg)
{
/* Hack for PowerPoint
*
* Mail from PaulWa:
@thoroc
thoroc / Makefile.new
Last active Sep 3, 2020
Create a list of targets for Makefile without having to write and maintain a list inside a `define HELP ... endef` block
View Makefile.new
.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 ""
View dict-to-args.py
#!/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 Aug 10, 2020
Removing and purging files from git history: https://blog.ostermiller.org/git-remove-from-history
View README.md

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 Jul 7, 2020
bellaso/vigenere cipher to encode and decode a string
View bellaso.py
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:
"""
@thoroc
thoroc / Fedora-recover-space.md
Last active Mar 30, 2020
Help! /dev/mapper/fedora-root out of free space. How can I fix this?
View Fedora-recover-space.md

Background

LVM has 3 layers:

  • PV: phisical volumes (Hard disks).
  • VG: volume groups, can spread across multiple PVs and can be expanded.
  • LV: logical volumes. These are the ones you map to mount points.

On top of you LV there is you file system.