Skip to content

Instantly share code, notes, and snippets.

View runekaagaard's full-sized avatar

Rune Kaagaard runekaagaard

  • Copenhagen, Denmark
View GitHub Profile
;; Bootstrap packages.
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize)
(if (not (package-installed-p 'use-package))
(progn
@runekaagaard
runekaagaard / list_all_model_signals.py
Last active July 4, 2022 15:41 — forked from voldmar/signals.py
List all signals by model and signal type. Tested with Django 1.7.
# coding:utf-8
import gc
import inspect
import ctypes
from collections import defaultdict
from django.core.management.base import BaseCommand
from django.db.models.signals import *
@runekaagaard
runekaagaard / tails.py
Last active April 8, 2022 05:53
Runs and outputs multiple bash commands in one terminal. Each command gets a color. "pip install termcolor" is needed.
import fcntl, os, re, sys, signal
from subprocess import Popen, PIPE
from termcolor import colored
from itertools import cycle
RE = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
CLEARLN = "\033[2K\r"
def escape_ansi(s):
return RE.sub('', s)
@runekaagaard
runekaagaard / python_pipes.py
Last active February 26, 2022 13:18
pipe operator in python.
from functools import wraps
class Ror:
def __init__(self, func, args, kwargs):
self.func = func
self.args = args
self.kwargs = kwargs
def __ror__(self, arg):
return self.func(arg, *self.args, **self.kwargs)
@runekaagaard
runekaagaard / last-daemon.sh
Last active April 26, 2021 14:17
Run multiple dev servers in parallel with a single command. Each line has a colored prefix. CTRL+C closes all. Requires GNU parallel.
#!/bin/bash
# COLOR CODES
# Red 31 41
# Green 32 42
# Yellow 33 43
# Blue 34 44
# Magenta 35 45
# Cyan 36 46
# White 37 47
state = {
"users":
User.mutable.all() > {
"tags": Tag.mutable.up().all(),
},
"movie":
Movie.mutable.get(pk=91) > {
"actors": Actor.mutable.up().all(),
"style": Style.mutable.up().get(),
}
@runekaagaard
runekaagaard / change_monitor.py
Created November 2, 2019 12:53
POC Python Change Monitor of generic nested data
from collections import namedtuple
ATTR_LOOKUP = 1
ITEM_LOOKUP = 2
Change = namedtuple("Change", "path to")
class Lookup(namedtuple("Lookup", "key lookup_type")):
def __str__(self):
if self.lookup_type == ATTR_LOOKUP:
@runekaagaard
runekaagaard / README.md
Created September 13, 2019 17:55 — forked from mayorova/README.md
Mutual SSL in NGINX

Securing traffic to upstream servers with client certificates

Info: https://www.nginx.com/resources/admin-guide/nginx-https-upstreams/

Creating and Signing Your Certs

Source: http://nategood.com/client-side-certificate-authentication-in-ngi

This is SSL, so you'll need an cert-key pair for you/the server, the api users/the client and a CA pair. You will be the CA in this case (usually a role played by VeriSign, thawte, GoDaddy, etc.), signing your client's certs. There are plenty of tutorials out there on creating and signing certificates, so I'll leave the details on this to someone else and just quickly show a sample here to give a complete tutorial. NOTE: This is just a quick sample of creating certs and not intended for production.

@runekaagaard
runekaagaard / pgx.rst
Last active September 18, 2018 14:09
Bash scripts for extracting individual databases from a sql file dumped using pg_dumpall

Postgresql Xtra commands

  • pgx_list_dbs: Lists the names of databases in an .sql file dumped using pg_dumpall.
  • pgx_extract_db: Extracts a single database from a sql file dumped with pg_dumpall and outputs its content to stdout.

Installation

@runekaagaard
runekaagaard / midipad.py
Created May 14, 2017 09:15
A midi plugin for a 3x3 pad.
from rtmidi.midiutil import open_midiport
NOTEON = 144
NOTEOFF = 128
BASE = 65
SCALE = [1, 2, 1, 1, 2, 2, 1, 2]
NOTE = BASE
STEP = 0
TOPBASE = BASE + 24