Skip to content

Instantly share code, notes, and snippets.

View mauricedb's full-sized avatar

Maurice de Beijer mauricedb

View GitHub Profile
@mauricedb
mauricedb / Subject under test
Last active December 7, 2023 14:46
Testing stateful React hooks
import { useState } from 'react';
export function useCounter(initial = 0) {
const [count, setCount] = useState(initial);
return [count, () => setCount(count + 1)];
}
@mauricedb
mauricedb / .storybook\main.js
Created August 19, 2020 18:20
SDN Storybook
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 / gist:5356933
Last active August 16, 2021 16:54
Return JSON data in a camelCase format from an ASP.NET WebAPI controller.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
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",
"sec-fetch-mode": "cors",
@mauricedb
mauricedb / index.njk
Last active May 23, 2020 18:32
Pagination with Eleventy and Nunjucks
<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 %}
@mauricedb
mauricedb / Joke.js
Last active January 18, 2020 10:28
useAbortableFetch
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;
type Person = yup.InferType<typeof personSchema>;
const person: Person;
type Person = {
firstName: string;
nickName: string | null;
email?: string | null;
birthDate: Date;
};
const person = {
firstName: "Matt",
nickName: "The Hammer",
email: "matt@the-hammer.com",
birthDate: new Date(1976, 9, 5)
};
console.log(personSchema.isValidSync(person));