Computing

Mostly Linux terminal (zsh on my machines, bash/tcsh elsewhere)

Anything complicated that I run more than once ends up as an alias here

  • bash/zsh misc
    • search directory recursively for search expression
        grep --include\*.{extensions} -rnw 'home/folder/' -e 'pattern'
      
    • (zsh specific) Replace all instances of foo with bar in all files recursively
        sed -i -- 's/foo/bar/g' **/*(D.)
      
    • recursively delete all .git folders (before backing up to an external drive without backing up all thousands of annoying .pack files)
        ( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs rm -rf
      
    • zsh globbing loops
        for f in **/*.ext; do <command> $f; done
      
    • symlinks (both files and directories)
        ln -s <target> <link_name>
      
    • hard drive space
        df -H
      
    • chmod
        chmod +x script.sh
      
    • chown
        chown -R user:domain folder
      
    • scp (copy log files from ssh server to local directory)
        apoorva@age4.nber.org:apoorva/Do/\*.log ./
      
    • populate sensible gitignores
        'echo "*.csv\n*.dta\n*.ipynb_checkpoints" >> .gitignore'
      
  • convert
    • pngs into gif (for R/Python plots)
        convert -delay 45 -loop 0 *.png <gif-title>.gif
      
    • pdfs to jpgs
        for i in `ls *.pdf`; do convert -density 300 "$i" "${i%%.*}.png"; done
      
    • tsv to csv (hahvahd does tsv for some inexplicable reason)
        tr '\t' ',' < input.tab > output.csv
      
  • pdf operations
    • combine
        pdfunite in1.pdf in2.pdf out.pdf
      
  • wget
    • match extension/pattern
        wget <site> -nd -np -l1 -r -v  -A "<pattern>*.<extension>"
      
    • mirror entire site
        wget -mkEpnp <site>
      
  • git
    • init new .gitignore with sensible defaults
        echo '*.csv\n*.dta\n*.ipynb_checkpoints' >> .gitignore
      
    • refresh repo after update to .gitignore
        git rm -r --cached . && git add .
      
    • remove current remote and add new remote
        git rm remote origin && git remote add origin <repo link>
      
  • conda / jupyter / ipython - conda cheatsheet
    • convert notebooks into scripts
        jupyter nbconvert --to script *.ipynb
      
    • activate environment
        source activate <env>
      
    • export list of packages from current environment
        conda env export > requirements.txt
      
    • delete environment
        conda env remove --name <env-name>
      
  • misc programming
    • compile fortran (heaven forfend)
      <compiler> (f90/f95/gfortran) -o <exec> <script.f90>
    
  • pandoc - ref
    • generic
        pandoc -s <input file> -o <output file>
      
    • markdown to latex
        pandoc -s <md> -o <tex>
      
    • markdown to pdf with citations
        pandoc -s --bibliography biblio.bib --filter pandoc-citeproc CITATIONS -o example24a.html
      
  • Rmarkdown
    • convert to pdf
        echo "library(rmarkdown); rmarkdown::render(\"$1\", \"pdf_document\")" | R --vanilla
      
    • convert to html
        echo "library(rmarkdown); rmarkdown::render(\"$1\")" | R --vanilla