Skip to content

Instantly share code, notes, and snippets.

View vnglst's full-sized avatar
💭
Building 🪲

Koen van Gilst vnglst

💭
Building 🪲
View GitHub Profile
@vnglst
vnglst / Caddy.conf
Last active February 1, 2024 05:00
Caddy configuration files
# Upstart service for Caddy
# Save in /etc/init/caddy.conf
description "Caddy Server"
author "Koen van Gilst"
start on filesystem or runlevel [2345]
stop on shutdown
#not working yet, try again on 25/2
@vnglst
vnglst / machine.js
Last active September 10, 2021 18:46
Generated by XState Viz: https://xstate.js.org/viz
const addNumber = assign({
numbers: (ctx, event) => {
let { howMany = 5 } = event;
let toAdd = [];
for (let i = 0; i < howMany; i++) {
toAdd.push(Math.floor(Math.random() * 9));
}
return [...ctx.numbers, ...toAdd];
module.exports.catchErrors = function catchErrors(fn) {
return function(...args) {
return fn(...args).catch(err => {
console.error(err)
})
}
}
@vnglst
vnglst / request.js
Created February 6, 2017 09:43
Mocked version of request.js
const fs = require('fs')
const request = (url) => new Promise((resolve, reject) => {
// Get userID from supplied url string
const lastSlash = url.lastIndexOf('/')
const userID = url.substring(lastSlash + 1)
// Load user json data from a file in de subfolder for mock data
fs.readFile(`./src/api/__mockData__/${userID}.json`, 'utf8', (err, data) => {
if (err) reject(err)
// Parse the data as JSON and put in the key entity (just like the request library does)
@vnglst
vnglst / example.sh
Created June 14, 2018 10:32
Now aliasing
now alias $(now ./build --public --static) play-it.now.sh
// AsyncPopup using renderProps
const AsyncPopupV2 ({ hasLoaded = false, renderContent }) => (
<View>{hasLoaded ? renderContent() : null}</View>
);
// example usage:
const App = () => (
<View>
<AsyncPopupV2
hasLoaded
// 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} />
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,
@vnglst
vnglst / shrinkpdf.sh
Created April 2, 2018 14:56
Reduce size of pdf files from command line (requires gs, ghostscript)
#!/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 / 03-compound-component.js
Last active February 1, 2018 08:49
Egghead React Kent C. Dodds
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} />
)