file ITT We minify various code snippets

  • HiGuy
  • HiGuy's Avatar Topic Author
  • Offline
  • Administrator
  • Administrator
  • At college, may not be around
More
05 Nov 2012 04:33 #1 by HiGuy
HiGuy created the topic: ITT We minify various code snippets
Link to minifier:

Mac Tested: cl.ly/3O1O2k3p420h

I'll start.
Here's a fun script from my projects folder:

Code:function minifyScript(%a,%b){%c=getRealTime();%d=true;%e=true;%f=true;%g=true;%h=true;%i=true;%j=false;for(%k=0;%k<strlen(%b);%k+ +){%l=getSubStr(%b,%k,1);switch$(%l){case n:%d=false;case l:%e=false;case s:%f=false;case c:%g=false;case i:%h=false;case h:%i=false;case t:%j=true;case m:setModPaths($modPath);}}if(!%g)%d=false;%m=new FileObject();if(!%m.openForRead(%a)){%m.close();%m.delete();error(Could not read!);return;}%n=;%o=0;%p=0;while(!%m.isEOF()){%q=%m.readLine();%o++;%p+=strlen(%q);if(%h)%q=trim(%q);%n=%n NL%q;}%m.close();%m.delete();if(%j)echo(Read script!);resetCanvas();if(%g){%r=;%s=0;%t=0;for(%k=0;%k<getFieldCount(%n);%k++){%q=getField(%n,%k);if(%j){echo(Comme nts for line SPC%k SPC%q);resetCanvas();}%u=false;%v=false;for(%w=0;%w<strpos(%q,//);%w++){if(%w!=0)%x=getSubStr(%q,%w-1,1);%y=getSubStr( %q,%w,1);%z=getSubStr(%q,%w+1,1);if(%y$=\'&&!%v){if(!%u)%u=true;else if(countbackslash(%q,%w))%u=false;}if(%y$=\&&!%u){if(!%v)%v=true;else if(countbackslash(%q,%w))%v=false;}}if(%j)echo(Minify: DQ: SPC%v SPC Q: SPC%u);if(!%v&&!%u){if(strPos(%q,//)!=-1)%q=getSubStr(%q,0,strPos(%q,//));}if(%j){echo(Minify: Final: SPC%q);resetCanvas();}if(%q!$=){%r=%r NL%q;%s++;%t+=strlen(%q);}}%n=%r;}if(%e){%n=minifyLocals(%n,%j);}if(%f){%r=;%s=0;%t=0;for(%k=0;%k<getFieldCount(%n);%k ++){%q=getField(%n,%k);if(%j){echo(Spaces for line SPC%k SPC%q);resetCanvas();}%q=nilAll(%q, ,@;=(){}$!%+-/*[]<>:|&);if(%q!$=){%r=%r NL%q;%s++;%t+=strlen(%q);}}%r=getSubStr(%r,1,strlen(%r)-1);%n=%r;}if(%d){%r=;%s=0;%t=0;for(%k=0;%k<getFieldCount(%n);% k++){%q=getField(%n,%k);if(%j){echo(Newlines for line SPC%k SPC%q);resetCanvas();}%q=strreplace(%q,\r,);%q=strreplace(%q,\n,);if(%q!$=){%r=%r SPC%q;%s++;%t+=strlen(%q);}}%r=strreplace(%r,\r\n,);%r=strreplace(%r,\r,);%r=strreplace(%r,\n,);%r=nilAll(%r , ,@;=(){}$!%+-/*[]<>:|&,%j);%n=%r;}%ab=filePath(%a)@/@fileBase(%a)@_min@fileExt(%a);%bb=strlen(%n);if(%i){%n=//

NL // Original file: SPC fileBase(%a)@fileExt(%a)NL // Script minified by Minifier 1.0 by HiGuy NL // NL // Minification Stats: NL // Script minified in SPC(getRealTime()-%c)/1000 SPC seconds NL // Script shrunken from SPC%p SPC characters to SPC%bb SPC characters NL //
\n NL%n;}%cb=new FileObject();if(!%cb.openForWrite(%ab)){%cb.close();%cb.delete();error(Could not write!);return;}%cb.writeLine(%n);%cb.close();%cb.delete();echo(Shrank SPC fileBase(%a)@fileExt(%a)SPC from SPC%o SPC lines to SPC%s SPC lines.);}function getMinName(%db){%eb=abcdefghjilkmnopqrstuvwxyz;%fb=;while(true){%gb=%db%26;%fb=getSubStr(%eb,%gb,1)@%fb;%db-=%gb;%db /=26;if(%db==0)return%fb;}}function minifyLocals(%n,%j){%hb=0;%ib=0;%jb=;for(%k=0;%k<getFieldCount(%n);%k++){%q=getField(%n,%k);%kb=0;while((%lb=strPos(%q ,%,%kb))!=-1){%mb=getSubStr(%q,%lb,strlen(%q));%kb=%lb+1;%nb=firstPos(%mb, ,./?;\\'[]{}\\|-=+()*&%$#@!,1);%ob=getSubStr(%mb,0,%nb);if(%ob!$=%){if(%pb[%ob]$=){%pb[%ob]=%@getMinName(%hb);if(%j){echo(New Local: SPC%ob SPC%pb[%ob]);resetCanvas();}%hb++;}else{if(%j){echo(Old Local: SPC%ob SPC%pb[%ob]);resetCanvas();}}%qb=strlen(%q);%q=getSubStr(%q,0,%lb)@%pb[%ob]@getSubStr(%q,%nb+%lb,strlen(%q));%ib++;}}%jb=%jb NL%q;}return%jb;}function firstPos(%eb,%p,%rb){%sb=strlen(%eb);for(%k=0;%k<strlen(%p);%k++){%tb=getSubStr(%p,%k,1);%gb=strPos(%eb,%tb,%rb);if(%gb= =-1)continue;if(%gb<%sb)%sb=%gb;}return%sb;}function nilAll(%q,%ub,%j){for(%k=0;%k<strLen(%ub);%k++){%vb[getSubStr(%ub,%k,1)]=true;}%u=false;%v=false;for(%k=0;%k<strlen(%q);%k++){if(%j){if(%k%300==0){echo(Nilling loop SPC%k);resetCanvas();}}if(%k!=0)%x=getSubStr(%q,%k-1,1);%y=getSubStr(%q,%k,1);%z=getSubStr(%q,%k+1,1);if(!%u&&!%v&&%y!$= \'&&%y!$=\&&%vb[%y]){if(%x$= ){%q=getSubStr(%q,0,%k-1)@getSubStr(%q,%k,strLen(%q));%k--;}if(%z$= ){%q=getSubStr(%q,0,%k+1)@getSubStr(%q,%k+2,strLen(%q));%k--;}}if(%y$=\'&&!%v){if(!%u){%u=true;if(%x$= &&%vb[%y]){%q=getSubStr(%q,0,%k-1)@getSubStr(%q,%k,strLen(%q));%k--;}}else{if(countbackslash(%q,%k)){%u=false;if(%z$= &&%vb[%y]){%q=getSubStr(%q,0,%k+1)@getSubStr(%q,%k+2,strLen(%q));%k--;}}}}if(%y$=\&&!%u){if(!%v){%v=true;if(%x$= &&%vb[%y]){%q=getSubStr(%q,0,%k-1)@getSubStr(%q,%k,strLen(%q));%k--;}}else{if(countbackslash(%q,%k)){%v=false;if(%z$= &&%vb[%y]){%q=getSubStr(%q,0,%k+1)@getSubStr(%q,%k+2,strLen(%q));%k--;}}}}}return%q;}function countbackslash(%q,%k){if(%k!=0)%x=getSubStr(%q,%k-1,1);%y=getSubStr(%q,%k,1);%z=getSubStr(%q,%k+1,1);if(%x!$=\\)return true;%wb=1;%k--;while(getSubStr(%q,%k-1,1)$=\\&&%k>0){%wb++;%k--;}return!(%wb%2);}


Props to whoever guesses this one

PQ in a nutshell
function clientcmd12dothepq() {
    commandToClient(LocalClientConnection, '34onthedancefloor');
}

Please Log in or Create an account to join the conversation.

  • Jeff
  • Jeff's Avatar
  • Offline
  • Developer
  • Developer
  • PlatinumQuest Programmer
More
05 Nov 2012 04:37 #2 by Jeff
Jeff replied the topic: ITT We minify various code snippets
Its the minified code of the minifier in torqueScript. I win.

I am a programmer. Most here know me for being one of the major contributors to Marble Blast Platinum and PlatinumQuest.

Please Log in or Create an account to join the conversation.

Moderators: Kalle29AayrlRegislian