Skip to content

Instantly share code, notes, and snippets.

View johanmeiring's full-sized avatar

Johan Meiring johanmeiring

View GitHub Profile
@johanmeiring
johanmeiring / photototo.py
Last active August 29, 2015 14:06
Walk through dir, collect JPGs, copy to destination with timestamp as name, with duplicate detection.
import exifread
import os
import re
import shutil
in_dir = "path"
out_dir = "path"
clean = False
@johanmeiring
johanmeiring / .bashrc
Last active October 2, 2015 02:58
Colour *nix prompt with git status
# Ubuntu / Debian:
export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]`[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "\[\e[31m\]" || echo "\[\e[32m\]"`$(__git_ps1 " (%s)\[\e[00m\]") \[\e[00m\]\$ '
# OSX:
export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]`[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "\[\e[31m\]" || echo "\[\e[32m\]"`$(__git_ps1 " (%s)\[\e[00m\]") \[\e[00m\]\$ '
@johanmeiring
johanmeiring / checkSpace.sh
Last active October 2, 2015 02:58
Linux disk space checker
#!/bin/bash
# Disk space checking script.
# Version 0.2
# All of the below parameters can be overriden via command line arguments.
# Minimum disk space that should be available, in kilobytes.
THRESHOLD=20971520
# Partition/Filesystem that we should check.
PARTITION="/dev/md1"
# Email address that mail should be sent to.
@johanmeiring
johanmeiring / checkreplication.sh
Created July 3, 2012 09:06
MySQL Replication Status Checker
#!/bin/bash
# MySQL Replication Status Checker
# This script will run the SHOW SLAVE STATUS query on the specified server, and then report it if Last_IO_Errno or Last_SQL_Errno do not equal 0.
# Most effective when used as a cron job that runs once every minute.
# Version 0.1
# DB Info
DBHOST=localhost
USERNAME=root
PASSWORD=lolololol
@johanmeiring
johanmeiring / gist:3952290
Created October 25, 2012 12:23
Backup file rotation
#!/bin/bash
DEST=/root/BACKUPS
# Code to actually create backup files goes here...
# Check if we need to rotate the backup files.
FC=`ls ${DEST}/*.tar | wc -l`
if [[ $FC -gt 6 ]]; then
echo "Too many backup files. Deleting oldest one..."
DELETE_FILE=`ls -tr ${DEST}/*.tar | head -1`
@johanmeiring
johanmeiring / migrate_all.sh
Created March 12, 2013 08:33
Basic bash script to create migrations for all apps in a Django project. File to be placed in the root directory of the project. Requires South.
#!/bin/bash
for file in $(\
find . -maxdepth 1 -type d | \
egrep -v "\.$" | \
sed -r 's/\.\///'); do
python manage.py schemamigration $file --auto
done
exit 0
@johanmeiring
johanmeiring / pingsubnet.sh
Created August 8, 2013 08:28
Ping a subnet and record reachable IPs in a file.
#!/bin/bash
COUNTER=1
rm ips
while [[ $COUNTER -lt 255 ]]; do
ping 192.168.254.$COUNTER -c 1 -W 1 && echo "192.168.254.$COUNTER" >> ips
COUNTER=$(( $COUNTER + 1 ))
done
@johanmeiring
johanmeiring / models.py
Created September 16, 2013 14:22
Basic Custom User Model for Django 1.5
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser, PermissionsMixin
class UserManager(BaseUserManager):
def create_user(self, email, first_name, surname, password=None):
if not email:
raise ValueError('Users must have an email address')
@johanmeiring
johanmeiring / gist:935dc22ba8224184095824f9c7c80257
Created April 6, 2016 20:29
Ansible on Windows via Vagrant
vagrant init withinboredom/Trusty64
vagrant ssh
sudo apt-get update
sudo apt-get install -y language-pack-en git python-dev python-pip libkrb5-dev
sudo locale-gen en_US.UTF-8
cd /home/vagrant && git clone git://github.com/ansible/ansible.git --recursive
sudo pip install paramiko PyYAML Jinja2 httplib2 six "pywinrm>=0.1.1" kerberos
echo "source /home/vagrant/ansible/hacking/env-setup" >> /home/vagrant/.bashrc

Keybase proof

I hereby claim:

  • I am johanmeiring on github.
  • I am johanmeiring (https://keybase.io/johanmeiring) on keybase.
  • I have a public key whose fingerprint is 5572 17A5 BD5B 42C9 71B0 D40F A5CA 6E4F CBA6 3188

To claim this, I am signing this object: