Skip to content

Instantly share code, notes, and snippets.

View vhbui02's full-sized avatar

VH vhbui02

View GitHub Profile
@vhbui02
vhbui02 / mongodb-null-non-exist.md
Created May 16, 2023 08:22
[MongoDB check for null and non-exist field] just like JS #mongodb

null + no exist

find({item: null})

only null

find({
	item: { 
  	$type: 10	
  }
})
@vhbui02
vhbui02 / mongodb-r-operation.md
Last active May 17, 2023 11:46
[MongoDB R operation]

Get list of Collection

db.getCollectionInfos() db.getCollectionNames()

MAIN METHOD

db.collection.find()

MATCH NORMAL DATA TYPE

Match Embedded/Nested/Sub Document inside a Document

@vhbui02
vhbui02 / mongodb-c-operation-insert.md
Last active May 16, 2023 14:27
[MongoDB C operation - INSERT]

single docs

insertOne()

multiple docs

insertMany()

NOTE: if Collection does not exist yet. The field specifed inside above will be taken as blueprint to construct a new collection (if _id not specified then it is auto added). After then it could continue to resolve the insert operation at start.

db.people.insertOne( {
@vhbui02
vhbui02 / mongodb-crud.md
Last active May 17, 2023 17:47
[MongoDB Capped - Time Series] when creating a new collection, you can choose either 0 or 3 #mongodb

Capped collection

  • fixed size
  • circular
  • data are placed by their insertion order => sp high performance in CRD
  • docs also stored in the order of disk storage
  • ensure that docs size NOT increase the size allocated on disk
@vhbui02
vhbui02 / mongodb.md
Last active May 18, 2023 03:53
[MongoDB General] takes weeks to months to learn, i've managed in 3 days #db #mongodb

Research later

  • readConcern
  • readPreference
  • writeConcern

Return full result set in VSCode playground (default in playground is 20)

db.getCollection('insert collection name here!').find({}).toArray()

Note: could use .hasNext()/.next() to iterate

@vhbui02
vhbui02 / react-hooks.md
Last active May 13, 2023 04:03
[React Hooks] proper learning React Hooks #react #hooks

Initial Render and Re-renders

The initial render is the 1st time that the component tree is rendered to the DOM. It happens when the application first loads, or when the root component is first rendered. (also known as "mounting" the components)

Re-renders, on the other hand, happen when the components's state or props change, and the component needs to be updated in the DOM to reflect these changes.

React uses a virtual DOM to optimize the process of updating the actual DOM, so that only the necessary changes are made.

How do you trigger a re-render in a React component?

  • changing the component's state or props.
  • Parent element re-render => Child also re-render, even though its state or props haven't changed. (need optimization)
@vhbui02
vhbui02 / font-awesome.md
Created May 11, 2023 15:26
[font-awesome] very good icon assets #css
@vhbui02
vhbui02 / vite.md
Last active May 13, 2023 03:18
[Vite] another React framework, but (maybe) better than CRA #cra #vite #react

Vite use JSX, but default Vite doesn't know how to

Specify some config

Vite doesn't re-render everything inside a component, just the parts that the changes affects

const [value, setValue] = useState(0);

// changeing
// setValue(value + 1)
@vhbui02
vhbui02 / javascript.md
Last active May 11, 2023 17:45
[JavaScript] Some best practices I've learnt on Internet'

Optional chaining (?.)

Check if the obj accessed or function called, that used this operator, is undefined or null. The expression short circuits and evaluates to undefined instead of throwing an error.

obj.val?.prop
obj.val?.[expresions]
obj.func?.(args)

ALL CAPS

@vhbui02
vhbui02 / inport-export.md
Last active May 9, 2023 08:49
[import/export in CJS vs ES6] the last time i'm gonna forget about this #js

CommonJS Syntax (CJS for short)

Module system used in Node.js and other JavaScript environments.

Importing

const moduleA = require('./moduleA'))