Skip to content

Instantly share code, notes, and snippets.

@jeanlescure
Last active March 12, 2021 22:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeanlescure/a7ef2c3166effdf575d9c0c04267ed7a to your computer and use it in GitHub Desktop.
Save jeanlescure/a7ef2c3166effdf575d9c0c04267ed7a to your computer and use it in GitHub Desktop.

Arch Linux clear DNS cache

nscd -K; nscd

Chrome Kiosk for OBS

google-chrome-stable --app=https://obs.ninja/?view=Abcd123 --user-data-dir=/tmp --kiosk

Minification one-liners

# Minify JS
npx terser -o app.min.js app.js common.js

# Minify CSS
npx clean-css-cli -o style.min.css css/bootstrap.css style.css

# Minify HTML
npx html-minifier index-2.html -o index.html --remove-comments --collapse-whitespace

# XML
npx pretty-data-cli --type xml --minify input.xml > input.min.xml

Dettach from frozen ssh session

Press Enter, then ~, then .. (In some languages, you may need to press Shift or Alt to enter the ~ character.)

Copy current directory elsewhere skipping node_modules

mkdir -p /destination/$(pwd | awk -F'/' '{print $NF}')
cp -r !(node_modules) /destination/$(pwd | awk -F'/' '{print $NF}')

Delete all node_modules folders recursively

find . -name "node_modules" -type d -prune -exec rm -rf '{}' +

The -prune option skips child node_modules directories so that only top level node_modules are removed, for better performance.

Tar commands

# best time/compression ratio in parallel
tar --use-compress-program="pigz -4 " -cf my.tar.gz ./file1 ./file2 ./directory

# best performance parallel decompression
tar --use-compress-program=pigz -xf my.tar.gz

# compress current directory properly
tar --exclude=mydir.tar.gz --use-compress-program="pigz -4 " -cf mydir.tar.gz * .??*

Count files in a folder (recursive)

find . -type f | wc -l

Share MacOS X directory over NFS

Add a line akin to the following in /etc/exports:

/Users/myuser/Documents/MySharedDir -maproot=myuser:mygroup -alldirs localhost 192.168.0.104

The previous example shares directory MySharedDir and all sub-directories with clients localhost and 192.168.0.104.

The -maproot=myuser:mygroup maps the root user in the client to be the myuser:mygroup user:group combo when creating/saving files. The -maproot option could be switched out for -mapall which as its name implies would map all connected users to the local user:group specified, but that's not very safe.

Once saved, run the following to restart NFS server daemon:

sudo nfsd restart

And verify your shares:

showmount -e

Bind mouse buttons to keys in linux (X11)

Test if xev installed

xev

Should open a little key and mouse capture window and output the captured events on terminal.

If xev not found install x11-utils:

sudo apt-get install x11-utils

With xev running take note of mouse button numbers and key names you want to map.

Install xbindkeys and xautomation:

sudo apt-get install xbindkeys xautomation

Create the xbindkeys config file using:

xbindkeys --defaults > ~/.xbindkeysrc

Next we need to add the key/button bindings to the config file ~/.xbindkeysrc:

## Map mouse button 6 to "move workspace right" key combination
"xte 'keydown Alt_L' 'keydown Control_L' 'keydown Right' 'keyup Right' 'keyup Control_L' 'keyup Alt_L'"
b:6

## Map mouse button 2 to "move workspace left" key combination
"xte 'keydown Alt_L' 'keydown Control_L' 'keydown Left' 'keyup Left' 'keyup Control_L' 'keyup Alt_L'"
b:2

Finally apply changes:

xbindkeys -p

Reverse mouse scroll in linux (X11)

Edit ~/.Xmodmap file and make the pointer mapping the following:

pointer = 1 2 3 5 4 6 7 8 9 10 11 12

NOTE: The 4 and 5 are out of sequence, basically telling xmodmap to reverse vertical scrolling "buttons". To reverse horizontal scrolling 6 and 7 should be switched as well.

Reload xmodmap:

xmodmap ~/.Xmodmap

Adding fonts in linux

Copy fonts (within their own aptly named folders) to this path:

/usr/share/fonts

The following clears the font cache:

fc-cache -fv

Completely remove MariaDB

apt-get --purge remove -y mariadb-server
apt-get --purge remove -y "mysql*"
rm -rf /etc/mysql/ 

Manjaro regain .ssh permission

chmod -R u+rwX,go-rwx ~/.ssh

Manjaro mount Mac OSX shared folder

On MacOS machine make sure shared folder has windows sharing turned on and on Finder view folder info and check share.

Then on Manjaro install:

pamac install thunar-shares-plugin-gtk3

and run:

sudo mount -t smb3 //mac.local/shared-folder /mnt/shared-folder -o user=...,pass=...,nounix,uid=...,gid=...,file_mode=0777,dir_mode=0777

Manjaro switch Keyboard Alt/Ctrl/Super keys

In XFCE

# /etc/X11/xorg.conf.d/00-keyboard.conf

# Read and parsed by systemd-localed. It's probably wise not to edit this file
# manually too freely.
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us"
        Option "XkbModel" "pc105"
	Option "XkbVariant" "mac"
	Option "XkbOptions" "altwin:ctrl_alt_win,compose:ralt"
EndSection

In KDE

KDE Plasma (kcm_keyboard to be specific) adds it's own mapping on top of X11 / Xorg, so this is a two step process.

First create ~/.Xmodmap file with contents:

keycode 64 = Control_L
keycode 133 = Alt_L

remove mod1 = Meta_L

Then go to System Settings -> Input Devices -> Keyboard -> Advanced, make sure Configure Keyboard Options is checked and within the list make sure that Ctrl is mapped to Alt; Alt is mapped to Win option is also checked.

Logout and then log back-in.

Docker full reset in Linux

Containers

docker ps -a
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Volumes

docker volume ls
docker volume prune

Images

docker images -a
docker rmi $(docker images -a -q)

System

docker system prune -a

Run MongoDB locally using docker

# Create credentials
export MONGO_USER=mongoadmin
export MONGO_PASS=$(openssl rand -base64 32)

# Start
docker run -d --name quick-mongo \
    -e MONGO_INITDB_ROOT_USERNAME=$MONGO_USER \
    -e MONGO_INITDB_ROOT_PASSWORD=$MONGO_PASS \
    -p 27017:27017 \
    mongo
printf "\nUser: $MONGO_USER\nPassword: $MONGO_PASS\n\n"

# Stop
docker kill quick-mongo && docker rm quick-mongo

SSH Agent always running

if pgrep -x "ssh-agent" > /dev/null
then
    echo "Agent is running..."
else
    eval `ssh-agent`
fi

AWS CLI create custom IOT authorizer

aws iot create-authorizer \
--authorizer-name <LAMBDA-NAME> \
--authorizer-function-arn <LAMBDA-ARN> \
--status ACTIVE \
--signing-disabled

aws lambda add-permission --function-name <LAMBDA-NAME> --principal iot.amazonaws.com --source-arn <AUTHORIZER-ARN> --statement-id <RANDOM-UID> --action "lambda:InvokeFunction"

aws iot test-invoke-authorizer --authorizer-name <LAMBDA-NAME>  \
--mqtt-context '{"username": "the_user_name", "clientId":"unique_device_id"}' \
--http-context '{"headers": {"token": "the_token"}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment