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 permissions

Python versions using pyenv


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