Posts

Showing posts with the label limit

About JavaScript apply arguments limit

Just a quick one from ECMAScript ml ... it is true that browsers may have a limited number of arguments per function. This may be actually a problem, specially when we use apply to invoke a generic function that accepts arbitrary number of arguments. String.fromCharCode This is a classic example that could fail with truly big collection of char codes and here my suggestion to avoid such limit: var fromCharCode = (function ($fromCharCode, MAX_LENGTH) { // (C) WebReflection - DO THE FUCK YOU WANT LICENSE return function fromCharCode(code) { typeof code == "number" && (code = [code]); for (var result = [], i = 0, length = code.length; i ) { result.push($fromCharCode.apply(null, code.slice(i, i + MAX_LENGTH))); } return result.join(""); }; }(String.fromCharCode, 2048)); // example alert(fromCharCode(80)); // P alert(fromCharCode([80, 81, 82, 83, 84])...

double tweet - up to 280 chars tweets!

Update At least one other person did the same and before this post, here there's the prove . The algo seems to be almost the same, except the length is probably padded to be module of 2 (\x00 at the end) so you can use double-tweet gadget to decode gareth message as well :) Via encode template and same bookmark link, I would like to introduce my last simple experiment: WebReflection::double-tweet (just a click to give it a try, another one to remove) The Concept Twitter lets us type messages with a maximum of 140 characters. Fortunately, twitter accepts Unicode characters and still fortunately, it is extremely easy to pack two ASCII characters into a single Unicode one. Accordingly, 140 ASCII characters could be packed into 280. A Fast ASCII pack / unpack function ASCIIPack(s){ // WebReflection Mit Style License for(var r = [], i = 0, length = s.length, c; i < length; ++i){ c = s.charCodeAt(i); r.push(++i < length ? (c << 8) + s.charCodeAt(i)...