Skip to content

Instantly share code, notes, and snippets.

View clarkmcc's full-sized avatar

Clark McCauley clarkmcc

View GitHub Profile
@clarkmcc
clarkmcc / aggregate.go
Created January 13, 2020 22:46
Handy functions for creating MongoDB aggregate pipelines in Go
package aggregate
import "go.mongodb.org/mongo-driver/bson"
type Operation bson.M
// The Pipe functions similar to the RxJS pipe function
// (https://rxjs-dev.firebaseapp.com/api/index/function/pipe) in that
// it accepts a set of functions as parameters. Each function receives
// as its input, the output of the previous function. The allows you
@clarkmcc
clarkmcc / util.go
Created January 13, 2020 22:34
Accepts a slice of strings and returns a slice of slices of strings where each child slices's length is the length of the size parameter
package util
// Accepts a slice of strings and returns a slice of slices of strings where each child slices's length
// is the length of the batchSize
func StringBatch(size int, s []string) [][]string {
var b [][]string
for size < len(s) {
s, b = s[size:], append(b, s[0:size:size])
}
b = append(b, s)
@clarkmcc
clarkmcc / getModuleVersions.ts
Created October 29, 2019 01:41
This method is attached to a server-side inversify service that retrieves a list of executable's depending on the provided parameters. It returns a list of those executables (after parsing them) to the called. This snippet makes use of several string methods (split, pop, replace) as well as array methods (filter, forEach).
public async getModuleVersions(modulePrefix: string): Promise<any> {
try {
let fileExtension: string;
let moduleLocation: string;
switch (modulePrefix) {
case 'module1':
fileExtension = 'exe';
moduleLocation = '';
break;
@clarkmcc
clarkmcc / mr-test.ts
Created September 16, 2019 21:11
Test New Meter Read Format
const myMeterRead = new MeterRead({
'reportDtTm' : null,
'pageCounts' : {
'equiv' : {
'total' : {
'displayName' : 'Total',
'value' : 6660
},
'totalBlack' : {
'displayName' : 'Total Black',
@clarkmcc
clarkmcc / device.ts
Last active September 16, 2019 16:18
AWS IoT Device - Connect over port 443
/**
* Creates a new instance of the iot.device class that we can connect to and listen on
* @private
* @type {*}
* @memberof Device
*/
private _device: any = iot.device({
keyPath: __dirname + "device.private.key",
certPath: __dirname + "device.cert.pem",
caPath: __dirname + "root-CA.crt", // https://www.amazontrust.com/repository/AmazonRootCA1.pem