Skip to content

Instantly share code, notes, and snippets.

Jamund Ferguson xjamundx

Block or report user

Report or block xjamundx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gatsby-mismatch.md

Dealing with some serious issues regarding dev/build mismatch in gatsby and finally found the reason fo rit. It revolves around wrapRootElement and replaceComponentRenderer being treated differently during the hydration process. Look what happens when you return this:

gatsby-ssr.js

export const wrapRootElement = () => {
  return <div className="wrapper">text</div>
}
@xjamundx
xjamundx / gatsby-source-properties.js
Last active Sep 26, 2018
gatsby properties source plugin
View gatsby-source-properties.js
// i am expecting this to generate an allPropertiesFile thing in graphqil
// but it doesn't seem to be reflected in there at all
exports.sourceNodes = async ({ actions, createNodeId }) => {
const { createNode } = actions
// sample data will actually come from files.
const data = {
'myfolder/file2': { text: 'hi', buttonThing: 'hey' },
'myfolder/file1': { header: 'hi', footer: 'bye' },
View weird-flow.md

This seems fine

code:

// @flow
const data = document.body.getAttribute('my-attribute') || '{}'
const result = JSON.parse(data)
document.body.removeAttribute('my-attribute')
View param-enforcer.js
// idea 1 - use JOI (or similar) at the router level
let params = {
query: {
limit: Joi.number().integer().min(1).max(100).default(10)
}
}
server.get("/horse", enforceParams(params), controller.myRoute)
// idea 2 - use JOI (or similar) at the controller level
async function myRoute(req, res) {
View custom-errors.js
function handleRequest(req, res) {
// all the important request logic...
// send back the request id
res.send(requestId)
// if sending to an known sender...
if (senderId) {
await optInToExperiment(senderId)
}
View flow-example.js
// no types
function getFields(fields) {
return fields.reduce((prev, curr) => (prev[curr] = curr, prev), {})
}
// no return type
function getFields(fields: Array<string>) {
return fields.reduce((prev, curr) => (prev[curr] = curr, prev), {})
}
@xjamundx
xjamundx / webpack-unused-files.sh
Last active Sep 4, 2019
Quickly identify files unused by webpack
View webpack-unused-files.sh
# ----------------------------------- #
webpack --display-modules | awk '{print $2}' | grep ^\.\/ > files-processed.txt;
cd public/js/; # assumes all your files are here
find . -name "*.js" | grep -v eslint | grep -v __ > ../../files-all.txt; # excludes __tests__ and .eslintrc files
cd ../..;
cat files-all.txt | xargs -I '{}' sh -c "grep -q '{}' files-processed.txt || echo '{}'";
rm files-processed.txt files-all.txt;
# ----------------------------------- #
@xjamundx
xjamundx / promise-anti-patterns.md
Last active Jul 13, 2018
Promise Anti-Patterns
View promise-anti-patterns.md
View flow-experience.md

Trying Flow on my node.js code…Let’s see how this goes

Finding the getting started guide:

  1. google flow
  2. click “getflow.com”
  3. was something else
  4. google flow javascript
  5. found flowtype.org
  6. Click “get started” and landed here https://flowtype.org/docs/getting-started.html#_
View async-router.js
// catch any errors in the promise and either forward them to next(err) or ignore them
const catchErrors = fn => (req, res, next) => fn(req, res, next).catch(next)
const ignoreErrors = fn => (req, res, next) => fn(req, res, next).catch(() => next())
// wrap my routes in those helpers functions to get error handling
app.get('/sendMoney/:amount', catchErrors(sendMoney))
// use our ignoreErrors helper to ignore any errors in the logging middleware
app.get('/doSomethingElse', ignoreErrors(logSomething), doSomethingElse)
You can’t perform that action at this time.