Skip to content

Instantly share code, notes, and snippets.

thoroc /
Last active Mar 25, 2021
show how to open nautilus (linux file explorer) from a Jupyter Notebook
import subprocess
output_path = Path('output')
list_files = [ 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)['nautilus', dir_path])
thoroc /
Created Mar 25, 2021
How to list files in a Jupyter Notebook on a host
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 / 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 /
Last active Feb 15, 2021
Convoluted way to retrieve AWS SSM parameters values with a common path


ssm_name_suffixes = ['name', 'host', 'schema']

db_params = aws_ssm.get_parameters(env_keys=env_keys, ssm_name_suffixes=ssm_name_suffixes)
thoroc / mplayer.c
Created Sep 29, 2020
Comments by a developer inside the Windows Media Player source code see
View mplayer.c
/* RouteKeyPresses
* Reroutes cursor keys etc to track bar.
void RouteKeyPresses(PMSG pMsg)
/* Hack for PowerPoint
* Mail from PaulWa:
thoroc /
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
.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 ""
import os
from faker import Faker
from faker.providers import internet, lorem
from tabulate import tabulate
fake = Faker()
thoroc /
Last active Aug 10, 2020
Removing and purging files from git 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 /
Last active Jul 7, 2020
bellaso/vigenere cipher to encode and decode a string
class Cipher:
def __init__(self, key: str):
self.key = key
def encode(self, text: str, key: str = None) -> str:
thoroc /
Last active Mar 30, 2020
Help! /dev/mapper/fedora-root out of free space. How can I fix this?


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.