Skip to content

Instantly share code, notes, and snippets.

Avatar

Maurice de Beijer mauricedb

View GitHub Profile
View gist:4bcdaca88789dc74a0beadcf9fe438dc
This file has been truncated, but you can view the full file.
fetch("https://wb-api.ethz.ch/MFT/api/upload/v1/UploadChunk", {
"headers": {
"accept": "application/json",
"accept-language": "en-US,en;q=0.9,nl;q=0.8,de;q=0.7",
"authorization": "....",
"cache-control": "no-cache",
"content-type": "application/json",
"pragma": "no-cache",
"sec-fetch-dest": "empty",
View .storybook\main.js
module.exports = {
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-a11y",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/preset-create-react-app",
],
};
@mauricedb
mauricedb / index.njk
Last active May 23, 2020
Pagination with Eleventy and Nunjucks
View index.njk
<span>Page {{ pagination.pageNumber + 1 }} of {{ pagination.pages.length }}:</span>
{% if page.url !== pagination.href.first %}<a href="{{ pagination.href.first }}"><i class="ion-ios-skipbackward"></i></a>{% endif %}
{% if pagination.href.previous %}<a href="{{ pagination.href.previous }}"><i class="ion-arrow-left-b"></i></a>{% endif %}
{%- for pageEntry in pagination.pages %}
{%- if (loop.index0 - pagination.pageNumber) | abs <= 3 %}
<a href="{{ pagination.hrefs[ loop.index0 ] -}}"
{%- if page.url === pagination.hrefs[ loop.index0 ] %} class="active"{% endif %}>
{{- loop.index -}}
</a>
{%- endif %}
View PersonType.ts
type Person = yup.InferType<typeof personSchema>;
View Person.ts
type Person = {
firstName: string;
nickName: string | null;
email?: string | null;
birthDate: Date;
};
View person.js
const person = {
firstName: "Matt",
nickName: "The Hammer",
email: "matt@the-hammer.com",
birthDate: new Date(1976, 9, 5)
};
console.log(personSchema.isValidSync(person));
View personSchema.js
const personSchema = yup.object({
firstName: yup.string(),
nickName: yup.string().nullable(),
email: yup
.string()
.nullable()
.notRequired()
.email(),
birthDate: yup
.date()
View fetch-jokes.js
import React from 'react';
import ListGroup from 'react-bootstrap/ListGroup';
import { url } from '../../shared/jokes-api';
import Loading from '../../shared/loading';
function reducer(state, action) {
switch (action.type) {
case 'loaded':
return { ...state, loading: false, jokes: action.payload };
@mauricedb
mauricedb / Joke.js
Last active Jan 18, 2020
useAbortableFetch
View Joke.js
import React, { useState } from 'react';
import useAbortableFetch from './useAbortableFetch';
const Joke = () => {
const { json: joke, loading, error, abort } = useAbortableFetch(
'http://api.icndb.com/jokes/random/?limitTo=[nerdy]&escape=javascript'
);
if (loading) return 'Loading...';
if (error) return 'Error: ' + error;