Year #3, Week #18 đť âłď¸
Homework Plan
- 1 day Monkey Assignment #26 đ
- 1 day review all flashcards in your (new Netlify) app.
- 1 day read King C chapter 15 đ
- 1 day King C programming exercizes đ
- 1 day touch typing practice
- 1 or 2 days Flashcards assignment
- 1 day watch CS50
CS50 Lecture #4 segment,
from
58:44
to end. - 3 days Execute Program homework
Monkey #26 đ
- Address all feedback from prior MRâs, and merge.
- Create a new branch.
- Double-check that you did the first two steps.
- Start where you left of last time, after the 3.9 Bindings and the Environment section, which is labeled 3.10 Functions and Function Calls.
- â ď¸ DONT COMPLETE all of 3.10. Instead, stop đ in the middle of page 143
(pdf) or 181 (print), where he gets the tests passing and starts by saying
Easy right? The test passes.
. - Commit your work.
- As always, make sure to try to do as much as you can without the videos, but always also watch the videos and update your code to (mostly) match.
- Video link
- Submit a MR, Review your diffs and fixup!!, then slack the MR url
King C: Chapter 15 (Writing Large Programs) đ
First, make sure youâve slowly and carefully read all of chapter 15 of King C. assignment.
Make sure youâve addressed any feedback from last weekâs King C assignment, merge, and make a new branch.
Complete Programming
Project #1
, following these steps:- All the files needed (including a
quote.txt
file for testing) are in this snippet. Put them in a separate folder within your chapter 15 folder. - Before you make any changes to the file, get it to build using
cc
, outputting to a file calledjustify
. (Hint: in the book he basically gives you the command, just find where it is and changegcc
tocc
) - Once you get it to compile, run it against the
quote.txt
file by typing./justify < quote.txt
(The<
redirection character uses the contents of a file as the input to the program it âpointsâ to) - figure out another unix-command that will have the exact same effect as
./justify < quote.txt
- next, recreate the
Makefile
he lays out on Page 367, changinggcc
tocc
again. Type a command to âmakeâ the program using the Makefile, and double-check that it works. - look in the directory⌠do you see some new files? do you understand what they are and why theyâre there?
- Finally, do what he says in the assignment: âImprove the program by having
write_line
alternate between putting the larger gaps at the end of the line and putting them at the beginning of the line.â (read the below bullet points first) - What he means by âalternate betweenâŚâ is this: right now the program is weighted towards adding more spaces towards the end of the line, if the spaces canât be divided evenly, like so:
foo bar baz lol jim jo it so my
- when youâve completed the task, it will alternate each line, putting extra spaces at the end, then the beginning, resulting in this:
foo bar baz lol jim jo it so my
- the reason why the program works the way it does is that when you divide two
int
s in C, any decimal number that would result is implicitly ROUNDED DOWN:
int x = 3 / 2; // `x` = 1
- this causes extra spaces to keep getting deferred till later in the
write_line
function - to change this to alternating, you will have to keep track of some variable to flip back and forth to know whether you should weight extra spaces early or late.
- when you are trying to weight early, youâll need to ROUND UP when dividing instead of down
<math.h>
has two functionsfloor
andceil
that will be useful- you can cast an
int
to a float like this(double) x
.
- All the files needed (including a
Complete
Project #2
, using the same files as project 1.Complete
Project #3
, following these steps:- Make a new folder inside your âchapter 15â folder called
qsort/
and inside that folder, add a file calledqsort/qsort.c
containing this code. - Make the changes he describes.
- To test that your program works, for this project I want you to use a bare
cc ...
CLI command, not a makefile. Put the command you used in a comment just above yourmain()
function, so I can see the command you use when I look at your MR.
- Make a new folder inside your âchapter 15â folder called
Complete
Project #4
, following these steps:- Make a new folder inside your âchapter 15â folder called
remind/
and inside that folder, add a file calledremind/remind.c
containing this code. - Make the changes he describes.
- To test that your program works, for this project I want you to use a
Makefile
, and commit it with your work.
- Make a new folder inside your âchapter 15â folder called
Complete
Project #5
, using your code from Chapter 10 project 6 (RPN calculator), copying the code into a new folder in your âchapter 15â folder, and splitting it apart as required. You can usecc
ormake
for this one.before you commit, make sure you remove any
*.o
files and executable files (unless they were already ignored by your.gitignore
)commit your work, create a MR
before you slack me the URL, review your own diffs, clean up anything you notice, then slack me the URL.
Flashcards
- Make sure youâve addressed all feedback and merged any open MRs for both the webapp and api side of your project.
- create new branches for both your API and webapp, youâll be touching both in this assignment.
- Read this whole assignment through before starting.
- Part 1:
- when we did your last set of migrations in your api, we didnât update any of
your API code, so thereâs at least one error in your API right now youâll
need to fix, because your
GET /cards
function is probably still trying to read a column out of the database likecreated
ordate
ortime
that no longer exists. Find this and fix it. Make sure you update any types in your API to match. - on a similar note, you might need to check your web app code â if your api
returns different keys now (it might, or it might not, based on if you alias
your columns), then your webapp will have to adapt. Be sure any types for your
webapp are updated. Running
npx fldev ts:check
might be helpful if you update your types, to find all typescript errors. - get your âdevâ versions of your web-app and API going, and make sure they are talking to each other and things are working correctly.
- Make it so you can flip your cards:
- the state should go in redux, not local react state
- youâll need to decide how the user flips a card⌠what action flips it?
- commit your work
- Part 2:
- next, as a preparation for future work, I want you to make a new file called
lib/token-storage.ts
, and a corresponding test file:lib/__tests__/token-storage.ts
. - in your non-test file, start with this code:
// returns a token from LocalStorage,
// or null if it doesn't exist, or is expired
export function getUserToken(now: Date = new Date()): string | null {
throw new Error(`Method not implemented.`);
}
// sets a token in local storage, with an optional expiration date
export function setUserToken(token: string, expires?: Date) {
throw new Error(`Method not implemented.`);
}
- now, implement these two functions, with tests covering all these cases:
- getting a token when there is nothing in storage should return null
- getting a token that is not expired should return the token
- getting a token that is expired should return null
- setting a token should allow it to be retrieved later with getUserToken
- setting a token with no expiration means the token is only valid for the current session
- setting a token with an expiration should allow it to be retrived before it expires
- setting a token with an expiration should cause null to returned from getUserToken after the expiration is past.
- note, in order to âcontrol timeâ, the
getUserToken
function allows you to pass in a date value representing now. If you donât pass one in, it defaults to using the actual current time, via a default argument. - note 2: in order to get jest to allow you to use
localStorage
inside your functions, add this to the top of your test file:
/**
* @jest-environment jsdom
*/
- note 3: tokens with no expiration only are good for the âsessionâ which means
they should be stored in
sessionStorage
â this means your implementation will need to use both sessionStorage and localStorage â youâll need to figure out which ones (or both?) to check for a stored token, and in which one to set a token. đ¤ - note 4: review in the old ânew stuffâ the week when we did localStorage â sessionStorage is exactly the same, except it only lasts for the session.
- commit your work
- push up MRs for both API and web app side
- review your diffs
- slack me your MR urls
- after I review your âAPIâ MR and you merge, I want you to âdeploy it to productionâ, which means update the repo on the pi to be running the latest merged changes and restart the PM2 daemon. Once youâve done that, deploy to netlify and Slack the netlify preview deploy URL.