Skip to content

Instantly share code, notes, and snippets.

View ishahid's full-sized avatar

Imran Shahid ishahid

View GitHub Profile
@ishahid
ishahid / dropbox_poc.py
Last active August 29, 2015 13:56
Dropbox File Transfer Comparison - Queue vs Parallel
#!/usr/bin/python
"""
Dropbox File Transfer Comparison - POC
This program compares the speed of uploading multiple files to dropbox using
both queued and parallel connections per file.
"""
import time
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Write tags to files
Usage:
tag.py "TagName" FileName1 FileName2
You can use wildcards for the file name. Use quotes if spaces in tags.
To check if it worked, use xattr -l FileName
@ishahid
ishahid / sort_json_array.js
Created February 26, 2014 03:26
Generic way of sorting JSON array by attribute
function sort_by(attr) {
return function(a, b) {
if( a[attr] > b[attr]) {
return 1;
} else if( a[attr] < b[attr] ) {
return -1;
}
return 0;
}
}
@ishahid
ishahid / docx.py
Last active August 29, 2015 13:56
Utility to replace variables enclosed in square brackets with the given value in Microsoft Word docx files. Based upon the following blog post. http://virantha.com/2013/08/16/reading-and-writing-microsoft-word-docx-files-with-python/
import os, re, zipfile, shutil, tempfile
from lxml import etree
class docx():
def __init__(self, docx_filename):
self.filename = docx_filename
with open(self.filename) as f:
self.zipfile = zipfile.ZipFile(f)
@ishahid
ishahid / git_commits_monthly
Created March 25, 2015 04:49
bash script to find monthly git commits by users on monthly basis
#/bin/bash
DATES=("2014-03-01" "2014-04-01" "2014-05-01" "2014-06-01" "2014-07-01" "2014-08-01" "2014-09-01" "2014-10-01" "2014-11-01" "2014-12-01" "2015-01-01" "2015-02-01" "2015-03-01")
let "counter = 1"
for i in "${DATES[@]}"
do
echo -n "$i"
echo
git shortlog -s -n --after=${DATES[counter-1]} --before=${DATES[counter]}
@ishahid
ishahid / Hash.cs
Last active December 13, 2015 17:38 — forked from inogo/Hashes.cs
MD5 and SHA1 hash calculation tool.
using System;
using System.Text;
using System.Security.Cryptography;
static class Hash
{
public static string SHA1(string text)
{
byte[] buffer = Encoding.UTF8.GetBytes(text);
var sha1 = new SHA1CryptoServiceProvider();
@ishahid
ishahid / timestampedmodel.py
Last active December 24, 2015 06:49
An abstract base class model for Django that provides self-updating 'created' and 'modified' fields.
from django.db import models
class TimeStampedModel(models.Model):
"""
An abstract base class model that provides self-updating 'created'
and 'modified' fields.
"""
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
@ishahid
ishahid / http_headers.php
Created January 15, 2014 02:19
Display HTTP headers in PHP.
<?php
$http_client_ip = '';
$http_x_forwarded_for = '';
$remote_addr = $_SERVER['REMOTE_ADDR'];
$remote_host = '';
$remote_port = $_SERVER['REMOTE_PORT'];
$remote_user = '';
$redirect_remote_user = '';
$http_user_agent = $_SERVER['HTTP_USER_AGENT'];
@ishahid
ishahid / hash.py
Created January 15, 2014 02:28
Hash calculation tool.
#!/usr/bin/env python
import os, sys
import hashlib
def usage(full=False):
msg = ''
if full:
msg += 'Computes hash of a string.' + os.linesep
@ishahid
ishahid / soap.php
Created January 15, 2014 02:31
SOAP service call in PHP.
<?php
try {
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient('http://soap.service-provider.com/endpoint.asmx?WSDL', $options);
}