Skip to content

Instantly share code, notes, and snippets.

@baliyan9887
baliyan9887 / arrayUtils.js
Created January 26, 2024 11:04
A collection of generic functions for common array manipulations in JavaScript. These functions provide utility for tasks like pushing, popping, sorting, filtering, mapping, and more.
// 1. Push an Item to the Array
function pushItem(arr, item) {
arr.push(item);
}
// 2. Pop an Item from the Array
function popItem(arr) {
arr.pop();
}

On offsets

After the recent release of ps5-kstuff with support for PS4 fpkg files, there is a lot of questions about porting this to other firmwares (4.50 and 4.51 are important in particular, because users of those firmwares can't update to 4.03, but they are still vulnerable to all of the used exploits). The main problem with these ports it the bespoke XOM, which prevents finding the offsets by simply examining the dumps. So in this document I'm going to go over what offsets are important for ps5-kstuff, and how I found them for 4.03.

These are the main categories of offsets:

  1. Kernel data offsets, those can be found from data dumps that are not XOM-protected
  2. Kernel text offsets pointed to by kernel data
  3. doreti_iret offset (that's one offset, but it deserves its own word)
  4. Offsets found from single-stepping of kernel functions
@modeware
modeware / server.js
Created September 25, 2023 03:45
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" });
@aiphee
aiphee / StringToNode.tsx
Last active April 29, 2024 09:36
Fragment with dangerouslySetInnerHtml replacement -
import React from 'react';
interface IProps {
children: unknown;
}
/**
* Takes node content and makes JSX element out of it (kind of like dangerouslySetInnerHTML)
* Careful, always sanitize input!
* credit @yairEO https://github.com/facebook/react/issues/12014#issuecomment-1621382570
@manzt
manzt / my-ts-monorepo.md
Last active November 7, 2024 03:50
A minimal setup for TypeScript monorepo libraries

My Minimal TypeScript Monorepo Setup for ESM Libraries

After a deep dive looking up best practices for TypeScript monorepos recently, I couldn't find anything that suited my needs:

  1. Publish individual (typed) packages to NPM with minimal config.
  2. Supports fast unit testing that spans the entire project (e.g., via Vitest)
  3. Ability to have an interactive playground to experiment with the API in a real-time (e.g., via Vite)

Most solutions point to TypeScript project references,

@adhikarisushant
adhikarisushant / performance-optimization-with-reactjs.md
Last active June 18, 2023 20:20
Techniques for Optimizing Applications built with ReactJS

Performance Optimization for ReactJS Applications

General

Optimizations

  • "Start with a problem first, then solve it. dont go looking for problems."

  • "Measure first before you optimize for performance. And then measure again."

profiler --> general --> check 'highlight updates when components render' to visually see what components render' (green border around element as long as you have devTools open)

@msichterman
msichterman / expand.ts
Created May 24, 2023 22:57
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>
/*
analyze reserved properties from bundled dts for terser
$ pnpm tsm analyze.ts src/*.{ts, tsx} -i src/index.ts
{
"reservedProperties": [
"result",
"value",
"pubTypeKey",
"ikey",
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];
};
@aparx
aparx / types.ts
Last active March 18, 2024 01:03
(for internal usage) a couple of typesafe typescript utilities
// prettier-config-ignore
/** Typesafe alternative to Typescript's "Extract" type-utility */
export type UnionExtract<TUnion, TKeys extends TUnion> = TUnion extends TKeys
? TUnion
: never;
// prettier-config-ignore
/** Typesafe alternative to Typescript's "Exclude" type-utility */
export type UnionExclude<TUnion, TKeys extends TUnion> = TUnion extends TKeys
? never