Skip to content

Instantly share code, notes, and snippets.

View mzpqnxow's full-sized avatar

AG mzpqnxow

View GitHub Profile
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /db/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
@mzpqnxow
mzpqnxow / rc.local
Created August 22, 2021 15:26 — forked from yspb/rc.local
#!/bin/sh
sysctl vm.overcommit_memory=1
sysctl -w net.core.somaxconn=65535
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
exit 0
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
@mzpqnxow
mzpqnxow / redis.conf
Created August 22, 2021 15:25 — forked from yspb/redis.conf
################################## MODULES #####################################
loadmodule /db/modules/libredis-roaring.so
loadmodule /db/modules/rejson.so
loadmodule /db/modules/redisearch.so
################################## NETWORK #####################################
bind 127.0.0.1
protected-mode yes
@mzpqnxow
mzpqnxow / node.sh
Created August 22, 2021 15:24 — forked from yspb/node.sh
#make directories
mkdir /git
mkdir /db
mkdir /db/modules
mkdir /downloads
#update packages, install gcc and redis
add-apt-repository ppa:chris-lea/redis-server -y && \
apt-get update && \
apt-get upgrade -y && \
@mzpqnxow
mzpqnxow / lzmarotate.py
Last active January 5, 2022 16:55
LZMA compressed RotatingFileHandler with support for backupCount
"""Example extension of RotatingFileHandler that LZMA compresses the rotated files
Other examples I found didn't actually respect maxBackups, this does
- AG
"""
import codecs
import glob
import logging.handlers
import os
@mzpqnxow
mzpqnxow / logging.py
Created August 8, 2021 15:36 — forked from kingspp/logging.py
Python Comprehensive Logging using YAML Configuration
import os
import yaml
import logging.config
import logging
import coloredlogs
def setup_logging(default_path='logging.yaml', default_level=logging.INFO, env_key='LOG_CFG'):
"""
| **@author:** Prathyush SP
| Logging Setup
@mzpqnxow
mzpqnxow / cachetools-example.py
Created August 1, 2021 15:08
Using cachetools as a convenient short-hand to use Python functiion caching for a specific argument
from cachetools import cached
from cachetools.keys import hashkey
from random import randint
@cached(cache={}, key=lambda db_handle, query: hashkey(query))
@cached(cache={}, key=lambda db_handle, query: hashkey(query))
def find_object(db_handle, query):
saved = query
query = 5
@mzpqnxow
mzpqnxow / python-to-yaml.py
Created July 27, 2021 18:42
Python module variables to YaML
"""Enumerate and export a bunch of structured or scalar objects from a Python module to YaML
This enumerates everything in the module in the globals namespace automatically, skipping
a few things (like things starting with `__`)
Useful when you have a ton of constants (including some that are lists, tuples, dicts, etc) in a
Python module and you want to put them into YaML to maintain separately from the Python code. It's
not a difficult task, but it becomes painful when there are 10-20 (or more) different objects. This
just automates it
@mzpqnxow
mzpqnxow / igrep.sh
Last active July 22, 2021 17:47
In place grep - why would anyone want to do such a thing!?
#!/bin/bash
#
# WARNING: YOU WILL LOSE THE FILE IF YOU SCREW UP BE CAREFUL
# If UNSAFE is set to YES, no backup will occur; you better not screw up!
# grep args or pattern because your file will be gone :>
#
# - AG
set -Eu
declare -r UNSAFE=YES