Useful code snippets

I'm going to use this post to keep all the useful things about Git in particular but other things as well.

Add new remote repository

git remote add origin <remote repository URL>

Create a new branch to work in

git checkout -b <branchname>

Merge branch back in

Update gh-pages with master

Create Github page branch

Discard unstaged changes

Remove files from the repository based on your .gitignore without deleting them from the local file system

git rm --cached 'git ls-files -i -X .gitignore'

Remove file/folder from Git repository without deleting it from the local filesystem

Remove node_modules

Roll back to previous commit

git revert --no-commit 544993f8416a6e8a0cde66f7ea28379f9ebf446c .HEAD

This will revert everything from the HEAD back to the commit hash. (The –no-commit flag lets git revert all the commits at once, instead of littering history with messages for each commit in the range.)

to discard all the changes, and get a clean working tree:

See history of commits

git log

See remote branches

git remote show origin

Update gh-pages branch with master

git push origin master:gh-pages

New gh-pages branch and publish

Keep gh-pages up to date with a master branch

Kill processes

Start a webserver - cd into directory and:

Open bash profile in textedit

  1. touch ~/.bash_profile; open ~/.bash_profile
  2. source ~/.bash_profile

See what’s on the path

echo $PATH

Copy gem sets

rvm allows you to have many different installations of ruby. You can copy gem sets across

Ruby versions and sudo

Homebrew

Homebrew housekeeping

Homebrew updating

Homebrew permissions

Python versions using pyenv

Reference

Python checks

Python and Homebrew

Use pyenv and virtualenv

Virtualenv lets you create isolated Python environments where you can pin down versions of site-packages specific to a particular project. $ pip install virtualenv $ pyenv install 2.7.2 $ pyenv shell 2.7.2 $ virtualenv which python foo $ source foo/bin/activate $ pip install pandas $ pip install numpy

Get rid of new mail (bouncebacks) in Terminal

List globally installed NPM packages and version

nvm and node

Smart quotes

Merging topojson

When combining two or more files, you can specify the properties to keep:

Batch crop using Imagemagick

Quick batch crop:

Resize using Imagemagick

Convert to gif using Imagemagick

Regex to replace content between two characters

Regex to replace content between two characters

Regex to turn change case on text between two characters

PDF to text

Keyboard shortcuts

Importing photos from iPhone to computer

File path locations

Fix for blocked camera in Skype

Kill Jekyll

Activate emoji keyboard

Export Github issues to CSV

Eject disk popup gets stuck

Rename a Github branch

git branch -m new_name

Bootstrap media queries

Optimise images with

convert puzzle.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB puzzle_converted.jpg

Mac shortcuts

Delete shapefile in QGIS

Find IP

pyenv and homebrew

Rename files in a folder

Download YouTube video as audio

$ youtube-dl --audio-format 'best' "URL" $ youtube-dl --audio-format 'm4a' URL

Convert webm to mp4

ffmpeg -i FILENAME.webm FILENAME.mp4

Extract the audio from an .WEBM movie file to an .MP3 audio file

FILE="the-file-you-want-to-process.webm"; ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";

Batch process all WEBM video files in a folder

for FILE in *.webm; do echo -e "Processing video '\e[32m$FILE\e[0m'"; ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3"; done;

Batch process all MKV video files in a folder

for FILE in *.mkv; do echo -e "Processing video '\e[32m$FILE\e[0m'"; ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3"; done;

Batch process all mp4 video files in a folder

for i in *.mp4; do ffmpeg -i "$i" "${i%.*}.mp3"; done

Add to things

The email’s subject becomes your to-do’s title, and the rest goes into the notes.

MySQL

Note: By default, the MySQL user root has no password. It doesn’t really matter for a local development database. If you wish to change it though, you can use $ mysqladmin -u root password 'new-password'.

To start mongodb on Catalina

mongod --config /usr/local/etc/mongod.conf

Incorporate a separate repo into your repo

“There isn’t anything to compare. Nothing to compare, branches are entirely different commit histories” Starting from master:

Free up space on Mac

Capture video stream in VLC

Merge a folder of text files into a single file

cat *.txt » ~/Desktop/combined.txt

Force log in page on hotel wi-fi

Uninstall npm

curl -qL https://www.npmjs.com/install.sh | sudo sh

Changing file extensions for all files in a directory

VS Code tips

— Select all occurrences of find match