This file contains 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
XML = { | |
parse: (string, type = 'text/xml') => new DOMParser().parseFromString(string, type), // like JSON.parse | |
stringify: DOM => new XMLSerializer().serializeToString(DOM), // like JSON.stringify | |
transform: (xml, xsl) => { | |
let proc = new XSLTProcessor(); | |
proc.importStylesheet(typeof xsl == 'string' ? XML.parse(xsl) : xsl); | |
let output = proc.transformToFragment(typeof xml == 'string' ? XML.parse(xml) : xml, document); | |
return typeof xml == 'string' ? XML.stringify(output) : output; // if source was string then stringify response, else return object | |
}, |
This file contains 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
mapSearch = (query) => { | |
return new Promise((resolve, reject) => { | |
fetch("https://maps.google.com/maps/api/geocode/json?sensor=true&address=" + query) | |
.then((resp) => resp.json()) | |
.then(function(data) { | |
let types = { | |
country: 'country', | |
administrative_area_level_1: 'state', | |
administrative_area_level_2: 'county', | |
locality: 'city', |
This file contains 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
<? | |
function post($url, $data){ | |
$options = array( | |
'http' => array( // use key 'http' even if you send the request to https://... | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'POST', | |
'content' => http_build_query($data), | |
// 'content' => json_encode($data), | |
), |
This file contains 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
uniqueID = (length=6, n=true, lc=true, uc=true) => { // 62^6 = 50 Billion | |
let chars = ''; | |
if (n) chars += '1234567890'; | |
if (lc) chars += 'abcdefghijklmnopqrstuvwxyz'; | |
if (uc) chars += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
let ID = ''; | |
for (let i = 0; i < length; i++) | |
ID += chars[Math.floor((Math.random() * chars.length))]; | |
return ID; | |
} |