Skip to content

Instantly share code, notes, and snippets.

View dmitryhd's full-sized avatar

Dmitry Khodakov dmitryhd

View GitHub Profile
@dmitryhd
dmitryhd / pandas_cat_data_example.py
Created July 12, 2016 11:59
pandas: categorical data
import pandas as pd
df = pd.DataFrame({
'a': ['a', 'a', 'b', 'b', 'cc'],
'b': ['d', 'e', 'f', 'g', 'h'],
})
df.a.astype('category').cat.codes # + df.b.astype('category')
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/*
Name: Base16 Monokai Dark
Author: Wimer Hazenberg (http://www.monokai.nl)
CodeMirror template adapted for IPython Notebook by Nikhil Sonnad (https://github.com/nsonnad/base16-ipython-notebook)
CodeMirror template by Jan T. Sott (https://github.com/idleberg/base16-chrome-devtools)
Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16)
Fixed by DKhodakov
vim ~/.jupyter/custom/custom.css
/*
Name: Base16 Monokai Dark
Author: Wimer Hazenberg (http://www.monokai.nl)
CodeMirror template adapted for IPython Notebook by Nikhil Sonnad (https://github.com/nsonnad/base16-ipython-notebook)
CodeMirror template by Jan T. Sott (https://github.com/idleberg/base16-chrome-devtools)
Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16)
Fixed by DKhodakov
vim ~/.jupyter/custom/custom.css
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import time
import psutil
import os
class Timer:
def __init__(self, logger=None, msg='', log_start=True):
self.logger = logger
self.msg = msg
self.enter_memory_usage_mb = 0
@dmitryhd
dmitryhd / supervisord-example.conf
Created August 15, 2016 16:41 — forked from didip/supervisord-example.conf
Example configuration file for supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon
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
@dmitryhd
dmitryhd / send_to_carbon.py
Created November 2, 2016 14:26
Send to carbon
import socket
import time
CARBON_SERVER = '0.0.0.0'
CARBON_PORT = 2003
def send_to_carbon(metric: str, value, server: str, port=2003):
message = '{} {} {}\n'.format(metric, value, int(time.time()))
@dmitryhd
dmitryhd / latency.txt
Created December 2, 2016 14:04 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD