Skip to content

Instantly share code, notes, and snippets.

View inesusvet's full-sized avatar
🇬🇧
You know: fish, chips, cup 'o tea, bad food, worse weather, Mary flippin Poppins

Ivan Styazhkin inesusvet

🇬🇧
You know: fish, chips, cup 'o tea, bad food, worse weather, Mary flippin Poppins
View GitHub Profile
@inesusvet
inesusvet / time-keeper.py
Created September 4, 2017 19:09
Kill child by timeout
"""
Simple watchdog which kills the command affter timeout.
You can specify the timeout in seconds for kill by env-variable TIMEOUT
Example:
TIMEOUT=300 python time-keeper.py this-will-hang-up-but-gonna-be-killed-in-5-mins.exe
"""
import logging
import os
import subprocess
@inesusvet
inesusvet / shena-parser.py
Created August 17, 2017 20:12
Преобразование выгрузки транзакций из "нативного" php формата в csv
from __future__ import print_function
INPUT_FILENAME = 'export_dmr.txt'
OUTPUT_FILENAME = 'export_dmr.csv'
FIELDS = [
'dmr_transaction_id',
'paid_at',
'purchase_price',
'purchase_currency',
'order_price',
@inesusvet
inesusvet / 10-flake8.py
Created August 1, 2017 06:36
Git pre-commit hook to check code style of changed files right at commit time
from __future__ import print_function
"""
Pre-commit hook for PEP8 styling
Works well with flake8==3.0.4
"""
__author__ = 'Ivan Styazhkin <[email protected]>'
import subprocess
import sys
@inesusvet
inesusvet / proto.js
Last active February 19, 2025 17:37
module.exports = {
package: null,
syntax: "proto2",
messages: [{
name: "Msg",
syntax: "proto2",
fields: [{
rule: "optional",
type: "Commands",
name: "command_number",
@inesusvet
inesusvet / watchdog.py
Last active June 26, 2017 11:49
Restarts the target process when it exits
"""
Simple watchdog which just restarts the command.
You can specify the limit for restarts by env-variable LIMIT
Example:
LIMIT=10 python watchdog.py this_may_fall.exe
"""
import logging
import os
@inesusvet
inesusvet / watch_bro.py
Created June 24, 2017 20:18
Watch dog which knows only one trick
"""
Watchdog which can do one trick only - to sniff for a pattern in a log file and
"bark" by running some command. The program won't stop after "barking".
Usage:
python watch_bro.py <filename> <pattern> <command>
filename: A file to watch for changes
pattern: A string to look for in the file
command: What to execute when the pattern occurs
# -* coding: utf-8 -*-
"""
Memento
Не нарушая инкапсуляцию, определяет и сохраняет внутреннее состояние объекта и позволяет позже восстановить объект в этом состоянии
Chain of responsibility
Избегает связывания отправителя запрос с его получателем, давая возможность обработать запрос более чем одному объекту. Связывает объекты-получатели и передает запрос по цепочке пока объект не обработает его
Observer
@inesusvet
inesusvet / walk-game.py
Created March 14, 2017 10:41
Игра-бродилка
"""
Имеется лабиринт, нужно провести игрока к сокровищу
"""
import os
LOCATION_FILENAME = '.location'
TEST_LOCATION = [
[1, 1, 1],
[1, 0, 1],
@inesusvet
inesusvet / colored_formatter.py
Last active October 13, 2016 20:57
Форматтер для разноцветных записей в логах
from __future__ import print_function
import logging
class ColoredFormatter(logging.Formatter):
"""
See more colors and styles at http://stackoverflow.com/a/21786287
"""
@inesusvet
inesusvet / user-admin.py
Created September 30, 2016 16:59
Создание linux-пользователя по шаблону
# ~*~ coding: utf-8 ~*~
import datetime
import os
import sys
import subprocess
"""
Документация по модулю subprocess, который позволяет вызывать другие процессы,
писать им в stdin, читать из stdout и stderr, проверять код их завершения
https://docs.python.org/2/library/subprocess.html