Skip to content

Instantly share code, notes, and snippets.

View flerokoo's full-sized avatar

Emile Shodiev flerokoo

  • Georgia, Tbilisi
  • 06:21 (UTC +04:00)
View GitHub Profile
@flerokoo
flerokoo / client.js
Created April 21, 2023 08:46
Save server for generative art (no dependencies)
/**
*
* @param {string} data base64 encoded png image
* @param {string} fileName
* @returns {Promise<void>}
*/
export async function savePng(data, filePath, {port = 3001, host = "http://localhost"} = {}) {
const response = await fetch(`${host}:${port}`, {
body: JSON.stringify({data, filePath}),
method: "POST",

SETUP

  • Copy code to your project
  • Install dependencies: npm i express body-parser cors argparse

USAGE

Run server

node server.js --savePath ./save/directory/ --port 4000

isOculusGo() {
return /Pacific.+OculusBrowser/i.test(window.navigator.userAgent) // oculus browser
|| /SAMSUNG.?Pacific/i.test(window.navigator.userAgent); // samsung internet
}
isOculusQuest() {
return /Quest.+OculusBrowser/i.test(window.navigator.userAgent); // oculus browser
// TODO add support for Samsung Internet when (and if) it is released for Quest
}
@flerokoo
flerokoo / react-rerender-cause.js
Created August 20, 2019 10:11
Find out what causes react component rerender with this snippet
componentDidUpdate(prevProps, prevState) {
if(this.props && prevProps) Object.entries(this.props).forEach(([key, val]) =>
prevProps[key] !== val && console.log(`Prop '${key}' changed ${JSON.stringify(prevProps[key])} -> ${JSON.stringify(this.props[key])}`)
);
if(this.state && prevState) Object.entries(this.state).forEach(([key, val]) =>
prevState[key] !== val && console.log(`State '${key}' changed`)
);
}

Simple demo of how consul service discovery works within Node and Docker.

In this example there are 3 containers: master and 2 workers. When master receives a request from a client, it leverages consul to find all workers in the cluster. After that it performs GET request to a random worker and pipes it's response to client.