Skip to content

Instantly share code, notes, and snippets.

@nijave
nijave / tethering.sh
Created June 20, 2021 21:03
Android 10 Tethering Fix
#!/bin/sh
# Don't require DUN APN type
settings put global tether_dun_required 0
# use MagiskHide Props Config
# echo "net.tethering.noprovisioning=true" >> /system/build.prop
# iptables increment TTL for nat packets since carriers block these
# Requires kernel with CONFIG_IP_NF_TARGET_TTL enabled
# see https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/
import requests
from requests.adapters import HTTPAdapter, Retry
class TimeoutHTTPAdapter(HTTPAdapter):
DEFAULT_TIMEOUT = 30
def __init__(self, *args, **kwargs):
@nijave
nijave / cluster_dash.py
Last active May 23, 2021 19:34
CloudWatch CPU/Disk IOPs dashboard JSON generator for ASG-backed EC2 ECS clusters
import boto3
import json
# assumes ASG has tag Name="ECS Cluster - cluster_name"
cluster_name = "some-clsuter"
asgs = [
{
"name": asg["AutoScalingGroupName"],
"instance_type": asg["Instances"][0]["InstanceType"],
@nijave
nijave / pyiostat.py
Last active May 12, 2021 21:20
Rudimentary iostat in Python to demo sysfs block device stats
# pyiostat
import os
import time
from pprint import pprint
# https://www.kernel.org/doc/html/latest/block/stat.html
stat_labels_extended = [
# reads
@nijave
nijave / gigabyte-x470-gaming-7-sensors.sh
Last active July 1, 2024 00:13
Setup sensors for Gigabyte X470 Gaming 7 w/ Fedora
#!/bin/sh
# The chip info can be found via sensors-detect in lm_sensors
# Driver `to-be-written':
# * ISA bus, address 0xa40
# Chip `ITE IT8686E Super IO Sensors' (confidence: 9)
# Driver `it87':
# * ISA bus, address 0xa60
# Chip `ITE IT8792E Super IO Sensors' (confidence: 9)
@nijave
nijave / python_apache_logs.py
Last active May 4, 2021 02:08 — forked from sumeetpareek/python_apache_logs.py
A very simple Apache access log parser in Python
#!/usr/bin/env python3
import json
import re
import sys
parts = [
r'(?P<host>\S+)', # host %h
r'\S+', # indent %l (unused)
r'(?P<user>\S+)', # user %u
@nijave
nijave / s3_access_log_summary.py
Last active April 30, 2021 17:25
Shows a summary of information from AWS S3 Access logs assuming they're in the same directory
#!/usr/bin/env python3
import os
import re
# Reference https://stackoverflow.com/questions/7961316/regex-to-split-columns-of-an-amazon-s3-bucket-log
parse = re.compile(r"([^\s\"\[\]]+|\[[^\]\[]+\]|\"[^\"]+\")\s+")
logs = (
l.strip()
@nijave
nijave / logging.py
Last active April 13, 2021 02:31
Python logger setup (with alternate format)
import logging
import os
log = logging.getLogger(__file__ if __name__ == "__main__" else __name__)
logging.basicConfig(
level=getattr(logging, os.environ.get("LOG_LEVEL", "INFO").upper()),
format="%(asctime)s [%(levelname)s]: %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S%z",
)
@nijave
nijave / dkim-rotate.py
Created April 1, 2021 01:02
A simple opendkim key rotator
#!/usr/bin/env python3
# Note: many os-related methods in python3.5 don't accept
# pathlib.Path and require manual conversion to string, first
import os
import random
import re
import shutil
import subprocess
@nijave
nijave / sas_devices.py
Last active December 7, 2021 11:33
Convert sas2ircu output to json for easier use in other tools
#!/usr/bin/env python3
"""
Usage:
./sas_devices.py - json output
./sas_devices.py --summary - human output with locations and serial
Warning: sas2ircu invocations have occassionally caused kernel
panics on previous FreeBSD installations
Related https://redmine.ixsystems.com/issues/14859