Skip to content

Instantly share code, notes, and snippets.

@nashid
nashid / awk.md
Last active March 10, 2022 01:47
awk shortcuts

Print without the first elemenet:

grep "type" * | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}' | grep "\"type\""
@nashid
nashid / punctuation.js
Created February 21, 2022 23:48 — forked from davidjrice/punctuation.js
List of punctuation characters
var PUNCTUATION = "" +
"’'" + // apostrophe
"()[]{}<>" + // brackets
":" + // colon
"," + // comma
"‒–—―" + // dashes
"…" + // ellipsis
"!" + // exclamation mark
"." + // full stop/period
"«»" + // guillemets
@nashid
nashid / check-gpu-usage.md
Last active February 11, 2022 00:12
How to check GPU usage
  • Check GPU usage every 5s: watch -n5 nvidia-smi
Every 5.0s: nvidia-smi                                                                                                                                                                                                      Thu Feb 10 16:12:32 2022

Thu Feb 10 16:12:32 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 495.29.05    Driver Version: 495.29.05    CUDA Version: 11.5     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
@nashid
nashid / git-lfs
Last active January 22, 2022 22:11
```
brew install git-lfs
git lfs install
git lfs track "*.png"
git lfs track path/to/some/folders/*
```
Make sure you commit the .gitattributes file.
git add .gitattributes && git commit -m "Add Git LFS attribute dot file" && git push
@nashid
nashid / PBS_sample.sh
Created January 10, 2022 22:53 — forked from mathsam/PBS_sample.sh
Sample PBS script
# Sample PBS job script
#
# Copy this script, customize it and then submit it with the ``qsub''
# command. For example:
#
# cp pbs-template.sh myjob-pbs.sh
# {emacs|vi} myjob-pbs.sh
# qsub myjob-pbs.sh
#
# PBS directives are fully documented in the ``qsub'' man page. Directives
@nashid
nashid / clean.sh
Created December 29, 2021 20:15
Mac storage taking too much space
# nvm cache could get very large
nvm cache clear
@nashid
nashid / code-listing-with-color-latex.tex
Created December 7, 2021 03:10
Code listing with highlighting in latex
\definecolor{ashgrey}{rgb}{0.7, 0.75, 0.71}
\begin{lstlisting}[firstnumber=1]
'use strict';
const common = require('../common');
...
\end{lstlisting}
\vspace{-\baselineskip}
\begin{lstlisting}[firstnumber=10, backgroundcolor=\color{ashgrey}]
function main({ len, n }) {
@nashid
nashid / github-all-the-things.sh
Last active February 20, 2022 04:32
github - all the things
# remove lage files from commit history
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD
git push origin --force --all
# git commit in the past
git commit --date="5 day ago" -m "Your commit message"
# setup credential.helper store
$ git config credential.helper store
@nashid
nashid / .md
Created September 23, 2021 17:02 — forked from rahulrajaram/.md
Python: Write to a file from multiple threads

I recently came across the need to spawn multiple threads, each of which needs to write to the same file. Since the file will experience contention from multiple resources, we need to guarantee thread-safety.

NOTE: The following examples work with Python 3.x. To execute the following programs using Python 2.7, please replace threading.get_ident() with thread.get_ident(). As a result, you would need to import thread and not threading.

  1. (The following example will take a very long time). It will create 200 threads, each of which will wait until a global lock is available for acquisition.
# threading_lock.py
import threading