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
@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 / LazyTuples.m
Last active Nov 3, 2017
Implementation of lazy tuple list, for Streaming framework
View LazyTuples.m
BeginPackage["LazyTuples`"]
LazyTuples::usage = "LazyTuples[lists, opts] create a LazyList of the specified chunk size (\"ChunkSize\" option), containing tuples of the original lists";
Begin["`Private`"]
Needs["Streaming`"];
ClearAll[next];
next[{left_, _}, dim_] :=
@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 / 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 / SmartLet.m
Created Nov 7, 2014
Smart Let in Mathematica
View SmartLet.m
ClearAll[Let, let, symbolOrListQ, inSetDelayed];
SetAttributes[{Let, let, symbolOrListQ}, HoldAll];
symbolOrListQ[_Symbol] = True;
symbolOrListQ[{___?symbolOrListQ}] = True;
symbolOrListQ[_] = False;
Let::lvset = "Local variable specification `1` is not valid.";
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 / SimpleJavaReloader.m
Created Nov 4, 2013
A package to enable compiling Java classes from within Mathematica
View SimpleJavaReloader.m
(* ::Package:: *)
BeginPackage["SimpleJavaReloader`", {"JLink`"}];
JCompileLoad::usage =
"JCompileLoad[javacode_,addToClassPath_] attempts to compile a Java \
class defined by a string javacode, optionally adding to Java compiler classpath \
files and folders from addToClassPath, and load the resulting class into \
Mathematica";
@lshifr
lshifr / SEFormatter.m
Last active Dec 18, 2015
Code formatter palette for mathematica.stackexchange.com
View SEFormatter.m
(* Mathematica Package *)
(* :Title: SEFormatter *)
(* :Author: Leonid B. Shifrin *)
(* :Summary: Code formatting palette for mathematica.stackexchange.com
(but can be useful also for other formatting purposes) *)
(* :Context: SEFormatter` *)
@lshifr
lshifr / lincomp.c
Last active Dec 14, 2015
LinearComplexity
View lincomp.c
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
int random_in_range (unsigned int min, unsigned int max)
{
int range = max - min,
remainder = RAND_MAX % range,
bucket = RAND_MAX / range;
@lshifr
lshifr / EntireTableReader.m
Last active Dec 14, 2015
Java code for Mathematica to read entire file of floats
View EntireTableReader.m
JCompileLoad@"
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.util.Arrays;
public class EntireTableReader{
public static float[] getFloatTable(String filename, int rowByteCount, int rowChunkSize)
You can’t perform that action at this time.