Skip to content

Instantly share code, notes, and snippets.

View saurabhwahile's full-sized avatar

Saurabh Wahile saurabhwahile

View GitHub Profile
@saurabhwahile
saurabhwahile / backup-winrar.ps1
Created June 16, 2014 19:08
Creating RAR Archives From Windows Powershell
#Set-ExecutionPolicy Unrestricted
$fromFolderPath = $args[0][0]
$toFolderPath = $args[0][1]
$toFilename = ""
if ($fromFolderPath.Split("\")[-1] -eq "")
{
$toFilename = $fromFolderPath.Split("\")[-2]
$fromFolderPath = $fromFolderPath.SubString(0, ($fromFolderPath.length-1))
}
@saurabhwahile
saurabhwahile / sentence-jumbler
Created November 23, 2014 13:05
Jumble sentences in paragraph(s)
import os
import random
import collections
def jumbleSentences(paragraph):
sentences = paragraph.split('. ')
jumbledSentences = collections.OrderedDict()
jumbleCounter = 0
while jumbleCounter < len(sentences):
position = random.randrange(0, len(sentences))
@saurabhwahile
saurabhwahile / substitution-analyser.py
Created December 12, 2014 06:40
Analyse Substitution Cipher
from string import ascii_lowercase
ITERATIONS = 3
charMapping = {}
charControl = 0
for char in ascii_lowercase:
charMapping[charControl] = char
charControl+=1
@saurabhwahile
saurabhwahile / count-characters.py
Created February 23, 2015 14:15
Count Characters In Image - Using Space Efficient CCL Algorithm With Dilation and Erosion
__author__ = 'Saurabh'
from PIL import Image
IMAGE_NAME = 'RandomText.gif'
inputImage = Image.open(IMAGE_NAME)
inputImageMatrix = inputImage.load()
BLACK = 0
WHITE = 255
@saurabhwahile
saurabhwahile / set_proxy.sh
Created March 22, 2015 16:43
Set proxy based on ip address
#replace th0 with interface name and the 1st ip with nic ip and 2nd ip with proxy ip
ip="$(ifconfig eth0|grep 'inet addr'|awk -F':' '{print $2}'| awk -F' ' '{print $1}')"
if [[ $ip = "172.24.0.2" ]]
then
export http_proxy="http://172.24.0.1:3128"
fi
@saurabhwahile
saurabhwahile / measure_disk_perf.sh
Created May 24, 2015 09:07
Measure disk performance on linux
repeat=10
while [ $x -gt 0 ]
do
python "C:\\Python27\\lib\\timeit.py" -n 3 "f = open('file.txt', 'wb+'); f.write('chunk'); f.close()" >> results.txt
repeat=$((repeat-1))
done
data="$(awk '{print $6}' results.txt)"
echo $data
python -c "results = map(float, \"\"\"$data\"\"\".split('\n')); from matplotlib import pyplot; pyplot.plot(range(1,11), results); pyplot.savefig('results.png')"
rm results.txt
@saurabhwahile
saurabhwahile / MorphologicalOperations.java
Created October 1, 2015 06:19
Image Morphological Operations
import java.io.*;
import javax.imageio.*;
import java.awt.image.*;
import java.util.*;
import java.awt.Color;
class Operator
{
@saurabhwahile
saurabhwahile / switch_gateway.bat
Created December 16, 2015 06:02
Switch gateway, Ex: for failover/redundancy
@echo off
for /f "tokens=2,3 delims={,}" %%a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do set gateway=%%~a
IF %gateway%==192.168.1.1 (
netsh interface ip set address name="Wi-Fi" static 192.168.1.10 255.255.255.0 192.168.1.41 1
) ELSE (
netsh interface ip set address name="Wi-Fi" static 192.168.1.10 255.255.255.0 192.168.1.1 1
)
@saurabhwahile
saurabhwahile / twitter_unfollow.py
Created September 12, 2016 18:20
Mass unfollow on twitter
import tweepy
auth = tweepy.auth.OAuthHandler(
consumer_key="key",
consumer_secret="secret")
auth.set_access_token(
'token',
'secret')
api=tweepy.API(auth_handler=auth)
@saurabhwahile
saurabhwahile / zerodha_to_moneycontrol.py
Last active August 15, 2023 13:46
Script for importing zerodha stocks in xlsx to moneycontrol csv if you want to use moneycontrol terminal
#You'll still have to manually enter dates here, as the xlsx file from zerodha does not show dates(SIP of stocks causes multiple dates)
#EDIT: Usage python zerodha_to_moneycontrol.py <FILENAME>
import sys
from openpyxl import load_workbook
wb = load_workbook(sys.argv[1])
ws = wb.active
csv_list = [["BSE/NSE/ISIN Code","Buy Date","Buy Quantity","Buy Price",]]