Skip to content

Instantly share code, notes, and snippets.

View hardenchant's full-sized avatar

Gleb Lysov hardenchant

View GitHub Profile
@hardenchant
hardenchant / locker.py
Last active April 26, 2022 13:54
Run action when mac unlock
import logging
import os
# pip install pyobjc
from AppKit import NSDate, NSDistributedNotificationCenter, NSObject, NSRunLoop
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] %(levelname)s [%(funcName)s:%(lineno)d] %(message)s"
)
@hardenchant
hardenchant / bluetooth-speaker-power-control.py
Last active March 27, 2022 13:07
Power on over zigbee and notify when you connect to bluetooth
#!/usr/bin/python
import json
import logging
import logging.handlers
import os
import signal
import sys
import dbus
import dbus.mainloop.glib
@hardenchant
hardenchant / wg-install.sh
Created February 28, 2022 14:20
Setup new wg server
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "You need to run this script as root"
exit 1
fi
if [ "$(systemd-detect-virt)" == "openvz" ]; then
echo "OpenVZ is not supported"
exit
@hardenchant
hardenchant / wg-new-client.sh
Created January 16, 2022 14:04
Create new client for wireguard server
#!/bin/bash
export CLIENT_NUMBER='3'
export CLIENT_CONFIG_FILE="wg0-client$CLIENT_NUMBER.conf"
export CLIENT_PRIV_KEY="$(wg genkey)"
export CLIENT_PUB_KEY="$(echo $CLIENT_PRIV_KEY | wg pubkey)"
export CLIENT_WG_IPV4="10.66.66.$CLIENT_NUMBER"
export CLIENT_WG_IPV6="fd42:42:42::$CLIENT_NUMBER"
@hardenchant
hardenchant / render_client_path_from_logs.py
Created December 21, 2021 08:48
Render clientpath graph with GraphViz
import random
from datetime import datetime, timedelta
import graphviz
def generate_sample_data():
clients = [i for i in range(100)]
events = [f'page{i}' for i in range(20)]
now = datetime.now()
@hardenchant
hardenchant / pre-commit
Last active December 29, 2021 12:18 — forked from dreness/pre-commit
#git pre-commit #hook to set commit email address based on the repo's remote domain(s)
#!/bin/zsh
# source: https://gist.github.com/dreness/2de62e01d2053f9440eb
# Set repo's user.email to a default or alternate value based on remote domain.
# Because the in-flight commit info has already been set, if an email address
# change is needed, this commit is aborted. Retry the commit to use the new address.
#
# To automatically install custom hooks to new repos:
# 1) Add something like the following to ~/.gitconfig:
# [init]
# templatedir = ~/.git/templates
@hardenchant
hardenchant / mac_os_discord_autopatch.sh
Last active March 31, 2021 17:54
Install EnhancedDiscord on MacOS with plugins and config for 1080p 60fps streams
#!/bin/bash
# MacOS EnhancedDiscord installer with plugins and config for 1080p 60fps streams
# DISCLAIMER!
# Using EnhancedDiscord, or any other client mod, is against Discord's Terms of Service.
# Use it at your own risk. It's very unlikely any action will be taken against you,
# but we take no responsibility if anything happens.
# Usage:
# copy script into folder where you want store your EnhancedDiscord and plugins
@hardenchant
hardenchant / expand_partition_centos.md
Created June 14, 2019 17:14
Expand partition in CentOS 7. (vSphere)
# Before that, you must expand disk in vSphere
# /dev/sda - disk to expand
fdisk /dev/sda
n
p
[enter]
[enter]
[enter]
w
@hardenchant
hardenchant / moex_downloader.py
Created March 3, 2019 18:34
Download data to excel table from moex
import requests
import xlsxwriter
import json
start_date = "2000-03-01"
end_date = "2019-03-02"
link = f"https://iss.moex.com/iss/history/engines/stock/markets/shares/boardgroups/57/securities/SBER.jsonp?lang=ru&from=2000-03-01&till=2019-03-02&iss.json=extended&iss.meta=off&sort_order=TRADEDATE&sort_order_desc=desc&start="
resp = requests.get(link + "0")
@hardenchant
hardenchant / vpn_guide.md
Last active November 25, 2019 09:00
Working openvpn config

IPTABLES

Masquerade outgoing traffic

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

Allow return traffic

iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT