Skip to content

Instantly share code, notes, and snippets.

View davicedraz's full-sized avatar

Davi Cedraz davicedraz

View GitHub Profile
@davicedraz
davicedraz / logSocketIOLifeCycle.js
Created July 1, 2020 13:04
Function to log callbacks and websocket (Socket.io) lifecycle
export default function logSocketLifeCycle(socket) {
socket.on('connect', async () => {
console.log(`[WEBSOCKET]: Connect to Dojot WebSocket - ` + new Date().toLocaleString());
});
socket.on('disconnect', () => {
console.log(`[WEBSOCKET]: Connection closed - ` + new Date().toLocaleString());
});
socket.on('reconnecting', (attemptNumber) => {
@davicedraz
davicedraz / systemd.md
Last active June 4, 2020 17:11
Make the program run whenever a Unix Machine boots

In order to have a command or program run when the Pi boots, you can add it as a service. Once this is done, you can start/stop enable/disable from the linux prompt.

Create a service:

touch iot.service

Copy the content:

@davicedraz
davicedraz / OTAUpdate.h
Created April 21, 2020 20:16
Enable OTA Update on ESP8266 devices
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <ESP8266httpUpdate.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#define THIS_DEVICE "esp_01l"
#define CURRENT_VERSION "0_0_1"
#define DEBUG_HTTP_UPDATE false
@davicedraz
davicedraz / .eslintrc.json
Last active April 26, 2020 00:55
VSCode settings
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "prettier",
"plugins": ["prettier"],
"globals": {
"Atomics": "readonly",
@davicedraz
davicedraz / Vibration.js
Last active June 14, 2022 11:30
React Native service to continuous measures smartphone vibration by Accelerometer and Gyroscope using Observer pattern
import { SensorTypes, accelerometer, gyroscope, setUpdateIntervalForType } from "react-native-sensors";
import { map, filter } from "rxjs/operators";
class Vibration {
constructor({ updateInterval, offset }, callback) {
this.readings = { accelerometer: 0, gyroscope: 0, vibration: 0 };
this.updateInterval = updateInterval;
this.callback = callback;