Skip to content

Instantly share code, notes, and snippets.

View iddan's full-sized avatar

Iddan Aaronsohn iddan

View GitHub Profile
@iddan
iddan / instructions.bash
Last active August 20, 2018 03:18
Connect Electron to Create React App
create-react-app $NAME
npm install --save electron
npm run eject
replace scripts/start.js with this start.js
replace config/webpack.config.dev.js with this webpack.config.dev.js
@iddan
iddan / es_ideas.md
Created March 12, 2018 13:47
ES Ideas I want to propose / like

Array Update

Acts like objects but uses indeces as keys

const array = [ 1, 2, 3 ]
const newArray = [...array, 4: 5 ]

Iterable & Mapping Literals

@iddan
iddan / version.py
Last active October 30, 2017 20:57
Update python setup.py version safely
import ast
import jedi
from os import path
from pipenv.project import Project
from git import Repo
from git.refs.tag import TagReference
from pkg_resources import get_distribution
class Semver:
@iddan
iddan / app.jsx
Created June 29, 2017 09:12
repx
import React from 'react';
import connect from './connect';
// model
class User {
name = null;
}
// view
const _App = ({ user }) => user.name === null
@iddan
iddan / app.jsx
Last active May 18, 2017 10:27
New Redux
import Form from './form.jsx';
const App = (setState) => ({ entities }) => (
<div>
<h1>Entities Editor</h1>
<h2>Select an entity</h2>
<div>{
entities.map(entity => (
<div>
<h3>{ entity.id }</h3>
@iddan
iddan / with-path.js
Created May 17, 2017 22:26
With Path
const WithPath = (target, path = []) => new Proxy(target, {
get(target, property, receiver) {
const value = target[property];
const thisPath = [...path, property];
return {
...(typeof value !== 'object' ? value : WithPath(value, thisPath)),
[WithPath.Path]: thisPath
};
}
});
@iddan
iddan / component.js
Created April 13, 2017 07:24
react functional
function component(...args) {
const [func, opts = {}] = args.reverse();
if (opts.constructor !== Object) {
throw new Error('Options must be a plain object');
}
class FunctionalComponent extends (opts.impure ? React.Component : React.PureComponent) {
constructor() {
super(...arguments);
this.setState = this.setState.bind(this);
}
@iddan
iddan / form.jsx
Created March 14, 2017 15:51
css-modules-styled-components
import { Label } from './label.scss';
export default function Form({ fields }) {
return fields.map(field => <div>
<Label color="red" highlighted>{field}</Label>
<input type="text" />
</div>)
}
@iddan
iddan / load-image.js
Created February 7, 2017 17:36
One liner to load images with a promise
const loadImage = src => new Promise((resolve, reject) => Object.assign(new Image(), {
src,
onload() {
resolve(this);
},
onerror(err) {
reject(err);
},
}));
@iddan
iddan / index.js
Last active February 7, 2017 02:11
Promisify
const promisify = func =>
(...args) =>
new Promise((resolve, reject) =>
func(...args, (err, result) =>
err && reject(err) || resolve(result)
)
);