Skip to content

Instantly share code, notes, and snippets.

View bartmachielsen's full-sized avatar

Bart bartmachielsen

  • Vertical Data Analytics
  • Breda, Netherlands
View GitHub Profile
@bartmachielsen
bartmachielsen / login_required.py
Created January 28, 2019 13:23
login required middleware
from django.http import HttpResponseRedirect
from django.conf import settings
from re import compile
EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))]
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
class LoginRequiredMiddleware:
"""
@bartmachielsen
bartmachielsen / 00.install-android-sdk.sh
Created March 23, 2021 12:53 — forked from nhtua/00.install-android-sdk.sh
Run a Headless Android Device on Ubuntu server (no GUI)
#!/bin/bash -i
#using shebang with -i to enable interactive mode (auto load .bashrc)
set -e #stop immediately if any error happens
# Install Open SDK
apt update
apt install openjdk-8-jdk -y
update-java-alternatives --set java-1.8.0-openjdk-amd64
java -version
@bartmachielsen
bartmachielsen / audit_logging.py
Last active March 26, 2023 17:41
Django Auditlogging in combination with Django rest framework
from __future__ import unicode_literals
import threading
import time
from django.conf import settings
from django.db.models.signals import pre_save
from django.utils.functional import curry
from django.apps import apps
from auditlog.models import LogEntry
@bartmachielsen
bartmachielsen / pin_dependancies.py
Created November 9, 2023 09:35
Pin dependancies for Poetry
from pathlib import Path
import pkg_resources
import toml
def pin_dependency_version(dependency_name, installed_packages):
# If the package is in the installed packages and it's not a path or git dependency
if dependency_name in installed_packages and isinstance(dependency_name, str):
# Pin the version to the one currently installed, allowing compatible updates
@bartmachielsen
bartmachielsen / update_ecs_instance_types.py
Created November 17, 2023 13:55
Update ECS instance types using spot info
"""Update ECS Instance Types.
# Check if spotinfo command is installed
if ! command -v spotinfo &> /dev/null
then
echo "spotinfo could not be found, please install it"
# Brew install spotinfo
brew tap alexei-led/spotinfo
brew install spotinfo
fi