Skip to content

Instantly share code, notes, and snippets.

@tubaman
tubaman / cacheddict.py
Created December 4, 2020 00:29
A python dictionary where the items timeout after self.timeout seconds
import time
class CachedDict(object):
"""A dictionary where the items timeout after self.timeout seconds
We've implemented just enough of a real dictionary to work as a
replacement for the dicts in django.template.loader.cached.Loader
"""
@tubaman
tubaman / timedcachedloader.py
Created December 4, 2020 00:21
Timed Cached Template Loader for Django
from django.template.loaders.cached import Loader as CachedLoader
from django.conf import settings
from .cacheddict import CachedDict
class Loader(CachedLoader):
"""A cached template loader where the templates expire after self.timeout
seconds.
@tubaman
tubaman / remotetemplateloader.py
Created December 4, 2020 00:19
Remote Template Loader for Django
from urllib.request import urlopen
from django.conf import settings
from django.template import Origin, TemplateDoesNotExist
from django.template.loaders.base import Loader as BaseLoader
from django.utils.module_loading import import_string
class Loader(BaseLoader):
@tubaman
tubaman / surekill
Last active June 24, 2020 19:53
Linux CLI to kill a process using pgrep arguments as nicely but surely as possible
#!/bin/bash
# uses surekillpid: https://gist.github.com/tubaman/377458a11fedb49cc2132ea6e31ae8b2
pgrep $@ | grep -v $$ | xargs --no-run-if-empty surekillpid
@tubaman
tubaman / surekillpid
Last active June 23, 2020 23:42
Linux CLI to kill a pid as nicely but surely as possible
#!/bin/bash
# How to try to kill a process
# http://porkmail.org/era/unix/award.html#uuk9letter
# Be as nice as possible before shooting it in the head
# uses waitpid: https://gist.github.com/tubaman/00b792221bd75fbbca61184da3d414ce
options=$(getopt -o v --long verbose -- $@)
[ $? -eq 0 ] || {
exit 1
}
@tubaman
tubaman / waitpid
Created June 23, 2020 23:38
waitpid for the linux command line
#!/bin/bash
# Wait for a process(es) to finish by pid
# https://stackoverflow.com/a/41613532
for pid in $@; do
tail --sleep-interval=0.250 --pid=$pid -f /dev/null
done
@tubaman
tubaman / pwstore.py
Last active June 30, 2021 22:38
Python module to get password data from password-store.org(pass)
"""Python module to get password data from password-store.org(pass)
ex:
from pwstore import pwstore
password, data = pwstore("example.org")
username = data['Username']
"""
import re
@tubaman
tubaman / xref
Created August 29, 2019 18:47
Build ctags/cscope automatically
#!/bin/bash
set -o noglob
function addfiles {
NAME="$1"
find $EXCLUDE -name "$NAME" >> cscope.files
}
function autoignore {
@tubaman
tubaman / vncssh
Last active June 27, 2019 22:39
Script to connect from one linux desktop to another using VNC over ssh
#!/bin/bash
# Connect from one linux desktop to another using SSH over VNC
#
# The script works best if you have ssh public key authentication setup with
# an agent so you don't have to type your ssh password 1000 times.
#
# Usage: vncssh remote_servername
#
# What does this do?
# 1. Calculate the right scale factor so the remote desktop resolution will
@tubaman
tubaman / attusage.py
Created October 7, 2016 22:34
Parser for AT&T Wireless bill(CSV format)
#!/usr/bin/env python
import logging
import sys
import csv
import pint
ureg = pint.UnitRegistry()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)