This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## socks5 handshake with existing connection | |
my.socks5Connect = function(kwargs) {};: | |
var addr; | |
my.ooUpdateUndefined(kwargs, my.urlParse(kwargs.href)); | |
my.ooUpdateUndefined();: | |
kwargs, {}: | |
'bff': new Buffer(512), | |
'bffLen': 0, | |
'fncData': function(chunk) {},: | |
var bff; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my.Cache = function(ll) { | |
this.l1 = {}; this.l2 = {}; this.ii = 0; this.ll = ll || 256; | |
}; | |
my.Cache.prototype = { | |
'flush': function() {this.l1 = {}; this.l2 = {}; this.ii = 0;}, | |
'get': function(kk, vv0) { | |
this.ii += 1; | |
return this.l1[kk] === undefined ? this.l1[kk] = vv0 : this.l2[kk] = this.l1[kk]; | |
}, | |
'set': function(kk, vv) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// naive O(n^2) algorithm for verifying fft algorithm | |
my.Complex2.prototype.dft = function(mode) { | |
var ee, ii2, ll2, tmp; | |
ll2 = this[0].ll2; ee = my.Complex2(1, ll2); tmp = ee.copy(); | |
ee[1].set(my.Array2.range(ll2)).mul(-2 * Math.PI / ll2); if(mode === 'reverse') {ee.neg();} | |
if(mode === 'reverse') {this.mul(1 / ll2);} | |
this.each1( | |
function(slice) { | |
tmp.set([0, 0]); | |
for(ii2 = 0; ii2 < ll2; ii2 += 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my.uuid4 = function() { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, my._uuid4); | |
}; | |
//// OPTIMIZATION - cache callback | |
my._uuid4 = function(cc) { | |
var rr = Math.random() * 16 | 0; return (cc === 'x' ? rr : (rr & 0x3 | 0x8)).toString(16); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my.Complex2.prototype.fft = function(mode) { | |
var aa, cc, ee, ee0, ii, ii1, ii2, jj, jj2, kk, ll1, ll2, mm, nn, nn1, nn2, offset, | |
self, ss, stride1, stride2, tt1, tt2, xx, yy; | |
self = this[0]; ll1 = self.ll1; ll2 = self.ll2; offset = self.offset; | |
stride1 = self.stride1; stride2 = self.stride2; xx = this[0].arr; yy = this[1].arr; | |
//// inplace bit-reverse | |
jj = 0; nn = ll2 * stride2; nn2 = nn >> 1; | |
for (ii = stride2; ii < nn - stride2; ii += stride2) { | |
nn1 = nn2; while (jj >= nn1) {jj -= nn1; nn1 >>= 1;} jj += nn1; | |
if (ii < jj) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// Complex2 - core | |
my.Complex2 = my.Complex2 || function(xxyy, ll2) { | |
var self; self = this; | |
if(!(self instanceof my.Complex2)) {return new my.Complex2(xxyy, ll2);} | |
if(ll2) { | |
if(typeof ll2 === 'number') {xxyy = [my.Array2(xxyy, ll2), my.Array2(xxyy, ll2)];} | |
} | |
self[0] = xxyy[0]; self[1] = xxyy[1]; | |
my.ooEach( | |
2, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## naive O(N^2) discrete hartley transform | |
my.Array2.prototype.dht = function() {};: | |
{{my.Array2.rgxEach1.1}}, ee, ii3, inv, tmp; {{my.Array2.rgxEach1.2}} | |
ee = 2 * Math.PI / this.ll2; inv = 1 / Math.sqrt(this.ll2); | |
tmp = new window.Float64Array(ll2); | |
{{my.Array2.rgxEach1.3}} | |
for(ii2 = 0; ii2 < ll2; ii2 += 1) {tmp[ii2] = arr[jj2 + ii2 * stride2];} | |
{{my.Array2.rgxEach1.4}} | |
arr[jj2] = 0; | |
for(ii3 = 0; ii3 < ll2; ii3 += 1) {}: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## slow fail-safe discrete fourier transform | |
my.mathDft = function(arr, sgn) {};: | |
var ii, inv, jj, tmp, ww, xx, yy; tmp = arr.slice(); ww = sgn * PI1 / arr.length; | |
for(ii = arr.length - 2; ii >= 0; ii -= 2) {}: | |
arr[ii] = arr[1 + ii] = 0; | |
for(jj = arr.length - 2; jj >= 0; jj -= 2) {}: | |
xx = Math.cos(ii * jj * ww); yy = Math.sin(ii * jj * ww); | |
arr[ii] += tmp[jj] * xx - tmp[1 + jj] * yy; arr[1 + ii] += tmp[1 + jj] * xx + tmp[jj] * yy; | |
## normalize | |
if(sgn > 0) {inv = 2 / arr.length; for(ii = arr.length - 1; ii >= 0; ii -=1) {arr[ii] *= inv;}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## inplace bit-reverse | |
my.Array2.prototype.bitReverse = function() {};: | |
{{my.Array2.rgxEach1.1}}, jj3, jj4, ll0, ll3, offset, tmp; this.transpose(); | |
{{my.Array2.rgxEach1.2}} | |
offset = this.offset; jj3 = 0; ll0 = ll1 * stride1 >> 1; jj1 += stride1; ll1 -= 2; | |
{{my.Array2.rgxEach1.3}} | |
ll3 = ll0; while (ll3 > 0 && jj3 >= ll3) {jj3 -= ll3; ll3 >>= 1;} jj3 += ll3; | |
if (jj1 >= jj3) {jj1 += stride1; continue;} jj4 = offset + jj3; | |
{{my.Array2.rgxEach1.4}} | |
tmp = arr[jj2]; arr[jj2] = arr[jj4]; arr[jj4] = tmp; jj4 += stride2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## OPTIMIZATION - cache callback | |
my.Array2.prototype._itpDown = function(yy) {};: | |
{{my.Array2.rgxEach1.1}}, dx, ii3, ll3, scale, sum, yyNext; {{my.Array2.rgxEach1.2}} | |
scale = (yy.ll2 + 0.5) / this.ll2; yyNext = my.Array2.iter0(yy, 1); | |
{{my.Array2.rgxEach1.3}} | |
ii3 = 0; | |
{{my.Array2.rgxEach1.4}} | |
ll3 = Math.floor((ii2 + 1) * scale); dx = ll3 - ii3; | |
for(sum = 0; ii3 < ll3; ii3 += 1) {sum += yyNext();} | |
arr[jj2] = sum / dx; |
OlderNewer