Skip to content

Instantly share code, notes, and snippets.

/* extracted from http://www.iteral.com/jscrush/ by James Liu (@jamesliu96) */
/* @aivopaas | licensed under MIT license */
var JSCrush = function(s) {
Q = [];
for (i = 1000; --i; i - 10 && i - 13 && i - 34 && i - 39 && i - 92 && Q.push(String.fromCharCode(i)));
i = s = s.replace(/([\r\n]|^)\s*\/\/.*|[\r\n]+\s*/g, '').replace(/\\/g, '\\\\'), X = B = s.length / 2, O = m = '';
for (S = encodeURI(i).replace(/%../g, 'i').length;; m = c + m) {
for (M = N = e = c = 0, i = Q.length; !c && --i; !~s.indexOf(Q[i]) && (c = Q[i]));
if (!c) break;
if (O) {
@jamesliu96
jamesliu96 / mosaic.js
Created May 23, 2015 08:06
Mosaic Processor
var mosaic = function(h, a) {
for (var f = h.data, m = h.width, n = h.height, k = 0, p = m / a | 0, l, q, g, b, c, e, d; k < p; k++)
for (l = 0, q = n / a | 0; l < q; l++) {
for (g = [], b = [0, 0, 0], c = 0; c < a; c++)
for (d = 0; d < a; d++)
e = (l * a + c) * m + k * a + d, b[0] += f[4 * e], b[1] += f[4 * e + 1], b[2] += f[4 * e + 2];
g[0] = b[0] / (a * a), g[1] = b[1] / (a * a), g[2] = b[2] / (a * a);
for (c = 0; c < a; c++)
for (d = 0; d < a; d++)
e = (l * a + c) * m + k * a + d, f[4 * e] = g[0], f[4 * e + 1] = g[1], f[4 * e + 2] = g[2];
@jamesliu96
jamesliu96 / trim.js
Created May 24, 2015 18:31
Trim canvas image
var c = document.createElement('canvas');
var ctx = c.getContext('2d');
c.height = 300;
c.width = 300;
// ctx.fillStyle = "green";
// ctx.fillRect(0, 0, 160, 50);
// ctx.fillRect(50, 50, 50, 50);
// ctx.fillRect(100, 100, 50, 60);
@jamesliu96
jamesliu96 / keycontrol.sh
Created May 27, 2015 05:11
Apple Keyboard Control
#!/bin/sh
keyload() {
sudo kextload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
}
keyunload() {
sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
}
@jamesliu96
jamesliu96 / uuid.js
Created June 19, 2015 04:37
UUID automatic generator
var UUID = (function(r) {
return "xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, r);
})(function(c) {
var r = Math.random() * 16 | 0,
v = c == "x" ? r : (r & 3 | 8);
return v.toString(16);
});
@jamesliu96
jamesliu96 / bilidown.sh
Last active August 29, 2015 14:25
Bilibili Bash Downloader
#!/bin/sh
##############
# BILIBILI #
# BASH #
# DOWNLOADER #
##############
aid=`echo $1 | awk '{sub("av","");print}'`
page=$2
@jamesliu96
jamesliu96 / dice.js
Last active July 16, 2017 20:40
Simple dice
function dice(n) { var d = []; while(n > 0) { d.push(Math.ceil(6 * Math.random())); n--; } return d.sort(); }
@jamesliu96
jamesliu96 / rails-d.sh
Last active August 29, 2015 14:26
Rails on Ubuntu auto installation script
#!/bin/sh
sudo apt-get update
sudo apt-get install gcc g++ make
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev
wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
tar -xzf ruby-2.2.2.tar.gz
cd ruby-2.2.2/
./configure
make
@jamesliu96
jamesliu96 / add_account
Created August 8, 2015 09:10
PPTP CHAP account managing scripts
#!/bin/sh
if [ -z $1 ]; then
echo "Please specify username."
exit 1
fi
search=`grep '^'$1'' /etc/ppp/chap-secrets`
if [ -n $search ]; then
@jamesliu96
jamesliu96 / auth-down
Created August 8, 2015 12:25
PPTP server auto scripts
#!/bin/sh
USER=$2
rm /var/run/pptpd/$USER