This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
attr_accessor :brand, :model | |
def initialize(brand, model) | |
@brand = brand | |
@model = model | |
end | |
def name | |
puts "#{self.brand} #{self.model}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//= require paginate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├── 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), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('Hello world!') | |
a = a + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OOP | |
x, y = 4, 5 | |
x + y | |
>> 9 | |
x.__add__(y) | |
>> 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OOP | |
class Animal: | |
def __init__(self, name): | |
self.name = name | |
class Parrot(Animal): | |
def talk(self): | |
print self.name + ‘ want a cracker!’ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
OlderNewer