Skip to content

Instantly share code, notes, and snippets.

View raphaelsoul's full-sized avatar
㊗️
Question: why it works? why it not works? why it works after I restart?

Dechen Zhuang raphaelsoul

㊗️
Question: why it works? why it not works? why it works after I restart?
  • China
View GitHub Profile
@raphaelsoul
raphaelsoul / readme.md
Created June 20, 2018 06:34
结构说明
  • src

    • core // 核心/公共类库
      • app.ts // 暴露一个koa application实例对象 和一个由logjs提供的logger工具类
      • redis.ts // redis client的封装 promisified by bluebird
      • sequelize.ts // 建立数据库链接 实例化数据模型 绑定模型关系
      • (mongoose.ts) // 暂时不在库里
    • middlewares // 抽取公用的中间件,例如上传 权限控制 头部检查 passport封装等
    • models // model层
@raphaelsoul
raphaelsoul / webpack.config.js
Created April 4, 2018 01:25
webpack bundle config for backend(typescripted)
const path = require('path');
const nodeExternals = require('webpack-node-externals')
module.exports = {
entry: './src/app.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
@raphaelsoul
raphaelsoul / log4j2-config-example.xml
Created September 17, 2017 16:29
just another log4j2 config sample
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="ConsoleStream" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-dd-MM HH:mm:ss,SSS XXX}{GMT+0} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<RollingFile
name="AppStream"
fileName="runtime/logs/app.log"
filePattern="runtime/logs/app-%d{yyyy-MM-dd}.log.gz"
var diff = $(this).data('time')*1000 - Date.parse(new Date());
if (diff < 0 ) { $(this).text('竞猜结束');return; }
var sec = diff/1000%60;
var min = Math.floor(diff%(24*3600*1000)%(3600*1000)/(60*1000)) || '';
var hour = Math.floor(diff%(24*3600*1000)/(3600*1000)) || '';
var day = Math.floor(diff/(24*3600*1000)) || '';
day = day.length === 0 ? '' : day + '天';
hour = hour.length === 0 ? '' : hour + '小时';
min = min.length === 0 ? '' : min + '分钟';
sec = sec.length === 0 ? '' : sec + '秒';
@raphaelsoul
raphaelsoul / node-async
Created March 28, 2017 15:56
very basic example to understanding promise and aysnc/await
var http = require('http')
function callAPI() {
return new Promise((resolve, reject) => {
http.get('http://www.jb51.net', (res) => {
resolve(res.statusCode)
})
})
}
@raphaelsoul
raphaelsoul / webpack.config.js
Created February 14, 2017 11:33
webpack 2.0 configuration example
const path = require('path')
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const prod = process.argv.indexOf('-p') !== -1
const theme = 'geil'
const ProjectRoot = path.dirname(path.dirname(path.dirname(__dirname)))
const TargetWebRoot = path.join(ProjectRoot, 'blog', 'web', 'themes', theme)
const ResourceRoot = path.join(__dirname, 'resources')
@raphaelsoul
raphaelsoul / recursiveScan.php
Created December 19, 2016 16:14
a code snipper for recursive
$allControllers = [];
function scanControllers($path, &$result) {
$dirs = scandir($path);
foreach($dirs as $dir){
if ($dir{0} == '.') { //todo: 适配linux下.开头的隐藏文件
continue;
}
if (substr($dir, -4) == '.php') {
$result[] = $path. DIRECTORY_SEPARATOR .$dir;
def load_apps(apps):
import importlib
GlobalUrls = []
for app in apps:
module = importlib.import_module('app.{AppName}.urls'.format(AppName=app))
GlobalUrls += getattr(module,'urls')
return GlobalUrls
@raphaelsoul
raphaelsoul / function.js
Last active July 16, 2016 07:13
sample gist for anonymous variables in different programming languages
'use strict';
var fn_use_rest = function(...rest){console.log(rest);}
var fn_use_args = function(){console.log(arguments);}
fn_use_rest(1,2,3,a=4,b=5);
/*
* OUTPUT
* Array [1,2,3,4,5]
@raphaelsoul
raphaelsoul / TestController.php
Last active April 12, 2016 02:03
how to use pjax in laravel
public function getTestPjax(Request $request) {
if($request->header('X-PJAX')){
return "here shoud render html snippts";
} else {
return "here shoud render full documents";
}
}