Skip to content

Instantly share code, notes, and snippets.

View phpsmarter's full-sized avatar

ReactSmarter phpsmarter

View GitHub Profile
var reduce = fn => (Arr, acc) => Arr.reduce(fn, acc);
var add = reduce((acc,x)=>acc+x);
add([1,2,3],0);// -> 6
@phpsmarter
phpsmarter / compose.js
Created March 29, 2018 01:18 — forked from jperasmus/compose.js
"compose" function that handles both sync and async functions
// Async compose
const compose = (…functions) => input => functions.reduceRight((chain, func) => chain.then(func), Promise.resolve(input));
// Functions fn1, fn2, fn3 can be standard synchronous functions or return a Promise
compose(fn3, fn2, fn1)(input).then(result => console.log(`Do with the ${result} as you please`))
@phpsmarter
phpsmarter / 02_anonymous_user.js
Created March 27, 2018 08:04 — forked from tricoder42/02_anonymous_user.js
2017/06/06 [Medium] Use Selectors in Redux for Great Good
const initialState = {
user: {
name: 'anonymous',
token: null
}
}
const getUser = state => state.user || {}
const isAuthenticated = state => Boolean(getUser(state).token)
const isAnonymous = state => !isAuthenticated(user)
@phpsmarter
phpsmarter / ramda
Created March 26, 2018 00:39 — forked from raine/ramda
Browse Ramda documentation in Terminal
#!/usr/bin/env bash
# Browse Ramda documentation in Terminal
# Requires jq and a tool such as fzf or peco for interactive filtering
LATEST="http://raine.github.io/ramda-json-docs/latest.json"
DOCS_URL="http://ramdajs.com/docs/"
json=$(curl -s $LATEST)
functions=$(echo "$json" | jq -r '.[] | if .sig and (.sig | length > 0) then .name + " :: " + .sig else .name end')
@phpsmarter
phpsmarter / booking-service-api.raml
Created February 17, 2018 11:36 — forked from crizstian/booking-service-api.raml
Example of a raml file
#%RAML 1.0
title: Booking Service
version: v1
baseUri: /
types:
Booking:
properties:
city: string
cinema: string
@phpsmarter
phpsmarter / transducer-rxjs-ramda.js
Created January 25, 2018 03:28 — forked from michiel/transducer-rxjs-ramda.js
transducer in es6 with ramda and rxjs
const Rx = require('rx');
const R = require('ramda');
const seq = Rx.Observable.range(1, 10);
const isEven = (x) => x % 2 === 0;
const add1 = (x) => x + 1;
const transducer = R.compose(
R.map(add1),
@phpsmarter
phpsmarter / compose-async.js
Created January 23, 2018 19:37 — forked from export-mike/compose-async.js
compose utility function for async await, A team effort with @cameronbourke and @gwyneplaine. It was a fun discussion.
/*
* Requires Node 8+
* Works in chrome, simply copy and paste into console.
*/
const R = require('ramda');
const compose =
(...funcs) =>
(...args) =>
funcs.reduceRight(async (a, f) => {
@phpsmarter
phpsmarter / gql-apollo-test.spec.js
Created January 20, 2018 02:27 — forked from shlomitc/gql-apollo-test.spec.js
A working example of graphql and apollo client test
import 'mocha';
import {expect} from 'chai';
import 'isomorphic-fetch';
import ApolloClient from 'apollo-client';
import gql from 'graphql-tag';
import {print} from 'graphql-tag/bundledPrinter';
describe('some test', () => {
it('should pass', () => {
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import { MatchSummary, NoDataSummary } from '@mls-digital/react-components';
import MatchSummaryQuery from './match-summary.graphql';
const mapResultsToProps = ({ data }) => {
if (!data.match)
return {
loading: data.loading,
};
import { get } from 'lodash';
import { withRouter } from 'react-router';
import { graphql } from 'react-apollo';
import { compose, mapProps } from 'recompose';
import jobListQuery from './jobList.graphql';
function SomeBaseComponent() {
{/*... some component...*/}
}