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 / header.py
Created March 18, 2016 06:09
standard and recomanded python head
#! /usr/bin/env python
# -*- coding: utf-8 -*-
@raphaelsoul
raphaelsoul / another sample
Last active March 28, 2016 09:18
对比测试多线程性能
from threading import Thread
import queue
import time
# q是任务队列
#NUM是并发线程总数
#JOBS是有多少任务
q = queue.Queue()
NUM = 2
JOBS = 10
#具体的处理函数,负责处理单个任务
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import queue as Queue
import threading
import time
exitFlag = 0
class myThread (threading.Thread):
@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";
}
}
@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]
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 / 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;
@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 / 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)
})
})
}
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 + '秒';