Skip to content

Instantly share code, notes, and snippets.

@smac89
smac89 / egcd.py
Last active Feb 18, 2021
Extended Euclidean Algorithm in Python (Without recurrsion)
View egcd.py
#!/usr/bin/python3
import math
# Taken in part from: https://www.geeksforgeeks.org/python-program-for-basic-and-extended-euclidean-algorithms-2/
def gcdExtended(a, b):
"""
Calculates the GCD of the two given numbers, as well as the coefficients x and y
such that ax + by = gcd(a,b). This is useful in cryptography
See: https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
@smac89
smac89 / post.md
Last active Oct 3, 2020
Xfce Lockscreen with xsecurelock and xscreensaver #linux #xfce
View post.md
  • Install both xscreensaver and xsecurelock using your package manager

  • Make sure xscreensaver is not set to lock the screen or to manage the display. Xfce aleady does all those, so there is no need to enable it again.

  • Also make sure that the xscreensaver daemon is not autostarted. Not doing this may result in the screen not being locked.

  • Set the following environmental variables (in ~/.xprofile or ~/.xsession) for xsecurelock:

    # xsecurelock options
    export XSECURELOCK_SAVER=saver_xscreensaver
    
@smac89
smac89 / 1. Firefox Tips.md
Last active Sep 8, 2020
Tips for using firefox on Linux #firefox #linux #desktop #tuning
View 1. Firefox Tips.md
@smac89
smac89 / post.md
Created Sep 1, 2020
XFCE Exo remove unused applications #exo #xfce #desktop
View post.md

Clearing old applications from xfce exo

In order to find out where exo reads desktop applications from, I had to run the application from my terminal using the command:

strace exo-preferred-applications 2>&1 | grep 'openat.*\.desktop'

This allowed me to identify two folders where exo reads preferred applications from:

@smac89
smac89 / jwt.mjs
Last active Aug 5, 2020
Learning how JWT works
View jwt.mjs
import crypto from 'crypto';
import assert from 'assert';
const header = {"alg":"HS256","typ":"JWT"};
const payload = {"loggedInAs":"admin","iat":1422779638};
const unsignedToken = Buffer.from(JSON.stringify(header)).toString('base64') +
'.' + Buffer.from(JSON.stringify(payload)).toString('base64');
const hmac = crypto.createHmac('sha256', 'secretkey');
@smac89
smac89 / zsh-lazy.md
Last active Aug 3, 2020
ZSH lazy loading #zsh #lazy
View zsh-lazy.md

The following is a function I use in my .zshrc file to achieve some form of lazy evaluation.

local function lazy_load() {
    local -xr thunk="$(cat)"
    # (u) removes duplicates
    local -xr triggers=(${(u)@})
    
    # Only if length of triggers is greater than zero
    # otherwise the function will immediately execute.
@smac89
smac89 / Unbound timer.md
Last active May 30, 2020
Create systemd timer from simple command
View Unbound timer.md

To create the timer described here

systemd-run --on-calendar='*-*-01 12:00:00' --unit='unbound-root-hints' \
--remain-after-exit --description='Update root hints for unbound' --property='Type=exec' \
--property='After=network.target' --timer-property='Persistent=true' \
--timer-property='RandomizedDelaySec=2s' --timer-property='AccuracySec=1us' \
/usr/bin/curl -o /etc/unbound/root.hints https://www.internic.net/domain/named.cache
@smac89
smac89 / Restoring Sanity.md
Last active Feb 11, 2021
Linux Desktop User: Sane defaults
View Restoring Sanity.md

Being a Linux desktop user is not easy, but it doesn't have to be difficult.

Enabling persistent journals

This is especially useful for collecting logs of system issues.
@smac89
smac89 / StructuralSearch.md
Last active May 10, 2020
Structural search tips. #IntelliJ #idea
View StructuralSearch.md

Find field references on an instance

In this example, we want to find places where one did:

someClass.someField

Where someClass is of the type fully.qualified.SomeClass

Find and replace field reference with method call