Thursday, February 5, 2015

Notes In Resolving Conflict on GIT Rebase

So after doing git rebase master from a featured branch or some other branch you get a conflict.

Here are some notes on resolving.
  • After getting the conflict, you will be redirected to temporary branch where you have to resolve your conflict.
  • Resolve your conflicts as usual removing <<<<<<, ======, >>>>>>>> and doing your manual merges
  • After resolving do a git add .
  • Do not commit but after doing git add do git rebase --continue or git will complain about having no resolution to your conflict
  • The rebase should go as usual

Tuesday, November 4, 2014

Access SSL Enabled URL via Curl

Sometimes you may have problems accessing URL that are SSL enabled. The solution is to simply set the flags below:


    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
To output and debug the problem you can:
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://temp', 'rw+'));
$result = curl_exec($ch);
curl_close($ch);

if ($result === FALSE) {
    printf("cUrl error (#%d): %s
\n", curl_errno($curlHandle),
           htmlspecialchars(curl_error($curlHandle)));
}

rewind($verbose);
$verboseLog = stream_get_contents($verbose);

print_r($verboseLog);

Monday, April 14, 2014

How to Fix SSHFS Mounts Not Writable by PHP

Problem:
When accessing a php file in the browser that uses is_writable(), is_dir(),... etc of a mounted directory through sshfs, PHP sometimes cannot detect the mounted directory so the functions above always returns false.

1.) Steps to resolve:
$> sudo adduser $USER fuse
$> ls -l /etc/fuse.conf
$> sudo chmod a+r /etc/fuse.conf

2.) Edit fuse.conf and enable user_allow_other
$> sudo vim /etc/fuse.conf

3.) Connect with allow_user
sshfs -o allow_other,uid=1000,gid=33 user@192.168.1.101:/path/to/mounted/mydir mydir

Sunday, January 12, 2014

install fastcgi

sudo apt-get update && sudo apt-get install libapache2-mod-fastcgi sudo a2enmod fastcgi

Monday, January 6, 2014

Composer Update/Install

Dont install require-dev packages (--no-dev), prefer the distribution packages (--prefer-dist), maximum verbosity (-vvv), show profiles such as memory usage and time (--profile)
php composer.phar update --no-dev --prefer-dist -vvv --profile

Tuesday, November 26, 2013

Tip: How to Add Timestamp With CURRENT_DATETIME in Doctrine 2 ORM

Assuming that your database profiler is Mysql:
    /**
     * @ORM\Column(type="datetime", nullable=false)
     * @ORM\Version
     * @var string
     */
    protected $creationTimestamp;

The above declaration should produce:
CREATE TABLE mytable (creationTimestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL);
The trick is adding @Version which converts the type 'datetime' to 'timestamp'. Remember that this is only for MySql profiler.

Wednesday, November 20, 2013

How to use ZF2's Curl Http Adapter with Header information

Just sharing some of my painful WTF experiences using ZF2's Curl Http client adapter so you wont have to deal with my headaches.

Basically I am trying to send a CURL_HTTPHEADER with these params.
This is what it should look like straight php:

$c = curl_init('http://url');
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'Authorization: Bearer 1jo41324knj23o'
));
Simple enough right? Well I was assuming the same thing using ZF2's Curl Adapter:
$client = new Client('http://url');
$client->setMethod('post');

$adapter = new Curl()
$adapter->setCurlOption(CURLOPT_POST, 1);
$adapter->setCurlOption(CURLOPT_POSTFIELDS, $data);
$adapter->setCurlOption(CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'Authorization: Bearer 1jo41324knj23o'
));
Well the thing is this will not work because the headers and data are being set exclusively by write() in the client object as you will see in the source:
// inside Curl::write()
// line 374 Curl.php
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $curlHeaders);

// line 380 Curl.php
if ($method == 'POST') {
    curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
}

// line 398 Curl.php
if (isset($this->config['curloptions'])) ...
    foreach ((array) $this->config['curloptions'] as $k => $v) ...
 
Notice at line 398 that this is where the remaining curl parameters gets set. This means that CURLOPT_HTTPHEADER and CURLOPT_POSTFIELDS have already been defined so our usage from above will not work (Maybe there is a CURL flag to overwrite this, I just don't know at the moment). So how do you make this work? You have to pass your definitions in the Client object:
$client = new Client('http://url');
$client->setMethod('post');
$client->setRawBody($data);
$client->setHeaders(array(
    'Content-Type: application/json',
    'Authorization: Bearer 1jo41324knj23o',
));
$client->setAdapter(new Curl());
$client->send();
Now the write() method will pull from these params when assembled