This file contains hidden or 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
const sat = (val) => { // saturation helper function | |
if (val > 255) return 255; | |
if (val < 0) return 0; | |
return val | 0x00; // returning integer | |
}; | |
const pixelData = await imageLoader("./seaside.png"); // get the pixel data of the backgroung image in RGBA format | |
const buffer = new Uint8Array(W * H * 1.5); // byte buffer for the incoming frame in YUV 422 format | |
const bufferRGB = new Uint8Array(W * H * 4); // byte buffer for the result frame in RGBA format |
This file contains hidden or 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
const W = 640; // image width | |
const H = 360; // image height | |
async function start() { | |
const cam = (await navigator.mediaDevices.enumerateDevices()).filter( | |
(device) => device.kind === "videoinput" | |
)[0]; // select the first camera | |
const { deviceId } = cam; | |
const constraints = { |
This file contains hidden or 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
navigator.bluetooth | |
.requestDevice({ | |
filters: [{ services: [0x2a6e, 0x2a6f] }, { namePrefix: "Ambient" }], | |
}) | |
.then((device) => { | |
console.log("> Requested " + device.name); | |
device.addEventListener("advertisementreceived", (event) => { | |
console.log("Advertisement received. Device Name: " + event.device.name); | |
console.log(" RSSI: " + event.rssi); |
This file contains hidden or 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
async function scan() { | |
navigator.bluetooth.addEventListener("advertisementreceived", (event) => { | |
console.log( | |
`Advertisement received, device: ${event.name}, RSSI: ${event.rssi}dB` | |
); | |
event.manufacturerData.forEach((valueDataView, key) => { | |
console.log("Manufacturer data:", `0x${valueDataView.getUint16().toString(16)}`); | |
}); | |
event.serviceData.forEach((valueDataView, key) => { | |
console.log("Service data:", `0x${valueDataView.getUint16().toString(16)}`); |
This file contains hidden or 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
// create the worker from a JavaScript source | |
const myWorker = new Worker("/src/myworker.js"); | |
// listen to the results | |
myWorker.onmessage = function (e) { | |
console.log("worker result", e.data); | |
}; | |
// kick it on | |
myWorker.postMessage("start"); |
This file contains hidden or 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
// blocking operation wrapped in promise | |
const blockingPromise = () => | |
new Promise((resolve) => { | |
const result = blockingFunction(); | |
resolve(result); | |
}); | |
const promiseRun = () => { | |
blockingPromise().then((result) => { | |
console.log(`result: ${result}`); |
This file contains hidden or 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
const run = () => { | |
const result = blockingFunction(); | |
return result; | |
}; |
This file contains hidden or 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
// optimized batch update | |
yield put ( batchUpdate( { | |
subSetItterator: item => item.rating < 5, | |
updateItterator: item => {...item, flag:true } | |
}); |
This file contains hidden or 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
// batch delete example | |
yield put ( batchDeleteItems({ itterator: item => item.rating < 5 }) ) ; | |
// batch update | |
yield put ( batchUpdate( { itterator: item => item.rating < 5 ? {...item, flag:true } : item } ) |
This file contains hidden or 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
// idsToDelete is an array of item IDs to be deleted | |
const data = yield select( someItemsFromStore() ) | |
idsToDelete = data.filter( item => item.rating < 5 ) | |
// yielding put effects one-be-one | |
idsToDelete.forEach( id => { | |
yield put(deleteItem({id:i})) | |
}); | |
// using yield all |