Skip to content

Instantly share code, notes, and snippets.

View johncrim's full-sized avatar

John Crim johncrim

  • Seattle area
  • 11:54 (UTC -07:00)
View GitHub Profile
@johncrim
johncrim / ng-new.sh
Created January 5, 2023 01:41
Yarn new Angular project
yarn dlx -p @angular/cli ng new $@
@johncrim
johncrim / InheritedProtoMemberAttribute.cs
Last active September 3, 2025 04:15
protobuf-net non-polymorphic member re-use
using System.Reflection;
using ProtoBuf;
using ProtoBuf.Meta;
/// <summary>
/// Property attribute for including base class members in derived class messages without using "oneof"
/// for polymorphism. Can be removed once https://github.com/protobuf-net/protobuf-net/issues/916 is implemented.
/// </summary>
[AttributeUsage(AttributeTargets.Property)] // | AttributeTargets.Field)]
public class InheritedProtoMemberAttribute : ProtoMemberAttribute
@johncrim
johncrim / final.ts
Created March 8, 2021 15:07
@Final decorator
export declare interface Type<T> extends Function {
new (...args: any[]): T;
}
function preventSubclassing<T>(constructor: Type<T>): Type<T> {
const newCtor = function (...args: any[]): T {
if (new.target.prototype !== constructor.prototype) {
throw new TypeError(`${constructor.name} cannot be subclassed`);
}
return new constructor(args);
#!/bin/bash
# Bash script to install latest ASP.NET Core 3.0 Preview 5 SDK
# This script is needed since the SDK builds don't seem to include .deb files hosted in any apt repos.
DOTNET_SDK_URL="https://download.visualstudio.microsoft.com/download/pr/7e4b403c-34b3-4b3e-807c-d064a7857fe8/95c738f08e163f27867e38c602a433a1/dotnet-sdk-3.0.100-preview5-011568-linux-x64.tar.gz"
# Must match the directory under /usr/share/dotnet/sdk/$ASPNETCORE_VER
ASPNETCORE_VER="3.0.100-preview5-011568"
DOTNET_PACKAGE_FILE="/tmp/aspnetcore-sdk-3.0.0-preview5.tar.gz"
@johncrim
johncrim / log-concept.spec.ts
Last active March 6, 2019 08:34
Concept for javascript/typescript logging. This preserves correct filename and line numbers in console.log, in the debug case. And, it provides a way to replace console.log calls with other logic in production. It also provides a way to stub out calls when the severity level is switched off.
/** Log severity options */
export class Severity {
static readonly Off = new Severity(0, 'off');
static readonly Debug = new Severity(1, 'debug');
static readonly Verbose = new Severity(2, 'verbose');
static readonly Info = new Severity(3, 'info');
static readonly Warn = new Severity(4, 'warn');
static readonly Error = new Severity(5, 'error');
static readonly Severe = new Severity(6, 'severe');