Skip to content

Instantly share code, notes, and snippets.

@kirk86
Forked from ansantam/cheatsheet.md
Created October 29, 2015 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirk86/019a6efed4643c6bcbd9 to your computer and use it in GitHub Desktop.
Save kirk86/019a6efed4643c6bcbd9 to your computer and use it in GitHub Desktop.
Cheatsheet

Bash

Checkout a specific version

svn co <url> -r version

Redirect all the verbose to the /dev/null file.

The null device discards all data written to it but reports that the write operation has succeeded. Typically used for disposing of unwanted output streams of a process:

> /dev/null

If the command uses the standard error:

> /dev/null 2>&1

Count the files in the current directory

ls | wc -l

Erase a string from file

sed -i -e 'string' filename

Search for a pattern in file, case insensitive search

grep -i pattern file

Find a directory (type d) or file (type f)

find / - type d -name "name"

Find files starting with name in dir

find /dir/ -name name*

Create a symbolic link from target directory to current directory

ln -s target_directory ./current_directory

Show first 10 lines of file

head file

Show last 10 lines of file

tail file

Show file

more file

Unzip

tar xvzf file.tar.gz
tar xvzf file.tgz

File permissions

chmod 744 file

First digit is owner permission, second is group and third is everyone. Calculate permission digits by adding numbers:

4	read
2	write
1	execute

Git

GitHub Colors

To add GitHub colors to your terminal, just type:

git config --global color.ui auto

Editor for the commit messages

git config --global core.editor "emacs"
export GIT_EDITOR=emacs

Download a repository when you are a contributor

git clone git@github.com:user/repo.git

Git clone:

git clone git://project.url
git checkout #ofcommit

Git branches:

git checkout -b branchname
git push -u origin branch

Git fast-forward

When your branch my_branch is behind several commits with respect to other_branch, you can fast-forward it:

git checkout other_branch
git pull
git checkout my_branch
git push

SSH Key

Everytime I have to generate an SSH key I follow this. My only problem is that there is one step missing for me to work.

Before typing:

ssh-add ~/.ssh/id_rsa

you must type:

eval `ssh-agent -s`

Creating repositories

Every time I create a repository on GitHub, I follow the instructions they provide. For example, for this repository:

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/KFubuki/useful_stuff.git
git push -u origin master

The only problem is that, from lxplus at least, git push -u origin master just doesn't work. If you have your SSH key configured, to solve this you just have to edit the .git/config file in your repo directory, and change:

url = https://github.com/KFubuki/useful_stuff.git

to:

url = ssh://git@github.com/KFubuki/useful_stuff.git

LSF

Kill all your jobs:

bkill -u username 0

LaTeX

Compile with BibTex

latex example
bibtex example
latex example
latex example
dvips example

Python

Compile a script

import py_compile
py_compile.compile("file.py")

List of directories which will be searched for modules at runtime

python -v
>>> import sys
>>> sys.path

Virtual Environment

  • Create it:
virtualenv venv
  • Activate it:
cd venv
source bin/activate
  • Install everything you need:
pip install -U setuptools
pip install -U pip

pip install numpy
pip install scipy
pip install matplotlib
pip install PySide
pip install ipython[all]
pip install patsy
pip install pandas
pip install sympy
pip install nose

pip install statsmodels
pip install zipline
pip install quandl
pip install scikit-learn
  • Activate IPython:
ipython profile create
ipython notebook
  • Close venv
deactivate

IPython

Convert your notebook to PDF:

ipython nbconvert notebookname.ipynb --to latex --post pdf

SixTrack

Compile with the collimation block

./make_six gfortran collimat

Sublime Text

Location

I always forget where it is: ~/.config/sublime-text-3/Packages.

Using Diffy package to see the difference between two files.

To compare and show the diffs:

CTRL + k followed by CTRL + d.

To clear the marked lines:

CTRL + k followed by CTRL + c

Search and Replace - Multiple Files

Ctrl + Shift + F

In the search panel, you can customize the display of results with the following options:

Show in Separate Buffer/Output Panel
Show Context
svn co svn+ssh://svn.cern.ch/reps/Sixtrack/trunk/Sixtrack --username ansantam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment