Skip to content

Instantly share code, notes, and snippets.

View matthewoestreich's full-sized avatar
♠️
👋

Matt Oestreich matthewoestreich

♠️
👋
View GitHub Profile
@matthewoestreich
matthewoestreich / babel.ts.html
Created August 29, 2021 17:19
Babel+TS in browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="root"></div>
@matthewoestreich
matthewoestreich / capsFirstLetter.js
Created August 21, 2021 16:12
caps first letter in str
function capsFirstLetter(str) {
if (typeof str !== "string") {
throw new Error("param `str` must be a string!");
}
const firstLetterCaps = str[0].toUpperCase();
const restOfString = str.slice(1);
return firstLetterCaps + restOfString;
}
const myStr = "something";
@matthewoestreich
matthewoestreich / index.js
Created August 11, 2021 19:41
ssrPocNodeJS.js
const http = require("http");
const https = require("https");
const url = require("url");
const server = http.createServer((request, response) => {
const path = url.parse(request.url).pathname;
switch (path) {
/**
* This is just documentation comments, doesn't do anything to the code
* @route '/' home path
class House {
# Lower case bc private
hidden [Room[]]$rooms
# Constructor (PoSH support overloading, which is huge)
House() {
$this.rooms = Room[];
}
# [Room[]] means our return type is an array of Rooms
class House {
constructor() {
this.rooms = [];
}
getRooms() {
return this.rooms;
}
addRoom(name, props) {
this.rooms.push({ name, props });
}
@matthewoestreich
matthewoestreich / house.ts
Last active July 30, 2021 00:25
House class with rooms
/**
* This code would live inside the library.
*/
class House {
// Private
#rooms: Array<Room> = [];
getRooms(): Array<Room> {
return this.#rooms;
@matthewoestreich
matthewoestreich / findDailyHigh30MinTimeFrame.js
Last active July 4, 2021 05:26
fmpcloud.io locate in which 30 min time frame the high of the day occurred.
#!/usr/bin/env node
const fetch = require("node-fetch");
// Main
(async () => {
const apiKey = "<your_api_key>";
const symbol = "TSLA";
const from = "2021-06-15";
const to = "2021-06-19";
@matthewoestreich
matthewoestreich / getRelativeDate.js
Last active March 2, 2021 03:08
Get relative date from a known date. Before or after N days.
#!/usr/bin/env node
/**
* Use this function like:
* `getRelativeDate("before", 3, new Date("7/2/1992"));`
*
* @param {String} beforeOrAfter ("after"|"before")
* @param {Number} numberOfDays number of days before or after the 'date' param
* @param {Date} date the 'RelativeToDate' in 'getDateRelativeToDate'
*
* @return * If "before" or "after" is not used as the value of the `beforeOrAfter`
@matthewoestreich
matthewoestreich / prettyPrintJSON.go
Created November 28, 2020 07:14
Pretty Print JSON strings in Golang
func prettyPrint(i interface{}) {
prettyJSON, err := json.MarshalIndent(i, "", " ")
if err != nil {
fmt.Printf("Error : %s \n", err.Error())
}
fmt.Printf("%s\n", string(prettyJSON))
}
@matthewoestreich
matthewoestreich / server.js
Created November 17, 2020 22:04
Vanilla Node server demonstrating the Node event loop
const http = require("http");
const { log } = console;
// This just lets us block the event loop
const workFor = 5 // seconds
const work = (s = workFor) => new Promise(r => setTimeout(r, s * 1000));
const appPort = 8888
let reqCount = 0