Skip to content

Instantly share code, notes, and snippets.

View pepoluan's full-sized avatar
🏡

Pandu E POLUAN pepoluan

🏡
View GitHub Profile
@pepoluan
pepoluan / RegexLookup.vb
Last active September 13, 2024 08:11
RegexLookup function for Excel
' This is supposed to be a VBA (VB for applications) module, but GitHub does not have a syntax-highlighter for .vba files
'
' SPDX-License-Identifier: MPL-2.0
'
' This Source Code Form is subject to the terms of the Mozilla Public
' License, v. 2.0. If a copy of the MPL was not distributed with this
' file, You can obtain one at https://mozilla.org/MPL/2.0/.
' REQUIREMENTS:
' - You MUST add a reference to "Microsoft VBScript Regular Expressions 5.5" (or any compatible versions)
@pepoluan
pepoluan / pwgen.py
Last active September 17, 2024 09:35
pwgen utility -- in Python
#!/usr/bin/env python3
# SPDX-License-Identifier: MPL-2.0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
from __future__ import annotations
import argparse
import random
import secrets
@pepoluan
pepoluan / sponge.py
Last active September 10, 2024 08:16
sponge utility -- in Python
#!/usr/bin/env python3
# SPDX-License-Identifier: MPL-2.0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
from __future__ import annotations
import argparse
import sys
import tempfile
@pepoluan
pepoluan / self-create-venv.py
Created May 16, 2024 10:37
Self-creating a virtualenv with required modules
import subprocess
import sys
import tempfile
from pathlib import Path
try:
### PERFORM IMPORTS OF NEEDED MODULE IN THIS try: BLOCK
from rich.traceback import install as rtb_install
rtb_install(show_locals=True)
@pepoluan
pepoluan / check-group.sh
Last active April 2, 2024 10:51
Check for User Nonsense
#!/bin/bash
for i in $(cut -s -d: -f4 /etc/passwd | sort -u ); do
if ! grep -q -P "^.*?:x:$i:" /etc/group; then
echo "Group $i is referenced by /etc/passwd but does not exist in /etc/group"
fi
done
@pepoluan
pepoluan / kernel_config_sort.py
Created March 15, 2024 11:59
Linux kernel config sorter
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2024, Pandu POLUAN
import fileinput
import re
@pepoluan
pepoluan / json_cleaner.py
Last active April 13, 2024 14:48
Python-based JSON Cleanup Preprocessor
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Context: https://stackoverflow.com/a/56701174/149900
from io import StringIO
WHITESPACE = " \t\r\n"
@pepoluan
pepoluan / perftest.py
Created October 7, 2021 05:17
Sort By .items() vs Sort By .keys()
import pprint
import random
import timeit
MEMBS_COUNT = 100
indexes = list(range(MEMBS_COUNT))
random.shuffle(indexes)
orig_dict = {}
@pepoluan
pepoluan / dupefinder.py
Last active May 16, 2024 16:59
Python DupeFinder
#!/usr/bin/env python3.9
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
import os
import time
import xxhash
from collections import namedtuple
@pepoluan
pepoluan / example.py
Created December 14, 2020 16:55
Simple RFC5424-over-UDP Logging Handler & Formatter
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
facility = 23 # local7; see RFC 5424
formatter = RFC5424Formatter(appname="my-awesome", facility=facility)
syslog_handler = UTF8DatagramHandler("127.0.0.1", 514)
syslog_handler.setFormatter(formatter)
syslog_handler.setLevel(logging.DEBUG)
logger.addHandler(syslog_handler)