Skip to content

Instantly share code, notes, and snippets.

View charleslukes's full-sized avatar
👋

Charles Chiakwa charleslukes

👋
  • 15:10 (UTC +01:00)
View GitHub Profile
@charleslukes
charleslukes / package.json
Last active April 26, 2024 08:13
Webpack Configuration for ESModule
{
"type": "module",
"dependencies": { },
"devDependencies": {
"webpack": "^5.87.0",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.1",
},
@charleslukes
charleslukes / old_events.js
Last active September 27, 2022 12:18
GET PREVIOUS EVENTS ON POLKADOT CHAIN
const oldEvents = async () => {
// get current block
const currentBlock = await api.rpc.chain.getHeader();
const currentBlockData = currentBlock.toJSON();
// By default a Polkadot/Substrate node will only keep state for the last 256 blocks, unless it is explicitly run in archive mode
for (let index = 0; index < 255; index++) {
const blockNum = currentBlockData.number - (index + 1);
const blockHash = await api.rpc.chain.getBlockHash(blockNum);
const apiAt = await api.at(blockHash.toJSON());
const events = await apiAt.query.system.events();

Setting up Webpack for any Typescript project from Scratch

Welcome to step by step hands-on guide to setup webpack in your upcoming typescript project. Please follow the steps and you should be able to create your own webpack project. Please download the source code from github.

You will learn below things:

  1. ✅Create a Typescript node.js project.
  2. ✅Install Dependencies with webpack & typescripts.
  3. ✅Use Webpack CLI to crate webpack.config.js file and modify webpack.config.js based on our need.
@charleslukes
charleslukes / README.txt
Created May 1, 2021 23:25
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.1+commit.df193b15.js&optimize=false&runs=200&gist=
SIMPLE GREETER PROJECT
This is a contract that
1. SET AND GETS Owners name
2. say hello with Owners name.
let num = [0,8,-2,5,0];
let val = 0;
const startAndEndOfVal = (numArr: Array<number>, val: number) => {
let indexes = numArr.sort().reduce((acc: Array<number>, cur: number, index: number) => {
if(cur === val){
acc.push(index)
}
return acc
}, []);
/**
* A simple calculator project implementing the add numbers method
*/
//Add method
function addNumber (...arg) {
let calculator = 0;
if(arg.length === 0){
throw new Error('The input cannot be empty');
}
/**
* A simple calculator project implementing the add numbers method
*/
//Add method
function addNumber (...arg) {
let calculator = 0;
if(arg.length === 0){
throw new Error('The input cannot be empty');
}
describe('addNumbers method ', () => {
it('Should contain atleast one input ', () => {
expect(addNumber(1,2)).toBe(3);
expect(addNumber(1)).toBe(1);
});
it('Should throw an error is user doesnt input value ', () => {
expect(addNumber).toThrow();
})
it('Should return the sum of numbers in the arguments ', () => {
expect(addNumber(1,3)).toBe(4);
function addNumber (...arg) {
let calculator = 0;
if(arg.length === 0){
throw new Error('The input cannot be empty');
}
for (let index = 0; index < arg.length; index++) {
if(typeof arg[index] !== 'number'){
return 'Input must be a number';
}
calculator += arg[index];
describe('addNumbers method ', () => {
it('Should contain atleast one input ', () => {
expect(addNumber(1,2)).toBe(3);
expect(addNumber(1)).toBe(1);
});
it('Should throw an error is user doesnt input value ', () => {
expect(addNumber()).Throw();
})
it('Should return the sum of numbers in the arguments ', () => {