My Developer Tools: Tricks of the Trade
Author
Brett Champion
Title
My Developer Tools: Tricks of the Trade
Description
My Developer Tools Livestream Notebook
Category
Essays, Posts & Presentations
Keywords
developer tools
URL
http://www.notebookarchive.org/2023-01-8bvy8rp/
DOI
https://notebookarchive.org/2023-01-8bvy8rp
Date Added
2023-01-18
Date Last Modified
2023-01-18
File Size
2.42 megabytes
Supplements
Rights
Redistribution rights reserved
Download
Open in Wolfram Cloud
My Developer Tools: Tricks of the Trade
My Developer Tools: Tricks of the Trade
Brett Champion
Misc
Misc
◼
VS Code with Wolfram Language Extensions
◼
Ability to run old versions
Everything Lives in a Package
Everything Lives in a Package
◼
Autoloaded at launch
◼
Includes Frontend Preferences
◼
Package lives in Version Control (CVS from Feb 25, 2010, git since Nov 3, 2014.)
Kernel Customizations
Kernel Customizations
WireTap
WireTap
WireTap::"usage"="WireTap[symbol] prints out the input and output for symbol[args]."WireTap[sym_] := With[{flag = ToExpression["$WireTap`"<>SymbolName[sym]]}, Unprotect[sym]; sym[args__] /; flag =!= True := Block[{r, flag = True}, Print[">>> ", sym, " sym >>> ", HoldForm[sym[args]]]; r = sym[args]; Print["<<< ", sym, " <<< ", r]; r ]; DownValues[sym] = RotateRight[DownValues[sym]]; sym] WireTap[] := Names["$WireTap`*"]
In[]:=
FeatureSpacePlot[RandomColor[20]]
Out[]=
In[]:=
WireTap[ListPlot];
In[]:=
FeatureSpacePlot[RandomColor[20]]
>>> ListPlot sym >>> ListPlot{-19.4003,-29.4358},{39.4074,-14.4652},{-7.30055,62.3581},{44.7852,-27.8755},{-23.4511,-12.5657},{30.9195,-37.9712},{-31.4894,13.8848},{-38.6497,31.4946},{-13.6991,-58.1852},{-8.41161,-34.6692},{-22.7236,28.9083},{-43.7833,18.4906},{28.0773,-24.1244},{-13.4665,75.3338},{7.9977,-40.1584},{-29.3484,49.7602},{66.6852,-5.74812},{-1.16327,-60.6056},{58.7337,2.80088},{-23.7191,62.773},AspectRatio1,AxesFalse,FrameFalse,GridLinesStyleDirective,LabelingFunctionFunction{System`FeatureSpacePlotDump`x$,System`FeatureSpacePlotDump`y$,System`FeatureSpacePlotDump`z$},WithSystem`FeatureSpacePlotDump`odata$=,,,,,,,,,,,,,,,,,,,Last[System`FeatureSpacePlotDump`y$],System`FeatureSpacePlotDump`origmeta$={{},{},Charting`padList[{{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}}〚Last[System`FeatureSpacePlotDump`y$]〛]},(Which[!System`FeatureSpacePlotDump`renderable,Placed[#1,Tooltip],#3〚-1〛=!={},Callout[#3〚-1,1〛,Center,BackgroundOpacity[0]],True,Callout[#1,Center,BackgroundOpacity[0]]]&)[System`FeatureSpacePlotDump`odata$,System`FeatureSpacePlotDump`y$,System`FeatureSpacePlotDump`origmeta$],MethodAxisPaddingScaled[0.02],DefaultBoundaryStyleAutomatic,DefaultGraphicsInteraction{Version1.2,TrackMousePosition{True,False},Effects{Highlight{ratio2},HighlightPoint{ratio2},Droplines{freeformCursorModeTrue,placement{xAll,yNone}}}},DefaultMeshStyleAbsolutePointSize[6],DefaultPlotStyleDirective,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],Directive,AbsoluteThickness[1.6],DomainPaddingScaled[0.02],PointSizeFunctionSmallPointSize,RangePaddingScaled[0.05],PerformanceGoalQuality,PlotLegendsExpressions,PlotRangeAll,PlotRangeClippingFalse,PlotRangePaddingScaled[0.05],PlotStyleNone
<<< ListPlot <<<
Out[]=
TimingTrap
TimingTrap
TimingTrap::"usage"="TimingTrap[symbol] prints out the time used during each call to symbol[args]."TimingTrap[sym_] := With[{flag = ToExpression["$TimingTrap`"<>SymbolName[sym]]}, Unprotect[sym]; sym[args__] /; flag =!= True := Block[{t, r, flag = True}, {t, r} = AbsoluteTiming[sym[args]]; Print[sym -> t]; r ]; DownValues[sym] = RotateRight[DownValues[sym]]; sym] TimingTrap[] := Names["$TimingTrap`*"]
In[]:=
Quit
In[]:=
FeatureSpacePlot[RandomColor[100]]
Out[]=
In[]:=
TimingTrap[DimensionReduce];
In[]:=
FeatureSpacePlot[RandomColor[100]]
DimensionReduce0.553419
Out[]=
OptionNames
OptionNames
OptionNames::usage = "OptionNames[f] gives the list of all the option names for f. OptionNames[f, pat] gives all option names that match pat."
Options[OptionNames] = Options[StringMatchQ];
OptionNames[f_, o:OptionsPattern[]] := Map[First, Options[f]]
OptionNames[f_, pat_, o:OptionsPattern[]] := Select[OptionNames[f], StringMatchQ[ToString[#], pat, o]& ]
Options[OptionNames] = Options[StringMatchQ];
OptionNames[f_, o:OptionsPattern[]] := Map[First, Options[f]]
OptionNames[f_, pat_, o:OptionsPattern[]] := Select[OptionNames[f], StringMatchQ[ToString[#], pat, o]& ]
In[]:=
OptionNames[Plot]
Out[]=
{AlignmentPoint,AspectRatio,Axes,AxesLabel,AxesOrigin,AxesStyle,Background,BaselinePosition,BaseStyle,ClippingStyle,ColorFunction,ColorFunctionScaling,ColorOutput,ContentSelectable,CoordinatesToolOptions,DisplayFunction,Epilog,Evaluated,EvaluationMonitor,Exclusions,ExclusionsStyle,Filling,FillingStyle,FormatType,Frame,FrameLabel,FrameStyle,FrameTicks,FrameTicksStyle,GridLines,GridLinesStyle,ImageMargins,ImagePadding,ImageSize,ImageSizeRaw,LabelingSize,LabelStyle,MaxRecursion,Mesh,MeshFunctions,MeshShading,MeshStyle,Method,PerformanceGoal,PlotLabel,PlotLabels,PlotLayout,PlotLegends,PlotPoints,PlotRange,PlotRangeClipping,PlotRangePadding,PlotRegion,PlotStyle,PlotTheme,PreserveImageOptions,Prolog,RegionFunction,RotateLabel,ScalingFunctions,TargetUnits,Ticks,TicksStyle,WorkingPrecision}
In[]:=
OptionNames[Plot,"Image*"]
Out[]=
{ImageMargins,ImagePadding,ImageSize,ImageSizeRaw}
PropertyNames
PropertyNames
PropertyNames::usage = "PropertyNames[obj] gives the list of all the property names for obj. PropertyNames[obj, pat] gives all property names that match pat."Options[PropertyNames] = Options[StringMatchQ];PropertyNames[obj_, o:OptionsPattern[]] := obj["Properties"]PropertyNames[obj_, pat_, o:OptionsPattern[]] := Select[ PropertyNames[obj], StringMatchQ[CanonicalName[#], pat, o] || StringMatchQ[CommonName[#], pat, o]& ]
In[]:=
PropertyNames,"*GDP*"
Out[]=
,,,,,,,,
discrepancy in expenditure estimate of GDP
expenditure per student fraction of GDP per capita
GDP
GDP deflator
GDP per employed person
GDP
potential GDP
PPP conversion factor gdp
GDP value added
In[]:=
PropertyNames,"*gross*",IgnoreCase->True
Out[]=
,,,,,,,,,,,,,,,
gross national income
government consumption expenditures and gross investment
gross capital formation
gross domestic income
GDP
Gross Domestic Purchases
gross domestic savings
gross fixed capital formation
gross national expenditure
gross national expenditure deflator
GNP
gross savings
GSP
gross value added at factor cost
merchant ships gross
potential GDP
In[]:=
CanonicalName,CommonName
GDP
GDP
Out[]=
{GrossDomesticProduct,GDP}
SkeletonForm
SkeletonForm
SkeletonForm::usage = "SkeletonForm[expr] represents expr in a way that is sometimes useful for seeing its structure."sl[a_] := "<" <> ToString[Length[a]] <> ">"dp[dbg_, str_] := If[dbg, Print[str]]dirQ[x_] := MemberQ[{Hue,RGBColor,GrayLevel,Thickness,PointSize,EdgeForm,FaceForm}, Head[x]]Attributes[SkeletonForm] = HoldAll;SkeletonForm[expr_, dbg_:False] := InputForm[expr //. { h_[a_Integer] :> h[a], h_[a__Integer] :> h["Integer" <> sl[{a}]], h_[a_Real] :> h[a], h_[a__Real] :> h["Real" <> sl[{a}]], h_[a_?OptionQ] :> h[a], h_[a__?OptionQ] :> h["Option" <> sl[{a}]], h_[a_Complex] :> h[a], h_[a__Complex] :> h["Complex" <> sl[{a}]], h_[a_GrayLevel] :> h[a], h_[a__GrayLevel] :> h["GrayLevel" <> sl[{a}]], h_[a_RGBColor] :> h[a], h_[a__RGBColor] :> h["RGBColor" <> sl[{a}]], h_[a_Hue] :> h[a], h_[a__Hue] :> h["Hue" <> sl[{a}]], h_[a_?NumberQ] :> h[a], h_[a__?NumberQ] :> h["NumberQ" <> sl[{a}]], h_[a_?NumericQ] :> h[a], h_[a__?NumericQ] :> h["NumericQ" <> sl[{a}]], h_[a_Image] :> h["Image<"<>StringRiffle[ImageDimensions[a], "><"]<>">"], h_[d_?dirQ, a__Line]:> h[d, "Line" <> sl[{a}]], h_[d_?dirQ, a__Polygon]:> h[d, "Polygon" <> sl[{a}]], h_[a__ /; (Length[{a}] > 1 && Length[Union[{a}]] == 1)] :> h[First[{a}], sl[{a}]], {{s1_String}, s2_String} /; (StringMatchQ[s1, "*>"] && StringMatchQ[s2, "<*"]) :> {s1 <> s2} }]
In[]:=
SkeletonForm[Plot[Sin[x],{x,0,10}]]
Out[]//InputForm=
Graphics[
{{{{}, {}, Annotation[
{Directive[Opacity[1.], RGBColor[
Real<3>], AbsoluteThickness[1.6]],
Line[{Real<2><565>}]},
Charting`Private`Tag$30705#1]}}, {}},
{Option<25>}]
{{{{}, {}, Annotation[
{Directive[Opacity[1.], RGBColor[
Real<3>], AbsoluteThickness[1.6]],
Line[{Real<2><565>}]},
Charting`Private`Tag$30705#1]}}, {}},
{Option<25>}]
In[]:=
ResourceFunction["ShortInputForm"][Plot[Sin[x],{x,0,10}]]
Out[]=
GraphicsAnnotationDirectiveOpacity[1.],,AbsoluteThickness[1.6],Line[{{2.04×,2.04×},,Axes{True,True},AxesLabel{None,None},AxesOrigin{0,0},DisplayFunctionIdentity,Frame{{False,False},{False,False}},FrameLabel{{None,None},{None,None}},FrameTicks{{Automatic,Automatic},{Automatic,Automatic}},GridLines{None,None},GridLinesStyleDirective,ImagePaddingAll,Method{"DefaultBoundaryStyle"Automatic,"DefaultGraphicsInteraction"{"Version"1.2,"TrackMousePosition"{True,False},"Effects"{"Highlight"{"ratio"2},"HighlightPoint"{"ratio"2},"Droplines"{"freeformCursorMode"True,"placement"{"x""All","y""None"}}}},"DefaultMeshStyle"AbsolutePointSize[6],"ScalingFunctions"None,"CoordinatesToolOptions"{"DisplayFunction"(DeleteCases[{(Identity[#1]&)[Part[#1,1]],(Identity[#1]&)[Part[#1,2]]},{}]&),"CopiedValueFunction"(DeleteCases[{(Identity[#1]&)[Part[#1,1]],(Identity[#1]&)[Part[#1,2]]},{}]&)}},PlotRange{{0,10},{-1.,1.}},PlotRangeClippingTrue,PlotRangePadding{{Scaled[0.02],Scaled[0.02]},{Scaled[0.05],Scaled[0.05]}},Ticks{Automatic,Automatic}
-7
10
-7
10
564
}],"Charting`Private`Tag$32522#1",AspectRatio1
GoldenRatio
In[]:=
ResourceFunction["IconizedView"][Plot[Sin[x],{x,0,10}]]
Out[]=
Graphics{},{},DirectiveOpacity[1.],,AbsoluteThickness[1.6],Line
,{},DisplayFunctionIdentity,Ticks{Automatic,Automatic},AxesOrigin{0,0},FrameTicks{{Automatic,Automatic},{Automatic,Automatic}},GridLines{None,None},DisplayFunctionIdentity,PlotRangePadding{{Scaled[0.02],Scaled[0.02]},{Scaled[0.05],Scaled[0.05]}},PlotRangeClippingTrue,ImagePaddingAll,DisplayFunctionIdentity,AspectRatio,Axes{True,True},AxesLabel{None,None},AxesOrigin{0,0},DisplayFunctionIdentity,Frame{{False,False},{False,False}},FrameLabel{{None,None},{None,None}},FrameTicks{{Automatic,Automatic},{Automatic,Automatic}},GridLines{None,None},GridLinesStyleDirective,Method{DefaultBoundaryStyleAutomatic,DefaultGraphicsInteraction{Version1.2,TrackMousePosition{True,False},Effects{Highlight{ratio2},HighlightPoint{ratio2},Droplines{freeformCursorModeTrue,placement{xAll,yNone}}}},DefaultMeshStyleAbsolutePointSize[6],ScalingFunctionsNone,CoordinatesToolOptions{DisplayFunction({(Identity[#1]&)[#1〚1〛],(Identity[#1]&)[#1〚2〛]}&),CopiedValueFunction({(Identity[#1]&)[#1〚1〛],(Identity[#1]&)[#1〚2〛]}&)}},PlotRange{{0,10},{-0.999999,1.}},PlotRangeClippingTrue,PlotRangePadding{{Scaled[0.02],Scaled[0.02]},{Scaled[0.02],Scaled[0.02]}},Ticks{Automatic,Automatic}
{565, 2} matrix |
1
GoldenRatio
DocSource
DocSource
DocSource[s_Symbol] := DocSource[SymbolName[s]]DocSource[s_String] := Block[{}, NotebookOpen[ FileNameJoin[{ $RootDirectory, "Users", "brettc", "Source", "Documentation", "English", "System", "ReferencePages", "Symbols", s<>".nb" }] ]; (* no return value *) ]
In[]:=
DocSource@Plot
FullStack
FullStack
FullStack::"usage" = "FullStack[expr] evaluates expr in an environment where messages have access to the complete stack, rather than the sanitized one."
FullStack = Function[arg, Block[{MessageMenu`$PruneStack = False}, arg], HoldAll]
FullStack = Function[arg, Block[{MessageMenu`$PruneStack = False}, arg], HoldAll]
Sample Code
Sample Code
In[]:=
BeginPackage["Foo`"];
In[]:=
RandomScene::usage="RandomScene[n] creates a scene with n random tubes";
In[]:=
Begin["Foo`Private`"];
In[]:=
ClearAll["Foo`Private`*"]
In[]:=
RandomScene[n_]:=Graphics3D[randomTubes[n]]
In[]:=
randomTubes[n_]:=Table[{RandomColor[],Tube[RandomReal[1,{2,3}]]},n]
In[]:=
End[];
In[]:=
EndPackage[];
Examples
Examples
In[]:=
RandomScene[5]
In[]:=
RandomScene[5]//FullStack
OpenGL/Metal
OpenGL/Metal
OpenGL::usage = "OpenGL[expr] displays expr using the OpenGL renderer when possible."
Metal::usage = "OpenGL[expr] displays expr using the Metal renderer when possible."
OpenGL[expr_] := Style[expr, RenderingOptions -> {"3DRenderingEngine" -> "OpenGL"}]
Metal[expr_] := Style[expr, RenderingOptions -> {"3DRenderingEngine" -> "Metal"}]
Metal::usage = "OpenGL[expr] displays expr using the Metal renderer when possible."
OpenGL[expr_] := Style[expr, RenderingOptions -> {"3DRenderingEngine" -> "OpenGL"}]
Metal[expr_] := Style[expr, RenderingOptions -> {"3DRenderingEngine" -> "Metal"}]
In[]:=
scene=Graphics3D[Table[{RandomColor[],Tube[RandomReal[1,{2,3}],RandomReal[0.1]]},1000]];
In[]:=
Style[{Metal[scene],OpenGL[scene]},ImageSizeMultipliers->{1,1}]
Out[]=
,
In[]:=
Graphics`RenderTiming[scene]
Out[]=
0.046166
In[]:=
Graphics`RenderTiming[OpenGL[scene]]
Out[]=
0.108104
In[]:=
Graphics`RenderTiming[Metal[scene]]
Out[]=
0.048435
Scripts
Scripts
FrontEnd/init.m
FrontEnd/init.m
Docked Cell
Docked Cell
DockedCells -> Cell[BoxData[ GridBox[{{ ButtonBox["\"⊕\"", ButtonFunction :> SetBanner, Appearance -> None, Evaluator -> Automatic, Method -> "Preemptive"], " ", ButtonBox["\"⊗\"", ButtonFunction :> SetOptions[$FrontEndSession, DockedCells -> {}], Appearance -> None, Evaluator -> Automatic, Method -> "Preemptive"] }}]], "DockedCell", TextAlignment -> Right, CellFrameMargins -> {{3, 3}, {1, 0}}]
Evaluation Completion Action
Evaluation Completion Action
EvaluationCompletionAction -> "ShowTiming"
In[]:=
Table[PrimePi[i],{i,10^6}];
In[]:=
1+1
Out[]=
2
Autocompletion Settings
Autocompletion Settings
CodeAssistOptions -> {
"MatchingAlgorithm"->"Fuzzy"
}
"MatchingAlgorithm"->"Fuzzy"
}
◼
Get to symbols like SmoothDensityHistogram without having to type it all out
sdh
SmoDen
ShowFrameRateCounter
ShowFrameRateCounter
/18/23 11:41:00 In[45]:=
Plot3D[Sin[x]Cos[y],{x,0,10},{y,0,10}]
/18/23 11:41:00 Out[45]=
My Toolbar
My Toolbar
◼
My toolbar is specific to me. :-) Here’s code to start constructing your own:
In[]:=
CurrentValue[EvaluationNotebook[],DockedCells]=Cell[BoxData[ToBoxes[Grid[{{docButton[]}}]]],"DockedCell"]
Out[]=
CellBoxDataTagBoxGridBoxTagBoxTooltipBoxButtonBox"📕",ButtonFunctionBlock[{$CellContext`sel=NotebookRead[ButtonNotebook[]]},If[$CellContext`sel==={},$CellContext`sel=Input[Doc notebook:];If[$CellContext`sel=!=$Canceled,CreateDialog[$CellContext`sel]],CreateDialog[$CellContext`sel]]],AppearanceNone,MethodQueued,EvaluatorAutomatic,"Doc source notebook",TooltipStyleTextStyling,#1&,AutoDeleteFalse,GridBoxItemSize{Columns{{Automatic}},Rows{{Automatic}}},Grid,DockedCell
In[]:=
docButton[]:=Tooltip[Button["📕",Block[{sel=NotebookRead[ButtonNotebook[]]},If[sel==={},sel=Input["Doc notebook:"];If[sel=!=$Canceled,CreateDialog[sel]],CreateDialog[sel]]],Appearance->None,Method->"Queued"],"Doc source notebook"]
In[]:=
docButton[]
Out[]=
📕
◼
Check what NotebookRead returns for different types of selections
In[]:=
Pause[5];NotebookRead[]
Out[]=
InputForm
In[]:=
InputForm[%]
Out[]//InputForm=
Plot
◼
Check what Input returns under various circumstances
In[]:=
Input["Doc notebook:"]
Out[]=
Plot
◼
Set the toolbar to the default
In[]:=
CurrentValue[EvaluationNotebook[],DockedCells]=Inherited;
◼
This line in a Kernel init.m is what actually sets the toolbar, where setBanner constructs and sets the toolbar:
RunScheduledTask[setBanner[],{3}]
Cite this as: Brett Champion, "My Developer Tools: Tricks of the Trade" from the Notebook Archive (2023), https://notebookarchive.org/2023-01-8bvy8rp
Download