Skip to content

Instantly share code, notes, and snippets.

View Cogentx's full-sized avatar
💭
Simplifying Projects

Cogent X360 Labs Cogentx

💭
Simplifying Projects
View GitHub Profile
@Cogentx
Cogentx / TypeScript-Temporal-Uncertainty.ts
Created March 25, 2022 17:47
TypeScript Temporal Uncertainty
let displayNames = ['Joe Doe', 'Jane Doe'];
const getSuffix = () => {
if (Math.random() * 100 < 50) {
return null;
}
return 'md';
};
displayNames.forEach((name) => {
let suffix = getSuffix();
@Cogentx
Cogentx / firebase-v9-react-next.js
Created March 8, 2022 23:10
Firebase v9 - Initialize in React | Next.js
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import { getStorage } from 'firebase/storage';
const firebaseConfig = {
/* Firebase config goes here */
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
@Cogentx
Cogentx / firebase-v9-firestore-react.tsx
Created March 8, 2022 23:08
Cloud Firestore - addDoc Example using Firebase v9 with Next.js | React | TypeScript
import { useRef } from 'react';
import Image from 'next/image';
import { useSession } from 'next-auth/react';
import { EmojiHappyIcon } from '@heroicons/react/outline';
import { CameraIcon, VideoCameraIcon } from '@heroicons/react/solid';
import { collection, addDoc, serverTimestamp } from 'firebase/firestore';
import { db } from '../firebase';
export default function InputBox() {
const { data: session } = useSession();
@Cogentx
Cogentx / react-typescript-useref-type-definitions.tsx
Created March 8, 2022 20:48
React TypeScript useRef Type Definitions
// It's important to pass NULL as the default value to useRef Hook since React.useRef can only be NULL or an Element Object.
// <div> reference type
const divRef = React.useRef<HTMLDivElement>(null);
// <button> reference type
const buttonRef = React.useRef<HTMLButtonElement>(null);
// <br /> reference type
const brRef = React.useRef<HTMLBRElement>(null);
@Cogentx
Cogentx / react-typescript-useref-hook.tsx
Created March 8, 2022 20:47
React TypeScript useRef Hook
import { useRef } from 'react';
export default function InputBox() {
// before render `inputRef` is `null`
// after render `inputRef` is an Object with a `current` property
const inputRef = useRef<HTMLInputElement>(null);
const sendPost = async (e: any) => {
// prevent page refresh on submit
e.preventDefault();
<!DOCTYPE html>
<html lang="en">
<!-- See Kevin Powell (KP) [https://youtu.be/HJ0-fUJ-2F0] for definitions -->
<!-- <head> is our meta data (not visible on page) -->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Basics</title>
</head>
// see YouTube video from Basarat (https://youtu.be/8KIkLPQPt98)
// Example 1 - Template Literal Types - Basic
let jsStringLiteral: string;
jsStringLiteral = 'Hello';
jsStringLiteral = 'World';
let jsTemplateLiteral: `Example: ${string}`; // Okay
jsTemplateLiteral = `Example: ${jsStringLiteral}`; // Okay
jsTemplateLiteral = `Example: ${3.14}`; // Okay
@Cogentx
Cogentx / react-typescript-basic-component.tsx
Created October 18, 2021 23:33
React TypeScript Basic Component
interface Props {
title : string
color?: string
}
const Header = (props : Props) => {
return (
<header>
<h1
style={{
@Cogentx
Cogentx / typescript-basics.ts
Last active October 18, 2021 23:23
Basic intro to TypeScript (Based on Traversy Media YouTube Crash Course)
// Basic Types
let id : number = 5;
let company : string = 'Me Inc.';
let isPub : boolean = true;
let x : any = 'Hello';
// Arrays
let ids : number[] = [1, 2, 3, 4, 5];
// Tuple
@Cogentx
Cogentx / bejeweled-default.markdown
Created May 17, 2019 02:58
Bejeweled - default