Skip to content

Instantly share code, notes, and snippets.

@CodeArtha
CodeArtha / print_progressbar.py
Created February 9, 2024 11:10
python print progressbar
# This function prints a progress bar in the terminal without deleting previous terminal output and without creating a newline
# each time the progress bar is updated. This version works with a fixed width of the progress bar. There is another version
# in [this gist](https://gist.github.com/greenstick/b23e475d2bfdc3a82e34eaa1f6781ee4) that will adapt to the width of the terminal
# though this comes with a large performance penalty. Its ok for one-offs, by the author recommends to use a proper progress
# bar library instead for a more robust solution. [This other gist](https://gist.github.com/shakeyourbunny/303b000168edc2705262ce40381034a3)
# makes the resizeable progress bar work on windows. The comments on both those gist are worth a read.
def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '▒', printEnd = "\r"):
"""
Call in a loop to create terminal progress bar
@CodeArtha
CodeArtha / delete-largest-duplicate.sh
Created October 21, 2022 08:53
Bash script to keep the lightest version of duplicate audio or video files that have been compressed and share a common filename beginning.
#!/usr/bin/env bash
# This script looks for near duplicates in the current directory and keeps only the one with the smallest filesize.
# By that I mean that a file and its duplicate have the same name beginning up to a certain character position
# (i.e: a title) with an additionnal variable part at the end (i.e: a timestamp).
#
# The duplicates contain the "same" information for a human, but are actually encoded differently. Hence they can't
# be compared using a hash. For instance video files encoded differently, or a raw music file and its compressed mp3
# counterpart.
# The heaviest file is moved to an archive directory to review before deleting
@CodeArtha
CodeArtha / raw2webp.py
Last active October 21, 2021 08:10
Python script to convert raw images (CR2 in this case) to WEBP or other formats if needed. Works on computers where rawkit complains that rawlib is not installed and since I can't install it on my workcomputer I found this workaround. Requires a "input" and "output" folder in the same directory as the script.
from PIL import Image
import rawpy
import imageio
import numpy as np
import os
def main():
paths = os.listdir("input")
for path in paths:
raw = None
@CodeArtha
CodeArtha / nextcloud-git-exclude.sh
Last active June 21, 2021 22:50
Excluding all your git repositories from nextcloud sync to avoid conflicts and merges
#!/bin/bash
## This script finds all the git repositories recurcively from the folder the scripts sits in and add them to the nextcloud exclusion list.
## I had issues with nextcloud syncing my git repositories, this either created nextcloud sync conflicts or git merge conflicts. So I always excluded my git repo from being synced by nextcloud.
## This script just automates the process. Best place it at the root of your nexcloud directory and execute it. That way it gets them all.
exlist=~/.config/Nextcloud/sync-exclude.lst
for string in $(find . -name .git -type d -prune );
do
@CodeArtha
CodeArtha / extract.sh
Created June 8, 2021 18:51
bash function for extracting any compressed archive. add this function to your .bashrc file. isn't writen to be used as a standalone script
#
# # ex - archive extractor
# # usage: ex <file>
ex ()
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
@CodeArtha
CodeArtha / ssh-permission.sh
Last active April 17, 2021 21:30
script to automatically set the right permission to the ssh-keys
#!/usr/bin/env bash
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
chmod 644 ~/.ssh/config
chmod 644 ~/.ssh/*.pub
@CodeArtha
CodeArtha / wordlist_cleanup.md
Created April 10, 2020 15:09
Set of bash commands to work with and cleanup wordlists

Clean up wordlists using bash one-liners

The following bash one-liners are useful commands for manipulating wordlists (or any text file). For instance, if you need to remove all blank lines from a file, a one-liner will do the trick. Similarly, if you need to remove duplicate passwords (or text), you can do that too. If you have multiple wordlists, you can also combine them into one large file.

  • Remove duplicates

awk '!(count[$0]++)' old.txt > new.txt

@CodeArtha
CodeArtha / ChangeExtension.sh
Created July 21, 2019 00:30
Bash script to change all files with one extension in a folder to another
#!/bin/bash
from_ext=".txt"
to_ext=".csv"
for file in *$from_ext; do mv "$file" "$(basename "$file" $from_ext)$to_ext"; done
import sys
# Scripts maps a number between b0 - b1 onto the a0 - a1 scale.
# Config is hardcoded for faster data input when using the same range over and over again
a0 = float(0)
a1 = float(500)
b0 = float(61)
b1 = float(538)
try:
@CodeArtha
CodeArtha / matrix_inversion.py
Last active July 10, 2019 18:49
Simple python script written for my master thesis to invert a square matrix and print it in a format that can be pasted in libre office calc without needing further refactoring
from sympy import *
# Sample matrix
m = Matrix([
[0.0000, 0.0928, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,],
[0.0000, 0.0000, 0.0000, 0.2300, 0.5200, 0.1000, 0.1200, 0.1000,],
[1.0000, 0.1700, 0.0000, 1.0000, 1.0000, 0.6000, 0.1032, 0.2700,],
[0.0000, 0.0000, 0.0000, 0.2300, 0.0000, 1.0000, 0.0000, 0.1200,],
[0.0000, 0.0000, 0.0000, 0.2700, 0.0000, 0.0000, 0.0000, 0.0000,],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0700, 0.7000, 0.0300,],