Skip to content

Instantly share code, notes, and snippets.

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 / 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();
});
}
@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 / 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 / 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 / eval.asp
Created July 11, 2015 23:45
Simple example of Eval in ASP Classic
<%@ LANGUAGE="VBSCRIPT" %>
<%
function myFunction()
response.write("Hello world")
end function
eval("myFunction()")
%>
@JavaScript-Packer
JavaScript-Packer / load-and-run.asp
Created July 11, 2015 23:41
Load local ASP page and eval/execute it from a simple function
<%@ LANGUAGE="VBSCRIPT" %>
<%
function load(ASPfile)
Server.Execute(ASPfile)
end function
'Call load("SameDirOrSubDir.asp")
%>
@JavaScript-Packer
JavaScript-Packer / load-HTML-file.asp
Last active August 29, 2015 14:24
ASP Classic function to load a local HTML5 file
<%@ LANGUAGE="VBSCRIPT" %>
<%
'fetch("webpage.htm")
sub fetch(file)
Dim x
Set fso = Server.CreateObject("Scripting.FileSystemObject")
set fs = fso.OpenTextFile(Server.MapPath(file), 1, true)
Do Until fs.AtEndOfStream
x = fs.ReadLine
Response.Write x
@JavaScript-Packer
JavaScript-Packer / load-URL.asp
Last active August 29, 2015 14:24
ASP function for loading external URL. Use in a custom 404.asp error page to make dynamic URLS like http://www.holybiblesearch.net/Jesus.htm (Jesus.htm is not found, loads a page anyhow).
<%@ LANGUAGE="VBSCRIPT" %>
<%
sub fetch(URL)
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", URL, false
objXMLHTTP.Send
Response.Write objXMLHTTP.responseText
Set objXMLHTTP = Nothing
response.end 'remove this if not using for 404.asp or it will kill the page after load
end sub
@JavaScript-Packer
JavaScript-Packer / does-string-contain.js
Created July 8, 2015 20:27
Tiny minified JavaScript function to find out if a string contains a search word/tern using regex. Live demo on http://jsfiddle.net/apmepe5j/
function is_in(a,b,c,d){return c=RegExp(b),d=c.test(a)}
alert(is_in("WHAK.com's awesome haystack!","needle"));
//returns false
alert(is_in("WHAK.com's awesome haystack!","some"));
//returns true