Skip to content

Instantly share code, notes, and snippets.

Koen van Gilst vnglst

Block or report user

Report or block vnglst

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 asyn await error handling.js
module.exports.catchErrors = function catchErrors(fn) {
return function(...args) {
return fn(...args).catch(err => {
console.error(err)
})
}
}
View example.sh
now alias $(now ./build --public --static) play-it.now.sh
View AsyncPopup-RN.jsx
import React from 'react';
import PropTypes from 'prop-types';
import { ViewPropTypes } from 'react-native';
import Popup from './Popup';
import Loader from './Loader';
import LoadingError from './LoadingError';
const AsyncPopup = ({
style,
View AsyncPopup-with-renderProps.jsx
// AsyncPopup using renderProps
const AsyncPopupV2 ({ hasLoaded = false, renderContent }) => (
<View>{hasLoaded ? renderContent() : null}</View>
);
// example usage:
const App = () => (
<View>
<AsyncPopupV2
hasLoaded
View Async-Implementation-v1.jsx
// conditionally render children based on loading state
const AsyncPopup = ({ hasLoaded = false, children }) => (
<View>{hasLoaded ? children : null}</View>
);
// example usage
const App = () => (
<View>
<AsyncPopup hasLoaded>
<DataComponent data={someData} />
@vnglst
vnglst / shrinkpdf.sh
Created Apr 2, 2018
Reduce size of pdf files from command line (requires gs, ghostscript)
View shrinkpdf.sh
#!/bin/sh
# http://www.alfredklomp.com/programming/shrinkpdf
# Licensed under the 3-clause BSD license:
#
# Copyright (c) 2014, Alfred Klomp
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@vnglst
vnglst / example.js
Last active Jan 30, 2018
JSON Schema function validation
View example.js
const api = {};
const ajv = new Ajv({
coerceTypes: true,
useDefaults: true,
allErrors: true,
});
api.api = (schema, handler) => {
const validator = ajv.compile(schema);
@vnglst
vnglst / delay.js
Last active Jan 15, 2018 — forked from daliborgogic/delay.js
Handy snippet: Node.js Async/Await delay
View delay.js
'use strict'
const timeout = ms => new Promise(res => setTimeout(res, ms))
function convinceMe (convince) {
let unixTime = Math.round(+new Date() / 1000)
console.log(`Delay ${convince} at ${unixTime}`)
}
async function delay () {
@vnglst
vnglst / 03-compound-component.js
Last active Feb 1, 2018
Egghead React Kent C. Dodds
View 03-compound-component.js
function ToggleOn({on, children}) {
return on ? children : null
}
function ToggleOff({on, children}) {
return on ? null : children
}
function ToggleButton({on, toggle, ...props}) {
return (
<Switch on={on} onClick={toggle} {...props} />
)
View async-await.js
// The exact same test using async/await
describe('#getUser() using async/await', () => {
it('should load user data', async () => {
const data = await github.getUser('vnglst')
expect(data).toBeDefined()
expect(data.entity.name).toEqual('Koen van Gilst')
})
})
You can’t perform that action at this time.