Skip to content

Instantly share code, notes, and snippets.

View rj76's full-sized avatar

Richard Jansen rj76

  • The Hague, The Netherlands
View GitHub Profile
@rj76
rj76 / gradient_descent.py
Created August 7, 2021 14:59
gradient descent
theta0 = 0
theta1 = 0
alpha = .2
dataset = [
{'x': 1, 'y': 0.5},
{'x': 2, 'y': 1},
{'x': 4, 'y': 2},
{'x': 0, 'y': 0},
@rj76
rj76 / find_encoding.py
Created July 15, 2021 08:01
Find encodings for a char
import pkgutil
import encodings
import os
def all_encodings():
modnames = set([modname for importer, modname, ispkg in pkgutil.walk_packages(
path=[os.path.dirname(encodings.__file__)], prefix='')])
aliases = set(encodings.aliases.aliases.values())
return modnames.union(aliases)
@rj76
rj76 / templatetags_acl.py
Created June 29, 2021 19:19
Django templatetag ACL implementation
# templatetags
from django import template
from apps.core import utils
register = template.Library()
module_paths_text = None
modules = {}
@rj76
rj76 / django-key-rotation.md
Created November 28, 2019 12:51
Idea to rotate keys of encrypted django fields

key rotation

  • switch to django-fernet-fields
  • django-dbsettings
  • modify to fetch key from db in stead of settings
  • store keys in encrypted table using pgcrypt (per tentant?)
  • figure out rotation algorithm
@rj76
rj76 / nmbrs.py
Last active November 4, 2019 13:25
Django implementation for communicating with Nmbrs' SOAP API
import datetime
from django.conf import settings
from tenant_schemas.utils import tenant_context
from zeep import Client
from apps.company import models
from apps.member.models import Tenant
@rj76
rj76 / wordpress.py
Last active October 31, 2019 10:19
WordPress :/
import json
import pymysql
from django.conf import settings
class WordPress:
db = None
cursor = None
@rj76
rj76 / rename.sh
Created September 12, 2019 08:17
rename dragon ball z files so they are in a uniform format
#!/bin/bash
for file in *.mkv; do
newfile=`echo $file | sed "s/[_]/ /g" | sed "s/\s\.mkv$/\.mkv/" | sed "s/^DBZ -/Dragonball Z/"`
mv "$file" "$newfile"
done
@rj76
rj76 / should-recreate-db.sh
Created July 27, 2019 09:51
Try to automate pytest --create-db
# pre commit
find apps -type d -name migrations -exec ls -1 '{}' ';' | md5sum > md5sum
git add md5sum -m 'updated md5sum'
# before test
find apps -type d -name migrations -exec ls -1 '{}' ';' | md5sum | diff md5sum -
@rj76
rj76 / template_context.py
Created July 24, 2019 05:09
Order fields available as django template {{ fields }}
ctx = {}
if request and not isinstance(request.user, AnonymousUser):
ctx.update({
'user_email': request.user.email,
'username': request.user.username,
})
logger.info(ctx)
elif request and isinstance(request.user, AnonymousUser):
@rj76
rj76 / gsuite-protonmail.md
Created April 3, 2019 14:57
GSuite -> Protonmail
  • install protonbridge
  • setup thunderbird for protonbridge
  • change MX records main domain to point to protonmail
  • setup MX records other domain to point to google
  • setup accounts on new domain in google
  • migrate mail from users old domain to users new domain
  • wait
  • setup accounts new domain in thunderbird
  • move mail from accounts new domain to protonmail account
  • let it sync