Skip to content

Instantly share code, notes, and snippets.

@atb00ker
Last active February 12, 2020 12:33
Show Gist options
  • Save atb00ker/9d7ca5f02e56b03a00fafb593997570d to your computer and use it in GitHub Desktop.
Save atb00ker/9d7ca5f02e56b03a00fafb593997570d to your computer and use it in GitHub Desktop.
Useful snippets for web-development
web-encode-decode.js : JavaScript to encode and decode any given string.
web-custom-google-forms : Make forms on your website and submit on Google forms pragmatically.
Step 1. Make a form with required fields then open the dev-tools on browser and make a fake submsission.
Step 2. In the tab used for network analysis, look for POST request created by the site to submit.
You'll find the ID of all the questions and the methode used by Google to take in the response.
Step 3. Fill the information accordingly in the link below:
https://docs.google.com/forms/d/[YOURFORMID]/formResponse?entry.[YOURQUESTION1IDHERE]=[YOURQUESTION1ANSWERHERE]&entry.[YOURQUESTION2IDHERE]=[YOURQUESTION2ANSWERHERE]&submit=Submit
Step 4. Complete! You can now take the response from user and submit it to the form using JavaScript.
Demo: https://github.com/atb00ker/asetalias.github.io/blob/master/assets/js/user/swHelper.js
Read more: https://github.com/heaversm/google-custom-form
applicationServerKey: urlBase64ToUint8Array('BKNmZNhH7cszaNYeHKxwf7fnb56EW84vRCiWD4P_HkwQUcAC5lWGbJXac0IMIQKHq6zekdImGimQ49SFAWEmIc0')};
applicationServerKey.toMagicEncodedString();
applicationServerKey.fromMagicEncodedString();
//Convert url(Base64) to an array
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i)
outputArray[i] = rawData.charCodeAt(i);
return outputArray;
}
//Magic String Encoding & Decoding.
String.prototype.toMagicEncodedString = function(){var ostr=this.toString().replace(/\s+/g,'');if(ostr.length<8){alert("Password must be at least 8 characters long with no spaces.");return null;};var x,nstr='',len=ostr.length;for(x=0;x<len;++x){nstr+=(255-ostr.charCodeAt(x)).toString(36).toUpperCase().toPaddedString(2,'0');};return nstr;}
String.prototype.fromMagicEncodedString = function(){var ostr=this.toString();var x,nstr='',len=ostr.length;for(x=0;x<len;x+=2){nstr+=String.fromCharCode(255-parseInt(ostr.substr(x,2),36));};return nstr;}
Number.prototype.toPaddedString = function(len,pad){len=(len)?Number(len):2;if(isNaN(len)){alert("Padded String 'length' argument is not numeric.");return null;};var dflt=(isNaN(this.toString()))?" ":"0";pad=(pad)?pad.toString().substr(0,1):dflt;var str=this.toString();if(dflt=="0"){while(str.length<len)str=pad+str;}else{while(str.length<len)str+=pad;}return str;}
String.prototype.toPaddedString = Number.prototype.toPaddedString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment