Skip to content

Instantly share code, notes, and snippets.

View pavdmyt's full-sized avatar
🛠️
Focusing

Pavel Dmytrenko pavdmyt

🛠️
Focusing
View GitHub Profile
@pavdmyt
pavdmyt / get_block_time.sh
Created September 29, 2020 09:45
Print Prometheus block's minTime and maxTime
#!/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"
#!/bin/bash
# Turn off SWAP
sysctl vm.swappiness=0
echo 'vm.swappiness = 0' >> /etc/sysctl.conf
@pavdmyt
pavdmyt / .pypirc
Created January 27, 2019 22:49
pypirc; upload package to PyPI
# ~/.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>
"""
Some func problems
~~~~~~~~~~~~~~~~~~
Provide your solutions and run this module.
"""
def add(a, b):
@pavdmyt
pavdmyt / core_i3.txt
Last active March 20, 2018 16:18
Benchmarking various factorial function implementations.
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 August 17, 2017 10:26
[Python] Print all valid IPv4 netmasks in dot-decimal notation.
# -*- 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 August 15, 2017 09:36
Daemon to sync current dir contents with remote
# -*- 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 February 1, 2017 09:55
clean requirements-dev.in
#!/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 August 29, 2016 15:26
Some implementations of infinite / endless for loops in Python.
"""
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
@pavdmyt
pavdmyt / cached_property.py
Last active September 22, 2016 12:53
Code snippets
"""
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
"""