This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
* Defines the given symbol if it has not been defined. For the value of the | |
* symbol, this function tries to load it from the given environment variable. | |
* The optional third argument is the default value which is used when the | |
* environment variable is undefined. This function returns the value of the | |
* symbol if defined, otherwise returns $Failed. | |
*) | |
LoadVariable[symbol_, env_String, default_:Null] := ( | |
If[!ValueQ[symbol], | |
If[Environment[env] =!= $Failed, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* The extended euclidean algorithm, which gives x and y such that | |
* a*x + b*y = gcd(a, b) >= 0. | |
* Input: Integers $a and $b. | |
* Output: Integers $x and $y. | |
* | |
#procedure ExtGCD(a,b,x,y,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6) | |
#define aa "`tmp1'" | |
#define bb "`tmp2'" | |
#define lastx "`tmp3'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Prints the absolute path to the directory containing the given path. | |
# The directory must exist. | |
abs_dirname() {( | |
cd "`dirname \"$1\"`" && pwd | |
)} | |
# Examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Wraps "mktemp -d $1XXXXXXXXXX" | |
mktemp_d() {( | |
umask 077 | |
{ | |
# Use mktemp if available. | |
dir=`mktemp -d "$1XXXXXXXXXX" 2>/dev/null` && [ -d "$dir" ] | |
} || { | |
# Fall back on mkdir. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
* Evaluates the given expression with printing the timing in the real time. | |
*) | |
Time[expr_] := Module[{t, r}, | |
{t, r} = AbsoluteTiming[expr]; | |
Print["Elapsed time: ", t, " seconds."]; | |
r | |
]; | |
SetAttributes[Time, HoldFirst]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# append_path VAR PATH - adds PATH to the end of PATH | |
append_path() { | |
[ $# -lt 2 ] && return | |
[ ! -d "$2" ] && echo "Warning: path $2 is not found on `hostname`" >&2 | |
remove_path $1 $2 | |
if eval '[ -z "$'$1'" ]'; then | |
eval $1=$2 | |
else | |
eval $1='$'$1:$2 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CF den; | |
S x; | |
S a,j,n,x1,x2; | |
S a,b,c; | |
L F1 = den(1-x); | |
L F2 = den(1-x)^2 / x; | |
L F3 = den(a+b*x ); | |
L F4 = den( +b*x+c*x^2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This snippet uses C++11 features. For C++03, see the previous revision. | |
* | |
* Replace idioms like | |
* | |
* struct Foo { | |
* int a; | |
* }; | |
* | |
* void func(Foo *f) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = gcc | |
CFLAGS = -g -O2 -Wall -Wextra -std=c90 -pedantic | |
CXX = g++ | |
CXXFLAGS = -g -O2 -Wall -Wextra -std=c++98 -pedantic | |
F77 = gfortran | |
FFLAGS = -g -O2 -Wall -Wextra -std=f95 -pedantic | |
FC = gfortran | |
FCFLAGS = -g -O2 -Wall -Wextra -std=f95 -pedantic | |
CPPFLAGS = | |
DEFS = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filesize() { | |
if [ -f "$1" ]; then | |
wc -c "$1" | awk '{print $1}' | |
else | |
echo "filesize: file $1 doesn't exist" >&2 | |
return 1 | |
fi | |
} |
OlderNewer