By David Akin
Create and open a new file
vim file.txt| 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(() => { |
| /** | |
| * Price alert snippet | |
| * For monitoring market cap on assets exchanges | |
| * Precious Akin | |
| */ | |
| // Available exchange assets | |
| enum ASSET { | |
| 'NGN' = '\u20A6', // ₦ | |
| 'USD' = '$' |
| @-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`; | |
| }; |
| // 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 |
| 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(); |
| 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); |