Programming

Table of Contents

Notes on Gitbook

Python

$ conda install -c conda-forge tmux

  • Post-Installation

$ conda config --set auto_activate_base false
# It creates ~/.condarc with following content:
auto_activate_base: false

  • Jupyter notebook

$ conda install ipykernel
$ python -m ipykernel install --user --name lal --display-name "python-lal"
# It modifies ~/Library/Jupyter/kernels/ or ~/.local/share/jupyter/kernels/

$ pip -V
$ python -m site

HTTP server

  • Start a http server

$ python3 -m http.server

Virtual Environment

  • virtualenv

$ virtualenv <myenv>
$ source myenv/bin/activate
$ deactivate

  • pip

$ pip freeze > requirements.txt
$ pip install -r requirements.txt

C/C++


Haskell

$ sudo port install ghc


Latex

Setup

$ sudo apt-get install texlive-full

Packages

\usepackage{amsmath} % AMS math
\usepackage{amssymb} % AMS symbols
\usepackage{physics} % \bra \ket ...

% Text Color
\usepackage{xcolor}
\newcommand{\red}{\textcolor{red}}
\newcommand{\blue}{\textcolor{darkblue}}

% Hyperlink
\usepackage[colorlinks]{hyperref}
\definecolor{darkblue}{HTML}{2E3092}
\hypersetup{colorlinks=true,linkcolor=darkblue,citecolor=darkblue,urlcolor=darkblue}

\usepackage{amsthm} % AMS theorem
\theoremstyle{definition}
\newtheorem{example}{Example}[section]
\newtheorem*{solution*}{Solution}

Packages

\usepackage[sc]{mathpazo}
\linespread{1.05} % Palladio needs more leading (space between lines)
\usepackage[T1]{fontenc}

Makefile

  • $ latexmk -pdf main.tex

Git

Gitignore

# .gitignore

**/.DS_Store

SSH

Client

  • Permission

$ chmod 700 ~/.ssh
$
chmod 644 ~/.ssh/authorized_keys
$ chmod 644 ~/.ssh/config
$ chmod 600 ~/.ssh/id_rsa
$ chmod 644 ~/.ssh/id_rsa.pub
$ restorecon -R -v ~/.ssh

  • .ssh/config entry

Host ShortNameForConnection
Hostname
ServerIPorDomainName
User
YourUsername
IdentityFile
~/.ssh/id_rsa_YourPrivateKey
ProxyCommand ssh
name_of_gateway_machine -W %h:%p
LocalForward 8899 localhost:8899
ForwardX11 yes

  • Socks proxy

$ ssh -ND 8899 sshServerIP

Server

  • Installation

$ sudo apt-get install openssh-server
# finished!

# Checking status
$ sudo service ssh status

# Change Configuration
$ sudo vim /etc/ssh/sshd_config
$ sudo service ssh restart

  • Permission

$ chmod 700 ~/.ssh
$ chmod 644 ~/.ssh/known_hosts
$ restorecon -R -v ~/.ssh

macOS

Startup Items

  • 1) /Library/LaunchAgents/*
    2) System Preferences > Users & Groups > Login Items

Make Bootable Media

  • $ diskutil list
    /dev/disk2 (external, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: Apple_partition_scheme *15.6 GB disk2
    1: Apple_partition_map 4.1 KB disk2s1
    2: Apple_HFS 2.4 MB disk2s2
    $ diskutil unmountDisk /dev/disk2
    $ dd if=ubuntu.iso |pv |sudo dd of=/dev/rdisk2 bs=1m
    # Use rdisk2 instead of disk2 for better performance

MacPort

  • $ sudo port uninstall inactive
    $ port echo leaves
    $ sudo port uninstall leaves

Backup to Disk Image

  • $ sudo dd if=/dev/rdisk2s2 bs=1m |pv |gzip > disk2s2.img.gz
    $ sudo gzip -dc disk2s2.img.gz |pv |sudo dd of=/dev/sda bs=1m

Find

  • $ find . -type d -perm 777 -exec chmod 755 {} \;
    $ find . -type f -perm 777 -exec chmod 644 {} \;
    $ find . -name ".DS_Store" -exec rm {} \;

Enable Spolight indexing for Google Drive

  • # Enable
    $ mdutil /Volumes/GoogleDrive/ -i on
    # Disable

    $
    mdutil /Volumes/GoogleDrive/ -i off
    $ Check
    $ mdutil /Volumes/GoogleDrive/ -
    s