Firefox Java Plugin – Debian Wheezy

By default Firefox has no Java plugin because of security issues.
One can install plugin by following next steps:
0. Exit Firefox browser if it is running
1. Make directory if it does not exist -> /usr/lib/mozilla/plugins
2. Make a symbolic link for libnpjp2.so file which resides in JRE directory, e.g.:

sudo ln -s /usr/lib/jvm/jdk1.8.0_20/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins/libnpjp2.so

Please note, that amd64 is an architecture of the OS you have installed, possibly it could be i386 in your case.
3. Start Firefox and type about:plugins in address box to check if browser able to see Java plugin.

Install proprietary Oracle JDK in Debian 7.0 Wheezy

This is a YAP (yet another post) about how one can manually install Oracle’s proprietary JDK/JRE version (in Debian 7.0 Wheezy as an example).

First of all, download fresh version of JDK/JRE from the Oracle website.
Copy archive to desired location, in the following example we will use

/usr/lib/jvm

as an installation source directory.
Unpack the archive and run next commands:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk/bin/java 1071
sudo update-alternatives --install /usr/bin/javac javac /media/mydisk/jdk/javac 1071
sudo update-alternatives --install /usr/bin/jcontrol jcontrol /media/mydisk/jdk/bin/jcontrol 1071

You may need read man pages for update-alternatives to check out the parameters and what they mean.

Now, if you want freshly installed version of java/javac to be default in your system, run next commands:

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config jcontrol

Follow the instructions issued by update-alternatives to select default version among the list of available installations.
After that, check if everything worked fine by issuing commands

java -version
javac -version

You should see 1.8.0 for both.

Having error while trying use jqFileUpload with RequireJS?

Once upon a time, I needed to use jqFileUPload plugin (actually modified version which provides Angular’s directive around native jqFileUpload plugin).
In the same time, my Angular-base project was configured to be used together with RequireJS.
I spend few ours trying to figure out what I was doing wrong – why I was getting errors in my browser’s console.
Those errors were about something weird… Something in `load-image-exif` and `load-image` files.

My require.js main config file looked like this:

require.config({
  paths: {
    'semantic': '../../bower_components/semantic-ui/build/packaged/javascript/semantic.min',
    'jquery': '../../bower_components/jquery/dist/jquery.min',
    'domReady': '../../bower_components/requirejs-domready/domReady',
    'angular': '../../bower_components/angular/angular.min',
    'angular-route': '../../bower_components/angular-route/angular-route.min',
    'angular-resource': '../../bower_components/angular-resource/angular-resource.min',
    'jquery.fileupload': '../../bower_components/angular-jqfile-upload/js/jquery.fileupload',
    'jquery.fileupload-angular': '../../bower_components/angular-jqfile-upload/js/jquery.fileupload-angular',
    'jquery.ui.widget': '../../bower_components/angular-jqfile-upload/js/vendor/jquery.ui.widget',
    'jquery.fileupload-image': '../../bower_components/angular-jqfile-upload/js/jquery.fileupload-image',
    'jquery.fileupload-process': '../../bower_components/angular-jqfile-upload/js/jquery.fileupload-process',
    'jquery.fileupload-audio': '../../bower_components/angular-jqfile-upload/js/jquery.fileupload-audio',
    'jquery.fileupload-video': '../../bower_components/angular-jqfile-upload/js/jquery.fileupload-video',
    'jquery.fileupload-validate': '../../bower_components/angular-jqfile-upload/js/jquery.fileupload-validate',
    'jquery.fileupload-ui': '../../bower_components/angular-jqfile-upload/js/jquery.fileupload-ui',
    'jquery.iframe-transport': '../../bower_components/angular-jqfile-upload/js/jquery.iframe-transport',
    'canvas-to-blob': '../../bower_components/blueimp-canvas-to-blob/js/canvas-to-blob.min',
    'load-image': '../../bower_components/blueimp-load-image/js/load-image.min',
    'load-image-exif': '../../bower_components/blueimp-load-image/js/load-image-exif',
    'load-image-ios': '../../bower_components/blueimp-load-image/js/load-image-ios',
    'load-image-meta': '../../bower_components/blueimp-load-image/js/load-image-meta',
    'load-image-orientation': '../../bower_components/blueimp-load-image/js/load-image-orientation'
  },
 
  // angular does not support AMD out of the box, put it in shim
  shim: {
	  'semantic': {
		  exports: 'semantic',
		  deps: ['jquery']
	  },
    'angular': {
      exports: 'angular'
    }
  },
 
  // kick start application
  deps: ['./bootstrap']
});

Those errors made me crazy so I even decided to get rid of using RequireJS with Angular app at all!
Next day, I decided Google for a bit and I was extremly lucky to get to this answer – http://stackoverflow.com/a/20734214.
No votes for it, but that is correct answer and helps resolve the issue.

To recall here, the reason is – I used minified version of `load-image` script, which includes all dependencies in it…
So, all I had to do is replace this line with a path to not minified version:

    .....
    'load-image': '../../bower_components/blueimp-load-image/js/load-image<span style="text-decoration: line-through;">.min</span>',
    .....

After had that done everything started up.

Postgres and earthdistance extension

First of all, let me describe how one can install extensions for your Postgresql.
It depends whether you have version 8.4+ or 9.1+ installed.

In following sections I will describe procedure related to Debian based OSes.

First of all, you have to install contrib packages for corresponding version:

root@debian:/home/web# apt-cache search postgres | grep contrib
postgresql-contrib - additional facilities for PostgreSQL (supported version)
postgresql-contrib-8.4 - additional facilities for PostgreSQL
postgresql-contrib-9.1 - additional facilities for PostgreSQL

with command:

apt-get install postgresql-contrib postgresql-contrib-x.y

After that, restart postgresql daemon:

/etc/init.d/postgresql restart

Change to the database owner account, e.g.:

su postgres

Change to the contrib modules’ directory:

cd /usr/share/postgresql/8.4/contrib/

Now, there are 2 different way how you could install extensions for your database.

1. Postgres-8.4.x
Load the SQL files for needed extension using command:

psql -U user_name -d database_name -f module_name.sql

for example,

psql -U postgres -d your_database_name -f cube.sql
psql -U postgres -d your_database_name -f earthdistance.sql

2. Postgres-9.1.x
Extensions are stored under /usr/share/postgresql/9.1/extension directory,
so you need to cd to it:

cd /usr/share/postgresql/9.1/extension

and then launch psql.
In opened database console run this query:

CREATE EXTENSION "cube"; -- you will not be able install "earthdistance" w/o "cube" extension
CREATE EXTENSION "earthdistance"; --or any other extension you need

That is all – you can use installed extension.

Okay, now lets proceed to the main topic of the post.
What is earthdistance?
It is a simplified solution to make calculations over spatial coordinates (latitude, longitude), calculate distance between two points in the Earth.
In case if you do not want install and learn PostGIS extension for the Postgres DB, although that extension provides much more functionality, you can go with earthdistance.
In earthdistance the Earth is treated as an ideal sphere and if it works for you – you don’t have too precise calculations -, then you can earthdistance.
Otherwise you definitely should take a look at PostGIS.

So, here is the main point – what the SQL should look like when you want to search location of some subject based on its coordinates?
Just use such expression in WHERE part of you SQL (for example):

... WHERE earth_box(ll_to_earth({longitude_float_value}, {latitude_float_value}), {radius_in_meters}) @> ll_to_earth(some_table.latitude, some_table.longitude)

of course values in curly braces should be just numbers, no need to put { and } outside.

Install PHP 5.4 from DotDeb

In case if you want have latest php-5.4 both in CLI and with Apache-2.x it is better to install it through apt-get
You need to add these source to sources.list file:

deb http://packages.dotdeb.org squeeze all
deb-src http://packages.dotdeb.org squeeze all
deb http://packages.dotdeb.org squeeze-php54 all
deb-src http://packages.dotdeb.org squeeze-php54 all

If you are getting this error

W: GPG error: http://packages.dotdeb.org stable Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY E9C74FEEA2098A6E
W: GPG error: http://nginx.org squeeze Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62

you need follow such steps:

gpg --keyserver keys.gnupg.net --recv-key 89DF5277
gpg -a --export 89DF5277 | sudo apt-key add -
gpg --keyserver keyserver.ubuntu.com --recv-key ABF5BD827BD9BF62
gpg -a --export ABF5BD827BD9BF62 | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

HowTo Compile and Install php-5.4.x on Debian OS (squeeze)

Recently I was trying install latest PHP 5.4.x (at the moment of writing this is 5.4.10) version on my stable Debian OS (v6.0-squeeze-32bit).
As far as you may know, stable Debian proposes PHP-5.3.4 as latest available release. I wanted to use embedded into PHP-5.4 web-server.
I was thinking that install PHP-5.4 would be faster process then configuring new virtual host in Apache. Yep, lazy me! :-)
Well, spoiling the story, I would like to say, that the overall process took 2-2.5 hours from me before I was able to launch my scripts.
To be honest, that was my first time when I was compiling PHP from source, and I feel I got great experience with that!
But okay, let’s look at the process step-by-step.

First of all, you may need install “libxml2-dev” linux library (don’t remember why, though :-)).
Oh, wait! Looks like it needed for you be able to configure you PHP installator.

sudo apt-get install libxml2-dev

I also believe that most web developers need to use DB with theirs scripts, thus they may need PDO php extension.
So, you need to compile PHP with this directive:

configure --with-pdo-mysql --with-mysql

(see http://php.net/manual/en/ref.pdo-mysql.php for more details)

Usually, good devloper uses debug tools extensively. As we all know most popular PHP debugger is a xdebug.
This package could be installed from pecl repository.
Before asking pecl to install xdebug, make sure you have php5-dev package installed in your system. With that package phpize is being shipped, which is required to install PHP extensions through pecl.
If you don’t have php5-dev install, you are going get this error message:

ERROR: `phpize’ failed

and here is your next command:

sudo apt-get install php5-dev

After that, you will be able install xdebug extension with help of pecl:

sudo pecl install xdebug

Next. Let’s assume you work with not only documents written solely in English, but with some other languages (Italian, Portugeese, Russion, Dutch, etc.)
Also let’s assume you need to handle dates written in non-english format (btw, about that look for my article about how one can handle dates written in languages different from English). php5-intl extension comes to help! Here http://php.net/manual/en/intl.installation.php you will find information how to enable this extension:

configure --enable-intl

If PHP’s configurator shows error message

“configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.”

you need install this Linux package:

apt-get install libicu-dev

These are development files for International Components for Unicode.

Next, it may happen that you need load remote http resources. Usually, that is done with curl (php5-curl).
I was not enable that extension because faced such message:

configure: error: Please reinstall the libcurl distribution

In such case you need install this Linux package:

sudo apt-get install libcurl4-gnutls-dev

(thanks to http://phpconfigure.com/2011/04/configure-error-please-reinstall-the-libcurl-distribution/)

In case if you need to deal with multibyte encodings and use PHP’s functions prefixed with mb_*, you need enable that as well:

configure --with-mbstring

Okay, as I said, after couple hours of fight I was able to finish with this configuration options and directives:

sudo ./configure --with-pdo-mysql --with-mysql --with-curl --enable-intl --enable-mbstring=all

As I said at the beginning, I was hoping that install PHP-5.4 would be faster then configure virtual host. How far away from truth was I!..
But I do not regret about my choice, because now I feel strong in believe that I have mastered some important things and have grown my professional level!

Fell free to add comments and ask things that left unclear for you.

Fn keys stopped work Lenovo on Thinkpad Edge with Debian

Once upon a time ALL functional keys (brightness, volume control, camera, microphone, wi-fi) of my Lenovo Thinkpad Edge 15 suddenly stopped work. I’m not a guru-guy in all that Linux’s low-level bullshit like acpi events, etc. So, I periodically tried to find a solution for the problem in the INet, but having no idea what to search for – I was searching for acpi, fakekeys, Debian (that is the OS installed on my laptop), – I didn’t find any solution. But with help of luck suddenly I discovered one great forum about Ubuntu OS, where there was an unexpected solution of absolutely similar trouble…
Well, all the deal is about BIOS issues on Lenovo Thinkpad Edge!! :(
So far, to restore previous BIOS’s state, all you need is unplug an AC adapter and remove battery for approx. 1 minute or a little bit longer. That is all! Fn keys are work again like a charm!
Thanks to guys who proposed the solution!

Download audio from VKontakte

Here is a tiny helper script allowing to create a list of URLs of mp3 files which then could be fed to smth. like Download Master.
This script need to be launched in Firebug’s console (extention for the FireFox web browser, oriented at programmers) while you are on the “My audio” page of the VK’s web site.
As a result of execution you will get a list of links to audio files of your playlist. Then you just need to copy that list to TXT file after what the file need to be imported into DM through the menu item File -> Import. That is all! Files are being downloaded! The only issue is file name. What you will get is a unique ID and not human-readable title. If you wish you could rename all files manualy, otherwise you could write another script, let’s say using PHP programming language. That script should read ID3 tags of each file and use meaningfull title extracted from the tag as new name for your file.
Well, here is the script, actually:

var hiddenFields = document.getElementsByTagName("input");
var mp3s = [];
function getHiddenField(elem, index, collection){
    if(elem.getAttribute("type") == "hidden" && (/audio_info\d+_\d+/).test(elem.getAttribute("id"))){
        mp3s.push(elem.getAttribute("value").split(",")[0]);
    }
}
for(var i=0; i < hiddenFields.length; i++){
    getHiddenField(hiddenFields[i], i, hiddenFields);
}
console.log(mp3s.join("\n"));

Personal web-developer's site