Skip to content

Instantly share code, notes, and snippets.

View 0ex-d's full-sized avatar

Precious 0ex-d

View GitHub Profile
@0ex-d
0ex-d / react_hooks_effect.js
Created December 11, 2020 08:26
useEffect vs useLayoutEffect in one simple component.
import * as React from 'react';
export default (()=> {
const ref = React.useRef();
/*
* useEffect hook
* Used when DOM changes are unobservable
*/
React.useEffect(() => {
ref.value = '2019';
/*
* This example shows how using lazy initialization
* in React.useState helps prevent unnecessary computation
* Note: There are rare chances you'll need it.
*/
const Clock = () => {
const [time, setTime] = useState(() => new Date()); // ✅ correct
// const [time, setTime] = useState(() => 1000); // ❌ wrong and over-optimization
useEffect(() => {
@0ex-d
0ex-d / price-alert-util.ts
Last active January 6, 2021 23:41
Price alert snippet for monitoring market cap on assets exchanges.
/**
* Price alert snippet
* For monitoring market cap on assets exchanges
* Precious Akin
*/
// Available exchange assets
enum ASSET {
'NGN' = '\u20A6', // ₦
'USD' = '$'
@0ex-d
0ex-d / style.css
Created June 3, 2021 21:02
Add shake effect to material-ui modal
@-webkit-keyframes shake {
0%,
to {
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
10%,
30%,
50%,
70%,
/**
* Quick hack to generate migration template into a file
* @author David
* @param {*} files
* @returns {string} SQL template
*/
const SqlTempGenerator = files => {
if (!Array.isArray(files)) throw "Must be an array of SQL files";
let sqlStr = "INSERT INTO migrations (filename) VALUES";
return sqlStr.concat(" ", files.map(file => `('${file}')`).join(","), ";");
describe("Referential Equality", () => {
function foo() {
return 'bar';
}
const otherFoo = function() {
return `bar`;
};
@0ex-d
0ex-d / beginner_snippets_javascript.js
Last active December 27, 2021 11:20
Simple snippets for beginners in Javascript
// the below are snippets in JavaScript
// they are independent and have been broken
// into smaller functions
// it is likely you'll use them in your code
//
// Remember: no matter how small or big a project maybe
// it still comprises of one or more pieces coming together
// it is just how you use it (LOGIC) to solve a problem.
//
// Arrays & Objects powers the world
@0ex-d
0ex-d / format_cryptoAmount.ts
Created December 27, 2021 11:13
Properly handle crypto currency and stable coins value in large decimals
import BigNumber = require('bignumber.js');
/** Format a value in crypto or stablecoin equivalent */
function cryptoFormat(numeric: string | number): number {
try {
const num = typeof numeric === 'string' ? Number(numeric) : numeric;
if (!Number.isNaN(num)) {
throw new TypeError('Amount should be a number');
}
return new BigNumber(num).toNumber();
@0ex-d
0ex-d / vim-commands.md
Created January 31, 2022 04:05
Vim easy command mappings

(Vi)m Commands

By David Akin

Create and open a new file

vim file.txt

Vim Modes:

@0ex-d
0ex-d / baguvix.js
Created February 24, 2022 22:01
WIP 🚧 A single daemon in Node.js (using spawn)
const { spawn } = require('child_process');
const fs = require('fs');
const cmdProcesses = {
processDaemon: function(file) {
return new Promise((resolve, reject) => {
const args = [file, 'cron', '-', 'output', '-'];
const childProcess = spawn('baguvix', args);