Skip to content

Instantly share code, notes, and snippets.

@sc0ttj
sc0ttj / Dijkstra's-algorithm.js
Created May 19, 2025 21:01 — forked from Prottoy2938/Dijkstra's-algorithm.js
Dijkstra's algorithm implementation in JavaScript
//Dijkstra algorithm is used to find the shortest distance between two nodes inside a valid weighted graph. Often used in Google Maps, Network Router etc.
//helper class for PriorityQueue
class Node {
constructor(val, priority) {
this.val = val;
this.priority = priority;
}
}
function noteFromKey(keyCode) {
var char = String.fromCharCode(keyCode).toUpperCase();
if(pianoMap[char]) {
return pianoMap[char];
}
else {
return false;
}
}
/*
@sc0ttj
sc0ttj / safe-object.js
Last active May 20, 2025 09:07
Type-safe JS Objects that validate against a schema
// Helpers.js
// A reliable alternative to `typeof`:
const type = v => Array.isArray(v) ? 'array' : Object.prototype.toString.call(v).slice(8, -1).toLowerCase();
// More type checking
const isType = (v,t) => type(v) === t;
const isFn = v => isType(v, 'function');
const isObj = v => isType(v, 'object');
const isNum = v => isType(v, 'number');
@sc0ttj
sc0ttj / country-bounding-boxes.py
Created May 20, 2024 16:23 — forked from graydon/country-bounding-boxes.py
country bounding boxes
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),
@sc0ttj
sc0ttj / README.md
Created December 13, 2023 12:29 — forked from armollica/README.md
Convert SVG to Canvas

Convert SVG to canvas on-the-fly.

This article from MDN explains the process: Drawing DOM object into a canvas. This works for any DOM object, not just SVG. Not sure if this is well supported by older browsers. Works on Chrome, Firefox and IE 10 for me. The bar chart is a fork of this block by Mike Bostock: Canvas Bar Chart.

@sc0ttj
sc0ttj / handlebars-helpers.md
Last active November 11, 2024 13:03
Handlebars helpers for VJ

Handlebars helpers

We'll see some example "helpers" which access the vocabs, without needing lookup, or passing in @root.vocab.

Lets use the following vocabs:

key english
country_names_1 England
country_names_2 Scotland
@sc0ttj
sc0ttj / SCSS.md
Created October 31, 2023 18:29 — forked from jareware/SCSS.md
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

@sc0ttj
sc0ttj / modifiers.scss
Created October 31, 2023 18:28 — forked from sarahdayan/modifiers.scss
Sass Modifiers Mixin
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
// Sass modifiers mixin by Sarah Dayan
// Generate All Your Utility Classes with Sass Maps: frontstuff.io/generate-all-your-utility-classes-with-sass-maps
// http://frontstuff.io
// https://github.com/sarahdayan
@sc0ttj
sc0ttj / safe-objects.js
Last active February 5, 2024 13:23
Javascript - safer objects, with "prototype pollution" prevention, and schema validation
// NOTE:
// ----------------------------------------------------------------------------
//
// ** When a key/value structure is needed, Map should be preferred to Object. **
//
// It’s possible to create Objects in JavaScript that don’t have a prototype.
// It requires the usage of Object.create(). Objects created through this
// API won’t have the __proto__ and constructor attributes.
// "Prototype pollution" attacks