Skip to content

Instantly share code, notes, and snippets.

View crisu83's full-sized avatar
🎩
Coding

Christoffer Niska crisu83

🎩
Coding
View GitHub Profile
@crisu83
crisu83 / pipe.ts
Last active April 3, 2021 16:44
Simple strongly typed pipe function
type OperatorFn<T> = (value: T) => T;
interface PipeFn {
<T>(...fns: OperatorFn<T>[]): (value: T) => T;
}
const pipe: PipeFn = (...fns) => value =>
fns.reduce((val, fn) => fn(val), value);
export default pipe;
@crisu83
crisu83 / utils.tsx
Last active December 4, 2020 15:31
Utility components built on top of Styled System.
// Utility components on top of styled-system.
// Inspired by [Rebass](https://rebassjs.org/) and adopted to our needs.
// See: https://react-typescript-cheatsheet.netlify.app/docs/advanced/patterns_by_usecase
import {Theme} from '@/styles/theme';
import css, {SystemStyleObject} from '@styled-system/css';
import shouldForwardProp from '@styled-system/should-forward-prop';
import {
ComponentPropsWithRef,
ComponentPropsWithoutRef,
@crisu83
crisu83 / ErrorProvider.jsx
Last active December 2, 2019 11:34
Testing with Apollo Client
import { ApolloProvider } from '@apollo/react-hooks';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient from 'apollo-client';
import { ApolloLink, Observable } from 'apollo-link';
import React from 'react';
const ErrorProvider = ({ errors, children }) => {
const errorLink = new ApolloLink(
() =>
new Observable(observer => {
@crisu83
crisu83 / init
Last active April 1, 2019 14:27
Releasing your library written in TypeScript on NPM code snippets
$ yarn
$ yarn add -D typescript rollup rollup-plugin-typescript2
@crisu83
crisu83 / react.code-snippets
Created January 22, 2019 13:54
My VS Code React snippets
{
"reactClassComponent": {
"prefix": "rcc",
"body": "import * as React from 'react'\n\nclass ${TM_FILENAME_BASE} extends React.Component {\n\trender() {\n\t\treturn (\n\t\t\t<div>\n\t\t\t\t$0\n\t\t\t</div>\n\t\t)\n\t}\n}\n\nexport default ${TM_FILENAME_BASE}\n",
"description": "Creates a React component class"
},
"reactPureComponent": {
"prefix": "rpc",
"body": "import * as React from 'react'\n\nclass ${TM_FILENAME_BASE} extends React.PureComponent {\n\trender() {\n\t\treturn (\n\t\t\t<div>\n\t\t\t\t$0\n\t\t</div>\n\t\t)\n\t}\n}\n\nexport default ${TM_FILENAME_BASE}\n",
"description": "Creates a React pure component class"
@crisu83
crisu83 / settings.json
Created January 22, 2019 12:20
My VS Code settings
{
"diffEditor.renderSideBySide": false,
"editor.fontFamily": "Operator Mono Lig",
"editor.fontLigatures": true,
"editor.fontSize": 14,
"editor.formatOnSave": true,
@crisu83
crisu83 / AbstractPageBuilder.php
Last active April 18, 2018 21:09
WIP Relay concept for our GraphQL implementation
<?php
namespace ALehdet\AspaApi\GraphQL\Relay;
use Digia\GraphQL\Relay\PageInfo;
use Digia\GraphQL\Relay\PageInfoBuilderInterface;
abstract class AbstractPageBuilder implements PageInfoBuilderInterface
{
/**
class VehicleResolver extends AbstractResolver
{
public function resolveFoo()
{
return 'foo';
}
public function resolveType($rootValue, $contextValues, $info)
{
if ($rootValue instanceof Airplane) {
yarn run v0.19.1
$ flow; test $? -eq 0 -o $? -eq 2
The flow server's version didn't match the client's, so it exited.
Going to launch a new one.
Launching Flow server for /Users/juuso/projects/poc
Spawned flow server (pid=15149)
Logs will go to /private/tmp/flow/zSUserszSjuusozSprojectszSpoc.log
src/hello/saga.js:13
13: fork(function* () {
@crisu83
crisu83 / createEntityCrudSaga.js
Last active September 20, 2016 08:19
A work-in-progress implementation of an entity CRUD saga for redux-saga.
import isArray from 'lodash/isArray';
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';
import { takeLatest } from 'redux-saga';
import { call, fork, put } from 'redux-saga/effects';
import { arrayOf, Schema } from 'normalizr';
import { callApi } from '../../api/helper';
import { normalizeEntityResponse } from '../../common/helper';
/**