Skip to content

Instantly share code, notes, and snippets.

View technocake's full-sized avatar

Robin Garen Aaberg technocake

View GitHub Profile
@technocake
technocake / docker-compose.yml
Last active September 23, 2022 10:41
python redis 101
redis:
image: redis
web:
build: .
environment:
# Points to docker hostname redis (from servicename above)
REDIS_URL: "redis://redis/0"
@technocake
technocake / UmbracoHack.cshtml
Created October 21, 2021 09:19
umbraco-programatically-user
// in top of view file
@using Umbraco.Core;
@using Umbraco.Core.Models;
@using Umbraco.Core.Models.Membership;
@using Umbraco.Core.Services;
@using Umbraco.Web.Security.Providers;
@technocake
technocake / disablel-fbclid.nginx.conf
Created September 8, 2019 20:30
NGINX - Remove fbclid from all urls
location / {
...
# Disable fbclid tracking on all urls
if ($query_string ~ "^(.*)fbclid=(.*)$") {
rewrite ^(.*)$ $uri? permanent;
}
}
@technocake
technocake / personummer_kontrollsifre.py
Created September 4, 2019 14:44
Kalkuler kontrollsifre på norske personnumre
# coding: utf-8
def kk(ssn9):
"""
Calculates control decimals for norwegian national identity numbers
see: https://no.wikipedia.org/wiki/F%C3%B8dselsnummer#Oppbygning
D nummer: https://no.wikipedia.org/wiki/F%C3%B8dselsnummer#D-nummer
@technocake
technocake / env.py
Last active May 5, 2021 12:12
Load django settings from environment variables
import os
def env(key, default=None, return_type=None, list_element_type=str):
"""
Function to parse settings from environment consistently.
Handles parsing of bool/int/list/str values correctly.
:param key: name of environment variable to load setting from.
:param default: Optional default value if key is not present in environment. # noqa
@technocake
technocake / eat_dates.py
Created August 27, 2019 12:45
parse UTC + 0 isoformated strings
from datetime import datetime
inn = '2019-02-02T23:12:39.05Z'
fmt = "%Y-%m-%dT%H:%M:%S.%fZ"
print(datetime.strptime(inn, fmt))
@technocake
technocake / settings.py
Created August 12, 2019 20:17 — forked from andreagrandi/settings.py
Sending emails from Django during development without using a real SMTP server. Python comes with a very basic and integrated SMTP server. To start it just open a terminal and type: python -m smtpd -n -c DebuggingServer localhost:1025 Then configure your settings.py using the following parameters. You will see the email directly in the terminal …
if DEBUG:
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = '[email protected]'
@technocake
technocake / goto promptline
Last active October 21, 2021 11:51
goto_prompt.sh
# add this to your bash rc file
# It will display the current goto project that is active.
# zsh: add this line:
# setopt PROMPT_SUBST
prompt_goto() {
# Check if project command exist
if [ -z "$(command -v project)" ]; then
return 0
@technocake
technocake / encoding.py
Created July 14, 2019 19:54
python encoding info
import sys
default = sys.getdefaultencoding()
e_in = sys.stdin.encoding
e_out = sys.stdout.encoding
print('''
python system default encoding: {}
stdin: {}
stdout: {}
'''.format(default, e_in, e_out)
@technocake
technocake / backupgoto.sh
Last active July 16, 2019 22:25
backup all goto projects
# add to .bash_profile / .bashrc / .zshrc
function backupgoto {
foldername=$(date +%d%m%y)
target="${HOME}/gotobackup/${foldername}"
mkdir -p "$target"
cp -r ${HOME}/.goto "$target" \
&& echo "Backuped goto to $target" \
|| echo "Failed to backup goto"
}