Skip to content

Instantly share code, notes, and snippets.

@SuoXC
SuoXC / request_parallely.php
Created November 20, 2016 15:45
use php curl_multi_* to perform http requests
<?php
interface HandleIterator {
public function getNextHandle();
public function dataCallback($data);
}
class IndexHandleIterator implements HandleIterator{
private $curl;
private $count;
public function __construct(){
$this->curl = curl_init("http://localhost/index.php");
@SuoXC
SuoXC / Facade.php
Last active August 1, 2017 01:34
simple service locator + Facade(like in Laravel) implementation
<?php
class Facade{
private static $service = null;
public static function getKey(){
return 'world';
}
public static function __callstatic($method,$args){
if(!isset(self::$service)){
self::$service = ServiceLocator::getInstance()->getService(self::getKey());
}
@SuoXC
SuoXC / docker-compose.yml
Created November 20, 2016 16:24
docker compose file to build a redis cluster ?
version: '2'
services:
db:
image: mysql
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment: # ???
MYSQL_ROOT_PASSWORD: root
@SuoXC
SuoXC / .vimrc
Created November 29, 2016 01:46
""""""""""""""""""""""""""""""""""""""""""""""""""""""
"原生设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on
"set foldmethod=syntax "set default foldmethod
set foldminlines=10
@SuoXC
SuoXC / iplookup.php
Last active December 3, 2016 08:59
fetch ip info parallelly, used for analyzing user data
<?php
//install dependancy: composer require guzzlehttp/guzzle
include 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Promise\each_limit;
$client = new Client();
function getIps(){
while(!feof(STDIN)){
$ip = trim(fgets(STDIN));
@SuoXC
SuoXC / ProcessExecutor.php
Created February 25, 2017 16:12
use anonymous function and an array of args to create a series of sub process to do the job,no need to care about process management api.
<?php
/**
* @example
*
* $a = new ProcessExecutor();
* $b = function ($arg){ sleep(1);echo "hello $arg\n"; };
* $a->setRunnables($b,['aaa','bbb']);
* $a->setCheckStatus(function($arg){return $arg === 'aaa';});
* $a->execute();
* var_dump($a->getRunStatusArr());
@SuoXC
SuoXC / font_plotter.py
Created February 28, 2018 16:02
plot glyphs in a specified font to images
from PIL import Image, ImageDraw, ImageFont
class FontPlotter:
def __init__(self,font_size=200,convas_size=256):
self._font_size = font_size
self._convas_size = convas_size
self._offset = int((convas_size - font_size) / 2)
self._font = None
def loadFont(self,filename):
@SuoXC
SuoXC / add_user.sh
Created March 6, 2018 09:59
add an user on all nodes in a cluster
# 在所有机器上配置部署账号和权限
set -x
ROOT_PASS=rootpassword
USR=dev
PASS=password
OTHER_NODES_IP="ip1 ip2" #以空格分割
@SuoXC
SuoXC / gbk_to_utf8.py
Last active April 13, 2018 15:14
python 修改文本文件编码
def gbk_to_utf8(source, target):
with open(source, "r", encoding="gbk") as src:
with open(target, "w", encoding="utf-8") as dst:
for line in src.readlines():
dst.write(line)
import sys
from pyspark import SparkContext
from pyspark import HiveContext
from pyspark.sql.types import *
from _collections import defaultdict
from datetime import date
from operator import add
from datetime import datetime
sc = SparkContext()