Skip to content

Instantly share code, notes, and snippets.

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 }
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)
class DoublyLinkedList {
constructor () {
this.head = null
this.tail = null
}
insertHead(node) {
if (!this.head) {
this.head = node
this.tail = node
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()
}
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('');
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 })
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
};
class Api::V1::UsersController < ApplicationController
skip_before_action :require_login
def index
users = User.all
render json: {
users: users
}
end
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')
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