Skip to content

Instantly share code, notes, and snippets.

@rdm
Created January 12, 2014 03:09
Show Gist options
  • Save rdm/8380234 to your computer and use it in GitHub Desktop.
Save rdm/8380234 to your computer and use it in GitHub Desktop.
blocks 3
max depth 2
max block 143
scripts 2
max script 51
text =: 0 : 0
@{
if (Post) {
Page.Foo = true;
} else {
if (IsLocalHost) {
Page.Foo = true;
}
Page.Foo = true;
}
}
@{
Response.Write('start');
}
<html>
<script>
alert('start');
</script>
<div id='Foo'>@Page.Foo</div>
<script>
alert($('#Foo').val());
</script>
</html>
@{
Response.Write('bye');
}
)
Chars=:'@{}</script>'
States=: (1+0,#Chars)$0
Ends=: i.0
appendToken=: 3 :0
s=. (<:States +&# y){.States
start=. 0
while. 0~:next=.(<start,Chars i.{.y){s do.
y=. }. y
start=. next
end.
n=. (#s)-i.-#y
States=: n ((start,}:n),each Chars i.y)} s
Ends=: Ends, {:n
States=: ((#Ends)#,:{.States) Ends} States,0
{:n
)
NB. these =: are for mnemonic purposes only - not used by calc2
At=: appendToken '@'
Left=: appendToken '{'
Right=: appendToken '}'
Begin=: appendToken '<script>'
End=: appendToken '</script>'
classify=: 1}.Ends i. 2 {"1(5;(States,"+0);((<"+Chars),<a.-.Chars);0 _1 0 0) ;: ]
calc2=: 3 :0
Trace=. classify y
'At Left Right Begin End'=: (i.#Ends)=/Trace
Depth0=. Left -&(+/\) Right
Brace0s=. 0 1 E. Depth0
BraceNs=. +/\ Brace0s
Codes=. At*0 1 E. Depth0
CODE=. (*Depth0) * (1+Codes) (] e. {) BraceNs
Depth=. Depth0-CODE
SCRIPT=. Begin -&(+/\) End
smoutput 'blocks ',":Left -&(+/) Codes
smoutput 'max depth ',":>./ Depth
smoutput 'max block ',":>./ Brace0s +//. *Depth
smoutput 'scripts ',":+/ Begin
smoutput 'max script ',":(>./ Begin +//. SCRIPT)-#'</script>'
)
calc2 text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment