Skip to content

Instantly share code, notes, and snippets.

View sergeevabc's full-sized avatar

Aleksandr Sergeev sergeevabc

View GitHub Profile
@sergeevabc
sergeevabc / bpasswd2portable.html
Last active August 29, 2015 14:07
BPasswd2 nobullshit edition (Original: https://github.com/bwalex/bpasswd)
<!DOCTYPE html>
<html>
<head>
<title>BPasswd2 nobullshit edition</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
/* normalize + pure */ article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none;height:0}[hidden]{display:none}html{font-size:100%;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}html,button,input,select,textarea{font-family:sans-serif}body{margin:0}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1{font-size:2em;margin:.67em 0}h2{font-size:1.5em;margin:.83em 0}h3{font-size:1.17em;margin:1em 0}h4{font-size:1em;margin:1.33em 0}h5{font-size:.83em;margin:1.67em 0}h6{font-size:.67em;margin:2.33em 0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}blockquote{margin:1em 40px}dfn{font-style:italic}hr{-moz-box-sizing:content-box;box-sizing:conte
function Uint8ArrayToString(arr) {
var encodedString = String.fromCharCode.apply(null, arr),
decodedString = decodeURIComponent(escape(encodedString));
return decodedString;
}
function stringToUTF8Array(s) {
var i,
d = unescape(encodeURIComponent(s)),
b = new Uint8Array(d.length);
for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i);
return b;
}
@sergeevabc
sergeevabc / Base64novnc.js
Last active August 29, 2015 14:07
Base64 encode http://jsperf.com/base64-encode/3 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ and =
var Base64novnc = {
encode: function(data) {
"use strict";
var result = '';
var toBase64Table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split('');
var length = data.length;
var lengthpad = (length % 3);
// Convert every three bytes to 4 ascii characters.
for (var i = 0; i < (length - 2); i += 3) {
result += toBase64Table[data[i] >> 2];
@sergeevabc
sergeevabc / Base91.js
Last active August 29, 2015 14:07
Base91 encode, decode https://github.com/mscdex/base91.js ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~"
(function() {
var hasNode = (typeof process !== 'undefined' && process.versions && process.versions.node),
hasTypedArray = (typeof Uint8Array !== 'undefined');
if (hasNode && require('fs').existsSync(__dirname + '/../build/Release/base91encdec.node')) {
module.exports = require(__dirname + '/../build/Release/base91encdec.node');
return;
}
var AVERAGE_ENCODING_RATIO = 1.2297,
ENCODING_TABLE = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
@sergeevabc
sergeevabc / Base58.js
Last active August 29, 2015 14:07
Base58 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
// https://github.com/cryptocoinjs/bs58
function base58encode(buffer) {
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
var ALPHABET_MAP = {};
for (var i = 0; i < ALPHABET.length; i++) {
ALPHABET_MAP[ALPHABET.charAt(i)] = i;
}
var BASE = 58;
if (buffer.length === 0)
return '';
@sergeevabc
sergeevabc / Base85ZeroMQ.js
Last active August 29, 2015 14:07
Base85 ZeroMQ encode 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#
// https://github.com/noseglid/base85
function z85encode(buffer) {
var enctable = {
0: '0',
1: '1',
2: '2',
3: '3',
4: '4',
5: '5',
6: '6',
@sergeevabc
sergeevabc / Base62.js
Created October 17, 2014 11:48
Base62 encode, decode https://github.com/odan/base62js 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
if (!$d) {
var $d = {}
}
$d.BitStream = function BitStream(options) {
this.Source = [];
if (typeof options === 'object') {
this.Source = options
}
if (typeof options === 'number') {
var dim = Math.floor(options);
@sergeevabc
sergeevabc / TypeOfVariable.js
Created October 17, 2014 11:50
What is the type of that variable? (String, Array, etc)
function type(variable) {
return Object.prototype.toString.call(variable).replace(/^\[object (.+)\]$/, "$1").toLowerCase();
}
@sergeevabc
sergeevabc / FisherYatesShuffle.js
Created October 17, 2014 16:17
Fisher-Yates shuffle
var i = arr.length,
rndIndex, tmpValue;
while (--i) {
rndIndex = ~~(Math.random() * (i + 1));
tmpValue = arr[i];
arr[i] = arr[rndIndex];
arr[rndIndex] = tmpValue;
}