Skip to content

Instantly share code, notes, and snippets.

View akaihola's full-sized avatar
🌇
Working from home

Antti Kaihola akaihola

🌇
Working from home
  • Wärtsilä Oyj
  • Espoo, Finland
View GitHub Profile
@akaihola
akaihola / LICENSE.txt
Last active December 18, 2021 23:23
XML pretty-print for ElementTree
Copyright (c) 2013, Antti Kaihola
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@akaihola
akaihola / movephotos.py
Created November 10, 2013 09:26
Move photo from one tree to another in a git repository
#!/usr/bin/python3.3
import os
NEWDIR = '/home/akaihol/Kuvat_'
OLDDIR = '/media/akaihol/tasku/Valokuvat'
def get_file_fingerprint(path):
@akaihola
akaihola / repeating_cache_manager.py
Created August 26, 2013 13:22
Recurring dynamic Celery task manager
import time
class InvalidOperation(Exception):
pass
class RepeatingCacheManager(object):
"""Recurring dynamic Celery task manager
@akaihola
akaihola / mover.py
Created April 19, 2013 11:05
A Python script for moving a given list of files to a separate subdirectory while maintaining the directory structure.
#!/usr/bin/env python
"""Move listed files to a separate tree
Usage::
cd /root/of/files
python mover.py <list-of-files.txt # only lists what will be moved
python mover.py -x <list-of-files.txt # actually moves the files
@akaihola
akaihola / salt-bootstrap.sh
Created February 20, 2013 20:22
Salt minion bootstrap script for pristine Debian/Ubuntu virtual hosts
#!/bin/bash
# Salt minion bootstrap script for freshly installed Debian/Ubuntu
# virtual servers
#
# Let's assume you have a newly created Debian/Ubuntu VPS with no
# network interface running. To bootstrap Salt, copy this file into
# your home directory on the [SALT MASTER] and do the following on the
# VPS:
#
@akaihola
akaihola / add-resizing-iframe.js
Created August 28, 2012 10:55
HTML iframe which resizes according to its contents
// Add this JS to the parent window, replacing the URL and width
// appropriately.
if (document.location.search == '?debug=1') {
document.write('<div id="autosizing-iframe-debug" style="position:absolute;width:233px;height:10em;overflow:scroll;margin-left:-233px;background:#cff;"></div>');
};
document.write('<iframe src="http://OTHERDOMAIN.COM/IFRAME/URL/" width="547px" height="10000px" frameborder="0" scrolling="no" id="autosizing-iframe" style="border: none;"></iframe>');
(function() {
var debug = document.getElementById("autosizing-iframe-debug"),
@akaihola
akaihola / django_debug_memory.py
Created August 20, 2012 10:37
Middleware for dumping the effect of each view to the RSS memory usage
"""Django Middleware for printing view's RSS usage after each request
Code for retrieving process memory information adapted from
http://code.activestate.com/recipes/286222-memory-usage/
"""
import inspect
import os
@akaihola
akaihola / cache_switch.py
Created August 10, 2012 07:44
Cache backend switching for Django tests
from django.core.cache.backends.base import BaseCache
from functools import wraps
import sys
class OldStyleClass:
pass
ClassType = type(OldStyleClass)
@akaihola
akaihola / README.rst
Last active October 3, 2015 06:08
gits - run Git while using a predefined private SSH key

gits - Git shared

Note

The instructions below haven't been checked. Please check them and make any necessary corrections. Thanks.

@akaihola
akaihola / warmup.py
Created April 5, 2012 08:31
Warms up a web server by sending requests until the maximum or average response duration falls below a given threshold
#!/usr/bin/env python3
# also compatible with Python 2.7
# and Python 2.6 (requires argparse)
"""
Warms up a web server by sending requests until the maximum or average response
duration falls below a given threshold.
"""