Skip to content

Instantly share code, notes, and snippets.

View kadnan's full-sized avatar
📢
Working from home

Adnan Siddiqi kadnan

📢
Working from home
View GitHub Profile
@kadnan
kadnan / beautiful_idiomatic_python.md
Created March 15, 2017 06:25 — 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!

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 / listing_seq.py
Created December 11, 2016 08:21
Scraping OLX Listing
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 / RegisterController.php
Created December 8, 2016 10:49
Register a Social user manually
<?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 / mergcsv.php
Created October 7, 2016 15:00
To Merge CSV files by Header Keys
<?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 / predict.py
Created September 23, 2016 06:01
Prediction of Match results by running Naive Bayes
"""
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 / transform_data.py
Created September 23, 2016 05:59
Transformation of data for training and test data
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 / grab_data.py
Created September 23, 2016 05:56
Fetching, parsing and cleaning Pakistan England Test data from Cricinfo
"""
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 / migrate.sh
Created June 16, 2016 14:12 — forked from dj1020/migrate.sh
Upgrade MAMP to Mysql 5.7 tested by Ken Lin 2015/11/09
#!/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"