Skip to content

Instantly share code, notes, and snippets.

@ty-shaikh
ty-shaikh / car.rb
Created June 9, 2016 19:54
OOP Practice
class Car
attr_accessor :brand, :model
def initialize(brand, model)
@brand = brand
@model = model
end
def name
puts "#{self.brand} #{self.model}"
@ty-shaikh
ty-shaikh / application.js
Last active June 10, 2016 21:25
Pagination example
//= require paginate
@ty-shaikh
ty-shaikh / project_structure.txt
Last active August 6, 2018 20:33
Data Science Project Structure
├── README.md <- The top-level README for developers using this project.
├── data
│ ├── external <- Data from third party sources.
│ ├── interim <- Intermediate data that has been transformed.
│ ├── processed <- The final, canonical data sets for modeling.
│ └── raw <- The original, immutable data dump.
├── models <- Trained and serialized models, model predictions, or model summaries
├── notebooks <- Jupyter notebooks. Naming convention is a number (for ordering),
@ty-shaikh
ty-shaikh / imperative.py
Created December 4, 2018 16:31
Programming Paradigm -- Imperative
# Imperative
lines = open('data.txt')
broken_lines = [l.split(',') for l in lines]
ages_by_state = {}
for bl in broken_lines:
state, age = bl[2], bl[5]
state = state.strip().lower().replace(’.’,’’)
age = float(age)
if state in ages_by_state.keys():
@ty-shaikh
ty-shaikh / functional.py
Created December 4, 2018 16:33
Programming Paradigm -- Functional
# Functional
def normalize_state(s):
return s.strip().lower().replace(’.’,’’)
def mean(nums):
return sum(nums) / len(nums)
def extract_state_age(l):
pieces = l.split(’,’)
return normalize_state(state), float(age)
@ty-shaikh
ty-shaikh / side_effects.py
Created December 4, 2018 16:34
Programming Paradigm - Side Effects
print('Hello world!')
a = a + 1
@ty-shaikh
ty-shaikh / functional_v2.py
Created December 4, 2018 16:36
Programming Paradigm - Functional v2
def get_year_extractor(example_date):
# not sure if example_date is YYYYMMDD
# or YYYY‐MM‐DD or MM‐DD‐YYYY
if len(example_date)==8:
return lambda d: d[:4]
elif (example_date[4]==’-’ and example_date[7]==’-’):
return lambda d: d[:4]
else:
return lambda d: [‐4:]
@ty-shaikh
ty-shaikh / oop_origin.py
Created December 4, 2018 16:37
Programming Paradigm - OOP Origin
# OOP
x, y = 4, 5
x + y
>> 9
x.__add__(y)
>> 9
@ty-shaikh
ty-shaikh / oop.py
Created December 4, 2018 16:38
Programming Paradigm - OOP
# OOP
class Animal:
def __init__(self, name):
self.name = name
class Parrot(Animal):
def talk(self):
print self.name + ‘ want a cracker!’
@ty-shaikh
ty-shaikh / bad_code.py
Last active December 31, 2018 02:05
Bad Code
import urllib
url = "https://en.wikipedia.org/wiki/Dangiwa_Umar"
cont = urllib.urlopen(url).read()
from HTMLParser import HTMLParser
class Parser(HTMLParser):
def handle_starttag(self, x, y):
if x=='p': self.inp = True
if x=='a':
try:
if self.inp: