Skip to content

Instantly share code, notes, and snippets.

View taxilian's full-sized avatar

Richard Bateman taxilian

View GitHub Profile
@taxilian
taxilian / README.md
Created January 4, 2021 21:02
macOS set up yubico-piv-tool

Why?

Homebrew build doesn't work -- dunno why. I should figure out why and fix it then submit a PR, but I'm lazy.

Prep

brew install cmake libtool pkg-config check gengetopt help2man pcsc-lite openssl
@taxilian
taxilian / .zshrc
Last active July 19, 2021 17:56
Easily switch between different SSH agents on mac, probably easy to adapt to any linux
function showAgent() {
echo The current SSH agent is $(readlink ~/.ssh-agent-link)
}
function updateSshAgentSock() {
NEWSOCK=$2
if [ -z "$NEWSOCK" ]; then
echo -n "No socket found for ${1}; not changing agents. "
return 1
elif [ ! -S "$NEWSOCK" ]; then
@taxilian
taxilian / compress.yaml
Last active September 16, 2020 16:02
Traefik kubernetes configuration that I use
# Enable gzip compression
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: gzip-compress
spec:
compress: {}
@taxilian
taxilian / common.ts
Created September 14, 2020 15:31
Example typescript pattern for defining a view using 'mongoose-decorators-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 22:13
Mongodb 4.2 update pipeline creator which updates modified field if anything changed
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 18:21
Email address validation typescriptified model used by HamStudy.org, example of mongoose-decorators-ts use
// 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 April 28, 2020 21:21
A more flexible Promise.all replacement, allows more syntax options including using objects / maps
// 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 April 16, 2020 20:29
EBF parser / generator for Amateur Radio VEC submission
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 July 15, 2020 15:33
Improved type definitions

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 December 17, 2019 19:34
Untested prototype for a readahead iterator in typescript
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) {