Just a curation of commands I keep finding myself having to google. If your often scouring through documentation or saving snippets, I would recommend using (Dash)[https://kapeli.com/dash].
Monitor the end of a file
sudo tail -f /var/log/apache2/access.log
Copying from remote to local
scp -vr user@remote:/path/to/file destination/folder
Inverse for local to remote
scp -vr /local/file user@remote:/path/to/destination
scp may not work while using zsh, so you may need to switch to bash.
Build image (from directory where there is a dockerfile)
docker build -t __placeholder__ .
Create background container
docker run -dp 9200:9200 --name ES elasticsearch
The "d" from -dp actually makes it run in the backfound
Remove all images
docker rmi -f $(docker images -q)
Run commands inside container
docker run -it --rm __placeholder__ bash
Stop containers all
docker stop $(docker ps -q)
Create Branch
git branch _branch_name_
git checkout _branch_name_
Shorthand for the above
git checkout -b _branch_name_
When happy with changes, merge
git checkout master
git merge _branch_name_
Set global username and email
git config --global user.name "Marc Harriss"
git config --global user.email my@email.com
Get config
git config -l
Where to find git conf
sublime ~/.gitconfig
Pull all changes in the repo including changes in the submodules
git pull --recurse-submodules
Pull all changes for the submodules
git submodule update --remote
Add submodule and define the master branch as the one you want to track
git submodule add -b master [URL to Git repo]
git submodule init
grep -lr '<<<<<<<' . | xargs git checkout --theirs
Copy ssh key
cat ~/.ssh/id_rsa.pub | pbcopy .
(mac)
Fix host verification issue
ssh-keyscan -H __website.com__ >> ~/.ssh/known_hosts
Remove folder once uploaded
git rm -r --cached node_modules && touch .gitignore && echo "node_modules/" >> .gitignore
Undo commits
git reset --soft HEAD^
Reset to last commit
git reset --hard HEAD^
Listen to all events
Object.keys(window).forEach(key => {
if (/^on/.test(key)) {
window.addEventListener(key.slice(2), event => {
console.log(event);
});
}
});
Psuedo elements
var color = window.getComputedStyle(
document.querySelector('.element'), ':before'
).getPropertyValue('color')
cd ~/npm-global/bin
Check if command your are trying to run exists Add alias in ~/.zshrc | ~/.bashrc whichever terminal you use
alias ng="~/.npm-global/bin/__placeholder__
Add to top of ~/.zshrc | ~/.bash_profile
source /Users/YOUUSERNAME/.bash_profile
View all global packages
npm ls -g --depth 0
Shell autocomplete
npm completion >> ~/.bashrc
Or
npm completion >> ~/.zshrc
Add app bar space
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}’
$Killall Dock
repeat for each spacer
Flush dns
sudo killall -HUP mDNSResponder;say DNS cache has been flushed
If that doesnt work then
sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache;say MacOS DNS cache has been cleared
Launching programs from the terminal.
chrome () {
open -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "$1"
}
code () {
open -a /Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron "$1"
}
Watching files
sudo fs_usage | grep my.cnf
Backup your databases
Check for MySQL processes
ps -ax | grep mysql
Stop and kill any MySQL processes Analyze MySQL on HomeBrew:
brew remove mysql
brew cleanup
Remove files:
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
Unload previous MySQL Auto-Login:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Remove previous MySQL Configuration:
sublime /etc/hostconfig
Remove the line MYSQLCOM=-YES- Remove previous MySQL Preferences:
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
sudo rm -rf /etc/my.cnf
sudo rm -rf /etc/mysql/
Reboot just to ensure any MySQL processes are killed Try to run mysql, it shouldn't work
Check if apache2 active
sudo netstat -plunt | grep apache2
brew update
brew install mongodb
mkdir -p /data/db
It's likely to encounter perm issues.
sudo chown -R "id -un" /data/db
Add script to head
var script = document.createElement('script');
script.src = "https://code.jquery.com/ui/1.12.1/jquery-ui.js";
script.integrity = "sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30=";
script.crossOrigin = "anonymous";
document.head.append(script);
Change icons Across Page
(function (newS, selector) {
var fonts = document.querySelectorAll(selector)
fonts.forEach(function(item) {
item.classList.remove(selector);
item.classList.add(newS);
})
})('far', 'fa')
gem build <gemname>
gem push <gemname>-<version>
curl -u mharriss https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials
# Install latest version of setuptools and wheel
python3 -m pip install --user --upgrade setuptools wheel
# Run in the directory where setup.py is located
python3 setup.py sdist bdist_wheel
# Install Twine to upload the generated packages
python3 -m pip install --user --upgrade twine
# Upload to test.pypi.org
python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*