Archive for the ‘development’ Category

Prototype styled Google Analytics javascript snippet

Monday, August 11th, 2008

Recently I’ve created a prototype styled javascript snippet to enable google analytics on one of my sites. Save this code in google.analytics.js file and include it from the head tag of the page just after including of the prototype.js:

gaTrackerId = 'ss-ddddddd-d'; // insert your tracker id here

document.observe('dom:loaded', function() {
var gaJsHost = (
('https:' == document.location.protocol)
? 'https://ssl.'
: 'http://www.'
) + 'google-analytics.com/ga.js';
var script = new Element('script', { 'src': gaJsHost});
var gaTrack = function() {
if (
!script.readyState
|| /loaded|complete/.test(script.readyState)
) {
var pageTracker = _gat._getTracker(gaTrackerId);
pageTracker._trackPageview();
}
};
script.observe('load', gaTrack);
script.observe('readystatechange', gaTrack);
document.body.appendChild(script);
});

Copying nodes between XML documents with Java DOM

Thursday, June 26th, 2008

Today I had an atomic task of creating a most convenient way to copy nodes from one XML document to another with Java’s DOM implementation. Googling did not help me much in it, so I will share the solution here in case someone would be challenged too.

So, imagine you have multiple XML documents like this:

<document><section><node attribute="value" /></section></document>

…, another one like this:

<storage><sections /></storage>

… and you wish to read the multilple documents and to put the <section> nodes into the <sections> node of the second one respecting all the structure.

To do that you should:

1. Create the XML document builder:

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

2. Get the <sections> node of the target file:

File target;
Document targetDom = builder.parse(new InputSource(new FileReader(target));
Node targetSections = targetDom.getElementsByTagName("sections").item(0);
// TODO this is not the best way to use that.
// I advice XPath instead.

3. Iterate over the source files and get the <section> nodes:

File[] sources;
for (File source : sources) {
Node sourceSection = builder.parse(new InputSource(new FileReader(source))
.getElementsByTagName("section").item(0);
// [continued inside]
}

4. Copy the node into the target document:

targetDom.appendChild(targetDom.adoptNode(section.cloneNode(true)));
// 'true' means we want to clone children too

5. Write the target back to the file:

TransformerFactory.newInstance().newTransformer().transform(new DOMSource(targetDom)
, new StreamResult(new FileWriter(target)));

That’s it. Note, this code lacks error handling and probably won’t work directly after copy-paste, but just shows you the usage of the classes.

Why Eclipse Equinox P2 Update Manager is not good enough for me yet

Friday, May 16th, 2008

As you all know in Eclipse 3.4 there is a new Update Manager (more correctly - Plug-in Manager) which is intended to be better.

The update managing side of it is an improvement indeed. But the first thing raised my alertness is there is no place to point where do I want my selected plug-ins to be installed. Well, I thought it’s just a default selection and manually downloaded the plug-ins and dropped them into the famous dropins directory (of course with keeping directory structure). And then after restarting eclipse I discovered that there is no such a thing like hierarchy of plug-ins and plug-in locations at all. That’s too bad.

Now, let’s say you installed all the plug-ins. Then if you want to update them, you don’t have a overall progress bar. And this is a network connection related progress. Isn’t it stupid?

Another glitch: My wireless connection to my neighbor’s hub suddenly aborted. So what does it do? It shows me an error dialog behind the modal dialog of progress information. I’m not even mentioning that there is no retry/ignore options.

Now they say: you can replace the new p2 with the good old Update Manager. But for that you must restore several configuration files from 3.3.2. I understand, this is my stupid mistake that I first completely destroyed my previous installation (I can allow it to myself at home), but it’s still annoying.

Working with Eclipse on two displays - Picture

Tuesday, April 1st, 2008

As I mentioned previously, recently I started to work on two monitors. Here comes the picture (sorry for the bad quality):

Working with Eclipse on two displays

Saturday, March 22nd, 2008

Several days ago I was given an additional monitor, and the question of “how to arrange Eclipse view on two displays” was raised. After several tests I made the conclusion that the best way is to stay with my default preferred arrangement, with single difference - to detach and move all the non-editor views to the secondary screen. It frees up editor area and at the same time does not require re-adopting new layout.

The bad news is Eclipse rejects to start up when UltraMon is running.

Nice Diagram Editor - yWorks’ yEd

Thursday, February 21st, 2008

Today I felt need in simple diagram editor in order to draw a comprehensive flow-chart diagram.

Previously I widely used Dia one, but it was always to painful to achieve acceptable with no constant mistakes and overall creation always took too long.

In the past I also several times evaluated Enterprise Architect, Visio and SmartDraw, but they were too heavy, not only from the package size and memory usage view, but also they required too much time to get used to them, and time is the most expensive resource, as you know.

So, today I’ve restarted the process of finding a simple and good diagram editor, and surprisingly, the first try give me the one, which caused me to stop immediately.

I won’t list here all yWorksyEd’s features and won’t compare it to anything else - Just try it, and I promise: you will be happy. The only thing to add is it’s very fast and light, despite the fact it’s java based.

Java Code Structure and Dependencies Analysis Tools for Eclipse

Friday, February 1st, 2008

One of my first assignments at the new company (remember, I left Zend previous week), was analysing existing projects structure. Which means distribution of classes into packages, package dependencies, libraries usage etc.

The results, I would say, were far from being perfect, but I can bet, most of large (and especially proprietary) projects would look similar or even worse. But this is not what I was going to say.

What I am going to say, is for this purpose I evaluated several analysis tools and I want to share my opinion about them.

Here they are (in order of evaluation).

1. Eclipse Metrics(1) (CPL)

Pros: Runs fast, provides tangle detector.

Cons: Dependencies graph is not usable with large projects. No text output of dependencies is available.

2. Eclipse Metrics(2) (CPL)

Pros: no.

Cons: Does not analyze dependencies.

2. JDepend

Pros: Nice and simple UI, fast analysis.

Cons: Provides neither graph nor detailed dependency cycles information, doesn’t provide links to source.

3. eDepend (Commercial)

Pros: Fully featured graphic dependency analyzer, allows filtering on dependency kind

Cons: Commercial, creates disproportedly wide graphs for large projects that are hard to maintain, very slow analyzing and graph creation, doesn’t provide info on elements which depend on selected element.

4. stan4j (Free Beta)

Pros: Fully featured graphic dependency analyzer, very cute GEF based UI, cycles and tangles visualizer, very convenient eclipse integration, report/graphics export ability.

Cons: Does not provide recursive dependency paths on selected elements, does not provide inter-package class dependencies information, non graphical views improvement is suggested.

Conclusion

In the end, in order to perform my task I’ve mostly used stan4j, sometimes switched to eDepend and once or twice times executed JDepend - each of them has its specific advantages.

Zend Studio for Eclipse Release & cetera

Tuesday, January 22nd, 2008

Dear diary,

I have 2 news for you today.

  1. Today we successfully released Zend Studio for Eclipse. My contribution to it, beyond PDT commitments, is Sebastian Bergmann’s PHPUnit testing framework integration plug-in, File Network support, Organize Includes and other parts of Refactoring engine, Code Coverage browser… well, it seems that’s it. Maybe several additional, but minor things. Enjoy, guys. This is really a great (and some say - the best) PHP IDE.
  2. Occasionally, these are my last days at Zend Technologies. Since next week I’m starting at Nielsen Online (BuzzMetrics) to do text-mining. If you ask why, the answer is simple - I got bored of Zend, where I spent last 6.5 years of my life, and wanted to do something really new and exciting. I hope it will work :) For now I’m planning to stay an Eclipse committer and continue to help my brothers at Zend to move on.

Source

Dependency Injections in Java 5

Saturday, December 22nd, 2007

Recently I’ve discovered a new “framework” which simplifies dependency injections in Java 5. It’s called Guice.

Well, what can I say. It indeed has sence. But what I’m wandering of is you need a framework for this thing. In PHP you can solve the problem in exactly x lines. And certainly don’t perform at lectures to explain the concept. :)

PDT Resource Containers Include Paths

Sunday, December 16th, 2007

Last week I have been working on extending of Include Path Libraries management in PDT and Zend Studio for Eclipse (Neon). The change won’t be released either in PDT 1.0.2 or in Zend Studio for Eclipse GA, but in the next ones (since it changed almost every aspect of products’ functionality).

The change’s idea is very trivial - until now you had the project’s root as a unchangeable default include path and ability to attach another project roots as additional include paths (variable and library functionality is not changed, except several minor bug fixes). And the point is to make the default visible and removable and to allow addition of specific folders both under same project and other PHP projects. Seems simple, huh? Well, it’s not so much.

The main change is very quick indeed - just replace IProject references with IContainer ones, handle properties serialization etc. and you are there. However when you think a bit about the model (classes, functions, constants) it comes that element beyond the specified folders should be invisible from within the project. Thus it was a need to implement a project’s model filtered wrapper, which efficiently cuts the unneeded elements from the model. Also include path order is relevant from now, which affects debugger execution. That’s about all the changes which affect PDT.

However, when Zend Studio for Eclipse comes to a picture, it becomes even more complicated. First of all, you have File Network in it, which is a graph of all PHP files connected by include/require statements. Second you have Organize Includes, Refactoring Move/Rename of file/folder and at last - include content assist (code completion). All of these should respect the change in configuration and also reflect the configuration change in reasonable time.

This time I won’t go deep into implementation, because it’s less interesting by itself and limit myself with just a brief demo:

Demo Thumbnail

  • You are currently browsing the archives for the development category.
  • Pages

  • Archives

  • Categories