Skip to content

Instantly share code, notes, and snippets.

🎩 DATE OFF BY ONE DAY (EARLIER) FIX

If a Mongoose schema has a type of Date and you are using a <input type="date"> to allow the user to enter/select a date, the actual date stored in the database will be one day earlier than specified.

This is because of the way JavaScript's Date() class/constructor, which Mongoose uses to convert a string value into a data object, incorrectly sets the date if the string is in the YYYY-MM-DD format. You can demo this by typing new Date('2025-01-29') in the console - the returned date will be yesterday. Interestingly, new Date('01/29/2025') or even new Date('1-29-2025') do not suffer from this bug.

The most straightforward fix is to append T00:00 (designate the time) to the end of the date string. Try it in the console: new Date('2025-01-29T00:00'). You can code the fix in either the front or the backend (controller), for example:

mern-project-template Code-Along Guide

Today's plan to code a mern-project-template that includes JWT authentication and can be used to start any MERN-Stack project, including Project 3!

Initial Project Setup

  1. Create a folder named mern-project-template within the ~/code/ga folder.
  2. cd into the new mern-project-template folder and open it in VS Code.
  3. Open a Terminal in VS Code.
  4. Run npm init -y to create a package.json file.
@jim-clark
jim-clark / instructions.md
Created September 11, 2024 12:56
Instructions to set up a new MERN-Stack project by cloning the mern-project-template starter code

SET UP YOUR mern-project-template !

  • Please follow these instructions to set up the mern-project-template in your own personal GitHub account so that you can clone it for the Hoot project as well as your Project 3:
  • Move into your ~/code/ga folder: cd ~/code/ga
  • Clone my mern-project-template: git clone https://git.generalassemb.ly/SEB-0722/mern-project-template.git
  • Move into the newly created project folder: cd mern-project-template
  • Delete the current repo folder: rf -rf .git
  • Initialize a new local repo: git init
  • Make your first commit: git add -A && git commit -m "MERN Starter Code"
  • Create a new repo named mern-project-template in your personal GitHub account.

Automate Pulling Updates From Upstream

Did you know that we can write scripting functions in our shell (zsh/bash) configuration file?

Let's code a simple function that will run the git commands necessary to:

  1. Commit any changes you've made in the current local repo that you're in (in Terminal).
  2. Pull updates from the upstream remote.
  3. Push the new commits to the origin remote (typically your fork).

Identify the Shell Config File

@jim-clark
jim-clark / pull-upstream.md
Last active April 15, 2025 11:37
Obtain Updates to Class Repos (Course, Lectures & Assignments)

General Assembly

Choose From the Following Games

Note: Games are listed in approximate order of increasing difficulty.

  1. Spaceman
    • Word guessing game
  • May change "theme" to something other than Spaceman

Let's Code Connect-Four!

Intro

So far, we've covered the fundamentals of:

  • HTML
  • CSS
@jim-clark
jim-clark / guide-key-concepts.md
Last active March 28, 2024 13:23
Key Concepts of The Guide To Building a Browser Game

Key Concepts of The Guide To Building a Browser Game

Coders!

Before this morning's Rock-Paper-Scissors code-along and before you begin to code your amazing games for project 1, it's worthwhile to refresh the KEY CONCEPTS of the Guide on How to Build a Browser Game...

The Guide on How to Build a Browser Game is a proven PROCESS that helps students be successful by producing:

  • Well structured code that closely mimics the popular MVC (Model-View-Controller) pattern
  • More concise code (often, less is more)
  • Less buggy code

Django Class-Based View Customization Tips

ListView Filtering Example

class CatList(ListView):
  model = Cat
  
  # Only return the cats for the logged in user
 def get_queryset(self):

Rolling Back Django Migrations

Django migrations can be unapplied to a database in the reverse order that they were applied using the following commands...

Listing the Migrations for a Specific Django App

Run the following to list the existing migrations for the main_app Django app:

python3 manage.py showmigrations main_app