Skip to content

Instantly share code, notes, and snippets.

import * as React from "react";
const displayItem = (currentPage: number, maxPerPage: number, index:number): boolean => {
const currentPageStart = ((currentPage - 1) * maxPerPage) + 1;
const currentPageEnd = currentPage * maxPerPage;
if ((index + 1) >= currentPageStart && (index + 1) <= currentPageEnd ) {
return true;
}
@jrson83
jrson83 / input.scss
Last active October 2, 2023 22:20
Generated by SassMeister.com.
.first {
color: green;
}
%example-default {
color: red;
}
.bdg {
@extend %example-default;
@jrson83
jrson83 / index.ts
Created October 14, 2023 20:39 — forked from mike-jewell/index.ts
vite-plugin-ssr_https
import express from 'express'
import compression from 'compression'
import { renderPage } from 'vite-plugin-ssr'
import { Options } from 'sirv'
import fs from 'fs'
import path from 'path'
import https from 'https'
const isProduction = process.env.NODE_ENV === 'production'
const root = `${__dirname}/..`
@jrson83
jrson83 / server.js
Created October 14, 2023 20:41 — forked from modeware/server.js
Run a .ts extension file on a browser (Was wondering how vite was able to run a ts file on a browser, in memory transpilation, browser only cares for the header that tells file type.)
var http = require("http");
var { readFileSync } = require("fs");
var path = require("path");
//create a server object:
http
.createServer(function (req, res) {
if (req.method === "GET" && req.url == "/") {
const file = readFileSync(path.join(__dirname, "/index.html"));
res.writeHead(200, { "Content-Type": "text/html" });
const { PerformanceObserver, performance } = require('perf_hooks');
let arraySize = 1000000;
let iterations = 100;
console.log("Starting performance test with %d array size and %d iterations", arraySize, iterations);
let values = {
FORIN: 0,
FOROF: 0,
@jrson83
jrson83 / index.ts
Created January 28, 2024 23:08 — forked from vmlf01/index.ts
TypeScript training - module 2 sample
// sample shopping cart data
const shopping_cart = {
items: [
{ id: '1', name: 'T-Shirt Game of Thrones', size: 'XL', taxCode: 'IVA23', quantity: 1, unitPrice: 24.99 },
{ id: '2', name: 'T-Shirt Big Bang Theory', size: 'L', taxCode: 'IVA23', quantity: 2, unitPrice: 12.50 },
],
subTotal: 0,
tax: 0,
total: 0,
};
interface Messenger {
sendText: () => void;
sendFile: () => void;
checkStatus?: () => void;
}
type RequiredFields<T> = {
[K in keyof T as T[K] extends Required<T>[K] ? K : never]: T[K];
};
@jrson83
jrson83 / isz-glitch-fix-test.md
Created February 4, 2024 23:25
isz-glitch-fix-test

New Quick Code

[Isz Glitch Cure]
80010008 03000000 - Searches for 8 bytes of 03 00 00 00 05 00 01 00 once using Default Offset
05000100 00000000
92000000 00000DD1 - Adjusts the pointer offset by adding a value of 3537 dec = DD1 hex to the pointer
D8000000 020130FF - Tests and skips the following two code lines if 2 bytes from pointer equal `FF 30`
D8000000 0103C0FF - Tests and skips the following code line if 2 bytes from pointer equal less than `FF C0`
08000001 00000030 - Writes 1 byte with 1 offset from pointer, replacing a value less than `C0` with `30` (partial Isz glitch fix)
@jrson83
jrson83 / expand.ts
Created February 13, 2024 02:43 — forked from msichterman/expand.ts
use conditional type inference to "copy" a type T into a new type variable O and then an identity-like mapped type which iterates through the copied type's properties. The conditional type inference is conceptually a no-op, but it's used to distribute union types and to force the compiler to evaluate the "true" branch of the conditional (if you …
// https://stackoverflow.com/a/69288824
export type Expand<T> = T extends (...args: infer A) => infer R
? (...args: Expand<A>) => Expand<R>
: T extends infer O
? { [K in keyof O]: O[K] }
: never;
export type ExpandRecursively<T> = T extends (...args: infer A) => infer R
? (...args: ExpandRecursively<A>) => ExpandRecursively<R>
@jrson83
jrson83 / file.ts
Last active March 6, 2024 05:29
typescript-discriminated-unions
// https://dev.to/darkmavis1980/what-are-typescript-discriminated-unions-5hbb
export type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never
export type ParseArgsArgumentConfig = Expand<
{
required?: boolean
desc?: string
} & (
| {