Skip to content

Instantly share code, notes, and snippets.

View ruiokada's full-sized avatar

Rui Okada ruiokada

View GitHub Profile
@ruiokada
ruiokada / randomSpanningTree.js
Created May 1, 2026 03:46
Given the adjacency list of a graph, computes a spanning tree at random uniformly. Uses Andrei Broder's algorithm based on a random walk on the graph (https://www.cs.cmu.edu/~15859n/RelatedWork/Broder-GenRanSpanningTrees.pdf).
/**
* Given the adjacency list of a graph, computes a spanning tree at random uniformly. Uses Andrei Broder's algorithm based on
* a random walk on the graph (https://www.cs.cmu.edu/~15859n/RelatedWork/Broder-GenRanSpanningTrees.pdf).
*
* @method randomSpanningTree
* @param {Array} The graph's adjacency list as an array. Vertices are labeled by their index in the array. E.g. the triangle graph is [[1, 2], [0, 2], [0, 1]].
* @return {Array} Returns the adjacency list of the spanning tree as an array.
*/
function randomSpanningTree(graph) {
@ruiokada
ruiokada / .block
Last active September 18, 2019 17:39 — forked from cmgiven/.block
Map to Force-Directed Graph
license: mit
height: 600
@ruiokada
ruiokada / suntimes.js
Last active April 5, 2026 13:21
Calculate sunrise/sunset times from latitude/longitude coordinates using Javascript.
/**
* Calculates today's sunrise and sunset hours in local time (or in the given tz) for the given latitude, longitude.
* The tz parameter is mainly for the possible circumstance that your system timezone does not match the location
* you are currently at.
*
* Computations are based on the formulas found in:
* https://en.wikipedia.org/wiki/Julian_day#Converting_Julian_or_Gregorian_calendar_date_to_Julian_Day_Number
* https://en.wikipedia.org/wiki/Sunrise_equation#Complete_calculation_on_Earth
*
* @method suntimes