跳至主要内容

博文

目前显示的是 八月, 2012的博文

ssh 不用密码

http://www.linuxproblem.org/art_9.html 这篇文章有详细解释。 具体: ssh-keygen -t rsa ssh b@B mkdir -p .ssh (这个一般都有了) cat .ssh/id_rsa.pub | ssh mathieu@192.168.1.52 'cat >> .ssh/authorized_keys' 然后就ok了。

how to show the performance of php symfony, twig.

First , you need add this in app_dev.php, at the begining. $GLOBALS['PerformanceTwigExtensionMicrotime'] = microtime(true); in php, we need to create a twig extension service: class PerformanceTwigExtension extends \Twig_Extension { public function getFunctions() { return array( 'performance_exectime' => new \Twig_Function_Method($this, 'getExecTime') ); } public function getExecTime() { if (!isset($GLOBALS['PerformanceTwigExtensionMicrotime'])) { return 0; } $durationInMilliseconds = (microtime(true) - $GLOBALS['PerformanceTwigExtensionMicrotime']) * 1000; return number_format($durationInMilliseconds, 3, '.', ''); } public function getName() { return "performance_extension"; } } And another normal service for controller: class Performance { private $execTimeArray; public function __con

msyql dump 的问题

mysql dump 在dos下生成的文件在linux下会出错,所以最好用phpmyadmin来做这个,好像两边都可以用。 错误是: Can't create table 'bannieres.acl_entries' (errno : 150) 等等,或者干脆就啥也不干。

如何在twig 中显示 执行时间

I created a new file performance.php in the web folder which looks like this: php /**  * This file is only used for doing realtime performance measurement  * Right now only the microtime is calculated, but in the future the  * xhproof module could be used: http://de2.php.net/manual/en/book.xhprof.php  *  * MAKE SURE TO NOT USE THIS FILE IN PRODUCTION FOR OTHER STUFF THAN REAL TIME  * PERFORMANCE MEASUREMENT  */ $GLOBALS [ 'PerformanceTwigExtensionMicrotime' ] = microtime ( true ); require_once __DIR__ . '/app.php' ; I also registered a twig extension which uses the global and calculates the elapsed time: php namespace Acme \ DemoBundle \ Extension ; class PerformanceTwigExtension extends \ Twig_Extension {     public function getFunctions () {         return array (             'performance_exectime' => new \ Twig_Function_Method ( $this , 'getExecTime' )         );     }     public function getExecTime () {    

inject a service in a twig extesion.

I would advise creating a general service and injecting it to the Twig extension. The extension would act just as a wrapper to the service. namespace Acme \ Bundle \ DemoBundle \...; class MyService {     public function myFunc ( $foo , $bar )     {         // some code...     }     // additional methods... } namespace Acme \ Bundle \ DemoBundle \ Twig \ Extension ; class MyTwigExtension extends \ Twig_Extension {     protected $service ;     public function __construct ( MyService $service )     {         $this -> service = $service ;     }     public function getFunctions ()     {         return array (             'myTwigFunction' => new \ Twig_Function_Method ( $this -> service , 'myFunc' ),             'mySecondFunc'   => new \ Twig_Function_Method ( $this -> service , 'mySecondFunc' ),         );     } } 不过我并不确定这个 twig_function_method 返回的数组到底怎么用。

如何在form 里获得 entity

To access your entity from your FormView in a twig template you can use the following code {{ form.get('value') }} Where form is your FormView object. This will return your entity and from there you can call any methods on it. If you embed a collection of entities or a single entity in your form you can access it the same way {{ form.someembedform.get('value') }} or {% for obj in form.mycollection %} {{ obj.get('value').someMethod }} {% endif %}

doctrine 一次insert 或者操作大量 record

http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/batch-processing.html#batch-processing 我的例子: $cities=Array(); $cities=Array(); $em = $this->getDoctrine()->getEntityManager(); $qb=$em->getRepository('AcmeBannieresBundle:TVille')->createQueryBuilder('tv'); //$cities=$qb->getQuery()->execute(); $iterableResult =$qb->getQuery()->iterate(); $j=0; while (($row = $iterableResult->next()) !== false) { $city=$row[0]; //$city=new TVille(); for ($p=1;$p++;$p<9){ $banner=new BannerCity(); $banner->setCity($city); $banner->setPosition($p); //$city->addBannerCity($banner); $em->persist($banner); } //$em->persist($city); $j++; if ($j>100){ $em->flush(); $em->clear(); // Detache

install apc

apt-get update apt-get install libpcre3-dev #an APC dependency apt-get install php5-cli apt-get install php5-dev wget http://pear.php.net/go-pear.phar #downloading pear, the php package manager php go-pear.phar #installing pear pecl install apc vim /etc/php5/apache2/php.ini #edit your php.ini and add extension=apc.so /etc/init.d/apache2 restart #restart apache to reload your php.ini file

update error

命令行升级ubuntu; apt-get update  sudo apt-get upgrade 如果遇到什么server 的错误,可以在此更改update server list: /etc/apt/sources.list

stop mysqlserver

Stopping MySQL database server : mysqld failed ! dimanche 14 juin 2009 ,  par  Sebastien Le Lourec Vous pouvez rencontrer ce problème soit en tentant de faire un stop/start manuel de votre serveur mysql, soit en essayant de faire une mise à jour via apt-get. Cet article commençait à prendre un peu la poussière en attente de finition... Je ne me souviens plus trop du contexte exact. Je crois que je voulais faire une mise à jour via apt-get. La solution : En tant que root, allez voir dans  /etc/mysql/debian.cnf  le mot de passe correspondant à  debian-sys-maint . Une fois que c’est fait, tapez : # mysql -u root -p puis une fois sur l’invite mysql : mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'votre_mot_de_passe' WITH GRANT OPTION; en y mettant bien sûr le mot de passe trouvé dans debian.cnf. Coffee time.  但这只是一种可能,还有一种可能是装了upstart: http://upstart.ubuntu.com/cookbook/#system-job 这种情况想要stop一个程序

How to switch from GUI to console mode,不要gui boot ubuntu

转载至: http://askubuntu.com/questions/79033/how-to-switch-from-gui-to-console-mode  you can do it by editing the grub file found in the path /etc/default/ #vim /etc/default/grub look for: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" change to: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash text" then save the file. After saving the file update the grub. #sudo update-grub Once updated, restart the machine it will automcaitaclly boot in console mode. To switch over the GUI execute #startx

如果丢失root 密码或者 错误的删除/etc/group

Reset the root password on a linux box Intro The following steps were used to successfully reset the root password of a "Fedora 10" machine. In general, can be applied to any linux machine. GRUB While booting, after the initial splash and POST screen of the bios, the control transfers to GRUB. If there is just one linux operating system installed, the GRUB screen is bypassed to the booting screen, in that case just keep on pressing or tapping the ESC Button until you see the GRUB Menu. Edit  Choose the OS you want to boot into and press "e" to edit. Edit  Find the line that corresponds to  kernel , and again press "e". Add the following line to the end of the line. single init=/bin/bash Then press enter, and then "b" to boot the OS. After booting you will get a root shell. Mounting the filesystem in readwrite mode : Type in the following command to remount the filesystem in read write mode. mount -o remount,rw / Not doing this

mysql dump restore 的问题

Duplicate entry '20' for key 'PRIMARY' mysql 因为dump以后是creat schema,导致的 改成 drop database if exists banniers; CREATE database IF NOT EXISTS `bannieres` DEFAULT CHARACTER SET utf8 ; USE `bannieres` ; 就没问题了。

enable gzip

转载: http://dnhome.wordpress.com/2011/10/06/apache-wampserver-enable-compression-gzip/ Apache – WampServer – enable compression gzip Posted: October 6, 2011 in  Apache ,  WAMP 1 Compression is a simple and effective way to speed up your site. Modern browsers supports gzip compressed content and are capable of uncompressing gzip data into plain text. If you use  WAMP  ( www.wampserver.com ) to develop websites on a local PC, then you probably don’t need to enable gzip (server-side file compression to reduce the amount of data transferred when a web page is requested). Enabling gzip on  WAMP  is actually quite easy, though most of the advice I found was wrong. Here’s what worked for me. 1. Enable Apache module to support gzip, you much enable two module:  deflate_module  and  headers_module  2. Config file type to support gzip on WAMP Server. Open the Apache’s httpd.conf and add the following code at the end of file. AddOutputFilterByType DEFLATE text/html text/plain

Single Sign On (sso)

Well, let me explain a bit further then. (All URLs are fictional!) As I said, the visitor goes to http://www.yourwebpage.com  and indicates he wants to log in. He is redirected to http://your.loginpage.org?return=http://www.yourwebpage.com/Authenticated  where he will have to provide his username and password. When his account information is valid, he will return to the page that was provided in the login URL, but with an additional parameter that will be used as ID. Thus, he goes to http://www.yourwebpage.com/Authenticated?ID=SharedSecret  where SharedSecret would be a temporary ID, valid for 30 seconds or less. When your authentication page gets called, the page would then call a method that's shared between yourwebpage.com and loginpage.org to look for the account information of SharedSecret to retrieve a more permanent ID. This permanent ID is stored in the web session of yourwebpage.com and should NEVER be shown to the user. The shared method could be anything. If both serv

one to many 或者many to many 的 eager fetch

如果你想不要让doctrine 为每一个related one to many 或者many to many 生成一个sql的话,只能直接写DQL 比如: $qb=$em->getRepository('AcmeBannieresBundle:TVille')->createQueryBuilder('tv'); $qb->leftJoin('tv.codep', 'cp') ->leftJoin('tv.departement', 'dep') ->where('dep.code = :codep') ->setParameter('codep', $codep); $cities=$qb->getQuery()->execute(); 是不行的,每次你要读codep的时候它都要query一把,dql可以解决这一点: $query=$em->createQuery('SELECT tv,cp FROM AcmeBannieresBundle:TVille tv LEFT JOIN tv.codep cp LEFT JOIN tv.departement dep WHERE dep.code= :codep') ->setParameter('codep', $codep); $cities=$query->getResult(); 这个就只执行一个sql。

jquery datatable:

如果你的th和td是不一致的话,会导致 oCol is undefined: oCol.fnSetData( oData, val ); 之类的错误。 另外一篇文章说:                 $ ( "#tRes" ). dataTable ({                         "bPaginate" : true ,                         "bLengthChange" : true ,                         "bFilter" : true ,                         "bSort" : true ,                         "bInfo" : true ,                         "bAutoWidth" : true ,                       "aoColumns" : [                                         null ,                                         null //put as many null values as your columns                     ]                     }); 这个也是一个原因。