Skip to content

Instantly share code, notes, and snippets.

View AsaoluElijah's full-sized avatar

Asaolu Elijah AsaoluElijah

View GitHub Profile
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Permit.io RBAC Group Chat</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&display=swap"
rel="stylesheet"
const socket = io({
reconnection: true,
reconnectionAttempts: 5,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
});
let currentUser = null;
let currentRole = null;
let messageHistory = [];
@AsaoluElijah
AsaoluElijah / throttling.js
Created June 20, 2024 16:39
Implementing Throttling with JavaScript
class Throttler {
constructor(maxRequests, period) {
this.maxRequests = maxRequests;
this.period = period;
this.requestTimes = [];
}
addTokens() {
const now = Date.now();
this.requestTimes = this.requestTimes.filter(time => now - time < this.period);
@AsaoluElijah
AsaoluElijah / React-MetaMask-EthersJS-Integration.jsx
Created September 14, 2023 21:31
This Gist provides a React code snippet that demonstrates how to connect to MetaMask using the ethers.js library. It includes a simple form styled with Tailwind CSS, allowing users to transfer ETH from their MetaMask account to another address. Upon successful transaction, a confirmation message is displayed.
import React, { useState, useEffect } from "react";
import { ethers } from "ethers";
function App() {
const [provider, setProvider] = useState(null);
const [address, setAddress] = useState("");
const [amount, setAmount] = useState("");
const [message, setMessage] = useState("");
useEffect(() => {
body {
font-family: PolySans;
}
nav {
padding: 20px;
text-transform: uppercase;
color: #ccc;
}
@AsaoluElijah
AsaoluElijah / backend.js
Created June 28, 2021 00:55
Upload and read uploaded file content in express.js
/*
⚠ First install express and multer by running:
npm i -s express multer
*/
const express = require("express");
const multer = require("multer");
const path = require('path')
@AsaoluElijah
AsaoluElijah / first.md
Last active April 19, 2021 18:58
Nuxt.js store (vuex) cheat sheet 📝

Understanfing vuex (store) in Nuxt.js

NTL,R - A "store" is basically a reactive container that holds your application state. Also, data in a store is univeral, i.e you can access them anywhere in your vue/nuxt.js application

Key Terms

  • State - state is just like data(){return{..}} in normal vue.js, but with different syntax in a store

  • Mutation - mutations also are literally methods:{methodName(){...}} in a normal vue.js file, but with different syntax in a store

@AsaoluElijah
AsaoluElijah / number_with_comma.md
Last active October 1, 2020 11:50
Add comma separator to thousands in JavaScript

Add comma separator to thousands - Javascript

const numberWithCommas = (x) => {
    return Number(x).toLocaleString();
}

Example

@AsaoluElijah
AsaoluElijah / last_elem.md
Last active September 26, 2020 23:36
Get Last Element In An Array - PHP, JavaScript & Python

Get Last Element In An Array - PHP, JavaScript & Python

Javascript

const sampleArray = ["foo", 1, 2,"bar"];
let lastElement = sampleArray[sampleArray.length - 1];
console.log(lastElement) // bar
function clean_hex(input, remove_0x) {
input = input.toUpperCase();
if (remove_0x) {
input = input.replace(/0x/gi, "");
}
var orig_input = input;
input = input.replace(/[^A-Fa-f0-9]/g, "");
if (orig_input != input)