Refactoring Tips for Python Developers
This page is a recopilation of the following sources:
This page is a recopilation of the following sources:
#!/usr/bin/python3 | |
############################################################################################### | |
# Author: n0nuser - Pablo Jesús González Rubio - https://nonuser.es - gonzrubio.pablo@gmail.com | |
############################################################################################### | |
# | |
# Traverses files in a folder, executing the query in each file to a MS SQL Server | |
# | |
# If it succeeds, the file could be deleted | |
# | |
# If there's any error with a file (execution of query or not able to read file), |
def randomPassword(length): | |
""" | |
pass = randomPassword(16) | |
Ref: https://stackoverflow.com/a/2257449 | |
""" | |
return(''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(length))) | |
def _get_size(bytes: int, suffix="B"): | |
"""Scale bytes to its proper format. | |
e.g: |
from Crypto.Cipher import AES # Use cryptodome!! | |
import base64 | |
BS = 16 | |
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS).encode() | |
unpad = lambda s: s[:-ord(s[len(s)-1:])] | |
def iv(): | |
return chr(0) * 16 |
loadkeys es
awful.keyboard.append_global_keybindings({ | |
-- Volume Control | |
-- https://bbs.archlinux.org/viewtopic.php?pid=958820#p958820 | |
awful.key({ }, "XF86AudioPlay", function () awful.util.spawn("mpc toggle") end), | |
awful.key({ }, "XF86AudioNext", function () awful.util.spawn("mpc next") end), | |
awful.key({ }, "XF86AudioPrev", function () awful.util.spawn("mpc prev") end), | |
awful.key({ }, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer -c 0 set Master 1dB+") end), | |
awful.key({ }, "XF86AudioLowerVolume", function () awful.util.spawn("amixer -c 0 set Master 1dB-") end), | |
awful.key({ }, "XF86AudioMute", function () awful.util.spawn("amixer -c 0 set Master toggle") end), | |
}) |
# Page settings | |
baseURL = "baseurl" | |
languageCode = "en" | |
title = "Hey! I'm using GA4" | |
[markup] | |
[markup.goldmark] | |
[markup.goldmark.renderer] | |
unsafe = true |
import re | |
import socket | |
import struct | |
import platform | |
import subprocess | |
# https://stackoverflow.com/a/166589 | |
def getWANIP(): | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect(("8.8.8.8", 80)) |
alias aliases="source ~/.bash_aliases" | |
# OS | |
alias poweroff="halt -p" | |
# Reboot and forever with No Gui | |
alias rebootNoGui='sudo systemctl set-default multi-user && sudo reboot' | |
# Reboot and forever with Gui |