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 / Unflatten.m
Created Oct 6, 2015
Creating nested structure from flat, for Mathematica expressions
View Unflatten.m
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 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 / 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 / GithubGistClient.m
Created Dec 12, 2012
A Mathematica client for Github gists
View GithubGistClient.m
(* 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 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 / 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 / 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;
@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 / 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]];
You can’t perform that action at this time.