Friday, April 11, 2014

CentOS: Compiling and Installing PHP Imagick extension

Requirements

This extension requires ImageMagick version 6.2.4+ and PHP 5.1.3+. Package information is here, Imagick package on PECL

The normal procedure goes like this

    wget http://pear.php.net/go-pear.phar
    php go-pear.phar
    pecl install imagick

While it throws the following error,

    No releases available for package "pecl.php.net/imagick"
    install failed

So I decided to compile directly from source (in order to generate imagick.so)

    yum install php-pear php-devel
    yum install ImageMagick ImageMagick-devel
    yum install pcre-devel
    wget http://pecl.php.net/get/imagick-3.2.0RC1.tgz
    tar -xvf imagick-3.2.0RC1.tgz
    cd imagick-3.2.0RC1/
    phpize
    ./configure
    make
    make test
    make install

Remember to turn on the extension in the php configuration file.

    vim /etc/php.ini
        extension = imagick.so

References

Sunday, April 6, 2014

PHP: Get Token From Dropbox

Just use Dropbox for serving the files/pictures of your personal site or startup site, for free use, there is up to 16 GB maximum capacity, far enough to carry out your idea.

First off, we will sign up for Dropbox, start a application that uses Core API. This will give you the key and secret. Prepare it in a file named config.json.

{
  "key": "your-dropbox-api-key",
  "secret": "your-dropbox-api-secret"
}

Download you PHP sdks from here: https://www.dropbox.com/developers/core/sdks/php. Unzip and put in your project directory.

Prepare you getdbxtoken.php as following, this will load dropbox php library along with you config in the previous json file.

<?php
require_once "dropbox-php-sdk-1.1.3/lib/Dropbox/autoload.php";
use \Dropbox as dbx;

        $appInfo = dbx\AppInfo::loadFromJsonFile("config.json");
        $webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
        $authorizeUrl = $webAuth->start();
        echo "1. Go to: " . $authorizeUrl . "\n";
        echo "2. Click \"Allow\" (you might have to log in first).\n";
        echo "3. Copy the authorization code.\n";
        $authCode = \trim(\readline("Enter the authorization code here: "));

        list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
        print "Access Token: " . $accessToken . "\n";

        $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
        $accountInfo = $dbxClient->getAccountInfo();
        print_r($accountInfo);

?>

Run the script from command line:

chmod a+x getdbxtoken.php
php -q getdbxtoken.php

You will need to input auth code in order to get the token, which is obtained by following the link and give the allow permission (go to the brower and [login in] and grant that). While you get that auth code, copy it to your command line, press enter. It will throw you the access token. In consequence, we tried to open a new client and fetch the account info, which is returned as an array, printed to your screen later.

1. Go to: https://www.dropbox.com/1/oauth2/authorize?locale=&client_id=SOME_CLIEND_ID&response_type=code
2. Click "Allow" (you might have to log in first).
3. Copy the authorization code.
Enter the authorization code here: 

To note once obtained the token, you might want to save it to a secure place since you don't need to log in (auth) again. Next time you can just build client by the token, and connect directly to dropbox.

Sunday, March 23, 2014

Ubuntu: Compile Hylafax 6.0.6 From Source

Let's do it all in the terminal.

wget ftp://ftp.hylafax.org/source/hylafax-6.0.6.tar.gz
tar -xvf hylafax-6.0.6.tar.gz
cd hylafax-6.0.6/
sudo apt-get install g++
sudo apt-get install libtiff4 libtiff4-dev libtiff-tools
./configure
make
sudo make install

Note at the configuration stage, some confirmations will pop out, such as

HylaFAX configuration parameters (part 1 of 2) are:

[ 1] Directory for applications:        /usr/local/bin
[ 2] Directory for lib data files:      /usr/local/lib/fax
[ 3] Directory for lib executables:     /usr/local/sbin
[ 4] Directory for system apps:   /usr/local/sbin
[ 5] Directory for manual pages:        /usr/local/man
[ 7] Directory for spooling:            /var/spool/hylafax
[ 8] Directory for uucp lock files:     /var/lock
[ 9] Uucp lock file scheme:             ascii
[10] PostScript imager package:         gs
[11] PostScript imager program:         /usr/bin/gs
[12] Manual page installation scheme:   bsd-source-cat
[13] Default page size:                 North American Letter
[14] Default vertical res (lpi):        98
HylaFAX configuration parameters (part 2 of 2) are:

[15] Location of getty program:         /sbin/agetty
[16] Location of voice getty program:   /bin/vgetty
[17] Location of sendmail program:      /usr/lib/sendmail
[18] Location of TIFF tools:            /usr/bin
[19] Location of SysV init scripts: /etc/init.d
[20] Location of SysV start scripts: ../rc2.d ../rc3.d ../rc4.d ../rc5.d
[21] Location of SysV stop scripts: ../rc0.d ../rc1.d ../rc6.d
[22] Name of SysV start script:  S97hylafax
[23] Name of SysV stop script:  K05hylafax
[24] Init script starts faxq:  yes
[25] Init script starts hfaxd  yes
[26] Start paging protocol:  no

Ubuntu 12.04: Change Default Chinese Font to WenQuanYi Micro Hei

sudo vi /etc/fonts/conf.avail/69-language-selector-zh-cn.conf

This is a fall-back list of font settings for zh-cn language. First two are for western characters. The bolded line shows the change.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

 <match target="pattern">
  <test qual="any" name="family">
   <string>serif</string>
  </test>
  <edit name="family" mode="prepend" binding="strong">
   <string>DejaVu Serif</string>
   <string>Bitstream Vera Serif</string>
   <string>WenQuanYi Micro Hei</string>
   <string>HYSong</string>
   <string>AR PL UMing CN</string>
   <string>AR PL UMing HK</string>
   <string>AR PL ShanHeiSun Uni</string>
   <string>AR PL New Sung</string>
   <string>WenQuanYi Bitmap Song</string>
   <string>AR PL UKai CN</string>
   <string>AR PL ZenKai Uni</string>
  </edit>
 </match> 
 <match target="pattern">
  <test qual="any" name="family">
   <string>sans-serif</string>
  </test>
  <edit name="family" mode="prepend" binding="strong">
   <string>DejaVu Sans</string>
   <string>Bitstream Vera Sans</string>
   <string>WenQuanYi Micro Hei</string>
   <string>WenQuanYi Zen Hei</string>
   <string>Droid Sans Fallback</string>
   <string>HYSong</string>
   <string>AR PL UMing CN</string>
   <string>AR PL UMing HK</string>
   <string>AR PL ShanHeiSun Uni</string>
   <string>AR PL New Sung</string>
   <string>AR PL UKai CN</string>
   <string>AR PL ZenKai Uni</string>
  </edit>
 </match> 
 <match target="pattern">
  <test qual="any" name="family">
   <string>monospace</string>
  </test>
  <edit name="family" mode="prepend" binding="strong">
   <string>DejaVu Sans Mono</string>
   <string>Bitstream Vera Sans Mono</string>
   <string>WenQuanYi Micro Hei Mono</string>
   <string>WenQuanYi Zen Hei Mono</string>
   <string>Droid Sans Fallback</string>
   <string>HYSong</string>
   <string>AR PL UMing CN</string>
   <string>AR PL UMing HK</string>
   <string>AR PL ShanHeiSun Uni</string>
   <string>AR PL New Sung</string>
   <string>AR PL UKai CN</string>
   <string>AR PL ZenKai Uni</string>
  </edit>
 </match> 

</fontconfig>

Sunday, January 19, 2014

mono: Running C#, ASP.NET under Ubuntu

Mono is not monotone at all, it makes Microsoft-centered technologies available on various platforms including Ubuntu. Mine is 12.04.

sudo apt-get install mono-devel mono-gmcs gtk-sharp2 

Compile and execute

Fetch the example files at Console helloword program

gmcs hello.cs
mono hello.exe

Compile and execute gtk program

Source Here

dmcs hello-gtk.cs -pkg:gtk-sharp-2.0
mono hello-gtk.exe

Install ASP server xsp2 and start server

sudo apt-get install mono-xsp2 asp.net-examples
xsp2

When server is on, it gives

Listening on address: 0.0.0.0
Root directory: /home/user
Listening on port: 8080 (non-secure)
Hit Return to stop the server.

Now you can visit your .aspx files under http://localhost:8080/yourfile.aspx

Monday, January 6, 2014

Update to Banshee 2.6

sudo add-apt-repository ppa:banshee-team/ppa
sudo apt-get update
sudo apt-get install banshee

Friday, January 3, 2014

Ubuntu: Burn Fedora ISO to USB Stick

For a complete burning techniques, refer Fedora: How to Create and Use Live USB

Startup disk creator only works for Ubuntu ISOs.

Use Disk Utility to get know of where your usb is mounted. In my case, it is /dev/sdc, and the name of downloaded Fedora iso file is there in the command line.

sudo dd bs=4M if=Fedora-Live-Desktop-x86_64-19-1.iso of=/dev/sdc

Note that dd is in bs mode, which means it write in BYTES at a time.

Aside (From USB img to HD)

dd can also copy iso image from USB to your hard disk:

sudo dd if=/dev/sdb of=usb-image.iso