Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Fitzhardinge bendog

View GitHub Profile
@bendog
bendog / pyproject.toml
Last active Apr 2, 2020
black rules for django projects
View pyproject.toml
[tool.black]
line-length = 120
target_version = ['py37']
exclude = '''
(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.hg
| \.mypy_cache
View install_zsh.md

setting up zsh

install and setup zsh

echo $SHELL

if this is zsh go to the next stage, if not check zsh is installed

which zsh
@bendog
bendog / django_functional_view_to_class_based_view.md
Last active Feb 17, 2022
Django functional view to class based view refactoring
View django_functional_view_to_class_based_view.md

Django functional view to class based view refactoring

To understand what's happening with django generic class based views, lets create a function view where we handle all of the functionality explicity, then migrate the functionality to a class.

Setup the model and form

First let's setup the supporting files.

Create the models

@bendog
bendog / AWS API Gateway Python3 Lambda JWT Authentication.md
Last active Jan 29, 2022
Python3.6 AWS Api Gateway Lambda based JWT authentication code and lambda type hints.
View AWS API Gateway Python3 Lambda JWT Authentication.md

AWS Lambda JWT authenticaiton

AWS API Gateway has the ability to pre-authenticate connections prior to launching the endpoint, by passing the authorizationToken to a Lambda function. There are clear benefits for simplifying end point security and also a reduction in duplicated code by utilising this feature. However I found the AWS examples were excessively complicated for what should be a very simple task.
So here's my example.

The main concern is that AWS Lambda authentication expects a very specific response and if that response is not given it will throw a 500 error with x-amzn-ErrorType: AuthorizerConfigurationException in the response header if the response object is not exactly as expected.

Usage

I personally use to handle the publishing part of my Lambdas, but I'll include an image of the API Gateway config.

@bendog
bendog / timed_cache_helper.py
Created Sep 10, 2018
Python functools.lru_cache with timeout and passing lru_cache kwargs
View timed_cache_helper.py
import functools
import datetime
def timed_cache(maxsize=128, typed=False, **timedelta_kwargs):
def _wrapper(f):
update_delta = datetime.timedelta(**timedelta_kwargs)
next_update = datetime.datetime.utcnow() - update_delta
# Apply @lru_cache to f with no cache size limit
f = functools.lru_cache(maxsize=maxsize, typed=typed)(f)
@bendog
bendog / ssh
Last active Aug 16, 2017
~/bin/ssh wrapper to change Mac OS Terminal profiles when running SSH
View ssh
#!/bin/sh
HOSTNAME=`echo $@ | sed s/.*@//`
set_bg () {
osascript -e "tell application \"Terminal\" to set current settings of window 1 to (first settings set whose name is \"$1\")"
}
on_exit () {
set_bg "BenDog"
@bendog
bendog / select_report.md
Last active Jul 11, 2017
template for selecting reports
View select_report.md
<select id="reportFileName">
    {% for report in reports_list %}
        {% if report.year %}
            {% for year in years %}
                <option value="{{ report.id }}_{{ report.params }}_{{ year }}.html"> {{ report.name }} {{year}}</option>
                {% for month in months %}
                    <option value="{{ report.id }}_{{ report.params }}_{{ year }}_{{ month}}.html"> {{ report.name }} {{year}} {{month}}</option>
                {% end for %}
 {% end for %}
View keybase.md

Keybase proof

I hereby claim:

  • I am bendog on github.
  • I am bendog (https://keybase.io/bendog) on keybase.
  • I have a public key ASBVVsxFRCokBbBb4dblwEIsU-1_4JayCCC1ZpvFh3yEyQo

To claim this, I am signing this object:

@bendog
bendog / ben.fitzhardinge.resume.md
Last active Nov 10, 2021
Ben Fitzhardinge Resume
View ben.fitzhardinge.resume.md

Ben Fitzhardinge

ben@fitzhardinge.net

Personal Statement

I'm passionate about elegant systems, whether these are for software solutions, managing people, documenting complex problems, or for helping people connect and become more productive.
I believe all systems should help and not hinder the users.

I'm a firm believer in iterative design and Agile methodologies, however in true agile form, I believe the best methodologies should be more like principles. Principles which we can borrow from when it makes sense, not laws which must be obeyed. However when presented with a problem I will always suggest we work towards a minimum viable product, get it out in the hands of the intended audience, and then get the feedback required to make it what it needs to become.