Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / RemoveOpenWithSublimeText3.bat
Created February 16, 2022 17:31
Remove context menu opens to Open With Sublime Text 3 in Windows.
@echo off
SET st2Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg delete "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3"
@reg delete "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3"
@reg delete "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command"
rem delete it for folders
@reg delete "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3"
function strStr(haystack: string, needle: string): number {
let index = -1;
if (!needle || !needle.length) {
index = 0;
}
else {
let nextStart = 0;
let j = 0;
for (let i=0; i<haystack.length; i++) {
@primaryobjects
primaryobjects / single.ts
Created February 15, 2022 02:32
Find the single number among all duplicates in an array in linear runtime and constant space. https://leetcode.com/problems/single-number/
function singleNumber(nums: number[]): number {
let value = 0;
for (let num of nums) {
value ^= num;
}
return value;
};
@primaryobjects
primaryobjects / resolution.md
Last active February 15, 2022 02:05
How to set Windows 10 resolution for a specific program

How to Set the Windows 10 Resolution for a Specific Program

In Windows 10, when running an application or game in a specific resolution, the following batch file may be used. This is helpful for situations where your normal desktop resolution is different than the one running in the program.

  1. Download qres.
  2. Save qres.exe in the same folder as the desired application.
  3. Create run.bat in the same folder as the desired application.
start /wait qres.exe /x:1920 /y:1080
"Application.exe"
@primaryobjects
primaryobjects / buySellStocks.ts
Created February 14, 2022 02:08
Find the best time to buy and sell stocks with a cooldown, solved in TypeScript. https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/
const maxProfit = (prices: number[]): number => {
// Dynamic programming using memoization.
const search = (index: number, holding: boolean=false, history: {[key: string]: number} = {}): number => {
// Memoization key.
const key = `${index}-${holding}`;
// Base case 1.
if (history[key]) {
// We already have a value for this state.
return history[key];
@primaryobjects
primaryobjects / movezeroes.py
Created February 13, 2022 15:53
Move zeroes to the end of the array, in-place without temporary variables. https://leetcode.com/problems/move-zeroes/
#
# Count the occurences of zeroes.
# For each non-zero value, move it left by "count".
# Finally, insert "count" zeroes to fill the array.
# Worst-case time complexity (all zeroes): O(n*2) => O(n)
#
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
count = 0
for i in range(len(nums)):
@primaryobjects
primaryobjects / findLucky.py
Created February 12, 2022 02:37
Find the lucky integer having a frequency in the array equal to its value. https://leetcode.com/problems/find-lucky-integer-in-an-array/
class Solution:
def findLucky(self, arr: List[int]) -> int:
hash = {}
for i in arr:
hash[i] = hash[i] + 1 if i in hash else 1
largest = -1;
for key in hash:
if hash[key] == key and key > largest:
@primaryobjects
primaryobjects / countChange.js
Created February 11, 2022 01:44
Count change, return all possible combinations of coins to equal target.
function combinations(target = 4, coins = [1, 2, 3, 4, 5]) {
const combos = [];
const results = [];
for (let i=0; i<coins.length; i++) {
const c1 = coins[i];
for (let j=i+1; j<coins.length; j++) {
const c2 = coins[j];
combos.push([c1, c2]);
@primaryobjects
primaryobjects / binaryGap.ts
Created February 10, 2022 19:43
Find the longest distance between two adjacent 1's in binary representation of n. https://leetcode.com/problems/binary-gap/submissions
function binaryGap(n: number): number {
const bin = n.toString(2);
// May get better speed by trimming trailing '0' from left and right?
// const bin = n.toString(2).replace(/^0+|0+$/g, '');
let distance = 0;
let left = -1;
for (let i=0; i<bin.length; i++) {
if (bin[i] === '1') {
if (left !== -1) {
@primaryobjects
primaryobjects / happy.ts
Created February 10, 2022 03:39
Determine happy numbers, sum of squares of digits https://leetcode.com/problems/happy-number
function isHappy(n: number): boolean {
let digit = 1;
let count = 0;
while (n > 0 && n !== 1 && count < 10) {
let sum = 0;
count++;
while (n) {
digit = n % 10;