Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / 1-nightwatch.md
Last active August 18, 2022 13:56
Running Nightwatch automated testing with Selenium on Windows. Quick-start setup.
  1. Install the chromedriver package via:
npm install chromedriver --save

or install with a local binary via:

npm install chromedriver --chromedriver_filepath=C:\\YOUR_PROJECT_PATH\\chromedriver.zip
#
# [2017-07-10] Challenge #323 [Easy] 3SUM
# https://www.reddit.com/r/dailyprogrammer/comments/6melen/20170710_challenge_323_easy_3sum/
#
# Demo at http://www.r-fiddle.org/#/fiddle?id=Qzdqx96U&version=2
#
# In computational complexity theory, the 3SUM problem asks if a given set of n real numbers contains three elements that sum to zero.
#
# by Kory Becker
# http://primaryobjects.com
var date = new Date().toISOString();
// 2017-07-19T13:52:37.361Z
console.log(date);
// 2017-07-19T13:52:37Z
console.log(moment.utc(date).format());
// 2017-07-19T09:52:37-04:00
console.log(moment.utc(date).local().format());
@primaryobjects
primaryobjects / best.js
Last active July 14, 2017 17:21
Find the most profitable buy and sell point from a list of prices. https://jsfiddle.net/L1ukry89/2/
var bestPurchase = function(prices) {
var best = null;
var current = {};
prices.forEach(function(price) {
if (!current.min || price < current.min) {
// New buy-point.
if (current.min && current.max) {
current.profit = current.max - current.min;
@primaryobjects
primaryobjects / etf-cluster.R
Last active November 6, 2017 00:41
K-means clustering on Vanguard ETF funds by Year 1, 5, and 10 returns.
packages <- c('flexclust', 'caTools')
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))
}
library(flexclust)
library(caTools)
# Read the data set. Source: https://investor.vanguard.com/mutual-funds/list#/etf/name/month-end-returns
data <- read.csv2('vanguard-etf.tsv', header=T, sep='\t', stringsAsFactors=F)
@primaryobjects
primaryobjects / Bear-Market.md
Last active July 4, 2017 18:34
An experienced investor describes a bear market.

Description of a Bear Market

Our family owned "Larimore's Diner" in Foxboro, Mass. in 1929 (I was 5 years old at that time). When the depression hit, we lost the Diner and moved into my grandfather's home in Miami. Grandfather, who was a millionaire investor and chief executive of an investment trust company, lost everything--including the Miami home we lived in.

BEAR MARKET OF 1929-1937 (Dow plunged 89%)

-1929--1930--1931--1932

(-31%)(-25%)(-43%)(-08%) Large Cap Stocks

(-34%)(-35%)(-47%)(-06%) Mid/Small Cap Stocks

@primaryobjects
primaryobjects / commit.png
Last active May 31, 2023 09:34
How to setup prettier as a pre-commit hook for Git commits.
commit.png
@primaryobjects
primaryobjects / colors.R
Last active May 9, 2021 17:11
Plotting RGB color points on a 2D plot in R. Clustering the data into groups and plotting the resulting grouping.
# Generate a set of random colors.
colors <- as.data.frame(t(sapply(1:1000, function(i) {
parts <- sample(0:255, 3)
c(red = parts[1], green = parts[2], blue = parts[3], hex = rgb(parts[1], parts[2], parts[3], maxColorValue = 255))
})), stringsAsFactors = F)
colors$red <- as.numeric(colors$red)
colors$green <- as.numeric(colors$green)
colors$blue <- as.numeric(colors$blue)
#
# [2017-06-12] Challenge #319 [Easy] Condensing Sentences
# https://www.reddit.com/r/dailyprogrammer/comments/6grwny/20170612_challenge_319_easy_condensing_sentences/
#
# Demo at http://www.r-fiddle.org/#/fiddle?id=p7yvuSZQ&version=2
#
# Compression makes use of the fact that repeated structures are redundant, and it's more efficient to represent the pattern and the count or a reference to it. Siimilarly, we can condense a sentence by using the redundancy of overlapping letters from the end of one word and the start of the next. In this manner we can reduce the size of the sentence, even if we start to lose meaning.
# For instance, the phrase "live verses" can be condensed to "liverses".
# In this challenge you'll be asked to write a tool to condense sentences.
#
@primaryobjects
primaryobjects / index.html
Last active July 10, 2023 16:24
Calling a React component's methods from outside of React. Demo https://plnkr.co/edit/E6lPrL331KGxoikGinFm?p=preview
<!DOCTYPE html>
<html>
<head>
<script data-require="jquery@3.1.1" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script data-require="tether@*" data-semver="1.4.0" src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<link data-require="bootstrap@4.0.5" data-semver="4.0.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<script data-require="bootstrap@4.0.5" data-semver="4.0.5" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js"></script>
<script data-require="react@*" data-semver="15.5.0" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.0/react.min.js"></script>
<script data-require="react@*" data-semver="15.5.0" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.0/react-dom.min.js"></script>