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 / permutation.py
Created July 7, 2017 12:00
Search list of reasonable words in a scrambled collection of letter
from nltk.corpus import wordnet
import threading
from queue import Queue
from datetime import datetime
import time
class WordSearch:
def __init__(self):
self.combo = set()
@victor-iyi
victor-iyi / password_hashing.py
Created August 27, 2017 13:48
Password hashing
import uuid
import hashlib
splitter = '$'
def hash_password(password):
# userid is used to generate a random number
salt = uuid.uuid4().hex # salt is stored in hex value
hash_pass = '{}{}{}'.format(
hashlib.sha256(salt.encode() + password.encode()).hexdigest(),
@victor-iyi
victor-iyi / vic-sort.py
Created August 27, 2017 13:55
An optimized sorting algorithm
'''
VICTOR's sorting algorithm!
=> vicSort
HOW vicSort WORKS
not_sorted = [2, 4, 1, 8, 5]
sorted = []
[2] # If no element in `sorted` add the first one
@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',
@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 / 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 / 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 / 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 / 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 / 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)