Skip to content

Instantly share code, notes, and snippets.

View victor-iyi's full-sized avatar
🎯
Focusing

Victor I. Afolabi victor-iyi

🎯
Focusing
View GitHub Profile
@victor-iyi
victor-iyi / fibonacci.py
Created August 27, 2017 14:19
Explore 4 different implementations of Fibonacci algorithm
### PROGRAMMING FIBONACCI NUMBERS FROM BEGINNER TO EXPERT
### Method: 1
print('Method: 1')
def fibonacci(no):
series = [1,1]
for _ in range(1, no-1):
series.append(series[-1] + series[-2])
return series
@victor-iyi
victor-iyi / neighbors.py
Created August 27, 2017 14:16
A Naïve implementation of the K-Nearest neighbor's algorithm
from scipy.spatial.distance import euclidean
from collections import Counter
class KNeighborsClassifier:
def __init__(self, k=5):
self.k = k
def fit(self, X_train, y_train):
@victor-iyi
victor-iyi / cart_pole.py
Created August 27, 2017 14:14
A trained deep neural net capable of playing the OpenAI's cart pole game 😎
import gym
import random
import numpy as np
import tflearn
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
from statistics import mean, median
from collections import Counter
LR = 1e-3
@victor-iyi
victor-iyi / sock_data.py
Created August 27, 2017 14:12
Retrieve stock information for any named company's ticker
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import urllib
import numpy as np
def bytespdates2num(formt, encoding='utf-8'):
strconverter = mdates.strpdate2num(formt)
def bytesconverter(b):
s = b.decode(encoding)
return strconverter(s)
@victor-iyi
victor-iyi / source_code.py
Created August 27, 2017 14:11
Retrieve source code for any given URL
import urllib.request
import urllib.parse
def get(url):
try:
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
req = urllib.request.Request(url, headers=headers)
reqeust = urllib.request.urlopen(req)
resp = request.read().decode()
@victor-iyi
victor-iyi / curse-of-dimensionality.py
Created August 27, 2017 14:10
Estimate how long to brute force 1000 possible weights to train a Neural network
import numpy as np
time_taken_for_one_weight = 0.04
weights_to_try = 1000
weights_in_net = 8 # for 1 layer
one_year = 3600*24*365
years_to_train = time_taken_for_one_weight*(weights_to_try**weights_in_net)/one_year
print('{:,}'.format(years_to_train))
@victor-iyi
victor-iyi / regex.py
Created August 27, 2017 14:08
A guide to most used regular expressions in Python
import re
'''
Identifiers:
\d = any number
\D = anything but a number
\s = space
\S = anything but a space
\w = any letter
@victor-iyi
victor-iyi / 5-layer-convnet.py
Created August 27, 2017 14:06
A five (5) layer Convolutional Neural Network for classifying MNIST handwritten digits
# coding: utf-8
# # 5-Layer Convnet for classifying the MNIST dataset
# In[1]:
# importing the dependencies
import tensorflow as tf
import numpy as np
@victor-iyi
victor-iyi / part-of-speech-tag.py
Created August 27, 2017 14:04
Guide on using part of speech tagging with NLTK
import nltk
from nltk.corpus import state_union
from nltk.tokenize import PunktSentenceTokenizer
'''
POS tag list:
CC coordinating conjunction
CD cardinal digit
@victor-iyi
victor-iyi / lines-of-code.py
Created August 27, 2017 14:02
Estimate how many lines of code is in your project 😎
import os
import numpy as np
project_dir = '/Users/victor/Documents/Devcrib/DigiSchools/desktop/digischools-desktop'
ignored_files = ['node_modules', 'package-lock.json', 'uploads', 'fonts',
'bootstrap-grid.min.css', 'bootstrap.css', 'bootstrap.min.css', 'dropzone.css',
'owl.carousel.min.js', 'jquery.min.js', 'jquery-1.10.2.js', 'owl.carousel.min.css',
'owl.theme.default.min.css', 'owl.video.play.png', 'pretty.min.css',
'jquery_upload.min.js', 'datatables.min.js', 'dataTables', 'datatables.min.css',
'bootstrap.min.js', 'dropzone.js', 'tether.min.js', 'wow.min.js', 'font-awesome.min.css',