Skip to content

Instantly share code, notes, and snippets.

View KevinPy's full-sized avatar

Kevin Py KevinPy

View GitHub Profile
@KevinPy
KevinPy / format.ts
Last active May 20, 2025 09:23
Format lot of things
// ---------------------------------------------
// Number
// ---------------------------------------------
const amount = 1234567.89;
const priceFR = new Intl.NumberFormat(
"fr-FR",
{
style: "currency",
@KevinPy
KevinPy / Push_LO_blueprint.yaml
Created May 11, 2025 15:58
Zigbee2MQTT - Tuya 2-Button Scene Switch Push_LO
blueprint:
name: Zigbee2MQTT - Tuya 2-Button Scene Switch Push_LO
description: Automate your Tuya 2-Button Scene Switch (Push_LO) via Zigbee2MQTT.
domain: automation
input:
switch:
name: Push_LO Switch
description: Tuya 2-Button Scene Switch to use
selector:
entity:
@KevinPy
KevinPy / noob-request.js
Created November 25, 2021 10:29
Open Stackoverflow auto when your request fail
try {
// Do something
}
catch (error) {
const url = `https://stackoverflow.com/search?q=[js]+${error.message}`;
window.open(url, '_blank');
}
@KevinPy
KevinPy / filter.js
Created March 29, 2019 16:57
Filter unique values
const array = [1, 1, 2, 3, 5, 5, 1]
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // [1, 2, 3, 5]
@KevinPy
KevinPy / Horizontal2Vertical.js
Created November 28, 2018 14:43
Transform Array of Array => Horizontal to Vertical
const arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
const rotate = arr.reduce((value, row) => {
return row.map((_, i) => {
return [...(value[i] || []), row[i]];
});
@KevinPy
KevinPy / mix_array_object.js
Created March 22, 2018 08:14
[JS] Mix Arrays / Object
////////////////////////////////////////////////////////////////
/* Combine 2 arrays in Object with key */
////////////////////////////////////////////////////////////////
const arr1 = ['01', '02', '03'];
const arr2 = ['10', '20', '30'];
let obj = arr1.map((item, i) => {
return {
arr1: item,
arr2: arr2[i]