Skip to content

Instantly share code, notes, and snippets.

@josephrocca
josephrocca / getImageData.js
Last active February 25, 2018 06:04
Get image data (pixel RGB array, width, height) by URL
// Only works for images hosted on the same domain unless CORs headers of image allow you to use it.
// Usage:
// let data = await getImageData("http://example.com/image.png");
// Put it in a try/catch to handle errors or use await getImageData("...").catch(e => ...);
function getImageData(url) {
return new Promise((resolve, reject) => {
let img = new Image();
img.onload = function() {
let canvas = document.createElement("canvas");
canvas.width = img.width;
@josephrocca
josephrocca / vivagraph-0.10.0-webglImage-fixed.js
Created February 26, 2018 05:58
Vivagraph 0.10.0 webglImageNodeProgram weird mirroring bug fixed
// Fixed by @weequ: https://github.com/anvaka/VivaGraphJS/pull/204/files
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Viva=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/**
* This is an entry point for global namespace. If you want to use separate
* modules individually - you are more than welcome to do so.
*/
@josephrocca
josephrocca / massive-phrase-list.json
Created June 13, 2018 12:51
A massive list of phrases scraped from the web
This file has been truncated, but you can view the full file.
[{"phrase":"A bad excuse is better than none","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A bad penny always turns up","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A bad tree does not yield good apples","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A bad workman blames his tools","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A barking dog seldom bites","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A bird in hand is worth two in a bush","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A black plum is as sweet as a white","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A book holds a house of gold","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A broken friendship may be soldered but will never be sound","source":"https://www.learn-english-today.com/proverbs"},{"phrase":"A burden of one's own choice is not felt","source":"https://www.learn-e
@josephrocca
josephrocca / streaming-decompress-bz2.html
Created July 13, 2018 09:21
Streaming bz2 decompression in browser (newline delimited JSON)
<script src="https://unpkg.com/unbzip2-stream@1.2.5/dist/unbzip2-stream.min.js"></script>
<script>
async function loadBzipJson(url, cb) {
let text = "";
let bz2 = window.unbzip2Stream();
bz2.on('data', (d) => {
text += new TextDecoder('utf-8').decode(d);
while(text.includes("\n")) {
cb(JSON.parse(text.slice(0, text.indexOf("\n"))));
text = text.slice(text.indexOf("\n")+1);
@josephrocca
josephrocca / frequencies-of-pairs-of-letters-in-english.json
Last active July 31, 2018 03:17
frequencies of pairs of letters in english [a-z0-9'\-], using reddit comments as corpus
{"10":9331,"11":3452,"12":3099,"13":1741,"14":1919,"15":3362,"16":4020,"17":4212,"18":1621,"19":1884,"20":12579,"21":1041,"22":1105,"23":1044,"24":1336,"25":2064,"26":797,"27":881,"28":844,"29":718,"30":3417,"31":1005,"32":855,"33":736,"34":671,"35":1088,"36":870,"37":594,"38":611,"39":487,"40":2369,"41":572,"42":588,"43":516,"44":655,"45":921,"46":496,"47":541,"48":762,"49":542,"50":4149,"51":584,"52":713,"53":535,"54":471,"55":694,"56":601,"57":501,"58":430,"59":482,"60":2207,"61":544,"62":408,"63":431,"64":627,"65":807,"66":570,"67":447,"68":468,"69":463,"70":1433,"71":420,"72":532,"73":376,"74":432,"75":862,"76":450,"77":463,"78":460,"79":372,"80":2025,"81":495,"82":443,"83":493,"84":416,"85":606,"86":445,"87":386,"88":493,"89":444,"90":1408,"91":521,"92":503,"93":460,"94":451,"95":600,"96":587,"97":549,"98":645,"99":8867,"be":129751,"ei":31624,"il":83287,"le":165234,"id":63569,"d ":470592," k":43419,"ki":45808,"iw":377,"wi":84647,"i ":154196," f":221481,"fe":45633,"er":346337,"rn":20542,"ns":64040,"se":1
@josephrocca
josephrocca / npm-bad-word-relaxed-false-positives.js
Last active August 13, 2018 12:48
npm bad-word-relaxed false positives
// ==== NOTES ====
// Seems to have quite a few false matches. Might be worth updating the npm repo to tell
// people that `bad-words` seems to have fixed up its initial problems. It doesn't make
// any false matches in the google-10k list.
// ==== CODE ====
const Filter = require('bad-words-relaxed');
const profanity = new Filter();
const fetch = require('node-fetch');
@josephrocca
josephrocca / nlp-compromise-11.12.0 noun part-of-speech.txt
Created August 14, 2018 03:39
nlp-compromise-11.12.0 noun part-of-speech
===== NOTES =====
Some of the words in the desiquintans.com noun list aren't actually nouns, so this script itself
had a few false positives.
===== CODE =====
const fetch = require('node-fetch');
const nlp = require('compromise');
(async function() {
let words = await fetch("http://www.desiquintans.com/downloads/nounlist/nounlist.txt").then(r => r.text()).then(text => text.split("\n"));
for(let w of words) {
@josephrocca
josephrocca / test.html
Last active September 15, 2018 10:39
scrap - image loading in webcomponent test
<script>
(function(window, document, undefined) {
//document = document.currentScript.ownerDocument;
class ImageOnLoadExample extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
@josephrocca
josephrocca / simple-test.html
Last active September 15, 2018 12:33
scrap - simple web component test - async method
<script>
(function(window, document, undefined) {
const thisDoc = document.currentScript.ownerDocument;
class TestComponent extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
@josephrocca
josephrocca / example.js
Last active September 27, 2018 15:01
Decode WebP Images in NodeJS
(async function() {
const WebPDecoder = await require("./fetchWebPDecoder")();
let webPDataUrl = "data:image/webp;base64,UklGRvYRAABXRUJQVlA4IOoRAAAQgQCdASpAAfAAPu1qrlEppaQqqXIMIVAdiWUHDODHxFjwOctUkVXfTu1UpVUx/8lcT9b44Nz547X6Nn7QXa4dE58x2yL9IRGF4LD3X1pNIIC8qvPaDVDfcOj3EjGc+T9JhNJF+L/SM7sk8BKuDSa9HYiOOPGixk0tWnhAPbVsTW2lc62I2xRGGbcjPJKjDUzadFCmB0hIFFWlTLKi6sBE/xkHbn/zbCr3pURqob/vE5mte/EjzeKcS7diP0QXZTbqEAHxHsKHICWbCjPQ2ZIUZ5Csu45dJ/hH/Gj1zF+R11M6P6dOpmpLZC+Fpv7dzbE08zm01ZOyOyXMBFoIJoB9bUmXZNfuYe4DuIGJrHH9Jw5K5Xp4m8dprR3hyErtiuNMK59cK4Ku0JyhQbrWURbQWFTbNvFk8hjBOOdBQPO/mJHMyHw/tSsFM6E+2yhGFDXnR9uYL+TCkGjo9JUE/2e7zJ9mLHS4ut+NkkDBQO7qJfJhYf1/PK5wUyAKc8oyhSCNBs28xKg/624mNhmQQhARg9qbZD8l8GiKnton/U3MCwVr81c0+6xKrGWYKYJGvRyVRj5TqwwbQPdrek7/hyhW/YNEYYY/BPljajvona6v3h+Q9faJtzqv0HBqITCFbKrXaFF0IZhlZZ4jLfL9h7kZ+I9tAUwxyeFWEpzl0+yDzOaJkwIAEshOQvZ3LsV5EIj/sysyOYDHhKKcVHPgGLHGq6g4OHovginNIHs08DpGFRfG7DG7MEF835uLXSHASXMdFpjHe3yp8NWYyVAqKfzrxU1tNQDkbezkHfcXRibTbHIlnxeP8sLv/hL7MRWyH/OoGNm+lok41jGTBlv0eZVrBXpx5r+xyBRdPkex0