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
import ( | |
"math" | |
"strings" | |
) | |
func levenshteinDistance(s string, t string) int { | |
// degenerate cases | |
s = strings.ToLower(s) | |
t = strings.ToLower(t) | |
if (s == t) { return 0 } |
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
// Extracts base URL from location of current document. | |
function extractBaseUrl() { | |
// Get URL without query path | |
var url = [location.protocol, '//', location.host, location.pathname].join(''); | |
// Remove filename if present | |
var f = url.substr(url.lastIndexOf("/") + 1).toLowerCase(); | |
if (f.indexOf('.html') >= 0 || f.indexOf('.htm') >= 0 || f.indexOf('.php')) { | |
url = url.substr(0, url.length - f.length); | |
} | |
// Add last slash if missing |
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
if (typeof(console) === 'undefined') { | |
var functionNames = ['info', 'error', 'warn', 'dir', 'trace', 'log', 'assert']; | |
console = {}; | |
for (var i = 0; i < functionNames.length; i++) console[functionNames[i]] = function(){}; | |
} |
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
<?php | |
/** | |
* Generates human-readable string. | |
* | |
* @param string $length Desired length of random string. | |
* | |
* retuen string Random string. | |
*/ | |
function readable_random_string($length = 6) |