Skip to content

Instantly share code, notes, and snippets.

View AkyunaAkish's full-sized avatar

Akyuna Akish AkyunaAkish

  • Amazon
  • remote
View GitHub Profile
@AkyunaAkish
AkyunaAkish / Cart.tsx
Created April 21, 2024 03:25
cart ts gunpla
import { useContext, useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { ProductContext } from "../contexts/ProductContext";
import DeleteIcon from "@mui/icons-material/Delete";
import { Product } from "../contexts/ProductContext";
import { Divider } from "@mui/material";
function Cart() {
const { populateCart, populatedCart, removeFromCart, editCartItem } =
useContext(ProductContext);
type Product = {
// ... product stuff
quantity?: number; // add this to the existing product type
}
// create new state (and add it to the types and context value etc)
const [populatedCart, setPopulatedCart] = useState<Product[]>([]);
async function fetchProduct(productId: string): Promise<Product> {
const res = await fetch(`${BASE_URL}/products/${productId}`);
@AkyunaAkish
AkyunaAkish / starter.js
Created December 10, 2021 18:14
Thierry Oke Starter Modal Body
import { useState } from 'react';
import moment from 'moment';
// Once you fix your modal, logic, this component can be used
// as a starting point for the content of the modal
// this will need to be styled and tied into the filter logic for the games outside of the modal
// either in a parent state, or global context/redux so that when you close the modal
// the page will have access to the selected date and update results
// npm i --save moment (if you don't already have it)
// check out flexbox if you are unfamiliar, you can use css flexbox to
@AkyunaAkish
AkyunaAkish / prettyTimeDiff.js
Created June 11, 2018 17:25
getPrettyTimeDiff, pass start date and end date to get string showing diff in days, hours, minutes, seconds
function getPrettyTimeDiff(startDateTime, endDateTime) {
// get total seconds between the times
let delta = Math.abs(endDateTime - startDateTime) / 1000;
// calculate (and subtract) whole days
let days = Math.floor(delta / 86400);
delta -= days * 86400;
// calculate (and subtract) whole hours
let hours = Math.floor(delta / 3600) % 24;
CREATE TABLE DIM_UI_SBM (
LETO_UI_SBM_ID SERIAL,
SUB_PRJ_ID NUMERIC(20) NOT NULL,
LETO_UI_SBM_TYP VARCHAR(25) NOT NULL,
UI_TST_SBM_SUB_TYP VARCHAR(25),
EXC_STU VARCHAR(30),
HPQC_USR_NM VARCHAR(50),
MTA_EFC_DTE TIMESTAMP,
MTA_UPT_DTE TIMESTAMP,
CRT_USR_ID VARCHAR(15),
--set search_path TO apdp;
--SHOW search_path;
CREATE TABLE DB_SCH_DTA (
PRJ_ID NUMERIC(20) NOT NULL,
CONN_DTA_ID NUMERIC(20) NOT NULL,
ENV_NM VARCHAR(15) NOT NULL,
SCH_NM VARCHAR(25) NOT NULL,
USR_NM VARCHAR(30),
function asyncFunction(bool) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if(bool) {
resolve('Promise resolved after .5 of a second');
} else {
reject('Promise rejected after .5 of a second');
}
}, 500);
});
@AkyunaAkish
AkyunaAkish / flatChainedPromiseExample.js
Last active January 26, 2018 21:16
Flat-Chained Promise Example
function asyncFunction(bool) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if(bool) {
resolve('Promise resolved after .5 of a second');
} else {
reject('Promise rejected after .5 of a second');
}
}, 500);
});
@AkyunaAkish
AkyunaAkish / badPromiseNesting.js
Last active January 26, 2018 19:25
Bad Promise Nesting Pattern
function asyncFunction(bool) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (bool) {
resolve('Promise resolved after .5 of a second');
} else {
reject('Promise rejected after .5 of a second');
}
}, 500);
});
@AkyunaAkish
AkyunaAkish / handlingMultipleFunctionCallsThatEachReturnAPromise.js
Created January 26, 2018 18:55
Handling multiple function calls that each return a Promise using Promise.all
function asyncFunction(bool) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if(bool) {
resolve('Promise resolved after 5 seconds');
} else {
reject('Promise rejected after 5 seconds');
}
}, 5000);