Skip to content

Instantly share code, notes, and snippets.

Avatar
📢
Working from home

Adnan Siddiqi kadnan

📢
Working from home
View GitHub Profile
@kadnan
kadnan / migrate.sh
Created Jun 16, 2016 — forked from dj1020/migrate.sh
Upgrade MAMP to Mysql 5.7 tested by Ken Lin 2015/11/09
View migrate.sh
#!/bin/sh
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.9-osx10.10-x86_64.tar.gz
tar xfvz mysql-5.7*
echo "stopping mamp"
sudo /Applications/MAMP/bin/stop.sh
sudo killall httpd mysqld
echo "creating backup"
@kadnan
kadnan / grab_data.py
Created Sep 23, 2016
Fetching, parsing and cleaning Pakistan England Test data from Cricinfo
View grab_data.py
"""
This will grab the data from CricInfo Site about TestMatch Played by Pakistan against England from 1954-till now
"""
import requests
from bs4 import BeautifulSoup
url = 'http://stats.espncricinfo.com/ci/engine/team/7.html?class=1;opposition=1;template=results;type=team;view=results'
r = requests.get(url)
html = r.text
@kadnan
kadnan / transform_data.py
Created Sep 23, 2016
Transformation of data for training and test data
View transform_data.py
import pandas as pd
file_name = 'data_england_test.csv'
fields = ['Result','Toss','Bat']
df = pd.read_csv(file_name,skipinitialspace=True,usecols=fields)
df.to_csv('data_england_test_filter.csv',index=False)
# Convert features and labels into digits
df_replace = df.replace(['lost','draw','won','1st','2nd'],[-1,0,1,-1,1])
dataset_length = len(df_replace)
# 67% of training data
@kadnan
kadnan / predict.py
Created Sep 23, 2016
Prediction of Match results by running Naive Bayes
View predict.py
"""
Labels : Lost, Draw, Won [-1,0,1]
Features
==========
Toss(Lost,Won) = [-1,1]
Bat(First, Second) = [-1,1]
"""
# Import Library of Gaussian Naive Bayes model
from sklearn.naive_bayes import GaussianNB
@kadnan
kadnan / mergcsv.php
Created Oct 7, 2016
To Merge CSV files by Header Keys
View mergcsv.php
<?php
$files_to_read = ['file1.csv', 'file2.csv', 'file3.csv'];
$all = [];
$merged_file = [];
$_row = [];
$val = '';
/**
* Read CSV file and return data associated with it's key
* @param $file_name
@kadnan
kadnan / RegisterController.php
Created Dec 8, 2016
Register a Social user manually
View RegisterController.php
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use League\Flysystem\Exception;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
use Socialite;
@kadnan
kadnan / listing_seq.py
Created Dec 11, 2016
Scraping OLX Listing
View listing_seq.py
import requests
from bs4 import BeautifulSoup
from time import sleep
def get_listing(url):
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'}
html = None
links = None
@kadnan
kadnan / beautiful_idiomatic_python.md
Created Mar 15, 2017 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!
View beautiful_idiomatic_python.md

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@kadnan
kadnan / fabfile
Created May 15, 2017
Gist for Automating remote and local git commands
View fabfile
from fabric.api import *
from fabric.colors import red, green
from time import sleep
from pprint import pprint
from fabric.contrib.files import exists
def local_git():
is_done = True
@kadnan
kadnan / producer-raw-recipies.py
Created Jun 10, 2018
methods to connect Kafa Producer and publishing data.
View producer-raw-recipies.py
def publish_message(producer_instance, topic_name, key, value):
try:
key_bytes = bytes(key, encoding='utf-8')
value_bytes = bytes(value, encoding='utf-8')
producer_instance.send(topic_name, key=key_bytes, value=value_bytes)
producer_instance.flush()
print('Message published successfully.')
except Exception as ex:
print('Exception in publishing message')
print(str(ex))