Skip to content
Graham Wakefield edited this page Jun 20, 2019 · 4 revisions

SSH

Set up SSH authorized keys

# Generate client-side key from Terminal:
cd ~
ssh-keygen -t rsa -C "[email protected]"
# when it asks, don't enter a password.
# creates the following 2 files in the hidden ~/.ssh directory:
# ~/.ssh/sshid_rsa
# ~/.ssh/id_rsa.pub
# id_rsa.pub is the public key that gets uploaded to the server
# e.g. paste contents into github profile SSH keys
# id_rsa is your private file, do not share

copy ssh key to a server

scp ~/.ssh/id_rsa.pub user@domain:./
# Then, log into the server and execute the following commands:
ssh user@domain
mkdir .ssh
chmod 700 .ssh
cd .ssh
touch authorized_keys
touch authorized_keys2
chmod 600 authorized_keys
chmod 600 authorized_keys2
cat ../id_rsa.pub >> authorized_keys
cat ../id_rsa.pub >> authorized_keys2
rm ../id_rsa.pub
exit

remote ssh

# enter server:
ssh user@domain
# exit server:
exit

# copy local file to server
scp localfilepath user@domain:./
# launch remote gui apps on local
ssh -X <command>

# launch remote gui apps on remote
export DISPLAY=:0
# or
export DISPLAY=:0.0
<command>

multi-cast ssh

on Linux, look at mssh <user@domain> host1 host2 host3 etc. in an ssh -X context: dbus-launch mssh ...

on osx, consider http://code.google.com/p/csshx

Backup

# -v verbose
# -a preserves modification times & modes
# -r recurse directories
# -E extended attributes
rsync -ravE --one-file-system /Volumes/My\ Book /Volumes/GANDALF
# for an incremental backup (removing extraneous files): --delete --ignore-errors

Permissions

# add read permission to user
chmod u+r	
# add read permission to user & group
chmod ug+r
# add read/write permission to all
chmod a+rw	
# add execute permission to all
chmod a+x
# remove execute permission to others (not user/group):
chmod o-x
# do it recursively:
chmod -R a+rw directory
# long example:
# set a directory tree to rwx for owner directories, rw for owner files, --- for group and others.
chmod -R u+rwX,g-rwx,o-rwx directory

Shell scripts

# basic loops:
for i in *.pdf; do echo $i; done
for f in *; do echo "lipo -create $f ../lib_osx64/$f -output ../lib_osx/$f"; done
for f in *; do lipo -create $f ../lib_osx64/$f -output ../lib_osx/$f; done

gcc/clang

# export pre-processed header (where stub.c only has #include <header>
gcc -E stub.c | grep -v '^#'

# Find out what symbols are in a library/app:
nm applicationname

# Find out what dylibs/frameworks an app links to:
otool -L applicationname

# Find out what architectures a library is:
lipo -info libxyz.a
# merge osx arch-specific libs into a universal lib:
lipo -create libx32.a libx64.a -output libx.a

# Change expected location of a dylib (in the dylib):
install_name_tool -id @executable_path/../Frameworks/libqt.3.dylib demo.app/Contents/Frameworks/libqt.3.dylib

# Change expected location of a dylib (in the app):
install_name_tool -change libqt.3.dylib  @executable_path/../Frameworks/libqt.3.dylib demo.app/Contents/MacOS/demo

# TODO update for relative path on newer OSX

Patching

patch -p1 < path/to/file

Git

typical workflow

# see what is not yet tracked and needs to be
git status

# stage a file (do this after each modification):
git add <files>
# commit the staged files
git commit -m 'message'

# or, commit all changes to files already tracked:
git commit -am 'message'

# append new stages to the current commit
git commit --amend

# now pull, in case of merge conflicts:
git pull
# resolve any conflicts, then push
git push

deal with problems

# un-stage an added file:
git reset HEAD <file>
# revert a file (deletes the changes permanently!)
git checkout -- <file>

# remove a file
git rm <file>
# or just un-track a file (which was e.g. added accidentally)
git rm --cached <file>
# move a file
# (or manually using rm and add)
git mv <old> <new>

branches

# list current branches:
git branch
# with last commit:
git branch -v
# list branches not merged with current branch:
git branch --no-merged
# or, create a local 'tracking branch' based of a server branch:
# (allows git push / git pull to work automatically)
# (git clone basically does this for <master> branch)
git checkout -b <branchname> origin/<branchname>

# start a new branch for task1:
# aka git branch task1 && git checkout task1
git checkout -b task1
git checkout -b task1 <from_branch>
# edit/add and commit changes to task1...
# go back to working state before task1:
git checkout master

# merge branch task1 back into current branch:
git merge task1

# send your latest changes to a branch to server:
git push origin <branchname>

# delete a local branch
git branch -d task1

submodules

IMPORTANT: changes to submodules must be committed to their respective submodule repos, from the submodule's folder. Only then can the containing repo be committed.

# a submodule is a reference to a particular revision of a repo
git submodule add -b master git://github.com/defunkt/my-fantastic-plugin.git plugins/my-fantastic-plugin

# pull all submodules in a repo
git submodule init && git submodule update

# remove submodule:
# Delete the relevant section from the .gitmodules file.
# Delete the relevant section from .git/config.
# (no trailing slash):
git rm --cached path_to_submodule 
# Commit
# Delete the now untracked submodule files
rm -rf path_to_submodule

setup new machine

git config --global user.name grrrwaaa
git config --global user.email [email protected]
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.interactive auto

git config --global github.user grrrwaaa
git config --global core.editor code
git config --list

setup new project

# new project in local folder
git init
# clone external
git clone https://[email protected]/LuaAV/LuaAV.git <optional local path>
git submodule init && git submodule update

more info

# see what's up:
git status
git diff
git diff --staged
git log
git log -p -2 --stat
git log --since=2.weeks

git help <verb>