Skip to content

Instantly share code, notes, and snippets.

# This is a list of rules for ignoring files in every Git repository on your
# computer. See https://help.github.com/articles/ignoring-files

# GitHub maintains a repository of items that can generally be gitignored
# globally safely at: https://github.com/github/gitignore/tree/main/Global

# GitHub also maintains a repository of language-specific items that should
# typically be ignored on a per-project basis with a .gitignore in that
# project's root directory.

Accepting Multi-Line Input and Rendering in EJS

If you'd like a user to be able to enter multi-line text and have that text render the line-breaks within HTML, read on...

Mongoose Schema

As usual, use a String property on a schema to hold the text content, for example:

const logEntrySchema = new Schema({

Accessing Mongoose enum Validator Arrays

If you are using an enum validator in a schema and would like to access and iterate over the enum's strings to, for example, render the <option> tags for a <select> element, you can access the array of strings in your controller function and pass them to your template as follows:

// models/movie.js

const movieSchema = new Schema({
  ...
  mpaaRating: {

Using Neon for PostgreSQL Hosting

Creating a Database

  1. Sign up at https://neon.tech/.

  2. You get one free "project" which can contain multiple "branches" which can contain multiple databases. Name your project something like "sei" and stick with the default "main" branch.

  3. Click the Database dropdown.

Displaying Error Detail in the MERN-Stack

Scenario

When errors happen in the controller, typically due to validation errors when CUD'ing MongoDB/Mongoose documents, you might want to display specific error information to the user instead of a generic error message.

Let's assume that the schema for a User model has two properties, username & email, that need to be unique. When a user signs up, if either property is not unique, we want to let them know which property, username or email, caused the error.

The demonstration code we're going to use was created by cloning mern-infrastructure and updating the userSchema as follows:

@jim-clark
jim-clark / py-pac-poe-solution-1.py
Last active May 23, 2024 21:34
Solution to Optional Py-Pac-Poe Lab
# Py-Pac-Poe
print("----------------------")
print("Let's play Py-Pac-Poe!")
print("----------------------\n\n")
score = {'X': 0, 'O': 0, 'T': 0}
num_wins = int(input("How many wins to play to? "))
board = {}
turn = 'X'
winner = None
require('dotenv').config();
require('./config/database');
const Movie = require('./models/movie');
const Performer = require('./models/performer');
(async function() {
/*-- Write the code for each exercise below --*/
exports.performers = [
{name: 'Natalie Portman', born: '06-09-1981'},
{name: 'Kevin Bacon', born: '07-08-1958'},
{name: 'Tom Cruise', born: '07-03-1962'},
{name: 'Brad Pitt', born: '12-18-1963'},
{name: 'Emma Watson', born: '04-15-1990'},
{name: 'Carrie Fisher', born: '10-21-1956'},
{name: 'Mark Hamill', born: '09-25-1951'},
{name: 'Harrison Ford', born: '07-13-1942'},
{name: 'Jodie Foster', born: '11-19-1962'},

Technical Screening Interview Practice Guide

This guide contains instructions for the Technical Screening Interview Practice session of the Technical Interviewing Basics webinar.

Preparation for Taking Notes, Making Observations, etc.

For quick notes and observations, the Interviewer may want to copy/paste the following "URL" into the browswer's address bar:

data:text/html,