Skip to content

Instantly share code, notes, and snippets.

@joebo
Created January 11, 2014 20:35
Show Gist options
  • Save joebo/936ca5e2017c0a3b5c56 to your computer and use it in GitHub Desktop.
Save joebo/936ca5e2017c0a3b5c56 to your computer and use it in GitHub Desktop.
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');
}
)
seq=: 13 : '(# y) = +/ (x=y)'
calc =: 3 : 0
len=. (# text) -1
CODESTART=:'@{'
SCRIPT_START =. '<script>'
SCRIPT_END =. '</script>'
STATE=:0
CODE=:1
SCRIPT=:2
blocks=:0
chars=.''
depth=.0
maxDepth=:0
maxBlock=:0
scripts=:0
maxScript=:0
for_i. i.1+len do.
left=: i }. text
c=:{. left
if. (((#CODESTART) {. left) seq CODESTART) do.
STATE=:CODE
chars=.''
depth=.0
end.
if. (((#SCRIPT_START) {. left) seq SCRIPT_START) do.
STATE=:SCRIPT
chars=.''
depth=.0
end.
if. STATE = CODE do.
chars=.chars,c
depth=.depth+(c='{')-(c='}')
maxDepth=: maxDepth >. <: depth
if. (c='}') *. (depth=0) do.
blocks=:blocks+1
maxBlock=: maxBlock >. ( # chars)
NB. smoutput chars
STATE=:0
end.
end.
if. STATE = SCRIPT do.
chars=.chars,c
if. (((#SCRIPT_END) {. left) seq SCRIPT_END) do.
scripts=:scripts+1
scriptLen=: <: (# chars) - (# SCRIPT_START)
maxScript=: maxScript >. scriptLen
end.
end.
end.
smoutput 'blocks ' , ": blocks
smoutput 'max depth ' , ": maxDepth
smoutput 'max block ' , ": maxBlock
smoutput 'scripts ' , ": scripts
smoutput 'max script ' , ": maxScript
)
calc''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment