An online markdown blog and knowledge repository.
Technical interviewing in 2 weeks, which will over prep us for most real interviews.
Continuation of Android dev using the Task Master app.
Using Rooms: Is an ORM (Object Relational Manager) + SQL Queries.
AWS Amplify on Tuesday and DynamoDB => AWS is a high-value skill set.
Advice:
TCP/IP and REST are common networking / WRRC techniques, regardless of the framework or language used.
Graphs: Not on final technical whiteboard. Abstract datastructure that things data together with 'paths'.
Room Database: Similar to the 3-liner JPA Code in Spring, but we will need to build our own Queries.
The App talks to the Room DB, and in parallel communities with the DAO (Data Access Object).
The DAO does "get entities", and persists data back to the DB.
Entities is the same as before, Classes with annotations and GET/SETters.
Emulator Requirement: Must set the phone Emulator API to (32?).
Database Inspector:
SQL Lite:
Data Access Object:
Rooms Setup:
Create Entities to model the data:
Create an ENUM if one is necessary:
// package reference here
public enum EnumName {
CATEGORY1("category1"),
CATEGORY2("category2");
private final String someString;
// CTOR
// getters, setters
// @Override toString() or other overrides and custom methods as necessary
}
Implement the Enum in the entity:
EnumName enumName;
Adding Entity Decorators:
@PrimaryKey(autoGenerate=true)
Create a DAO for the Entities:
@Insert public void insertEntity(Entity entity);
@Query("SELECT * FROM Entity ORDER BY field ASC") public List<Product> findAll();
@Query("SELECT * FROM Entity WHERE id = :id") public Entity findById(Long id);
An DAO can use GENERICS!
Create a Database Representation:
public abstract EntityDao entityDao();
Create DB Converters Class:
// this converts timestamp to date
@TypeConverter
public static Date fromTimeStamp(Long value) {
return value == null ? null : new Date(value);
}
// this converts date to timestamp
@TypeConverter
public static Long dateToTimestamp(Date date) {
return date == null ? nul : date.getTime();
}
Create a Database now that the boilerplate DB interface layer code is done!
Set variables for what will be needed/injected:
Within OnCreate() method on the MainActivity:
In production environment, you must set up multi-threading so that DB queries do not lock the UI.
For this class, we are going to set "AllowMainThreadQueries()" to avoid DB setup and use errors using Rooms.
For AWS Multi-threading will be utilized and will not require AllowMainThreadQueries() at all.
Once you reach a point where you can build and run the app without errors:
Set Up a Spinner Element:
Optional: Add the selectable items into you XML Resources, but this is not a scalable solution like Enums can be.
Optional: Use explicit casting "(Spinner)" to ensure ref is captured.
Note: When casting to ensure types are correct, use parenthesis to enforce order-of-operations - likely you are trying to write multi-line statements onto a single line.
Enum Notes: Define it as a child to the class that needs it, and include toString() and fromString() methods to ensure it can be called.
Tracking Element IDs: Use the XML to more rapidly find and copy/past IDs, rather than the rendered UI.
Required: You must get a reference to the Spinner UI element in order to do anything with it.
Belayed until another time.
Remember anything you put into OnCreate()? Those are stuck in the Lifecycle.
Use super.onResume();
and add use clearn() and getAllItem() etc to load the Fields on subsequent times the Activity is loaded.
Tell RecyclerView that data has changed behind it without the Adapter being scoped to the Class level e.g. ProductListRecyclerViewAdpater plrvAdapter;
and then use that Field within Class.methods().
Code Challenge: Time box to no more than 2 hours! (me):
Lab 29: Room => Task Model and Room, Add Task Form, updates to Home and Details pages. Stretch goals (2, optional).
All AWS, today and tomorrow.
Host mobile apps using AWS Amplify.
When you write "Edge Case" on your technical whiteboard, think of it like this: "What are the 'edges' of the data/inputs and outputs that my function has to deal with?"
Always good to include a step-through.
Use colors to identify areas of a step-through such as iterations the step-through step is in.
Remember to add test-case handling in your pseudocode.
Make sure you whiteboard this! Even if coding doesn't happen, have a whiteboard ready for Weds morning discussion.
There are dozens of AWS Cloud Services, many devs know 1, we will have experience with 4 by the time we graduate.
AWS is a collection of APIs and platforms to provide services.
SNS: Automate (or manual) message-sending service.
Elastic Beanstalk: Like Heroku but charges money.
Can create a budged in the Billing Console > Budgets window, and make sure it applies to all AWS Services.
Note: A budget and alerts in AWS Billing Console has been set up!
Read the docs on how to download and install
Commands:
Note: AdministrativeAccess-Amplify is selected by default, DE-SELECT IT and just select AdministrativeAccess.
Note: DOWNLOAD the CSV of the newly created users. This will be necessary in the AWS CLI console when logging in.
Update build.gradle scripts at the Project level and the App level to support AWS Amplify.
The AWS Amplify getting started document has a list of items that must be added to the Project's build.gradle.
Checkout the graphql.org Learn Files
GraphQL notes:
Detects specific ACTIONS, and perform processing when the Action occurs.
[X] Write at least 3 Espresso Tests.
[X] Merge-sort: Whiteboard completely. Coding is your choice.
Is Data CIA? Stored Confidentiality, with Integrity, and Available?
Cloud Pros:
CLoud Cons:
After installing Amplify, additional folders are put in your Project.
GraphQL will also add folder and files including a Schema json, queries, etc.
step to convert from Room to Amplify w/ GraphQL:
From Instructor Alex:
// Steps for adding Amplify to your app
// 1. Remove Room from your app
// 1A. Delete the Gradle Room dependencies in app's (lower-level) build.gradle
// 1B. Delete database class
// 1C. Delete DAO class
// 1D. Remove `@Entity` and `@PrimaryKey` annotations from the Product model class
// 1E: Delete the database variables and instantiation from each Activity that uses them
// 1F: Comment out DAO usages in each Activity that uses them
// 2. Make an IAM user
// 3. Run `amplify configure`
// 4. Add Amplify Gradle dependencies in build.gradle files
// 5. Run `amplify init`
// 6. Run `amplify add api` (or `amplify update api`)
// 7. Run `amplify push`
// 8. Change model in "amplify/backend/api/amplifyDatasource/schema.graphql" to match your app's model
// 9. Run `amplify api update` -> Disable conflict resolution
// 10. Run `amplify push --allow-destructive-graphql-schema-updates`
// 11. Run `amplify codegen models`
// 12A. Add an application class that extends Application and configures Amplify
// 12B. Put the application class name in your AndroidManifest.xml
// 12C. Uninstall the app on your emulator
// 13. Convert every usage of model classes to use Amplify generated models in app/src/main/java/com/amplifyframework/datastore/generated/model
// 13A. Instantiate classes using builder
// 13B. Get data elements via getters (if you aren't already)
// 14. Convert all DAO usages to Amplify.API calls
// 15. Update RecyclerView adapter's collection via runOnUiThread()
// 16. Fix date output in RecyclerView items
Add Task Form, refactor your homepage recyclerview, and get Amplify up and running.
Remove Enum from the project, add a hard-coded list of Strings that represent all the categories.
Spinner code might have to be altered to utilize the list instead.
Remember to utilize onResume property to ensure re-vising views are updated with Amplify + Dynamo latest data.
No deductions for late submissions.
Most complex of all sort algorithms.
JS Array.sort() uses Quicksort.
Quicksort is a common interview question.
AWS and Billing:
Final Technical Whiteboard and Interviews will require camera on.
Put your working screen under the camera so your face is head-on with the camera feed.
Pivot:
Managing Quicksort Temporary Placeholders:
Variable LOW is used to track how many values are less than the PIVOT point.
One => Many and Many => One
Note: Many to Many is a Left-Join SQL in the end.
Use the schema.graphql file to build new table(s).
Create a new 'type', name it, and utilize directives '@model', '@auth' etc.
type Contact @model @auth(rules: [{allow:public}]) {
id: ID!
email: String!
fullName: String
products: [Product] @hasMany(indexName: "byContact", fields: ["id"])
}
Update Product to enable the FK relationship:
type Product @model @auth(rules: [{allow:public}]) {
id: ID!
name: String!
description: String
dataCreate: AWSDateTime
productCategory: String
contactId: ID! @index(name: "byContact", sortKeyFields: ["name"])
contactPerson: Contact @belongsTo(fields: ["contactId"])
}
Note: Relationship descriptions API has been updated a little, is similar, but a lot cleaner.
When done editing Schema:
When creating a new entity (Amplify Class) after setting up the schema:
// sample code from Taskmaster project
Task task = Task.builder()
.title(newTaskTitle)
.body(newTaskDescription)
.state(newTaskStatus)
.build();
Amplify uses 'success' as a callback function.
Inside an Amplify success callback add:
Log.i(string title, string message);
// sample code from Taskmaster project
Log.i("", "Entered incrementTaskCounter lambda.");
TextView successText = AddTask.this.findViewById(R.id.submittedText);
// aws amplify graphql insert method
Amplify.API.mutate(
ModelMutation.create(teamAlpha),
response -> Log.i("HomeActivity", "Added Team with id: " + response.getData().getId()),
error -> Log.e("HomeActivity", "Failed to create new Team", error)
);
finish(); // necessary to exit the lambda
Note: Review ApiModelname.java to see what the params are needed for Queries and Scaler methods!!
Grabbing a stream of a collection and filter it for a selected item (comparisonObj) and return it as an instance, else throw a specific exception:
myModel.stream().filter(c -> c.getter().equals(comparisonObj)).findAny().orElseThrow(RuntimeException::new);
Similar to JS Promises, which are asynchronous methods.
Asynchronous is not procedural programming.
Asynchronous will take whatever time the longest call takes.
Synchronous will take the SUM OF ALL CALLS in order.
CompletableFuture is an asynchronous package.
CompletableFuture<List<MyModel>> thingFuture = null;
Closing methods are necesary: To resolve the CompletableFuture (e.g. tell it to complete) you must include '.complete(arg)'.
You must complete a CompletableFuture otherwise your app will hang, so Exceptions must be handled.
CompletableFuture Exceptions receive 2 params, the output (if processing completed) and the exception that was thrown.
To capture the exception write the 3rd parameter like:
failure -> {
mymodelFuture.complete(null);
Log.e(String logTitle, String customMessage);
}
Another CompletableFuture exception type: InterruptedException.
Note: You might run into a 'null reference exception' when using CompletableFuture calls. How to deal with this? TBD
Advice:
MUST BE PAIRED.
Treat as if this is the final technical interview.
Cognito
DynamoDB
S3
GitHub:
[X] replit.com
[ ] CodePen
[X] Google on Sandboxing Code
[ ] code sandbox
[X] HackerRank
[ ] CoderPad
[X] Code Fellows advice to set up GoogleDocs for Technical Interview
[X] Leetcode
[X] CodeWars
These notes supplement reading notes on graphs in this repo.
Lots of examples of Graphs, generally, in the world.
Graph are interconnected data structures.
Nodes in Graphs are called Vertices.
Note: Try to stick with the accepted terminology so everyone is on the same page especially Vertices vs Nodes.
Root: The starting vertex when analysing and traversing a graph.
Potential Connections: Edges are connections, and Graphs have neighbors via edges. But not all Vertices are connected directly to all others.
Neighbor: Currently-adjacent Vertex.
Degree: Number of edges connected to a Vertex.
Traversals:
Cyclic vs Acyclic:
Edges can have Weight:
Graph Implementation!
Remember left and right? These are edges!
Reference all edges like done in the kAry Tree!
Find vertices via Breadth First Traversal and return the collection.
Consider using a hashset or set to track visited vertices.
Wikipedia article Amazon Web Services
Pseudocode Reference from CSC Calpoly Institute
[ ] TaskMaster: How to alter the background colors on Activities.
[ ] Android Studio: Create a macro to do common things like: Font resize/zoom.
Return to Root README.md