美国军队是如何应对示威的

刚断断续续的读完了麦克纳马拉写的《回顾越战的悲剧与教训》(In Retrospect: The Tragedy and Lessons of Vietnam。从书名就知道,这本书是主要谈越战的,但对这本书印象最深的却不是越战,而是1967年10月21日,2万多反战者示威游行,冲击五角大楼的事件。

当时越战不断升级,国内反战情绪不断高涨,反战人士计划举行大规模示威游行,目标就是五角大楼。美国政府很早就知道了这个消息,九月份总统林登.约翰逊召集麦克纳马拉等其他高管商讨此事。五角大楼没有任何自然屏障或围墙,人们可以从四面八方走向它,保卫难度相当大。美国军方派出2500名配备来福枪(步枪)的军人肩并肩围住五角大楼,并辅以武装警察。

示威前一天,通过陆军参谋长向所有参与行动的士兵、军官和武装警察发布了一份由陆军副部长戴维·E·麦吉弗特签署的通告,通告如下:

为维护国家机关的权威,我们要完成一个非常艰巨的任务,我们既要坚持宪法赋予人民的自由集会和表达意愿的权力,又要保护政府部门的财产和日常工作的进行。我们不能容忍触犯法律,我们也同样不能容忍阻碍宪法所授权力的合法使用……过强或过弱的反应我们都应该避免,我们的行为必须坚定但又不失尊严。我们要致力于这样一种行动方式:绝对减少可能的流血和伤亡,减少逮捕人数。在可行的范围内分辨违法者与守法者,用最少的暴力完成保护政府雇员(军职的和文职的)工作和财产的任务。(摘自陈丕西翻译的《回顾:越战的悲剧与教训》的第十章)。

麦克纳马拉在回忆录中说:“当我在将近三十年后重读戴维·E·麦吉弗特这些话时,我仍旧不禁为美国军人的职业道德和尽责的作风感到自豪”(摘自陈丕西翻译的《回顾:越战的悲剧与教训》的第十章)。

示威者向士兵们投掷泥团、袖标、传单、木棍和石块,士兵们没有动。 有少数示威者冲破拦阻想进入五角大楼,但都被安排在楼内的后备部队挡回。《华盛顿邮报》在对示威的报导中曾这样说:“虽然从下午直到深夜都存在着出现暴力冲突的可能,但始终没听到一声枪响,也没有什么严重的伤害见诸报道。”(摘自陈丕西翻译的《回顾:越战的悲剧与教训》的第十章)。

当时麦克纳马拉就在五角大楼顶部注视事件的发展,几年后记者问他当时怕不怕,他说的确很怕。

请参看:面临同样的选择

Windows Live Messenger 2011尝鲜

今天装了Windows Live 2011, 用上了Windows Live Messenger 2011。一上来显示的窗口如下:

windows live messeger 默认界面

原先的Messenger窗口被挤到右上的小角落,和右下的广告区域差不多大。而MSN中国网站的内容占据了整个界面的一半以上。 好不容易找到右上角有个小按钮,把界面变回原先的界面:

windows live messeger 简单界面

结果在默认显示方式下,下面和messenger无关的区域占了至少1/3的界面高度。放大窗口,发现联系人的显示方式变了:

windows live messeger简单界面最大化

联系人多列显示,这样同屏显示的联系人数量确实多了不少,但找一个人需要视线在屏幕上做“之”字来回扫描,很不习惯。

原先在msn(live messenger)显示的名字一直是Oldmonk,安装完新版后,发现名字变成了在微软站点填写的真名。在菜单里选择改名,居然还要去live.com网站上去改,输入一个Oldmonk做first name还不行,必须再输入个last name,只好输入“扫地”做first name,“老僧”做last name。

最希望添加的通话记录和hotmail帐号同步的功能还是没有添加,依然在本地保存,也就更谈不上通话记录的搜索了。

微软大概是想通过hotmail和msn积累起的用户量建立起类似facebook的真名为基础的sns社区,可有些画虎不成反类犬的感觉,让我也离msn渐行渐远了。

Git安装经验

最近安装Git服务器折腾了很多时间Sad smile, 其实就卡在一些小地方。大多数git安装指南提到的东西就不说了,就记录一下卡住我的两点:

  1. git访问接口有ssh, http, git://。 刚开始找到的安装指南这几种方式都实现了,于是也一样画葫芦做了一遍,尤其指南中说git:// 方式最快,所以特别看重这个。实现git://协议需要在服务器安装git-daemon, 在debian用apt-get install git-daemon-run安装, 记得要开放tcp 9418 端口。 后来发现压根不需要实现全部接口,只保留一种就足够了。 其中http方式是readonly的,而git://方式需要多开放一个端口,于是只保留了ssh方式
  2. 桌面是windows,用msysgit+TortoisGit。msysgit用ssh-keygen生成的密钥,需要放到msysgit安装目录下的.ssh目录下,很多安装指南上说要放到C:\Users\[用户名]\.ssh下, 耽误了我很多时间。但这个密钥只是对命令行的git有效。 TortoiseGit要用随它一起安装的Puttygen生成密钥,其中的公钥不要保存文件,而是直接从生成窗口中拷贝,追加到服务器上authorized_keys里。某个指南讲的保存公钥文件再cat 公钥文件>>authorized_keys的方式是行不通的。

Tags:

categories IT

Google搜索结果预览

刚才第一次看到Google搜索结果预览,搜索感恩节,结果的前5个都支持预览。下图红框标出来的就是预览图。让我佩服的是,预览图中加上了搜索关键词所在的段落特别强调标出,关键词用红字显示。

Google Instant Previews

 

通过这项技术的实现我猜google搜索技术已经实现了如下功能:

  1. 索引一个关键词时,google能准确知道这个关键词在真实网页中所在的位置,大小
  2. 搜索爬虫能够解析javascript。 在firefox中用noscript关闭js解析,第一个搜索结果的页面中右侧是显示是完全不同的

本来这就要点发布,突然才又想了想,感觉google很有可能是用webkit之类的浏览器rendering engine渲染出来的,并不能证明google爬虫就有真正完全解析html,css, js的能力。 大家认为呢?

Tags:

categories IT

服务器备份脚本

前些天Linode的Fremont机房出现电源事故,造成一些服务器数据丢失,给一些人造成不小的影响。 以前自己也写过简单的在线备份脚本,但功能太弱,所以后来又写了个复杂点的。这里共享现在用的服务器备份脚本,希望对大家有用。该脚本特点如下:

  1. 用php开发
  2. 通过sftp把指定的目录和数据库备份到指定服务器
  3. 备份目录时会检测目录内文件的最后修改日期,如果和上次备份一样就不会再备份
  4. 每个备份文件都加日期戳,备份文件名是www.20101120.tar.gz 这种。
  5. 备份目录时可指定剔除的文件名
  6. 可以设定一个备份文件的保留时间,超过这个时间就删除。还可以设定一个备份文件保留的最少分数,如果一个数据库或一个目录的备份少于这个份数,超过设定时间也不会删除。

代码遵守GPL协议,请在该协议基础上随便使用。

因为当时是自用,而且对php不熟,所以很多地方写得并不严谨,欢迎指出。

下载链接是: http://www.doyj.com/wp-content/uploads/2010/11/phpbk.zip

下面是备份文件中最主要的phpbk.php的代码

  1. <?php
  2. /*
  3. Server Backup Script 0.1 2010/11/22
  4. Programmer: Cui Yingjie
  5. Email: cuiyingjie@gmail.com 
  6. Blog: http://www.doyj.com
  7. Sina microblog: http://t.sina.com.cn/laoseng
  8. Twitter: http://twitter.com/#!/oldmonk
  9.  
  10.  
  11. **************************************************************
  12. Copyright (C) 2010 Cui Yingjie
  13. All Rights Reserved
  14.  
  15. This library is free software: you can redistribute it and/or
  16. modify it under the terms of the GNU Lesser General Public
  17. License as published by the Free Software Foundation, either
  18. version 3 of the License, or (at your option) any later version.
  19.  
  20. This library is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  23. Lesser General Public License for more details.
  24.  
  25. You should have received a copy of the GNU Lesser General Public
  26. License along with this library; If not, see <http://www.gnu.org/licenses/>.
  27. */
  28.  
  29. require_once("sftp.php");                                           
  30.  
  31. define('BKFTP_SERVER','www.bkserver.com');        //backup server address
  32. define('BKFTP_USER','bkuser');                                //backup server user name
  33. define('BKFTP_PASS','password');                            //backup server password
  34. define('BKFTP_PORT', 22);                                            //backup server port
  35. define('BKFTP_KEEPDAYS','60');                              //backup files keep days
  36. define('BKFTP_MAXBKCOUNT','4');                                //定义备份保留的最大个数, 当一个备份文件已经超过了设定的保留最大天数,但这个备份的数量少于最大备份个数时不删除此文件
  37.  
  38.  
  39. function load_array_dump($filename) 
  40. {
  41.     return unserialize(file_get_contents($filename));
  42. }
  43.  
  44. //first char of filepath must be  "/".
  45. function get_bkpath( $filepath )
  46. {
  47.     return '/home/'.BKFTP_USER.$filepath ;    //need be changed according your server configuration. 这段是因为备份服务器的目录结构是 /home/用户名,请根据自己服务器器的情况修改,
  48. }
  49.  
  50. function save_array_dump($filename, $array) 
  51. {
  52.     $fp = fopen($filename, 'w+') or die("I could not open $filename.");
  53.     fwrite($fp, serialize($array));
  54.     fclose($fp);
  55. }
  56.  
  57. function nftpupload( $srcfile, $dest )
  58. {
  59.     try 
  60.     {
  61.         $ftp_dir=$dest;
  62.        
  63.         $filename = end(explode('/',$srcfile )) ;
  64.        
  65.         //build a fully qualified (FTP) path name where the file will reside
  66.         $destination_file= get_bkpath( $ftp_dir.$filename ) ;   
  67.        
  68.         $sftp = new SFTPConnection(BKFTP_SERVER, BKFTP_PORT);
  69.         $sftp->login(BKFTP_USER, BKFTP_PASS);
  70.        
  71.         $sftp->uploadFile($srcfile, $destination_file);
  72.     }
  73.     catch (Exception $e) 
  74.     {
  75.         echo $e->getMessage() . "\n";
  76.     }
  77. }
  78.  
  79. function IsFTPFileExist( $ftpfile )
  80. {
  81.     try 
  82.     {
  83.         $sftp = new SFTPConnection(BKFTP_SERVER, BKFTP_PORT);
  84.         $sftp->login(BKFTP_USER, BKFTP_PASS);
  85.        
  86.         $filelist = $sftp->scanFilesystem( get_bkpath( dirname( $ftpfile ) ) );
  87.        
  88.         return in_array( basename( $ftpfile ) , $filelist ) ;
  89.     }
  90.     catch (Exception $e) 
  91.     {
  92.         echo $e->getMessage() . "\n";
  93.     }
  94.  
  95.     return false ;
  96. }
  97.  
  98. function DeleteNDaysAgoInDirFTPFile( $ftpdir , $days ) 
  99. {
  100.     try 
  101.     {
  102.         $sftp = new SFTPConnection(BKFTP_SERVER, BKFTP_PORT);
  103.         $sftp->login(BKFTP_USER, BKFTP_PASS);
  104.        
  105.         $filelist = $sftp->scanFilesystem(  get_bkpath( $ftpdir ) );
  106.        
  107.         $ic = count( $filelist ) ;
  108.         $afiles = array() ;
  109.         for( $i = 0 ; $i < $ic ; $i++ )
  110.         {
  111.             $afn = explode('.',$filelist[ $i ] ) ;
  112.             if( count( $afn ) != 4 )
  113.                 continue ;
  114.             if( strlen( $afn[ 1 ] ) != 8 )
  115.                 continue ;
  116.            
  117.             if( !isset( $afiles[ $afn[ 0 ] ] ) )
  118.                 $afiles[ $afn[ 0 ] ] = array() ;
  119.            
  120.             $afiles[ $afn[ 0 ] ][ $afn[ 1 ] ] = $filelist[ $i ] ;
  121.         }
  122.        
  123.         $ic = count( $afiles ) ;
  124.         foreach (  $afiles as $key => $value ) 
  125.         {
  126.             $jc = count( $value ) ;
  127.             if( $jc < BKFTP_MAXBKCOUNT )
  128.                 continue ;
  129.            
  130.             ksort( $value ) ;
  131.             foreach( $value as $date => $filepath ) 
  132.             {
  133.                 $bktime = strtotime( substr( $date , 0 , 4 ).'-'.substr( $date , 4 , 2 ).'-'.substr( $date , 6 , 2 ).' 00:00:00' ) ;
  134.                 if( $bktime == false )
  135.                     continue ;
  136.                
  137.                 $diff = time() - $bktime ;
  138.                 if( $diff > 86400 * $days )
  139.                 {
  140.                     $jc-- ;
  141.                    
  142.                     $sftp->deleteFile( get_bkpath( $ftpdir.$filepath ) ) ;
  143.                     if( $jc < BKFTP_MAXBKCOUNT )
  144.                         break ;
  145.                 }
  146.             }
  147.         }
  148.     }
  149.     catch (Exception $e) 
  150.     {
  151.         echo $e->getMessage() . "\n";
  152.     }
  153. }
  154.  
  155. //获取一个目录下所有文件最晚的最后修改时间
  156. function GetPathLastMTime( $filepath , $aexcludefiles )
  157. {
  158.     if (is_dir($filepath)) 
  159.     {
  160.         $lmtime = strtotime( '2000-01-01 00:00:00' ) ;
  161.         if ($dh = opendir($filepath)) 
  162.         {
  163.             while (($file = readdir($dh)) !== false) 
  164.             {
  165.                 if( $file == '.' || $file == '..' )
  166.                     continue ;
  167.                    
  168.                 if( in_array( $file , $aexcludefiles ) )
  169.                     continue ;
  170.                
  171.                 if( is_link( $filepath."/".$file ) )
  172.                     continue ;
  173.                    
  174.                 $lt1 = GetPathLastMTime( $filepath."/".$file    , $aexcludefiles ) ;
  175.                
  176.                 if( $lt1 > $lmtime )
  177.                     $lmtime = $lt1 ;
  178.             }
  179.            
  180.             closedir($dh);
  181.         }
  182.        
  183.         return $lmtime ;
  184.     }
  185.     else
  186.         return filemtime( $filepath ) ;
  187. }
  188.    
  189.     $bkdatafile = '/backup/bkdata.dat' ;        //备份时用到的数据文件,会在这里保存目录的最后修改时间,用来在下次备份中做比对,看是否有被修改
  190.     $bkdatdir     = '/backup/tmp' ;                        //备份用到的临时目录
  191.     $bklogfile     = '/backup/bk.log' ;                //备份日志文件
  192.     $tarexclude = '/backup/tarexclude.cfg' ;    //备份tar目录时需要剔除的文件名列表,会把日志,缓存等文件剔除掉
  193.    
  194.     $dbbkftppath = '/backup/db/' ;                    //数据库备份到备份服务器上的目录名
  195.     $filebkftppath = '/backup/' ;                        //目录备份到备份服务器上的目录名
  196.    
  197.     DeleteNDaysAgoInDirFTPFile( $dbbkftppath , BKFTP_KEEPDAYS ) ;           
  198.     DeleteNDaysAgoInDirFTPFile( $filebkftppath , BKFTP_KEEPDAYS ) ;
  199.    
  200.     $aexcludefiles = array( 'logs' , 'nobk' , 'cache' , '.log.gz' , '.log' ) ;   
  201.    
  202.     $abkdb = array( array( 'user' => 'dbadmin1' , 'pin' => 'dbpassword1' , 'dbname' => 'db1' ) , //这个数组里放入要备份的数据库列表,用户名,口令,数据库名
  203.         array( 'user' => 'dbadmin2' , 'pin' => 'dbpassword2' , 'dbname' => 'db2' ) ,
  204.         array( 'user' => 'dbadmin3' , 'pin' => 'dbpassword3' , 'dbname' => 'db3' ) ,
  205.                 ) ;
  206.                
  207.     $abkdir = array( '/home/user' , '/var/www'    , '/etc' ) ;        //在这个数组里放入要备份的目录路径
  208.    
  209.     $bklog = fopen( $bklogfile, 'a');
  210.  
  211.     if( file_exists( $bkdatafile ) )
  212.     {
  213.         $aLastBkTime = load_array_dump( $bkdatafile ) ;
  214.     }
  215.     else
  216.     {
  217.         $ic = count( $abkdir ) ;
  218.         for( $i = 0 ; $i < $ic ; $i++ )
  219.         {
  220.             $aLastBkTime[ $abkdir[ $i ] ] = strtotime( '2000-01-01 00:00:00' ) ;
  221.         }
  222.     }
  223.  
  224.     //备份数据库
  225.     $ic = count( $abkdb ) ;
  226.     for( $i = 0 ; $i < $ic ; $i++ )
  227.     {
  228.         $sqlfile = $bkdatdir.$abkdb[ $i ][ 'dbname' ].'.'.gmstrftime ('%Y%m%d', time()).'.sql' ;
  229.         $gzsqlfile = $sqlfile.'.gz' ;
  230.         $ftpfile = $dbbkftppath.basename( $gzsqlfile ) ;
  231.        
  232.         if( IsFTPFileExist( $ftpfile ) )
  233.         {
  234.             $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' ftp file exist '.$ftpfile."\n" ;
  235.             fwrite($bklog, $smsg);
  236.             echo $smsg ;
  237.             continue ;
  238.         }
  239.        
  240.         $cmd = '/usr/bin/mysqldump -u'.$abkdb[ $i ][ 'user' ].' -p'.$abkdb[ $i ][ 'pin' ].' -f '.$abkdb[ $i ][ 'dbname' ].'>'.$sqlfile ;
  241.        
  242.         $sr = shell_exec( $cmd ) ;
  243.         $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' backup database '.$abkdb[ $i ][ 'dbname' ]." $sr\n" ;
  244.         fwrite($bklog, $smsg);
  245.         echo $smsg ;
  246.        
  247.         $cmd = '/bin/gzip -9 -f '.$sqlfile ;
  248.         $sr = shell_exec( $cmd ) ;
  249.         $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' compress sql file '.$sqlfile." $sr\n" ;
  250.         fwrite($bklog, $smsg );
  251.         echo $smsg ;
  252.        
  253.         nftpupload( $gzsqlfile , $dbbkftppath ) ;
  254.        
  255.         $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' ftp upload file '.$gzsqlfile.' to '.$dbbkftppath."\n" ;
  256.         fwrite($bklog, $smsg );
  257.         echo $smsg ;
  258.        
  259.         unlink( $gzsqlfile ) ;
  260.     }
  261.    
  262.     //备份文件
  263.     $ic = count( $abkdir ) ;
  264.     for( $i = 0 ; $i < $ic ; $i++ )
  265.     {
  266.         $tarfile = $bkdatdir.end(explode('/',$abkdir[ $i ] )).'.'.gmstrftime ('%Y%m%d', time()).'.tar.gz' ;
  267.         $ftpfile = $filebkftppath.basename( $tarfile ) ;
  268.        
  269.         if( IsFTPFileExist( $ftpfile ) )
  270.         {
  271.             $aLastBkTime[ $abkdir[ $i ] ] = time() ;
  272.             $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' ftp file exist '.$ftpfile."\n" ;
  273.             fwrite($bklog, $smsg);
  274.             echo $smsg ;
  275.             continue ;
  276.         }
  277.            
  278.        
  279.         $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' check last update time '.$abkdir[ $i ]."\n" ;
  280.         fwrite($bklog, $smsg );
  281.         echo $smsg ;
  282.        
  283.         $lmtime = GetPathLastMTime( $abkdir[ $i ] , $aexcludefiles ) ;
  284.        
  285.         if( $lmtime <= $aLastBkTime[ $abkdir[ $i ] ] )
  286.         {
  287.             $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' file is not changed '.$abkdir[ $i ]."\n" ;
  288.             fwrite($bklog, $smsg );
  289.             echo $smsg ;
  290.             continue ;
  291.         } 
  292.        
  293.         //备份文件
  294.         $cmd = 'tar -czf '.$tarfile.' --exclude-caches --exclude-from='.$tarexclude.' '.$abkdir[ $i ] ;
  295.         $sr = shell_exec( $cmd ) ;
  296.         $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' compress file '.$tarfile." $sr\n" ;
  297.         fwrite($bklog, $smsg );
  298.         echo $smsg ;
  299.        
  300.         nftpupload( $tarfile , $filebkftppath  ) ;
  301.         $smsg = gmstrftime ('%b %d %Y %H:%M:%S', time()).' ftp upload file '.$tarfile.' to '.$filebkftppath."\n" ;
  302.         fwrite($bklog, $smsg );
  303.         echo $smsg ;
  304.        
  305.         $aLastBkTime[ $abkdir[ $i ] ] = time() ;
  306.        
  307.         unlink( $tarfile ) ;
  308.     }
  309.    
  310.     save_array_dump( $bkdatafile , $aLastBkTime ) ;   
  311. ?>

下面是sftp.php的内容

  1. //Need libssh2 libssh2-php, PECL ssh2 >= 0.9.0
  2. class SFTPConnection
  3. {
  4.     private $connection;
  5.     private $sftp;
  6.  
  7.     public function __construct($host, $port=22)
  8.     {
  9.         $this->connection = @ssh2_connect($host, $port);
  10.         if (! $this->connection)
  11.             throw new Exception("Could not connect to $host on port $port.");
  12.     }
  13.  
  14.     public function login($username, $password)
  15.     {
  16.         if (! @ssh2_auth_password($this->connection, $username, $password))
  17.             throw new Exception("Could not authenticate with username $username " . "and password $password.");
  18.         $this->sftp = @ssh2_sftp($this->connection);
  19.         if (! $this->sftp)
  20.             throw new Exception("Could not initialize SFTP subsystem.");
  21.     }
  22.  
  23.     public function uploadFile($local_file, $remote_file)
  24.     {
  25.         $sconn = $this->connection;
  26.         ssh2_scp_send ( $sconn , $local_file , $remote_file ) ;
  27.         /*$sftp = $this->sftp;
  28.         $stream = @fopen("ssh2.sftp://$sftp$remote_file", 'w');
  29.         if (! $stream)
  30.             throw new Exception("Could not open file: $remote_file");
  31.         $data_to_send = @file_get_contents($local_file);
  32.         if ($data_to_send === false)
  33.             throw new Exception("Could not open local file: $local_file.");
  34.         if (@fwrite($stream, $data_to_send) === false)
  35.             throw new Exception("Could not send data from file: $local_file.");
  36.         @fclose($stream);*/
  37.     }
  38.    
  39.         function scanFilesystem($remote_file) {
  40.               $sftp = $this->sftp;
  41.             $dir = "ssh2.sftp://$sftp$remote_file"
  42.               $tempArray = array();
  43.             $handle = opendir($dir);
  44.           // List all the files
  45.             while (false !== ($file = readdir($handle))) {
  46.             if (substr("$file", 0, 1) != "."){
  47.               if(is_dir($file)){
  48. //                $tempArray[$file] = $this->scanFilesystem("$dir/$file");
  49.                } else {
  50.                  $tempArray[]=$file;
  51.                }
  52.              }
  53.             }
  54.            closedir($handle);
  55.           return $tempArray;
  56.         }   
  57.  
  58.     public function receiveFile($remote_file, $local_file)
  59.     {
  60.         ssh2_scp_recv( $this->$connection , $remote_file , $local_file ) ;
  61.         /*$sftp = $this->sftp;
  62.         $stream = @fopen("ssh2.sftp://$sftp$remote_file", 'r');
  63.         if (! $stream)
  64.             throw new Exception("Could not open file: $remote_file");
  65.         $contents = fread($stream, filesize("ssh2.sftp://$sftp$remote_file"));           
  66.         file_put_contents ($local_file, $contents);
  67.         @fclose($stream);*/
  68.     }
  69.        
  70.     public function deleteFile($remote_file){
  71.      $sftp = $this->sftp;
  72.       unlink("ssh2.sftp://$sftp$remote_file");
  73.     }
  74. }
  75.  
  76. ?>

代码运行环境是php 5, mysql 5, 要安装libssh2-php, 没在其他环境下测试过。现在用cron每天定期运行该脚本,曾有次误删网站根目录全部内容,幸亏有前一天的备份才得以立刻恢复。照理应该再写个对应的恢复脚本,但一直犯懒没写,想等着服务器出问题再说,希望不会有这样的机会。

欢迎大家使用,有啥意见请多交流, 联系方式写在了代码中。

Tags:

categories IT

推荐个性价比很高的wifi信号覆盖方案

以前为团园做过wifi信号覆盖,但信号总是不稳定。 后来自己在家做的时候,发现还是要用wds来做效果最好,当时原生支持wds的路由还找不到,是买了linksys路由后自己刷ddwrt来做wds,效果很好,一直用到现在。前一阵左岸说无线信号频频出问题,于是重新找方案,最终是用三个TP-LINK WR841N来做wds,效果非常好。这个路由支持802.11N制式,原厂固件就支持wds,而且信号极佳,在京东只卖143元。 在网上找到个不错的教程,按图索骥就把信号覆盖做好了。

Tags:

categories IT

关于贫困线

前几天看到网易的贫困线专题,提到中国政府2009年制定的贫困线是1196元,当时就很好奇这个贫困线能否保证一个人活下去。今天又看到有人在微博提起,,于是花了点时间研究了一下。

一个人在贫困线以上那至少应该有维持生命及基本健康的饮食,那吃什么样的饮食才够呢:

一份资料来自soso

中国营养学会制订的蛋白质膳食供给量,要求成年人每天为70克,补充人的机体蛋白质一天的损耗。70克蛋白质约从200克动物性食物中摄取。
具体的安排:100克畜、禽、鱼、肉类,约60克的蛋,再加上约50克豆制品。
十多岁的青少年,身体生长快,需要更多的食物蛋白质来增强机体组织,孕妇、乳母同样也要增加蛋白质的供给量,一般每天宜在70克的基础上,额外增加20–30克蛋白质,需多进食100–150克肉类,10岁以儿童应相对减少。

一份资料来自百度知道

五谷类(大米、面包、谷粉及粉面类食物,每天约300-500克)蔬菜类(每天约400-500克)水果类(每天约100-200克)奶类及豆类(奶制品每天100克,豆制品每天50克)鱼、禽、肉、蛋(每天125-200克)油脂类(每天不超过25克)

 

综合上面来看,一个成年人需要每天吃300克粮食,肉制品100克,蛋60克,豆制品50克(水果,蔬菜,奶制品等其他食品不算在内)。这几样价格分别为,大米:4元/公斤(来源21food),肉:12元/公斤(按肉中最便宜的鸡肉计算,来源21food),鸡蛋:7.9元/公斤(来源中国鸡蛋网),黄豆:1元/公斤(来源食品产业网)。 据此可以得出,一个人一天至少消费2.9元左右才能维持健康饮食标准,算下来就是一年1058.5元,居然1196元真的是能让人不饿死的。而且不只是不饿死,还多出139.5元去解决一年的住房,医疗,教育,交通,穿衣,以及娱乐等精神食粮。多么仁慈的政府啊,感动的要涕泪横流了。

Tags:

categories 生活

第二次人口普查

敲门声,开门,一位笑盈盈的陌生大姐,拿着一堆表格,问:“上次人口普查后没变化吧?”答:“无。”,大姐:“好,送你一小礼物”。还没来得及说谢谢,大姐已扭头离去。我的第二次人口普查就此结束。

礼物如图

Page 2 of 4512345...102030...Last »