Lewati navigasi

To reduce the number of blogs that I have to maintain, I’m deciding to move back all technical stuffs to my min blog petrabarus.net.

Just share a bit. When we want to commit source code, it’s better to check locally before pushing the source code to repository which then check them at the build server.

Here’s a source code for the wrapper script. The needed binaries are PHPCS, ESLint, and Stylelint.

To execute in the pre-commit, you can just use this.

SOURCE_FILES=${SOURCE_FILES:-`git diff-index --name-only --diff-filter=ACMR HEAD`}

exit $?

This was just an idea popped up when I had trouble sleeping last night. Basically we can use Thrift for defining the data and service going in and out Lambda service instead of plain REST API.

Below is the code for the server. To make it easier to deploy I am using Serverless Framework.

This is still lack authentication process whatsoever so I don’t think this should be use in production until I figure it out.

The full source code is hosted here: https://github.com/petrabarus/aws-lambda-thrift-example

Putting this here too (I’m in habit for putting scripts into blog).

Just drop this again..

at first I’m using awk, but turns out there is pr command.

Source: Stackoverflow.

Just dropping by here

Just met a problem when I tried to serialize a PHP DateInterval object in HHVM (at least for 3.9.1). Turns out the DateInterval is unserializable. Create a bit workaround for this.


$dateinterval1 = new DateInterval('PT1H');
$baseDate = new DateTimeImmutable();
$date1 = $baseDate->add($dateinterval1);
$string1 = $dateinterval1->format('%y years %m months %d days %h hours %i minutes %s seconds');

$dateinterval2 = DateInterval::createFromDateString($string1);
$date2 = $baseDate->add($dateinterval2);

$string2 = $dateinterval2->format('%y years %m months %d days %h hours %i minutes %s seconds');
if ($string1 == $string2) {
    print "Formats are equal\n";
if ($date1 == $date2) {
    print "Objects are equal\n";
if ($date1->getTimestamp() == $date2->getTimestamp()) {
    print "Timestamp are equal\n";

The test can be seen here: https://3v4l.org/HvLFP

Usually before committing a file we need to check modified files against the code convention before committing to the code repository.

Here’s a single line to run modified files in Git against PHPCS.

git ls-files -m | grep '\.php$' | xargs ./vendor/bin/phpcs -s --standard=etc/phpcs/ruleset.xml

Code above assumes you install PHPCS using composer and have your own standard located in the etc/phpcs/ruleset.xml.


To check all uncommited files, run this

git ls-files --others --exclude-standard | grep '\.php$' | xargs ./vendor/bin/phpcs -s --standard=etc/phpcs/ruleset.xml

I just watched The Last: Naruto The Movie a couple of days ago and I recalled that it’s been almost a quarter of decade since I last read the mangascan.

Reading Naruto in Kindle

Reading Naruto in Kindle

So I got a complete 2GB of mangascan pictures from my friend from volume 1 until volume 72. I’ve been a fan of Kindle e-book reader and I want to read the mangascan in my Kindle device. Here’s how I converted the PNG and JPG files to PDF so it can be readable in Kindle.

Basically what I need is imagemagick library to convert the images to PDF. Here is how to use the imagemagick to do the conversion.

As long as the JPG/PNG files is named with proper file naming, doing a batch conversion in zipped files is as simple as this. It shouldn’t take too long to convert all of the images to PDF. In my case it took less than an hour. The quality of the PDF is not that bad, but I think we can configure the imagemagick to increase the quality. I assume it reduces the quality by a bit.

for zipfile in $(find . -type f -iname &quot;*.zip&quot; | sort -n); do
    echo &quot;$zipfile&quot;
    filename=$(basename &quot;$zipfile&quot;)
    echo &quot;$filename&quot;
    unzip $zipfile -d $filename
    echo &quot;Converting....&quot;
    find $filename | sort -n | tr '\n' ' ' | sed &quot;s/$/\ ${filename}.pdf/&quot; | xargs convert -verbose

See? Pretty simple, right? (The fact that it’s really simple is why I posted here. Might be useful for me in the future).

To accept Angular $http.post that is formatted as JSON in Yii2, just set this in the Yii2 application component.

        'request' => [
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',

To use the data, don’t use global $_POST. Instead use

$data = Yii::$app->getRequest->post();
%d blogger menyukai ini: