Image for post
Image for post

A few weeks ago I wrote a post about designing Mongoose schemas for a MongoDB that I am porting from a Postgres API I built a few months back. The project, Cart Compass, is a virtual shopping cart that allows users to create lists and then dynamically reorder them in a way that will guide quickly through the supermarket aisles.

I spent last week setting up the routes in Express to see how well the nested Mongoose schemas function at delivering requested data from the database to the React client.

Initial Setup

Heading over to VSCode’s terminal I install Express 4.14.1. I also install the node.js CORS package, which enables cross-origin resource sharing between resources. By default, browsers won’t allow servers from the same origin to talk, the situation we find ourselves in when working locally in development mode with say, an Express server running serving the APIs and a React site all running at localhost. This behavior is for security, but won’t be an issue running things locally. Installing the CORS package allows us to by pass this restriction. …

Image for post
Image for post

As developers we like to build things, to get our hands dirty. Writing code, debugging, testing, deploying are all part and parcel of our process. But in our rush to construct we can forget the benefit of seeing the forest through the trees before hacking away at the branches. The investment we make in planning will help create a clear path that ultimately minimizes the number of wrong turns we make while building our apps, and if we should stray off course, provides a solid framework to get back on track.

Let’s look at steps we can take to help focus the planning stages of our coding projects. …

As promised, I’ve begun to refactor my Cart Compass shopping list SPA API using Node.js/Express/MongoDb. The original deployment’s API was built with Ruby on Rails and PostgreSQL, but I’ve experimented with MongoDb a bit and the compact structure of Cart Compass’ DB seemed like a good case for using MongoDb.

MongoDb falls into the class of noSQL databases as opposed to SQL databases like PostgreSQL. The two classes are quite philosophically different with the SQL databases built on a series of interrelated tables, each table responsible for a specific area of data. Designed correctly, a SQL database offers a powerful way of storing and retrieving data, especially in large systems that require a strict associations between the tables. …

Leetcode #62 — a JavaScript Solution

This puzzle requires you to calculate the total number of unique paths from the top lefthand corner of a grid to the bottom righthand corner. You can only travel to the right or down, but may switch directions as much as you want.

Here’s one possible path for a 3 x 4 grid:

Image for post
Image for post

The grid above is has 10 possible solutions, and is simple enough that you can, with not too much trouble, imagine all 10 paths visually. However, as the grid expands, the permutations become much more difficult to keep track of. …

Jest is one of the most popular testing suites for Javascript and can be used for unit, component, and integration testing. Jest allows you to run through various aspects of your code while verifying that the results are what you expect.

The setup:

npm install --save-dev jest

Jest will automatically run any file that:

  • is named with a .test.js extension OR
  • is inside directory named ‘__tests__’

In order to run your tests, you’ll need to import your code modules into the test file(s) so that they can be accessed by the tests:

//sayName.jsfunction sayName(name){
return `My name is ${name}`…
Image for post
Image for post
Photo by Peter Pryharski on Unsplash

This blog should serve as an introduction to what TypeScript is (and isn’t) as well as basic instructions for getting TypeScript set up and running in VSCode allowing you to further experiment on your own.

JavaScript can be notoriously loose with its interpretation of code. Numbers are coerced to strings. Strings are coerced to numbers. You can write a function that multiplies two numbers, and then pass a string as one of the arguments without an error.

3 * '3' // 9
3 + '3' // '33'
3 + 3 + '3' // '63'
function multiply(a, b){
console.log(a*b) …

Here’s my JavaScript solution to this popular challenge.

Input: A set of SORTED non-overlapping intervals (intervals) AND a new interval (newInterval).

Output: A new set of SORTED intervals that includes the new interval. If the new interval overlaps any of the other intervals, the intervals need to be merged.

Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
Output: [[1,5],[6,9]]
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
Output: [[1,2],[3,10],[12,16]]
Explanation: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].

Constraints: The set of intervals needs to be ordered, and there can be no overlapping.

First we can quickly determine if the following conditions are…

There are three ways of declaring variables in JavaScript — var, let and const. Each method of declaration functions slightly differently. Var is the original JS variable declaration method. With the advent of ES2015 let and const were added.

Variables declared with var and left uninitialized are hoisted to the top of the execution context as ‘undefined’ whereas a variable declared with let or const needs to be initialized at declaration time, before being referenced. In general it’s good practice to initialize your variables when declaring and before referencing them anyway. Let and const add some extra safeguards.

console.log(x); //undefined
var x = 'pig';
console.log(x); …

It’s week three of Shopping List (Cart Compass) development and, while it’s not quite ready for prime time, it’s getting closer.

Image for post
Image for post

The Story:

Our family has worked out week long cooking assignments for each of us. I’m not a big fan of hanging out in the local grocery store, so I wanted a shopping list that would allow me to add items, by category, and then reorder the categories to correspond to the layout of my local HEB (if you’ve ever lived in Texas, you know about HEB!). …

Last week I shared the logic and components to view a sorted list of items from a shopping list SPA that I’m designing. At that point I had been focusing on designing the React/Redux front end only, using seeded data I’d provided in the code. This week I’ll outline some of the decisions I’ve made with regards to calls to the Rails API that I’ve set up to house the Postgres database. This is more of an exploration than a concrete set solution.

Here are some of the features I’ve decided that I want for the shopping list:

  • A User can create a new named List. …

About

Rick Glascock

After years of teaching music in Austin, Shanghai and Yangon, I’m making a career change to my other passion, software development.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store