Skip to content

Instantly share code, notes, and snippets.

View martin-martin's full-sized avatar
⛰️
hill view from the balcony

Martin Breuss martin-martin

⛰️
hill view from the balcony
View GitHub Profile
import numpy as np
def create_deck():
RANKS = '2 3 4 5 6 7 8 9 10 J Q K A'.split()
SUITS = '♣ ♢ ♡ ♠'.split()
return np.array([r + s for s in SUITS for r in RANKS])
print(create_deck())
# ['2♣' '3♣' '4♣' '5♣' '6♣' '7♣' '8♣' '9♣' '10♣' 'J♣' 'Q♣' 'K♣' 'A♣' '2♢'
# '3♢' '4♢' '5♢' '6♢' '7♢' '8♢' '9♢' '10♢' 'J♢' 'Q♢' 'K♢' 'A♢' '2♡' '3♡'
# Auto-activate virtual environments on cd when it's called `venv/`
# auto activate virtualenv
# Modified solution based on https://stackoverflow.com/questions/45216663/how-to-automatically-activate-virtualenvs-when-cding-into-a-directory/56309561#56309561
function cd() {
builtin cd "$@"
## Default path to virtualenv in your projects
DEFAULT_ENV_PATH="./venv"
## If env folder is found then activate the vitualenv
@martin-martin
martin-martin / coco_final.py
Created September 1, 2022 14:09
Potential code for answering the question (errors bubble up)
# How can I make sure that the exception messages
# of Exceptions that occur in the sub-function `load_model()`
# show up in the stack trace of the `main()` function?
class UnsupportedInputError(Exception): pass
class SourceEqualsTargetError(Exception): pass
supported_inputs = ["a", "b", ...]
@martin-martin
martin-martin / settings.json
Created November 26, 2021 18:49
VS Code workspace settings JSON file with sensible default settings for video recording at Real Python
{
"window.zoomLevel": 3,
"workbench.startupEditor": "none",
"workbench.editorAssociations": {
"*.ipynb": "jupyter.notebook.ipynb"
},
// remove distracting elements
"breadcrumbs.enabled": false,
"editor.minimap.enabled": false,
"workbench.statusBar.visible": false,
def modify_make_command(arguments, project_path, parent_folder, folder, suffix):
if arguments == config.benchmark.BENCHMARK["HPCG"].url:
for sub_path in Path(project_path.joinpath("apps", parent_folder, folder)):
shell_execute(f"make arch={suffix}", sub_path.parent.as_posix())
if arguments == config.benchmark.BENCHMARK["CLOVERLEAF"].url:
for sub_path in Path(project_path).glob(f"**/**/?akefile"):
shell_execute(
"make COMPILER = GNU MPI_COMPILER = gfortran C_MPI_COMPILER = gcc",
sub_path.parent.as_posix(),
)
print("hellow")
@martin-martin
martin-martin / lesson-checker.py
Last active July 28, 2021 13:14
Check for correct frame rate and aspect ratio of each video lesson, and determine total length of the course
# Requires installation of `ffmpeg` and `ffmpeg-python`:
# - https://www.ffmpeg.org
# - https://pypi.org/project/ffmpeg-python/
import fractions
from pathlib import Path
import ffmpeg
@martin-martin
martin-martin / times.py
Created July 12, 2021 13:50
Find and add lesson times mentioned in a Markdown document
from pathlib import Path
import re
with open('outline.md', 'r') as f_in:
content = f_in.read()
# Finds all time mentions in the format shown below
pattern = r'\((\d+)\smin\)' # (3 min)
minutes = re.findall(pattern, content)
import argparse
from pathlib import Path
import re
import sys
my_parser = argparse.ArgumentParser(description='List Markdown headings')
my_parser.add_argument('Path',
metavar='path',
type=str,
@martin-martin
martin-martin / rescrape.py
Created March 29, 2021 13:37
Example scraper and scraper test solution
import requests
from bs4 import BeautifulSoup
BASE_URL = "https://codingnomads.github.io/recipes/"
def get_page_content(url):
"""Gets the response from a HTTP call to the URL."""
page = requests.get(url)
return page