Skip to content

Instantly share code, notes, and snippets.

@tueda
tueda / extend-copyright.sh
Created October 28, 2013 10:19
Used for replacing copyright lines in source files.
@tueda
tueda / PrintTiming.m
Created November 12, 2013 09:19
Prints the timing when the Mathematica kernel is terminated.
(*
* Prints the timing when the Mathematica kernel is terminated.
*)
Print["Begin at: ", DateString[]];
$Epilog := (
Print["End at: ", DateString[]];
Print["Elapsed Time: ", SessionTime[]];
Print["CPU Time: ", TimeUsed[]];
);
@tueda
tueda / commit-msg-check.sh
Last active August 12, 2016 09:29
A git hook warning too long lines in commit messages, not fitting with 50/72 formatting.
#!/bin/sh
#
# A (client-side) git hook script which warns if there are too long lines in
# the commit message, not fitting with 50/72 formatting.
#
# To use this script, copy it as .git/hooks/commit-msg and give it an executable
# file permission.
#
FILE=$1
@tueda
tueda / is_text.sh
Created December 1, 2013 13:51
Checks if $1 is a text file.
# Checks if $1 is a text file.
is_text() {
file "$1" | grep text >/dev/null
}
@tueda
tueda / gist+x.sh
Last active May 23, 2020 12:37
A script to give executable file permissions to files in a Gist.
#! /bin/sh
#
# @file gist+x.sh
#
# Gives executable file permissions to files in a Gist.
#
set -e
prog=`basename "$0"`
# Command line options.
@tueda
tueda / rstrip.sh
Created December 1, 2013 22:29
A script to remove trailing whitespace from text files.
#! /bin/sh
#
# @file rstrip.sh
#
# Removes trailing whitespace from text files.
#
# Example:
# rstrip.sh *.c
# rstrip.sh -r . # all files in the current directory
#
@tueda
tueda / EnsurePath.m
Created December 3, 2013 15:33
Ensures the given path is created. For Mathematica 7+.
(*
* Makes a directory tree.
*)
EnsurePath[path_String] := Module[{names, cd, p},
names = FileNameSplit[path];
cd = {};
While[Length[names] > 0,
AppendTo[cd, First[names]];
names = Rest[names];
p = FileNameJoin[cd];
@tueda
tueda / tarb
Last active April 23, 2024 02:18
A script for creating tarballs. #bin #sh
#!/bin/bash
#
# @file tarb
#
# Creates a tarball of the current directory.
#
# Examples:
# $ cd tarb-test
# $ tarb # create ../tarb-test.tar.gz
# $ tarb -j # create ../tarb-test.tar.bz2
@tueda
tueda / test-InternalSeries.m
Last active August 29, 2015 13:55
An experiment on System`Private`InternalSeries in Mathematica v5.1+.
(*
* Tested in v5.1, v5.2, v6.0.3, v7.0.1, v8.0.4 and v9.0.1.
* It is said that Wolfram changed the way how Series works between v5.0 and
* v5.1, but I don't have any working binaries of <= v5.0 for now.
*)
ExplicitFunc[x_] := 1/x^3 Log[1-x];
Series[ExplicitFunc[x], {x, 0, 3}] // Print;
Series[Log[1-x] ExplicitFunc[x], {x, 0, 3}] // Print;
@tueda
tueda / fun-SplitDigits.m
Created February 1, 2014 22:47
1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256...
(* https://news.ycombinator.com/item?id=7144616 *)
SplitDigits[x_, n_, m_] := Module[{a},
a = RealDigits[FractionalPart[N[x, n + 1]]];
a = Join[ConstantArray[0, -a[[2]]], a[[1]]];
a = Drop[a, -1];
a = ToString /@ a;
a = Partition[a, m];
a = (StringJoin @@ # &) /@ a;
a = ToExpression /@ a;