Skip to content

Instantly share code, notes, and snippets.

View Hultner's full-sized avatar
📯
What are you trying to shell?

Alexander Hultnér Hultner

📯
What are you trying to shell?
View GitHub Profile
@Hultner
Hultner / sql_murder_mystery.sql
Created December 25, 2019 11:55
SQL Murder Mystery
-- You vaguely remember that the crime was a ​murder​
-- that occurred sometime on ​Jan.15, 2018​ and that
-- it took place in ​SQL City​.
/*
select *
from crime_scene_report csr
where
csr.date = '20180115'
and type = 'murder'
and lower(city) = 'sql city'
@Hultner
Hultner / pep572.py
Created February 7, 2019 18:22
PEP 572
# From: https://www.python.org/dev/peps/pep-0572/#syntax-and-semantics
# Handle a matched regex
if (match := pattern.search(data)) is not None:
# Do something with match
# A loop that can't be trivially rewritten using 2-arg iter()
while chunk := file.read(8192):
process(chunk)
@Hultner
Hultner / walrus.py
Last active June 16, 2019 10:25
Python 3.8 Walrus operator PEP 572 Example
sample_data = [
{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": False},
{"userId": 1, "id": 2, "title": "quis ut nam facilis", "completed": False},
{"userId": 1, "id": 3, "title": "fugiat veniam minus", "completed": False},
{"userId": 1, "id": 4, "title": "et porro tempora", "completed": True},
{"userId": 1, "id": 4, "title": None, "completed": True},
]
print("With Python 3.8 Walrus Operator:")
for entry in sample_data:
@Hultner
Hultner / pyenv-shell-38.sh
Created February 7, 2019 14:58
Use python 3.8 through pyenv
$ pyenv shell 3.8-dev
$ python --version
$ python
@Hultner
Hultner / pyenv-install-38-dev.sh
Created February 7, 2019 14:57
Install python 3.8 dev
$ pyenv install --list | grep 3.8
$ pyenv install 3.8-dev
@Hultner
Hultner / pyenv-install-38-dev.sh
Created February 7, 2019 14:57
Install python 3.8 dev
$ pyenv install --list | grep 3.8
$ pyenv install 3.8-dev
@Hultner
Hultner / zlib.sh
Created February 7, 2019 14:36
zlib
# Install zlib
brew install zlib
# Add zlib-variables to your shell.
tee -a ~/.profile <<<CONF
export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
CONF
@Hultner
Hultner / pyenv.sh
Created February 7, 2019 14:01
Python 3.8 instructions
$ brew update
$ brew install pyenv
@Hultner
Hultner / conftest.py
Last active October 30, 2020 02:32
pytest: Save failures with details to file
# content of conftest.py
import pytest
import os.path
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield