Skip to content

Instantly share code, notes, and snippets.

View roelvan's full-sized avatar
🏠
Working from home

Roel Vaneyghen roelvan

🏠
Working from home
View GitHub Profile
@roelvan
roelvan / Image.js
Created March 28, 2022 13:09
Panic nova syntax
import Image from '@components/Image';
const Avatars = ({ users = [] }) => (
<div className="flex -space-x-2 overflow-hidden">
{users.map((user) => (
<div className="flex flex-col items-center" key={user.name}>
<div className="relative inline-block h-20 w-20 rounded-full ring-4 ring-white overflow-hidden bg-gray-100">
<Image
width={160}
height={160}
@roelvan
roelvan / belgian-holidays.js
Created December 14, 2021 13:41
🇧🇪 Checks if a date is a Belgian holiday
// 🇧🇪 Checks if a date is a Belgian holiday
/*
The code below is not fully mine.
Everything is based on some snippets I found online (another github gist and something on stackoverflow if I am not mistaken).
I was in a hurry and forgot to keep track of my sources, my apologies.
*/
// I did not bother translating all holiday names to English, was a bit easier to work with
// you could replace this with another date library or use native JS if bundle size is an issue
import { addDays, getYear, isSameDay } from 'date-fns';
@roelvan
roelvan / handler.js
Last active April 9, 2020 23:38
TradeTracker redirect handler for node.js
// Tradetracker Direct Linking Redirect Page.
// https://sc.tradetracker.net/implementation/overview?f%5Btarget%5D=&f%5Bname%5D=General&f%5Bversion%5D=All&f%5BversionInfo%5D=Redirect
const crypto = require('crypto');
// Set domain name on which the redirect-page runs, WITHOUT "www.".
const DOMAIN_NAME = '';
// Set tracking group ID if provided by TradeTracker.
const TRACKING_GROUP_ID = '';
// Don't change this line
const ONE_YEAR_IN_SECS = 31536000;
@roelvan
roelvan / Pagination.vue
Created October 12, 2019 01:37
Bulma Pagination Component - No dependencies (Based on https://github.com/jgrandar/vue-bulma-paginate)
<template>
<nav
v-if="showPagination"
class="pagination"
role="navigation"
aria-label="pagination"
>
<a
:disabled="currentPage < 2"
class="pagination-previous"
@roelvan
roelvan / games.js
Last active December 20, 2019 01:43
NOW v2 Error: MongoClient must be connected before calling MongoClient.prototype.db
const { send } = require('micro');
const { handleErrors } = require('../../../lib/errors');
const cors = require('../../../lib/cors')();
const qs = require('micro-query');
const mongo = require('../../../lib/mongo');
const { ObjectId } = require('mongodb');
const handler = async (req, res) => {
let { limit = 5, exclude = '' } = qs(req);
@roelvan
roelvan / now.json
Last active January 15, 2019 06:59
If you want to port an existing @zeithq node app from v1 to v2, you can use the following now.json. (credits: https://twitter.com/styfle/status/1077111544905850880)
{
"name": "your-app",
"alias": "your-app.now.sh",
"Version": 2,
"builds": [
{ "src": "index.js", "user": "@now/node-server", "config": { "maxLambdaSize": "50mb" } }
],
"routes": [{ "src": "/(.*)", "dest": "/index.js" }]
}
const { MongoClient } = require('mongodb');
const { promisify } = require('es6-promisify');
let _connection;
const connect = () => {
if (!process.env.MONGO_URL) {
throw new Error(`Environment variable MONGO_URL must be set to use API.`);
}
return promisify(MongoClient.connect)(process.env.MONGO_URL, {
## Create Booking
curl -X "POST" "https://[subdomein].bookfast.app/bookings" \
-H 'x-api-key: SECRET' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"phone": "+314844908159",
"numberOfSpots": 1,
"firstName": "Fleur",
"coupon": "TEST",
"email": "[email protected]",
@roelvan
roelvan / bookfast.php
Created December 14, 2018 07:24
CREATE booking
<?php
// get cURL resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, 'https://[jouw-subdomein].bookfast.app/bookings');
// set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
@roelvan
roelvan / list.js
Last active December 6, 2018 17:17
Lambda node micro example
const { send } = require('micro');
const cors = require('micro-cors')();
const { handleErrors } = require('errors');
const mongo = require('mongo');
const COLLECTION_NAME = 'games_v3';
const handler = async (req, res) => {
const db = await mongo();
const games = db.collection(COLLECTION_NAME);