Skip to content

Instantly share code, notes, and snippets.

View ctsiaousis's full-sized avatar
🤹

Chris Tsiaousis ctsiaousis

🤹
  • Greece
  • 14:16 (UTC +03:00)
View GitHub Profile
@ctsiaousis
ctsiaousis / commander.hpp
Created June 3, 2024 19:05
Save different types of function pointers to an std::unordered_map
void foo() {}
void bar(int val) {}
char foobar(const std::string &str) {return str[0];}
class Commander {
public:
template <typename Func, typename... Args>
void operator()(Func func, Args... args) {
std::invoke(func, args...);
}
@ctsiaousis
ctsiaousis / nmToRGB.cpp
Created August 2, 2022 10:24
Convert Light Wavelengths to RGB values
void nmToRGB(int wavelength, double *r, double *g, double *b){
double Gamma = 0.80;
double IntensityMax = 255;
double factor, red, green, blue;
if((wavelength >= 380) && (wavelength<440)){
red = -(wavelength - 440) / (440 - 380);
green = 0.0;
blue = 1.0;
}else if((wavelength >= 440) && (wavelength<490)){
@ctsiaousis
ctsiaousis / collection.md
Created June 3, 2021 21:04
Multi-Repository managment

A usefull collection of scripts for managing multi-repository syncing

At first, git submodules can be intimidating. Those scripts are a nice workaround for managing projects that consist of multiple submodules.

clone_all.sh

#!/bin/sh
declare -a totalModules=(
	"http://example.url/example/module1.git"
	"http://example.url/example/module2.git"
	)
@ctsiaousis
ctsiaousis / audioNotify.sh
Created June 3, 2021 20:50
A simple script for changing audio level using pulsemixer and notifying the user with custom icons using notify-send
#!/bin/sh
pulsemixer --change-volume ${1} || exit
vol=$(pulsemixer --get-volume | cut -d " " -f1)
[[ $vol -eq "0" ]] && notify-send -i $HOME/.local/share/myIcons/audioNotify/sound_0.png " " -t 2000 ;
[[ $vol -gt "0" && $vol -lt "21" ]] && notify-send -i $HOME/.local/share/myIcons/audioNotify/sound_1.png " " -t 2000 ;
[[ $vol -gt "20" && $vol -lt "36" ]] && notify-send -i $HOME/.local/share/myIcons/audioNotify/sound_2.png " " -t 2000 ;
[[ $vol -gt "35" && $vol -lt "51" ]] && notify-send -i $HOME/.local/share/myIcons/audioNotify/sound_3.png " " -t 2000 ;
@ctsiaousis
ctsiaousis / bluetoothMenu.sh
Created June 3, 2021 20:44
A UI for selecting and connecting to known bluetooth devices. Uses dmenu.
#!/bin/sh
MAC_ADDRESS="00:42:79:9D:01:7C"
customSpeaker() { #Automated sony speaker connection
echo -e "scan on\nconnect ${MAC_ADDRESS}\n" | bluetoothctl && sleep 7 &&
bluetoothctl info ${MAC_ADDRESS} | grep 'Paired: yes' &&
notify-send "MyBluetoothScript" "<i>connected to speaker</i>" &&
exit
}

Never Again forget how to set-up a python virtual environment and use it with jupyter-notebook

  • python3 -m venv tensorflow Create the venv.
  • source ./tensorflow/bin/activate Activate it. All packages from now on are now local.
    • If you want to go out of environment type deactivate.
  • pip install ipykernel Install the ipykernel module to have a kernel available for this venv.
  • python -m ipykernel install --user --name=tensorflow Install the kernel globally (--user) so that jupyter can detect it.
  • pip install tensorflow Enjoy installing big packages without messing up your system. =)
@ctsiaousis
ctsiaousis / backup.sh
Last active May 22, 2021 13:02
A simple script for automated `rsync` backups to encrypted devices. Called like `./backup.sh /dev/sde1 /myMountPoint/ myUserName`
#!/bin/sh
[[ $# -ne 3 ]] && echo "Please specify device, mount-point and username. Exiting..." && exit
[[ $EUID -ne 0 ]] && echo "Please run as root. Exiting..." && exit
[[ ! -d $2 ]] && echo "Argument 2 must be a directory. Exiting..." && exit
[[ `id $3 &>/dev/null || echo -1` -ne 0 ]] && echo "Not a valid user. Will not push cache to backup. Exiting..."
DIR=${2%/} #remove trailing dash
cryptsetup open $1 backup || { echo "Could not open \"backup\". Exiting..." ; exit; } #backup is the name of cryptsetup