Skip to content

Instantly share code, notes, and snippets.

View xuhdev's full-sized avatar

Hong Xu xuhdev

View GitHub Profile
for epoch in range(1): # loop over the dataset multiple times
running_loss = 0.0
for i, data in enumerate(train_loader, 0):
# get the inputs; data is a list of [inputs, labels]
inputs, labels = data
# zero the parameter gradients
optimizer.zero_grad()
# forward
outputs = net(inputs)
loss = criterion(outputs, labels)
@xuhdev
xuhdev / TAGS
Created November 8, 2019 05:14
TAGS
TensorIterator.h,6009
namespace at {at58,1889
struct DimCounter {DimCounter60,1905
IntArrayRef shape;shape67,2097
Range range;range68,2118
DimVector values;values69,2133
int64_t offset;offset70,2153
struct CAFFE2_API OperandInfo {OperandInfo73,2175
using StrideVector = SmallVector<int64_t, 6>;StrideVector74,2207
@xuhdev
xuhdev / use_macports.sh
Last active September 3, 2019 08:29
Wrap executables installed by Macports
#!/bin/sh
## Wrap Macports command (any executables installed by Macports).
if [ "$#" -le 0 ]; then
echo "Usage: $0 command [arg1, arg2, ...]" >&2
exit 1
fi
if [[ -z $MACPORTS_PREFIX ]]; then
@xuhdev
xuhdev / pip_install_with_confirmation.py
Last active August 8, 2019 19:12
Run ``pip install`` with a confirmation only if some packages are missing. This is useful to put in the beginning of a Jupyter notebook.
# Author: Hong Xu. This file is under CC0.
def pip_install_with_confirmation(packages):
"""Run ``pip install`` with a confirmation only if some packages are missing. This is useful to put in the beginning of
a Jupyter notebook.
Args:
packages (dict): Each key is the name of a package to be installed. Each value is a sequence of size 3. The
first two elements are the ``package`` and ``name`` parameter of ``importlib.import_module()``, respectively.
#!/bin/bash
# Usage:
# grepl [OPTIONS] [GREP-OPTIONS] PATTERN FILE
help() {
cat <<EOF
Usage: grepl [OPTIONS] [GREP-OPTIONS] PATTERN FILE
Options:
@xuhdev
xuhdev / overleaf-auto-push.sh
Last active October 25, 2017 04:18
Auto push to overleaf
watchmedo shell-command \
--patterns='*.pdf' \
--ignore-directories \
--recursive \
--command 'git commit -a -m "U" && git push'
@xuhdev
xuhdev / inputrc
Created November 17, 2016 05:31
My inputrc
$include /etc/inputrc
"\C-p":history-search-backward
"\C-n":history-search-forward
set colored-stats On
set completion-ignore-case On
set completion-prefix-display-length 3
set mark-symlinked-directories On
set show-all-if-ambiguous On
set show-all-if-unmodified On
@xuhdev
xuhdev / to-complement-dimacs.py
Last active August 6, 2016 20:19
Convert a graph in DIMACS format to its complement graph
#!/usr/bin/python3
#
# Convert a DIMACS graph to its complement graph.
#
# Usage:
#
# to-complement.py < in-dimacs > out-dimacs
import sys
@xuhdev
xuhdev / gen-editorconfig-from-gitignore.sh
Last active August 3, 2016 01:11
Generate an editorconfig file from a gitignore file.
#!/bin/bash
# Generate an editorconfig file from a gitignore file. Usage:
#
# /path/to/gen-editorconfig-from-gitignore.sh < .gitignore >> .editorconfig
while read line
do
if [[ -z $line ]]
then
@xuhdev
xuhdev / backbackslash.py
Last active December 28, 2015 11:59
Often when your file needs to go through a few filters, the number of backslashes needed for escaping is just horrible! This small script just solves the problem. Works well on Python 2.6 and later as well as Python 3.
# Often when your file needs to go through a few filters, the number of
# backslashes needed for escaping is just horrible! This small script just
# solves the problem. Works well on Python 2.6 and later as well as Python 3.
# This file is under public domain.
# Copyright (C) 2013 Hong Xu <hong@topbug.net>
from __future__ import print_function