Skip to content

Instantly share code, notes, and snippets.

View DeastinY's full-sized avatar
🏠
Working from home

DeastinY DeastinY

🏠
Working from home
View GitHub Profile
@DeastinY
DeastinY / logging_sample.py
Created November 14, 2019 14:06
Example for python logging
#!/usr/bin/python3
import logging
# log levels are debug, info, warning, error and critical. Setting e.g. info logs info and above (warning, error, critical)
# logging.basicConfig(level=logging.INFO, filename="logging_sample.log")
# Basic logging is probably not sufficient. You can and should create your own Logger like this
logger = logging.getLogger('logging_sample') # Use this name to get the same logger from different submodules
FORMAT = "[%(filename)s:%(lineno)s - %(funcName)5s() ] %(message)s"
logging.basicConfig(format=FORMAT, filename="logging_sample.log", filemode="w") # default for filemode is append, w = (over)write
import timeit
import numpy as np
import pandas as pd
from pathlib import Path
def create_test_data(large=False, small=False):
# Note that a large_number by 1 dataframe is not really representative.
root = Path("tmp")
root.mkdir(exist_ok=True)
if large:
def calculate_horowitz(df):
"""calculates the Horowitz index, defined as PaO2/FIO2.
300-450: all fine (depending on age)
200-300: moderately severe lung damage
<200: severe lung damage"""
paO2 = df["paO2"]
if len(paO2) == 0:
return [np.nan] * len(df)
fiO2 = df["FiO2"]
if len(fiO2) == 0:
try:
df_a = pd.merge(x, y)
except pd.errors.MergeError: # occurs if only interventionids are used
df_a = None
try:
df_b = pd.merge(x, y)
except pd.errors.MergeError: # occurs if only attributeids are used
df_b = None
if df_a is None and df_b is None:
import time
from multiprocessing import Pool, cpu_count
def my_func(i):
time.sleep(1)
return i
print(cpu_count())
with Pool(cpu_count()) as pool:
@DeastinY
DeastinY / asic_plot.py
Created May 6, 2019 13:20
Basic, common style ASIC plot guide
width, height = 18, 14
plt.figure()
mydata.plot.bar(color='C0', figsize=(width, height))
ax = plt.gca()
ax.set_title("Title", size=28)
ax.set_ylabel("YLabel", size=24)
ax.set_xlabel("XLabel", size=24)
ax.grid(True)
ax.tick_params(axis="both", which="major", labelsize=18)
plt.tight_layout()
### Keybase proof
I hereby claim:
* I am deastiny on github.
* I am deastiny (https://keybase.io/deastiny) on keybase.
* I have a public key ASAA-92XOq0rTDS7myuZwjwZ4mTNCkmYN9tBpuQmoDsWmgo
To claim this, I am signing this object:
@DeastinY
DeastinY / input.txt
Last active December 3, 2018 13:07
Christmas Songs Dataset
O Come, All Ye Faithful
O come, all ye faithful, joyful and triumphant,
Come ye, O come ye, to Bethlehem.
Come and behold Him, born the King of angels;
Refrain
O come, let us adore Him,
O come, let us adore Him,
➜ ~ echo "test test" >> somefile.txt
➜ ~ gpg --symmetric somefile.txt
➜ ~ cat somefile.txt
test test
➜ ~ cat somefile.txt.gpg
���6,�f��I�� ؞�i���݇h��͡�~ �Nv�-�&��Z'�i�r57�"�˜vp�� ���\��jzuZT�8�_|➜ ~ rm somefile.txt
➜ ~ gpg -d somefile.txt.gpg
gpg: AES encrypted data
gpg: encrypted with 1 passphrase
test test

Keybase proof

I hereby claim:

  • I am deastiny on github.
  • I am deastiny (https://keybase.io/deastiny) on keybase.
  • I have a public key ASAVxM4gPtS-5S-2j0JZqeOTDMp3oKwPcGTV787VPlUWbwo

To claim this, I am signing this object: