Skip to content

Instantly share code, notes, and snippets.

Anders Ingemann andsens

Block or report user

Report or block andsens

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
andsens /
Last active Sep 18, 2017
Deinitialize a submodule and merge it as a branch
#!/bin/bash -xe
deinit() {
test -d $module_path
current_branch=$(git rev-parse --abbrev-ref HEAD)
url=$(cd $module_path; git config --get remote.origin.url)
remote_name=$(basename $url)
branch_name=$(basename $url)
head=$(cd $module_path; git rev-parse HEAD)
andsens /
Created Mar 3, 2015
Converts a passpack csv export to a lastpass csv export
#!/usr/bin/env python
from collections import Counter
import csv
all_tags = []
lines = []
with open('passpack.csv') as passwords_handle:
passwords = csv.reader(passwords_handle, delimiter=',',
quotechar='"', quoting=csv.QUOTE_MINIMAL)
andsens /
Last active Aug 29, 2015
Measure network throughput between two machines
# Idea snatched from
# Command for quick installation:
# url=''; curl -so $url || wget --quiet -O $url; chmod +x
server() {
type pv > /dev/null 2>&1
if [ $? -eq 0 ]; then
while true; do
nc -l 1122 | pv --rate > /dev/null
printf "\n"
andsens /
Last active Aug 29, 2015
Renders a jinja2 template and outputs the result
#!/usr/bin/env python
# Dependencies: jinja2, pyyaml, docopt
import docopt
usage = """jjrender
Renders a jinja2 template and outputs the result
Pipe the variables in yml format into stdin
Alternatively you can simply paste the tpl after starting jjrender, terminate input with Ctrl+D
Usage: jjrender TEMPLATE
andsens /
Created Apr 28, 2014
Configure server for chrooted sftp users and create those users
# source this file in /root/.bashrc or /root/.zshrc
# Sets up the server for chrooted users
configure_chrooted() {
grep ^chrooted: /etc/group
if [[ $? == 0 ]]; then
printf "The chrooted group already exists, aborting...\n"
exit 1
andsens /
Last active Aug 29, 2019
This is a generic init-script, easily modifiable to suit your needs. It uses quite a lot of lsb init-functions and adheres to the lsb standards.
# Provides: generic-prog
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Generic Program
# Description: Generic Program is a generic program to do generic things with
andsens /
Last active Aug 9, 2016
Google spreadsheet function for signing S3 URLs (very handy for CSV cost allocation reports when combined with the ImportData() function)
function sign_s3(access_key, private_key, bucket, object_name, validity, base_url) {
if(!base_url) {
base_url = "";
if(!validity) {
validity = 60;
expires = Math.floor((new Date()).getTime() / 1000) + validity;
object_name = encodeURIComponent(object_name);
stringToSign = "GET\n\n\n"+expires+"\n/"+bucket+"/"+object_name;
andsens / convert_db_encoding.php
Created Oct 3, 2012
Converts an entire database to utf-8. Handy when you forgot to set default_encoding etc. in my.cnf
View convert_db_encoding.php
$mysqli = new mysqli('hostname', 'username', 'password');
$result = $mysqli->query(
`TABLE_COLLATION` != 'utf8_general_ci'
AND `TABLE_SCHEMA` != 'mysql'
AND `TABLE_SCHEMA` != 'information_schema'");
andsens /
Created Oct 1, 2012
Starts a single instance and measures the time until SSH connectivity
#!/bin/bash -e
# These need to be set.
#export EC2_HOME="/path/to/ec2-api-tools"
#export PATH="$PATH:${EC2_HOME}/bin"
andsens /
Last active Oct 17, 2019
Backup all MySQL databases into separate files
## backup each mysql db into a different file, rather than one big file
## as with --all-databases. This will make restores easier.
## To backup a single database simply add the db name as a parameter (or multiple dbs)
## Putting the script in /var/backups/mysql seems sensible... on a debian machine that is
## Create the user and directories
# mkdir -p /var/backups/mysql/databases
# useradd --home-dir /var/backups/mysql --gid backup --no-create-home mysql-backup
## Remember to make the script executable, and unreadable by others
You can’t perform that action at this time.