Skip to content

Instantly share code, notes, and snippets.

@josephrocca
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.
View dcgan_chainer_to_keras.py
#!/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
josephrocca / urls.txt
Created Oct 10, 2020
pokemondb sprite urls
View urls.txt
https://img.pokemondb.net/sprites/bank/normal/bulbasaur.png
https://img.pokemondb.net/sprites/bank/normal/ivysaur.png
https://img.pokemondb.net/sprites/bank/normal/venusaur.png
https://img.pokemondb.net/sprites/bank/normal/charmander.png
https://img.pokemondb.net/sprites/bank/normal/charmeleon.png
https://img.pokemondb.net/sprites/bank/normal/charizard.png
https://img.pokemondb.net/sprites/bank/normal/squirtle.png
https://img.pokemondb.net/sprites/bank/normal/wartortle.png
https://img.pokemondb.net/sprites/bank/normal/blastoise.png
https://img.pokemondb.net/sprites/bank/normal/caterpie.png
@josephrocca
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: https://gist.github.com/mathiasbynens/1243213
@josephrocca
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
josephrocca / only-adjectives.md
Last active Jul 20, 2019
Words that are only adjectives (no other part-of-speech)
View only-adjectives.md

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("https://raw.githubusercontent.com/taikuukaits/SimpleWordlists/master/Wordlist-Adjectives-All.txt").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: https://bugs.chromium.org/p/v8/issues/detail?id=9348
// and doesn't cause crash when memory usage pushes into dozens
// of GB: https://bugs.chromium.org/p/v8/issues/detail?id=9350
// You need to pass trackKeys:true into the constructor options argument object
// if you want to use map.keys() or the other iterators.
@josephrocca
josephrocca / setup.sh
Last active May 21, 2019
server setup script
View setup.sh
#!/usr/bin/env bash
# Node v12
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
# Kakoune
sudo apt install libncursesw5-dev pkg-config
git clone https://github.com/mawww/kakoune.git && cd kakoune/src
make
@josephrocca
josephrocca / robin_sloan_scifi_word_freq.json
Created Feb 1, 2019
Sci-Fi word frequency list - English - From Robin Sloan's corpus: https://archive.org/details/scifi-corpus
View robin_sloan_scifi_word_freq.json
This file has been truncated, but you can view the full file.