Skip to content

Instantly share code, notes, and snippets.

View modster's full-sized avatar
🧠

EM Greeff modster

🧠
View GitHub Profile
@modster
modster / schema.yml
Created November 16, 2021 13:02
schema.yml
paths:
/graphql:
post:
summary: 'My GraphQL API Endpoint'
description: 'My GraphQL API Endpoint'
operationId: 'graphql'
responses:
'200':
description: 'Successfull Query'
content:
@modster
modster / path-segments.md
Last active December 1, 2021 08:17
Vercel Serverless Functions Examples

Example Serveless Function using path segments

The following Next.js example uses the path segment in its functionality when requested:

export default function handler(req, res) {
  const { name } = req.query;
  res.end(`Hello ${name}!`);
}
@modster
modster / server.js
Created December 3, 2021 23:59
Req and res are streams in and out
// https://nodejs.org/api/stream.html#api-for-stream-consumers
const http = require('http');
const server = http.createServer((req, res) => {
// `req` is an http.IncomingMessage, which is a readable stream.
// `res` is an http.ServerResponse, which is a writable stream.
let body = '';
// Get the data as utf8 strings.
@modster
modster / server.js
Last active January 19, 2022 04:54
Simple Express Server
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
@modster
modster / index.js
Created December 5, 2021 06:12
npx Hello World
// npx
console.log("Hello World")
@modster
modster / README.md
Created December 5, 2021 06:13 — forked from Tynael/README.md
How to use npx to run gist based scripts
@modster
modster / prisma.md
Created December 5, 2021 06:24
Seed a Prisma DB with npx

Create a new file named seed.js. This can be placed anywhere within your projects folder structure. The below example places it in the /prisma folder.

In the seed.js file, import Prisma Client, initialize it and create some records.

const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()

async function main() {
  const alice = await prisma.user.upsert({
@modster
modster / react.md
Last active December 14, 2021 23:49
React Notes

📌 React Notes ⚡️

React is the entry point to the React library.

  • If you use ES6 with npm, you can write import React from 'react'
  • If you use ES5 with npm, you can write var React = require('react')
  • If you load React from a <script> tag, these top-level APIs are available on the React global:
<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
@modster
modster / endpoints.md
Created December 15, 2021 02:09
RunKit
@modster
modster / server.js
Created December 15, 2021 03:16
Websockets
//https://nodejs.org/docs/v0.10.40/api/http.html#http_event_upgrade_1
var http = require('http');
// Create an HTTP server
var srv = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay');
});
srv.on('upgrade', function(req, socket, head) {
socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +