Skip to content

Instantly share code, notes, and snippets.

View flaeppe's full-sized avatar

Petter Friberg flaeppe

View GitHub Profile
@flaeppe
flaeppe / duplicate_rows.py
Last active May 21, 2024 07:56
Django -- Find duplicate rows over column
from django.db.models import Exists, OuterRef
MyModel.objects.filter(
Exists(
MyModel.objects.exclude(pk=OuterRef("pk")).filter(col=OuterRef("col"))
)
)
@flaeppe
flaeppe / swedish_holiday_rules.py
Last active January 15, 2020 19:23
Swedish holiday(red day) rules in Python
from dateutil.relativedelta import FR, SA
from dateutil.rrule import rrule, YEARLY
STATIC_HOLIDAYS = (
(1, 1), # New years day
(1, 6), # Epiphany
(5, 1), # International workers' day
(6, 6), # National day
(12, 24), # Christmas eve
@flaeppe
flaeppe / python.vim
Last active August 4, 2019 08:54
Python vim syntax regex to highlight/color kwargs
" \v[\(\,]\_s{-}\zs\w+\ze\_s{-}\=(\=)@!(\_s)@! (Original multiline regex)
syn match pythonFunctionKeyword "\v\s{-}\zs\w+\ze\=(\=)@!(\_s)@!" display
syn cluster pythonExpression add=pythonFunctionKeyword
syn region pythonFunctionKwargs start=+(+ end=+)+ keepend contains=@pythonExpression
HiLink pythonFunctionKeyword Identifier
@flaeppe
flaeppe / iptables_flush.sh
Last active April 12, 2017 10:39
Resets iptables configuration.
#!/bin/sh
# Set this up as a cronjob to flush firewall blockades on given time intervals
# when configuring of firewall is wanted. Just to avoid putting the machine on
# lockdown seen externally.
echo "Stopping firewall and allowing everyone..."
ipt="/sbin/iptables"
## Failsafe - die if /sbin/iptables not found
[ ! -x "$ipt" ] && { echo "$0: \"${ipt}\" command not found."; exit 1; }