Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
improving daily

Johnson Ogwuru ogwurujohnson

:octocat:
improving daily
View GitHub Profile
@ogwurujohnson
ogwurujohnson / functional-components.js
Last active Jun 2, 2021
Converting class component to functional component
View functional-components.js
import { useEffect } from 'react';
function MyComponent({ fetchDrafts, fetchHistory }) {
useEffect(() => {
if (!fetchDrafts || !fetchHistory) {
return null
}
fetchDrafts();
fetchHistory();
@ogwurujohnson
ogwurujohnson / useStateWithPromise.js
Created Jan 8, 2021
Await state changes, can be used as well to make a method call after state change
View useStateWithPromise.js
const useStateWithPromise = (initialState) => {
const [state, setState] = useState(initialState);
const resolverRef = useRef(null);
useEffect(() => {
if (resolverRef.current) {
resolverRef.current(state);
resolverRef.current = null;
}
/**
@ogwurujohnson
ogwurujohnson / groupBy.js
Created Oct 21, 2020
Reimplement lodash groupby
View groupBy.js
const users = [
{ name: 'Jim', color: 'blue' },
{ name: 'Sam', color: 'blue' },
{ name: 'Eddie', color: 'green' },
];
const usersByColor = users.reduce((acc, value) => {
if (!acc[value.color]) {
acc[value.color] = [];
}
@ogwurujohnson
ogwurujohnson / promisewithloop.js
Created Aug 27, 2020
Loop and append to Another array
View promisewithloop.js
const getAddress = async (addresses) => {
const existingAddresses = [];
const res = addresses.map(async (item) => {
const address = await getAddressInfo({ nrg_address: item });
// console.log(address);
if (address) {
console.log("here");
return existingAddresses.push(address);
}
});
@ogwurujohnson
ogwurujohnson / MultiSigWallet.sol
Created Apr 24, 2020
A multi signatory smart contract for sending funds on the block chain
View MultiSigWallet.sol
pragma solidity ^0.4.0;
pragma experimental ABIEncoderV2;
contract MultiSigWallet {
uint minApprovers;
address beneficiary;
address owner;
mapping(address => bool) approvedBy;
@ogwurujohnson
ogwurujohnson / Voter.sol
Created Apr 23, 2020
An ethereum voting smart contract
View Voter.sol
pragma solidity ^0.4.0;
pragma experimental ABIEncoderV2;
contract Voter {
struct OptionPos {
uint pos;
bool exists;
}
@ogwurujohnson
ogwurujohnson / portscanner.js
Last active Apr 23, 2020
My attempts at building a browser port scanner
View portscanner.js
/* eslint-disable camelcase */
/* eslint-disable func-style */
import io from 'socket.io-client';
// we will take callback from external source and use it for what we want her, which is passing true or false
export const checkSocketIoConnect = (url, timeout) => {
return new Promise(function(resolve, reject) {
let errAlready = false;
timeout = timeout || 50000;
@ogwurujohnson
ogwurujohnson / BFS
Created Feb 12, 2020
A BFS algorithm i wrote for solving a proof of mine puzzle in a demo block chain i built
View BFS
def bfs():
q = Queue()
q.enqueue([current_room["room_id"]])
visited = set()
while q.size() > 0:
path = q.dequeue()
v = path[-1]
if v not in visited:
if v == 182: ### change to whatever room you want to find
return path
@ogwurujohnson
ogwurujohnson / README-Template.md
Created Aug 27, 2018 — forked from PurpleBooth/README-Template.md
A template to make good README.md
View README-Template.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites