Skip to content

Instantly share code, notes, and snippets.


Stephan Schmitz eyecatchup

View GitHub Profile
View calc-sapisidhash.js
async function getSApiSidHash(SAPISID, origin) {
function sha1(str) {
return window.crypto.subtle.digest("SHA-1", new TextEncoder("utf-8").encode(str)).then(buf => {
return Uint8Array(buf), x=>(('00'+x.toString(16)).slice(-2))).join('');
const digest = await sha1(`${TIMESTAMP_MS} ${SAPISID} ${origin}`);
eyecatchup / draw-bootstrap-grid.js
Created Mar 30, 2022
Draw the Bootstrap grid as a full page overlay
View draw-bootstrap-grid.js
var grid = 12
var cols = document.createDocumentFragment()
var col = document.createElement('div') = `height: ${document.documentElement.scrollHeight}px; width: calc(100% / ${grid}); background-color: rgba(240, 128, 128, 0.3);`
var innerCol = document.createElement('div') = `height: ${document.documentElement.scrollHeight}px; width: calc(100% - 30px); margin: auto 15px; background-color: rgba(244, 0, 0, 0.1); position: relative;`
for (var i, i = 1; i <= grid; i++) {
eyecatchup / vue.config.js
Created Sep 25, 2020
(Vue.js) Webpack dev server config to use a (corporate) proxy
View vue.config.js
const HttpsProxyAgent = require('https-proxy-agent')
const proxy = new HttpsProxyAgent('')
module.exports = {
// ...
configureWebpack: {
devServer: {
// ...
proxy: {
eyecatchup / error-stringify.js
Created Feb 18, 2020
Custom replace function for JSON.stringify to stringify JS Error Objects.
View error-stringify.js
jsonFriendlyErrorReplacer = (key, value) => {
if (value instanceof Error) {
value = Object.assign({},
value, // Pull all enumerable properties, supporting properties on custom Errors
{ // Explicitly pull Error's non-enumerable properties
message: value.message,
stack: value.stack
eyecatchup /
Last active Aug 31, 2021
Ionic Native / Cordova InAppBrowser: Multiple `executeScript` Promises

Ionic Native / Cordova InAppBrowser: Multiple executeScript Promises

I recently worked on a project with Ionic Native and Cordova. One thing I noticed (and took me some time to resolve), was an issue with the then function of the InAppBrowser plugin's executeScript Promise not being executed on iOS.

TL;DR When you use multiple executeScript Promises within one method, the then functions will not fire on iOS. You have to await results.

To illustrate the issue, let's declare a new InAppBrowser instance:

const browser = this.iab.create('', '_blank');
eyecatchup / catch-js-error-stacktrace.js
Created Jul 1, 2019
JavaScript global error handling
View catch-js-error-stacktrace.js
var sendError = function (err) {
console.log('Caught JS client error:');
var xhr = new XMLHttpRequest();'POST', '/api/error/add', true);
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
eyecatchup /
Created May 24, 2019
Search Chrome Devtools history

Search Chrome Devtools history

  1. Undock the console (click on the icon in the bottom-left corner, ![undock icon][1]).
    (if you don't see ![the undock icon][2], but ![][3], then hold the mouse pressed for a few seconds to get the desired icon)
  2. Press Ctrl + Shift + J to open the console for this console. (On OSX use Cmd + Option + i)
  3. Use the following snippet to get an array of matches for your search term:
const searchHistory = query => {console.dir(JSON.parse(localStorage.getItem('consoleHistory')).filter(function(item){ return ~item.indexOf(query);}))}
eyecatchup /
Last active Jul 23, 2019
Creating a `GeneratorFunction` in JavaScript

Generator defined using the function* statement syntax:

// function *idMaker(){ <- also possible, even though no reference found
function* idMaker(){
  var index = 0;
  while(index < index+1)
    yield index++;
eyecatchup /
Last active Apr 6, 2022
Smooth Scroll behavior polyfill

The Scroll Behavior specification has been introduced as an extension of the Window interface to allow for the developer to opt in to native smooth scrolling. To date this has only been implemented in Chrome, Firefox and Opera.

There's a complete polyfill here (3.3KB minified). But most of the times, the following is enough for me (641 bytes minified):


Use as: scrollToElem('#elem-selector');