Skip to content

Instantly share code, notes, and snippets.

View nothrem's full-sized avatar

Nothrem Sinsky nothrem

  • Czech Republic
View GitHub Profile
if (!String.prototype.toNumberString) {
/**
* Converts each character into its numerical representation of given base
* By default converts to Hexadecimal (base = 16)
* This conversion is required for JWT implementation http://kjur.github.io/jsrsasign/
*
* Examples:
* '*123'.toNumberString(); //returns '2a313233'
* '*123'.toNumberString(10); //returns '42495051'
* '*123'.toNumberString(8); //returns '52616263';
/*
* MD5 by: http://www.myersdaily.org/joseph/javascript/md5-text.html
* Polyfill by: https://gist.github.com/nothrem/f1aad311019009a9252592716b368b53
*/
if (!String.prototype.md5) {
(function () {
var md5cycle = function(x, k) {
var a = x[0], b = x[1], c = x[2], d = x[3];
a = ff(a, b, c, d, k[0], 7, -680876936);
/* Use as standalone function or static method of any object.
* Set default $shardLevel to a value relevant for your usercase (e.g. +3 for MD5 filenames, -2 for ID filenames, etc.)
*/
/**
* Creates subfolders for storing files to prevent folder overloading by too many files.
*
* @param mixed $filename (required) Basic filename without extension. Can be anything convertable to string valid for filenaming.
* @param string $root (optional, default: '/') Where to start creating the subfolders. Set false to skip folder creation.
* @param string $ext (optional, default: none) Extension for the file.