Skip to content

Instantly share code, notes, and snippets.

View markodayan's full-sized avatar
🍑

Mark Odayan markodayan

🍑
View GitHub Profile
@markodayan
markodayan / assertion-library.js
Created July 18, 2020 12:01
Assertion Libary Basic Example (JS Testing)
const { sum, subtract } = require('../math'); // const sum = (a, b) => a - b; const subtract = (a, b) => a - b;
// sum is intentionally wrong to check if error handling is done according to our assertion function
let result, expected;
result = sum(3, 7);
expected = 10;
expect(result).toBe(expected);
result = subtract(7, 3);
@markodayan
markodayan / example.js
Last active July 14, 2020 07:42
Creating Middleware in Express (Important Steps)
// Will create a middleware called logger
// middleware is a called function requiring inputs of (req,res,next) that runs with every http request (if global app middleware)
// next MUST be called to continue on with the http request
const logger = (req,res,next) => {
req.hello = 'Hello World';
console.log('Middleware ran');
next();
};
@markodayan
markodayan / database.sql
Created July 10, 2020 12:50
Express Server with PostgreSQL CRUD routes
CREATE DATABASE perntodo;
CREATE TABLE todo(
todo_id SERIAL PRIMARY KEY,
description VARCHAR(255)
);
@markodayan
markodayan / app.js
Created June 29, 2020 11:52
Serve Front end App (Client) from Node.js Backend
// set static folder pointing to built client app
app.use(express.static('client/build'));
@markodayan
markodayan / layout.js
Created June 24, 2020 09:05
Next.js Layout Component (Wrapping Layout around the custom App)
import Head from 'next/head';
import Navbar from './Navbar';
const Layout = ({ children }) => {
return (
<div>
<Head>
@markodayan
markodayan / _app.js
Created June 24, 2020 08:59
Next.js Custom App Component (In pages root dir to apply global styles)
import '../styles/global.css';
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />;
}
@markodayan
markodayan / utility.module.css
Created June 21, 2020 11:34
utility class example
.heading2Xl {
font-size: 2.5rem;
line-height: 1.2;
font-weight: 800;
letter-spacing: -0.05rem;
margin: 1rem 0;
}
.headingXl {
font-size: 2rem;
@markodayan
markodayan / _app.js
Created June 21, 2020 11:17
Next gloal styles
import '../styles/global.css';
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />;
}
@markodayan
markodayan / commands.sh
Last active September 1, 2020 13:07
Git Version Control
# list all commits made across different branches on the repo
git log
# list all branches (will also show which branch you are currently on)
git branch
# switch to a branch
git checkout <existing_branch_name>
# create new branch
@markodayan
markodayan / data.js
Created April 22, 2020 20:53
JS imports and exports in webpack env
const users = [
{ name: 'mario', premium: true },
{ name: 'luigi', premium: false },
{ name: 'yoshi', premium: true },
{ name: 'toad', premium: true },
{ name: 'peach', premium: false },
];
export const getPremUsers = (users) => {
return users.filter((user) => {