Blog | Profile | Projects

drapeko

@author drapeko

PHP, Create filesystem hierarchical array

with 2 comments

You have a straightforward list of directories. Your task is to create an hierarchical array of these directories. How can you do it? The simplest way is presented below.

You have an array of directories (straightforward list of directories):


	 $array = array(
		 '/home/drapeko/var',
		 '/home/drapeko/var/y',
		 '/home/drapeko',
		 '/home',
		 '/var/libexec'
	 );

And you would like to transform this array to hierarchy of directories:


 $array = array (
     'home' => array (
         'drapeko' => array (
             'var' => array (
                 'y' => array()
             )
         )
     ),
     'var' => array(
         'libexec' => array()
     )
 );

How can you do it?

First of all the below function will help us.


/**
 * This function converts real filesystem path to the string array representation.
 *
 * for example,
 * '/home/drapeko/var/y   will be converted to  ['home']['drapeko']['var']['y']
 *
 *
 * @param $path 		realpath of the directory
 * @return string		string array representation of the path
 */
function pathToArrayStr($path) {
     $res_path = str_replace(
          array(':/', ':\\', '/', '\\', DIRECTORY_SEPARATOR), '/', $path
     );
     // if the first or last symbol is '/' delete it (e.g. for linux)
     $res_path = preg_replace(array("/^\//", "/\/$/"), '', $res_path);
     // create string
     $res_path = '[\''.str_replace('/', '\'][\'', $res_path).'\']';

     return $res_path;
}

It simply converts the real path of the file to array string representation.

How can you use this function? I know it looks a little bit confusing. But it’s quite simple. Consider the example below:


 $result = array();
 $check = array();
 foreach($array as $val) {
 	$str = pathToArrayStr($val);
 	foreach($check as $ck) {
 		if (strpos($ck, $str) !== false) {
 			continue 2;
 		}
 	}
 	$check[] = $str;
 	eval('$result'.$str.' = array();');
 }
print_r($result);

Heh, how do you find it? This approach has helped me very much. I hope you will find it useful. :)

  • Share/Save/Bookmark

Written by rdrapeko

May 24th, 2009 at 12:53 am

Posted in Posts

Tagged with , , , ,

PHP Intelligencer, tiny autoload framework

without comments

Several months ago I wrote an article that included several interesting examples of __autoload function, some autoloading approaches and a tiny script that is able find interfaces/classes and generate arrays of associations among these classes/interfaces, their locations and extended/included classes/interfaces.

http://wp.drapeko.com/2009/03/28/autoloading-in-php/

I widely use this script and I’ve found it really convenient.  I don’t have to think anymore of how to store my classes, what is the structure of the project etc. All this work is done by this script.

But… I have to launch it manually.

I’ve decided to go further and began to create a tiny framework called Intelligencer. This framework will extend functionality of the autoload generator script.

Some Intelligencers features:

  1. It is very tiny and does not depend on other frameworks and external libraries. It’s very easy to integrate it.
  2. It has an ability to store and control inheritance associations and relations between classes/interfaces and their locations.
  3. If something has changed Intelligencer will automatically regenerate (if necessary) lists of associations. It’s really very useful in the development stage.
  4. Intelligencer has a huge number of config settings. It’s flexible.
  5. Intelligencer supports environments. You can easily create your custom environments and switch between them.
  6. You can create several Intelligencers that will be responsible for different parts of your application.
  7. You can work with Intelligencer both on config level and API level.

If you use it, it will do all work for you. It’s an open source. Location -  sourceforge.

The first release will come very soon.

  • Share/Save/Bookmark

Written by rdrapeko

May 20th, 2009 at 10:37 pm

Google Adsense Appeal letter

with 7 comments

I began to use Google Adsense two months ago. One month ago my account was banned. Unfortunately, the first appeal was unsuccessful and I did not get any explanations.  I don’t know the exact reason why I was banned. It makes me laugh but the number of ‘earned’ money was a little bit more than 10 dollars. But I’m really very interested in good relations with Google, that’s why several days ago I appealed for the second time.

I sent a letter below.

Dear Sir/Madam Appeal

I am writing for the second time regarding these misunderstanding. Your
previous letter made me very unhappy and I didn’t expect such a decision to
be made. I am indeed very interested in cooperation with Google and I am
convinced that there was a misunderstanding.

I claim that I have followed all the terms and conditions and I have not
broken any rules/ In particular, I have not place any forbidden content, I
didn’t click on the banners and I have not incited anybody to click on
them. What if somebody did it on purpose so as to deprive me? In that case
I have absolutely no protection against somebody’s bad intentions. My
account has been active only for a week. Is the statistics gathered during
such a short period of time sufficient to conclude this is indeed me who
tried to cheat Google?

I’d hate to lose the opportunity to work with Google and with AdSense in
particular. I have no intention to create other accounts under a different
name. I am not interested in illegal actions or unfair profit.  I am ready
to uphold my rights and prove that. I would really want to have my account
annulled so as to start building the long-term and trustworthy relations
with Google.

I appeal to Google to reconsider the matter.

I look forward to hearing from you,

Yours faithfully,
Roman

Have you been in a similar situations? What is the result?

P.S. I decided to be independent from one particular adv company. I will try to implement one interesting idea very soon in terms of advertisement. Stay in touch. :)

  • Share/Save/Bookmark

Written by rdrapeko

May 16th, 2009 at 5:46 pm

Posted in Posts

Tagged with , , , ,

Connect remotely to Unix/Linux using SSH with X-Windows support

without comments

Situation: you would like to connect remotely using SSH protocol to Linux/Unix OS from Windows environment and to run remotely a program that uses X-Windows (e.g. Eclipse) .

How can you do it?

  1. Download SSH client. The most popular is free PuTTY client (http://www.chiark.greenend.org.uk/~sgtatham/putty/)
  2. Secondly download and install X-Windows server for your Windows environment. I suggest to use xming (http://sourceforge.net/projects/xming). xming installation tips are available here: http://gears.aset.psu.edu/hpc/guides/xming/
  3. Open Putty, go to Connection->SSH->X11 and enable X11 forwarding
  4. Connect to the remote host and launch the program
  • Share/Save/Bookmark

Written by rdrapeko

May 16th, 2009 at 2:31 pm

Oracle Advanced PL/SQL Developer Certified Professional 1z0-146

with 39 comments

I took Oracle beta 1z1-146 exam in the end of January, 2009. Several days ago I checked prometric.com and discovered that this exam was passed. Now I’m one of the first Oracle Advanced PL/SQL Developer Certified Professional all over the world!!! it’s my second OCP :)

oracle_certprof_clr_rgb

I did not find any dumps, any mock exams or any sample questions, while I was preparing for this exam. I used only these http://rapidshare.com/files/127182353/D52601GC10_netbks.com.rar official Oracle preparation slides (remember to switch comments - it’s a book). 1z1-146 exam was really tough. 165 questions in 180 minutes. Production exam requirements: time - 90 min, questions - 68. There is a difference, is not it?

If you are going to take one of Oracle beta exams and you have time and ability to stay calm, you are not interested to economize some money I suggest waiting for a production one. Pluses: 1) You will probably get results two weeks earlier then beta-takers 2) More time, less questions 3) It’s not so  stressful 4) The probability to pass is much higher.

Do you agree? What is your experience in taking certification exams? :)

  • Share/Save/Bookmark

Written by rdrapeko

April 26th, 2009 at 9:33 pm

Posted in Posts

Tagged with , , , , , ,

How to install Rational Rose on Windows XP Home Edition

with 4 comments

How to install Rational Rose on Windows XP Home Edition?

If you are trying to do it, you probably get the following message:

“We are attempting to install on an unsupported operating system. We recommend that you install on a supported operating system. See your Rational product’s Release Notes for a complete list of supported operating systems and service packs.”

Fortunately, this restriction is artificial one. You can turn it off.

  1. Start -> Run -> cmd
  2. Go to the directory where Rational is installed (example, cd C:/Program Files/Rational)
  3. Find Rose.msi file. Usually it’s located in the SETUP folder. It can be called 1041_Rose.msi or something very similar.
  4. Type msiexec.exe /l*vx inst.log /i Rose.msi /c DISABLE_PLATFORM_BLOCKS=1
  • Share/Save/Bookmark

Written by rdrapeko

April 23rd, 2009 at 10:52 am

Posted in Posts

Tagged with , ,

Looking for a new Job, interesting questions

with one comment

A month ago I relocated to London. And now I’m looking for a job here. The process is quite boring. Agents, sites, applications, cover letters, CVs. And.. unfortunately no visible result yet. But sometimes potential employers ask to do interesting tasks. For example, one of them asked to answer the questions below:

What is your favourite What do you *think* of
  • programming language
  • operating system
  • editor/IDE
  • version control system
  • bug tracking system
  • development tool
  • web site
  • movie
  • record
  • book?
  • XML
  • Web Services
  • Flash
  • Excel
  • AJAX, “web 2.0″
  • the Semantic Web
  • Agile Development
  • UML
  • OO
  • Microsoft
  • Google
  • Apple?

My version could be found below.

Read the rest of this entry »

  • Share/Save/Bookmark

Written by rdrapeko

April 4th, 2009 at 5:59 pm

Autoloading in PHP

with 12 comments

computer_mainHave you ever been faced with autoloading in PHP? Are you a newbie? Do you think you understand the nature of autoloading? This article is for you. This article will take approximately 25-35 min.
This article:

  1. Asks you: what is an autoloading? Do you really understand how __autoload() function works?
  2. Examines several autoloading approches
  3. Suggests a script that scans folders for classes and interfaces and generates array of associations between classes and their locations.

Autoloading/Dependency generator: download (4.6 KB) 07 05 2009 →, description

Examples for this article: download (4.0 KB) →, description ↓

Read the rest of this entry »

  • Share/Save/Bookmark

Written by rdrapeko

March 28th, 2009 at 6:29 am

Promotions (coming soon)