Skip to content

Instantly share code, notes, and snippets.

View maecapozzi's full-sized avatar

Mae Capozzi maecapozzi

View GitHub Profile
@maecapozzi
maecapozzi / UserProfileContainer.js
Created July 30, 2017 21:20
Example of making a HTTP request in React
import React from 'react'
import axios from 'axios'
import UserProfile from './UserProfile'
class UserProfileContainer extends React.Component {
state = {}
componentDidMount() {
axios.get('http://localhost:3001/users', {
params: {
@maecapozzi
maecapozzi / javascript_concepts-cheat-sheet.md
Last active October 12, 2017 19:14
JavaScript Concepts

Hoisting

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.

JavaScript always initializes, and then declares variables.

function hoist() {
  a = 20;
  var b = 100;
}
@maecapozzi
maecapozzi / dataStructures.js
Last active November 3, 2017 18:24
Stack Implementation in JavaScript
class Stack {
constructor () {
this.state = {
storage: '',
count: 0,
mostRecent: ''
}
};
@maecapozzi
maecapozzi / greetingCallback.js
Last active November 23, 2017 14:46
Displays a greeting using a callback
const greeting = (name) => {
console.log('Hello ' + name)
}
const processUserInput = (callback) => {
let name = prompt('please enter your name')
callback(name)
}
processUserInput(greeting)
const greetUser = () => {
new Promise((resolve, reject) => {
let name = prompt('Please enter your name')
resolve(name)
}).then((name) => {
console.log('Hello ' + name)
})
}
const makeHTTPRequest = (url, methodType, callback) => {
const xhr = new XMLHttpRequest()
xhr.open(methodType, url, true)
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
callback(xhr.responseText)
}
}
xhr.send()
}
const makeHTTPRequest = (username) => {
const url = 'https://api.github.com/users/' + username
fetch(url)
.then(response => response.json())
.then(response => console.log(response))
}
makeHTTPRequest('maecapozzi')
function *getUser(username) {
const uri = 'https://api.github.com/users/' + username
const response = yield fetch(uri)
const parsedResponse = yield response.json()
console.log(parsedResponse)
}
getUser('maecapozzi')
const getUser = async (username) => {
const uri = 'https://api.github.com/users/' + username
const response = await fetch(uri)
const parsedResponse = await response.json()
console.log(parsedResponse)
}
getUser('maecapozzi')
import React, { Component } from 'react'
import './App.css'
import axios from 'axios'
class App extends Component {
constructor () {
super()
this.state = {
username: ''