Skip to content

Instantly share code, notes, and snippets.

View jollytoad's full-sized avatar

Mark Gibson jollytoad

View GitHub Profile
@jollytoad
jollytoad / fix-std-lib-imports.ts
Created April 8, 2024 12:36
Replace underscore with dashes in strings that look like Deno `@std` imports
import { walk } from "jsr:@std/fs@^0.221.0/walk";
export async function fixStdLibImports(root: string) {
for await (const entry of walk(root, { exts: [".ts"] })) {
const content = await Deno.readTextFile(entry.path);
const replaced = content.replaceAll(/"@std\/([^"]+)"/g, (str) => {
return str.replaceAll("_", "-");
});
@jollytoad
jollytoad / HTMLBodyElementParserStream.js
Last active September 29, 2023 11:05
Streaming HTML parser using a TransformStream
/**
* Parse a stream of HTML into Elements.
*
* Only emits child elements of the body once the parser moves
* onto the next child element. All head elements are ignored,
* as are non-element child nodes of the body (eg. comments, character data).
*
* The stream can be a series of individual HTML elements, not necessarily
* enclosed within `<html>`/`<body>` tags, but proceeded by `<!DOCTYPE html>`,
* and this would be a perfectly valid HTML5 document (as far as the parser
@jollytoad
jollytoad / ReadableStream_asyncIterator.js
Last active September 29, 2023 10:26
Polyfill for ReadableStream.prototype[@@asyncIterator]
/**
* @template T
* @this {ReadableStream<T>}
*/
async function* readableStreamIterator() {
const reader = this.getReader();
try {
let done, value;
do {
({ done, value } = await reader.read());
@jollytoad
jollytoad / plugins.d.ts
Last active October 15, 2019 23:11
Strawman proposal for a Blockly plugin system
import * as Blockly from "./blockly";
/**
* This would be an interface exposed at Blockly.Plugins
*/
interface Plugins {
/**
* Register a new plugin with Blockly
* @param factory a function that returns a PluginSpec.
*/
@jollytoad
jollytoad / field_variable.js
Last active August 23, 2018 13:22
Multi-type variable support for Blockly
/**
* Check whether the given variable type is allowed on this field.
* @param {string|Array<string>} type The type (or types) to check.
* @return {boolean} True if the type (or one of the types) is in the list of allowed types.
* @private
*/
Blockly.FieldVariable.prototype.typeIsAllowed_ = function (type) {
var typeList = this.getVariableTypes_()
if (!typeList) {
return true // If it's null, all types are valid.
@jollytoad
jollytoad / jsx-h.js
Last active February 3, 2017 03:20
Wrapper for virtual-dom/h to support compiled JSX (ES6)
import h from 'virtual-dom/h'
export default function(tag, props, ...children) {
if (typeof tag === 'function') {
return tag(props, ...children)
} else {
return h(tag, transformProps(props), children)
}
}
@jollytoad
jollytoad / keybase.md
Last active August 18, 2016 12:53
Keybase proof

Keybase proof

I hereby claim:

  • I am jollytoad on github.
  • I am jollytoad (https://keybase.io/jollytoad) on keybase.
  • I have a public key ASBNy3nSrQbjlDYfZFrXj0ecD8mnqT3_mPQlYjg6II3nKgo

To claim this, I am signing this object:

@jollytoad
jollytoad / gist:4201905
Created December 4, 2012 08:44
Read a File using a FileReader returning a jQuery promise
function readFile(file) {
var reader = new FileReader();
var deferred = $.Deferred();
reader.onload = function(event) {
deferred.resolve(event.target.result);
};
reader.onerror = function() {
deferred.reject(this);
@jollytoad
jollytoad / parseDataUri.js
Created December 4, 2012 08:40
Parse a data URI
function parseDataUri(uri) {
var m = /^data:([^;,/]+\/[^;,/]+)?(;charset=([^;,]+))?(;base64)?,(.*)$/.exec(uri);
return m && {
type: m[1] || "text/plain",
charset: m[3],
base64: !!m[4],
data: m[5]
};
}
@jollytoad
jollytoad / photoframe.html
Created May 18, 2011 23:31
Picasa photo frame
<!DOCTYPE html>
<html>
<head>
<title>Photos</title>
<style>
html, body { padding: 0; margin: 0; background-color: black; color: white; width: 100%; height: 100%; }
#photo { background-repeat: no-repeat; background-position: center; background-size: auto 100%; width: 100%; height: 100%; }
#msg { position: fixed; bottom: 0; right: 0; text-align: right; color: white; font-size: 10px }
</style>
</head>