Skip to content

Instantly share code, notes, and snippets.

View chengjianhua's full-sized avatar
💦

Jianhua Cheng chengjianhua

💦
View GitHub Profile
function print (path, layer) {
if (layer.route) {
layer.route.stack.forEach(print.bind(null, path.concat(split(layer.route.path))))
} else if (layer.name === 'router' && layer.handle.stack) {
layer.handle.stack.forEach(print.bind(null, path.concat(split(layer.regexp))))
} else if (layer.method) {
console.log('%s /%s',
layer.method.toUpperCase(),
path.concat(split(layer.regexp)).filter(Boolean).join('/'))
}
/*eslint-disable*/
var foo = { n: 1};
(function(foo) {
console.log(foo.n);
foo.n = 3;
var foo = { n: 2 };
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
@chengjianhua
chengjianhua / .setup.js
Created March 29, 2017 09:11
The setup for mocha test environment
import { jsdom } from 'jsdom';
import chai from 'chai';
import chaiEnzyme from 'chai-enzyme';
import { shallow, mount, render } from 'enzyme';
chai.use(chaiEnzyme());
global.should = chai.should();
global.shallow = shallow;
@chengjianhua
chengjianhua / index.html
Created March 26, 2017 05:19 — forked from anonymous/index.html
preview images with slide animation
<div>
<div id="preview" class="preview">
<nav class="nav">
<button class="close">
返回
</button>
</nav>
<div class="container">
<button class="prev">&lt;</button>
<button class="next">&gt;</button>
@chengjianhua
chengjianhua / withStyles.js
Created March 8, 2017 03:52
withStyle HOC for style-loader
import React, { Component } from 'react';
import hoistStatics from 'hoist-non-react-statics';
function withStyles(style) {
return function wrapWithStyles(ComposedComponent) {
class WithStyles extends Component {
componentWillMount() {
style.use();
}
@chengjianhua
chengjianhua / gray-filter.css
Last active March 3, 2017 05:13
gray filter, disabled
.gray {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%);
filter: gray;
}
@chengjianhua
chengjianhua / scroll-bottom.js
Created February 28, 2017 02:26
jQuery judge whether scroll to the bottom of window
<script type="text/javascript">
$(document).ready(function(){
alert($(window).height()); //浏览器时下窗口可视区域高度
alert($(document).height()); //浏览器时下窗口文档的高度
alert($(document.body).height());//浏览器时下窗口文档body的高度
alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin
alert($(window).width()); //浏览器时下窗口可视区域宽度
alert($(document).width());//浏览器时下窗口文档对于象宽度
alert($(document.body).width());//浏览器时下窗口文档body的高度
@chengjianhua
chengjianhua / hackSetTitleInWeixin.js
Last active February 21, 2017 10:05
the hack method that can make the title in weixin's webview be changable
hackSetTitle = (title) => {
document.title = title;
const iframe = document.createElement('iframe');
iframe.src = '/favicon.ico';
iframe.style.visibility = 'hidden';
const listener = () => {
setTimeout(() => {
iframe.removeEventListener('load', listener);
@chengjianhua
chengjianhua / ajax.test.js
Created December 17, 2016 04:06
the test for ajax which based on axios
import chai from 'chai';
import sinon from 'sinon';
import mock from 'mock-require';
import moxios from 'moxios';
mock('v2/models/globals/SessionState', {
currentUser: {
neoToken: '1234567890'
}
});