Skip to content

Instantly share code, notes, and snippets.

View du5rte's full-sized avatar
🏠
Working from home

Duarte Monteiro du5rte

🏠
Working from home
View GitHub Profile
creating custom Graphql Types
https://github.com/stylesuxx/graphql-custom-types/blob/master/src/scalars.js
export default function formCollectionToPlainObject(HTMLFormControlsCollection) {
return Object.entries(HTMLFormControlsCollection).reduce((acc, [key, value]) => {
return {
...acc,
[key]: value.value
};
}, {});
}
@du5rte
du5rte / store.js
Created June 23, 2017 12:51
Redux Store on different development modes
export default (
process.env.NODE_ENV === "production"
? require("./productionStore").default
: require("./developmentStore").default
);
@du5rte
du5rte / injectProps.jsx
Created June 29, 2017 09:44
Prop injector
function injectProps(options) {
return function(InitialComponent) {
return function DndStateInjector() {
return <InitialComponent {...options} />;
};
};
}
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 July 14, 2017 10:27
Distance between two Points(x,y) Pythagorean Theorem
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)
}
@du5rte
du5rte / unionAndInterface.js
Created August 31, 2017 12:59
GraphlQL UnionType and InterfaceType
import {
GraphQLID,
GraphQLInt,
GraphQLString,
GraphQLObjectType,
GraphQLList,
GraphQLNonNull,
OrderTypeEnum,
GraphQLUnionType,
GraphQLInterfaceType,
@du5rte
du5rte / booleanTest.js
Created September 13, 2017 15:21
test multiple booleans
const tests = [true, false, true]
const finalTest = tests.reduce((acc, val) => {
return acc && val
}, true);
console.log(finalTest)
@du5rte
du5rte / ratios.js
Last active July 25, 2018 10:35
Expand Ratios
// https://stackoverflow.com/questions/14224535/scaling-between-two-number-ranges
function withinRange(val, { min, max }) {
return (
val > max
? max
: val < min
? min
: val
);
@du5rte
du5rte / popup.js
Created September 18, 2018 12:42
Pop up
export default function popup(url, {name='', width=500, height=500}={}) {
// References
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open
let options = `
width=${width},
height=${height},
left=${window.screenX + ((window.outerWidth - width) / 2)},
top=${window.screenY + ((window.outerHeight - height) / 2)}
`