Skip to content

Instantly share code, notes, and snippets.

@jimkang
jimkang / check-for-islands.js
Last active October 11, 2017 04:24
Quick program to check a tree for islands (groups of nodes that do not connect to every other node)
/* global process */
// Exhaustively searches for islands in a minimum spanning tree.
var fs = require('fs');
if (process.argv.length < 3) {
console.log('Usage: node tools/check-for-islands.js minimum-spanning-tree.json');
}
var mst = JSON.parse(fs.readFileSync(process.argv[2]));
@jimkang
jimkang / scrape-wikipedia-artist-names.js
Created September 18, 2017 13:46
Scraping artist names from Wikipedia pages like this: https://en.wikipedia.org/wiki/Category:Musicians_by_band Paste this into the console for each page.
var artistNodes = document.getElementsByClassName('CategoryTreeLabel');
var nodeCount = artistNodes.length;
var names = [];
for (var i = 0; i < nodeCount; ++i) {
let name = artistNodes[i].textContent;
name = name.replace('(band) ', '');
name = name.replace(' members', '');
names.push(name);
}
console.log(JSON.stringify(names, null, 2));
CREATE TEMP FUNCTION repoNamesHaveD3(repoNames ARRAY<STRING>)
RETURNS INT64
LANGUAGE js AS """
return repoNames.some(nameHasD3) ? 1 : 0;
function nameHasD3(name) {
var normalized = name.toLowerCase();
return normalized.indexOf('d3') === 0 ||
normalized.indexOf('-d3') !== -1;
}
<svg id="garden-board" width="1000" height="3000">
<g class="plant-layer"><g transform="translate(0,0)"><rect id="03a0416" width="17" height="13" fill="rgb(190, 210, 237)"></rect></g><g transform="translate(0,14)"><rect id="22bf24a" width="17" height="14" fill="rgb(190, 210, 237)"></rect></g><g transform="translate(0,29)"><rect id="24ea52c" width="17" height="13" fill="rgb(190, 210, 237)"></rect></g><g transform="translate(18,0)"><rect id="4b62869" width="16" height="13" fill="rgb(190, 210, 237)"></rect></g><g transform="translate(18,14)"><rect id="6780740" width="16" height="14" fill="rgb(190, 210, 237)"></rect></g><g transform="translate(18,29)"><rect id="6d405a1" width="16" height="13" fill="rgb(190, 210, 237)"></rect></g><g transform="translate(35,0)"><rect id="8e9e31b" width="13" height="17" fill="rgb(190, 210, 237)"></rect></g><g transform="translate(49,0)"><rect id="ac6d3d3" width="13" height="17" fill="rgb(190, 210, 237)"></rect></g><g transform="translate(63,0)"><rect id="c320142" width="13" height
@jimkang
jimkang / why-was-i-killed.sh
Created June 4, 2017 19:23
Find out why the kernel killed your process
cat /var/log/kern.log | grep <process name>
@jimkang
jimkang / striplinks.js
Created May 26, 2017 22:17
The good-enough link stripping function I use all the time
@jimkang
jimkang / tls.json
Created May 25, 2017 00:51
Every three-letter acronym on Wikipedia as of now.
[
"AAA",
"AAB",
"AAC",
"AAD",
"AAE",
"AAF",
"AAG",
"AAH",
"AAI",
@jimkang
jimkang / tla.txt
Created May 24, 2017 22:39
Every three-letter abbreviation on Wikipedia as of now.
AAA
AAB
AAC
AAD
AAE
AAF
AAG
AAH
AAI
AAJ
[
{
"id": "2ck8lFrYAch2GPtdhpTHe3",
"name": "All Together Now - Remastered"
},
{
"id": "2qUHGEbPevF1XHhQbQA8kL",
"name": "ABC-DEF-GHI"
},
{
@jimkang
jimkang / strict-equals-references.js
Created March 14, 2017 01:57
Strict equals works on references
> var a = {x: 0, y: 0};
undefined
> var b = {x: 0, y: 0};
undefined
> var list = [a, b];
undefined
> list[0] === a
true
> list[0] === b
false