Skip to content

Instantly share code, notes, and snippets.

View harrisonmalone's full-sized avatar

Harrison Malone harrisonmalone

View GitHub Profile

Destructuring Challenge

  1. Print blue and 1996 to the screen using object destructuring
const car = {
    colour: 'blue', 
    brand: 'ford',
    gears: 4,
 year: '1996',
def sum_with_for(min, max)
total = 0
# we create the total variable outside of the loop so that we can use it for the sum, we add to it in each iteration
return -1 if min > max
# we can put the return -1 here as we can check the values at this point even before the first loop
for i in (min..max) do
total += i
end
# for each loop we add total to i (i represents the iteration)
# example => total = total + 1 on the first loop (total is set at zero), then total = total + 2 on the second loop (total will now be 1 after that first iteration)
@harrisonmalone
harrisonmalone / _form-validation.md
Last active July 4, 2023 22:23
form validation and events lecture for m0119

Lecture ✍️

JS Events

So far we have mostly been using HTML buttons to trigger JS functions, but this is only one event we can use to trigger logic from our JS files. In previous tasks we set up what is called an event listener to detect when the button was clicked. We passed a callback as a function that gets called when event is triggered. Being able to pass functions as parameters - the same way as we can with variables - is one of the major strengths of the JS language.

Event-based programming can be a little tricky to wrap your head around, especially as a beginner. Up until now you have probably been mainly programming in a sequential or imperative way - each line is executed one after another. When we introduce event listeners and callbacks we are determining the functionality we want to happen but we are not actually in control of when this functionality happens - functions aren't called until the button is actually clicked by the user.

Let's create a Coder Academy webapp that allows users t

@harrisonmalone
harrisonmalone / done-callback-example.js
Last active June 22, 2023 08:21
a range of challenges from freecodecamp for express and mongodb, the first example i need to ask matt about
var findAndUpdate = function(personName, done) {
// need a bit more clarification on what the done function is actually doing
var ageToSet = 20
const person = Person.findOneAndUpdate({name: personName}, {age: ageToSet}, {new: true}, function(err, data){
if (err) {
return done(err)
}
else {
return done(null, data)
// why do we pass null as the first argument in the success method call

Sequelize Challenge

Use the lesson for reference as well as the documentation.

In the lesson, we did not cover many to many associations. You will use appointments as a model to split each association into 1:N

Perhaps look at the documentation on Commentable?

Objective:

Mini MERN Project

This is a chance to implement a full MERN stack app, and get some practice with all the pieces of technology we have used to date.

  • We are going to base the app around recipes (unless you have a strong feeling about what you’d like to do instead - but note that discussions about the structure of your data and various other elements will be more difficult if you go down this route).
  • If you are feeling confident, you are welcome to take this project off in any direction that you like, and start building something that you are interested in, as long as you use Node, Express, Mongo/Mongoose, and React.
  • But if you are keen on some direction, please follow these steps. We can run some review classes on each stage as needed later in the day.
  • If you don't understand what is going on in any of these steps, please ask. It is important to understand why you are taking these steps as you go. Come to the review classes as necessary.
  1. First think about how to arrange your data. This

Lesson Material

Backend Deployment

I know we went through how to deploy with now.sh and this works most of the time. In saying that, I've lost a bit of faith in Now over the past few cohorts seeing some weird bugs.

Now used to be great for Express deployments but it has changed a lot over the past year.

You can see what kinds of deployments Now is great for by running:

const express = require('express')
const router = express.Router()
router.use('/users', require('./users'))
module.exports = router
@harrisonmalone
harrisonmalone / _sinatra_basics.md
Last active September 5, 2021 14:30
code for simple sinatra web app that returns json

Lecture ✍️

What is Sinatra

  • Sinatra is a framework that is considered by the ruby community as baby rails
  • It's not really baby by any means; it's more like a stripped back version of rails
  • You have to create more of the code yourself, rails comes bundled with more features that allows you to start coding quicker
  • But it is kind of nice to know that you wrote every line of code in the app

What is a framework

  • A framework is something that allows a programmer to handle all the aspects of what it takes to build an API or a web app
# board begins its life as an array of empty strings
board = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
# method for displaying the tictactoe board
def display_board(board)
puts " 1 2 3"
puts "A #{board[0]} | #{board[1]} | #{board[2]}"
puts " ----------"
puts "B #{board[3]} | #{board[4]} | #{board[5]}"
puts " ----------"