Skip to content

Instantly share code, notes, and snippets.

View Olshansk's full-sized avatar
🦉

Daniel Olshansky Olshansk

🦉
View GitHub Profile
@Olshansk
Olshansk / gist:42007ef6a57620424abcd780ced0cb5b
Created November 23, 2017 04:25
Blockstack Verification
Verifying my Blockstack ID is secured with the address 1PwrzAjKF65Wme7JsddXGsqjTKeuQ42K3e https://explorer.blockstack.org/address/1PwrzAjKF65Wme7JsddXGsqjTKeuQ42K3e
@Olshansk
Olshansk / bitcoin_analysis.py
Created December 22, 2017 02:11
Basic analysis of some bitcoin stats
from datetime import timedelta
from apscheduler.schedulers.blocking import BlockingScheduler
import requests, json, datetime, numpy, requests_cache
import matplotlib.dates as mdate
import matplotlib.pyplot as plot
import numpy as np
ALL_HISTORICAL_DATA_ENDPOINT = 'https://blockchain.info/charts/market-price?timespan=all&format=json'
NUM_UNIQUE_ADDRESSES = 'https://blockchain.info/charts/n-unique-addresses?timespan=all&format=json'
@Olshansk
Olshansk / get_stats_profile.py
Created February 17, 2020 02:02
Manual import source code from StatsProfile.get_stats_profile (bpo-37958)
from pstats import func_std_string, f8
from dataclasses import dataclass
from typing import Dict
@dataclass(unsafe_hash=True)
class FunctionProfile:
ncalls: int
tottime: float
percall_tottime: float
cumtime: float
@Olshansk
Olshansk / get_stats_profile_log_generation.py
Last active February 17, 2020 15:20
A short script that simulates stats profile logging at regular time intervals
import cProfile, pstats
import time
from random import randint
START_TIME = int(time.time())
timestamped_stats_profiles = []
def sleep1():
time.sleep(0.1)
@Olshansk
Olshansk / get_stats_profile_log_aggregation.py
Last active February 17, 2020 19:20
A short script that aggregates all the timestamped & logged stats profiles
from collections import Counter
import itertools
TIME_SLICE = 10 # Aggregate logs every 10 seconds
def time_to_bucket(time):
return (time-START_TIME) // TIME_SLICE
def bucket_to_time(bucket):
return bucket * TIME_SLICE + START_TIME
@Olshansk
Olshansk / get_stats_profile_visualization.py
Last active February 17, 2020 03:16
Visualize the results of all the aggregated stats profiles
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
WIDTH = 0.4
ind = np.arange(len(time_sliced_counters))
x_axis = tuple(time for (time, c) in time_sliced_counters)
@Olshansk
Olshansk / get_stats_profile_example_print_stats.py
Created February 17, 2020 14:43
An example of how to profile a simple python script using print_stats
import cProfile, pstats
import time
from random import randint
def sleep1():
time.sleep(0.1)
def sleep2():
time.sleep(0.2)
@Olshansk
Olshansk / joint_probability_matricies_1.py
Last active May 25, 2020 23:08
Joint Probability Matrices - Data Generation
# Data Generation
NUM_STUDENTS = 30
MEAN = 80
STD = 20
# https://stackoverflow.com/questions/36894191/how-to-get-a-normal-distribution-within-a-range-in-numpy
# Need to cap the values of the distributions to [0,100]
def get_truncated_normal(mean, sd, size, low, upp):
return truncnorm((low - mean) / sd, (upp - mean) / sd, loc=mean, scale=sd).rvs(size)
@Olshansk
Olshansk / joint_probability_matricies_2.py
Last active May 25, 2020 23:16
Transition Matricies - Bucketize Data
NUM_BINS = 10
bins = np.linspace(0, 100, NUM_BINS + 1)
# Note: we set include_lowest to true to make sure that we include zeroes
bucket_GT = pd.cut(grades_GT, bins=bins, include_lowest=True, right=True)
bucket_P = pd.cut(grades_P, bins=bins, include_lowest=True, right=True)
# Output of the cut function
pd.DataFrame({'grades': grades_GT, 'bucket': bucket_GT}).head()
@Olshansk
Olshansk / joint_probability_matricies_3.py
Last active May 25, 2020 23:24
Joint Probability Matricies - Group and Merge the Data
# Generate a pandas dataframe where the index represents the student number
df_GT = pd.DataFrame({'bucket': bucket_GT}).reset_index()
display(df_GT.head())
df_P = pd.DataFrame({'bucket': cut_P}).reset_index()
display(df_P.head())
# Merged the actual predicted grades
merged_df = pd.merge(df_GT, df_P, on=['index'], suffixes=('_grouth_truth', '_predicted'))
display(merged_df.head())