Skip to content

Instantly share code, notes, and snippets.

@joeweller
joeweller / howto-install-jekyll_homebrew-rbenv.txt
Last active November 4, 2021 23:49 — forked from r-brown/howto-install-jekyll_homebrew-rbenv.txt
How to install Jekyll using Homebrew and rbenv - native on m1 mac
# install Homebrew, visit: https://brew.sh/
# check current user
$ echo $(whoami)
# optional - uninstall brew ruby
$ brew uninstall ruby
# install rbenv
$ brew update
@joeweller
joeweller / Collatz_conjecture.py
Created August 23, 2021 21:09
Collatz conjecture
import sys
def main(args):
n = int(args[1])
print(f"start = {n}")
while not n == 1:
n = problem(n)
print(f"{n}")
def problem(n):
@joeweller
joeweller / sleepPromise.js
Created May 21, 2021 22:22
JS promise function to sleep for specified time
const sleepPromise = async function(timeType, timeValue) {
const timeModifier = { 'ms': null, 's': 1000, 'm': 60, 'h': 60 }
const timeTypes = ['ms', 's', 'm', 'h']
for (let i = 1; i < timeTypes.length; i++) {
let key = timeTypes[i]
timeValue = timeValue * timeModifier[key]
if (timeType === key) {
break;
}
@joeweller
joeweller / Git_VSCode
Created May 18, 2019 21:51
Initiate ssh-agent and open VSCode
START "" "start-ssh-agent" ^&^& EXIT
code | exit
@joeweller
joeweller / wait_15.py
Created January 17, 2019 21:24
Algorithm: Wait for next quart hour
from datetime import datetime
import time
# minute, second, millisecond to a string and split into list
min_sec = datetime.now().strftime("%M %S .%f").split(" ")
# calculate minutes to wait for the next whole quart hour
# explanation of m calculation: e.g. time = 12:33 : min = 33
# 33 % 15 = 3 : find out minutes since last quart
# 15 - 3 = 12 : whole minutes to wait for next quart
@joeweller
joeweller / graceful_escape.py
Last active March 24, 2018 00:47
graceful_escape: Python3 object to allow a loop to exit gracefully; useful for multithread/multiprocessor/IO console applications
import threading # import threading
class escape:
"""Object status() to return false when "enter" key is pressed"""
def __init__(self):
self.run = True # should code run?
self.get_key = threading.Thread(target=self.escape_wait) # init thread
self.get_key.start() # start input thread
def status(self): # return False if "enter key" is pressed. otherwise ,True
@joeweller
joeweller / Python3Prime.py
Created March 18, 2018 14:44
Prime number generator for python3 using the classical division technique
def main():
number = 0 # starting number
while True:
prime = True # assumes number is prime initially
t = 0 # test for number of divisions
number += 1 # increment number (as must be positive)
for i in range(1, number + 1): # iterate all numbers between 1 and "number".
if (number / i).is_integer(): # test for whole number division
if i == 1 or i == number:
@joeweller
joeweller / iterate-timetest.py
Created January 30, 2018 21:11
Compare time: iterate to list: "for loop" vs "comprehension"
import time
from random import randrange, choice
def main():
print("\n")
str_len = 100
list_len = 10000
dummy_list = mk_random_list(str_len, list_len)
test = [] # test list
@joeweller
joeweller / visual-dict_from_random_reduction.py
Created January 27, 2018 17:29
A visual representation: populating python3 dicts with RNG through list elimination
import os
import random
import time as Time
"""an efficiency visualisation: indexing dict keys and randomly choosing
one to change its value until all are changed
-removes key from index after value change: no collisions
-100 dict key value pairs"""
def main():
@joeweller
joeweller / visual-dict_from_random.py
Created January 27, 2018 17:26
A visual representation: populating python3 dicts with RNG
import os
from random import randrange
import time as Time
"""an efficiency visualisation: randomly picking dict key and changing values until all are changed
-the loop passes on collisions
-100 dict key pairs"""
def main():
number_grid = {} # empty grid for numbers