This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const superpowerQueue = new Queue() | |
superpowerQueue.enqueue('invisibility') | |
superpowerQueue.enqueue('teleportation') | |
superpowerQueue.enqueue('super-strength') | |
superpowerQueue.enqueue('flight') | |
superpowerQueue | |
//===> Queue { storage: { '0': 'invisibility', '1': 'teleportation', '2': 'super-strength', '3': 'flight' }, head: 0, tail: 4 } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var LRUCache = function(capacity) { | |
this.map = new Map() //=> initializes a new Hash Map | |
this.capacity = capacity //=> how big the Cache is allowed to be | |
} | |
LRUCache.prototype.get = function(key) { | |
if (!this.map.has(key)) { | |
return -1 | |
} | |
const value = this.map.get(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DoublyLinkedList { | |
constructor () { | |
this.head = null | |
this.tail = null | |
} | |
insertHead(node) { | |
if (!this.head) { | |
this.head = node | |
this.tail = node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { connect } from 'react-redux'; | |
import { fetchAllUsers } from '../../redux/actions/users/fetchAllUsers'; | |
import User from './user'; | |
class ShowUSers extends React.Component { | |
componentDidMount = () => { | |
this.props.boundFetchAllUsers() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
import history from '../../history'; | |
// redux hooks: | |
import { useSelector, useDispatch } from 'react-redux'; | |
// action: | |
import { signupUser } from '../../actions/userAuth/signupUser'; | |
function SignupForm(props) { | |
const [first_name, setFirstNameChange] = useState(''); | |
const [last_name, setLastNameChange] = useState(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { API_URL } from '../../apiConstants'; | |
export const POST_USER = "POST_USER" | |
export const POST_USER_SUCCESS = "POST_USER_SUCCESS" | |
export const POST_USER_ERRORS = "POST_USER_ERRORS" | |
export const POST_USER_FAILURE = "POST_USER_FAILURE" | |
export const signupUser = ({ first_name, last_name, email, password, company_name }) => (dispatch) => { | |
// console.log(user_name) | |
dispatch({ type: POST_USER }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { POST_USER, POST_USER_SUCCESS, POST_USER_ERRORS, POST_USER_FAILURE } from '../actions/userAuth/signupUser'; | |
const initialState = { | |
isLoading: false, | |
error: "", | |
errors: [], | |
user: {}, | |
loggedIn: false | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::V1::UsersController < ApplicationController | |
skip_before_action :require_login | |
def index | |
users = User.all | |
render json: { | |
users: users | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::API | |
before_action :require_login | |
skip_before_action :require_login, only: [:home] | |
def home | |
render json: {message: "Server is up and running!"} | |
end | |
def encode_token(payload) | |
JWT.encode(payload, 'my_secret') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::V1::AuthController < ApplicationController | |
skip_before_action :require_login, only: [:login, :auto_login] | |
def auto_login | |
if session_user | |
render json: session_user | |
else | |
render json: {errors: "No user logged in."} | |
end | |
end |