Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Bateman taxilian

View GitHub Profile
@taxilian
taxilian / compress.yaml
Last active Sep 16, 2020
Traefik kubernetes configuration that I use
View compress.yaml
# Enable gzip compression
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: gzip-compress
spec:
compress: {}
@taxilian
taxilian / common.ts
Created Sep 14, 2020
Example typescript pattern for defining a view using 'mongoose-decorators-ts'
View common.ts
export const readOnlyExcludeKeysModel = <const>[
'watch', 'bulkWrite', 'create', 'createCollection',
'syncIndexes', 'listIndexes', 'ensureIndexes',
'createIndexes', 'findByIdAndRemove', 'findByIdAndDelete',
'findByIdAndUpdate', 'findOneAndRemove', 'findOneAndDelete',
'findOneAndUpdate', 'insertMany', 'remove', 'deleteOne',
'deleteMany', 'replaceOne', 'update', 'updateMany', 'updateOne',
];
export type readOnlyExcludeKeysModel = typeof readOnlyExcludeKeysModel[number];
export const readOnlyExcludeKeysDoc = <const>[
@taxilian
taxilian / makeUpdatePipeline.ts
Last active May 15, 2020
Mongodb 4.2 update pipeline creator which updates modified field if anything changed
View makeUpdatePipeline.ts
import mongoose, { LeanDocument } from "mongoose";
import '@/lib/PromiseAll';
// Used because Object.keys doesn't give us types for field names
export function keys<T extends object>(obj: T) : (keyof T)[] {
return Object.keys(obj) as (keyof T)[];
}
// Spelled incorrectly on purpose
const defaultIgnoreType = '__UNMODIFEID__';
@taxilian
taxilian / SessionInstance.ts
Last active May 11, 2020
Email address validation typescriptified model used by HamStudy.org, example of mongoose-decorators-ts use
View SessionInstance.ts
// excerpt, not full file
@schemaDef({
indexes: [
[{ session_def: 1, sequence_num: 1, owner: 1 }, { unique: true }],
[{ start_date: 1, end_date: 1 }],
[{ owner: 1, date: 1, session_def: 1, sequence_num: 1 }],
[{ password: 1, date: 1 }, { sparse: true }],
[{ date: 1 }],
],
@taxilian
taxilian / PromiseAll.ts
Created Apr 28, 2020
A more flexible Promise.all replacement, allows more syntax options including using objects / maps
View PromiseAll.ts
// Object.fromEntries polyfill, if you use this your tsconfig.json probably will need to be
// updated with something like this in compilerOptions (using this with node 10.17):
// "lib": [
// "ES2018", "ES2019.Object",
// ]
function ObjectFromEntries<A extends PropertyKey, B>(iter: [A, B][]) : Record<A, B> {
const obj: Record<A, B> = {} as any;
for (const pair of iter) {
@taxilian
taxilian / ebf.ts
Created Apr 16, 2020
EBF parser / generator for Amateur Radio VEC submission
View ebf.ts
export const velist = {
"anchorage": "Anchorage Amateur Radio Club",
"arrl": "American Radio Relay League (ARRL)",
"cavec": "Central America CAVEC, Inc.",
"golden": "Golden Empire Amateur Radio Society",
"lagroup": "Greater L.A. Amateur Radio Group",
"jefferson": "Jefferson Amateur Radio Club",
"laurel": "Laurel Amateur Radio Club, Inc",
"mrac": "MRAC VEC, Inc",
@taxilian
taxilian / README.md
Last active Jul 15, 2020
Improved type definitions
View README.md

Why these types?

These types are forked from the current (as of Jan 2020) mongoose types on definitelytyped; they add things like automatic handling of "lean" documents (including toObject) and advanced types for filter and update queries

Why not update these in DefinitelyTyped?

Well, I want to and I think we should, but I'm hesitant to try to push it through because there are some breaking

@taxilian
taxilian / ReadAheadIterator.ts
Last active Dec 17, 2019
Untested prototype for a readahead iterator in typescript
View ReadAheadIterator.ts
class ReadAheadIterator<T extends any> implements AsyncIterator<T> {
currentQ: Promise<T>[] = [];
constructor(private readNext: Iterator<Promise<T>>, private readAheadCount: number = 5) {
this.readAhead();
}
[Symbol.asyncIterator]() { return this; }
readAhead() {
while (this.currentQ.length < this.readAheadCount) {
@taxilian
taxilian / zsh_aliases.sh
Last active May 28, 2020
Handy aliases that I use on all my systems
View zsh_aliases.sh
# This makes the dark blue color lighter so you can read it
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Mac version
alias du1='du -d 1 -h'
# Linux version
alias du1='du --max-depth=1 -h'
@taxilian
taxilian / instructions.md
Last active Dec 2, 2019
Creating a case sensitive code volume on macOS which auto mounts inside your home directory
View instructions.md

Create /Users/<username>/code (or wherever you want it)

  1. Open Disk Utility; create a new volume:

    • APFS (Case Sensitive, Encrypted)
    • Put in the password; it won’t save yet
  2. Open terminal, run: sudo diskutil apfs list

    • Find the volume you created in the list; it’s probably the last item. Looks like this (volume CodeFS):

        Volume disk1s6 19927108-1370-4A52-840F-3AF7B9F5FB6D
      
You can’t perform that action at this time.