Skip to content

Instantly share code, notes, and snippets.

josephrocca / crawlDirectory.js
Created Dec 9, 2020
Get all files within a directory (deep/recursive) using the web File System Access API
View crawlDirectory.js
async function crawlDirectory(directoryHandle, files) {
for await (let [name, handle] of directoryHandle.entries()) {
if(handle.kind === "file") files.push(handle);
else if(handle.kind === "directory") crawlDirectory(handle, files);
let directoryHandle = await window.showDirectoryPicker();
let files = [];
await crawlDirectory(directoryHandle, files);
View dcgan_training_pokemon.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python3
from functools import partial
import os
import sys
from absl import app
from absl import flags
from absl import logging
josephrocca / urls.txt
Created Oct 10, 2020
pokemondb sprite urls
View urls.txt
josephrocca / escapeUnicode.js
Created Jun 18, 2020
Replace all Unicode characters with escape codes (JavaScript function)
View escapeUnicode.js
// This function matches all non-ASCII characters after splitting the string in a "unicode-safe" way (using `[...str]`).
// It then splits each unicode character up into its code-points, and gets the escape code for each, and then joins all
// all the ASCII characters and Unicode escapes into one string.
function escapeUnicode(str) {
return [...str].map(c => /^[\x00-\x7F]$/.test(c) ? c : c.split("").map(a => "\\u" + a.charCodeAt().toString(16).padStart(4, "0")).join("")).join("");
// Based on discussion in this thread:
josephrocca / getAllMatches.js
Last active May 26, 2020
JavaScript matchAll "polyfill"
View getAllMatches.js
// Not actually a polyfill. Just a function that gets all matches and puts them in an array. So I don't have to keep Googling for how exec works.
function getAllMatches(str, regex) {
const matches = [];
let m;
while(1) {
m = regex.exec(str);
if(m) matches.push(m);
else break;
josephrocca /
Last active Jul 20, 2019
Words that are only adjectives (no other part-of-speech)

I've taken this list and filtered out words that have other parts-of-speech according to wordpos. It went from 28,479 lines down to 23,799 lines. wordpos definitely isn't perfect, so it's likely that there are many words still in this list that have other part-of-speech values. Here's the code I used:

const fetch = require('node-fetch');
const WordPOS = require('wordpos');
const wordpos = new WordPOS();

(async function() {
  let text = await fetch("").then(r => r.text());
  let adjectives = text.replace(/\r/g, "").split("\n");
View BigMap.mjs
// This is very "hacked together" - not properly bug/security tested or anything.
// Slower than using @ronomon/hash-table directly, but still faster
// than V8 for strings right now:
// and doesn't cause crash when memory usage pushes into dozens
// of GB:
// You need to pass trackKeys:true into the constructor options argument object
// if you want to use map.keys() or the other iterators.
josephrocca /
Last active May 21, 2019
server setup script
#!/usr/bin/env bash
# Node v12
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
# Kakoune
sudo apt install libncursesw5-dev pkg-config
git clone && cd kakoune/src
josephrocca / robin_sloan_scifi_word_freq.json
Created Feb 1, 2019
Sci-Fi word frequency list - English - From Robin Sloan's corpus:
View robin_sloan_scifi_word_freq.json
This file has been truncated, but you can view the full file.