Skip to content

Instantly share code, notes, and snippets.

Avatar
👶
Taking care of a newborn

Bret Comnes bcomnes

👶
Taking care of a newborn
View GitHub Profile
View prom.js
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'), {})
View errors.ts
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)
@bcomnes
bcomnes / settings.json
Last active Sep 30, 2021
Sublime custom syntax reference
View settings.json
{
"folders":
[
{
"path": ".",
}
],
"settings": {
"project_syntaxes": [
{
@bcomnes
bcomnes / monty-hall.js
Created May 14, 2021
a monty-hall solution
View monty-hall.js
// 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;
}
View index.js
// 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
View safe-url.js
export class SafeURL extends URL {
constructor(url, base) {
super(
url.replace(/^(http(s?):\/\/)?/, 'http$2://'),
base
);
}
}
@bcomnes
bcomnes / bookmarks.sql
Last active Dec 14, 2020
bookmark pg schema v2
View bookmarks.sql
CREATE EXTENSION IF NOT EXISTS citext;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT uuid_generate_v1mc(),
username citext UNIQUE NOT NULL,
email citext UNIQUE NOT NULL,
email_confirmed BOOLEAN NOT NULL DEFAULT false,
password text
);
View bookmarking-schema.sql
CREATE EXTENSION citext;
CREATE DOMAIN email_address AS citext
CHECK (
value ~ '^[a-zA-Z0-9.!#$%&''*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$'
);
CREATE TABLE users (
id INT GENERATED ALWAYS AS IDENTITY primary key,