Skip to content

Instantly share code, notes, and snippets.

View AsaoluElijah's full-sized avatar

Asaolu Elijah AsaoluElijah

View GitHub Profile
@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)
/*
* Complete the vowelsAndConsonants function.
* Print your output using 'console.log()'.
*/
function vowelsAndConsonants(s) {
let output = [];
s = s.toLowerCase();
let letters = s.split("");
for(let i = 0; i < letters.length; i++){
if(s[i] == "a" || s[i] == "e" || s[i] == "i" || s[i] == "o" || s[i] == "u"){
@AsaoluElijah
AsaoluElijah / express-server-side-rendering.md
Created January 4, 2020 13:28 — forked from joepie91/express-server-side-rendering.md
Rendering pages server-side with Express (and Pug)

Terminology

  • View: Also called a "template", a file that contains markup (like HTML) and optionally additional instructions on how to generate snippets of HTML, such as text interpolation, loops, conditionals, includes, and so on.
  • View engine: Also called a "template library" or "templater", ie. a library that implements view functionality, and potentially also a custom language for specifying it (like Pug does).
  • HTML templater: A template library that's designed specifically for generating HTML. It understands document structure and thus can provide useful advanced tools like mixins, as well as more secure output escaping (since it can determine the right escaping approach from the context in which a value is used), but it also means that the templater is not useful for anything other than HTML.
  • String-based templater: A template library that implements templating logic, but that has no understanding of the content it is generating - it simply concatenates together strings, potenti
@AsaoluElijah
AsaoluElijah / meta-tags.md
Created January 3, 2020 00:49 — forked from lancejpollard/meta-tags.md
Complete List of HTML Meta Tags

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta name="keywords" content="your, tags"/>
<meta name="description" content="150 words"/>
<meta name="subject" content="your website's subject">
<meta name="copyright"content="company name">
<meta name="language" content="ES">