Skip to content

Instantly share code, notes, and snippets.

View josephdpurcell's full-sized avatar

Joseph D. Purcell josephdpurcell

View GitHub Profile
@josephdpurcell
josephdpurcell / itzg_docker-minecraft-bedrock-server_vatonage-one-block-boot.log.txt
Created December 17, 2023 00:08
Minecraft server log when booting itzg/docker-minecraft-bedrock-server with vatonage's one-block world 2023-12-16
$ docker compose up
[+] Running 1/0
✔ Container mc Recreated 0.1s
Attaching to mc
mc | DEBU[0000] Using /data to match uid and gid
mc | DEBU[0000] Resolved UID=0 from match path
mc | DEBU[0000] Resolved GID=0 from match path
mc | Looking up latest version...
mc | Updating permissions
mc | 2023/12/16 11:45:41 Setting level-name to OneBlock in server.properties
@josephdpurcell
josephdpurcell / README.md
Created December 8, 2022 17:56
How to enable autocomplete and autocorrect on CodeMirror6

Setup dependencies:

npm init -y
npm i codemirror @codemirror/lang-javascript
npm i rollup @rollup/plugin-node-resolve

Create an editor:

@josephdpurcell
josephdpurcell / README.md
Last active January 21, 2023 02:54
How to integrate Directus and Listmonk using Flows

I want a manual trigger that when clicked will create a Campaign in my Listmonk instance, but only if the item is published.

Step 1: Create a Collection

Create a Collection called "Post" with fields:

  • uuid (string, system field added during creation; this is the ID specifier)
  • status (string, system field added during creation)
  • title (string)
  • content (Markdown)
@josephdpurcell
josephdpurcell / param-type.enhancer.ts
Last active September 7, 2022 15:29
PartialBody decorator for NestJS
import { ParamDecoratorEnhancer } from '@nestjs/common';
import { METADATA__PARAM_TYPE } from './constants'; // METADATA__PARAM_TYPE = 'partialBodyType'
/**
* This enhancer grabs the Typescript type of the parameter and shoves it into
* the metadata. We do this because the CustomParamFactory does not have access
* to the type of param.
*/
export const paramTypeEnhancer: ParamDecoratorEnhancer = (
target: Record<string, unknown>,
@josephdpurcell
josephdpurcell / my-decorator.ts
Created September 7, 2022 14:14
Get ArgumentMetadata in NestJS createParamDecorator
import { ArgumentMetadata, createParamDecorator, ExecutionContext } from '@nestjs/common';
import { METADATA__PARAM_TYPE } from '../constants'; // METADATA__PARAM_TYPE = 'myType'
import { paramTypeEnhancer } from './param-type.enhancer';
export const MyDecorator = createParamDecorator(
async (data: unknown, ctx: ExecutionContext): Promise<any> => {
const metatype = Reflect.getOwnMetadata(METADATA__PARAM_TYPE, ctx.getHandler());
// We build the argument metadata that @nestjs/class-validator is expecting.
// Specifically, we specify the type as "custom" -- this is a special value
@josephdpurcell
josephdpurcell / google-cloud-structured-logger.ts
Last active December 2, 2021 21:38
An opinionated Google Cloud structured logger
/**
* Google's logging enums:
* DEFAULT (0) The log entry has no assigned severity level.
* DEBUG (100) Debug or trace information.
* INFO (200) Routine information, such as ongoing status or performance.
* NOTICE (300) Normal but significant events, such as start up, shut down, or a configuration change.
* WARNING (400) Warning events might cause problems.
* ERROR (500) Error events are likely to cause problems.
* CRITICAL (600) Critical events cause more severe problems or outages.
* ALERT (700) A person must take an action immediately.
@josephdpurcell
josephdpurcell / sub-documents-in-array.ts
Last active November 29, 2021 18:28
NestJS + mongoose: how to find and set sub document values by object or array
export class MyModel extends BaseModel {
@prop({ required: false, items: MyModel })
items: MyModel[];
}
export class ModelService extends BaseService {
async findByNestedField(key: string): Promise<MyModel> {
return await this.findOneAsync(
{
items: {
@josephdpurcell
josephdpurcell / README.md
Last active April 5, 2024 15:41
NestJS: Ignore global ValidationPipe interceptor for a controller route

What is this?

This is an example of how to ignore a global validation pipe for a specific parameter, e.g. a request body. In fact, this example just shows a request body but you could apply this principle to other decorators.

This approach assumes validateCustomDecorators: false in the global validation pipe. If validateCustomDecorators is true in the global pipe I think you're out of luck. If that is your situation, consider refactoring so that validateCustomDecorators is false in the global pipe and then have each custom decorator add validation if it needs it.

How does this work?

The NestJS ValidationPipe does not validate custom decorators. So, in this above example we just make a @RawBody() param decorator, and NestJS will skip validating it.

@josephdpurcell
josephdpurcell / migrate_plus.migration.blog.yml
Last active October 17, 2019 00:04
A script to import sample data into Jackrabbit JCR
id: blog
label: Blog
source:
plugin: jcr
host: "http://localhost:8080/server"
query: 'SELECT * FROM [nt:unstructured] AS node WHERE ISDESCENDANTNODE(node, "/migrate_source_jcr_example/blog") AND [sling:resourceType] = "components/structure/page"'
type: "JCR-SQL2"
user: "admin"
pass: "admin"
workspace: "default"
@josephdpurcell
josephdpurcell / drupalci.yml
Last active October 1, 2019 11:19
Drupal 9 compatibility drupalci-.yml
# This file customizes the steps that DrupalCI will use when testing this project.
#
# The primary customization provided here is to check for deprecation errors. It is recommended
# to do this only when you've used https://github.com/mglaman/drupal-check/ to verify any
# existing deprecation errors are addressed.
#
# Learn to make one for your own drupal.org project:
# https://www.drupal.org/drupalorg/docs/drupal-ci/customizing-drupalci-testing
build:
assessment: