Skip to content

Instantly share code, notes, and snippets.

import jwt from 'jsonwebtoken';
const data = { some: 'json' };
const key = 'MuchSecretVerySecureSoSafe';
jwt.sign(data, key);
const L = require('@7urtle/lambda');
const myCurry = L.curry((a, b) => a + b);
const myNary = L.nary(a => b => a + b);
// myCurry and myNary can be called
// both as curried and n-ary.
myCurry(1)(2) === myCurry(1, 2);
// => true
// pure function
// depends only on its input
// and produces only its output
const pureFunction = input => input + 1;
const pureFunction2 = function(input) {
return input + 1;
};
@MeetMartin
MeetMartin / 404.js
Created August 8, 2021 06:22
React Router In Under 60 Seconds
import React from 'react';
const Page404 = () => {
return (
<>
<p>
This is not the page that you are looking for!
</p>
</>
);
@MeetMartin
MeetMartin / Monad.js
Last active April 22, 2024 06:33
JavaScript Monad in under 60 seconds.
// JavaScript functional programming
// Monad under 60 seconds
const Functor = {
of: value => ({
value: value,
inspect: () => console.log(`Functor(${value})`),
map: fn => Functor.of(fn(value))
})
};
// /src/components/Wallpaper.js
import React, { useContext, useEffect, useState } from 'react';
import { randomOf } from '@7urtle/lambda';
import styled from 'styled-components';
import { StoreContext } from '../store/StoreContext';
const BackgroundDiv = styled.div`
background: ${props => 'linear-gradient(135deg, ' + props.colors[0] + ', ' + props.colors[1] + ')'};
// /src/pages/HomePage.js
import React, { useContext, useEffect } from 'react';
import { StoreContext } from '../store/StoreContext';
import { QuoteComponent, Background, Footer } from '../components';
const HomePage = () => {
const { state, actions } = useContext(StoreContext);
// /src/App.js
import React from 'react';
import { StoreProvider } from './store/StoreContext';
import HomePage from './pages/HomePage';
const App = () => {
return (
<StoreProvider>
// /src/store/StoreContext.js
import React, { createContext, useReducer, useEffect } from 'react';
import { reducer, initialState } from './reducers';
import { useActions } from './actions';
import { applyMiddleware } from './middleware';
const StoreContext = createContext(initialState);
// /src/store/middleware.js
import types from './types';
import { getQuote } from './hooks/QuoteHook';
const applyMiddleware = state => dispatch => action => {
switch (action.type) {
case types.REQUEST_RANDOM_QUOTE:
console.debug('[applyMiddleware]', types.REQUEST_RANDOM_QUOTE);
getQuote(dispatch)(action);