Skip to content

Instantly share code, notes, and snippets.

@josephrocca
josephrocca / robin_sloan_scifi_word_freq.json
Created February 1, 2019 18:30
Sci-Fi word frequency list - English - From Robin Sloan's corpus: https://archive.org/details/scifi-corpus
This file has been truncated, but you can view the full file.
[["the",1525822],["and",674744],["of",652624],["to",640889],["a",632384],["he",397874],["in",365169],["i",355116],["it",345875],["was",334239],["that",289920],["you",271823],["his",234562],["had",197751],["for",185642],["on",177058],["with",168310],["but",167076],["as",156642],["at",147392],["is",147082],["be",139376],["said",129771],["they",128724],["not",127876],["have",119022],["were",110064],["him",110059],["from",106605],["we",105946],["this",104558],["all",103965],["she",99490],["one",97835],["there",96107],["out",95461],["her",92843],["what",90389],["no",87988],["if",87456],["by",86852],["me",85342],["up",83391],["an",81799],["would",80978],["my",76870],["or",72968],["them",72908],["been",71502],["could",70379],["its",69778],["so",69552],["are",69392],["into",65377],["then",63288],["like",62445],["do",62289],["about",61958],["your",59700],["now",58651],["when",57757],["time",56519],["back",53631],["their",53562],["more",52462],["know",48939],["can",47843],["only",46853],["just",46465],["will",46365],["
@josephrocca
josephrocca / setup.sh
Last active May 21, 2019 13:40
server setup script
#!/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 / BigMap.mjs
Last active June 10, 2019 16:49
BigMap.js
// 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 / only-adjectives.md
Last active July 20, 2019 10:23
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("https://raw.githubusercontent.com/taikuukaits/SimpleWordlists/master/Wordlist-Adjectives-All.txt").then(r => r.text());
  let adjectives = text.replace(/\r/g, "").split("\n");
@josephrocca
josephrocca / getAllMatches.js
Last active May 26, 2020 15:41
JavaScript matchAll "polyfill"
// 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 / escapeUnicode.js
Created June 18, 2020 11:18
Replace all Unicode characters with escape codes (JavaScript function)
// 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 / urls.txt
Created October 10, 2020 23:33
pokemondb sprite urls
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
#!/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 / dcgan_training_pokemon.ipynb
Created October 13, 2020 11:23
dcgan_training_pokemon.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@josephrocca
josephrocca / crawlDirectory.js
Created December 9, 2020 12:31
Get all files within a directory (deep/recursive) using the web File System Access API
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);