Skip to content

Instantly share code, notes, and snippets.

View AloofBuddha's full-sized avatar

Benjamin Cohen AloofBuddha

View GitHub Profile
@AloofBuddha
AloofBuddha / useEffect.jsx
Created August 2, 2023 19:11
useEffect for video-store-pt-3
useEffect(() => {
async function omdbAPIRequest() {
const requests = inventory.map((inventoryItem) => {
return axios.get(
`http://www.omdbapi.com/?i=${inventoryItem.id}&apikey=7f539340`
);
});
const responses = await Promise.allSettled(requests);
const responseDatas = responses.map((response) => response.value.data);
@AloofBuddha
AloofBuddha / 1-pass-by-value.js
Last active June 7, 2023 16:17
Pass by value vs reference in JS
// primitives are 'passed by value' in JS
// meaning the value of the variable is copied over into a new local variable in the function
let n = 1;
function addOne(x) {
x += 1;
return x;
}

Sure, here's a programming assignment for teaching the basics of regular expressions in Javascript:

Programming Assignment: Regular Expressions in Javascript

In this assignment, you will be using regular expressions to validate and manipulate strings in Javascript.

Task 1: Validate Email Addresses

Create a function validateEmail(email) that takes an email address as input and returns true if the email address is valid and false otherwise. An email address is considered valid if it meets the following criteria:

@AloofBuddha
AloofBuddha / perms.js
Created December 16, 2022 16:44
Permutations in JavaScript
/**
* The main thing to see here is the 'optimal substructure' i.e.
* perms([1, 2, 3]) could benefit from first knowing the result of
* perms([1, 2]), which in turn could use perms([1]) as a starting point
* and our basest of cases would be perms([]) at which point we have a
* trivial problem (so was perms([1]) but I like to accoutn for empty).
*
* This points us to a helper function we are going to need, spread.
* spread will 'spread' a single value into all possible array positions
* at the previous level. So our logic is something like:
@AloofBuddha
AloofBuddha / markup-as-an-idea.md
Last active October 20, 2022 15:37
Markup as an idea

Markup as an idea

What is markup

markup is just the general idea that you can represent information as 'code' using a data structure.

so for example, JSON counts as a markup language:

{
@AloofBuddha
AloofBuddha / recursion-review.md
Last active April 26, 2018 01:47
Recursion Review for C4Q

Recursion and Dynamic Programming

Recursion

Recursion is fundamentally the idea of defining a function in terms of itself. This sounds trippy and unnecessary, so let's look at a canonical example. The 'hello world' of a recursive functions is

function fibbonacci(n) { ... }

The fibonnaci sequence is the sequence of numbers

@AloofBuddha
AloofBuddha / closure-tutorial.md
Last active September 18, 2018 18:55
Closure tutorial

Global Scope, Inner Scope and Closures

This tutorial aims to cover the topics of

  • Global Scope
  • Inner Scope (or sometimes called Function Scope)
  • and Closures

in the JavaScript language.


@AloofBuddha
AloofBuddha / walkthrough.md
Last active April 17, 2017 16:48
Bones Setup Walkthrough

My own walkthrough of setting up Bones

Replace kaizerroll with your own username wherever you see it in the following examples!

Also, only one person on the team needs to create the Github repo (1-2). Everyone else can be added as a project member and clone it.

  1. Fork bones from https://github.com/FullstackAcademy/bones
  • click the fork button at the top-right
  • You should now have your own remote copy of this repo listed with your own Github repositories
  • Mine is at https://github.com/kaizerroll/bones
@AloofBuddha
AloofBuddha / README.md
Last active February 3, 2017 17:18
Event Delegation Examples

Event Delegation

Here's an example of event delegation and when you would use it.

Here is an interactive jsbin of with-delegation.js https://jsbin.com/pufide/8/edit?html,js,console,output JSBin is in general a great resource for trying out front-end code without having to do a lot of setup!


All files share the same index.html

Front-End JS Concepts

Front-end JS is different than Node for a number of reasons that can be confusing. Hopefully the info here will help you clear up some of the confusion you may have!

Important Note Upfront All of the concepts described here still apply in the modern day, but recent tools and trends have made some less relevant than others. All of this information still applies when sending over a plain HTML file, but a specific dev tool called Webpack solves a number of these problems and has as a result become a pretty essential tool for front-end development. I will try to make a note when it applies!

Including your css/js files

When we send back an HTML file as the response to a GET request, we can include any number of other resources using their URLs. This means using `