Skip to content

Instantly share code, notes, and snippets.

View Dark4HNTB.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
View static.js
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
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'), {})
@bcomnes
bcomnes / errors.ts
Last active October 22, 2021 00:27
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 September 30, 2021 20:06
Sublime custom syntax reference
View settings.json
{
"folders":
[
{
"path": ".",
}
],
"settings": {
"project_syntaxes": [
{
@bcomnes
bcomnes / monty-hall.js
Created May 14, 2021 20:36
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
@bcomnes
bcomnes / safe-url.js
Created December 14, 2020 19:20
safe-url.js
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 December 14, 2020 16:37
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
);