Skip to content

Instantly share code, notes, and snippets.

View markodayan's full-sized avatar
🍑

Mark Odayan markodayan

🍑
View GitHub Profile
@markodayan
markodayan / jest.config.js
Created December 30, 2021 15:05
Jest Configuration (specifically TS prep)
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig.json');
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
modulePaths: ['<rootDir>'],
};
@markodayan
markodayan / deps.sh
Created January 22, 2022 13:22
React Typescript Deps (Alongside CRA TS)
npm i -D jest ts-jest prettier codecov cypress eslint eslint-config-prettier eslint-plugin-react @typescript-eslint/eslint-plugin @typescript-eslint/parser
npm i -D @types/jest
@markodayan
markodayan / ReactFC.tsx
Last active January 22, 2022 16:57
React TypeScript child examples (destructureProps most recommended - React FC not necessary anymore for the most part)
import React from 'react';
interface ChildProps {
message: string;
}
const Child: React.FC<ChildProps> = ({ message }) => {
return <div>{message}</div>;
};
@markodayan
markodayan / serialise.js
Last active August 14, 2022 22:34
JavaScript app - serialise data and send to Golang app
// Step 1
let data = {
name: "Chris Redfield",
age: 30,
job: "STARS soldier",
};
// Step 2 (Serialisation Step)
let serialised = JSON.stringify(data);
@markodayan
markodayan / deserialise.go
Created August 14, 2022 22:39
Deserialise - receive serialised payload and deserialise into a golang struct variable
// Step 1
serialised := receiveSerialisedPayload();
// Step 2 - We can deserialise into a struct with knowledge of the payload structure
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Job string `json:"job"`
}
@markodayan
markodayan / byte-array.js
Last active August 21, 2022 01:47
JSON to Byte Array (Chris Redfield object)
// We have a string -> "{"name":"Chris Redfield","age":30,"job":"STARS soldier"}"
// The string represented as an array of bytes
// with decimal values where each byte ranges from 0 - 255
[
123, 34, 110, 97, 109, 101, 34, 58, 34, 67,
104, 114, 105, 115, 32, 82, 101, 100, 102, 105,
101, 108, 100, 34, 44, 34, 97, 103, 101, 34,
58, 51, 48, 44, 34, 106, 111, 98, 34, 58,
34, 83, 84, 65, 82, 83, 32, 115, 111, 108,
@markodayan
markodayan / byte-array-hex.js
Created August 18, 2022 23:04
Byte array expressed in hexadecimal format
[
'0x7b', '0x22', '0x6e', '0x61', '0x6d',
'0x65', '0x22', '0x3a', '0x22', '0x43',
'0x68', '0x72', '0x69', '0x73', '0x20',
'0x52', '0x65', '0x64', '0x66', '0x69',
'0x65', '0x6c', '0x64', '0x22', '0x2c',
'0x22', '0x61', '0x67', '0x65', '0x22',
'0x3a', '0x33', '0x30', '0x2c', '0x22',
'0x6a', '0x6f', '0x62', '0x22', '0x3a',
'0x22', '0x53', '0x54', '0x41', '0x52',
@markodayan
markodayan / encode.ts
Last active August 22, 2022 03:03
RLP encoding algorithm implemented in TypeScript
type Input = string | number | bigint | Uint8Array | Array<Input> | null | undefined | any;
function encode(input: Input): Uint8Array {
/* (1) Non-value input */
if (input === '' || input === false || input === null) {
const value = parseInt('0x80', 16);
return Uint8Array.from([value]);
}
/* (2) Empty list input */
@markodayan
markodayan / encode-helpers.ts
Created August 21, 2022 22:04
Encoding Helpers
/* If string supplied is prefixed with '0x' remove it and return the new string */
function stripHexPrefix(input: string): string {
if (input.startsWith('0x')) {
input = input.slice(2);
}
return input;
}
/* Convert a hexadecimal string to an array of hexadecimal byte values (in preparation of inserting into a byte array) */
@markodayan
markodayan / 12_964_874.json
Last active August 22, 2022 03:16
Legacy Ethereum Block
{
"difficulty":"0x1b315bd824e5e8",
"extraData":"0x65746865726d696e652d75732d7765737431",
"gasLimit":"0xe4e1b2",
"gasUsed":"0xe4dd4b",
"hash":"0x14687ccc4adfd2b0f0d530fc8f8c64dd29ac301ddea26e99087e11d0eae4f575",
"logsBloom":"0x2361a9b76107883d7089e585a3a1422374b21375b8168423507d70b2bccab1a10c5771c82882574255d25bb3c04747e9971ca844ed667b2407dbfb207a24ac5940985ec6f00a0b2c19baaaff217033b63ba7fc2467e64f816ace1764d9e90dd97f5098d2d383ae4951c21952e837eac70290d769b61b275e0a1f75d030382a06e890ef782655601487fc124d274a7626195724f7275409589d2f00e50a5b2914c3db2b5bb1de73284217e0d2f23fa4999a52fa4611e0a005292abd3e5b5d09ff13d12537398412f03416d82181fbb1939965568e078f2f1e65481b8eed3aea90f8f37e99c12fa02500ac1721c2409770d5b52440ab43c050277a2b93357970a7",
"miner":"0xea674fdde714fd979de3edf0f56aa9716b898ec8",
"mixHash":"0x7ae3558891959354b482938e5a61b1d7e371636e5a718137e16753f595531f6a",
"nonce":"0xb81e11f2cb22375e",