Skip to content

Instantly share code, notes, and snippets.

View xuhdev's full-sized avatar

Hong Xu xuhdev

View GitHub Profile
@xuhdev
xuhdev / one_column_subplot.py
Last active October 4, 2015 14:27
Use matplotlib to plot in a column from several ascii data files
#!/usr/bin/env python
# Requires numpy and matplotlib
# This file is in public domain
def usage():
import sys
print >>sys.stderr, sys.argv[0] + " [options] file1 [file2 file3 ...]"
@xuhdev
xuhdev / my-vim-configure.sh
Created July 12, 2012 04:29
My Vim source configuration script
#!/bin/sh
./configure --with-features=huge --enable-pythoninterp --enable-python3interp --enable-perlinterp --enable-rubyinterp CFLAGS='-O3 -Wall -Wextra' $*
@xuhdev
xuhdev / empty_beamer.tex
Created October 7, 2012 22:41
Empty beamer template
\documentclass[14pt]{beamer}
\usetheme{Singapore}
\begin{document}
\begin{frame}
\end{frame}
@xuhdev
xuhdev / loadmatrix.py
Last active December 10, 2015 12:58
load matrix from an ascii file into a numpy.matrix object.
def load_matrix_from_file(f):
"""
This function is to load an ascii format matrix (float numbers separated by
whitespace characters and newlines) into a numpy matrix object.
f is a file object or a file path.
"""
import types
import numpy
@xuhdev
xuhdev / input.txt
Last active December 10, 2015 22:18
Load matrix from an ascii file.
1 2 3 4
9 8 7 6
@xuhdev
xuhdev / derivative.m
Last active December 16, 2015 11:49
nth order derivative in matlab
% Derivative in MatLab.
%
% Copyright (C) 2013 Hong Xu <[email protected]>
% All rights reserved.
%
% License:
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
@xuhdev
xuhdev / diag.sh
Created May 26, 2013 00:37
Print the diag elements of a matrix in an ASCII format file.
awk '{ print $NR }'
@xuhdev
xuhdev / kron.cpp
Last active December 19, 2015 17:48
kronecker product
// kronecker product
//
// kprod = a kron b
//
// size of a is (ma, na)
// size of b is (mb, nb)
// example:
//
@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 / 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 <[email protected]>
from __future__ import print_function