This file contains 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
/** | |
* Merge Sort Algorithm: "divide and conquer", "break you down in order to build you back up" | |
* Overview: | |
* --------- | |
* A recursive sorting algorithm where we 1) divide an unsorted array in half (dismantle big array into tiny sub-arrays) | |
* until we reach atomic values (< 2 - it's never 0), then we 2) sort the adjacent sub-arrays (left, right) and | |
* 3) merge the sorted sub-array values (put things back together) after each iteration | |
* | |
* Time Complexity (worst case): | |
* ----- |
This file contains 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
/** | |
* Greedy Algorithm (maximum daily profit from stock sale) - "let me see what my options are, first..." | |
* | |
* Overview: | |
* --------- | |
* By using Greedy Algorithms we can pass over the data once (O(n) time), storing values we find to be optimal, per our criteria, by | |
* comparing them to current values. We have to go over the entire set to do this, but we only have to do it once - yay! | |
* | |
* From Wikipedia: "A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal | |
* choice at each stage with the hope of finding a global optimum." |
This file contains 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
#!/bin/bash | |
## | |
# Git Open Remote Repo URL | |
# - by default opens at current tracked branch | |
# - opens with default web browser | |
# - supports HTTPS, ssh protocols using default "origin" | |
# Options: | |
# -b opens base repo URL | |
# -r change remote |
This file contains 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
/** | |
* Load HTML + scripts from a fetched HTML page (e.g. fetch a GitHub project page) | |
* | |
* PS - not really thatttttt useful. If you're using this, it's probably because | |
* of a bad design choice, initially. I just wanted a mini-challenge. | |
*/ | |
fetch('[URL_OF_WEBPAGE]') | |
.then((res) => res.text()) | |
.then((text) => { | |
this.apiRoot.innerHTML += text; |
This file contains 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
/** | |
* CachedCall | |
* | |
* Caches a network GET request. When called more than once, the closure returns the cached value. | |
* | |
* @param {func} asyncFunc - i.e. `async (arg) => {}` | |
* @param ...args - spreads arguments into an array | |
* @return {Promise} cachedResponse | unresolvedCall - thenable with a resolved value | |
*/ | |
export const CachedCall = (asyncFunc, ...args) => { |
This file contains 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
// __mocks__/mockFetch.js | |
const MockFetch = responseJson => ( | |
() => ( | |
new Promise(resolve => resolve({ | |
json: () => JSON.parse(JSON.stringify(responseJson)), | |
})) | |
) | |
); | |
This file contains 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
const sumAll = (arr) => { | |
// get our largest and smallest int's | |
const max = Math.max.apply(null, arr); | |
const min = Math.min.apply(null, arr); | |
// how many slots are there to add? | |
const slots = (max - min) + 1; | |
// create sparse array with number of slots found | |
const sumArr = Array(slots); |
This file contains 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 React, { Component } from 'react'; | |
export default class ErrorBoundary extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { error: null, errorInfo: null }; | |
} | |
componentDidCatch = (error, errorInfo) => catchFunc(error, errorInfo, this) |
This file contains 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://stackoverflow.com/questions/40985920/making-golang-gorilla-cors-handler-work/40987389#40987389 | |
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With"}) | |
originsOk := handlers.AllowedOrigins([]string{os.Getenv("ORIGIN_ALLOWED")}) | |
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"}) | |
// start server listen | |
// with error handling | |
log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), handlers.CORS(originsOk, headersOk, methodsOk)(router))) |
This file contains 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
# Dont forget to set the env variable "certdomain", and either fill in your email below or use an env variable for that too. | |
# Also note that this config is using the LetsEncrypt staging server, remove the flag when ready! | |
Resources: | |
sslSecurityGroupIngress: | |
Type: AWS::EC2::SecurityGroupIngress | |
Properties: | |
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]} | |
IpProtocol: tcp | |
ToPort: 443 |
OlderNewer