Not working HTTPS queries with Curl

If you can work with usual http queries using PHP Curl, but have problems with https you can try to include this option:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

Tags: , ,

July 22nd, 2008, posted by Atuk

Converting openssh key from seahorse to putty

If you want to use your key generated in Seahorse in Putty you’ll have to convert it. The process is clear – make export of private key in Seahorse and import it to Puttygen. However one extra step is required – you have to delete everything before —–BEGIN DSA PRIVATE KEY—– mark. Otherwise Puttygen won’t recognise private key.

Tags:

May 31st, 2008, posted by alex

Finding matrix’s max or min element in MatLab

Function max(A) (or min(A)) return a row vector with maximum (minimum) elements from each column of matrix A. If you need to find largest or smallest element in the vhole matrix, you should use max() or min() function once again: max(max(A)) or min(min(A)).

Tags:

May 18th, 2008, posted by Atuk

Prototype.js formElmt.request() and non-valid HTML

Handy and pretty $('myform').request() can be easily broken if you have really broken HTML. For example:

<table>
<form id="myform">
  <input />
  <input />
  <tr><td></td></tr>
</table></form>

$('myform').serialize() will return empty string for such html. As a result you’ll have ajax request with no parameters, obviously not what you’ve expected. Fix html and everything will work.

Tags: , ,

May 16th, 2008, posted by alex

Add font to your system (Windows)

When you working with graphics, for example in Photoshop, you may need to use nonstandart fonts. To add new font you can copy font file to Windows/Fonts directory. You can access it using usual file manager or via Control Panel -> Fonts.

Tags: ,

May 13th, 2008, posted by Atuk

tty’s killed on Ubuntu Hardy Heron VPS

If you’ve upgraded your Ubuntu VPS to 8.04 check your syslog. It could happen that getty processes are being killed all the time:

May  2 06:28:54 vps_server init: tty3 main process (19690) terminated with status 1
May  2 06:28:54 vps_server init: tty3 main process ended, respawning
May  2 06:28:59 vps_server init: tty6 main process (19753) terminated with status 1
May  2 06:28:59 vps_server init: tty6 main process ended, respawning
May  2 06:29:00 vps_server init: tty5 main process (19764) terminated with status 1
May  2 06:29:00 vps_server init: tty5 main process ended, respawning
May  2 06:29:00 vps_server init: tty1 main process (19772) terminated with status 1
May  2 06:29:00 vps_server init: tty1 main process ended, respawning
May  2 06:29:02 vps_server init: tty4 main process (19891) terminated with status 1
May  2 06:29:02 vps_server init: tty4 main process ended, respawning
May  2 06:29:02 vps_server init: tty2 main process (19892) terminated with status 1
May  2 06:29:02 vps_server init: tty2 main process ended, respawning
...

To get rid of this (you don’t need terminals on remote machine) edit files /etc/event.d/tty1, /etc/event.d/tty2, etc and comment lines that causes respawning:

respawn
exec /sbin/getty 38400 tty1

Tags: , , ,

May 9th, 2008, posted by alex

Tracking deployed svn revision

Sometimes it’s useful to know which subversion revision is installed on your website.

I propose simple solution for this. Each time you or somebody update your website, run the command:

svnversion /path/to/your/working/copy > version && scp version login@domain.tld:./version

It will get global revision from your working copy and uploads a file to website, so you can check revision anytime just by opening http://domain.tld/version

Tags:

April 5th, 2008, posted by alex

Exclude WordPress admin from AWStats statistics

This is dead easy, in AWStats config set parameter

SkipFiles="REGEX[^\/wp-admin]"

All newly parsed statistics won’t include admin.

Tags: ,

April 2nd, 2008, posted by alex

URL file-access problems in PHP

For many hosting providers it’s standart to disable URL file access. So, if your PHP code has file_get_contents(), require(), require_once(), include() or include_once() commands with some URL as a parameter, you will receive an error message: ‘URL file-access is disabled in the server configuration’.

To avoid this error you can try to use CURL.

Instead of this command:

$content = file_get_contents('http://sample_url');

You should use:

$ch = curl_init();
$timeout = 3;
curl_setopt ($ch, CURLOPT_URL, 'http://sample_url');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$content = curl_exec($ch);
curl_close($ch);

Tags: ,

March 30th, 2008, posted by Atuk

Distance measurement between two locations on Earth in MatLab

Suppose, you need to calculate distance between two locations on Earth in kilometers. And suppose you know their geographical coordinates, i.e. [latitude, longitude]. In MatLab there is a function distance(lat1, lon1, lat2, lon2). It calculates distance between two points in angle units (in degrees there). So, you can calculate distance between two objects in angle units. Next you should to convert angle units into kilometers. Use for this distdim(angle,’deg’,'kilometers’) function.

For example you need to find distance between Minsk, Belarus (53.9, 27,5667 [53° 54′ 0″ N, 27° 34′ 0″ E]) and Caracas, Venezuela (10.5207, -66.9245 in [10° 31′ 14.52″ N, 66° 55′ 28.2″ W]).

Type:

>> distdim(distance(53.9, 27.5667, 10.5207, -66.9245),'deg','kilometers')

Result will be 9355.484 kilometers.

Tags: ,

March 19th, 2008, posted by Atuk