Skip to content

Instantly share code, notes, and snippets.

View peaBerberian's full-sized avatar

Paul Berberian peaBerberian

View GitHub Profile
// ================================ HTML-LOGGER ================================
//
// This code will display a semi-opaque div HTMLElement on the top of the screen
// containing log produced through `console` methods (and optionally logging
// requests).
//
// You can configure it by updating the variables below.
/**
* To set to `true` to also show HTTP(S) requests made through either the
const base64abc = [
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/",
];
/**
* Convert an array of bytes into a base64 string.
@peaBerberian
peaBerberian / websocket_client.js
Last active April 22, 2022 08:28
Log client/server for local debugging on embedded devices
// Note: if not on localhost, don't forget to add something like:
// `<meta http-equiv="Content-Security-Policy" content="connect-src 'self' ws: wss:">`
// to the HTML page to allow websocket connections to external websites
// SERVER_URL of the server (relative to the client).
// Localhost by default
const SERVER_URL = "ws://127.0.0.1";
// Port on which the server is listening.
// If going through ngrok, you can set it to `null`
/*
// This constant can also be computed with the following algorithm:
const base64abc = [],
A = "A".charCodeAt(0),
a = "a".charCodeAt(0),
n = "0".charCodeAt(0);
for (let i = 0; i < 26; ++i) {
base64abc.push(String.fromCharCode(A + i));
}
for (let i = 0; i < 26; ++i) {
{
const cLog = console.log;
const cWarn = console.warn;
const cError = console.error;
const cInfo = console.info;
const cDebug = console.debug;
function addTSToArgumentList(argList) {
const ret = [performance.now()];
for (let i = 0; i < argList.length; i++) {
@peaBerberian
peaBerberian / initial_seek_after_segment_push.html
Created January 8, 2021 14:52
Initial seek after media segment pushed
<!DOCTYPE html>
<!--
This file allows to quickly test if starting a content at a position different
from `0` after the media segments have been pushed works.
To do that:
1. You might want to update the variables at the top of the script (default
values should be alright but maybe the content is not available anymore).
@peaBerberian
peaBerberian / initial_seek_after_loaded_metadata.html
Created January 8, 2021 14:48
Initial seek after loaded metadata
<!DOCTYPE html>
<!--
This file allows to quickly test if starting a content at a position different
from `0` works.
More precizely, it tests that seeking as soon as the loadedmetadata event is
received works on the current platform.
To do that:
function be4toi(bytes, offset) {
return ((bytes[offset + 0] * 0x1000000) +
(bytes[offset + 1] * 0x0010000) +
(bytes[offset + 2] * 0x0000100) +
(bytes[offset + 3]));
}
function be8toi(bytes, offset) {
return (((bytes[offset + 0] * 0x1000000) +
(bytes[offset + 1] * 0x0010000) +
(bytes[offset + 2] * 0x0000100) +
/**
* Pretty print a TimeRanges Object, to see the current content of it in a
* one-liner string.
*
* @example
* This function is called by giving it directly the TimeRanges, such as:
* ```js
* prettyPrintBuffered(document.getElementsByTagName("video")[0].buffered);
* ```
*
!function(a,b,c,d,e,f,g,h,i){function j(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=s&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=s&f+1],c=c*d+h[s&(h[f]=h[g=s&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function k(a,b){var c,d=[],e=typeof a;if(b&&"object"==e)for(c in a)try{d.push(k(a[c],b-1))}catch(f){}return d.length?d:"string"==e?a:a+"\0"}function l(a,b){for(var c,d=a+"",e=0;e<d.length;)b[s&e]=s&(c^=19*b[s&e])+d.charCodeAt(e++);return n(b)}function m(c){try{return o?n(o.randomBytes(d)):(a.crypto.getRandomValues(c=new Uint8Array(d)),n(c))}catch(e){return[+new Date,a,(c=a.navigator)&&c.plugins,a.screen,n(b)]}}function n(a){return String.fromCharCode.apply(0,a)}var o,p=c.pow(d,e),q=c.pow(2,f),r=2*q,s=d-1,t=c["seed"+i]=function(a,f,g){var h=[];f=1==f?{entropy:!0}:f||{};var o=l(k(f.entropy?[a,n(b)]:null==a?m():a,3),h),s=new j(h);return l(n(s.S),b),(f.pass||g||function(a,b,d){return d?(c[i]=a,b):a})(function(){