Skip to content

Instantly share code, notes, and snippets.

View antonagestam's full-sized avatar
🍉

Anton Agestam antonagestam

🍉
View GitHub Profile
@antonagestam
antonagestam / demo.html
Last active February 19, 2019 09:54
Wrapper around NodeList to easily implement a jQuery-like API in a minimal way
<script type="module">
import $ from './dollar.js';
$('a').on('click', (e) => {
e.preventDefault();
console.log(e.currentTarget);
alert('ello');
});
</script>
@antonagestam
antonagestam / clean.sh
Created August 30, 2018 22:50
clean directory names
for i in *; do
if [[ ! -d "$i" ]]; then continue; fi;
from=$i
to=$(echo "$i" \
| tr -cd '\11\12\15\40-\176' \
| sed -e 's/^[[:space:]]*//' \
| sed 's/ /-/g')
@antonagestam
antonagestam / ldap_backend.py
Last active August 24, 2018 06:53
An LDAP authentication backend for Django, use at your own risk ...
import logging
from django.conf import settings
from django.contrib.auth.models import User
import ldap3
from ldap3.core import exceptions
logger = logging.getLogger(__name__)
@antonagestam
antonagestam / doco.sh
Last active August 23, 2018 08:12
doco
#!/usr/bin/env bash
# wrapper around docker-compose that remembers the file argument
set -euo pipefail
cmd_arg=${1:-}
state_file=~/.docofile
get_compose_file () {
@antonagestam
antonagestam / get_hashed_file.sh
Created August 20, 2018 10:33
get_hashed_file.sh
# Usage example:
# get_hashed_file "https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm" "c070b754ce2de9f714ab4db4736c7e05"
get_hashed_file() {
local url=$1
local filename=${url##*/}
local hash=$2
if [[ ! -f "$filename" ]]; then
echo "downloading $url"
@antonagestam
antonagestam / .vimrc
Last active May 3, 2019 17:12
.vimrc
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
[user]
name = Anton Agestam
email = git@antonagestam.se
[core]
editor = vim
excludesfile = ~/.gitignore
[rerere]
enabled = 1
[color]
diff = auto
@antonagestam
antonagestam / namedtuplecursor.py
Created May 28, 2018 15:23
aiomysql named tuple cursor
from collections import namedtuple
from aiomysql.cursors import Cursor, SSCursor
class _NamedTupleCursorMixin:
async def _do_get_result(self):
await super()._do_get_result()
fields = []
if self._description:
for f in self._result.fields:
get_lock () {
# get_lock assures only one process of a kind can be active at a time. It
# takes a path to a lockfile as its first argument and the number of seconds
# to let processes run for as its second argument. Use release_lock to
# remove the lockfile.
#
# To get an infinite lock, pass "infinite" as the locktime argument. This
# makes processes trying to acquire locks exit immediately if one already
# exists.
@antonagestam
antonagestam / log.sh
Last active September 19, 2018 09:16
helper functions for formatting log output
#!/usr/bin/env bash
# The logging functions all take input both as arguments and as stdin so that
# logging can be piped from other commands. The commands use this themselves:
# `log_sub` pipes into `log` which pipes into `prefix`.
prefix () {
local replace="s/^/$1/"
if (( $# > 1 )); then