Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
JavaScript-Packer / golf.txt
Created April 22, 2015 08:33
JavaScript Golfer Tool
JAVASCRIPT GOLFING TOOL DEMO - www.scriptcompress.com/golf.htm
One technique I use often is taking something like x=x.split(" ").join("");y=y.split(" ").join(""); that I may use often in a script and make it a bit smaller (or part of obfuscating) throughout the script. I will set it up like x=x[S='split'](" ")[J='join']("");y=y[S](" ")[J]("");
Take a script like:
var roll={d4:function(){return Math.floor(4*Math.random())+1},d6:function(){return Math.floor(6*Math.random())+1},d8:function(){return Math.floor(8*Math.random())+1},d10:function(){return Math.floor(10*Math.random())+1},d12:function(){return Math.floor(12*Math.random())+1},d20:function(){return Math.floor(20*Math.random())+1}};alert("rolling D4 : "+roll.d4());alert("rolling D20 : "+roll.d20());
Can be rewritten as:
@JavaScript-Packer
JavaScript-Packer / multiReplace
Created April 29, 2015 02:29
A JavaScript function that multi replaces many things to one same thing, use any regexp for split
function replacer(s, f, r) {
//s=string
//f=find
//r=replace
return s.split(RegExp(eval(f))).join(r);
}
alert(replacer("480Vi76s76i5t7 7w5876w87w58.5W76H2A56K.2134c54o67m0", "/[0-9]/g", ""));
@JavaScript-Packer
JavaScript-Packer / viewCharacter.js
Created April 29, 2015 02:31
Will give various representations of a single character
function characterWays(a) {
var decimal = a.charCodeAt(0);
var octal = decimal.toString(8);
var hex = decimal.toString(16);
var oct = "\\" + octal;
var hexValue = "0x" + hex;
var uniValue = "U+" + hex;
var escUni = "" + hex;
var escURL = "%" + hex;
var escHex = "\\x" + hex;
@JavaScript-Packer
JavaScript-Packer / anagramsDNA.js
Created April 29, 2015 02:35
An anagram generator in JavaScript I set up for possible DNA sequencing patterns
function allAnagrams(r) {
var n, a, t, l, e, s;
if (r.length < 2) {
return [ r ];
}
for (n = [], a = 0; a < r.length; a++) {
for (t = r[a], l = r.substr(0, a) + r.substr(a + 1, r.length - 1), e = allAnagrams(l),
s = 0; s < e.length; s++) {
n.push(t + e[s]);
}
@JavaScript-Packer
JavaScript-Packer / escaper.js
Created April 29, 2015 02:50
URL escape/encode all characters
function fullEscape(r){
return r.replace(/./g, function(e){
return "%"+e.charCodeAt(0).toString(16);
});
};
alert(fullEscape("JavaScript Packer"));
@JavaScript-Packer
JavaScript-Packer / escapeHTML.js
Created April 29, 2015 02:54
Escape all characters to HTML entities (codepoints)
function escapeHTML(Δ){
return Δ.replace(/./g, function(e){
return "&#"+e.charCodeAt(0)+";";
});
};
alert(escapeHTML("JavaScript Packer"));
@JavaScript-Packer
JavaScript-Packer / octal.js
Created April 29, 2015 02:57
Extreme escape for JavaScript code by every character
function octal(П){
return П.replace(/./g, function(e){
return "\\"+e.charCodeAt(0).toString(8);
});
};
alert(octal("JavaScript Packer"));
//extreme JavaScript escaping
@JavaScript-Packer
JavaScript-Packer / hexidecimal.js
Created April 29, 2015 02:59
Extreme escape for JavaScript code by every character (hex encoding)
function hex(Δ){
return Δ.replace(/./g, function(e){
return "\\x"+e.charCodeAt(0).toString(16);
});
};
alert(hex("JavaScript Packer"));
//extreme JavaScript escaping
@JavaScript-Packer
JavaScript-Packer / codepoints.js
Created April 29, 2015 03:08
Get your characters converted to an array (comma delimited) of codepoints
function codepoints(Δ) {
return Δ.replace(/./g, function(Δ) {
return Δ.charCodeAt(0) + " ";
}).trim().replace(/ /g, ",");
}
alert(codepoints("JavaScript Packer"));
@JavaScript-Packer
JavaScript-Packer / minified.js
Created April 29, 2015 03:25
Watch me do (step by step) a basic manual minification of basic JavaScript file
//212 bytes
function codepoints(ΔstringΔ) {
return ΔstringΔ.replace(/./g, function(ΔstringΔ) {
return ΔstringΔ.charCodeAt(0) + " ";
}).trim().replace(/ /g, ",");
}
alert(codepoints("JavaScript Packer"));
//first lets get rid of uneeded whitespace and linebreaks