Skip to content

Instantly share code, notes, and snippets.

View harrisonmalone's full-sized avatar

Harrison Malone harrisonmalone

View GitHub Profile
1. Write a function that acts like an Express route. In Express the routes (app.get(..)) take a string as the first argument, any number of middleware functions, and then a callback. You need your function to do the same.
2. Have this function then create a request and response object. You will take all the functions in turn, and pass these objects into them. These functions can just alter the objects in simple ways. After the objects have been through these middleware functions, pass the objects to the callback, and console.log out the res and req objects.
3. Now alter the middleware functions so that they put some conditions on the req and res objects that mean that the next middleware functions do not get invoked.

Weird .this

This is not so much a puzzle but more of an understanding of what's actually happening in different pieces of code.

function jon(){
    console.log("In jon function")
    console.log(this)
}
Boolean.prototype.toString = function() {
return String(this.valueOf())
}
Number.prototype.toString = function() {
return String(this.valueOf())
}
Array.prototype.toString = function() {
const arr = this.valueOf()
var x = 5,
o = {
x: 10,
doIt: function() {
var x = 20;
console.log(this.x);
setTimeout(function(){
console.log(this);
}, 1000);
}

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.

This time around 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 throughout the week. You will need to keep an eye on announcements when these are coming up.

const createIngredients = (ingredients) => {
const query = Ingredient.find({name: ingredients})
.then((doc) => {
const db = doc.map((ingredient) => {
return ingredient.name
})
const newIngredients = ingredients.filter((ingredient) => {
return db.indexOf(ingredient) == -1
})
let i, results = []

Twitter workflow

i think having tweetbot as a mac app is kind of overkill

workflow for tweeting from mac

  1. open textedit, write out tweets in this format line by line

  2. open mobile.twitter.com in split view (n is shortcut for new tweet)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
@harrisonmalone
harrisonmalone / hello.rb
Last active January 30, 2019 02:02
cronjobs work with ruby and js
def hello
# File.open(Random.rand.to_s + '.txt', "w+") { |f| f.write("write your stuff here") }
open('hello.txt', 'a') { |f| f.puts "Hello, world!" }
end
hello
# same process to run the cronjob as in test.js
# use which ruby to find where ruby is installed
const express = require('express');
const router = express.Router();
const User = require('../models/User.model');
require('dotenv').config();
const stripe = require("stripe")(process.env.REACT_APP_STRIPE_SECRET_KEY) // this is not posting
router.post('/api/stripe', (req, res, next) => {
const { token, email, selectedOption } = req.body
stripe.customers.create({