Skip to content

Instantly share code, notes, and snippets.

@lshifr
lshifr / LazyTuples.m
Last active Mar 1, 2021
A new version of lazy Tuples extension 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";
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 Mar 1, 2021
A version of LazyListSelect, which would allow per-chunk selector
View LazyListSelect.m
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 / RegistrationForm.py
Created Aug 18, 2017
Sample Django registration form
View RegistrationForm.py
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 / SQLFormatter.m
Created Apr 7, 2017
Simple SQL formatter / highlighter, for Mathematica
View SQLFormatter.m
$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",
View InlinedCompile.m
ClearAll[symbolRules];
symbolRules[syms_List]:=
Join @@ Map[
Function[s, symbolRules @ Unevaluated @ s, HoldFirst],
Unevaluated @ syms
]
symbolRules[sym_String]:=
ToExpression[sym, InputForm, Function[s,symbolRules @ Unevaluated @ s, HoldFirst]];
symbolRules[s_Symbol]:= Join[OwnValues[s],DownValues[s], UpValues[s], SubValues[s]];
symbolRules[]:= symbolRules @ Names["Global`*"];
@lshifr
lshifr / FrozenCode.m
Created May 19, 2016
A non-standard evaluator for Mathematica code, allowing to evaluate the code in the "frozen" mode
View FrozenCode.m
BeginPackage["FrozenCode`"]
FrozenCodeEvaluate::usage = "FrozenCodeEvaluate[Hold[code], {heads}] evaluates the code
in the 'frozen' mode, where only specific heads are allowed to evaluate";
Begin["`Private`"]
ClearAll[symbolToHideQ]
SetAttributes[symbolToHideQ, HoldFirst];
symbolToHideQ[s_Symbol, expandedSymbs_] :=! MemberQ[expandedSymbs, Unevaluated[s]];
@lshifr
lshifr / ReferenceTracker.m
Created Apr 29, 2016
A Mathematica package to track which symbols may reference a given symbol
View ReferenceTracker.m
BeginPackage["ReferenceTracker`"]
TrackReferences;
Begin["`Private`"]
Clear[$globalProperties];
$globalProperties = {
OwnValues,
DownValues,
@lshifr
lshifr / HTMLParser.m
Last active Mar 9, 2016
A very simplistic breadth - first HTML parser in Wolfram Mathematica
View HTMLParser.m
BeginPackage["HTMLParser`"]
ParseHTML::usage = "ParseHTML[s] parses a string of HTML code";
HTMLContainer::usage = "HTMLContainer[tag] is an inert container for the contents of html tag";
Begin["`Private`"]
listSplit[x_List,lengthlist_List,headlist_List]:=
@lshifr
lshifr / RuleBasedFunction.m
Created Dec 22, 2015
An implementation of a function constructor that takes (possibly overloaded) function definitions using standard pattern-based syntax (where function name should be denoted as Fn), and returns a Function-based definition that is garbage-collectable
View RuleBasedFunction.m
BeginPackage["RuleBasedFunction`"]
RuleBasedFunction::usage = "RuleBasedFunction[defs, attrs] constructs a pure function based on definitions given by rules";
Fn::usage = "Fn is a symbol used to denote a function in definitions used in RuleBasedFunction";
Begin["`Private`"]
SetAttributes[CleanUp, HoldAll]
CleanUp[expr_, cleanup_] :=
@lshifr
lshifr / NewOO.m
Last active Jul 4, 2016
A new Python - inspired implementation of an object-oriented extension for Mathematica language, which enables creation of garbage-collectable objects
View NewOO.m
BeginPackage["OO`"]
new
EndPackage[]
BeginPackage["OO`Core`", "RuleBasedFunction`"]
TypeQ;
ObjectQ;