Skip to content

Instantly share code, notes, and snippets.

Avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / 1-sum.js
Last active Jul 7, 2020
Replace BST nodes with the sum of nodes greater than the node. O(n) https://jsfiddle.net/Lr3mh8op/1/
View 1-sum.js
/* Given a binary tree, replace all node values with the sum of all node values greater than or equal to its own.
Note, in a binary search tree, values to the left are less than the parent, while values to the right are greater than the parent.
*/
const sum = node => {
// Returns the sum of all values in the tree.
return !node ? 0 : node.value + sum(node.left) + sum(node.right);
};
@primaryobjects
primaryobjects / chromedriver.py
Last active Jul 19, 2020
Automatically download the latest chromedriver for Selenium in Python. Works on Linux, Mac, Windows. Cross platform!
View chromedriver.py
#!/usr/bin/env python3
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import WebDriverException, SessionNotCreatedException
import sys
import os
import pathlib
import urllib.request
import re
import zipfile
@primaryobjects
primaryobjects / activities.md
Last active May 20, 2020
Working from home useful links WFH
View activities.md

Activities for Kids

Music Time With Priscilla Cunza-Marin

If you have babies or toddlers, and need to entertain them for 20-30 minutes with a little music, this is a great opportunity! Mondays and Thursdays at 1pm, kids can enjoy a short ukelele sing-along session of their favorite kids songs ("Alphabet song", "Heads, Shoulders, Knees and Toes", "I'm a Little Teapot", etc.) Please sign up and we will forward you the appointment with Zoom link https://us04web.zoom.us/j/907562844

Dance Classes with Karishma Motwani

Go to that important meeting or get that important task done while your kids enjoy 30-40 minutes of dance classes with Karishma Motwani, Mondays and Thursdays at 4:30pm! All ages welcome! Please sign up and we will forward you the appointment with Zoom link. Adults are welcome as well if you'd like to sneak some extra steps in for that step challenge! https://us04web.zoom.us/j/9422118428

Arts and Crafts with Neena Davies

Let your kids get creative learning how to do different arts a

@primaryobjects
primaryobjects / unsplash.sh
Created Mar 16, 2020
Automatically change Linux Mint Desktop Wallpaper by downloading a random image from unsplash.com
View unsplash.sh
#!/bin/bash
#
# Add a cron job to run this script every 15 minutes.
# crontab -e
# */15 * * * * /home/YOUR_USER_NAME/Documents/unsplash.sh
#
USER=$(whoami)
# Delete cached wallpaper.
@primaryobjects
primaryobjects / readme.md
Last active May 12, 2020
How to remote desktop from Linux Mint to Windows 10 with AzureAD Azure AD login
View readme.md

How to remote desktop from Linux Mint to Windows 10 with AzureAD

The following steps detail how to connect over Remote Desktop from Linux Mint or Ubuntu to Windows 10 with an AzureAD username and password login account.

  1. In Windows 10, right-click This PC or My Computer and select Properties.
  2. Click Remote Settings.
  3. Check the option Allow remote connections to this computer.
  4. Uncheck the option Allow connections only from computers running Remote Desktop with Network Level Authentication.
  5. Click OK.
@primaryobjects
primaryobjects / linear-regression.R
Created Jan 31, 2020
Linear regression with gradient descent in R.
View linear-regression.R
#
# An example of calculating linear regression with gradient descent for a single variable.
# Kory Becker
# 1/31/2020
#
# Calculate linear regression with gradient descent.
linearRegression <- function(x, y, alpha, iterations) {
# initialize coefficients
theta <- matrix(c(0,0), nrow=2)
@primaryobjects
primaryobjects / udacity-submit.md
Last active Jan 20, 2020
How to submit a project to Udacity in Windows with a Google or Facebook login.
View udacity-submit.md

How to submit a project to Udacity in Windows

When submitting a project to Udacity with a login on Google or Facebook, you will need to copy a jwt file to your PC in order for the login to work. Here's how.

  1. Save the link https://project-assistant.udacity.com/auth_tokens/new to C:\Users\YOUR_USER_NAME\AppData\Roaming\udacity-pa
  2. Open a CMD in Windows.
  3. Navigate to your project source code folder:
    cd c:\projects\aind-sudoku
@primaryobjects
primaryobjects / 1-sudoku-box.py
Last active Jan 19, 2020
Sudoku puzzle convert string of values into a dictionary of key/value pairs. Udacity Artificial Intelligence nanodegree project 1, quiz 1: Encoding the Board.
View 1-sudoku-box.py
from utils import *
# `grid` is defined in the test code scope as the following:
# (note: changing the value here will _not_ change the test code)
# grid = '..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..'
def grid_values(grid):
"""Convert grid string into {<box>: <value>} dict with '.' value for empties.
Args:
@primaryobjects
primaryobjects / id3.R
Last active Dec 26, 2019
Decision Tree with ID3 in R, machine learning, information gain, entropy.
View id3.R
library(data.tree)
entropy <- function(q) {
# Calculate the entropy for a value.
-1 * (q * log2(q) + (1 - q) * log2(1 - q))
}
positiveRatio <- function(data, outcomeCol = ncol(data)) {
# Calculate the ratio of T by the total samples.
positiveCount <- length(which(data[, outcomeCol] == T))
@primaryobjects
primaryobjects / informationGain.R
Last active Dec 25, 2019
Information Gain and Entropy calculation for usage with building Decision Trees with machine learning, AI. Demo https://repl.it/repls/ParchedCompetentLegacysystem
View informationGain.R
entropy <- function(q) {
# Calculate the entropy for a value.
-1 * (q * log2(q) + (1 - q) * log2(1 - q))
}
positiveRatio <- function(data) {
# Calculate the ratio of positives by the total measurements.
sum(data$positives) / (sum(data$positives) + sum(data$negatives))
}
You can’t perform that action at this time.