Skip to content

A list of commands that I always find myself coming back to.

Notifications You must be signed in to change notification settings

MarcHarriss/general_tips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

Introduction

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].

Linux

Monitoring

Monitor the end of a file

sudo tail -f /var/log/apache2/access.log

Scp

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.

Docker

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)

Git

Branching

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_

changing config

Set global username and email

git config --global user.name "Marc Harriss"

git config --global user.email [email protected]

Get config

git config -l

Where to find git conf

sublime ~/.gitconfig

Submodules

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

General

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

Time-machine

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^

JavaScript

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')

NPM

Fix paths

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__

Fix npm links

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

MacOS

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

Obliterate MYSQL from MAC

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

MongoDB

Check if apache2 active

sudo netstat -plunt | grep apache2

Install and fix

brew update

brew install mongodb

mkdir -p /data/db

It's likely to encounter perm issues.

sudo chown -R "id -un" /data/db

Browser JS

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')

Ruby

Managing gems

gem build <gemname>

gem push <gemname>-<version>

Ruby gems credentials

curl -u mharriss https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials

Python

Python packages

# 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/*

About

A list of commands that I always find myself coming back to.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published