Skip to content

Instantly share code, notes, and snippets.

View 19h's full-sized avatar
This is a verified account.

Kenan Sulayman 19h

This is a verified account.
View GitHub Profile
@19h
19h / TiYoutube3GPP.js
Created May 17, 2013 20:50
Titanium Mobile SDK Android: Extract Youtube Video URL / URI from video-id / identification / name and play 3gpp file.
Titanium.App.addEventListener("playvideo", function (e) {
win11 = Titanium.UI.createWindow({
orientationModes: [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT],
title: "Video",
zIndex: 222222
});
var activeMovie = Titanium.Media.createVideoPlayer({
fullscreen: !0,
autoplay: !0,
@19h
19h / incache.js
Created May 26, 2013 14:29
Sophisticated inline-cachine. Don't do this with large files — only micro streaming at the moment; unless you're sporting required amounts of memory.
// inline caching
_str = require("stream").Stream;
require("util").inherits(StreamCache, _str);
function StreamCache() {
_str.call(this);
this.readable = this.writable = !0;
this._buffers = [];
this._dests = [];
this._ended = !1
@19h
19h / atkinssieve.js
Created May 29, 2013 14:03
Javascript Prime-Generator (Atkins-Sieve)
atkinsSieve = function (e) {
last = 0;
for (var d = Array(e + 1), a = 0; a < d.length; a++) d[a] = 0;
for (var f = Math.floor(Math.sqrt(e)) + 1, b, c, a = 1; a < f; a++) for (c = 1; c < f; c++) {
b = 4 * Math.pow(a, 2) + Math.pow(c, 2);
if (b <= e && (1 === b % 12 || 5 === b % 12)) d[b] ^= 1;
b = 3 * Math.pow(a, 2) + Math.pow(c, 2);
b <= e && 7 === b % 12 && (d[b] ^= 1);
a > c && (b = 3 * Math.pow(a, 2) - Math.pow(c, 2), b <= e && 11 === b % 12 && (d[b] ^= 1))
}
@19h
19h / tokenizer.js
Last active December 18, 2015 02:08
Natural Language Tokenizer (English) — Update: only words with length <= 4 or where apostrophe included, length equals 4 with apostrophe removed
wL = ["to",
"as",
"you",
"the",
"i",
"to",
"a",
"and",
"it",
"of",
@19h
19h / cbc256
Created June 20, 2013 14:51
AES CBC 256 using Node.js [crypto]
/*
p is plaintext (non-encrypted value) OR CIPHER (already encrypted text)
t is either false [cbc256("value", false, "key")] for encryption or true for decryption
k is key.
*/
/*
Example:
val = "value";
v = cbc256(val, false, "key");
@19h
19h / escape.js
Created June 25, 2013 17:28
String escaper. Usage: sE("string"[, escapeASCII[, wrapAll]]).
sE = function (e, c, x) {
var f = {
"\b": "\\b",
"\t": "\\t",
"\n": "\\n",
"\v": "\\x0B",
"\f": "\\f",
"\r": "\\r",
"\\": "\\\\",
'"': '\\"',
@19h
19h / division.js
Created June 27, 2013 12:08
Javascript [V8-ECMA] Bitwise Division
var division = function (b, a) {
var c;
neg = quotient = 1;
if (0 < b && 0 > a || 0 > b && 0 < a) neg = -1;
tempdividend = 0 > b ? -b : b;
tempdivisor = 0 > a ? -a : a;
if (tempdivisor == tempdividend) c = 1 * neg;
else if (tempdividend < tempdivisor) c = 0;
else {
for (; tempdivisor << 1 <= tempdividend;) tempdivisor <<= 1, quotient <<= 1;
@19h
19h / CSF.js
Created June 27, 2013 13:34
Consensus Stamp Format (V8-ECMA) (Javascript)
/*
Consensus Stamp Format
<Day> / <Month in Quarter>:Q<Quarter> / <Years since 1970>
27th June, 2013 <> 27/3:Q2/43.
*/
toCSF = function (v) {
!(v instanceof Date) && (v=new Date(v));
@19h
19h / PE.js
Last active July 19, 2023 13:34
A Probabilistic Encryption Algorithm (V8/ECMA)
var encrypt = function (i, d) {
if (null == d || 0 >= d.length) return null;
for (var a = "", b = 0; b < d.length; b++) a += d.charCodeAt(b).toString();
var b = Math.floor(a.length / 5),
g = parseInt(a.charAt(b) + a.charAt(2 * b) + a.charAt(3 * b) + a.charAt(4 * b) + a.charAt(5 * b), 10),
j = Math.ceil(d.length / 2),
h = Math.pow(2, 31) - 1;
if (2 > g) return null;
for (var c = Math.round(1E9 * Math.random()) % 1E8, a = a + c; 10 < a.length;) a = (parseInt(a.substring(0, 10), 10) + parseInt(a.substring(10, a.length), 10)).toString();
for (a = (g * a + j) % h, e = "", f = "", b = 0; b < i.length; b++) e = parseInt(i.charCodeAt(b) ^ Math.floor(255 * (a / h)), 10), f = 16 > e ? f + ("0" + e.toString(16)) : f + e.toString(16), a = (g * a + j) % h;
@19h
19h / optim.js
Created July 2, 2013 14:47
General Optimizations
Operation => Optimized Operation.
x * 10 => (((x << 2) + x) << 1)
x * 100 => ((((((x << 2) + x) << 1) << 2) + (((x << 2) + x) << 1)) << 1)
x * 1000 =>(((((((((x << 2) + x) << 1) << 2) + (((x << 2) + x) << 1)) << 1) << 2) + ((((((x << 2) + x) << 1) << 2) + (((x << 2) + x) << 1)) << 1)) << 1)
x * 2 => x << 1
x * 4 => x << 2
x * 8 => x << 3
x * 16 => x << 4