Continuing with the local library express tutorial. I am trying to search multiple files at once for missing code and grep
has been my go to tool. This situation has allowed me to play around more with the command and I am loving every minute of it.
I used the command to see where I was using certain properties in my view by running snippets like grep -ir due_back .
. I also checked which controller handlers were empty by running a command like grep -iA 3 update_post /controllers/*
I mentioned previously that grep
is an amazing tool for working through large code bases. I can only continue to emphasize this point. Honestly, learning and growing in comfort with the CLI and all the common Unix/GNU commands has been monumental in my development lately. It’s like each command that I get more comfortable with acts as a multiplier for me in working with new code bases. These tools help me learn a code base faster because I do not have to open each file and scan through it. I can scan all the files at once looking for particular pieces that are of interest in the moment. That’s the key difference maker.
Coming up on almost a year since starting the Missing semester course from MIT – I have not regretted their advice and emphasis on getting comfortable with the command line.
TLDR;
Okay, so here are the highlights of what I did:
- Practice -> Continued working through the practice ‘Local Library’ project in the MDN ExpressJS guide. Continued my work on part 6 of the tutorial. I added the virtuals to the
BookInstance
andAuthor
models so that their date values would fill in theHTML
form inputs correctly on the update pages. Also finished writing theBookInstance
updatePOST
request handler. Still have a bit more to go on this step. I am starting to pick it up but for a while there I was lost working in the codebase. Seems like I was a bit too lax these past few days and forgot myself LOL.
Sample grep
results from the Local Library Project
Command 1: grep -iA 3 update_post controllers/*
-i
= the search pattern (update_post
) is case insensitive.-A 3
= show an additional 3 lines after the matching linecontrollers
= folder/directory I want to search in*
= Wild card symbol -> Search through all files in folder/directory
Results:
controllers/authorController.js:exports.author_update_post = function(req, res) {
controllers/authorController.js- res.send('NOT IMPLEMENTED: Author update POST');
controllers/authorController.js-};
controllers/authorController.js-
--
controllers/bookController.js:exports.book_update_post = [
controllers/bookController.js- // Convert the genre to an array
controllers/bookController.js- (req, res, next) => {
controllers/bookController.js- if(!(req.body.genre instanceof Array)){
--
controllers/bookInstanceController.js:exports.bookinstance_update_post = [
controllers/bookInstanceController.js- // Validate and sanitize fields.
controllers/bookInstanceController.js- body('book', 'Book must be specified').trim().isLength({ min: 1 }).escape(),
controllers/bookInstanceController.js- body('imprint', 'Imprint must be specified').trim().isLength({ min: 1 }).escape(),
--
controllers/genreController.js:exports.genre_update_post = function(req, res) {
controllers/genreController.js- res.send('NOT IMPLEMENTED: Genre update POST');
controllers/genreController.js-};
Command 2: grep -ir due_back .
-i
= the search pattern (due_back_date
) is case insensitive.-r
= search recursively through all folders/directories.
= current folder/directory I want to search in
Results:
./controllers/bookInstanceController.js: body('due_back', 'Invalid date').optional({ checkFalsy: true }).isISO8601().toDate(),
./controllers/bookInstanceController.js: due_back: req.body.due_back
./controllers/bookInstanceController.js: body('due_back', 'Invalid date').optional({ checkFalsy: true }).isISO8601().toDate(),
./controllers/bookInstanceController.js: due_back: req.body.due_back,
./models/bookinstance.js: due_back: {
./models/bookinstance.js:BookInstanceSchema.virtual('due_back_formatted').get(function(){
./models/bookinstance.js: return DateTime.fromJSDate(this.due_back).toUTC().toLocaleString(DateTime.DATE_MED);
./models/bookinstance.js:BookInstanceSchema.virtual('due_back_form_formatted').get(function(){
./models/bookinstance.js: return DateTime.fromJSDate(this.due_back).toUTC().toFormat('yyyy-MM-dd')
./populatedb.js:function bookInstanceCreate(book, imprint, due_back, status, cb) {
./populatedb.js: if (due_back != false) bookinstancedetail.due_back = due_back
./views/bookinstance_delete.pug: p #[strong Due back:] #{bookinstance.due_back_formatted}
./views/bookinstance_detail.pug: p #[strong Due back:] #{bookinstance.due_back_formatted}
./views/bookinstance_form.pug: label(for='due_back') Date when book available:
./views/bookinstance_form.pug: input#due_back.form-control(type='date' name='due_back' value=(bookinstance === undefined ? '' : bookinstance.due_back_form_formatted))
./views/bookinstance_list.pug: span (Due: #{val.due_back_formatted} )
./views/book_detail.pug: p #[strong Due back:] #{val.due_back_formatted}
Goal For Round 8 of the #100DaysofCode Challenge
This is my eighth round of the “#100daysofcode” challenge. I will be continuing my work from round five, six, and seven into round eight. I was working through the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. My goal was to become more familiar with algorithms and data structures. This goal was derived from my goal to better understand operating systems and key programs that I use in the terminal regularly e.g. Git. This goal was in turn derived from my desire to better understand the fundamental tools used for coding outside of popular GUIs. This in turn was derived from my desire to be a better back-end developer.
I am currently putting a pause on the algorithm work to build some backend/full stack projects. I primarily want to improve my skills with the back-end from an implementation perspective. I have improved tremendously in terminal and CLI skills but I lost focus due to how abstract the algorithm concepts got. I wanted to work on things that were more tangible until I can get to a position where I could directly benefit from improving my algorithm skills and theoretical knowledge. So that’s the focus right now. Build my backend skills and prove my full stack capabilities by building some dope projects.
Again, I still have no idea if my path is correct but I am walking down this road anyways. Worst case scenario I learn a whole bunch of stuff that will help me out on my own personal projects. Best case scenario I actually become one of those unicorn developers that go on to start a billion dollar company… You never know LOL.