Skip to content

Instantly share code, notes, and snippets.

@guoquan
guoquan / build.sh
Last active November 15, 2024 06:16
build CUDA-based jupyter docker stacks
# Refer to NGC for latest tag. https://catalog.ngc.nvidia.com/orgs/nvidia/containers/cuda/tags
# You don't need an OWNER, it will has a default jupyter
# Resulting quay.io/${OWNER}/minimal-notebook
DOCKER_BUILD_ARGS="--build-arg ROOT_CONTAINER=nvcr.io/nvidia/cuda:12.6.2-cudnn-devel-ubuntu22.04" OWNER=deepq make build/docker-stacks-foundation build/base-notebook build/minimal-notebook
@guoquan
guoquan / md5sum-win.sh
Created January 20, 2022 17:03
`md5sum` with checksum file from windows
cat $1 | tr -d '\r' | sed 's/\\/\//g' | md5sum -c -
@guoquan
guoquan / kmp.py
Last active June 18, 2020 19:35
Knuth Morris Pratt algorithm for list
# This code is developed based on David Eppstein's recipe
# http://code.activestate.com/recipes/117214-knuth-morris-pratt-string-matching/
class KnuthMorrisPratt():
def __init__(self, pattern):
self.pattern = pattern
@property
def pattern(self):
return self._pattern
@guoquan
guoquan / tensor-cartesian-product-performance.ipynb
Created March 4, 2020 21:21
Profiling Cartesian product among tensors.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@guoquan
guoquan / run.py
Created March 4, 2020 21:08
Funny progress indicator in python
import time
s = '|\-/'
s = '{(|)})|('
s = ['| ', '\ ', '\_ ', ' _ ', ' _/', ' /', ' |', ' /', ' _/', ' _ ', '\_ ', '\ ']
while True:
for ss in s:
print(ss, end='\r', flush=True)
time.sleep(0.1)
@guoquan
guoquan / nvidia-ps.sh
Created November 1, 2019 17:37
Show process information jointly with Nvidia GPU information.
join -1 2 -2 2 <(nvidia-smi pmon -c 1 -s mu | sort -k 2) <(ps -aux | sort -k 2) | cut -c -80
@guoquan
guoquan / hide_class.ipynb
Created May 31, 2019 20:50
A context manager to hide specific class in inheritance temporally. This is inspired by https://stackoverflow.com/a/14567117
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@guoquan
guoquan / fix_named.sty
Created May 9, 2019 15:59
Fix bibtex named style problem.
% *** fix named problem
\makeatletter
\let\@internalcite\cite
\def\cite{\def\citeauthoryear##1##2{##1, ##2}\@internalcite}
\def\shortcite{\def\citeauthoryear##1{##2}\@internalcite}
\def\@biblabel#1{\def\citeauthoryear##1##2{##1, ##2}[#1]\hfill}
\makeatother
% ***
@guoquan
guoquan / comment.sty
Created April 28, 2019 06:21
A set of macros in latex to create outline, TODO, FIXME, comment as a span or block, which is able to be hidden by another macro \hidec
\usepackage[dvipsnames]{xcolor}
\usepackage{etoolbox}
\newrobustcmd{\showcb}[3]{% make comment block
\csdef{#1}##1{%
\par\noindent\textcolor{#3}{// \colorbox{#3}{\textcolor{white}{#2}}: ##1}%
}
}
\newrobustcmd{\showcs}[3]{% make comment span
\csdef{#1}##1{%
\textcolor{#3}{/* \colorbox{#3}{\textcolor{white}{#2}}: ##1 */}%
@guoquan
guoquan / sample_extent.py
Last active April 15, 2019 22:25
Setup singleton pattern by decorator (how boring am I to have written these codes...)
from .singleton import singleton
from regr.base import AutoNamed
def named_singleton(cls):
if not issubclass(cls, AutoNamed):
raise TypeError('named_singleton can be applied to subclasses of AutoNamed,' +
' but MRO of {} is given.'.format(cls.mro()))
def getter(name=None):