Skip to content

Instantly share code, notes, and snippets.

View oreillyross's full-sized avatar
🏠
Working from home

Faktor 10 oreillyross

🏠
Working from home
View GitHub Profile
@oreillyross
oreillyross / reboot.sh
Created April 17, 2024 12:29
We can use both the up and down commands in combination to easily reboot our application when we want to get updated code or dependencies into it. We can chain these commands as
docker compose down --volumes && docker compose up --build
@oreillyross
oreillyross / docker.sh
Last active April 17, 2024 12:26
To return your development environment to a clean state
docker compose down
@oreillyross
oreillyross / docker.sh
Created April 17, 2024 11:07
The general Docker run command with flags
docker run -d p <host-port>:<container-port> -e <name>=<value> <image-name>
@oreillyross
oreillyross / uncompress.py
Last active October 6, 2022 10:26
uncompress solution in python
def uncompress(s):
res = []
i = 0
for j in range(len(s)):
if s[j].isdigit():
continue;
times = int(s[i:j])
res.append(s[j] * times)
i = j + 1
return ''.join(res)
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
from collections import deque
def bottom_right_value(root):
queue = deque([root])
@oreillyross
oreillyross / linked-list-traversal-algo.py
Created May 25, 2022 17:21
This is the core pattern to traverse a linked list in python
class Node:
def __init__(self, val):
self.val = val
self.next = None
a = Node('A')
b = Node('B')
c = Node('C')
d = Node('D')
@oreillyross
oreillyross / BFSbinarytreetraversal.js
Created April 12, 2022 09:24
for...of takes an iterable, so iterating left and right nodes in a BFS binary tree
for (const child of [node.left, node.right]) {
if (child) queue.push(child);
}
@oreillyross
oreillyross / timeout.js
Created April 6, 2022 08:31
Timeout function to use for promise based functions, to guarantee a timeout to a network request for example
function timeout(ms, promise) {
let timeOutId;
const timeOutPromise = new Promise((_, reject)) => {
timeOutId = setTimeout(() => {
reject(new Error(`The operation timed out at ${ms} s`));
}, ms)
}
return Promise.race([promise, timeOutPromise]).finally(() => {
clearTimeOut(timeOutId)
});
/**
* @param {string} s
* @return {number}
*/
var romanToInt = function(s) {
let sum = 0;
let remainingS = s;
const symbols = {
@oreillyross
oreillyross / switch.ts
Created September 29, 2021 19:53
Creating a typesafe enum using the Symbol operator and typeof
'use strict'
const on = Symbol('on')
const off = Symbol('off')
type switchState = typeof on | typeof off
function changeSwitch(switchState: switchState) {
switch (switchState) {
case on: