Skip to content

Instantly share code, notes, and snippets.

View NielsLeenheer's full-sized avatar

Niels Leenheer NielsLeenheer

View GitHub Profile
var kb = require("ble_hid_keyboard");
var services = {
0x180a: {
0x2a50: {
value: [
0x01, /* Use USB Vendor IDs */
0xac, 0x05, /* Apple */
0x5a, 0x02, /* Internal Keyboard */
0x00, 0x00
@NielsLeenheer
NielsLeenheer / console.hex.js
Created November 26, 2017 20:22
console.hex
console.hex = (d) => console.log((Object(d).buffer instanceof ArrayBuffer ? new Uint8Array(d.buffer) :
typeof d === 'string' ? (new TextEncoder('utf-8')).encode(d) :
new Uint8ClampedArray(d)).reduce((p, c, i, a) => p + (i % 16 === 0 ? i.toString(16).padStart(6, 0) + ' ' : ' ') +
c.toString(16).padStart(2, 0) + (i === a.length - 1 || i % 16 === 15 ?
' '.repeat((15 - i % 16) * 3) + Array.from(a).splice(i - i % 16, 16).reduce((r, v) =>
r + (v > 31 && v < 127 || v > 159 ? String.fromCharCode(v) : '.'), ' ') + '\n' : ''), ''));
@NielsLeenheer
NielsLeenheer / Duck.gltf
Last active August 1, 2017 20:20
WebGL / Three.js ducks
{
"asset": {
"generator": "COLLADA2GLTF",
"version": "2.0"
},
"scene": 0,
"scenes": [
{
"nodes": [
0
@NielsLeenheer
NielsLeenheer / screenmirror-puck.js
Last active April 4, 2020 12:13
Toggle screen-mirroring on the new MacBook Pro using a Puck.js
var kb = require("ble_hid_keyboard");
var services = {
0x180a: {
0x2a50: {
value: [
0x01, /* Use USB Vendor IDs */
0xac, 0x05, /* Apple */
0x5a, 0x02, /* Internal Keyboard */
0x00, 0x00
@NielsLeenheer
NielsLeenheer / geolocation.js
Last active June 22, 2020 15:02
Make navigator.geolocation.getCurrentPosition more reliable
(function() {
if (navigator.geolocation) {
function PositionError(code, message) {
this.code = code;
this.message = message;
}
PositionError.PERMISSION_DENIED = 1;
PositionError.POSITION_UNAVAILABLE = 2;
Consoles:
Xbox 360 - Internet Explorer 9
Xbox One - Internet Explorer 10
Sony PlayStation 3 - Netfront
Sony PlayStation 4 - Chromium based
Sony PlayStation TV - Netfront NX
Nintendo Wii - Opera 9.6, Presto
Nintendo Wii U - Netfront NX
@NielsLeenheer
NielsLeenheer / Native app communication
Last active May 1, 2023 13:16
How a web app running on HTTPS can communicatie with local services
I have a web app that needs to talk to point of sale hardware: receipt printers, customer displays,
cash drawers and payment terminals. Direct communication from the web app with these devices is
impossible, so I created a native app that can be installed on the computer that can talk to the
devices. The app runs a web server that exposes these devices using a REST api.
The native app registers itself upon startup with a webservice. It sends its own IP address on
the local network and the server also sees the external IP address of the network. The web app
sends a discovery request to the webservice and it receives all the local IP addresses which
have the same external IP address.
@NielsLeenheer
NielsLeenheer / Sony
Last active May 24, 2017 22:35
Google Chrome on Sony devices
Sony devices ship with Google Chrome as the default browser. Google Chrome is baked
into the firmware of the device. Different versions of the firmware come with different
versions of Google Chrome.
Usually the version that comes with the firmware is updated using Google Play, however...
When first starting up the device Sony does not ask the user to log into Google Play.
This means that unless you manually open Google Play and log in, the devices does not
receive any updates using Google Play. In this case Google Chrome is only updated when
the user installs a firmware update.
@NielsLeenheer
NielsLeenheer / LG Browser
Last active May 24, 2017 22:35
LG Browser
Chromium 30
458 / 555
https://html5test.com/results/related/7c791b543cbd7705f547a0a30e5404cf.html
- G Pad 8.3 Android 4.4.2
- G Pro 2 Android 4.4.2
- G2 Android 4.4.2
- G2 mini Android 4.4.2
- L65 Android 4.4.2
- L70 Android 4.4.2
@NielsLeenheer
NielsLeenheer / HTC Sense Browser
Created February 4, 2015 13:03
HTC Sense Browser
Note: All versions of the HTC Sense browser listed below send the following header: X-Requested-With: com.htc.sense.browser
Note: The difference between the two WebKit based versions are mostly which form field types are supported
Webkit
368 / 555
https://html5test.com/results/related/127d2c84dc7e495a6ed4ddd8ceccac2a.html