Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Bateman taxilian

View GitHub Profile
View consumer.schema.json
{
"type": "object",
"title": "Consumer",
"properties": {
"_id": {
"bsonType": "objectId",
"tsType": "ObjectId"
},
"uniqueSlug": { "type": "string" },
"name": { "type": "string" },
@taxilian
taxilian / stringTpl.ts
Created Aug 2, 2022
Typescript string template literal function creator
View stringTpl.ts
/**
* 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 Aug 1, 2022
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
View MongoProxy_CollectionConfig.ts
// 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 Feb 3, 2022
Env overrides for config
View config.ts
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 Sep 8, 2021
Bash script to export all kubernetes resources as YAML files in a directory structure
View backup_cluster.sh
#!/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 Aug 4, 2021
Tool for testing how often a command succeeds
View testCall.sh
#!/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 Jul 9, 2021
Dialog abstraction example
View ExampleSourceComponent.vue
<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 Apr 7, 2021
My attempt at implementing a node.js server with kubernetes best practices for closing gracefully
View app.ts
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 Mar 28, 2021
Bootstrapping a kubeadm cluster on ubuntu 20.04
View README.md
@taxilian
taxilian / arrlVeList.ts
Last active Mar 14, 2021
Get ARRL ve lists for each state
View arrlVeList.ts
// 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>;