Skip to content

Instantly share code, notes, and snippets.

@Corky3892
Corky3892 / filterDeep.ts
Created January 31, 2022 19:34
Parse an object recursively, applying a test function to each entry and return true on the first entry which passes the test function.
/**
* This method will scan the provided object recursively looking for entries which match the test function. When one is found will return true. Sample Usage:
* ```
* // Return those objects in the objArray with an entry equal to apple.
* objArr.filter(x, (o, k) => o[k] === 'apple');
* ```
*
* @param o The object to filter.
* @param fn The predicate function to test at each level of the object.
* @returns A boolean which when true indicates that the object meets the condition.
@Corky3892
Corky3892 / findOneAndUpdateWithValidation.ts
Last active October 1, 2021 19:37
Trying to pass the runValidators to the mongoose findOneAndUpdate() method does produce great results (as of 6.0.5). Here is a generic solution to the problem. PS: If any mongoose / typescript Guru's out there know how to make this truly generic (where type T can be inferred and not assigned) please do let me know.
import { FilterQuery, UpdateQuery, QueryOptions, Model, model } from 'mongoose';
/**
* As of mongoose 6.0.5 findOneAndUpdate does not handle the runValidators flag correctly.
* If you are running upsert in combination with this flag then the update will not get validated correctly.
* This is will fix that problem.
* @param filter The query which will be used to find the document.
* @param update The update which shall be applied.
* @param options The optional Query Options to extend the behavior.
*/
@Corky3892
Corky3892 / gist:f07a1234bb558de4d354d8c93e8375c2
Created September 25, 2019 16:03 — forked from fernandoaleman/gist:5083680
How to update VirtualBox Guest Additions with vagrant
# Start the old vagrant
$ vagrant init centos-6.3
$ vagrant up
# You should see a message like:
# [default] The guest additions on this VM do not match the install version of
# VirtualBox! This may cause things such as forwarded ports, shared
# folders, and more to not work properly. If any of those things fail on
# this machine, please update the guest additions and repackage the
# box.