Skip to content

Instantly share code, notes, and snippets.

Avatar

Adrian Mark Clave Perea adrianmarkperea

View GitHub Profile
@adrianmarkperea
adrianmarkperea / corr.py
Created Aug 27, 2020
Simple Correlation Matrix with Heat Map using Pandas and Seaborn
View corr.py
import seaborn as sns
fig = plt.subplots(figsize = (10,10))
sns.set(font_scale=1.5)
sns.heatmap(df.corr(),square = True,cbar=True,annot=True,annot_kws={'size': 10})
plt.show()
View ES6_classes.js
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
fullName() {
console.log(`${firstName} ${lastName}`);
}
}
View dynamic_functions.js
Person.prototype.sayHi = function() {
console.log(`Hi! I'm ${this.firstName}`);
}
// Note that we did not recreate the objects here
personA.sayHi(); // Hi! I'm Adrian
personB.sayHi(); // Hi! I'm Be
View shared_functions.js
personA.fullName === personB.fullName === Person.prototype.fullName
View construction_functions.js
function Person(firstName, lastName) {
// 1. An implicit object is created that we can reference with `this`
this.firstName = firstName;
this.lastName = lastName;
}
// 2. The resulting instance has a copy of the
// constructor function's prototype property
// inside its own prototype.
Person.prototype.fullName = function() {
View construction_functions.js
function Person(firstName, lastName) {
// 1. An implicit object is created that we can reference with `this`
this.firstName = firstName;
this.lastName = lastName;
}
// 2. The resulting instance has a copy of the
// constructor function's prototype property
// inside its own prototype.
Person.prototype.fullName = function() {
View normal_functions.js
function Person(firstName, lastName) {
return {
firstName,
lastName,
fullName() {
console.log(`${this.firstName} ${this.lastName}`)
}
};
}
View traditional_oop.py
class Person:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
def print_full_name(self):
print(f'{self.first_name} {self.last_name}')
person_a = Person('Adrian', 'Perea')
person_b = Person('Ben', 'Halpern')
View decorating_externals_functions.py
import numpy as np
rng = np.random.RandomState(0)
# Create a lot of numbers
nums = rng.random(10000000)
# Decorate np.sort with our time_it transformer
timed_sort = time_it(np.sort)
# Perform the sort with our time_it functionality
timed_sort(nums)