Skip to content

Instantly share code, notes, and snippets.

View Zekfad's full-sized avatar
9️⃣
IX

Yaroslav Vorobev Zekfad

9️⃣
IX
View GitHub Profile
@bag-man
bag-man / cpu.js
Last active October 28, 2024 22:02
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores
@bellbind
bellbind / dijkstra.js
Created July 11, 2012 07:27
[javascript]dijkstra algorithm (with custom data structure)
// Dijkstra Algorithm Example
// - Using suite data structure make algorithm clearer
// compile graph data to vertices structure: {"label": Vertex, ...}
// - Graph: [{from: "label", to: "label". cost: number}, ...]
// - Vertex: {label: string, edges: [{dest: Vertex, cost: number}, ...]}
var compileVertices = function (graph) {
var vs = {};
graph.forEach(function (edge) {
if (!vs[edge.from]) vs[edge.from] = {label: edge.from, edges: []};