Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Duarte Monteiro du5rte

🏠
Working from home
View GitHub Profile
@du5rte
du5rte / HoverDecorator.jsx
Last active May 8, 2017 — forked from laem/HoverDecorator.jsx
React Hover Component Decorator
View HoverDecorator.jsx
import React, { Component } from "react"
export default function hoverDecorator(InitialComponent) {
return class HoverDecorator extends Component {
constructor() {
super()
this.state = {
hover: false
}
View mergeObjectArraysByName.js
const stateFiles = [
{name: 'john'},
{name: 'lewis'},
]
const files = [
{name: 'ana'},
{name: 'john', email: "john@mail.com"},
]
View gist:33d85a08ee64a54715230cbe853c2856
creating custom Graphql Types
https://github.com/stylesuxx/graphql-custom-types/blob/master/src/scalars.js
View formCollectionToPlainObject.js
export default function formCollectionToPlainObject(HTMLFormControlsCollection) {
return Object.entries(HTMLFormControlsCollection).reduce((acc, [key, value]) => {
return {
...acc,
[key]: value.value
};
}, {});
}
@du5rte
du5rte / UserConnection.js
Last active May 31, 2017
GraphQL UserConnection with totalCount
View UserConnection.js
import { GraphQLInt, GraphQLNonNull, GraphQLInputObjectType } from "graphql";
import { connectionDefinitions, connectionArgs } from "graphql-relay";
import UserType from "./UserType";
// References
// http://graphql.org/learn/pagination/
// http://dev.apollodata.com/react/pagination.html
// https://www.reindex.io/blog/relay-graphql-pagination-with-mongodb/
// https://github.com/graphql/graphql-relay-js
@du5rte
du5rte / store.js
Created Jun 23, 2017
Redux Store on different development modes
View store.js
export default (
process.env.NODE_ENV === "production"
? require("./productionStore").default
: require("./developmentStore").default
);
View injectProps.jsx
function injectProps(options) {
return function(InitialComponent) {
return function DndStateInjector() {
return <InitialComponent {...options} />;
};
};
}
View handleNestedChange.jsx
import React, { Component } from "react";
import _ from "lodash";
export default class Example extends Component {
constructor(props) {
super(props);
this.state = {
uid: "",
@du5rte
du5rte / distanceBetweenPoints.js
Created Jul 14, 2017
Distance between two Points(x,y) Pythagorean Theorem
View distanceBetweenPoints.js
function distanceBetweenPoints(p1, p2) {
// http://www.mathwarehouse.com/algebra/distance_formula/index.php
// https://stackoverflow.com/questions/20916953/get-distance-between-two-points-in-canvas
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot
// or
// Math.sqr((p2.x - p1.x) + (p2.y - p1.y))
return Math.hypot(p2.x - p1.x, p2.y - p1.y)
}