Skip to content

Instantly share code, notes, and snippets.

@jamesBan
jamesBan / convert.py
Created April 13, 2017 06:15
python 调用office 转换文档
import sys
import os
import glob
import win32com.client
def convert(files, formatType = 32):
powerpoint = win32com.client.Dispatch("PowerPoint.Application")
powerpoint.Visible = 1
for filename in files:
@jamesBan
jamesBan / Dockerfile
Created March 27, 2017 12:37
docker php5命令行镜像
FROM alpine:3.4
RUN apk --no-cache --update add \
php5 \
php5-cli \
php5-pcntl \
php5-posix \
php5-sockets \
php5-mysql \
php5-zip \
php5-phar \
@jamesBan
jamesBan / yii-get-modules-actions
Created February 24, 2017 08:40
yii2获取所有module方法
<?php
foreach (\Yii::$app->getModules() as $id => $child) {
if(in_array($id, ['gii', 'debug'])) {
continue;
}
$module = \Yii::$app->getModule($id);
$namespace = $module->controllerNamespace."\\";
$dir = $module->controllerPath;
$fileList = glob($dir."/*Controller.php");
@jamesBan
jamesBan / multi_curl.php
Created February 6, 2017 12:42
curl 并行
<?php
$begin = microtime(true);
$url = 'http://cdn-1.yi-you.org/courseware/4202ee83f0d8a3944c4b72dd/4ba56224b2498ae0931fe1f108bee658.pdf';
$total = 71;
$urls = [];
for ($i = 1; $i <= $total; $i++) {
$urls[] = $url . '?odconv/jpg/page/' . $i . '/density/288/quality/92/resize/1280';
}
if(!is_dir('images')) {
@jamesBan
jamesBan / parse_xlsx.php
Created May 26, 2016 09:51 — forked from searbe/parse_xlsx.php
Parse simple XLSX in PHP with SimpleXML and ZipArchive
<?php
/**
* I had to parse an XLSX spreadsheet (which should damn well have been a CSV!)
* but the usual tools were hitting the memory limit pretty quick. I found that
* manually parsing the XML worked pretty well. Note that this, most likely,
* won't work if cells contain anything more than text or a number (so formulas,
* graphs, etc ..., I don't know what'd happen).
*/
@jamesBan
jamesBan / git-tip.sh
Last active April 5, 2016 09:14
删除远程不存在的分支
git remote show origin
git remote prune origin
@jamesBan
jamesBan / array_reduce.php
Last active March 15, 2016 05:36
嵌套匹配
<?php
$a = [
'1,2',
'3',
'4',
'5,6'
];
$hash = [
1 => 'xxx1',
@jamesBan
jamesBan / 全角转半角.php
Created October 16, 2015 08:25
全角转半角
<?php
function make_semiangle($str){
$arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4',
'5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9',
'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E',
'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J',
@jamesBan
jamesBan / dump.php
Last active September 16, 2015 08:09 — forked from eddmann/dump.php
An alternative to 'var_dump'
function dump()
{
$args = func_get_args();
echo "\n<pre style=\"border:1px solid #ccc;padding:10px;margin:10px;font:14px courier;background:whitesmoke;display:block;border-radius:4px;\">\n";
$trace = debug_backtrace(false);
$offset = (@$trace[2]['function'] === 'dump_d') ? 2 : 0;
echo "<span style=\"color:red\">" . @$trace[1+$offset]['class'] . "</span>:" .
@jamesBan
jamesBan / php tuple.php
Created September 16, 2015 07:56
php tuple splfixArray
<?php
class Tuple extends SplFixedArray
{
protected $prototype;
public function __construct(array $prototype, array $data = [])
{
echo __METHOD__ . "\r\n";
parent::__construct(count($prototype));