Skip to content

Instantly share code, notes, and snippets.

View pythonhacker's full-sized avatar
💭
Full Reset

Anand B Pillai pythonhacker

💭
Full Reset
View GitHub Profile
@pythonhacker
pythonhacker / toggle_displays.sh
Created January 29, 2022 13:26
Toggle Laptop and Monitor Display automatically
#!/bin/bash
# Use this script if you have an external monitor (HDMI) and want that as primary display
# but switch to the laptop monitor (eDP) when the external monitor is off (power off or otherwise)
# Guess if you have the external monitor attached to a UPS device, you don't need this script...!
# Detect when monitor is powered off and switch the laptop display back on
# and vice-versa, keeping the external monitor as primary display whenever
# possible.
function get_laptop_display() {
@pythonhacker
pythonhacker / uuid-gen.sh
Last active February 15, 2022 15:22
A pure bash function for creating UUIDs with no dependencies
function uuidgen() {
chunks=(4 2 2 2 6)
elems=()
for c in ${chunks[@]}; do
hex_chunk=$(xxd -l $c -p /dev/urandom)
elems+=( $hex_chunk )
done
@pythonhacker
pythonhacker / test_password_has_argon2i.go
Last active October 6, 2023 14:30
Testing password hashing using Argon2id cryptographic password hashing algorithm
// Storing cryptographic password hashes in database or memory
// and comparing with password.
package main
import (
"log"
"errors"
"strings"
"crypto/subtle"
"encoding/base64"
@pythonhacker
pythonhacker / k3s+letsencrypt+ingress.md
Last active November 1, 2024 12:55
Ingress Setup for K3S with TLS (letsencrypt)

Comprehensive Guide: Adding SSL Certification to Your k3s Cluster

Hello there! Today, we're diving deep into the process of adding SSL certification to services deployed on a k3s cluster. By the end of this guide, you'll be able to securely serve your services over HTTPS, enhancing the security of your applications.

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Installing cert-manager
  4. Creating an Issuer or ClusterIssuer
Strength Level Entropy (bits) Description / Example
🟥 Very Weak < 28 Simple words or predictable patterns — e.g. password123, qwerty
🟧 Weak 28–35 Slightly varied words or short phrases — e.g. MyDog2025
🟨 Moderate 36–59 Adequate for low-value logins or throwaway accounts
🟩 Strong 60–79 Meets modern security standards (NIST/OWASP)
🟦 Very Strong 80–99 Excellent protection for most use-cases
🟪 Excellent 100+ Practically unbreakable by brute-force today
@pythonhacker
pythonhacker / binary_search.py
Created January 6, 2026 12:17
Binary search using bisect module
import bisect
def binary_search(a, x, lo=0, hi=None):
""" Search for item x in a using bisect binary search """
if hi is None:
hi = len(a)
pos = bisect.bisect_left(a, x, lo, hi)
if pos != hi and a[pos] == x:
return pos
@pythonhacker
pythonhacker / binary_search_demo.py
Created January 6, 2026 12:24
Demo of binary search using bisect
>>> l = [10, 15, 18, 20, 21, 21, 21, 24, 24]
>>> binary_search(l, 18)
2
>>> binary_search(l, 21)
4
>>> binary_search(l, 24)
7
>>> binary_search(l, 100)
-1
@pythonhacker
pythonhacker / insort_demo.py
Last active January 6, 2026 12:38
Bisect insort functions demo
>>> bisect.insort_left(l, 12)
>>> l
[10, 12, 15, 18, 20, 21, 21, 21, 24, 24]
>>> bisect.insort_right(l, 20)
>>> l
[10, 12, 15, 18, 20, 20, 21, 21, 21, 24, 24]
>>> bisect.insort_left(l, 17)
>>> l
[10, 12, 15, 17, 18, 20, 20, 21, 21, 21, 24, 24]
@pythonhacker
pythonhacker / list_search.py
Created January 6, 2026 12:39
Generic sorted list search and locate using bisect
def search(a, x):
""" Locate the index of the leftmost value exactly equal to x """
i = bisect.bisect_left(a, x)
if i != len(a) and a[i] == x:
return i
return -1
def search_right(a, x):
""" Locate the index of the right most value exactly equal to x """
@pythonhacker
pythonhacker / list_search_demo.py
Last active January 6, 2026 12:43
Generic list search demo using bisect
>>> l=[10, 12, 15, 17, 18, 20, 20, 21, 21, 21, 24, 24]
>>> search(l, 18)
4
>>> search(l, 20)
5
>>> search(l, 21)
7
>>> search_right(l, 21)
10
>>> search_right(l, 24)