Skip to content

Instantly share code, notes, and snippets.

View gilbarbara's full-sized avatar
💥
Keep Buggering On

Gil Barbara gilbarbara

💥
Keep Buggering On
View GitHub Profile
@gilbarbara
gilbarbara / measurements.js
Last active May 7, 2017 17:48
Measurement data
const measurementsData = require('./measurements.json');
const newData = measurementsData.table.measurements.reduce((acc, val, idx) => {
acc.labels.push(val.name);
val.sizes.forEach((d, i) => {
let row = acc.data.find(r => r[0] === d.name);
if (!row) {
acc.data.push([d.name]);
@gilbarbara
gilbarbara / InputValidate.jsx
Last active September 6, 2017 17:29
React Input component with formsy-react validation
var React = require('react/addons'),
Bootstrap = require('react-bootstrap'),
Formsy = require('formsy-react');
var InputValidate = React.createClass({
mixins: [Formsy.Mixin, React.addons.PureRenderMixin],
getDefaultProps: function () {
return {
autocomplete: 'off',
@gilbarbara
gilbarbara / ExportLayersToSVG.jsx
Created March 31, 2017 21:51
Export Illustrator layers to SVG files
var doc = app.activeDocument;
try {
if (app.documents.length > 0) {
var exportOpts = new ExportOptionsSVG();
if (doc.saved == false) {
doc.save();
}
import React from 'react';
import { autobind } from 'core-decorators';
import { HOC } from 'formsy-react';
import { Input } from 'components/Input';
@autobind
export class InputValidate extends React.Component {
constructor(props) {
super(props);
@gilbarbara
gilbarbara / .eslintrc
Last active April 2, 2018 21:31
.eslintrc configuration file ES2015
{
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralShorthandMethods": true,
@gilbarbara
gilbarbara / comparator.js
Created February 15, 2018 02:49
compare data properties
function comparator(data: Object, nextData: Object): Object {
return {
changedFrom(key: string, actual: 'string', prev: string): boolean {
return data[key] === prev && nextData[key] === actual;
},
changedTo(key: string, actual: 'string'): boolean {
return data[key] !== actual && nextData[key] === actual;
},
changed(key: string): boolean {
return data[key] !== nextData[key];
@gilbarbara
gilbarbara / getTypeFromPropTypes.jsx
Created January 16, 2019 00:44
WIP: get type from a React component propTypes
const React = require('react');
const PropTypes = require('prop-types');
class Component extends React.Component {
render() {
return React.createElement('h1', {}, 'Component!');
}
}
Component.propTypes = {
@gilbarbara
gilbarbara / validate-spotify-uri.ts
Created April 27, 2019 19:57
Validate Spotify URIs
function validateURI(input: string): boolean {
let isValid = false;
if (input && input.indexOf(':') > -1) {
const [key, type, id] = input.split(':');
if (key && type && id && id.length === 22) {
isValid = true;
}
}
@gilbarbara
gilbarbara / mapReactChildrenRecursively.ts
Last active September 23, 2019 19:36
Map React Children Recursively
interface IOptions {
predicate: (child: React.ReactChild) => boolean;
props: { [key: string]: any };
}
function mapReactChildrenRecursively(children: React.ReactNode, options: IOptions): React.ReactNode {
if (!options.predicate || !options.props) {
return children;
}
@gilbarbara
gilbarbara / ReduxRouter.jsx
Last active November 28, 2019 18:01
react-router v4 with redux
import React from 'react';
import { Router } from 'react-router-dom';
import createBrowserHistory from 'history/createBrowserHistory';
const LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
export const history = createBrowserHistory();
class ReduxRouter extends React.Component {
static propTypes = {