Skip to content

Instantly share code, notes, and snippets.

View KMurphs's full-sized avatar

Stephan K. KMurphs

  • Pretoria, South Africa
View GitHub Profile
function SimpleWebSocket(address) {
if(!("WebSocket" in window)) {
console.log("WebSocket NOT supported by your Browser!");
return null
}
// Let us open a web socket
var ws = new WebSocket(address);
@KMurphs
KMurphs / half_consumption_bruteforce.py
Last active February 20, 2022 14:24
For the Priority Queue Medium Article
def add_fans(machine_consumptions, total_initial_consumption, n_fans):
# Find the machine that has the largest amount of consumption and the
# current total amount of consumption for the company
max_index, max_value, current_total_consumption = 0, machine_consumptions[0], 0
for machine_index in range(len(machine_consumptions)):
# Compute factory consumption
current_total_consumption = current_total_consumption + machine_consumptions[machine_index]
# Find worse machine with largest consumption so far
if max_value < machine_consumptions[machine_index]:
@KMurphs
KMurphs / heapify.py
Created February 20, 2022 14:00
Heapsort Algorithm
def heapify(heap_arr, heap_size, parent_index):
# heap_size is just the size of your array (heap_arr).
# We are sorting out a family of three, we want the max element to sit at the parent index
max_family_idx = parent_index
# Compute this parent's children index
left_child_idx = 2 * parent_index + 1
right_child_idx = 2 * parent_index + 2
# Find the maximum element in our "3-members" family.
def add_fans(ranked_machines, total_initial_consumption, total_current_consumption, n_fans):
# Resolve the recursion, because we have reached the target: "just below half of initial consumption"
if total_current_consumption <= total_initial_consumption / 2:
return n_fans
# Compute the site that have the largest amount of consumption and the
# total amount of consumption for the company
worse_machine = ranked_machines[0] # "Extracting" from the heap
@KMurphs
KMurphs / arduino-blink-led.md
Last active July 6, 2022 21:18
LabVIEW, Arduino: Getting Started
@KMurphs
KMurphs / arduino-update-led.md
Last active July 6, 2022 21:12
Arduino Update LED
/*
  Reading a serial ASCII-encoded string.

  This sketch demonstrates the Serial parseInt() function.
  It looks for an ASCII string of comma-separated values.
  It parses them into ints, and uses those to fade an RGB LED.

  Circuit: Common-Cathode RGB LED wired like so:
  - red anode: digital pin 3 through 220 ohm resistor
@KMurphs
KMurphs / labview-from-csv-dashboard.json
Last active July 9, 2022 14:58
labview-from-csv-dashboard.json
{
"meta": {
"type": "db",
"canSave": true,
"canEdit": true,
"canAdmin": true,
"canStar": true,
"canDelete": true,
"slug": "labview-from-csv",
"url": "/d/qxQ3Wb67k/labview-from-csv",
@KMurphs
KMurphs / grafana-exports.sh
Created July 9, 2022 11:23
Script to export Grafana Dashboards and Datasources
#!/usr/bin/env bash
# SOURCE VARIABLES
export token=xxxxx#admin token
export grafanaurl=http://xxx.xxx.xxx.xxx:3000/api
rm -rf backups
mkdir -p backups
cd backups