Skip to content

Instantly share code, notes, and snippets.

View bendog's full-sized avatar

Ben Fitzhardinge bendog

View GitHub Profile
@bendog
bendog / README.md
Created January 19, 2023 05:53
Remove *.pyc files from your python project repo

Remove .pyc files from your Python project git repo.

Here are a collection of command line arguments, which will help you fix your issues with .pyc files.

1. Prepare for your change

Go to your project root, the folder which is the base of your git repo.

Make sure your project is up to date with your remote, run git fetch

@bendog
bendog / pyproject.toml
Last active April 2, 2020 07:31
black rules for django projects
[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
@bendog
bendog / install_zsh.md
Last active November 7, 2024 07:53
ZSH setup

setting up zsh

install HomeBrew for Mac

go to https://brew.sh

Note: Be sure to run the commands which brew tells you to run at the end of your brew install!

install and setup zsh

@bendog
bendog / django_functional_view_to_class_based_view.md
Last active February 17, 2022 23:46
Django functional view to class based view refactoring

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 October 19, 2023 10:32
Python3.6 AWS Api Gateway Lambda based JWT authentication code and lambda type hints.

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 September 10, 2018 05:03
Python functools.lru_cache with timeout and passing lru_cache kwargs
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 August 16, 2017 04:58
~/bin/ssh wrapper to change Mac OS Terminal profiles when running 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 July 11, 2017 04:25
template for selecting reports
<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 %}
@bendog
bendog / keybase.md
Created July 5, 2017 01:54
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 November 26, 2023 02:23
Ben Fitzhardinge Resume

Ben Fitzhardinge

[email protected]

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.