Skip to content

Instantly share code, notes, and snippets.

💥
Keep Buggering On

Gil Barbara gilbarbara

Block or report user

Report or block gilbarbara

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View validate-spotify-uri.ts
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 / getTypeFromPropTypes.jsx
Created Jan 16, 2019
WIP: get type from a React component propTypes
View getTypeFromPropTypes.jsx
const React = require('react');
const PropTypes = require('prop-types');
class Component extends React.Component {
render() {
return React.createElement('h1', {}, 'Component!');
}
}
Component.propTypes = {
@gilbarbara
gilbarbara / comparator.js
Created Feb 15, 2018
compare data properties
View comparator.js
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 / randomID.js
Last active Jan 3, 2019
Generate a random alphanumeric string
View randomID.js
function randomID(size = 6) {
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let text = '';
for (let i = 0; i < size; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
@gilbarbara
gilbarbara / HtmlWrapper.js
Created Dec 25, 2017
Convert DOM node to React Element
View HtmlWrapper.js
@@ -0,0 +1,21 @@
import React from 'react';
import PropTypes from 'prop-types';
import ReactHtmlParser from 'react-html-parser';
export default class HtmlWrapper extends React.Component {
static propTypes = {
element: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
View measurements.js
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 / ExportLayersToSVG.jsx
Created Mar 31, 2017
Export Illustrator layers to SVG files
View ExportLayersToSVG.jsx
var doc = app.activeDocument;
try {
if (app.documents.length > 0) {
var exportOpts = new ExportOptionsSVG();
if (doc.saved == false) {
doc.save();
}
@gilbarbara
gilbarbara / ReduxRouter.jsx
Last active Jan 3, 2019
react-router v4 with redux
View ReduxRouter.jsx
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 = {
View InputValidate.jsx
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 / react-d3.jsx
Last active Oct 17, 2018
React + D3 example
View react-d3.jsx
import React from 'react';
import { autobind } from 'core-decorators';
import d3 from 'd3';
import moment from 'moment';
import classNames from 'classnames';
export default class EvolutionChart extends React.Component {
static propTypes = {
investment: React.PropTypes.object.isRequired,
size: React.PropTypes.array,
You can’t perform that action at this time.