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
andsens / jjrender.py
Last active Aug 29, 2015
Renders a jinja2 template and outputs the result
View jjrender.py
#!/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
andsens / throughput.sh
Last active Aug 29, 2015
Measure network throughput between two machines
View throughput.sh
#!/bin/sh
# Idea snatched from http://kb.sp.parallels.com/en/115348
# Command for quick installation:
# url='https://gist.githubusercontent.com/andsens/573186933e80a74462bb/raw/throughput.sh'; curl -so throughput.sh $url || wget --quiet -O throughput.sh $url; chmod +x throughput.sh
server() {
type pv > /dev/null 2>&1
if [ $? -eq 0 ]; then
while true; do
nc -l 1122 | pv --rate > /dev/null
printf "\n"
@andsens
andsens / type.sh
Created Jul 13, 2012
Keyboard typing tool for AppleTV AirControl
View type.sh
#!/bin/bash
url='http://apple-tv.anders.local'
menu="$url/remoteAction=1"
menuhold="$url/remoteAction=2"
up="$url/remoteAction=3"
down="$url/remoteAction=4"
select="$url/remoteAction=5"
left="$url/remoteAction=6"
right="$url/remoteAction=7"
playpause="$url/remoteAction=10"
@andsens
andsens / little_bobby_tables.sql
Created Jul 16, 2012
Creates ordered statements to drop all tables in mysql db avoiding most foreign key conflicts
View little_bobby_tables.sql
SELECT CONCAT('DROP TABLE `', `t`.`TABLE_SCHEMA`, '`.`', `t`.`TABLE_NAME`, '`;')
FROM `information_schema`.`TABLES` t
LEFT JOIN `information_schema`.`REFERENTIAL_CONSTRAINTS` rc
ON `rc`.`CONSTRAINT_SCHEMA` = `t`.`TABLE_SCHEMA`
AND `rc`.`REFERENCED_TABLE_NAME` = `t`.`TABLE_NAME`
WHERE `TABLE_SCHEMA` = 'dbname'
GROUP BY `t`.`TABLE_NAME`
ORDER BY COUNT(`t`.`TABLE_NAME`) ASC;
@andsens
andsens / ec2-jessie-ebs.log
Created Mar 30, 2016
Log of running `bootstrap-vz --dry-run manifests/official/ec2/ebs-jessie-amd64-hvm.yml --log - --debug`
View ec2-jessie-ebs.log
Loading provider ec2
Loading plugin cloud_init
Tasklist:
bootstrapvz.providers.ec2.tasks.packages.DefaultPackages
bootstrapvz.providers.ec2.tasks.host.AddExternalCommands
bootstrapvz.common.tasks.bootstrap.AddRequiredCommands
bootstrapvz.common.tasks.locale.LocaleBootstrapPackage
bootstrapvz.providers.ec2.tasks.host.GetInstanceMetadata
bootstrapvz.common.tasks.apt.AddDefaultSources
bootstrapvz.plugins.cloud_init.tasks.AddCloudInitPackages
@andsens
andsens / sign_s3.gs
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)
View sign_s3.gs
function sign_s3(access_key, private_key, bucket, object_name, validity, base_url) {
if(!base_url) {
base_url = "http://s3.amazonaws.com";
}
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;
View github_push_error.log
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 464 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
remote: ruby-jemalloc: symbol lookup error: /data/github/current/vendor/gems/2.1.7/ruby/2.1.0/gems/json-1.8.3/lib/json/ext/generator.so: undefined symbol: rb_data_typed_object_alloc
To git@github.com:user/repo
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:user/repo'
@andsens
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
#/usr/bin/php
<?php
$mysqli = new mysqli('hostname', 'username', 'password');
$result = $mysqli->query(
"SELECT `TABLE_SCHEMA`, `TABLE_NAME` FROM `information_schema`.`TABLES`
WHERE
`TABLE_COLLATION` != 'utf8_general_ci'
AND `TABLE_SCHEMA` != 'mysql'
AND `TABLE_SCHEMA` != 'information_schema'");
View .gitconfig
[log]
date = relative
[format]
pretty = shortlog
[pretty]
shortlog = format:%C(auto,yellow)%h%C(auto,magenta)% G? %C(auto,blue)%>(12,trunc)%ad %C(auto,green)%<(7,trunc)%aN%C(auto,reset)%s%C(auto,red)% gD% D
@andsens
andsens / convert_to_lastpass.py
Created Mar 3, 2015
Converts a passpack csv export to a lastpass csv export
View convert_to_lastpass.py
#!/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)
You can’t perform that action at this time.