Skip to content

Instantly share code, notes, and snippets.

View raynirola's full-sized avatar
🎯
Focusing

Ray Nirola raynirola

🎯
Focusing
View GitHub Profile
import { Account } from '@/pages/Background/cashback'
const StoreArea = {
local: chrome.storage.local,
sync: chrome.storage.sync,
session: chrome.storage.session,
}
export class Storage {
public area: chrome.storage.StorageArea = StoreArea.local
class Tokenizer {
private input: string = '';
private position: number = 0;
public appendData(data: string): void {
this.input += data;
}
public getNextToken(): string | null {
this.skipWhitespace();

Authentication and data storage flow incorporating both asymmetric and symmetric encryption methods for securely handling sensitive data in a client-server architecture. This approach uses Web Cryptography API functions and ensures that sensitive data is encrypted before being transmitted to the server, with decryption only possible by the rightful owner of the corresponding private key.

User Registration and Initial Setup

  1. User Visits Onboarding Page:

    • User creates an account on the client application.
  2. Account Creation:

    • User provides necessary information to create an account.
import { JSXElementConstructor, ReactNode } from "react";
type NoInfer<T> = [T][T extends any ? 0 : 1];
type ContainsChildren = { children?: React.ReactNode };
function ProviderStack<
Providers extends [
ContainsChildren,
...ContainsChildren[]
@raynirola
raynirola / retry.ts
Last active February 6, 2024 15:31
Simple retry helper with typescript
type Args<T> = {
fn: () => Promise<T>;
retries: number;
delay: number;
backoffFactor: number;
onFailedAttempt?: (error: unknown, attemptNumber: number) => Promise<void>;
};
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
"use strict";
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatusCode {
/**
* The server has received the request headers and the client should proceed to send the request body
@raynirola
raynirola / vercel.d.ts
Created December 28, 2023 11:51
Vercel system environment variables.
declare namespace NodeJS {
interface ProcessEnv {
readonly VERCEL?: '1'
readonly CI?: '1'
readonly VERCEL_REGION?:
| 'arn1'
| 'bom1'
| 'cdg1'
| 'cle1'
abstract class Comparator {
protected nGrams: Map<string, number> = new Map()
protected abstract process(inputString: string): string
protected abstract compute(inputString: string): Map<string, number>
public abstract compare(first: string, second: string): number
}
function extractDomainFromURL(url: string, onlyDomain?: boolean): string | undefined {
const hostname = new URL(url).hostname
const parts = hostname.split('.').slice(-3)
const tld = parts.at(1)
if(tld && tld === "com") return onlyDomain ? parts.shift() : parts.join('.')
if(tld && tld.length > 2) {
import { createCipheriv, createDecipheriv, randomBytes, createHash } from 'node:crypto';
type Preprocessor = (input: string) => string;
type Transformer = (input: string) => string;
class EncryptionError extends Error {
constructor(message: string) {
super(message);
this.name = 'EncryptionError';
}