Skip to content

Instantly share code, notes, and snippets.

@proclaim
proclaim / index.html
Created March 6, 2015 04:33
React Input Field [React Input Field] // source http://jsbin.com/qucoca
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[React Input Field]">
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="http://fb.me/react-with-addons-0.12.2.js"></script>
<meta charset="utf-8">
'use strict';
//var React = require('react');
import React from 'react';
class App extends React.Component {
constructor() {
super();
this.state = {online: false}
@proclaim
proclaim / 0_reuse_code.js
Created April 27, 2016 02:44
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@proclaim
proclaim / fetch.js
Last active April 27, 2016 02:59
RxJS Fetching github user example
var refreshButton = document.querySelector('.refresh');
var closeButton1 = document.querySelector('.close1');
var closeButton2 = document.querySelector('.close2');
var closeButton3 = document.querySelector('.close3');
var refreshClickStream = Rx.Observable.fromEvent(refreshButton, 'click');
var close1Clicks = Rx.Observable.fromEvent(closeButton1, 'click');
var close2Clicks = Rx.Observable.fromEvent(closeButton2, 'click');
var close3Clicks = Rx.Observable.fromEvent(closeButton3, 'click');
@proclaim
proclaim / flatten.js
Last active May 23, 2016 17:03
Flatten Nested Array ES6
/**
* @summary function that will flatten nested array into regular array
* @param Array - nested array (can be in different level)
*/
const flatten = nestedArray => nestedArray.reduce(
(a, next) => a.concat(Array.isArray(next) ? flatten(next) : next), []
);
// Test
@proclaim
proclaim / with_mutation.js
Last active May 25, 2016 14:30
Remove item from array with mutation
const students = ['yoshie', 'hiroshie', 'lisa', 'johnny'];
students.splice(0,1);
console.log(students);
// ["hiroshie", "lisa", "johnny"]
// mutation, 不行啊~
@proclaim
proclaim / without_mutation.js
Last active May 25, 2016 14:38
Add / remove item from array without mutaiton
const students = ['yoshie', 'hiroshie', 'lisa', 'johnny'];
const removeStudent = (students, index) => {
return [
...students.slice(0, index),
...students.slice(index + 1)
]
}
const addStudent = (students, index, newStudent) => {
const getStudentList = () => {
return new Promise((resolve, reject) => {
...
});
}
const getStudentInfo = (id) => {
return new Promise((resolve, reject) => {
...
})
const testCase1 = () => {
// setup variables, conditions, and other funky junkie
someAsync().then((result) => {
// assign the result and process, it'll be used later for test conditions
});
}
const testCase1 = () => {
return new Promise((resolve, reject) => {
someAsync().then((result) => {
// ... do my thing
resolve();
});
});
};
const testCase2 = () => { /* ... */ };