Skip to content

Instantly share code, notes, and snippets.

View johanmeiring's full-sized avatar

Johan Meiring johanmeiring

View GitHub Profile
@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 / gist:2894568
Created June 8, 2012 08:52
PHP str_putcsv function
<?php
/* From: http://www.php.net/manual/en/function.str-getcsv.php#88773 and http://www.php.net/manual/en/function.str-getcsv.php#91170 */
if(!function_exists('str_putcsv'))
{
function str_putcsv($input, $delimiter = ',', $enclosure = '"')
{
// Open a memory "file" for read/write...
$fp = fopen('php://temp', 'r+');
// ... write the $input array to the "file" using fputcsv()...
fputcsv($fp, $input, $delimiter, $enclosure);
@johanmeiring
johanmeiring / gist:3002458
Created June 27, 2012 08:32
"git lg" alias for pretty git log
# From http://garmoncheg.blogspot.com/2012/06/pretty-git-log.html
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
@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')

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: