This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DatabaseConnection } from '../__nonpublished_modules__/simple-rds-dao/types'; | |
import { dbConnection } from './database'; | |
/** | |
* wrap the function with a "higher order function" that automatically provides a managed database connection to the wrapped function | |
* | |
* inspired by react higher order components: https://reactjs.org/docs/higher-order-components.html | |
*/ | |
export const withDatabaseConnection = <T extends (args: { dbConnection: DatabaseConnection }) => any>( | |
targetFunction: T, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards | |
export type HasIdDefined<T> = T & { id: number }; | |
export const hasIdDefined = <T extends { id?: undefined | number }>(obj: T): obj is HasIdDefined<T> => { | |
return !!obj.id; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { detectPeaksWithRollingWindowZScore } from './detectPeaksWithRollingWindowZScore'; | |
describe('detectPeaksWithRollingWindowZScore', () => { | |
it('should be accurate for the example in the original implementation', () => { | |
let testData: number[] = [ | |
1, | |
1, | |
1.1, | |
1, | |
0.9, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tslint:disable max-classes-per-file | |
// TODO: publish as a seperate module | |
/* | |
ManagedDatabaseConnection: | |
- solves: | |
- reusing the same connection across many function invocations (e.g., lambda container reuse) | |
- closing the connection if no lambdas are using it automatically | |
- contract: | |
- start: state that need a connection | |
- end: state that no longer need connection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"pack": "npm pack && tar -xvzf *.tgz && rm -rf package *.tgz" | |
per https://medium.com/@jdxcode/for-the-love-of-god-dont-use-npmignore-f93c08909d8d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const calculateWeightedStandardDeviation = ({ values, weights }: { values: number[], weights: number[] }) => { | |
const weightedCount = weights.reduce((sum, value) => sum + value, 0); | |
// 1. calculate the weighted mean | |
const weightedSum = values.reduce((sum, value, index) => { | |
const weight = weights[index]; | |
return sum + value * weight; | |
}, 0); // tslint:disable-line align | |
const weightedMean = weightedSum / weightedCount; // weighted mean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | |
<iframe id = 'header_source_iframe' style = 'position:absolute; display:none;'></iframe> | |
<script> | |
document.domain = location.host.split(".").slice(-2).join("."); // remove subdomain from domain for cross-origin iframe support | |
var iframe = document.querySelector("#header_source_iframe"); | |
iframe.onload = function(){ | |
console.log("attaching header to the document."); | |
iframe.contentWindow.promise_dom_rendered | |
.then(()=>{ | |
iframe.contentWindow.attach_header_to_window(window) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This code is based on the LwIP SNTP example | |
*/ | |
// glibc dependencies: | |
#include <string.h> | |
#include <time.h> | |
#include <sys/time.h> | |
// espress IDF dependencies | |
#include "freertos/FreeRTOS.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## with ubuntu terminal | |
########################################## | |
## setup env | |
########################################## | |
#http://iot-bits.com/esp32/getting-started-with-esp32-esp-idf-part-2/ | |
#http://esp-idf.readthedocs.io/en/latest/get-started/linux-setup.html | |
## 1 download package dependencies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div style = 'width:500px; height:500px;'> | |
<canvas id="canvas" width="400" height="400"></canvas> | |
</div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script> | |
<script> | |
window.chartColors = { |