Skip to content

Instantly share code, notes, and snippets.

View dmitryhd's full-sized avatar

Dmitry Khodakov dmitryhd

View GitHub Profile
@dmitryhd
dmitryhd / README.md
Last active April 11, 2023 14:35
atomic vs mutex M2 benchmark

Surprisingly on Apple M2 (ARM) atomic is inferior to mutex.

g++ -std=c++20 -O3 atomic_vs_mutex_cnt.cpp -pthread
python3 run_counter.py > counter_perf.csv
pip3 install pandas seaborn
python3 plot.py

see result in mutex_vs_atomic_m2_chart.png

@dmitryhd
dmitryhd / colorlog.py
Last active June 27, 2019 20:55
python colored logs
class Color:
"""
https://misc.flogisoft.com/bash/tip_colors_and_formatting
https://gist.github.com/dmitryhd/68f2a71fb2832643217c17e61a78b214
"""
COLOR = '\033['
BOLD = '\033[1m'
RESET = '\033[0m'
DIM = '\e[2m'
BLINK = '\e[5m'
@dmitryhd
dmitryhd / line_profiler.py
Last active October 29, 2018 14:44
python line profiler
from line_profiler import LineProfiler
def profile_function(func, *args, **kwargs):
'''
Usage:
def long_function(x, y)
return x + y
z = profile_function(long_function, x=1, y=2)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmitryhd
dmitryhd / slackbot.py
Last active November 7, 2019 20:11
slackbot.py
__all__ = [
'SlackBot',
'RecBot',
]
import os
import time
import re
import subprocess
from functools import wraps
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
%matplotlib inline
plt.rcParams["figure.figsize"] = (12., 7.)
%config InlineBackend.figure_format = 'retina'
sns.set_style('dark')
matplotlib.rc('font', family='Arial') # in case of missing cyrillic fonts
import warnings; warnings.filterwarnings("ignore") # font warning
@h3
h3 / color.py
Last active June 27, 2019 19:38
Simple shell color outpout function
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
import sys
def c(i):
"""
import logging
import logging.handlers
import os.path as path
LOG_FORMAT = '[%(asctime)s] %(levelname)s %(message)s'
TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
LOG_DEFAULT_LEVEL = logging.DEBUG
import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
import seaborn as sns
%matplotlib inline
pylab.rcParams['figure.figsize'] = 12.0, 7.0
plt.rcParams['axes.labelweight'] = 'bold'
plt.rcParams['axes.titleweight'] = 'bold'
plt.rcParams['font.family'] = 'serif'
@dmitryhd
dmitryhd / logging.py
Last active July 20, 2017 11:22
Convenient logger helper
import logging
import logging.handlers
import os.path as path
def configure_logger(
logger_name='logger',
log_dir='/tmp/',
filename='',
to_stdout=True,