Skip to content

Instantly share code, notes, and snippets.

View ovieokeh's full-sized avatar
🏠
Working from home

Ovie Okeh ovieokeh

🏠
Working from home
View GitHub Profile
@ovieokeh
ovieokeh / intro.md
Last active November 23, 2020 08:20
Experimental idea for state management using Context API + Hooks

react-state-context is a small library for managing context state in an imperative and predictable way for small to mid-sized react apps.

These days, you don't have to install a library to manage your react state. Thanks to the Context API and the useReducer hook, you can manage your state cleanly without having to rely on prop drilling. This is great but only if you do it right. Without the structure provided by a dedicated state management library, you may find it difficult to structure and manage your state in a predictive way (think having tons of dispatch actions spread around your codebase without clarity on what each dispatch does).

/* eslint-disable react/jsx-props-no-spreading */
import { hot } from 'react-hot-loader/root';
import React, { useState, Fragment } from 'react';
import {
BrowserRouter as Router,
Switch,
Route,
Redirect,
useLocation,
useHistory,
@ovieokeh
ovieokeh / recursiveVersions.js
Last active November 4, 2019 11:34
Encoding and Decoding functions for Run Length encoding in JavaScript
function encode(input) {
if (!input) return ''
const currentLetter = input[0]
const length = input.length
let count = 1
while (count < length && currentLetter === input[count]) {
count += 1
}
@ovieokeh
ovieokeh / ActiveClients.jsx
Created April 22, 2019 14:51
A React.js component that parses data into a Bizcharts Line Graph
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Chart, Geom, Axis, Tooltip } from 'bizcharts';
import styled from 'styled-components';
import { themePurple, paleGrey, white, grey } from 'styles/colors';
import SecondaryDropdown from 'components/Dropdowns/SecondaryDropdown';
import { getActiveClients } from 'actions/clients';
import { remCalc } from 'styles/type';
interface iProps {
@ovieokeh
ovieokeh / migration.js
Created March 4, 2019 15:11
TS_VECTORS Sequelize SQL Migration
module.exports = {
up: async (queryInterface) => {
const { sequelize } = queryInterface;
const searchFields = ['title', 'content'];
try {
await sequelize.query(`ALTER TABLE "${tableName}" ADD COLUMN "${columnName}" TSVECTOR`);
await sequelize.query(`UPDATE "${tableName}" SET "${columnName}" = to_tsvector('english', title || ' ' || content )`);
await sequelize.query(`CREATE TRIGGER updateSearchIndex BEFORE INSERT OR UPDATE ON "${tableName}" FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger("${columnName}", 'pg_catalog.english', ${searchFields.join(', ')})`);
} catch (error) {
@ovieokeh
ovieokeh / binary_search.dart
Created February 25, 2019 11:35
Binary Search Implementation in Dart
void main() {
List array = generateList(2000000);
String result = find(1709400, array);
print(result);
}
List generateList(num amount) {
List numbers = [];
for (int i = 0; i <= amount; i++) {