Skip to content

Instantly share code, notes, and snippets.

View picasso250's full-sized avatar
💭
I may be slow to respond.

pica picasso250

💭
I may be slow to respond.
View GitHub Profile
<?php
namespace Lib;
use Exception;
use Psr\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class Container implements ContainerInterface
{
@picasso250
picasso250 / get_first_line.php
Created February 23, 2018 07:08
get first line of file content
<?php
function get_first_line($content) {
$pos = -1;
do {
$pos = strpos($content, "\n", $pos+1);
$found = trim(substr($content, 0, $pos));
// http://blog.sina.com.cn/s/blog_49f914ab0101eyjj.html
} while (trim(substr($content, 0, $pos), "\r\n\t \xEF\xBB\xBF") === "");
return substr($content, 0, $pos);
}
@picasso250
picasso250 / input.php
Created February 8, 2018 06:15
QuickForm 魔改
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
@picasso250
picasso250 / deploy-ssh
Last active May 14, 2018 10:41
deploy PHP project on linux
#!/bin/bash
# deploy project with ssh
# has to work with deploy_remote
set -eu
git_root_dir=~/Documents/work/git/xxx # the dir of git
git_src_dir=. # if you don't want copy whole dir, change it to sub dir
git_sub_dir="a b" # sub dir list to deploy
@picasso250
picasso250 / tail.php
Created January 25, 2018 09:19
tail for web
<?php
$f = isset($_GET['f']) ? $_GET['f'] : '';
if (!$f) {
die("plz specify f");
}
if (!is_file($f))
die("$f is not a file");
header("Content-Type:text/plain;charset=UTF-8");
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<canvas id="canvas" width="220" height="220"></canvas>
<script type="text/javascript">
var canvas = document.getElementById('canvas');
@picasso250
picasso250 / unzip_windows.php
Created December 19, 2017 04:48
unzip a zip file on windows, preserve the right encode chinese
<?php
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
for ($i=0;($filename=$zip->getNameIndex ($i))!==false; $i++) {
echo "$filename\n";
if ($filename[strlen($filename)-1] == '/') {
$filename = iconv('UTF-8', 'GBK', $filename);
if (!is_dir($filename)) {
@picasso250
picasso250 / libevent-2.0.20-stable.sh
Created March 22, 2017 08:14 — forked from vimalearnest/libevent-2.0.20-stable.sh
Install libevent and tmux on CentOS/RH 6.3
#!/bin/sh
curl -sL 'https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz' | tar zx
cd libevent-2.0.20-stable/
./configure --prefix=/usr/local/libevent/2.0.20-stable
make
sudo make install
sudo alternatives --install /usr/local/lib64/libevent libevent /usr/local/libevent/2.0.20-stable/lib 20018 \
--slave /usr/local/include/libevent libevent-include /usr/local/libevent/2.0.20-stable/include \
--slave /usr/local/bin/event_rpcgen.py event_rpcgen /usr/local/libevent/2.0.20-stable/bin/event_rpcgen.py
@picasso250
picasso250 / test.php
Last active May 11, 2018 16:41
PHP test tool by xiaochi
#!env php
<?php
// PHP test tool by xiaochi
// Usage: test.php foo.php
// If you have a test_foo.php, it will automatically include
// foo.php and run test_foo.php.
// It also includes `vendor/autoload.php`
$vendor_autoload = "vendor/autoload.php";
@picasso250
picasso250 / test
Last active March 17, 2016 03:05
C++ Testing framework, simple as possible
#!bash
# Usage: test X
# It will include `X.h` and `test_X.cpp`
# and execute all `test_.+()` functions.
if [[ x$1 == "x" ]]; then
echo "Usage: $0 <file>"
exit
fi