Skip to content

Instantly share code, notes, and snippets.

@jamesBan
jamesBan / exists
Last active August 29, 2015 14:04
检查mongodb collection 是否存在
<?php
$mongo = new MongoClient();
$db = $mongo->dbName;
$collection = $db->collectionName;
$cursor = $collection->find($criteria, array('_id' => 1))->limit(1);
if($coursor->count() == 0){
exit('not exist');
}
@jamesBan
jamesBan / install ImageMagick+tesseract-ocr.sh
Last active February 5, 2018 10:18
install ImageMagick+tesseract-ocr
wget http://leptonica.googlecode.com/files/leptonica-1.69.tar.bz2
tat xvf leptonica-1.69.tar.bz2
cd leptonica-1.69
./configure
make && make install
ldconfig
wget https://tesseract-ocr.googlecode.com/files/tesseract-ocr-3.02.02.tar.gz
tar zxvf tesseract-ocr-3.02.02.tar.gz
@jamesBan
jamesBan / mongodb hash mongoId.php
Last active September 16, 2015 07:59
get hash mongoId
<?php
$client = new MongoClient('mongodb://127.0.0.1');
$collection = $client->test->test;
//insert data
$data[] = array('name' => 'zhangsan', 'age' => rand(1, 100));
$data[] = array('name' => 'zhangsan1', 'age' => rand(1, 100));
$data[] = array('name' => 'zhangsan2', 'age' => rand(1, 100));
<?php
//http://flask.pocoo.org/snippets/71/ that is good idea
include 'predis/predis.phar';
class OnlineUsers {
/* time to consider user online */
private $minutes = 5 ;
function online() {
@jamesBan
jamesBan / random
Created July 7, 2015 13:19
Elasticsearach
{
"query" : { "query_string" : {"query" : "*:*"} },
"sort" : {
"_script" : {
"script" : "(doc['_id'].value + salt).hashCode()",
"type" : "number",
"params" : {
"salt" : 10000
},
"order" : "asc"
{
"movie2": {
"properties": {
"title": {
"type": "string",
"store": true
},
"created": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
@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));
@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
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 / array_reduce.php
Last active March 15, 2016 05:36
嵌套匹配
<?php
$a = [
'1,2',
'3',
'4',
'5,6'
];
$hash = [
1 => 'xxx1',