Mosh Cheat Sheet



§SSH / Mosh

More SSH awesomeness on https://github.com/moul/awesome-ssh

§SSH or mosh into a host and attach or create a named tmux session

and with mosh

replaces SERVER with your SSH target hostname.

Java tutorial for beginners - Learn Java, the language behind millions of apps and websites. 🔥 Want to master Java? Get my complete Java mastery bundle: htt. Mosh @moshhamedani course Java Programming #java is one of the kind, I enroll many Online Training's in Java and it takes a while for me to learn most of the important stuffs. If your a Java Programmer before and want to refresh things from the very basic this course if for you. I do have one request though.please make a cheat sheet.

§Unsafe SSH or Mosh connection (temporary servers: CI)

with Mosh:

§Non-interactive SSH with password

§Networking

§Measure network performances and stability with iperf

Install:

  • Install on mac with brew install iperf
  • Install on Linux with sudo apt install iperf

TCP test:

  • Run on the server: iperf -s -p 6666
  • Run on the client: iperf -c ${SERVER} -p 6666

UDP test:

  • Run on the server: iperf -s -p 6666 -u
  • Run on the client: iperf -c ${SERVER} -p 6666 -u -b 900m

§traceroute & ping with mytraceroute (mtr)

  • Install on Linux: sudo apt install mtr
  • Usage: mtr ${IP}

Example:

§Find big files & Cleanup space

§Get aggregated sizes of sub-dirs and files

§Find big files

§Cleanup docker

§Git / GitHub

§Git / GitHub essential tools

  • Install “hub” (https://hub.github.com/)
  • Install “refined GitHub” browser extension (https://github.com/sindresorhus/refined-github)

§Do rebase instead of merge when pulling

git config --global pull.rebase true

Mosh Cheat Sheet

§GitHub links

Mosh Cheat Sheet

Update the following variables when appropriate:

  • USER a GitHub user or organization, i.e.: moul

  • Pull-Requests

    • In any repo of an user/organization: https://github.com/pulls?utf8=%E2%9C%93&q=is%3Aopen+is%3Apr+archived%3Afalse+user%3AUSER
    • Opened by an user: https://github.com/pulls?utf8=%E2%9C%93&q=is%3Aopen+is%3Apr+archived%3Afalse+author%3AUSER
    • Assignee to an user: https://github.com/pulls?utf8=%E2%9C%93&q=is%3Aopen+is%3Apr+archived%3Afalse+assignee%3AUSER
    • Mentioning an user/a team: https://github.com/pulls?utf8=%E2%9C%93&q=is%3Aopen+is%3Apr+archived%3Afalse+mentions%3AUSER
    • Requesting review from an user/a team: https://github.com/pulls?utf8=%E2%9C%93&q=is%3Aopen+is%3Apr+archived%3Afalse+review-requested%3AUSER

§Close a pull request from command line with “hub”

  1. Install “hub”
  2. Type hub api -X PATCH /repos/$USER/$REPO/pulls/$ID -F state=closed

§List projects in JSON

  • Fetch: hub api --paginate user/repos | jq . > github.json
  • Only “moul’s” projects: cat github.json | jq '.[] | select(.owner.login 'moul') > moul.json
  • Remove some fields to have a smaller .json file: cat moul.json | jq 'with_entries(select(.key|test('_url')|not)) | del(.owner) | del(.permissions) | del(.url) | del(.node_id)'

Or inline

§Bonus: find and close a pull-request named “Enabled GuardRails” in the current repository

Cheat Sheet Terraria

§Manipulate JSON

§Flatten concatenated JSON files

Sometimes, when you run a command like this: hub api --paginate user/repos, you get multiple JSON outputs in the same file.

jq doesn’t care and you can run any jq command over the aggregated file, however, this .json file won’t be supported by most of the other softwares.

You can “repair” by flattening a concatenated JSON file by doing the following:

cat aggregate.json | sed 's/^]$$/],/;$$s/],/]]/;1s/^/[/' | jq '. | add'

The sed ... command will transfer the standalones arrays into a a valid array of arrays.

The jq . | add will flatten the array of arrays into a big 1 dimension array.

§Apply change on multiple files

§Replace a string by another in a whole Git repository

I’m using my https://github.com/moul/golang-repo-template project as repo template on GitHub.

The first task I need to do immediately after creating the new repo, is to replace every instance of golang-repo-template in the codebase by lorem-ipsum (the project name).

§Terminator on Windows

  • Install VcXsrv.exe on Windows and configure it to start automatically with the system
  • Create a startTerminator.sh file with the following content: cd; export DISPLAY=:0; nohup terminator &; sleep 1 and change the permissions chmod +x startTerminator.sh
  • Create a shortcut C:WindowsSystem32bash.exe {12345678-1234-5678-0123-456789abcdef} /home/moul/startTerminator.sh

Cheat Sheet Recipes

§Web

§Temporary static web server

And then open your browser on http://localhost:8000

§Generate directory listing

§Proxy to avoid caching

§Socat

§Connect to a TTY over TCP

§TCP to UDP proxy

Mosh

This TCP proxy can be forwarded over SSH to have access to an UDP port from localhost from a remote host

§Media manipulation

§Loop a video with ffmpeg

  1. calculate the amount of loops needed using https://dan.hersam.com/tools/time-calc.html
  2. for i in {1..383}; do printf 'file '%s'n' 'loop1.mp4' >> list.txt; done
  3. ffmpeg -f concat -i list.txt -c copy output.mp4

See this status

§Download YouTube video cover image

  • the image of one video: youtube-dl --write-thumbnail --skip-download https://www.youtube.com/watch?v=xxxxxxxx
  • the image of multiple videos: youtube-dl --write-thumbnail --skip-download -a urls.txt with one URL per line in urls.txt