Skip to content

Instantly share code, notes, and snippets.

View pythonhacker's full-sized avatar
New Beginnings

Anand B Pillai pythonhacker

New Beginnings
View GitHub Profile
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 (
pythonhacker /
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)
for c in ${chunks[@]}; do
hex_chunk=$(xxd -l $c -p /dev/urandom)
elems+=( $hex_chunk )
pythonhacker /
Created January 29, 2022 13:26
Toggle Laptop and Monitor Display automatically
# 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 /
Last active September 5, 2023 05:20
Controlling fan speed on Lenovo Thinkpad running antiX (or other Debian derivatives)


This is a write up on how to use thinkfan on Lenovo ThinkPads running antiX Linux. I am writing from my (bad) experience after installing antiX Grup Yorum 21 on a Lenovo ThinkPad P15s with the fan running constantly at max speed.

This is based on the guide provided at however since the thinkfan utility does not seem to be available in the default repos of antiX Linux, it also includes steps to build the utility from source code - plus other tweaks for Thinkpad.

Try installing from repo

 $ sudo apt install thinkfan
pythonhacker /
Last active March 25, 2021 16:24
Toggle X compositor on or off in shell (linux)
function toggle_xcomp() {
# toggle X compositor
ret=`xfconf-query -c xfwm4 -p /general/use_compositing`
case "$ret" in
"false") echo "turning compositor on";xfconf-query -c xfwm4 -p /general/use_compositing -t bool -s true;;
*) echo "turning compositor off";xfconf-query -c xfwm4 -p /general/use_compositing -t bool -s false;;
pythonhacker /
Last active June 25, 2020 06:19
@fermatslibrary - Anagram finder implemented using Prime Numbers in Rust
// Courtesy: @Fermatslibrary
// Reference:
// Copyright: Anand B Pillai @skeptichacker
use std::env;
use std::collections::HashMap;
pub fn is_prime(n: u64) -> bool {
A simple get function which caches responses for a URL
using a LFU cache
import requests
from collections import Counter
class LFUCache(object):
""" Least frequently used cache with caching done on SET """
pythonhacker / docli.log
Last active November 6, 2019 07:29
Error when running docli
$ docli droplet --snapshot 163461766
│ Fields │ Values │
│ SnapShot Id │ 53919120 │
│ SnapShot Name │ pfaas-sg-ps-1-1571760580915 │
│ Distribution │ Debian │
pythonhacker / scrapy_settings.txt
Created February 13, 2019 10:40
Find Scrapy HTTP cache directory
$ scrapy shell -s HTTPCACHE_ENABLED=True
2017-02-28 10:41:41 [scrapy.utils.log] INFO: Scrapy 1.3.2 started (bot: httpbin)
>>> from scrapy.utils.misc import load_object
>>> storage = load_object(settings['HTTPCACHE_STORAGE'])(settings)
>>> storage.cachedir
pythonhacker /
Created January 16, 2018 13:28
Test homogeneity of a Python data structure using a one liner
# For homogenous inputs, no assertion error
def homogeneity(data):
assert(len(dict(map(lambda x: (type(x), 1), data))) == 1)