Skip to content

Instantly share code, notes, and snippets.

View chengjianhua's full-sized avatar
💦

Jianhua Cheng chengjianhua

💦
View GitHub Profile
@chengjianhua
chengjianhua / test.js
Created November 4, 2016 16:54
curray add
function add() {
const param = arguments[0];
let sum = arguments[1] || 0;
if (!param) {
return sum;
} else {
sum += param;
return function (...args) {
return add.call(null, args[0], sum);
};
@chengjianhua
chengjianhua / untitled
Created October 12, 2016 09:59
ssh config
#### 以下为多个github 账户设置参考 ####
# first github user([email protected]),注意User项直接填git,不用填在github的用户名
Host genedock.github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_genedock
# gitlab
Host gitlab.com
HostName gitlab.com
@chengjianhua
chengjianhua / UploadFileModal.jsx
Created September 19, 2016 10:09
Read file when select file
const fileReader = new FileReader();
fileReader.readAsText(file);
fileReader.onloadend = (fileEvent) => {
const result = fileEvent.target.result;
console.log(result);
};
@chengjianhua
chengjianhua / DataTableBody.jsx
Created September 18, 2016 08:22
React check clicked target is whether contained in a another node.
handleOutSideClick(event) {
const {onRowUnSelected} = this.props;
const isDescendantOfRoot = ReactDOM.findDOMNode(this.tbody).contains(event.target);
if (!isDescendantOfRoot) {
event.stopPropagation();
this.setState({
selectedRowIndex: -1
}, () => {
@chengjianhua
chengjianhua / Data.js
Created September 14, 2016 05:50
update list item in immutable list
import {List, Map} from 'immutable';
import {ActionTypes} from '../constants/Constants';
const defaultState = new Map({
dataList: new Map({
currentAccount: '',
currentPath: new List(),
data: new List(),
isLoading: false
@chengjianhua
chengjianhua / disable-select-by-css.css
Last active September 18, 2016 08:40
disable selection
.disable-select {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@chengjianhua
chengjianhua / compute-pagination-buttons.js
Last active September 18, 2016 08:41
compute pagination buttons
function range(len, start) {
let end = 0;
const out = [];
if (start === undefined) {
start = 0;
end = len;
} else {
end = start;
@chengjianhua
chengjianhua / React.Chindren.jsx
Last active September 18, 2016 08:42
React.Children usage
React.Children.map(this.props.children, (child, index) => {
const props = child.props;
return Object.assign({}, child.props, {index});
});
@chengjianhua
chengjianhua / DataTable.jsx
Created August 18, 2016 03:31
React.cloneElement usage
React.cloneElement(child, {
onSort: this.handleSort.bind(this, field),
orderStatus: this.state.orderStatus
});
@chengjianhua
chengjianhua / Store.js
Last active August 18, 2016 03:30
sort according to the specified field in object
function _sort({array, sortField, order}) {
order = order.toLowerCase();
const isAsc = order === Order.ASC;
return array.sort((a, b) => {
let valueA = a[sortField] === null ? '' : a[sortField];
let valueB = b[sortField] === null ? '' : b[sortField];
if(!isAsc) {
const temp = valueA; valueA = valueB; valueB = temp;