Skip to content

Instantly share code, notes, and snippets.

@rcollette
rcollette / TargetedRankRequirementsReport.sql
Last active May 9, 2024 14:48
PostgreSQL database for ScoutBook exports and targeted rank advancement planning
-- Create a database in PostgreSQL
-- Apply this SQL to the dabase, using the command:
-- psql -d theDatabaseName -f TargetedRankRequirementsReport.sql
-- Import the Scoutbook exported troop roster into the scouts table first.
-- Import Scoutbook exported rank requirements into the rank_requirements table second.
-- Run various views to get "Reports". The view scout_requirements_targeted_all_scouts is probably of the most
-- interest and can be further filtered to target your needs.
@rcollette
rcollette / MoqItExtensions.cs
Created September 26, 2023 19:16
FluentAssertion Matcher for Moq
namespace Moq;
public static class ItExt
{
public static T IsEquivalentTo<T>(T expected)
{
// An inner function like this is called a local function, equivalent to Func<>() = ()=> ;
bool Validate(T actual)
{
actual.Should().BeEquivalentTo(expected);
@rcollette
rcollette / MatcherExtensions.cs
Last active September 26, 2023 19:15
moq enumerable matcher
namespace Moq;
public static class MatcherExtensions
{
public static T[] CreateEnumerableMatcher<T>(this T[] expectation)
{
return Match.Create<T[]>(
inputCollection =>
{
bool result = expectation.All(inputCollection.Contains);
return result;
@rcollette
rcollette / vpc-peering.ts
Created October 4, 2020 00:50
AWS CDK VPC Peering and Routing
private _createVpcPeering() {
// Currently, the console shows a name attribute for the peering connection but no
// name is available in the peering connection properties.
this.vpcPeeringConnection = new CfnVPCPeeringConnection(this, 'PeerToLegacyVpc', {
vpcId: this.vpc.vpcId,
peerVpcId: this.legacyVpc.vpcId,
}
);
}
@rcollette
rcollette / sumo_logic.config
Last active September 25, 2020 21:09 — forked from JefStat/sumo_logic.config
Elastic Beanstalk Sumo Logic Config via Gitlab Environment Variable
# This will automatically install the Sumo Logic collector on AWS Elastic
# Beanstalk instances. Add this to the .ebextensions folder in your app root
# To add or remove tracked files, simply add or remove source hashes to the
# sources array.
packages:
rpm:
SumoCollector: https://collectors.sumologic.com/rest/download/rpm/64
files:
"/home/ec2-user/setup-sumo.sh":
@rcollette
rcollette / PromiseResolver.ts
Created April 24, 2020 15:56
A Typescript Class Used to Mock Promises in Unit Tests
// tslint:disable-next-line:no-any
export class PromiseResolver<T = any> {
private _resolve: (value?: T | PromiseLike<T>) => void;
// tslint:disable-next-line:no-any
private _reject: (reason?: any) => void;
// tslint:disable-next-line:no-any
public executor = (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => {
this._resolve = resolve;
this._reject = reject;
@rcollette
rcollette / mongdb-aggregate-lookup
Created September 6, 2019 04:16
Example of a 3 level nested lookup and projection with MongoDb. This is effectively a paged search query.
db.someCollection.aggregate([
{
"$match":{
"$text":{
"$search":"boundary"
}
}
},
{
"$match":{
@rcollette
rcollette / add-webapi-solution.sh
Created May 31, 2019 18:33
An opinionated bash script for creating a .NET Core webapi (microservice) solution.
#!/bin/bash
set -e
set -x
export SOLUTIONNAME=${1:-"SolutionName"}
export FRAMEWORK=${2:-"netcoreapp2.2"}
export LANGVERSION=${3:-"7.3"}
add_project() {
if [[ "${1}" = "classlib" ]]
@rcollette
rcollette / gist:6252767
Created August 16, 2013 19:24
Results of IDbCommand cancel and no cancel when disposing before all records have been read.
<?xml version="1.0" encoding="utf-8"?>
<PerformanceReport>
<CallTreeSummary>
<CallTree Level="0" FunctionName="DataReaderDisposeCancelTest.exe" InclusiveElapsedTime="22,386.00" ExclusiveElapsedTime="0.00" InclusiveApplicationTime="0.51" ExclusiveApplicationTime="0.00" InclusiveElapsedTimePercent="100.00" ExclusiveElapsedTimePercent="0.00" InclusiveApplicationTimePercent="100.00" ExclusiveApplicationTimePercent="0.00" NumCalls="0" ModuleName="" />
<CallTree Level="1" FunctionName="DataReaderDisposeCancelTest.Program.Main(string[])" InclusiveElapsedTime="22,386.00" ExclusiveElapsedTime="0.51" InclusiveApplicationTime="0.51" ExclusiveApplicationTime="0.00" InclusiveElapsedTimePercent="100.00" ExclusiveElapsedTimePercent="0.00" InclusiveApplicationTimePercent="100.00" ExclusiveApplicationTimePercent="0.35" NumCalls="1" ModuleName="DataReaderDisposeCancelTest.exe" />
<CallTree Level="2" FunctionName="DataReaderDisposeCancelTest.Program.NoCancelTest(class System.Data.IDbCommand)" InclusiveElapsedTime=
@rcollette
rcollette / gist:6252733
Created August 16, 2013 19:19
Performance test code comparing IDataReader disposal prior to all records being read, using IDbCommand.Cancel() and without using Cancel()
namespace DataReaderDisposeCancelTest
{
using System;
using System.Configuration;
using System.Data;
using System.Data.Common;
internal class Program
{
private const int iterations = 50;