Skip to content

Instantly share code, notes, and snippets.

View shengoo's full-sized avatar

shengoo

  • Beijing, China
View GitHub Profile
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
var keys = {37: 1, 38: 1, 39: 1, 40: 1};
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
'use strict';
/**
* @param {Number} [baseFontSize = 100] - 基础fontSize, 默认100px;
* @param {Number} [fontscale = 1] - 有的业务希望能放大一定比例的字体;
*/
const win = window;
export default win.flex = (baseFontSize, fontscale) => {
const _baseFontSize = baseFontSize || 100;
const _fontscale = fontscale || 1;
<?php
/**
* Plugin Name: WordPress Importer Post ID Preservation
* Description: When importing posts make sure that post ID from the original site is used on the destination site. This should only be used when first setting up an environment, or if the destination site is not canonical (e.g. a dev or staging environment).
* Author: Weston Ruter, XWP
*/
/**
* Force WordPress Importer to never honor the post_exists() check, since we want to override existing posts.
*

使用componentDidCatch处理React中的Uncaught error

React 16 提供了一个内置的函数componentDidCatch, 它会在render抛出异常的时候运行。

官方的示例代码如下:

class ErrorBoundary extends React.Component {
  constructor(props) {
 super(props);

React Component lifecycle

Single component

init

  1. constructor
  2. componentWillMount
  3. render
  4. componentDidMount
@shengoo
shengoo / app.js
Created March 23, 2018 16:26
HeaderTransition
import React, {Component} from 'react';
import {
Animated,
Platform,
StatusBar,
StyleSheet,
Text,
View,
RefreshControl,
ScrollView,
@shengoo
shengoo / angular bootstrap nav collapse.html
Last active November 13, 2016 15:30
angular bootstrap nav collapse without jQuery
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
aria-expanded="false" aria-controls="navbar"
ng-click="showdropdown = !showdropdown">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">
@shengoo
shengoo / remove_devicepx.md
Last active November 8, 2016 09:01
remove devicepx from wordpress

add the following to your theme’s functions.php file:

function remove_devicepx() {
    wp_dequeue_script( 'devicepx' );
}
add_action( 'wp_enqueue_scripts', 'remove_devicepx' );
@shengoo
shengoo / angular2 nested routes.md
Last active November 4, 2016 08:38
angular2 nested routes

## angular2里的路由模块支持多层嵌套路由,不需要像angular1那样使用第三方的路由了。

具体配置如下:

const routes: Routes = [
  {path: '', component: IndexComponent},
  {path: 'home', component: HomeComponent},
  {path: 'about', component: AboutComponent  }//redirectTo: 'about/about1'
];
@shengoo
shengoo / props-vs-state.md
Created October 31, 2016 16:16
props-vs-state in react

props vs state

Ever since we started using React to rebuild our UI at uberVU (now Hootsuite) the #1 developer question has probably been:

What's the exact difference between props and state?

It's fairly easy to understand how they work—especially when seen in context—but it's also a bit difficult to grasp them conceptually. It's confusing at first because they both have abstract terms and their values look the same, but they also have very different roles.

Context