helion-prime
home about us blogs contacts

Archive for the ‘general programming’ Category

Understand Web with MAMA

Thursday, October 16th, 2008

Preamble

Did you ask you mam in childhood about nature of things? Yeah, who did not..
And now Opera software [http://en.wikipedia.org/wiki/Opera_Software] presented MAMA – the Metadata Analysis and Mining Application. It is analytical search engine that returns details of page structure.

How can we use use it?

“We at Opera believe this tool can also be useful to other stakeholders in the standards and browser-making world.
For example:
Browser manufacturers and others can use MAMA data on the popularity of widely used technologies to prioritize bugs and justify adding support for new technology to in-progress releases.
Standards bodies can use the data to measure the success and adoption rates of various technologies.
Web developers can use the same data to justify support of various technologies in their work.
It can provide real-world, practical samples of the Web developer’s “art”, for inspiration and instruction.”
According to MAMA project documentation

Some details

MAMA give us answers on questions like: how many sites use CSS (80,4% by MAMA), how many errors on average page (47), how many symbols on average page (16,400), which country the most use XMLHttpRequest, an important component of AJAX? (Norway, 10.2%).

Or more sophisticated: how many sites adapted for mobile gadgets, how much Web2.0 spread, what version of HTTP protocol more popular and so on..

MAM is active project and so with the lapse of time we will get bigger range of data. That will give us possibility to understand Web tendencies and Web better.
So thanks Mama.

Related links links to get details:
Mama project description: [http://dev.opera.com/articles/view/mama/]
Mama key findings [http://dev.opera.com/articles/view/mama-key-findings/]

Browsing Web with human interface: Mozilla Ubiquity

Wednesday, September 17th, 2008

preamble

Mozilla Labs as always makes us happy with new innovative ideas.
Maybe you remember post of Vasiliy Kiryanov about Mozilla Prism: with that platform we can use web-applications like regular desktop applications [http://blogs.helion-prime.com/vasiliykiryanov/2008/06/03/new-web-experience-with-mozilla-prism.html]
And now new fresh idea from Mozilla Labs: Ubiquity as a way “connecting the Web with language”.

Ubiquity way

For a long time people have idea to create a way to store and query data of any application easy.
It can give enormous flexibly like everything is already here and in appropriate format. We know this idea as W3C Semantic Web[http://ru.wikipedia.org/wiki/Semantic_Web], as we are still far from it, software developers on Internet are using mashups [http://en.wikipedia.org/wiki/Mashup_(web_application_hybrid)] to get similar effect today.

But what can we do from user side when we want to connect many different applications together, and use them in a same way. Ubiquity propose a way to describe common tasks in the Web using language-based instructions, and then you can create you own mashups with help of existing open Web APIs.

To have a better understanding how it work you can watch following video:

Now if you like the idea you can continue reading about it from Ubiquity tutorial: [https://wiki.mozilla.org/Labs/Ubiquity/Ubiquity_0.1_User_Tutorial]

related links:
Ubiquity Commands: [https://labs.toolness.com/ubiquity-herd]
Get Help & give your suggestion: [http://getsatisfaction.com/mozilla/products/mozilla_ubiquity]
Report a Bug: [http://labs.toolness.com/trac/report]

On-the-fly compilation in Java6

Friday, June 13th, 2008

One of interesting novelty of Java6 is a possibility to access compiler via special API.
Let’s look on this feature a bit closer.

In order to have an access to compilation subsystem we should use classes located at javax.tools package [http://java.sun.com/javase/6/docs/api/javax/tools/package-summary.html].
In the future in this package possibly appear classes to work with different external utilities, but at this moment we have only access to the compiler.

As simple example let’s look on request to compile:

1
2
3
4
5
6
7
8
9
10
11
12
13
   JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

   Iterable<SimpleJavaFileObject> srcList =  Arrays.asList(new SimpleJavaFileObject[]{
      new SimpleJavaFileObject(URI.create("string:///myclass.java"), Kind.SOURCE) {

         @Override
         public CharSequence getCharContent(boolean ignoreEncodingErrors) {
            return "class myclass {}";
         }
      }
   });
       JavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
       compiler.getTask(null, fileManager, null, null, null, srcList).call();

Let’s try to understand how it’s work:

The compiler access input data not directly but via objects inherited form JavaFileObject. Therefore depending on needs of developer information for compilation can be received from any place: network, file, memory; for that we need to implement successor of JavaFileObject.
It is better to do it by inheriting class-gag SimpleJavaFileObject

In our example implementation of SimpleJavaFileObject returns source of class as constant string. It is slightly harder with output data. There is another abstraction layer called JavaFileManager that is object factory per se.

Standard file manager that we receive in our example let us work with files on the disk. If you need to place output data on the network on in the memory you need to override JavaFileManager. It is better to do it inheriting ForwardingJavaFileManager, this class retarget request to provided during creation file manager. At the same time you can handle only those request that you need.

Last string of example creates compilation command and execute it at once. As a result of execution we have file in the execution directory of example with name myclass.class that contains bytecode of appropriate class. It is noteworthy that classloaders of system know nothing about existence of given class and so call Class.forName(“myclass”) throws ClassNotFoundException.

Let’s complete our example to get class bytecode as byte array. For that we need to implement our own file manager:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public class JavaMemFileManager extends ForwardingJavaFileManager {

   class ClassMemFileObject extends SimpleJavaFileObject {
      ByteArrayOutputStream os = new ByteArrayOutputStream();

      ClassMemFileObject(String className) {
         super(URI.create("mem:///" + className + Kind.CLASS.extension), Kind.CLASS);
      }
      byte[] getBytes() {
         return os.toByteArray();
      }

      @Override
      public OutputStream openOutputStream() throws IOException {
         return os;
      }
   }

   private HashMap<String, ClassMemFileObject> classes =
         new HashMap<String, ClassMemFileObject>();

   public JavaMemFileManager() {
      super(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null));
   }

   @Override
   public JavaFileObject getJavaFileForOutput(Location location,
         String className, Kind kind, FileObject sibling) throws IOException {
      if (StandardLocation.CLASS_OUTPUT == location && JavaFileObject.Kind.CLASS == kind) {
         ClassMemFileObject clazz = new ClassMemFileObject(className);
         classes.put(className, clazz);
         return clazz;
      } else {
         return super.getJavaFileForOutput(location, className, kind, sibling);
      }
   }

   public byte[] getClassBytes(String className) {
      if (classes.containsKey(className)) {
         return classes.get(className).getBytes();
      }
      return null;
   }
}

As you see our file manager override method getJavaFileForOutput that complier calls to receive output file object. Here we check destination, for new classes it should be StandardLocation.CLASS_OUTPUT and type. If it correspond to newly compiled class then we create new file object: we save it and pass it to the compiler.
Then we can receive access to the bytecode with method getClassBytes(className) passing the name of the class.

Let us change previous example to use new functionality:

1
2
3
4
5
6
   ....
   JavaFileManager fileManager = new JavaMemFileManager();
   compiler.getTask(null, fileManager, null, null, null, srcList).call();

   byte[] myClassBytes = ((JavaMemFileManager)fileManager).getClassBytes(“myclass”);
   ....

And yet one feature of example execution in our case will be absence of file on the disk.

Finally I made a library that makes easier access to Java6 Compiler API.
See details on: [ http://opensource.helion-prime.com/jruntime/ ]

Simplify of web-development with Firefox plug-ins

Monday, June 2nd, 2008

preamble

There is set of plug-ins that really simplify development process and glance will help you select something for your daily work.

golden list

name: firebug
functions: edit, debug, and monitor CSS, HTML, and JavaScript live
hints: page loading analysis, live working with CSS styles, JavaScript debugger
add-on page: [https://addons.mozilla.org/en-US/firefox/addon/1843]

name: user agent switcher
functions: switch the user agent of the browser
hints: cool but IE, and Firefox still interpret code differently and anyway for interpretation tests you need ‘ies4linux’ [http://www.tatanka.com.br/ies4linux/page/Main_Page]
add-on page: [https://addons.mozilla.org/en-US/firefox/addon/59]

name: dust-Me Selectors
functions:finds unused CSS selectors
add-on page: [https://addons.mozilla.org/ru/firefox/addon/5392]

name: firesizer
functions: resize of firefox the window to specific dimensions
hints: it helps to test site in required resolutions
add-on page: [https://addons.mozilla.org/en-US/firefox/addon/5792]

name: SQLite manager
functions: manage SQLite databases
hints: I think you know why it is better to use SQLite DB on workplaces
add-on page: [https://addons.mozilla.org/en-US/firefox/addon/5817]

name: add N edit cookies
functions: allows you add and edit session and saved cookies in live
add-on page: [https://addons.mozilla.org/en-US/firefox/addon/573]

Setup of Ruby on Rails environment under Debian GNU/Linux

Wednesday, May 21st, 2008

preamble

here you will find just quick-and-dirty hints how to use Ruby on Rails on Debian GNU/Linux platform

ruby and RoR installation

# apt-get install ruby

install ruby gems [http://en.wikipedia.org/wiki/RubyGems]
# apt-get install rubygems

then don’t use ‘rails’ Debian package because it doesn’t work with gem and so gem will not know about it.
you should use gems for that:
# gem install rails –include-dependencies

if you located behind a firewall, export following value before gem using:
HTTP_PROXY=http://[username]:[password]@[proxyserver]:[port]

if you use some IDE like NetBeans [http://en.wikipedia.org/wiki/NetBeans]with Ruby on Rails extension than after installing of ruby and rubygems packages
you can use NetBeans to install ruby extensions

installation of gems that require building of native extensions

some gems are simple set of ruby scripts and then can be just installed
some gems contain source code c/c++ and so before installing of such gems you should have:

**development environment
# apt-get install build-essential

**ruby development header files
# apt-get install ruby-dev

**header files of library that you want to build

for example: you want to have ruby driver for postgresql DB
# apt-get install postgresql-server-dev-8.3
# gem install postgres

enjoy it ..

©2010 Helion-Prime Solutions Ltd.
Custom Software Development Agile Company.