gpg / ssh

gpg

http://deferred.io/2017/08/03/yubikey4-gpg-ssh-u2f.html#how-i-use-my-yubikey-gnupg

https://gist.github.com/ankurk91/c4f0e23d76ef868b139f3c28bde057fc https://cfig.github.io/2017/12/08/GPG-with-Yubikey-4/o https://github.com/kvs/dotfiles/blob/master/fish/gnupg.fish https://ssd.eff.org/en/module/how-use-pgp-mac-os-x https://help.github.com/en/articles/associating-an-email-with-your-gpg-key

gpg --list-secret-keys --keyid-format LONG gpg --import

git

https://github.com/rycus86/githooks https://pythonhosted.org/jig/ https://github.com/bmwant/podmena https://github.com/mroth/lolcommits https://github.com/brigade/overcommit https://github.com/pre-commit/pre-commit-hooks

tmux

  • https://tmuxcheatsheet.com/
  • https://blog.bugsnag.com/tmux-and-vim/
  • https://theworkaround.com/2016/08/29/setting-up-tmux-with-rails.html
  • https://littlelines.com/blog/2014/09/02/seamlessly-navigate-rails-projects-with-tmux
  • https://gist.github.com/gblmarquez/926c22db9e1702b1ad73

fish tmux new -s named-session tmux -a named-session

Ctrl + b I to install/restart Ctrl + b y to yank Ctrl + b o to switch panes Ctrl + b % for a vertical pane Ctrl + b " for a horizontal pane

vim bindings work for navigation. | and w for splits

  • https://gist.github.com/MohamedAlaa/2961058
  • https://github.com/tmux-plugins/tmux-pain-control
  • https://github.com/tmux-plugins/tmux-sessionist
  • https://github.com/tmux-plugins/tmux-logging
  • https://github.com/tmux-plugins/tmux-copycat

ranger

https://ranger.github.io/

vim

  • http://vimdoc.sourceforge.net/htmldoc/starting.html#:mksession
  • :sp and :vsp for splits
  • Ctrl+w for focus shifting, max/min with _ and =

  • ':set spell' activates vim spellchecker. Use ']s' and '[s' to move between mistakes, 'zg' adds to the dictionary, 'z=' suggests correctly spelled words

  • check my .vimrc http://tiny.cc/qxzktw and here http://tiny.cc/kzzktw for more

fish

```fish chsh -s /usr/local/bin/fish

edit /etc/shells I think

chsh -s /bin/bash

curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish ```

Once nice thing about Fish is a web-based configuration. Run fish_config to start the web client.

get your fonts

Consider further...

  • https://github.com/danhper/fish-ssh-agent
  • https://github.com/jethrokuan/z

``` set --universal fish_user_paths $fish_user_path ~/bin/

Define alias in shell

alias rmi "rm -i"

Define alias in config file

alias rmi="rm -i"

This is equivalent to entering the following function:

function rmi rm -i $argv end

Then, to save it across terminal sessions:

funcsave rmi ```

brew

```

install brews

brew install bundle brew install $(< Brewfile )

Brewfile

brew cask install font-source-code-pro-for-powerline brew cask install iterm2

wget https://github.com/mbadolato/iTerm2-Color-Schemes/tarball/master

echo /usr/local/bin/fish >> /etc/shells chsh -s /usr/local/bin/fish

curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish ```

dotfiles/dfm/homesick

  • https://github.com/justone/dotfiles/wiki/Full-Documentation
  • https://github.com/andsens/homeshick
  • https://github.com/technicalpickles/homesick

also consider dnsmasq

atom

```

sync

apm list --installed --bare > ~/.atom/package.list

restore

apm install --packages-file ~/.atom/package.list

```

notes

To encrypt/decrypt... Cmd+Shift+P, bombe

fish ag -A sentry ~/notes/projects/*.md --no-numbers https://github.com/JunoLab/atom-bombe/blob/master/lib/encryption.coffee#L1

tools

  • 'htop' instead of 'top'
  • ps aux | egrep '[t]erminal
  • Pipe any command over 'column -t' to nicely align the columns
  • 'file' gives information about a file, as image dimensions or text encoding
  • watch
  • 'echo start_backup.sh | at midnight' starts a command at the specified time
  • 'ranger' is a nice console file manager for vi fans https://ranger.github.io/
  • linux: Use 'apt-file' to see which package provides that file you're missing
  • if you liked the 'psgrep' alias, check 'pgrep' as it is far more powerful
  • learn to use 'pushd' to save time navigating folders (j.py is better though) https://unix.stackexchange.com/questions/77077/how-do-i-use-pushd-and-popd-commands#77081
  • 'dict' is a commandline dictionary
  • Learn to use 'find' and 'locate' to look for files
  • Compile your own version of 'screen' from the git sources. Most versions have a slow scrolling on a vertical split or even no vertical split at all
  • 'trash-cli' sends files to the trash instead of deleting them forever. Be very careful with 'rm' or maybe make a wrapper to avoid deleting '' by accident (e.g. you want to type 'rm tmp' but type 'rm tmp *')
  • 'sort | uniq' to check for duplicate lines
  • Google 'magic sysrq' and learn how to bring you machine back from the dead
  • 'diff --side-by-side fileA.txt fileB.txt | pager' to see a nice diff
  • 'j.py' http://tiny.cc/62qjow remembers your most used folders and is an incredible substitute to browse directories by name instead of 'cd'
  • 'dropbox_uploader.sh' http://tiny.cc/o2qjow is a fantastic solution to upload by commandline via Dropbox's API if you can't use the official client
  • never run 'chmod o+x * -R', capitalize the X to avoid executable files. If you want only executable folders: 'find . -type d -exec chmod g+x {} \;'
  • 'xargs' gets its input from a pipe and runs some command for each argument
  • run jobs in parallel easily: ls *.png | parallel -j4 convert {} {.}.jpg

ETC

docker

DJANGO_DOCKER_ID=$( docker service ls | grep sportshi_dev_django | awk '{print $1}' ) echo $DJANGO_DOCKER_ID docker exec -i $DJANGO_DOCKER_ID bash

git commit --amend --reset-author --no-edit

youtube-dl

``` youtube-dl youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s"

youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" https://www.youtube.com/playlist?list=PLeuCAdRSnObyIgsHQowMS0Of-tQmHbdFa youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" ```

rsync -avPz -e "ssh -p 8000" [email protected]:/media/munich/torrents/Jap* ./

gifsicle

gifsicle --delay=10 --loop *.gif > anim.gif convert -delay 10 -loop 0 *.png animation.gif

  • http://unix.stackexchange.com/questions/3307/montage-together-five-gifs
  • http://www.imagemagick.org/Usage/layers/
  • http://www.imagemagick.org/script/command-line-processing.php

convert *.gif -gravity south -splice 0x111 -shave 0x111 -resize 400x400 -set delay 300 output.gif convert *.png -gravity south -splice 0x111 -shave 0x111 -resize 400x400 converted.png montage *.gif -mode concatenate -tile 1x2 -resize 400x400 output.gif

convert -size 320x90 canvas:none -stroke snow4 -size 1x90 -tile gradient:white-snow4 \ -draw 'roundrectangle 16, 5, 304, 85 20,40' +tile -fill snow \ -draw 'roundrectangle 264, 5, 304, 85 20,40' -tile gradient:chartreuse-green \ -draw 'roundrectangle 16, 5, 180, 85 20,40' -tile gradient:chartreuse1-chartreuse3 \ -draw 'roundrectangle 140, 5, 180, 85 20,40' +tile -fill none \ -draw 'roundrectangle 264, 5, 304, 85 20,40' -strokewidth 2 \ -draw 'roundrectangle 16, 5, 304, 85 20,40' \( +clone -background snow4 \ -shadow 80x3+3+3 \) +swap -background none -layers merge \( +size -font Arial \ -pointsize 90 -strokewidth 1 -fill red label:'50 %' -trim +repage \( +clone \ -background firebrick3 -shadow 80x3+3+3 \) +swap -background none -layers merge \) \ -insert 0 -gravity center -append -background white -gravity center -extent 320x200 \ cylinder_shaded.png

sips

Resizing

sips -Z 640 *.jpg sips -Z 800 *.jpg sips -Z 1600 *.JPG

terminal in osx

  • Copy is Ctrl + U
  • Paste is Ctrl + Y
  • Move by words via option+ left or right

via

ascii

jpg to ascii text

perl s// recursive

perl perl -p -i -e 's/\white\-text//g' `grep -ril white-text *`

pdf

bash convert -adjoin -page A4 *.jpeg multipage.pdf

du

largest 20

bash du -xk | sort -n | tail -20

bash du -h . | grep ^[0-9.][0-9.]G du -h . | grep ^[5-9][0-9][0-9.]M

name and line search and delete

find ./ -name '*.php' -exec sed -i '/three\_by\_three/d' {} \;

move files from subdirectory into current folder

find ./ -type f -exec mv {} ./ \; # Move all files into X find ./ -depth -type d -exec rmdir {} \; # Remove all subdirectories of X

mysql

```mysql SELECT * INTO OUTFILE '/tmp/result.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM users;

prompt mysql (\d)-(\r:\m:\s)>;

CREATE USER 'stampede'@'%' IDENTIFIED BY 'password'; grant all on stampede\_%.* to stampede@%; \G ``` Retrieved from http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt

bash

  • In bash, 'ctrl-r' searches your command history as you type
  • Input from the commandline as if it were a file by replacing 'command < file.in' with 'command <<< "some input text"'
  • '^' is a sed-like operator to replace chars from last command 'ls docs; ^docs^web^' is equal to 'ls web'. The second argument can be empty.
  • '!!:n' selects the nth argument of the last command, and '!$' the last arg 'ls file1 file2 file3; cat !!:1-2' shows all files and cats only 1 and 2
  • More in-line substitutions: http://tiny.cc/ecv0cw http://tiny.cc/8zbltw
  • 'nohup ./long_script &' to leave stuff in background even if you logout
  • 'cd -' change to the previous directory you were working on
  • 'ctrl-x ctrl-e' opens an editor to work with long or complex command lines
  • Use traps for cleaning up bash scripts on exit http://tiny.cc/traps
  • 'shopt -s cdspell' automatically fixes your 'cd folder' spelling mistakes
  • Add 'set editing-mode vi' in your ~/.inputrc to use the vi keybindings for bash and all readline-enabled applications (python, mysql, etc)

.bash-aliases

  • function lt() { ls -ltrsa "$@" | tail; }
  • function psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto; }
  • function fname() { find . -iname "$@"; }

Networking

check ports

lsof -i -n -P | grep trans

  • Some tools to monitor network connections and bandwith:
    • 'lsof -i' monitors network connections in real time
    • 'iftop' shows bandwith usage per connection
    • 'nethogs' shows the bandwith usage per process

cf. ssh bridging

  • 'ssh -R 12345:localhost:22 server.com "sleep 1000; exit"' forwards server.com's port 12345 to your local ssh port, even if you machine is not externally visible on the net. Now you can 'ssh localhost -p 12345' from server.com and you will log into your machine.
  • 'socat TCP4-LISTEN:1234,fork TCP4:192.168.1.1:22' forwards your port 1234 to another machine's port 22. Very useful for quick NAT redirection.
  • Configure postfix to use your personal Gmail account as SMTP: http://tiny.cc/n5k0cw. Now you can send emails from the command line. 'echo "Hello, User!" | mail [email protected]'

blah

  • Don't know where to start? SMB is usually better than NFS for most cases. 'sshfs_mount' is not really stable, any network failure will be troublesome
  • 'python -m SimpleHTTPServer 8080' shares all the files in the current folder over HTTP, port 8080
  • 'sleep' avoids getting kicked out from server.com for inactivity
  • Use this trick on .ssh/config to directly access 'host2' which is on a private network, and must be accessed by ssh-ing into 'host1' first

Host host2 ProxyCommand ssh -T host1 'nc %h %p' HostName host2

time-machine

  • https://discussions.apple.com/thread/3658856?start=45&tstart=0
  • http://www.bluedog.com.au/default/Time_Machine_Buddy.html
  • http://timesoftware.free.fr/timemachineeditor/
  • http://www.saidsvec.com/2012/02/18/tmutil-hidden-arguments/
  • http://feed42.blogspot.com/2012/06/time-machine-backups-to-afp-volume-over.html
  • https://discussions.apple.com/thread/4207296?start=30&tstart=0
  • http://pondini.org/TM/A5e.html
  • http://www.garth.org/archives/2011,08,27,169,fix-time-machine-sparsebundle-nas-based-backup-errors.html

sudo diskutil unmountDisk force /Volumes/Chris\ Macbook\ Air-1/ sudo diskutil unmountDisk force /Volumes/Chris\ Macbook\ Air/ tmutil status tmutil destinationinfo sudo tmutil startbackup ssh -Y -L 8001:localhost:548 [email protected] -p 8000; tmutil startbackup

screen

``` screen -a screen -list echo $TERM

Ctrl+a c create Ctrl+a n next Ctrl+a d detach Ctrl+a m monitor Ctrl+a k kill Ctrl+a h log Ctrl+a x lock screen -r ```

https://superuser.com/a/279167

http://chriskempson.com/projects/base16/