Skip to content

Instantly share code, notes, and snippets.

View diyism's full-sized avatar

Malcolm Ke Win diyism

View GitHub Profile
@diyism
diyism / gist:9384085
Created March 6, 2014 07:20
ghost for linux: partimage不能备ext4,而dd+gzip太慢,fsarchiver不错
sudo partimage save -bcdz1 /dev/sda5 /media/lubuntu/DOC/CloneDsk/Ghost/lubuntu.ke34.partimg.gz
sudo partimage restore -b /dev/sda5 /media/lubuntu/DOC/CloneDsk/Ghost/lubuntu.ke34.partimg.gz
sudo dd if=/dev/zero of=/media/lubuntu/lubuntu/zero_file bs=16M count={2M less than that in "df -m"}
sudo rm /media/lubuntu/lubuntu/zero_file
sudo dd if=/dev/sda5 conv=sync,noerror bs=16M | gzip -c > /media/lubuntu/DOC/CloneDsk/Ghost/lubuntu.ke34.dd.gz
gunzip -c /media/lubuntu/DOC/CloneDsk/Ghost/lubuntu.ke34.dd.gz | sudo dd of=/dev/sda5 conv=sync,noerror bs=16M
@diyism
diyism / realize mongdb schema with yii model rules
Last active August 29, 2015 13:57
realize mongdb schema with yii model rules
yii model rules类型:
无:不赋值(即setAttributes不复制),
仅safe表:可为空,不限规则,必须赋值,
仅required表:不可为空,不限规则,必须赋值,
无allowEmpty(默认true)+rule表:可为空,不空时必符合规则,必须赋值,
'allowEmpty'=>false+rule表:不可为空,必符合规则,必须赋值.
重载每个model的setAttributes,
先对top document用EMongoDocument->setAttributes()来验证元素, 并CModel->getErrors,
再对sub document用CModel->setAttributes()来验证元素, 并CModel->getErrors,
@diyism
diyism / sleep in reactphp
Created April 15, 2014 10:49
sleep in reactphp, 由于是单线程event loop,回调函数里绝对不要写sleep和EvTimer之类,会阻塞整个线程,应该写addPeriodicTimer
<?php
require 'vendor/autoload.php';
$i = 0;
chdir(dirname(__FILE__));
$app=function ($request, $response) use (&$i, &$loop)
{if ($request->getPath()=='/favicon.ico')
{$response->writeHead(200, array('Content-Type' => 'image/x-icon'));
$response->end('');
@diyism
diyism / data partition
Last active August 29, 2015 14:00
move /var, /home, /tmp to seperate partition
#boot from usb live
#edit /media/lubuntu/system/etc/fstab
UUID=xxxxxxx /data ext4 default 0 2
/data/var /var none bind 0 0
/data/home /home none bind 0 0
/data/tmp /tmp none bind 0 0
#then execute:
sudo cp -ax /media/lubuntu/system/var/* /media/lubuntu/data/var/
@diyism
diyism / proxy twitter api php
Last active August 29, 2015 14:02
proxy twitter api php
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');
define('THIS_PAGE', 'http://127.0.0.1/test.php');
define('CONSUMER_KEY', 'yT577ApRtZw51q4NPMPPOQ'); //official TweetDeck consumer key
define('CONSUMER_SECRET', '3neq3XqN5fO3obqwZoajavGFCUrC42ZfbrLXy5sCv8'); //offical TweetDeck consumer secret
define('NGINX_PROXY_TWITTER', 'http://proxy_twitter_api.domain.com'); //if there is proxy, set it 'https://api.twitter.com'
session_start();
@diyism
diyism / 图形交互型用adaptive(viewport撑满屏宽)
Created July 5, 2014 09:39
图形交互型用adaptive(viewport撑满屏宽)
对于ios safari和android chrome仅需width, 而target-densitydpi被忽略:
<meta name="viewport" content="width=380, user-scalable=no"/> #不要加initial-scale因默认不是1.0
<div style="background:yellow;width:380px;height:1000px;">jack3</div>
对于android browser需要width和target-densitydpi(注意一个tab设了一次target-densitydpi后即时刷新页面新dpi值也更改不了第一次设的值):
<meta name="viewport" content="width=380, user-scalable=no"/>
<div style="background:yellow;width:380px;height:1000px;">jack3</div>
<script>
design_width=380;
deviceDpi=160*window.devicePixelRatio;
@diyism
diyism / gist:b645d8dc0cf85faf238c
Created September 26, 2014 11:44
php_phantom_proxy.js and test.php
===========================test.php===========================
<?php
$input=array('pass_url'=>'http://www.sqjg.net/Jgcx/',
'pass_method'=>'GET',
'pass_headers'=>array(),
'pass_post'=>'',
'pass_inject_js'=>array('jquery-1.11.1.min.mod_for_phantom.js'),
'pass_tasks'=>array(0=>array('flag'=>"var rtn=document.getElementById('dyl_708');
return rtn;
",
@diyism
diyism / 新手配置大访问量网站服务器常出现的两个问题
Last active August 29, 2015 14:08
新手配置大访问量网站服务器常出现的两个问题
一.积累大量TIME_WAIT连接无法接受新请求:
比较安全的设置是/etc/sysctl.conf:
net.ipv4.tcp_timestamps=1
net.ipv4.tcp_tw_recycle=0
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_max_tw_buckets=10000 #改之后一般本地打开端口数从26000降到6000左右(netstat -tuwanp | awk '{print $4}' | sort | uniq -c | wc -l)
执行"sysctl -p"生效
参考: http://nick.txtcc.com/index.php/linux/1162
二.启动iptables一两个小时后出现大量丢包:
@diyism
diyism / gist:75820c3399465b8a29f1
Last active August 29, 2015 14:24
tesseract 3.03编译安装过程(centos 3.03), 以及训练步骤
https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract
http://sunfuze.github.io/2014/07/20/Ubuntu-14.04-%E4%BD%BF%E7%94%A8Tesseract-ocr%E8%AE%AD%E7%BB%83%E6%A0%B7%E6%9C%AC/
http://manpages.ubuntu.com/manpages/trusty/man1/tesseract.1.html
ubuntu 14.04直接:
sudo apt-get install tesseract-ocr
先装这4个, leptonica依赖到(到最后用tesseract -v可以看到三层依赖关系):
sudo yum -y install libjpeg-devel libpng-devel libtiff-devel zlib-devel
@diyism
diyism / htmlpost.xml
Created August 13, 2015 06:48
brainwallet blockchain pushtx htmlpost
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>brainwallet</author>
<description>POST method for YQL</description>
<sampleQuery><![CDATA[
select * from {table} where url='http://example.com'
and postdata="foo=foo&bar=bar" and xpath="//p"]]></sampleQuery>
<documentationURL></documentationURL>
</meta>