Skip to content

Instantly share code, notes, and snippets.

View carlomazzaferro's full-sized avatar

Carlo Mazzaferro carlomazzaferro

View GitHub Profile
carlomazzaferro / FusePoolLensSecondary.sol
Created November 1, 2021 11:54 — forked from sharad-s/FusePoolLensSecondary.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "./external/compound/Comptroller.sol";
import "./external/compound/PriceOracle.sol";
carlomazzaferro /
Created March 27, 2020 20:01
Get object size
import sys
from types import ModuleType, FunctionType
from gc import get_referents
# Custom objects know their class.
# Function objects seem to know way too much, including modules.
# Exclude modules as well.
BLACKLIST = type, ModuleType, FunctionType
carlomazzaferro /
Created March 27, 2020 12:53
Prophet's Memory Usage
from fbprophet import Prophet
import io
import requests
url = ""
s = requests.get(url).content
df = pandas.read_csv(io.StringIO(s.decode('utf-8')))
m = Prophet()
carlomazzaferro /
Created November 22, 2018 00:21
Inheriting docstrings from a top level function with decorators
This is particularly useful when using sphinx autodoc, when you have functions that share the same functionality
(say a cli command that wraps a function) and you don't want to rewrite the docstrings for each of them.
def register_docstrings(parent=None):
def doc_decorator(func):
func.__doc__ = parent.__doc__ + func.__doc__
return func
return doc_decorator
carlomazzaferro /
Last active February 1, 2017 07:59
OOP approach to creating a predictive model using perceptron learning in Python.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
class Perceptron(object):
def __init__(self, train, labels, learning_rate, iterations):
self.train = train
self.labels = labels
carlomazzaferro /
Created December 2, 2016 00:04
Parsing fasta file to python lists: protein ID, peptide sequence
def create_separate_lists(fasta_file):
Creates 2 lists from a fasta file
:param fasta_file: file
:return: one list for the IDs in the file and one list for the proteins/peptides in it
with open(fasta_file) as infile:
all_list = []
peptide = ""
lines = infile.readlines()