Skip to content

Instantly share code, notes, and snippets.

View xuyuji9000's full-sized avatar

Karl Xu xuyuji9000

  • Shanghai, China
View GitHub Profile
@xuyuji9000
xuyuji9000 / jquery_in_console.js
Last active November 2, 2016 09:28
"jQuery" inside chrome browser
javascript: (function(e, s) {
e.src = s;
e.onload = function() {
jQuery.noConflict();
console.log('jQuery injected');
};
document.head.appendChild(e);
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js')
@xuyuji9000
xuyuji9000 / 0_reuse_code.js
Created October 31, 2016 08:00
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
@xuyuji9000
xuyuji9000 / webpack.config.js
Last active January 6, 2017 20:23 — forked from learncodeacademy/webpack.config.js
Sample Basic Webpack Config
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/scripts.js",
output: {
path: __dirname + "/js",
filename: "scripts.min.js"
@xuyuji9000
xuyuji9000 / index.js
Last active January 19, 2017 03:35
combine reduers
// default inside a ./reducers folder
import { combineReducers } from "redux";
import tweets from "./tweetsReducer";
import user from "./userReducer";
export default combineReducers({
tweets,
user
});
@xuyuji9000
xuyuji9000 / 2.webpack.config.js
Last active March 20, 2017 08:15
react webpack with hotload
var path = require("path");
var webpack = require("webpack");
module.exports = {
entry: [
'webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
'webpack/hot/only-dev-server', // "only" prevents reload on syntax errors
"./src/app.js" // appʼs entry point
],
devtool: "source-map",
var WebpackDevServer = require("webpack-dev-server");
var webpack = require("webpack");
var config = require("./webpack.config.js");
var server = new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
noInfo: false,
historyApiFallback: true,
stats: {colors: true}
@xuyuji9000
xuyuji9000 / .gitignore
Created February 12, 2017 05:11
This is a reusable .gitignore file.
node_modules/
@xuyuji9000
xuyuji9000 / 1.webpack.config.js
Created March 20, 2017 08:14
react webpack without hotload
var path = require('path');
module.exports = {
entry: [
'./src/app.js',
],
devtool: 'source-map',
output: {
path: __dirname+'/dist',
filename: 'bundle.js',
@xuyuji9000
xuyuji9000 / php_try_catch.php
Last active April 21, 2017 10:48
PHP try catch
<?php
function inverse($x) {
if(!$x)
throw new Exception("Division by zero.");
return 1 / $x;
}
try {
echo inverse(5)."\n";
echo inverse(0)."\n";
server {
listen 80;
server_name localhost;
root [directory_path]/public;
index index.php
location / {
try_files $uri $uri/ /index.html;
if (!-e $request_filename){ rewrite ^(.*)$ /index.php last; }