Skip to content

Instantly share code, notes, and snippets.

View taxilian's full-sized avatar

Richard Bateman taxilian

View GitHub Profile
@taxilian
taxilian / consumer.schema.json
Created August 2, 2022 19:09
Example use of monGobb
{
"type": "object",
"title": "Consumer",
"properties": {
"_id": {
"bsonType": "objectId",
"tsType": "ObjectId"
},
"uniqueSlug": { "type": "string" },
"name": { "type": "string" },
@taxilian
taxilian / stringTpl.ts
Created August 2, 2022 17:08
Typescript string template literal function creator
/**
* Use this with a template literal in order to create reusable string template;
* use interpolation to add strings for each variable you want to use in the template.
*
* e.g.:
*
* const reUsableStringTemplate = stringTpl`${'name'} and ${'otherName'} are going to ${'place'}`;
*
* You can then call it with:
*
@taxilian
taxilian / MongoProxy_CollectionConfig.ts
Last active August 1, 2022 21:59
Tool to watch for .schema.json files and compile them as mongodb interfaces using json-schema-to-typescript, also proxy wrapper to use this for creating doc/model thingies
// Collection wrapper, used as an easy way to configure things and a place to put simple helpers,
// also the basis for making a "Model" object
import * as mongodb from 'mongodb';
import { JSONSchema4 } from 'json-schema';
import camelCase from 'lodash/camelCase';
interface IndexSpecification {
[key: string]: mongodb.IndexDirection;
}
@taxilian
taxilian / config.ts
Created February 3, 2022 20:05
Env overrides for config
import _ from 'lodash';
const ENV_PREFIX = `APP_CONFIG`;
function setEnvOverrides(cfg: Config) {
const foundVars = Object.keys(process.env).filter(name => name.startsWith(ENV_PREFIX));
for (const v of foundVars) {
const actualName = v.substr(ENV_PREFIX.length);
// console.log(`Processing ENV var ${actualName}`);
@taxilian
taxilian / backup_cluster.sh
Created September 8, 2021 21:12
Bash script to export all kubernetes resources as YAML files in a directory structure
#!/bin/bash
allCRDs=$(kubectl get crd -o name | cut -d '/' -f 2)
nsCRD=""
clusterCRD=""
for crd in $allCRDs; do
scope=$(kubectl describe crd $crd | grep "Scope" | cut -d ':' -f 2 | sed 's/^ *//g')
if [ "$scope" == "Namespaced" ]; then
@taxilian
taxilian / testCall.sh
Created August 4, 2021 16:33
Tool for testing how often a command succeeds
#!/bin/bash
CMD="$@"
declare -i COUNT
declare -i SUCCESS
SUCCESS=0
COUNT=0
for i in {1..100}; do
@taxilian
taxilian / ExampleSourceComponent.vue
Last active July 9, 2021 19:28
Dialog abstraction example
<script lang="ts">
import {showDialog} from './dialogMgr';
@Component()
export default class MyOtherComponent extends Vue {
markdown = '(some loaded markdown here)';
async openDialog() {
@taxilian
taxilian / app.ts
Last active April 7, 2021 00:34
My attempt at implementing a node.js server with kubernetes best practices for closing gracefully
const dbConnections: Array<MongoClient> = [];
export type startupMiddleware = ReturnType<typeof initMiddleware>;
let failCase: Error;
export function setUnrecoverableError(err: Error) {
failCase = err;
console.warn(`Unrecoverable error set:`, err, err.stack);
}
@taxilian
taxilian / README.md
Created March 28, 2021 01:51
Bootstrapping a kubeadm cluster on ubuntu 20.04
@taxilian
taxilian / arrlVeList.ts
Last active March 14, 2021 00:19
Get ARRL ve lists for each state
// Originally written by Jason Sweeney, refactored by Richard Bateman
// 2021
import axios from "axios";
import cheerio from "cheerio";
const stateListUrl = "http://www.arrl.org/ve-session-counts";
const stateUrl = "http://www.arrl.org/ve-session-counts?state=";
type PromisedReturnType<T extends (...args: any) => any> = T extends (...args: any) => Promise<infer R> ? R : ReturnType<T>;