Skip to content

Instantly share code, notes, and snippets.

View phpsmarter's full-sized avatar

ReactSmarter phpsmarter

View GitHub Profile
@phpsmarter
phpsmarter / ReactGame.js
Created January 16, 2018 08:10 — forked from busypeoples/ReactGame.js
ReactGame Example: React + Flow
// @flow
import React from 'react';
import { render } from 'react-dom';
type Field = 0 | 1;
type Position = [Field, Field, Field, Field];
type Unit = [Position, Position, Position, Position];
@phpsmarter
phpsmarter / ramda
Created January 16, 2018 08:42 — forked from jimmymain/ramda
ramda
http://jsfiddle.net/CrossEye/Gk6uu/light/
(function(R) {
var incomplete = R.filter(R.where({complete: false}));
var sortByDate = R.sortBy(R.prop('dueDate'));
var sortByDateDescend = R.compose(R.reverse, sortByDate);
var importantFields = R.project(['title', 'dueDate']);
var groupByUser = R.partition(R.prop('username'));
var activeByUser = R.compose(groupByUser, incomplete);
var gloss = R.compose(importantFields, R.take(5), sortByDateDescend);
'use strict';
var R = require('ramda');
var CATEGORIES = [
{category_type: 'cuisine', id: 1, name: 'French', type: 'categroy'},
{category_type: 'diets', id: 2, name: 'Vegetarian', type: 'category'}
];
var children = {
@phpsmarter
phpsmarter / code02.js
Last active January 16, 2018 08:47 — forked from BnayaZil/code02.js
Ramda series
import {prop, compose, apply, defaultTo, juxt} from 'ramda'
const player = {
id: 1,
name: 'Bnaya',
file: {
img: 'http://foo.bar/bnaya-zil.png'
}
}
@phpsmarter
phpsmarter / deep-merge.js
Created January 16, 2018 09:04 — forked from mrtnbroder/deep-merge.js
Ramda Receips
import R from 'ramda'
const mergePlan = (x, y) => {
if(Array.isArray(x) && Array.isArray(y)) {
return R.uniq(R.concat(x, y));
}
if(typeof x === 'object' && typeof y === 'object'){
return R.mergeWith(mergePlan, x, y)
}
@phpsmarter
phpsmarter / scratch.js
Created January 16, 2018 09:07 — forked from walkermatt/scratch.js
Ramda stuff
var R = require('ramda');
var states = [
{symbol: 'CT', name: 'Connecticut', pop: 3574097},
{symbol: 'ME', name: 'Maine', pop: 1328361},
{symbol: 'MA', name: 'Massachusetts', pop: 6547629},
{symbol: 'NH', name: 'New Hampshire', pop: 1316470},
{symbol: 'RI', name: 'Rhode Island', pop: 1052567},
{symbol: 'VT', name: 'Vermont', pop: 623741},
];
@phpsmarter
phpsmarter / ramdaprogram.js
Created January 16, 2018 09:08 — forked from 1Marc/ramdaprogram.js
ramda program
var byMonth = R.groupBy(R.prop('Month'));
var byAuthor = R.groupBy(R.prop('Author'));
var royalty_key = 'Royalty (SUM)';
var months_keys = R.uniq(R.map(R.prop('Month'), data)).sort();
var monthly_revenue =
R.map((group) =>
R.reduce((acc, record) => acc + parseMoney(record[royalty_key]), 0, group),
byMonth(data));
@phpsmarter
phpsmarter / sample_code1.js
Created January 16, 2018 09:10 — forked from char0n/sample_code1.js
Composing lenses in Ramda
import { lensPath, view } from 'ramda';
const complexObject = { level1: { level2: { prop1: 1, prop2: 2 } } };
const prop1Lens = lensPath(['level1', 'level2', 'prop1']);
console.assert(view(prop1Lens, complexObject) === 1);
@phpsmarter
phpsmarter / rn-compose-login.js
Created January 16, 2018 09:45 — forked from renso3x/rn-compose-login.js
Recompose RN login form
import React from 'react';
import PropTypes from 'prop-types';
import {
compose,
withHandlers,
withState,
setStatic,
setPropTypes
} from 'recompose';
import { View } from 'react-native';
@phpsmarter
phpsmarter / list.js
Created January 16, 2018 09:53 — forked from pokorson/list.js
List stateless with recompose
import React from "react";
import { pure, withReducer, compose, withHandlers, mapProps } from "recompose";
import R from "ramda";
import { createReducer } from "./utils";
const ListItem = pure(({ text }) => <li>{text}</li>);
const renderItems = R.map(t => <ListItem key={t} text={t} />);
const ListComponent = ({ todos, name, updateName, addTodo }) =>
<div>