Skip to content

Instantly share code, notes, and snippets.

View nikhilkumarsingh's full-sized avatar
🎯
Focusing

Nikhil Kumar Singh nikhilkumarsingh

🎯
Focusing
View GitHub Profile
@nikhilkumarsingh
nikhilkumarsingh / call_by_object.ipynb
Created May 14, 2018 17:43
Parameter passing in Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nikhilkumarsingh
nikhilkumarsingh / myshell.py
Created May 14, 2018 19:31
A simple Python Interactive Shell
while 1:
x = input(">>> ")
if x == 'exit':
break
try:
y = eval(x)
if y: print(y)
except:
try:
import requests
from bs4 import BeautifulSoup
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
login_data = {
'name': '<username>',
'pass': '<password>',
@nikhilkumarsingh
nikhilkumarsingh / real_time.ipynb
Created August 19, 2018 20:04
Plotting real time data using Python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import requests
from bs4 import BeautifulSoup
from random import choice
def get_proxy():
url = "https://www.sslproxies.org/"
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html5lib')
return {'https': choice(list(map(lambda x:x[0]+':'+x[1], list(zip(map(lambda x:x.text, soup.findAll('td')[::8]),
@nikhilkumarsingh
nikhilkumarsingh / pandas_lazy_io.md
Created September 21, 2018 13:03
Read CSV files in pandas in lazy manner
reader = pd.read_csv(filename, iterator=True)

## to get first n lines
reader.get_chunk(n)

## to get next n lines and so on
reader.get_chunk(n)
@nikhilkumarsingh
nikhilkumarsingh / randomize_dict.py
Created September 22, 2018 11:13
Randomize dictionary in Python
import random
d = {'a':1, 'b':2, 'c':3, 'd':4}
for key,val in zip(d.keys(), random.sample(list(d.values()), k=len(d.values()))):
d[key] = val
print(d)
import time
import psutil
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
fig.show()
i = 0
x, y = [], []
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nikhilkumarsingh
nikhilkumarsingh / Tutorial.ipynb
Last active February 1, 2019 13:54
Nested Loops in List Comprehension
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.