Skip to content

Instantly share code, notes, and snippets.

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

Ali Eslamifard alieslamifard

🏠
Working from home
  • Homeday
View GitHub Profile
@alieslamifard
alieslamifard / D3C.js
Created August 1, 2018 07:20
sample component for d3js with react-faux-dom
import React from 'react';
import PropTypes from 'prop-types';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import cs from 'classnames';
import * as d3 from 'd3';
import ReactFauxDOM from 'react-faux-dom';
import s from './D3C.scss';
class D3C extends React.Component {
static propTypes = {
@alieslamifard
alieslamifard / README.md
Last active October 15, 2018 10:51
upgrade babel 7.0.0-beta to 7.0.0 stable ( we've removed Babel's Stage presets )
  1. in package.json change all 7.0.0-beta to 7.0.0
  2. npm install in project directory
  3. npx upgrade in project directory
  4. remove @babel/preset-stage-2 from babelrc.js and webpack.config.js
  5. add lines below to plugins in webpack.config
// Stage 2
['@babel/plugin-proposal-decorators', { legacy: true }],
'@babel/plugin-proposal-function-sent',
'@babel/plugin-proposal-export-namespace-from',
@alieslamifard
alieslamifard / resize-based64-image-react.js
Created October 28, 2018 11:50
resized base64 image in react
getBase64 = (file, callback) => {
const reader = new FileReader();
reader.addEventListener('load', e => {
const img = this.imgElement;
const canvas = this.canvasElement;
img.addEventListener('load', i => {
const image = i.target;
let ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
const MAX_WIDTH = 100;
@alieslamifard
alieslamifard / iran-cities.js
Last active November 3, 2018 13:12
Iran cities Json module. شهرها و استان های ایران
module.exports = [
{
id: 201,
name: 'تبریز',
province_id: 101,
},
{
id: 202,
name: 'آذرشهر',
province_id: 101,
@alieslamifard
alieslamifard / gist:8331ecedcce17709b32aab5d11124484
Last active February 28, 2019 12:57
code-sample-schema-validation-1
const foo = { bar: [ { hey : "you" } ] };
if ( foo && foo.bar && foo.bar.length ) {
return foo.bar.map( items => <Component data={items.hey} /> );
}
const foo = { bar: [ { hey : "you" } ] };
if ( foo && foo.bar && foo.bar.length ) {
return foo.bar.map( items => <Component data={items.hey} /> );
}
if ( foo?.bar?.length ) {
return foo.bar.map(items => <Component data={items.hey} />)
}
export function async someAction() {
const response = await someHelperFunctionThatCallAnotherService();
if (!response) {
return dispatch({
type: 'FAILURE'
})
}
return dispatch({
type: 'SUCCESS',
export function async someAction() {
const response = await someHelperFunctionThatCallAnotherService();
if (!response) {
return dispatch({
type: 'FAILURE'
})
}
// check schema
@alieslamifard
alieslamifard / yeoman-1.js
Created March 5, 2019 14:25
yeoman generator
'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');
module.exports = class extends Generator {...}