Skip to content

Instantly share code, notes, and snippets.

@Ogaday
Ogaday / README.md
Created October 21, 2019 17:31
Rebracer

Python Kata by @nhumrich of the Pythondev Slack communtiy.

Write a function that takes in a string, and returns a string with everything inside curly brackets {} removed. Example: hello {world} returns hello {}. Example 2: {hello} {world} returns {} {}

Only submissions that DO NOT use regex will be accepted for taco's

tacos for: 1st, cleanest, shortest, fastest, my choice

nested doesn't count. So { hello {something} there} should return: {}

@Ogaday
Ogaday / README.md
Last active March 9, 2020 12:36
Tranpose Dict

Dictionary puzzle of the week:

The objective is to write an expression or function that, given a dictionary in which each value is a list, transpose it so the result is list of dictionaries, where:

  • The keys of each new dictionary are the same as the keys of the original dictionary
  • The values of the ith dictionary correspond to the ith elements of the values of the original dictionary

If that doesn't make sense, here's an example:

# Input:
@Ogaday
Ogaday / date_range.py
Created March 9, 2020 13:05
Date Range
from datetime import datetime, timedelta
from typing import Iterator
def date_range(
start: datetime,
stop: datetime,
step: timedelta
) -> Iterator[datetime]:
"""
@Ogaday
Ogaday / README.md
Last active August 7, 2022 13:33
Prefect on Dask on Kubernetes
@Ogaday
Ogaday / accents.md
Created April 29, 2020 18:48
Accents on linux

On my set up at least:

shift + alt gr ' <vowel>: áéíóú  
shitf + alt gr ` <vowel>: àèìòù  
shift + alt gr - <vowel>: āēīōū
@Ogaday
Ogaday / README.md
Created July 20, 2020 10:25
Parsing RFC 822 timestamps

Comparison using the python date format spec to parse RFC-822 date strings vs using dateutil.

In [1]: from timeit import timeit 
   ...: from time_rfc_822 import parse_RFC_822_naive, parse_RFC_822_dateutil 
   ...: sample_date_string = 'Fri, 06 Mar 2020 14:22:22 GMT' 
   ...: %timeit parse_RFC_822_naive(sample_date_string) 
   ...: %timeit parse_RFC_822_dateutil(sample_date_string)                                                                                                                                                                                                                                
17.5 µs ± 805 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
154 µs ± 12.6 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
@Ogaday
Ogaday / INSTALLING_PYTHON.md
Last active August 18, 2023 13:55
Installing Python From Source

Installing Python From Source

Installing Python on Linux isn't so hard. These are my notes for installing on Ubuntu.

  1. Install build dependencies using apt.
  2. Choose and download the version of Python you'd like to install from the releases page.
  3. Extract the directory
  4. Run ./configure and make to install
@Ogaday
Ogaday / README.md
Last active January 13, 2022 12:59
Mocking HTTP requests in Click

Mocking HTTP Requests in Click

Simple MVP to test mocking of HTTP requests made in Click commands using the responses library.

In simple_post.py we have a Click command that makes a request to https://httpbin.org, a useful API for testing requests.

In test_simple_post.py we have a test suite which can be run by PyTest. In the first

@Ogaday
Ogaday / AOC.md
Last active December 6, 2022 15:25
Advent of Code - Getting Started

Advent of Code - Getting Started

Some pointers for getting started with the Advent of Code.

You can run the notebook interactively here:

Binder

@Ogaday
Ogaday / argmax.py
Last active December 1, 2022 19:20
Native Argmax
"""
A native implementation of argmax.
https://towardsdatascience.com/there-is-no-argmax-function-for-python-list-cd0659b05e49
Tests::
pytest --doctest-modules -vvv argmax.py
Linting::