Skip to content

Instantly share code, notes, and snippets.

# Q: what are all the shortest paths from a single node to all other nodes?
"""
Example: All shortest paths from id:0 to all other nodes
{0: [[]],
1: [[1]],
2: [[2]],
3: [[1, 3], [2, 3]],
4: [[1, 3, 4], [2, 3, 4]],
5: [[1, 3, 4, 5], [2, 3, 4, 5]],
# These are SP500 prices for practicing sliding window and array problems.
# Q: What date was the largest adjusted close price?
# Q: What was the longest period of open prices between $3000.00 and $4000.00?
# Q: What was the longest period of increasing open prices?
# Q: What is the most profitable period to buy at the open and sell at the close?
# Q: What is the highest average close price in any 6 month consecutive window of time?
headers = ["Date","Open","High","Low","Close","Adj Close"]
data = [
import random
def is_terminal(token):
return token[0] != "_"
def expand(grammer, tokens):
result = []
for token in tokens:
if is_terminal(token):
result.append(token)
@theptrk
theptrk / typescript-react-type-cheat-sheet.tsx
Last active November 14, 2021 02:18
This cheatsheet is for working with types in typescript react
/* Formatting dates */
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
// leave locale undefined (varies according to default locale)
new Date().toLocaleDateString(undefined, {
year: "numeric",
month: "2-digit",
day: "2-digit",
})
/* document event: keydown */
@theptrk
theptrk / react-click-outside.js
Created September 23, 2021 14:39
react click outside of container / form
// answer comes from: https://stackoverflow.com/questions/32553158/detect-click-outside-react-component/54292872#54292872
// this adds typescript and I've used this for a form
/*
Custom Hook
*/
function useOuterClick(callback: any) {
const innerRef = useRef() as React.MutableRefObject<HTMLInputElement>;
const callbackRef = useRef() as React.MutableRefObject<HTMLInputElement>;
@theptrk
theptrk / README.md
Last active June 23, 2020 16:13
pyenv - get available versions for installation

First check the python downloads page to view the current releases

$ open https://www.python.org/downloads/

This produces the list of ALL available pyenv versions

$ pyenv install --list

  ...
  pypy3-dev
@theptrk
theptrk / openweather_api_example.html
Last active June 3, 2020 00:40
This uses the OpenWeather current weather data API: https://openweathermap.org/current
<!DOCTYPE html>
<html>
<head>
<title>Open Weather API</title>
<style type="text/css">
pre {
background-color: #f1f1f1;
padding: 5px;
margin: 5px;
border-radius: 5px;
@theptrk
theptrk / optional_chaining.js
Last active May 20, 2020 16:06
Optional Chaining in javascript - avoid crashing your app
// This is an example of Optional Chaining
const adventurer = {
name: 'Alice',
cat: {
name: 'Dinah'
}
};
const dogName = adventurer.dog?.name;
console.log(dogName);
@theptrk
theptrk / app.js
Created May 18, 2020 14:31
This is a starter html snippet
// js goes here
console.log("hello js")
@theptrk
theptrk / html_onsubmit.html
Created May 17, 2020 15:42
HTML onsubmit connected to javascript function using a todo list input example
<!DOCTYPE html>
<html>
<head>
<title>Hello onsubmit</title>
</head>
<body>
<h1>Hello onsubmit</h1>
<form onsubmit="handleForm()">
<input type="text" name="todo" autocomplete="off">
<button type="submit">Create Todo</button>