Skip to content

Instantly share code, notes, and snippets.

@AlexxIT
AlexxIT / nginx.sublime-build
Created May 26, 2017 07:12
SublimeText nginx Build System
{
"cmd": ["nginx.exe", "-s", "reload"],
"file_regex": "conf$",
"selector": "source.nginx",
"working_dir": "$file_path/.."
}
@AlexxIT
AlexxIT / one_line.py
Created May 9, 2018 03:37
In one line in Python
items1 = ['abc', 'bcd', 'cde']
items2 = [[1, 2], [3, 4], [5, 6]]
# return first result from iterator (with optional default)
r1 = next((item for item in items1 if 'd' in item), None)
print(r1)
# return first True result
r2 = any('d' in item for item in items1)
print(r2)
docker stats --all --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"
docker-compose exec nginx sh -c 'nginx -t && nginx -s reload'
docker-compose exec haproxy haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg && docker-compose kill -s HUP haproxy

open ports

from fluent.runtime import FluentBundle
def equal(val1, val2):
if isinstance(val1, str) and isinstance(val2, str):
return val1.lower() == val2.lower()
return val1 == val2
bundle = FluentBundle(['ru'], use_isolating=False,
#!/bin/bash
name="hassio"
path="/home/alexey/hassio"
if [[ $1 == "stop" ]]; then
docker stop $name && docker rm $name
elif [[ $1 == "log" ]]; then
docker logs --tail=100 -f $name
@AlexxIT
AlexxIT / adblock_script.rsc
Last active August 23, 2019 10:16
Блокировка рекламы на RouterOS
:local url "https://gist.githubusercontent.com/.../.../raw/.../hosts-500.txt";
/ip dns static remove [/ip dns static find address=127.0.0.1];
/tool fetch mode=https url=$url dst-path="adblock.rsc";
/import file-name="adblock.rsc";
import base64
import hashlib
import hmac
import json
import time
import uuid
import requests
user = 'mymail@gmail.com'
import socket
_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
_socket.settimeout(5.0)
try:
_socket.sendto('{"cmd":"whois"}'.encode(), ('224.0.0.50', 4321))
recv = _socket.recvfrom(1024)
print(recv)
except Exception as e:
# custom_components/boiler/__init__.py
"""
1. Place file here: /config/custom_components/sonofftest/__init__.py
2. Add to configuration.yaml: `sonofftest: 192.168.1.123` (IP of sonoff)
3. Block the Sonoff from accessing the Internet
4. Restart Sonoff
5. Wait Sonoff LED to start blinking (two blinks every 2 seconds)
6. Restart HA
"""
import asyncio
import logging