Skip to content

Instantly share code, notes, and snippets.

View benweizhu's full-sized avatar
🇨🇳
I may be slow to respond.

Ben benweizhu

🇨🇳
I may be slow to respond.
View GitHub Profile
@benweizhu
benweizhu / gist:166eb8bfe67fc66233e9
Created November 23, 2015 12:59
jest_webpack_preprocessosr.js
var babelJest = require('babel-jest');
module.exports = {
process: function (src, filename) {
return babelJest.process(src.replace(/import.*from.*\.((less)|(scss)|(svg)).*;/gi, ''), filename);
}
};
import React from "react";
import { render } from "react-dom";
const ParentComponent = React.createClass({
getDefaultProps: function() {
console.log("ParentComponent - getDefaultProps");
},
getInitialState: function() {
console.log("ParentComponent - getInitialState");
return { text: "" };
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@benweizhu
benweizhu / shell
Created May 1, 2017 02:58
stop / remove all Docker containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
@benweizhu
benweizhu / app.js
Created July 20, 2017 08:38 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@benweizhu
benweizhu / noncritcss.md
Created July 26, 2017 09:40 — forked from scottjehl/noncritcss.md
Comparing two ways to load non-critical CSS

I wanted to figure out the fastest way to load non-critical CSS so that the impact on initial page drawing is minimal.

TL;DR: Here's the solution I ended up with: https://github.com/filamentgroup/loadCSS/


For async JavaScript file requests, we have the async attribute to make this easy, but CSS file requests have no similar standard mechanism (at least, none that will still apply the CSS after loading - here are some async CSS loading conditions that do apply when CSS is inapplicable to media: https://gist.github.com/igrigorik/2935269#file-notes-md ).

Seems there are a couple ways to load and apply a CSS file in a non-blocking manner:

@benweizhu
benweizhu / gist:e3d2e65cafc05d010e431410a9a50fce
Created January 23, 2018 07:07
Dockerfile for GOCD Install Pip and fix Locale missing error
FROM gocd/gocd-agent-ubuntu-16.04:v17.11.0
RUN apt-get clean && apt-get update && apt-get install -y locales
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN apt-get update && \
@benweizhu
benweizhu / nginx.conf.default
Created January 30, 2018 10:02 — forked from nishantmodak/nginx.conf.default
Default Nginx Conf
#user nobody;
#Defines which Linux system user will own and run the Nginx server
worker_processes 1;
#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores.
#error_log logs/error.log; #error_log logs/error.log notice;
#Specifies the file where server logs.
@benweizhu
benweizhu / webpack.config.js
Created April 2, 2018 08:03
webpack node js
const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
target: "node",
entry: "./index.js",
externals: [nodeExternals()],
output: {
libraryTarget: 'commonjs2',
path: path.resolve(__dirname, ""),