Skip to content

Instantly share code, notes, and snippets.

View marcolink's full-sized avatar
🪐

Marco Link marcolink

🪐
View GitHub Profile
@marcolink
marcolink / npm-cheatsheet.md
Last active July 19, 2018 18:34
npm cheatsheet

NPM Cheatsheet

Commands

  • --dry-run

package.json

publish with version bump

@marcolink
marcolink / animated-background.html
Created September 5, 2018 15:01
animated-background.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Canvas - animated gradient Background</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row mt-5">
git tag | xargs git tag -d
@marcolink
marcolink / DESTRUCT-CUSTOM-REACT-HOOKS.md
Last active January 15, 2019 15:22
destructing custom react hooks

Destruct custom react hooks (with typescript)

Bad

const [myValue] = useCustomHook();
//or
const [myValue, setMyValue] = useCustomHook();
//or
const [myValue, setMyValue, isMyValueValid] = useCustomHook();
import * as React from "react";
function useRenderComponent<T>(Component: React.FC, initialProps?: T) {
const [props, setProps] = React.useState<T>(initialProps);
const updateProps = <K extends keyof T>(
field: K,
value: T[K]
) =>
setProps((prevState: T) => ({
...prevState,
@marcolink
marcolink / date-types.ts
Last active October 1, 2021 14:23
Typescript - Typed date strings using template string literal.
/**
* @desc range 0 - 9
*/
type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
export declare namespace ISO8601 {
/**
* @desc range 00 - 24
*/
type TimeHour = `${'0' | '1' | '2'}${'0' | '1' | '2' | '3' | '4'}`
@marcolink
marcolink / get-override-static.ts
Last active March 26, 2021 23:32
Get override for static field in typescript class
/*
https://www.typescriptlang.org/play?ssl=1&ssc=1&pln=16&pc=15#code/MYGwhgzhAECC0G8BQ1oAcCuAjEBLY0EALmEftAGa4CmIAJtALyIB2YAttQFzQDksvAL4p02PASIB7AMpEATrhYBzABQBKRCNRzqRDHJbQA8lgBW1YEQB0S3QAU5kqUQCeaakYoqiAC1wQ1K2BJFmI5DEtJOSsqWjoRYWEkUEgYACFoagAPImoWOhh4ZFRMHHJiUnJY+iZWDm4+NKEkJODQomgwWpZqAHc4dQBuZJDiaCxuvug0oaQR0MkQaisQSVUwNXmIReXV1Sw1IA
*/
class A {
public static field = 'A'
public toString() {
return Object.getPrototypeOf(this).constructor.field
}
}
@marcolink
marcolink / LocalizedEntry.ts
Created April 1, 2021 07:32
Helper for localized (contentful) Entry type
/*
* https://github.com/contentful/contentful.js/blob/master/index.d.ts#L81
*/
type Entry<Fields> = {
sys: {
id: string
}
fields : Fields
}
@marcolink
marcolink / chunkify.js
Last active January 17, 2023 23:46
Create contentful export chunks
/*
For very big spaces, we can create chunks of the export, and import them separately.
To make it work, we have to keep a specific order.
*/
const fs = require('fs');
const path = require('path');
/* the order of types must be kept */
const types = [
@marcolink
marcolink / fetchContentfulCollection.ts
Created October 7, 2021 09:30
fetch contentful collection
import { CollectionProp } from 'contentful-management/types';
type CollectionFuncResponse<TItem> = Promise<CollectionProp<TItem>>;
type CollectionFunc<TItem> = (skip: number, limit: number) => CollectionFuncResponse<TItem>;
export async function getAllCollectionItems<TItem>(
endpoint: CollectionFunc<TItem>,
skip = 0,
limit = 100
): Promise<Array<TItem>> {