Skip to content

Instantly share code, notes, and snippets.

View ogwurujohnson's full-sized avatar
🪐
working on headless technologies

Johnson Ogwuru ogwurujohnson

🪐
working on headless technologies
View GitHub Profile
@ogwurujohnson
ogwurujohnson / README-Template.md
Created August 27, 2018 21:15 — forked from PurpleBooth/README-Template.md
A template to make good README.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

@ogwurujohnson
ogwurujohnson / BFS
Created February 12, 2020 14:00
A BFS algorithm i wrote for solving a proof of mine puzzle in a demo block chain i built
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 / portscanner.js
Last active April 23, 2020 08:47
My attempts at building a browser port scanner
/* 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 / Voter.sol
Created April 23, 2020 08:46
An ethereum voting smart contract
pragma solidity ^0.4.0;
pragma experimental ABIEncoderV2;
contract Voter {
struct OptionPos {
uint pos;
bool exists;
}
@ogwurujohnson
ogwurujohnson / MultiSigWallet.sol
Created April 24, 2020 16:44
A multi signatory smart contract for sending funds on the block chain
pragma solidity ^0.4.0;
pragma experimental ABIEncoderV2;
contract MultiSigWallet {
uint minApprovers;
address beneficiary;
address owner;
mapping(address => bool) approvedBy;
@ogwurujohnson
ogwurujohnson / promisewithloop.js
Created August 27, 2020 10:22
Loop and append to Another array
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 / groupBy.js
Created October 21, 2020 17:42
Reimplement lodash groupby
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 / useStateWithPromise.js
Created January 8, 2021 06:50
Await state changes, can be used as well to make a method call after state change
const useStateWithPromise = (initialState) => {
const [state, setState] = useState(initialState);
const resolverRef = useRef(null);
useEffect(() => {
if (resolverRef.current) {
resolverRef.current(state);
resolverRef.current = null;
}
/**
@ogwurujohnson
ogwurujohnson / functional-components.js
Last active June 2, 2021 18:13
Converting class component to functional component
import { useEffect } from 'react';
function MyComponent({ fetchDrafts, fetchHistory }) {
useEffect(() => {
if (!fetchDrafts || !fetchHistory) {
return null
}
fetchDrafts();
fetchHistory();