Skip to content

Instantly share code, notes, and snippets.

View bcowell's full-sized avatar

Brayden Cowell bcowell

View GitHub Profile
@bcowell
bcowell / development.log
Created January 21, 2024 16:00
Annoyingly long rails stack traces
This file has been truncated, but you can view the full file.
There was an exception - NameError(undefined local variable or method `game' for #<GameChannel:0x00007fdf89352800 @connection=#<ApplicationCable::Connection:0x00007fdf8d3f9070 @coder=ActiveSupport::JSON, @env={"rack.version"=>[1, 6], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "rack.url_scheme"=>"http", "SCRIPT_NAME"=>"/cable", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 5.6.8 Birdie's Version", "GATEWAY_INTERFACE"=>"CGI/1.2", "REQUEST_METHOD"=>"GET", "REQUEST_PATH"=>"/cable", "REQUEST_URI"=>"/cable", "HTTP_VERSION"=>"HTTP/1.1", "HTTP_HOST"=>"localhost:3001", "HTTP_CONNECTION"=>"Upgrade", "HTTP_PRAGMA"=>"no-cache", "HTTP_CACHE_CONTROL"=>"no-cache", "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "HTTP_UPGRADE"=>"websocket", "HTTP_ORIGIN"=>"http://localhost:4321", "HTTP_SEC_WEBSOCKET_VERSION"=>"13", "HTTP_ACCEPT_ENCODING"=>"
@bcowell
bcowell / countArrayInversions.js
Created February 11, 2020 19:27
countArrayInversions.js
const countArrayInversions = (arr) => {
let count = 0;
let sortedArr = [];
arr.reverse().forEach(n => {
// Search in sorted arr for insertion index
// The number of elements < n in the sorted array are inversions of n
const i = binaryInsort(sortedArr, n);
count += i;
})
return count;
@bcowell
bcowell / reverseSentence.py
Created October 23, 2019 16:09
Given a string sentence, return the sentence with the words in the reverse order
# Given a string sentence, return the sentence with the words in the reverse order
# "I like apples" => "apples like I"
def reverseSentence(sentence):
words = sentence.split(" ")
return " ".join(words[::-1])
# If input is an array of characters instead of a string
# ['I', ' ', 'l' , 'i', 'k', e', ' ', 'a', 'p', 'p', 'l', 'e', 's']
# => ['a', 'p', 'p', 'l', 'e', 's', ' ', 'l', 'i', 'k', 'e', ' ', 'I']
def reverseSentenceArray(arr):
@bcowell
bcowell / mazebot-cert.json
Last active July 15, 2019 03:50
Noops Mazebot race cert solved using A*
{
"message": "This certifies that bcowell completed the mazebot race in 123.812 seconds.",
"elapsed": 123.812,
"completed": "2019-07-15T03:47:00.566Z"
}
@bcowell
bcowell / flipping-an-image.py
Last active March 29, 2019 18:11
Flipping an image
def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]:
return [[int(not i) for i in row[::-1]] for row in A]
@bcowell
bcowell / squares-of-sorted-array.py
Created March 13, 2019 13:40
Squares of a Sorted Array
def sortedSquares(self, A: List[int]) -> List[int]:
B = [i**2 for i in A]
B.sort()
return B
@bcowell
bcowell / tcp-timed-wait-delay.ps1
Last active February 21, 2019 21:36
Powershell command - Edit TcpTimedWaitDelay
netsh int ipv4 set dynamicport tcp start=1025 num=64510
netsh int ipv4 show dynamicport tcp
New-ItemProperty `
-Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" `
-Name "TcpTimedWaitDelay" `
-Value "30" `
-PropertyType "DWord"
@bcowell
bcowell / sort-array-by-parity.py
Last active February 20, 2019 15:07
sort-array-by-parity
def sortArrayByParity(self, A):
A.sort(key=lambda x: x%2)
return A
@bcowell
bcowell / two-sum.py
Created February 13, 2019 16:38
two-sum
def twoSum(self, nums: 'List[int]', target: 'int') -> 'List[int]':
index = {}
for i,num in enumerate(nums):
# build dictionary
if index.get(num) == None:
index[num] = i;
# if (target - num) is in dict
if index.get(target - num) != None:
if i != index.get(target-num): # cannot use same element
@bcowell
bcowell / shortest-to-char.py
Last active February 12, 2019 20:54
shortest-to-char
def shortestToChar(self, S: 'str', C: 'str') -> 'List[int]':
# store index of all chars c
ind = []
for i,c in enumerate(S):
if (c == C):
ind.append(i)
# Find shortest distance
# from current i to indexed c
arr = []