Skip to content

Instantly share code, notes, and snippets.

View mvidaldp's full-sized avatar
🎯
Focusing

Marc Vidal De Palol mvidaldp

🎯
Focusing
  • Cologne, Germany
View GitHub Profile
@mvidaldp
mvidaldp / rename.sh
Created November 2, 2020 02:51
Rename all extensions of the files from a folder
for f in *.old; do
mv -- "$f" "${f%.old}.new"
done
# source: https://unix.stackexchange.com/a/19656
@mvidaldp
mvidaldp / HowTo_GitHub_Fork_even_with_master.md
Created August 19, 2020 14:43
Set GitHub fork even with the master branch. Aka gitHub says "This branch is X commits ahead, Y commits behind" after pull requests merged.

Assuming your are inside your fork folder and the pull requests you did were accepted and so merged into the master branch of the repo. Run once at first:

git remote add upstream https://github.com/upstream/repo.git

Then whenever you want to make your fork even (sync changes), run:

git pull --rebase upstream master
git push --force-with-lease origin master
@mvidaldp
mvidaldp / ByteArray2Int.java
Last active October 19, 2020 09:23
How to decode signed and unsigned 12 and 24-bit encoded integers from a byte array in Java
// For unsigned integers, all byte array elements are decoded as unsigned using (value & 0xff) before the left shift (<<)
private static int byteArrayToUInt(byte[] input) {
if (input.length == 3) { // 24-bit encoded
// always decode them starting from right to left (2, 1, 0 indices in this example)
return (input[0] & 0xFF) << 16 | (input[1] & 0xFF) << 8 | (input[2] & 0xFF); // lowercase F(f) also works
} else if (input.length == 2) { // 12-bit encoded
return (input[0] & 0xFF) << 8 | (input[1] & 0xFF);
}
}
@mvidaldp
mvidaldp / wordpress_on_nginx.sh
Last active July 1, 2020 12:40
How to correctly set permission to run Wordpress on NGINX
# by default NGINX runs the master process as root and worker processes as user http
sudo chown http:http /var/www/yoursitefolder -R
# set only the necessary permissions (0755 for folders and 0644 for files)
sudo find /var/www/yoursitefolder -type d -exec chmod 0755 {} \; # folders
sudo find /var/www/yoursitefolder -type f -exec chmod 0644 {} \; # files
@mvidaldp
mvidaldp / PERSISTENT_ARCH_USB.md
Created June 7, 2020 22:18
Reminder: persistent Arch USB Linux kernel and Intel ucode upgrades

Extracted from: https://sourceforge.net/projects/arch-linux-usb-os/files/ArchUsbOs/

*** Arch USB OS uses save partition to save changes you make and programs you install When it comes to kernel+initramfs and intel-ucode upgrade this is problematic since these - are used to boot the OS but do so while residing on the USB drive itself, outside the squashed file system. So when kernel or intel-ucode is upgraded in order to be able to reboot you will have to - copy-paste files between "save" and "boot" partition.

Boot into another Linux installation or Linux Boot CD or USB and mount 'ARCH USB OS'- USB drive

@mvidaldp
mvidaldp / .bashrc
Created June 7, 2020 21:32
Gentoo's default BASHRC file (very nice color schemes)
# /etc/bash/bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
@mvidaldp
mvidaldp / .bashrc
Last active June 11, 2020 20:20
Set root PS1 to [Day Month DayNumber HH:MM] root@host /path/ $ on /root/.bashrc
# assuming you have ncurses installed on your system
PS1="\[$(tput setaf 6)\][\d \A]\[$(tput bold)\]\[$(tput setaf 1)\] \u\[$(tput setaf 2)\]@\[$(tput setaf 3)\]\h \[$(tput bold)\]\[$(tput setaf 4)\]\w\[$(tput bold)\]\[$(tput setaf 1)\] \\$\[$(tput sgr0)\] "
@mvidaldp
mvidaldp / .bashrc
Last active June 11, 2020 20:19
Set user PS1 to [Day Month DayNumber HH:MM] user@host ~ $ on ~/.bashrc
# assuming you have ncurses installed on your system
PS1="\[$(tput setaf 6)\][\d \A]\[$(tput bold)\]\[$(tput setaf 2)\] \u\[$(tput setaf 0)\]@\[$(tput setaf 3)\]\h \[$(tput setaf 4)\]\w\[$(tput bold)\]\[$(tput setaf 2)\] \\$\[$(tput sgr0)\] "
@mvidaldp
mvidaldp / lsl_api.cfg
Last active December 3, 2020 22:33
How to enforce LSL LabRecorder to default timestamps: create the file -> ~/lsl_api/lsl_api.cfg (C:/Users/username/lsl_api.cfg on Windows)
[tuning]
ForceDefaultTimestamps = 1
@mvidaldp
mvidaldp / switch_case.py
Created May 25, 2020 10:14
How to emulate switch/case in Python
def switch_case(value):
return {
0: 'case for 0',
1: 'case for 1',
2: 'case for 2',
# ...
}[value]
result = switch_case(value_to_evaluate)