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 / bootstrap_homeshick.sh
Last active Apr 9, 2019
Script that can set up an entire user account with homeshick automatically
View bootstrap_homeshick.sh
#!/bin/bash -ex
# Paste this into ssh
# curl -sL https://gist.github.com/andsens/2913223/raw/bootstrap_homeshick.sh | tar -xzO | /bin/bash -ex
# When forking, you can get the URL from the raw (<>) button.
### Set some command variables depending on whether we are root or not ###
# This assumes you use a debian derivate, replace with yum, pacman etc.
aptget='sudo apt-get'
chsh='sudo chsh'
@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 / dump.sh
Last active Oct 17, 2019
Backup all MySQL databases into separate files
View dump.sh
#!/bin/sh
## 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
@andsens
andsens / benchmark-ec2-boottime.sh
Created Oct 1, 2012
Starts a single instance and measures the time until SSH connectivity
View benchmark-ec2-boottime.sh
#!/bin/bash -e
# These need to be set.
#export EC2_HOME="/path/to/ec2-api-tools"
#export AWS_ACCESS_KEY='XXXXXXXXXXXXXXXXXXXX'
#export AWS_SECRET_KEY='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
#export PATH="$PATH:${EC2_HOME}/bin"
ami_id='ami-123abc12'
availability_zone='eu-west-1a'
keypair="johndoe@example.com"
@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'");
@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;
@andsens
andsens / debian-init.sh
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.
View debian-init.sh
#!/bin/sh
### BEGIN INIT INFO
# 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
### END INIT INFO
@andsens
andsens / chrooted.sh
Created Apr 28, 2014
Configure server for chrooted sftp users and create those users
View chrooted.sh
#!/bin/bash
# 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
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
You can’t perform that action at this time.