Skip to content

Instantly share code, notes, and snippets.

View ariesmcrae's full-sized avatar
💭
typescript, node.js, aws, java, go (golang)

A. M. ariesmcrae

💭
typescript, node.js, aws, java, go (golang)
View GitHub Profile
@ariesmcrae
ariesmcrae / FindEnumInList.java
Created December 9, 2019 11:58
Java: Find enum in list of enums
private static <T extends Enum<T>> boolean isInputInTheList(T input, List<? extends Enum<?>> list) {
return Optional.ofNullable(list)
.map(Collection::parallelStream)
.orElseGet(Stream::empty)
.anyMatch(x -> input!= null && ((Enum) x).name().equals(input.name()));
}
// or for the longer version
private static <T extends Enum<T>> boolean isInputInTheList(T input, List<? extends Enum<?>> list) {
@ariesmcrae
ariesmcrae / Test.ts
Created November 16, 2020 05:31
Typescript object with key/value pairs that are not known up front
interface ConfigDto extends Record<string, unknown> {}
const myConfigDto: ConfigDto = {
baseUrl: "http://test.com",
refershRateInSeconds: 2,
otherStuff: {a: "a", b: "b"},
showSpinner: true,
}
console.log(JSON.stringify(myConfigDto, null, 2))
@ariesmcrae
ariesmcrae / EventPublisher.js
Last active July 11, 2021 12:00
NodeJS AWS SDK for JavaScript v2 SNS: publishing a message from your local laptop when behind your corporate firewall
// I was getting this error when publishing sns from my local laptop:
// arn:aws:sns:ap-southeast-2:396497070286:int-afl-sns-topic
// Inaccessible host: `sns.ap-southeast-2.amazonaws.com'.
// This service may not be available in the `ap-southeast-2' region.",
// "code":"UnknownEndpoint",
// "region":"ap-southeast-2",
// "hostname":"sns.ap-southeast-2.amazonaws.com"
// getaddrinfo ENOTFOUND sns.ap-southeast-2.amazonaws.com
// This is the solution

Keybase proof

I hereby claim:

  • I am ariesmcrae on github.
  • I am aries (https://keybase.io/aries) on keybase.
  • I have a public key whose fingerprint is 8DC0 BF59 ACB5 5CC5 BF41 2E35 5C94 7AC4 1E65 49C2

To claim this, I am signing this object:

@ariesmcrae
ariesmcrae / Logger.ts
Created June 9, 2022 11:43
node.js singleton example in typescript
class Logger {
public error(msg: string, exception: Error): void {
console.error(msg, exception);
}
}
const instance = new Logger();
// Prevent modification to properties and values of the object.
@ariesmcrae
ariesmcrae / M5Stack.ino
Created September 4, 2022 10:11
Arduino IDE: M5Stack Core 2 with ENVIII Temperature / Humidity sensor and battery level
#include <M5Core2.h>
#include <M5_ENV.h>
SHT3X sht30;
float temperature = 0.0;
float humidity = 0.0;
void setup() {
M5.begin(); // Init M5Core2.
@ariesmcrae
ariesmcrae / M5Stack.ino
Last active September 4, 2022 10:32
Arduino Cloud: M5Stack Core 2 with ENV III temperature/humidity sensor
#include "thingProperties.h"
// M5Unit-ENV - Version: 0.0.6
#include <M5_ENV.h>
SHT3X sht30;
void setup() {
Wire.begin(); // Wire init, adding the I2C bus.
@ariesmcrae
ariesmcrae / M5Stack-Core-2.py
Last active September 17, 2022 02:48
M5Stack Core2 ESP32 python. Pumps temperature/humidity data regularly to AWS Core IoT MQTT
from m5stack import *
from m5stack_ui import *
from uiflow import *
import time
import unit
from IoTcloud.AWS import AWS
import json
screen = M5Screen()
screen.clean_screen()
@ariesmcrae
ariesmcrae / M5StickPlus.py
Last active September 18, 2022 12:21
M5Stack M5StickC-PLUS ESP32 Python. Pumps temperature/humidity data regularly to AWS Core IoT MQTT
from m5stack import *
from m5ui import*
from uiflow import *
import time
import unit
from IoTcloud.AWS import AWS
import json
setScreenColor(0x111111)
@ariesmcrae
ariesmcrae / nvm.md
Created September 28, 2022 05:23
nvm 101

Find the lastest node.js 16 LTS to cherry pick from

nvm ls-remote

Install the desired version of node.js 16 LTS

nvm install v16.17.1

Switch to the newly installed node.js 16 LTS

nvm use v16.17.1

Pin to the latest version of node.js 16 LTS so that it sticks to that version even if you've exited the command line