Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} original
* @param {TreeNode} cloned
public class Solution {
public int MinOperations(string s) {
// Using original first bit.
int count1 = 0;
char prev1 = s[0];
// Using opposite first bit.
int count2 = 1;
char prev2 = prev1 == '0' ? '1' : '0';
for (int i=1; i<s.Length; i++)
@primaryobjects
primaryobjects / order.cs
Created October 30, 2023 01:20
Print in order using locks and semaphore, multithreaded, threads in C# https://leetcode.com/problems/print-in-order
using System.Threading;
public class Foo {
private static Object _lock = new Object();
private static int _sequence = 0;
private int _limit = 100;
public Foo() {
}
public class Solution {
public int MinTimeToVisitAllPoints(int[][] points) {
int seconds = 0;
int cx = points[0][0];
int cy = points[0][1];
for (int i=1; i<points.Length; i++)
{
int[] coord = points[i];
int x = coord[0];
@primaryobjects
primaryobjects / hotspot-keepalive.bat
Last active March 24, 2024 07:57
Script to Enable Windows 10 Wifi Mobile Hotspot Automatically and Keep Alive on Disconnect
PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
PowerShell C:\Users\YOUR_USERNAME\Desktop\hotspot-keepalive.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
public class MinStack {
private struct Item
{
public int Val;
public int ParentMin;
};
private int _min;
private List<Item> _stack;
private int _minIndex;
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body onload="countRefreshes()">
<div class="container mt-5">
<div class="card">
@primaryobjects
primaryobjects / Sudoku.js
Created October 8, 2023 20:12
Sudoku in javascript, created using Bing ChatGPT GPT4 https://jsbin.com/bivoficadi/edit?js,output
class Sudoku {
constructor(emptyCellCount = 20) {
this.solvedBoard = this.generateSudoku();
this.board = JSON.parse(JSON.stringify(this.solvedBoard));
this.clearCells(emptyCellCount);
}
clearCells(K) {
// Remove K elements randomly to create an 'easy' puzzle
for (let i = 0; i < K; i++) {
@primaryobjects
primaryobjects / app.js
Created October 3, 2023 03:28
RobotC car driving simulator, built in javascript with ThreeJs. Supports car movement, forwards, reverse, turning, and for loops. https://www.brightonk12.com/cms/lib/MI02209968/Centricity/Domain/517/robotc_tutorial1.pdf Demo at https://simple-robotc-simulator.primaryobjects.repl.co
// Create a scene
var scene = new THREE.Scene();
// Create a camera
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
// Create a renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
@primaryobjects
primaryobjects / text-analysis.R
Created October 1, 2023 01:26
Text analysis with word frequency, topic modeling using LDA, and word clouds. https://www.coursera.org/learn/applying-data-analytics-business-in-marketing/home/week/3
# Load the rvest package
library(rvest)
library(ggplot2)
library(tidytext)
library(tidyverse)
library(topicmodels)
library(tm)
library(wordcloud)
library(RColorBrewer)