Skip to content

Instantly share code, notes, and snippets.

View cadd's full-sized avatar
💭
yeah

Robert cadd

💭
yeah
View GitHub Profile
callBackendAPI = async () => {
const response = await fetch('/express_backend');
const body = await response.json();
if (response.status !== 200) {
throw Error(body.message)
}
return body;
};
@cadd
cadd / header.py
Created July 14, 2021 12:05
Get Auth-Header Example
class UserAPI(MethodView):
"""
User Resource
"""
def get(self):
# get the auth token
auth_header = request.headers.get('Authorization')
if auth_header:
auth_token = auth_header.split(" ")[1]
else:
@cadd
cadd / ex1.js
Created July 13, 2021 13:02
MongoDB Lookup with pipelines
Venue.aggregate([
{ "$match": { "_id": mongoose.Types.ObjectId(id.id) } },
{ "$lookup": {
"from": Review.collection.name,
"let": { "reviews": "$reviews" },
"pipeline": [
{ "$match": { "$expr": { "$in": [ "$_id", "$$reviews" ] } } },
{ "$lookup": {
"from": Comment.collection.name,
"let": { "comments": "$comments" },
from pydantic import BaseModel, Field
from pymongo import MongoClient
from bson import ObjectId
from typing import Optional
client = MongoClient()
db = client.test
class PyObjectId(ObjectId):
@cadd
cadd / clients.js
Created September 2, 2020 14:42
Node MongoDB Connection
import dotenv from 'dotenv';
import { MongoClient } from 'mongodb';
dotenv.config();
const client = new MongoClient(
process.env.MONGODB_URI,
{
useUnifiedTopology: true,
},
@cadd
cadd / App.js
Created June 16, 2020 14:56 — forked from onedebos/App.js
import React, { useState, useEffect } from "react";
import axios from "axios";
const App = () => {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [user, setUser] = useState();
useEffect(() => {
const loggedInUser = localStorage.getItem("user");
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@cadd
cadd / User.js
Created October 30, 2019 12:01
Express w/ Passport JWT/Cookie Auth
const mongoose = require('mongoose');
const { Schema } = mongoose;
const userSchema = new Schema({
username: {
type: String,
index: true,
unique: true,
dropDups: true,
required: true,
@cadd
cadd / Dockerfile
Last active October 30, 2019 10:50
Cloud Run with Nginx
FROM nginx
COPY html /usr/share/nginx/html
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
@cadd
cadd / User.js
Last active October 25, 2019 15:45
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const SALT_WORK_FACTOR = 10;
const schema = mongoose.Schema({
name: String,
email: String,
password: String,
active: {type: Boolean, default: false},
}, {collection: 'user'});