Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
JavaScript-Packer / modded-base64.js
Last active September 30, 2015 15:39
If I recode base64 encoded data with my modded base64 encoder (you will have to include small 288 byte decode function with data to unpack) that uses spaces as one of the characters, I can now achieve decent compression with server side gzip of average 2% (few times over 10%) compared to 1% gained (usually gets bigger) before with embedded bzip …
function fake_btoa(a) {
var c, d, e, f, g, h, i, j, o, b = "WHAK.com/PaCker BDEFGIJLMNOQR\
STUVXYZbdfghijlnpqstuvwxyz+01234567=", k = 0, l = 0, m = "", n = [];
if (!a) return a;
do c = a.charCodeAt(k++), d = a.charCodeAt(k++), e = a.charCodeAt(k++), j = c << 16 | d << 8 | e,
f = 63 & j >> 18, g = 63 & j >> 12, h = 63 & j >> 6, i = 63 & j, n[l++] = b.charAt(f) + b.charAt(g) + b.charAt(h) + b.charAt(i); while (k < a.length);
return m = n.join(""), o = a.length % 3, (o ? m.slice(0, o - 3) :m) + "===".slice(o || 3);
}
function fake_atob(a) {
@JavaScript-Packer
JavaScript-Packer / syntax-hilite.js
Last active August 29, 2015 14:25
JavaScript source code syntax hi-lighter in less than 1KB of code! No CSS BS, easy to use, set up as a simple function, making it for http://www.scriptcompress.com/
function get_hi(a) {
function b(a, b) {
return "<span style=color:#" + a + ">" + (b || "$1") + "</span>";
}
for (e = document.body.children, c = e[1].text, e[0].value = c, x = [ /&/g, "&amp;", /</g, "&lt;", />/g, "&gt;", /\\./g, function(a) {
return "r" + p.push(a) + ">";
}, /([\[({=:+,]\s*)\/(?![\/\*])/g, "$1<h/", /(\/\*[\s|\S]*?\*\/|\/\/.*)|(<h\/.+?\/\w*)|".*?"|'.*?'/g, function(a, c, d) {
return "r" + p.push(b(c ? "666" :d ? "6a0" :"719", a)) + ">";
}, /((&\w+;|[-\/+*=?:.,;()\[\]{}|%^!])+)/g, b("17b"), /\b(break|case|catch|continue|push|default|eval|delete|fromcharcode|charcodeat|do|else|false|finally|for|function|if|in|instanceof|new|return|switch|this|throw|true|try|typeof|var|void|while|with)\b/gi, b("f00"), /\b(0x[\da-f]+|\d+)\b/g, b("d83"), /r(\d+)>/g, function(a, b) {
return p[b - 1].replace(x[18], x[19]);
@JavaScript-Packer
JavaScript-Packer / document.write.alt.htm
Created July 23, 2015 05:01
Better alternative for document.write() in JavaScript using createElement div document.body.appendChild
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var div = document.createElement("div");
div.innerHTML = '<a href="http://www.whak.ca">www.WHAK.ca</a>';
document.body.appendChild(div);
</script>
@JavaScript-Packer
JavaScript-Packer / swap-character-case.js
Created July 24, 2015 10:00
Switch uppercase with lowercase and vice versa...
function swapcase(t) {
return t.replace(/([a-z]+)|([A-Z]+)/g, function(t, w) {
return w ? t.toUpperCase() : t.toLowerCase();
});
}
function camelize(e) {
return e.replace(/\W+(.)/g, function(e, t) {
return t.toUpperCase();
});
}
function uncamelize(e, t) {
return e.replace(/([a-z\d])([A-Z])/g, "$1" + (t || " ") + "$2");
}
@JavaScript-Packer
JavaScript-Packer / stripper.js
Created July 24, 2015 10:04
Function removes leading and trailing whitespace from string
function strip(e) {
return e.trim ? e.trim() : e.replace(/^\s+/, "").replace(/\s+$/, "");
}
@JavaScript-Packer
JavaScript-Packer / numbers-for-humans.js
Created July 24, 2015 10:07
Make numbers show like 1st, 2nd, 3rd or (n)th
function humanizer(e) {
if (e % 100 >= 11 && 13 >= e % 100) {
return e + "th";
}
switch (e % 10) {
case 1:
return e + "st";
case 2:
return e + "nd";
@JavaScript-Packer
JavaScript-Packer / guid.js
Created July 24, 2015 10:09
Function to get a unique guid of the specified length (32 is default)
function guid(t) {
var a, r = [], e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", n = e.length;
for (t = t || 32, a = 0; t > a; a++) {
r[a] = e.charAt(Math.floor(Math.random() * n));
}
return r.join("");
}
@JavaScript-Packer
JavaScript-Packer / D3.js.embedded.69KB.demo.html
Last active August 29, 2015 14:25
D3.js is a JavaScript library for manipulating documents based on data. Demo on http://jsfiddle.net/n9rp2xqt/show/ D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization componen…
<!DOCTYPE html><meta charset="utf-8">
<body><!-- We compressed 147 KB https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js to 48 KB on
http://www.scriptcompress.com then embedded JavaScript into HTML file with working demo under 70KB -->
<script>var WHAK_com =atob('QlpoOTFBWSZTWRx4Tl4AsOhfgFAAf////7////+/////YOJd9D1r6UABW7A9nr3Gz7lD330ds\
t97PiSx3t4G75u6+rRqocUtb1iuqUdd3uym2LrKqr1pHpou7j6d5i+2qVSSRSh9kwYFKhIDzdz3vLZYAfTd6FKSq0+7rpHPW+2PTu\
G+2B9u+15Q3d1WexfV8OHvPc++0Qz7nOnTd3XHOabOji5GqoKWbQAPs9kM9s3bXo92vYN1l2c3Du7PTkPIW1ADvvvvj7fZ9AHz7LN\
ki9srlD7Hoy0bYAAoANr1uMtKPWdT2He7e3uO2syzfd7zPdV3ambYpTSWhfGAHuYe7h1CqK5NBCj3twUCgXsa0rbPd3ZQXjyu2ts8\
y1t1d12d267Wt3TdtrOq67bL3B0LYave940DbdHe527e5i9zqDbw+6wPu6S+vfM77nbTNzh1ueOJ7PLPfJCgyWvvoMPoL2F3eqUa+\
ju305fU68OcJ2W3t29u9VLx8dXsbD4sfWtrtJ7w+u+rPcKz299oPdeFzUemXvXXN7723222D66JWhq+9szc+K+XnDN7goHIBfLzVt\
nO3O9b65699t99ut5253W3dfHN4WYqNDffYCrwm623Trzt3NUdw97b3qngAKDPU03OGtmGjuOFdCSsuZ3vdFWd7nueoWus2AATVho\
@JavaScript-Packer
JavaScript-Packer / html-entities-encoder.htm
Created July 26, 2015 12:28
Encode HTML entities for every character in a string - Demo on http://jsfiddle.net/mjytsf60/
<textarea id=loader rows=11 cols=77></textarea>
<script>
function encodeHTMLentities(w){return w.replace(/[^]/g,function(w){return '&#'+w.charCodeAt(0)+';'})}
loader.value=encodeHTMLentities(document.body.innerHTML)
</script>