Skip to content

Instantly share code, notes, and snippets.

(set-macro-character #\[
(lambda (stream char)
(declare (ignore char))
(let ((result (read-delimited-list #\] stream t)))
`(,@result))))
(set-macro-character #\]
(lambda (stream char)
(declare (ignore stream char))
(error "Unmatched closing bracket: ]")))
(defgeneric _fmap (x f))
(defmacro fmap (f x)
`(_fmap ,x #',f))
(defmethod _fmap ((x number) f)
(funcall f x))
(defmethod _fmap ((x string) f)
(funcall f x))
@mixin lineClamp ($lines) {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: $lines;
}
export type COMPOSE = <T>(fn1: (a: T) => T, ...fns: Array<(a: T) => T>) =>
(a: T) => T
export const compose: COMPOSE = (fn1, ...fns) =>
fns.reduce(
(prevFn, nextFn) =>
(value) => prevFn(nextFn(value)),
fn1
);
{
"console.log": {
"scope": "javascript,typescript",
"prefix": "log",
"body": [
"console.log($1)",
],
"description": "console.log"
},
@christianwish
christianwish / Head.js
Last active May 1, 2021 15:09
Head with meta information (nextjs)
import NextHead from 'next/head';
export const Head = ({
title,
image,
imageAlt,
description,
author,
keywords,
}) => {
@christianwish
christianwish / maybe-either.ts
Last active March 12, 2021 12:17
Maybe and Either type implementation in TypeScript
type ADT0<T> = [T]
type ADT1<T, V> = [T, V]
// ---------------------------------
type Just<T> = ADT1<'Just:', T>
type Nothing = ADT0<'Nothing:'>
type Maybe<J> = Nothing | Just<J>
// functions
const just = <T>(v: T): Maybe<T> => ['Just:', v];
const nothing = <T>():Maybe<T> => ['Nothing:'];
https://github.com/evilsoft/crocks
https://github.com/ramda/ramda
https://github.com/lodash/lodash/tree/npm/fp
const isGreateThan = n => m => (m > n);
const square = x => x * x;
const filter = f => arr => arr.filter(f);
const map = f => arr => arr.map(f);
const reduce = f => arr => arr.reduce(f);
const includes = v => arr => arr.includes(v);
const applyTo = x => f => f(x);
const all = f => arr => arr.filter(f).length === arr.length;
@christianwish
christianwish / Zahlenbereiche.tex
Created February 19, 2020 12:26
Zahlenbereiche - Latex
$$\mathbb{N} = \{ 1,2, \dots\}$$
$$\mathbb{Z} = \{ \dots -2, -1, 0, 1,2, \dots\}$$
$$\mathbb{Q} = \{ x | x = \frac{m}{n} | m,n\in \mathbb{N}, n \neq 0\}$$