Skip to content

Instantly share code, notes, and snippets.

View markodayan's full-sized avatar
🍑

Mark Odayan markodayan

🍑
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / ex-1.js
Created December 20, 2021 20:43
Binding this context
const Person = {
firstName: "Lawrence",
lastName: "Eagles",
sayName: function () {
setTimeout(function() {
console.log("my fullname is " + this.firstName + " " + this.lastName)
}.bind(this), 100) // binds this here.
}
}
@markodayan
markodayan / async.ts
Last active December 20, 2021 12:03
Asynchronising functional programming pattern example
type Fn = (...args: any[]) => any;
function makeAsync<T extends Fn>(fn: Fn): (...args: Parameters<T>) => Promise<ReturnType<T>> {
return function (this: any, ...args: Parameters<T>): Promise<ReturnType<T>> {
return new Promise<ReturnType<T>>((res, rej) => {
try {
res(fn.call(this, ...args));
} catch (e) {
rej(e);
}
@markodayan
markodayan / crack.js
Last active November 23, 2021 08:17
Cracking private key with last 2 mnemonic words absent (18 bits of entropy at play)
const HDWallet = require('ethereum-hdwallet')
const bip39 = require('bip39');
const fs = require('fs')
const seedStart = 'program deny train foot scrap marble anxiety oblige hybrid clean'
const words = fs.readFileSync('./words.txt').toString('utf-8').split('\r\n')
for(let x = 0; x < words.length; x++){