Skip to content

Instantly share code, notes, and snippets.

View andreztz's full-sized avatar
🔨
High tech, low life.

André P. Santos andreztz

🔨
High tech, low life.
View GitHub Profile

These are only examples, for a few very common actions. You are expected to write your own rules for the rest. The syntax is regular JavaScript, but see the polkit(8) manpage for the object structure and available API. These examples are for polkit versions 106 and later, with the JS interpreter. They won't work with Debian's polkit v105.

  • If you don't know the action name, run pkaction:

    pkaction | grep cups
    
  • The possible results are YES, AUTH_SELF(_KEEP), AUTH_ADMIN(_KEEP), NO. Returning a result is final. Returning null will continue checking other rules.

  • Put your rules in /etc/polkit-1/rules.d/*.rules. (You can check everything in one giant addRule, or you can have a separate file and separate addRule for each program; it doesn't matter.)

@andreztz
andreztz / keepassxc_pam.fish
Created April 17, 2025 11:38 — forked from vorstrelok/keepassxc_pam.fish
KeePassXC PAM loing manager integration
#!/usr/bin/fish --private
# !!!Security note!!!
# This will give any process running as your user access to your password while
# key has not expired (2 minutes or revocation by service, whatever comes first)
# Proper solution would probably be writing PAM module and transfering key
# straight to KeePassXC's own keyring
set userid (/usr/bin/id -u "$PAM_USER")
if test "$PAM_TYPE" = 'auth'
@andreztz
andreztz / GitCommitBestPractices.md
Created April 11, 2025 13:35 — forked from luismts/GitCommitBestPractices.md
Git Tips and Git Commit Best Practices

Git Commit Best Practices

Basic Rules

Commit Related Changes

A commit should be a wrapper for related changes. For example, fixing two different bugs should produce two separate commits. Small commits make it easier for other developers to understand the changes and roll them back if something went wrong. With tools like the staging area and the ability to stage only parts of a file, Git makes it easy to create very granular commits.

Commit Often

Committing often keeps your commits small and, again, helps you commit only related changes. Moreover, it allows you to share your code more frequently with others. That way it‘s easier for everyone to integrate changes regularly and avoid having merge conflicts. Having large commits and sharing them infrequently, in contrast, makes it hard to solve conflicts.

Keybase proof

I hereby claim:

  • I am andreztz on github.
  • I am andreztz (https://keybase.io/andreztz) on keybase.
  • I have a public key ASBWWgHVimYGUwgB_RF3MsYX_wy20zBp9zpq64Sa0Qf12wo

To claim this, I am signing this object:

@andreztz
andreztz / expbackoff.sh
Created February 21, 2025 03:49 — forked from nathforge/expbackoff.sh
Exponential backoff in Bash
expbackoff() {
# Exponential backoff: retries a command upon failure, scaling up the delay between retries.
# Example: "expbackoff my_command --with --some --args --maybe"
local MAX_RETRIES=${EXPBACKOFF_MAX_RETRIES:-8} # Max number of retries
local BASE=${EXPBACKOFF_BASE:-1} # Base value for backoff calculation
local MAX=${EXPBACKOFF_MAX:-300} # Max value for backoff calculation
local FAILURES=0
while ! "$@"; do
FAILURES=$(( $FAILURES + 1 ))
if (( $FAILURES > $MAX_RETRIES )); then
@andreztz
andreztz / grammar
Created January 1, 2025 03:26 — forked from zehnpaard/grammar
Python Implementation of Backtracking Recursive Descent Parser based loosely on Language Implementation Patterns
list : '[' elements ']';
elements : element (',' element)*;
element : NAME | assign | list | list_assign;
assign : NAME '=' NAME;
list_assign : list '=' list;
NAME : ('a'..'z' | 'A'..'Z')+;
@andreztz
andreztz / ANSI.md
Created December 5, 2024 15:20 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@andreztz
andreztz / ANSI-escape-sequences.md
Created December 5, 2024 15:19 — forked from ConnerWill/ANSI-escape-sequences.md
ANSI Escape Sequences cheatsheet

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@andreztz
andreztz / create_img
Created November 16, 2024 16:41 — forked from sandeep-datta/create_img
A python script for creating a linux virtual disk with a ready to use rootfs
#!/usr/bin/python3
import sys
import os
import argparse
from os import path
from pprint import pprint
from tempfile import TemporaryDirectory
#include <Servo.h>
Servo myServo;
const int servoPin = 9; // Pino onde o servo motor está conectado
const int angleOpen = 90; // Ângulo para empurrar o cigarro
const int angleClose = 0; // Ângulo para posição de repouso
unsigned long previousMillis = 0; // Armazena o último tempo em que o servo foi ativado
const long interval = 3600000; // Intervalo de 1 hora (em milissegundos)