Skip to content

Instantly share code, notes, and snippets.

View AnthonyLzq's full-sized avatar
🏠
Working from home

Anthony Luzquiños AnthonyLzq

🏠
Working from home
View GitHub Profile
@anhldbk
anhldbk / remove_mqtt_retained_msgs.md
Last active December 25, 2023 20:38
Remove MQTT retained messages using MQTT.js version 1.10.x
var mqtt    = require('mqtt');
var lodash = require('lodash');
var client  = mqtt.connect({ host: 'localhost', port: 1883 });

client.on('connect', function () {
  console.log('Connected')
  client.subscribe('presence');
});
@robmathers
robmathers / groupBy.js
Created October 25, 2018 23:18
A more readable and annotated version of the Javascript groupBy from Ceasar Bautista (https://stackoverflow.com/a/34890276/1376063)
var groupBy = function(data, key) { // `data` is an array of objects, `key` is the key (or property accessor) to group by
// reduce runs this anonymous function on each element of `data` (the `item` parameter,
// returning the `storage` parameter at the end
return data.reduce(function(storage, item) {
// get the first instance of the key by which we're grouping
var group = item[key];
// set `storage` for this instance of group to the outer scope (if not empty) or initialize it
storage[group] = storage[group] || [];