Skip to content

Instantly share code, notes, and snippets.

View BolajiOlajide's full-sized avatar

Bolaji Olajide BolajiOlajide

View GitHub Profile
/*
Sometimes we only want to run an effect the very first time the component mounts.
In my experience, the majority of these times have been firing off a tracking event.
Usually I’ll maintain a hasSent local variable that I flip from false to true after I’ve sent it the first time.
*/
import { useRef, useEffect } from 'react'
const useInitialMount = () => {
// refs exist across component re-renders, so
// we can use it to store a value for the
@BolajiOlajide
BolajiOlajide / useTraceUpdate.js
Created April 16, 2020 00:54
hook for tracing changed props
function useTraceUpdate(props) {
const prev = useRef(props);
useEffect(() => {
const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
if (prev.current[k] !== v) {
ps[k] = [prev.current[k], v];
}
return ps;
}, {});
@BolajiOlajide
BolajiOlajide / lol.sql
Created February 21, 2020 21:58
postgres replace dots and + sign in gmail email
SELECT REGEXP_REPLACE('b.ol.aj.i+fafd@gmail.com', '(?!@)\+\w*|(?<!@gmail)\.', '', 'g'), 'b.ol.aj.i+fafd@gmail.com' as email;
{
"scripts": {
"start": "babel-node $1"
}
}
// with this you can run the user microservice with `npm run start user.js` or `yarn start user.js`
// and the music service with `npm run start music.js` or `yarn start music.js`
// i think you can even exclude the `.js`, it should be smart enough t pick the file.
@BolajiOlajide
BolajiOlajide / Makefile
Created December 17, 2019 17:24
Generate help command for Makefile
help: ## Display this help section
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf "\033[36m%-38s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@BolajiOlajide
BolajiOlajide / .storybook
Created November 26, 2019 22:24 — forked from romansorin/.storybook
Gatsby, TailwindCSS, Storybook configuration
- addons.js
- config.js
- webpack.config.js
const fizzBuzz = i => ({
truefalse : 'Fizz',
falsetrue : 'Buzz',
truetrue : 'FizzBuzz',
}[(i % 3 == 0) + '' + (i % 5 == 0)] || i)
var downloadAsCSV = function (arr, filename) {
csvRows = [];
for (var i = 0, l = arr.length; i < l; i++) {
csvRows.push(arr[i].join('#'));
}
var csvString = csvRows.join('%0A');
csvString = csvString.replace(/ /g, '__');
var a = document.createElement('a');
@BolajiOlajide
BolajiOlajide / settings.json
Created June 12, 2019 19:46
my vscode settings
{
"workbench.colorTheme": "Min Dark",
"python.formatting.provider": "none",
"editor.lineHeight": 25,
"editor.letterSpacing": 0.5,
"files.trimTrailingWhitespace": true,
"editor.renderWhitespace": "all",
"workbench.iconTheme": "material-icon-theme",
"editor.fontSize": 14,
"workbench.sideBar.location": "left",
@BolajiOlajide
BolajiOlajide / sequelize-cast.js
Last active September 4, 2019 22:30
Using sequelize cast
import Sequelize from 'sequelize';
const {
Op,
col: sequelizeCol,
cast: sequelizeCast
} = Sequelize;
// http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#static-method-cast
const valueCast = sequelizeCast(sequelizeCol('value'), 'int');