Skip to content

Instantly share code, notes, and snippets.

View bcomnes's full-sized avatar
👽

Bret Comnes bcomnes

👽
View GitHub Profile
<!DOCTYPE html>
<html lang="en-us" dir="ltr" itemscope itemtype="http://schema.org/Article">
<head>
<meta charset="utf-8">
<meta name="description" content="A resource for developers looking to put HTML5 to use today, including information on specific features and when to use them in your apps.">
<meta name="keywords" content="html5,html 5,html5 demos,html5 examples,javascript,css3,notifications,geolocation,web workers,apppcache,file api,filereader,indexeddb,offline,audio,video,drag and drop,chrome,sse,mobile">
<title>Yo Polymer – A Whirlwind Tour Of Web Component Tooling - HTML5Rocks Updates</title>
<script type='text/javascript'>window.mod_pagespeed_start = Number(new Date());</script><link rel="shortcut icon" href="http://www.html5rocks.com/favicon.ico">
<link rel="alternate" type="application/rss+xml" title="HTML5Rocks RSS" href="http://feeds.feedburner.com/html5rocks"/>
<link rel="stylesheet" media="all" href="http://www.html5rocks.com/static/css/base.css">
@media (prefers-color-scheme: dark) {
#main a { color: #bfdfff; }
body { background-color: #292a2d; }
#main a:hover { background-color: #000000; }
#main a:hover { color: #80ecff; }
#main a:hover { box-shadow: 0 0 7px #0080ff; }
#main a:hover { box-shadow: 0 0 7px #0080ff; }
}
@bcomnes
bcomnes / static.js
Created October 10, 2022 15:50
Fastify static with private admin section
import fp from 'fastify-plugin'
import path from 'path'
import desm from 'desm'
const __dirname = desm(import.meta.url)
/**
* This plugins adds fastify-static
*
* @see https://github.com/fastify/fastify-static
import fp from 'fastify-plugin'
import Fastify from 'fastify'
/**
* This plugins adds promethius metrics
*
* @see https://gitlab.com/m03geek/fastify-metrics
*/
export default fp(async function (fastify, opts) {
fastify.register(import('fastify-metrics'), {})
@bcomnes
bcomnes / errors.ts
Last active October 22, 2021 00:27
import { someAsyncTask } from 'a-library'
async function doSomething () {
try {
const results = await someAsyncTask();
const betterResults = results.map(stuff => { betterStuff: stuff });
return results;
} catch (error) {
if (error instanceof Error){
console.error(error.message)
0x2000d583cfc8919912e5C1eBb4B5C2c346e7324A
@bcomnes
bcomnes / settings.json
Last active September 30, 2021 20:06
Sublime custom syntax reference
{
"folders":
[
{
"path": ".",
}
],
"settings": {
"project_syntaxes": [
{
@bcomnes
bcomnes / monty-hall.js
Created May 14, 2021 20:36
a monty-hall solution
// Generate a random integer r with equal chance in min <= r < max.
function randomInt(min, max) {
var range = max - min;
if (range <= 0) {
throw new Exception('max must be larger than min');
}
var requestBytes = Math.ceil(Math.log2(range) / 8);
if (!requestBytes) { // No randomness required
return min;
}
// https://ballpit.github.io/website/pics.zip
const fs = require('fs')
const get = require('simple-get')
const pump = require('pump')
const path = require('path')
get('https://ballpit.github.io/website/pics.zip', (err, res) => {
if (err) throw err
@bcomnes
bcomnes / safe-url.js
Created December 14, 2020 19:20
safe-url.js
export class SafeURL extends URL {
constructor(url, base) {
super(
url.replace(/^(http(s?):\/\/)?/, 'http$2://'),
base
);
}
}