Skip to content

Instantly share code, notes, and snippets.

View shoaibi's full-sized avatar

Shoaibi shoaibi

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / GoogleMapsGeocoder.php
Created June 25, 2015 17:00
A quick and dirty GoogleGeocoder component for Yii v1.0
<?php
class GoogleMapsGeocoder extends CApplicationComponent
{
/**
* @var string
*/
const ENDPOINT_URL = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s';
/**
@shoaibi
shoaibi / java7-notes.md
Last active August 29, 2015 14:23
My Java7 Notes

Java Basics

General

  • For loop, set the comparison condition as variable outside the loop
  • conventions
    • ClassName
    • methodName
    • propertyName
    • CONSTANT_NAME
  • Constants should be static and final. Ideally private too.
@shoaibi
shoaibi / currency-fair-challenge-architecture-proposal
Created June 25, 2015 20:50
My proposal of how to architect the Currency Fair Trends challenge
Framework of choice: yii2.
Configure application log to log all exceptions.
Configure FileCache(just to have something to later replace, say, by Redis)
2 apps using same configs, same code: frontend, api.
Api application would have a module called v1.
Url pattern: http://app.com/ , http://api.app.com/v1/tradeMessages/consume
Trends:
- Most active user
@shoaibi
shoaibi / generate-public-key-from-private-key.sh
Created June 25, 2015 20:51
Generate ssh public key from private key
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
@shoaibi
shoaibi / restore-permissions.sh
Created June 25, 2015 20:54
A handy script to generate permissions(modes, user and group) restore scripts for /etc directory.
#!/bin/bash
# At the start of my DevOps career I used to mess up /etc permissions
# a lot so I ended up creating 2 set of scripts that would be generated
# on nightly bases using cron and then when required I'd just execute
# these scripts
find /etc -exec stat --format "chmod %a %n" {} \; > /root/restoreperms.sh
find /etc -exec stat --format 'chown %U:%G %n' {} \; > /root/restoreowners.sh