Skip to content

Instantly share code, notes, and snippets.

View cefn's full-sized avatar

Cefn Hoile cefn

View GitHub Profile
@cefn
cefn / config.ts
Created January 29, 2022 09:02
Env Variable enforcement and typing
import dotenv from "dotenv";
import { z } from "zod";
dotenv.config();
const envSchema = z.object({
COUCHDB_USER: z.string().min(1),
COUCHDB_PASSWORD: z.string().min(1),
});
@cefn
cefn / lock.ts
Created January 14, 2022 11:54
Simple lock implementation
let releaseGlobalsPromise: null | Promise<void> = null;
async function acquireGlobalsLock() {
while (releaseGlobalsPromise) {
await releaseGlobalsPromise;
}
let release!: () => void;
releaseGlobalsPromise = new Promise(
(resolve) =>
(release = () => {
releaseGlobalsPromise = null;
@cefn
cefn / fizzbuzz.ts
Created August 22, 2021 17:18
FizzBuzz Cefn
for (let x = 1; x <= 100; x++) {
console.log(
`${x % 3 === 0 ? "Fizz" : ""}${x % 5 === 0 ? "Buzz" : ""}` || x.toString()
);
}
#! /home/linuxbrew/.linuxbrew/opt/python@3.8/bin/python3.8
import os
import math
import shutil
import requests
from xml.etree import ElementTree
def decimalMinuteString(decimalDegreeString, paddegrees):
degrees = float(decimalDegreeString)
@cefn
cefn / configurator.js
Last active April 5, 2020 13:18
Uploads design docs to couchdb through nano for Component testing within views
const {
Loader
} = require("./designdocs/loader")
class CouchdbConfigurator{
constructor(dbHandle){
if( //duck-type check for nano db handle
typeof dbHandle === "object" &&
typeof dbHandle.config === "object" &&
dbHandle.config.url &&
@cefn
cefn / priority.js
Created April 5, 2020 13:13
Example view map function
var priorities = [
"!urgent",
null,
"!soon",
"!normal",
"!backlog",
"!wishlist",
]
function getPriorityOrder(task) {
@cefn
cefn / priority.test.js
Created April 5, 2020 13:03
Example unit-testing for CouchDB map function
const testScriptType = "map"
const testScriptId = "priority"
const priorities = [
"!urgent",
null,
"!soon",
"!normal",
"!backlog",
"!wishlist",
]
@cefn
cefn / loader.js
Last active April 5, 2020 12:52
Strategy for evaluating + unit-testing Couchdb map, reduce, update functions
const path = require("path")
const glob = require("glob")
const fs = require("fs")
const nodeEval = require("node-eval")
/** Helper object to construct a map of named design docs from a path containing js scripts.
* It populates couchdb design documents from js files targeting Spidermonkey 1.8.5
*
* File paths like
* * designdocs/map/priority.js
@cefn
cefn / whitefurze_purchase.py
Created December 15, 2019 17:22
Purchase order calculation comparing storage box vendors
from dataclasses import dataclass
@dataclass
class Vendor:
pass
"""
mini45=None
midi45=None
maxi45=None
import pytest
def checkHelper(value):
assert list(value) == list('foo')
@pytest.mark.parametrize("value", (
'foo',
'far'
))
def testInline(value):