Skip to content

Instantly share code, notes, and snippets.

View THEozmic's full-sized avatar
🏠
Working from home

Michael Ozoemena THEozmic

🏠
Working from home
View GitHub Profile
export default function flat () {
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0]);
return depth ? Array.prototype.reduce.call(this, function (acc, cur) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, depth - 1));
} else {
acc.push(cur);
}
export default (sequelize, DataTypes) => {
const Groups = sequelize.define('Groups', {
name: {
allowNull: false,
type: DataTypes.STRING,
validate: {
notEmpty: true
}
},
desc: {
export default (sequelize, DataTypes) => {
const GroupUsers = sequelize.define('GroupUsers', {
userId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'Users',
key: 'id'
}
},
import '../utils/db'
import Posts from './postsModel'
import { respondWith } from '../utils'
export const handler = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false
if (event.httpMethod !== 'GET') return respondWith({ statusCode: 200 })
import mongoose from 'mongoose'
import '../utils/db'
import Posts from './postsModel'
import { verifyToken, respondWith } from '../utils'
export const handler = async (event, context) => {
import mongoose from 'mongoose'
// Set Posts Schema
const schema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
username: {
type: String,
required: [true, 'Username field is required'],
},
profile_image: {
import jwt from 'jsonwebtoken'
import jwksClient from 'jwks-rsa'
export const respondWith = ({ statusCode, response = {} }) => {
return {
statusCode,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
@THEozmic
THEozmic / db.js
Last active January 31, 2019 17:01
import mongoose from 'mongoose'
const dotenv = require('dotenv')
dotenv.config()
const env = { ...process.env }
const isProduction = env.NODE_ENV === 'production'
// Initialize connection to database
@THEozmic
THEozmic / 404.js
Last active January 29, 2019 22:34
import React from 'react'
import Layout from '../components/layout'
import SEO from '../components/seo'
const NotFoundPage = () => (
<Layout>
<SEO title="404: Not found" />
<h1>NOT FOUND</h1>
<p>You just hit a route that doesn&#39;t exist... the sadness.</p>
@THEozmic
THEozmic / home.js
Last active January 29, 2019 22:40
import React from 'react'
import styled from '@emotion/styled'
import axios from 'axios'
import { navigate } from 'gatsby'
import { getUserNickname, getUserProfileImage, logout, isLoggedIn } from '../../services/auth'
import RecentPosts from '../../components/recentPosts'
import Button from '../../components/button'
import Layout from '../../components/layout'