Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
AndrewRayCode / withSsrPropsUser.tsx
Created August 9, 2024 16:49
Next.js Get User From Session in SSR with getServerSideProsp
import { GetServerSideProps } from 'next';
import { getSession } from './auth/[...nextauth]';
export type AddParameters<
TFunction extends (...args: any) => any,
TParameters extends [...args: any]
> = (
...args: [...Parameters<TFunction>, ...TParameters]
) => ReturnType<TFunction>;
@AndrewRayCode
AndrewRayCode / playcanvas_screenshot.ts
Created October 1, 2023 17:20
Take a screenshot with Playcanvas
const copyUIntToImageData = (data: Uint8Array, imageData: ImageData) => {
for (let i = 0; i < data.length; i += 4) {
let index = data.length - i; // flip how data is read
imageData.data[index] = data[i]; //red
imageData.data[index + 1] = data[i + 1]; //green
imageData.data[index + 2] = data[i + 2]; //blue
imageData.data[index + 3] = data[i + 3]; //alpha
}
};
@AndrewRayCode
AndrewRayCode / n-queens-recursive.ts
Last active May 18, 2023 17:39
N Queens Problem Javascript / Typescript recursive
type Queen = { row: number; column: number };
type Board = Queen[];
// A solution tree is a queen and all possible board combinations that
// satisfy the n queens problem for that queen placement
type Tree = [Queen, Tree] | [Queen];
// Convert a tree into a flat board
const getBoard = (t: Tree): Board => [
t[0],
@AndrewRayCode
AndrewRayCode / theme.css
Last active June 7, 2023 10:28
Prisma Documentation Dark Mode CSS
/* global */
#___gatsby {
background:#111;
color:#fff;
}
blockquote {
color:#ccc !important;
}
@AndrewRayCode
AndrewRayCode / better-2048-theme-dark-3d.css
Last active May 1, 2023 04:10
2048 Dark Theme, 3D tiles
body {
background: #000;
}
.game-container {
background: #444;
}
.grid-cell {
background: #333;
@AndrewRayCode
AndrewRayCode / style.css
Created April 20, 2023 00:06
2048 Dark Theme Custom CSS
body {
background:#000;
}
.grid-cell {
background: #333;
box-shadow: 0 0 10px inset #000;
}
.tile .tile-inner {
andrewray@~/ray $ npm install -g npm@latest
npm WARN npm npm does not support Node.js v16.2.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12, 13.
npm WARN npm You can find the latest version at https://nodejs.org/
npm WARN registry Unexpected warning for http://registry.npmjs.org/: Miscellaneous Warning UNABLE_TO_GET_ISSUER_CERT_LOCALLY: request to https://registry.npmjs.org/npm failed, reason: unable to get local issuer certificate
npm WARN registry Using stale data from http://registry.npmjs.org/ due to a request error during revalidation.
/Users/andrewray/.nvm/versions/node/v16.2.0/bin/npm -> /Users/andrewray/.nvm/versions/node/v16.2.0/lib/node_modules/npm/bin/npm-cli.js
/Users/andrewray/.nvm/versions/node/v16.2.0/bin/npx -> /Users/andrewray/.nvm/versions/node/v16.2.0/lib/node_modules/npm/bin/npx-cli.js
const foldrLazy = (fn, initialValue, [element, ...rest]) => {
if (element === undefined) {
return initialValue;
}
const exists = () => foldrShortCircuit(fn, initialValue, rest);
return fn(element, exists);
};
const foldr = (fn, initialValue, [element, ...rest]) => {
if (element === undefined) {
return initialValue;
}
return fn(element, foldr(fn, initialValue, rest));
};
const queueIfRunning = originalFn => {
let queuedCall;
let isRunning;
const runner = async (...originalArgs) => {
// If currently running, queue the next run
if (isRunning) {
queuedCall = originalArgs;
} else {
isRunning = true;