Skip to content

Instantly share code, notes, and snippets.

@lshifr
lshifr / AutoRenamings
Created January 26, 2012 16:04
A tiny framework to cure the leaks of lexical scoping in Mathematica
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 / LazyTuples.m
Last active March 1, 2021 23:39
A new version of lazy Tuples extension for Streaming framework
BeginPackage["LazyTuples`"]
LazyTuples::usage = "LazyTuples[lists, opts] create a LazyList of the specified chunk size (\"ChunkSize\" option), containing tuples of the original lists";
TuplesFunction::usage =
"TuplesFunction[lists][parts: _Integer | {__Integer} | _Span] generates a tuple or a set of tuples \
found at specific positions indicated, in the full list of tuples, as given by Tuples";
Begin["`Private`"]
@lshifr
lshifr / LazyListSelect.m
Created March 1, 2021 20:10
A version of LazyListSelect, which would allow per-chunk selector
ClearAll[LazyListSelect];
LazyListSelect[l:Streaming`LazyList`$PLazyList, crit_, fullSelect_:None]:=
Module[{selFun, chunkSizeF, mappedF, result, id = Streaming`Common`StreamingUUID[]},
selFun = If[fullSelect =!= None && crit === None,
fullSelect,
Function[chunkData, Select[chunkData, crit]]
];
chunkSizeF =
Function[index,
With[{chunk = Streaming`Components`RandomAccessList`ListPart[Streaming`LazyList`LazyListData[result], index]},
@lshifr
lshifr / LICENSE
Created December 12, 2012 08:35
Simple object-oriented extension for Mathematica
Copyright (c) 2012 Leonid Shifrin
This project is licensed under the MIT license,
http://opensource.org/licenses/MIT
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
@lshifr
lshifr / Unflatten.m
Created October 6, 2015 22:22
Creating nested structure from flat, for Mathematica expressions
BeginPackage["Unflatten`"]
Unflatten::usage = "Unflatten[h[elems], posints, heads] creates a nested structure by wrapping
the elements in positions intervals posints in heads heads";
UnflattenNested::usage = "UnflattenNested[expr, {startposlist, endposlist}, head] wraps elements
of expr at positions starting at startposlist_i and ending at endposlist_i in head head";
Begin["`Private`"]
@lshifr
lshifr / LazyTuples.m
Last active November 3, 2017 13:06
Implementation of lazy tuple list, for Streaming framework
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 / RegistrationForm.py
Created August 18, 2017 18:53
Sample Django registration form
class RegistrationForm(forms.Form):
username = forms.CharField(
label='Имя пользователя',
max_length=30,
widget=forms.TextInput(attrs={'class':'uname-reg'}))
email = forms.EmailField(
label='Email',
widget=forms.EmailInput( attrs={'class' : 'email-reg'})
)
password1 = forms.CharField(
@lshifr
lshifr / GithubGistClient.m
Created December 12, 2012 11:23
A Mathematica client for Github gists
(* Mathematica Package *)
BeginPackage["GithubGistClient`"]
(* Exported symbols added here with SymbolName::usage *)
(* TODO:
1. Make this OO
2. Get rid of curl
@lshifr
lshifr / SimpleJavaReloader.m
Created November 4, 2013 19:25
A package to enable compiling Java classes from within Mathematica
(* ::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 / SQLFormatter.m
Created April 7, 2017 16:33
Simple SQL formatter / highlighter, for Mathematica
$sqlKeywords = {
"ABSOLUTE","ACTION","ADD","AFTER","ALL","ALLOCATE","ALTER","AND","ANY","ARE","ARRAY","AS",
"ASC","ASENSITIVE","ASSERTION","ASYMMETRIC","AT","ATOMIC","AUTHORIZATION","AVG","BEFORE",
"BEGIN","BETWEEN","BIGINT","BINARY","BIT","BIT_LENGTH","BLOB","BOOLEAN","BOTH","BREADTH",
"BY","CALL","CALLED","CASCADE","CASCADED","CASE","CAST","CATALOG","CHAR","CHARACTER",
"CHARACTER_LENGTH","CHAR_LENGTH","CHECK","CLOB","CLOSE","COALESCE","COLLATE","COLLATION",
"COLUMN","COMMIT","CONDITION","CONNECT","CONNECTION","CONSTRAINT","CONSTRAINTS","CONSTRUCTOR",
"CONTAINS","CONTINUE","CONVERT","CORRESPONDING","COUNT","CREATE","CROSS","CUBE","CURRENT",
"CURRENT_DATE","CURRENT_DEFAULT_TRANSFORM_GROUP","CURRENT_PATH","CURRENT_ROLE","CURRENT_TIME",
"CURRENT_TIMESTAMP","CURRENT_TRANSFORM_GROUP_FOR_TYPE","CURRENT_USER","CURSOR","CYCLE","DATA",