Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
Focusing

Pavel Dmytrenko pavdmyt

🛠️
Focusing
View GitHub Profile
@pavdmyt
pavdmyt / get_block_time.sh
Created Sep 29, 2020
Print Prometheus block's minTime and maxTime
View get_block_time.sh
#!/bin/bash
# Given a Prometheus block name, prints timerange
# for the metrics stored inside.
#
# Usage example:
# for b in `cat block_names.txt`; do ./get_block_time.sh $b; done
TIMEZONE="EEST"
BLOCK_DIR="/srv/prometheus_data/$1"
View bootstrap-warm.sh
#!/bin/bash
# Turn off SWAP
sysctl vm.swappiness=0
echo 'vm.swappiness = 0' >> /etc/sysctl.conf
@pavdmyt
pavdmyt / .pypirc
Created Jan 27, 2019
pypirc; upload package to PyPI
View .pypirc
# ~/.pypirc upload to PyPI (legacy way)
# https://medium.freecodecamp.org/how-to-publish-a-pyton-package-on-pypi-a89e9522ce24
[distutils]
index-servers=pypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = <pypi-user>
password = <pypi-pwd>
View func_problems.py
"""
Some func problems
~~~~~~~~~~~~~~~~~~
Provide your solutions and run this module.
"""
def add(a, b):
@pavdmyt
pavdmyt / core_i3.txt
Last active Mar 20, 2018
Benchmarking various factorial function implementations.
View core_i3.txt
Logical CPUs: 4
Value to calculate: 1e+06
---
SimpleFactFast -- elapsed time: 2.909772092s
HalfIterFact -- elapsed time: 1m8.50245915s
SimpleFactIter -- elapsed time: 1m57.486627904s
ConcFactIter :: workers 1 -- elapsed time: 1m54.401843303s
ConcFactIter :: workers 2 -- elapsed time: 42.335188303s
@pavdmyt
pavdmyt / ipv4_netmasks.py
Last active Aug 17, 2017
[Python] Print all valid IPv4 netmasks in dot-decimal notation.
View ipv4_netmasks.py
# -*- coding: utf-8 -*-
"""
Print all valid IPv4 netmasks in dot-decimal notation.
Netmask reference chart:
http://unixwiz.net/techtips/netmask-ref.html
"""
@pavdmyt
pavdmyt / syncer.py
Last active Aug 15, 2017
Daemon to sync current dir contents with remote
View syncer.py
# -*- coding: utf-8 -*-
"""
A daemon that monitors files mtimes and automaticaly syncs it
with remote if files have changed.
How to use:
~~~~~~~~~~~
1. $ python syncer.py
@pavdmyt
pavdmyt / clean_requirements.py
Created Feb 1, 2017
clean requirements-dev.in
View clean_requirements.py
#!/usr/bin/env python
"""
Remove all packages from requirements-dev.txt
except of listed in PACKAGES.
"""
import os
@pavdmyt
pavdmyt / infinite_for_loops.py
Created Aug 29, 2016
Some implementations of infinite / endless for loops in Python.
View infinite_for_loops.py
"""
Some implementations of infinite / endless for loops in Python.
No practical applications, just pure theoretical interest :)
C/C++ example:
for (;;) {}
src: https://stackoverflow.com/questions/5737196/an-expression-for-an-infinite-generator
"""
import itertools
View cached_property.py
"""
Is analogous to @reify
Borrowed from here: https://github.com/aio-libs/yarl/blob/master/yarl/__init__.py
Topic references:
https://www.reddit.com/r/learnpython/comments/2oqusj/pyramids_reify_descriptor_could_it_be_simplified/
http://www.gghh.name/dibtp/2013/06/18/caching-in-python-with-a-descriptor-and-a-decorator.html
"""