Skip to content

Instantly share code, notes, and snippets.

View pepoluan's full-sized avatar
🏡

Pandu E POLUAN pepoluan

🏡
View GitHub Profile
@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 / 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 / NFSU2_TexMod_CPUAff.ahk
Last active December 16, 2023 21:22
NFSU2 + TexMod Loader, also sets CPU Affinity
; The purpose of this script is to start Need for Speed: Underground 2 (NFSU2) from TexMod, after loading a
; texture replacement package (TPF). This script also sets CPU Affinity of NFSU2's SPEED2.EXE, because SPEED2.EXE
; is not happy with a multicore processor; it wants to stay on one core and one core only.
#Include <Affinity_Set>
; Affinity_Set() is a function from affinity.ahk, which should be placed in
; a lib/ subdirectory (from where this script is located)
; My version was from https://github.com/dufferzafar/Autohotkey-Scripts/blob/master/lib/Affinity.ahk
; ===== TUNABLES =====
@pepoluan
pepoluan / dupefinder.py
Last active August 26, 2023 04:19
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 / 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 / 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)
@pepoluan
pepoluan / detect_enc.py
Last active March 10, 2020 05:06
Simple Detection of Text File Encoding
# This code is released to the Public Domain.
# Alternatively, you can use one of the following licenses: Unlicense OR CC0-1.0 OR WTFPL OR MIT-0 OR BSD-3-Clause
# IMPORTANT:
# Please do note that this does NOT attempt to perform complex guessing e.g. CP437 or CP850 or GB18030 or JIS or...
# Well, you get the idea.
# This function will simply try to guess the most common *Unicode* encoding, i.e., UTF-8, UTF-16, and UTF-32
# More ... 'exotic' unicode encoding such as UCS-1, UCS-2, UTF-7, etc are NOT detected. (They would likely be
# detected as "utf-8" by this function)
# If you need more 'advanced' detection, use the heavyweight "chardet" library instead.
@pepoluan
pepoluan / ssh_agent_listpubkeys.py
Last active February 26, 2020 04:10
SSH Agent Socket Interaction
import os
import socket
import sys
import struct
import contextlib
# Reference for the data structure / interaction:
# https://tools.ietf.org/html/draft-miller-ssh-agent-00
# Good to read:
@pepoluan
pepoluan / setdns.ps1
Created December 19, 2019 04:57
DNS Switcher Script for PowerShell
# This code is released to the Public Domain.
# Alternatively, you can use one of the following licenses: Unlicense OR CC0-1.0 OR WTFPL OR MIT-0 OR BSD-3-Clause
param(
[Parameter(Mandatory=$True,Position=1)]
[string] $server,
[string] $iface = "Wi-Fi", # EDIT AS NEEDED
[string] $dns_service = "dnscrypt-proxy" # EDIT AS NEEDED
)