Skip to content

Instantly share code, notes, and snippets.

View hartzis's full-sized avatar

(Brian) Emil Hartz hartzis

View GitHub Profile
@hartzis
hartzis / react-style-guide-old.md
Created November 28, 2015 20:06
React style guide : react < v0.13
@hartzis
hartzis / statelessFunctionalComponents.js
Last active November 7, 2015 21:30
Stateless functional components
export function CartItems({items, addToCart}) {
return (
<div>
<h3>Current Cart:</h3>
{items.map((item)=>CartItem(item, addToCart))}
</div>
)
}
export function CartItem({name}, addToCart) {
@hartzis
hartzis / nodeSideFetch.js
Created October 6, 2015 01:23
node side fetch example with express and body-parser
let router = require('express').Router();
let bodyParser = require('body-parser');
// parse application/json
router.use(bodyParser.json());
router.put('/api/update', update);
function update(req, res) {
console.log('updating-', req.body);
@hartzis
hartzis / clientSideFetch.js
Created October 6, 2015 01:20
client side fetch example
function update(data) {
return fetch('/api/update', {
method: 'put',
body: JSON.stringify(data),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(checkStatus)
atom settings
@hartzis
hartzis / high-order-viewport-component-example.js
Created July 24, 2015 19:06
Higher-order React component example
//from - https://github.com/kriasoft/react-starter-kit/blob/master/docs/react-style-guide.md
//Higher-order React component example:
// withViewport.js
import React, { Component } from 'react';
import { canUseDOM } from 'react/lib/ExecutionEnvironment';
function withViewport(ComposedComponent) {
return class WithViewport extends Component {
@hartzis
hartzis / imageServices.js
Created July 23, 2015 05:12
Handle Express Image File Upload
let multiparty = require('multiparty');
let fs = require('fs');
function saveImage(req, res) {
let form = new multiparty.Form();
form.parse(req, (err, fields, files) => {
let {path: tempPath, originalFilename} = files.imageFile[0];
let copyToPath = "./images/" + originalFilename;
@hartzis
hartzis / imageUploadService.js
Created July 23, 2015 01:16
Upload Image File Ajax Request
uploadImage(imageFile) {
return new Promise((resolve, reject) => {
let imageFormData = new FormData();
imageFormData.append('imageFile', imageFile);
var xhr = new XMLHttpRequest();
xhr.open('post', '/upload', true);
@hartzis
hartzis / ImageUploadComponent.jsx
Last active April 3, 2023 18:09
React Image Upload with Preview
// https://codepen.io/hartzis/pen/VvNGZP
class ImageUpload extends Component {
constructor(props) {
super(props);
this.state = {
file: '',
imagePreviewUrl: ''
};
this._handleImageChange = this._handleImageChange.bind(this);
this._handleSubmit = this._handleSubmit.bind(this);
@hartzis
hartzis / gist:ef675be7833c5aafaf6c
Last active August 29, 2015 14:24
fastclick react fix component?
// From - http://stackoverflow.com/questions/24335821/can-i-fastclick-reactjs-running-in-cordova/24345469#24345469
// or use
// https://github.com/zilverline/react-tap-event-plugin
React.initializeTouchEvents(true)
var TouchClick = React.createClass({