Skip to content

Instantly share code, notes, and snippets.

View KMurphs's full-sized avatar

Stephan K. KMurphs

  • Pretoria, South Africa
View GitHub Profile
@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
@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 / 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 / arduino-blink-led.md
Last active July 6, 2022 21:18
LabVIEW, Arduino: Getting Started
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 / 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.
@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]:
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 / to-si-notation.md
Created October 26, 2021 13:36
A python function to convert a number to a string using SI Notation

Originally inspired by https://gist.github.com/cho45/9968462#gistcomment-3522694

import math
SI_PREFIXES_CENTER_INDEX = 8
si_prefixes = ('y', 'z', 'a', 'f', 'p', 'n', 'μ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')


def to_si_notation(value: float, precision: int = 1):
    """Transforms a float number to a string (in SI Notation) using SI prefixes.
@KMurphs
KMurphs / scrappe.chrome-history.js
Last active September 6, 2021 13:11
Scrappe History from Google Chrome
Array.from(document.querySelector("#history-app").shadowRoot.querySelector("#history").shadowRoot.querySelectorAll("history-item")).filter((u,i) => i < 17).map(u => u.shadowRoot.querySelector("a").href)