Skip to content

Instantly share code, notes, and snippets.

Leonid Shifrin lshifr

Block or report user

Report or block lshifr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View CommonSubexpressionEliminator.m
ClearAll[csub];
csub[expr_Hold, rules_List, limitCount_] :=
With[{newrule =
Replace[If[# =!= {} && #[[-1, -1]] > 1, #[[-1, 1]], {}] &@
SortBy[Tally[
Cases[expr,
x_ /; Depth[Unevaluated[x]] > 2 &&
LeafCount[Unevaluated[x]] > limitCount :> Hold[x],
Infinity]], Last],
Hold[x_] :> (HoldPattern[x] -> Unique[])]},
@lshifr
lshifr / debug.m
Created Mar 26, 2015
Simple debugging utility for Mathematica programs
View debug.m
ClearAll[openerDress];
SetAttributes[openerDress, HoldAll];
openerDress[f_[args___]]:=
OpenerView[{
HoldForm[f],
HoldForm[f]@@Map[openerDress,Unevaluated[{args}]]
}];
openerDress[x_]:=HoldForm[x];
ClearAll[stackPrettify];
@lshifr
lshifr / CellTimeTrack.m
Last active Aug 29, 2015
Tracking cell execution time in Mathematica
View CellTimeTrack.m
BeginPackage["CellTimeTrack`"]
CellTimeTrack::usage = "CellTimeTrack[True|False] switches on or off the cell time-tracking mode";
Begin["`Private`"]
$style = Function[
arg,
StyleBox[arg, FontSize -> 16, FontWeight -> Bold, FontColor -> Darker[Green, 0.5]]
];
@lshifr
lshifr / filemodtime.c
Created Jun 19, 2015
List file modification times
View filemodtime.c
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
@lshifr
lshifr / AutoRenamings
Created Jan 26, 2012
A tiny framework to cure the leaks of lexical scoping in Mathematica
View AutoRenamings
ClearAll[getPatternSymbols, getDeclaredSymbols];
SetAttributes[{getPatternSymbols, getDeclaredSymbols}, HoldAll];
getPatternSymbols[expr_] :=
Cases[Unevaluated[expr],
Verbatim[Pattern][ss_, _] :> HoldComplete[ss], {0, Infinity},
Heads -> True];
getDeclaredSymbols[{decs___}] :=
Thread@Replace[HoldComplete[{decs}],
HoldPattern[a_ = rhs_] :> a, {2}];
@lshifr
lshifr / CodeHighligherGenerator.m
Created Feb 4, 2012
Code highligher generator
View CodeHighligherGenerator.m
(* Mathematica Package *)
(* Created by the Wolfram Workbench 05.01.2012 *)
BeginPackage["CodeHighlighterGenerator`"]
(* Exported symbols added here with SymbolName::usage *)
HighlighterLocation;
HighlighterPackageName;
@lshifr
lshifr / FunctionVersionInfo.m
Created Feb 20, 2012
Version information for Mathematica system functions
View FunctionVersionInfo.m
{"AbelianGroup" -> {"8"}, "AbortKernels" -> {"7"}, "Abort" -> {"2"},
"AbortProtect" -> {"2"}, "Abs" -> {"1"},
"AbsoluteCurrentValue" -> {"6"}, "AbsoluteDashing" -> {{"2", "6"}},
"AbsoluteFileName" -> {"7"}, "AbsoluteOptions" -> {"4"},
"AbsolutePointSize" -> {{"2", "6"}},
"AbsoluteThickness" -> {{"2", "6"}}, "AbsoluteTime" -> {{"2", "6"}},
"AbsoluteTiming" -> {"5"}, "AccountingForm" -> {"2"},
"Accumulate" -> {{"6", "7"}}, "AccuracyGoal" -> {{"1", "5"}},
"Accuracy" -> {{"1", "5"}}, "ActionMenu" -> {{"6", "8"}},
"Active" -> {"3"}, "ActiveStyle" -> {"7"}, "AcyclicGraphQ" -> {"8"},
@lshifr
lshifr / largeData.m
Created May 14, 2012
Large data framework
View largeData.m
ClearAll[$fileNameFunction,fileName, $importFunction,import, $exportFunction,
export, $compressFunction, $uncompressFunction]
$fileNameFunction = fileName;
$importFunction = import;
$exportFunction = export;
$compressFunction = Compress;
$uncompressFunction = Uncompress;
@lshifr
lshifr / GuideLinks.m
Created Jul 19, 2012
Graph rules for Mathematica documentation guides dependencies
View GuideLinks.m
@lshifr
lshifr / Readme.md
Created Nov 17, 2012
Correcting the prevoius commit using the API
View Readme.md

##CodeFormatter.m

###Formatting Mathematica code

CodeFormatter.m is a pretty-printer / code formatter for code written in the Mathematica language, which is also written in Mathematica. It works on the box level at the moment. The direct support for strings has not yet been implemented, but one can always convert code to boxes and use it then. Only a few boxes are currently supported, but

You can’t perform that action at this time.