Skip to content

Instantly share code, notes, and snippets.

View shoaibi's full-sized avatar

Shoaibi shoaibi

View GitHub Profile
@shoaibi
shoaibi / backup.config.sh
Created June 25, 2015 16:51
Take a backup of specified profiles from your machine to a samba share if connected to home network while sending the backup report to a remote url
#!/bin/bash
verbose_mode=0 # Set this to 1 or 0 to enable/disable outputting all log messages. Enabling this causes some known issues with rsync output. keep it disabled.
ip_check_url='http://myip.dnsomatic.com/' #URL that would show our current ip. This url should only show IP and nothing else, no other content, no html tags, etc...
home_network_ip='1.1.1.1' #External IP that we should be on for the backup to trigger
curl_url='http://reportingserver.com/backup-report.php' #url that should get alerts for cron jobs
signatures='1234567890' #random string to verify requests on curl_url script
rsync_exclusive=1 #whether or not we should exit if there is already an rsync process running, values could be 1 or 0
rsync_additional_opts='--verbose' # any additional switches that we may want to add, an example could be --verbose
backup_alert_period=10 #alert me if no backup has run after this many days
@shoaibi
shoaibi / log_parser.py
Created June 25, 2015 16:42
A small little thttpd log parser script I did as an assignment.
#!/usr/bin/python
# My very first python script :)
""" Pre-res:
require python-sqlite
"""
""" Possible Improvments
Support for long arguments switches
"""
@shoaibi
shoaibi / compare_images.php
Created June 25, 2015 16:36
Compare 2 images using Imagick in PHP
<?php
$image1 = new imagick("image1.png");
$image2 = new imagick("image2.png");
$result = $image1->compareImages($image2, Imagick::METRIC_MEANSQUAREERROR);
$result[0]->setImageFormat("png");
header("Content-Type: image/png");
echo $result[0];
@shoaibi
shoaibi / archive_table.sh
Created June 25, 2015 16:27
Archive a table from source to target
#!/bin/bash
TABLENAME=$1
DISABLE_CHARSETCHECK=$2
DRY_RUN=1
PROGRESS=100
RETRIES=3
RUN_TIME='5m' # could be 45m
TRANSACTION_SIZE=1000
@shoaibi
shoaibi / game-of-life.php
Last active August 29, 2015 14:23
A quick and dirty implementation of game of life
<?php
// instantiate GameOfLife and run it.
$gol = new GameOfLife();
$gol->run();
/**
* Class IOHelper
* Some misc utility functions for dealing with I/O on CLI
*/
@shoaibi
shoaibi / drop-or-truncate-db-tables.sh
Last active August 29, 2015 14:23
Drop or truncate tables in a mysql database
#!/bin/bash
MDB="$1"
KEYWORD="$2"
# Detect paths
MYSQL=$(which mysql)
AWK=$(which awk)
GREP=$(which grep)
E_BADARGS=65
@shoaibi
shoaibi / offsite-mysql-backup.sh
Created June 25, 2015 16:21
Backup a mysql database and scp it to an offsite box.
#!/bin/bash
#
#
# Take dump of the configured database and transfer it to an offsite server
#
start_date=`date +M%m-D%d-Y%Y_%Hh%Mm%Ss`
source_db_user="sourceDatabaseUserNameHere"
source_db_password="sourceDatabaseUserPasswordHere"
@shoaibi
shoaibi / url-monitor.php
Created June 25, 2015 15:55
A simple url monitor that monitor the status of the url and search the page for provided string, sends email notifications if the check fails
#!/usr/bin/php
<?php
// Use https://uptimerobot.com/ instead
define('CONTACT_TO', 'me@my.com');
define('CONTACT_FROM', 'report@my.com');
$message = '';
$subject = '';
if (count($argv) > 3)
@shoaibi
shoaibi / download-install-magento.sh
Created June 25, 2015 15:49
Download and install magento
#!/bin/bash
clear
stty erase '^?'
installSampleData=1
installExtensions=0
downloader="aria2c"
baseDownloadUrl="http://www.magentocommerce.com/downloads/assets"
magentoVersion="1.9.0.0"
magentoName="magento-${magentoVersion}"
@shoaibi
shoaibi / cert-helper.sh
Created June 25, 2015 15:47
Generate ssl key, csr or self signed crt with one command
#!/bin/bash
#
# Just a clumsy little cert helper I use oftenly
#
#
E_BADARGS=65
if [ $# -lt 3 -o $# -gt 11 ]; then
echo "Usage: $0 mode[=key|csr|crt] name keyLength[=4096] commonName organizationUnit organization locality state countryTwoLetterCode emailAddress days[=1900]"
exit $E_BADARGS