Skip to content

Instantly share code, notes, and snippets.

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 March 26, 2015 18:37
Simple debugging utility for Mathematica programs
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 August 29, 2015 14:17
Tracking cell execution time in Mathematica
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 June 19, 2015 15:41
List file modification times
#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 / CodeHighligherGenerator.m
Created February 4, 2012 20:12
Code highligher generator
(* 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 February 20, 2012 13:01
Version information for Mathematica system functions
{"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 19:55
Large data framework
ClearAll[$fileNameFunction,fileName, $importFunction,import, $exportFunction,
export, $compressFunction, $uncompressFunction]
$fileNameFunction = fileName;
$importFunction = import;
$exportFunction = export;
$compressFunction = Compress;
$uncompressFunction = Uncompress;
@lshifr
lshifr / GuideLinks.m
Created July 19, 2012 23:07
Graph rules for Mathematica documentation guides dependencies
@lshifr
lshifr / Readme.md
Created November 17, 2012 16:31
Correcting the prevoius commit using the API

##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

@lshifr
lshifr / cover_flow.nb
Created November 19, 2012 11:50 — forked from greggroth/cover_flow.nb
Mathematica:coverflow
pic = Import["ExampleData/rose.gif"];
Module[{width = 28, layers = 6, offset, highlight, slides, img,
data},
offset[x_, slide_] := 15/(1 + Exp[-(x - slide) 3]);
highlight[x_, slide_] :=
0.85 PDF[NormalDistribution[slide, 1], x]/
PDF[NormalDistribution[slide, 1], slide] + 0.15;
img = Table[pic, {n, 1, layers}];
Manipulate[Graphics3D[{
Table[{