Skip to content

Instantly share code, notes, and snippets.

Avatar
👋
Halo Dunia!

Bagaskara LA bagaskarala

👋
Halo Dunia!
View GitHub Profile
@bagaskarala
bagaskarala / index.js
Last active December 1, 2022 08:34
Get nested object value in javascript or JSON
View index.js
const getValue = (path, obj) => {
const newPath = path.replace(/\]/g, '');
const arrayPath = newPath.split(/[\[\.]+/) || newPath;
return arrayPath.reduce((obj, k) => (obj ? obj[k] : obj), obj);
};
const doFilterObject = (rawData, filterKey) =>
filterKey.reduce((acc, cur) => {
const isNested = new RegExp(/\[|\./, 'g').test(cur);
const newData = isNested ? getValue(cur, rawData) : rawData[cur];
@bagaskarala
bagaskarala / index.js
Last active August 4, 2022 09:34
Telegram broadcast multiple groups using bot
View index.js
const chatIdList = ['xxx','yyy','zzz'];
const botToken = 'xxx';
const message = 'your message here';
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
for (let i = 0; i < chatIdList.length; i++) {
fetch(`https://api.telegram.org/bot${botToken}/sendMessage?chat_id=${chatIdList[i]}&text=${message}&parse_mode=markdown`)
.then(response => response.json())
.then(response => {
console.log({ status: `${chatIdList[i]}: ${response.ok}` });
@bagaskarala
bagaskarala / settings.json
Last active April 27, 2021 09:16
vue javascript vscode settings
View settings.json
// place it on your workspace .vscode folder
{
// EDITOR
// ----------------------------------------
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[javascript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" },
"[typescript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" },
"[vue]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" },
"[scss]": { "editor.defaultFormatter": "stylelint.vscode-stylelint" },
"[css]": { "editor.defaultFormatter": "stylelint.vscode-stylelint" },