Posts tagged ‘Computers’

VN:F [1.9.14_1148]
Rating: 4.0/10 (1 vote cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

Great! We did it! Nothing working, but nevertheless the letter on the heading should be green. right?

VN:F [1.9.14_1148]
Rating: 7.0/10 (2 votes cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

Recently I was doing some heavy-duty Javascript stuff for a web project. It was quite a while since the Firefox plug-in and in many ways, it was rather enjoyable experience (and in some other ways boring :-) ).

If you want to do some cool stuff in the web nowadays, the adoption of a Javascript library like jQuery is typical. I had some experience in the past, but the development process showed me that I was not so experienced as I thought. jQuery has good documentation that can be used as a reference, but it is not very usefull, when you want to understand some basic concepts and you are in a hurry of doing some stuff to work.

So, this blog entry has one goal, to transfer my experience of doing stuff with jQuery as a set of rules/advices that will save time to inexperienced users like me.

Rule #1: “When you are using jQuery, forget low-level Javascript functions”

It is a good practice to use always jQuery’s functions to do the stuff you want. Never rely on the low-leve Javascript function. The reason is simple. jQuery offers an encapsulating object for all the elements of the DOM tree. If you select some nodes with the jQuery selectors and then try to access their children with the common DOM function offered by the standard Javascript API, you are done for. You lose that encapsulation and you are back in black.

Rule #2: “Use # for the ‘id’ selector, ‘.’ for the class selector and always use backslashes in front of dots in ids”

No special reason, just remember these three examples:

  • $(‘#theCoolId’) – id selector
  • $(‘.myBigFatClass’) – class selector
  • $(‘#theCoolId\\.With\\.Dots’) – more complex id selector

Rule #3: “When you have to insert code into an element, use html()”

Simple as that, select the node and paste the code:

$('#theCoolNode').html('
<h1>Hey Stranger!</h1>
');

Rule #4: “By default the ajax() call is asynchronous”

… so if you want to load something, be sure to disable async, or else you will try to access something that is not ready. How can you do that? Simple!

$.ajax({
	type: "GET",
	dataType: "xml",
	url: "data/strings.xml",
	success: function(xml) { /* success */ },
	error: function() { /* error */ },
	async: false /* I will wait to load the XML */
});

Rule #5: “insertBefore() and insertAfter() take the selector as the parameter”

I do not know about you, but I always thought that it is logical for the insertAfter() and insertBefore() to select a node, then append the node. But this is not the way they are implemented. A small example:

$('<h1>Hey Joe!</h1>').insertAfter('#theCoolNode')

Rule #6: “It is always your fault”

Usually it is, accept it and try to understand how things are working :) , instead of trying to convince everyone that you are Mr. Right!

VN:F [1.9.14_1148]
Rating: 8.0/10 (1 vote cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

VN:F [1.9.14_1148]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.14_1148]
Rating: +4 (from 4 votes)

No comment …

from my DSL modem.

VN:F [1.9.14_1148]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

It seems that adobe and apple are continuing on their war efforts on all fronts. Recently I tried to open a pdf and saw the following message:

Nice huh? To be honest, I consider acrobat reader one of the ugliest programs on Mac OS X. So, if I can help it, I will not install it.

VN:F [1.9.14_1148]
Rating: 5.0/10 (1 vote cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

These days i’m finalising the FIRE regular expression compiler. To add a feature, the need arise to modify the classpath at runtime. It was a surprise for me when i discovered that there is no official way to modify this at runtime. I even created my own URLClassLoader (java.net), and set it as default classloader for my thread, but nothing.

I searched in google a little and found this post on a forum, which provided a class named ClassPathHacker that could add a path or file (jar) to a classpath at runtime. All this by a programmer named Antony Miguel. Well done :) .

The source code of the class follows:

import java.net.*;
import java.io.*;
import java.lang.reflect.*;
 
public class ClassPathHacker {
 
	private static final Class[] parameters = new Class[]{URL.class};
 
	public static void addFile(String s) throws IOException {
		File f = new File(s);
		addFile(f);
	}
 
	public static void addFile(File f) throws IOException {
		addURL(f.toURL());
	}	 
 
	public static void addURL(URL u) throws IOException {			
		URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
		Class sysclass = URLClassLoader.class;
 
		try {
			Method method = sysclass.getDeclaredMethod("addURL",parameters);
			method.setAccessible(true);
			method.invoke(sysloader,new Object[]{ u });
		} catch (Throwable t) {
			t.printStackTrace();
			throw new IOException("Error, could not add URL to system classloader");
		}		
	}	
}

and an example of usage ..

import java.io.*;
 
public class ClassPathAdder {
	public static void main(String[] args) {
		try {
			ClassPathHacker.add(new File("/home/user/newClassPath"));
		} catch (IOException e) {
			System.err.println("Error - " + e.toString());
		}
	}
}

Cool! :-D

VN:F [1.9.14_1148]
Rating: 4.0/10 (1 vote cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

Typical day @ home. I just executed a du -s. Suddenly I realized that I wanted to do something else first, control-c and the computer responded:
computer-love

Lovely, isn’t it? I always knew :) .

VN:F [1.9.14_1148]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

Everyone that has a living (and networked) computer in his house has seen it. The revolution of our century in computing, the World Wide Web (WWW). Many consider it the next big-bang platform. Google, YouTube, and Facebook among others, deliver a variety of services for all kinds of taste. Social networks, video, music, and e-commerce is now done by web applications.

In addition, many traditional kind of applications are also web-ified, such as government facilities that have all transformed into e-Government. Yes, it is true. You don’t have to run anymore, two more clicks from your chair, and your dreams may come true.

Back then …

… i was a student. I remember surfing the web, that was comprised of simple, for today’s standards of course, HTML pages, downloading C compilers, and recent patches for video games. I also learned of dynamic content, CGI based applications with Perl and later with PHP. I even developed some web applications myself. Then i heard of Java and applets, more dynamic content in a stateless world. Cookies, hidden parameters, hashes, sessions, all concepts that gave birth to the modern era of computing.

Best effort …

… is what the standard says about HTML rendering. In simple english, “do the best you can” and in a more simple manner “write the worst code ever, it is my fault, not yours”. What happens if you open the <b> tag and never close it? Nothing at all. What even happens if you do not know what <custom_tag> means? Just ignore it.

In this platform, we based our dreams regarding the future of our applications, and to make it worse we decided to make it even worse. And we did it beautifully, we took the task of web design from the computer scientist and we created a bunch of incompatible technologies.

The Tower of Babel

Indeed the world-wide web consists of a bunch of unrelated, badly coupled technologies. For example, we have CSS and HTML. What was the key idea behind them? Who knows? We created HTML that followed a specific notation, that obeyed the tag open – tag close rule and then we decided (years later) to defy it and create something like the X configuration files. Why is that? Nobody knows, and keep in mind that they were proposed by the same organisation, W3C.

In all this, we tried to give more juice to it by adding a javascript, that simply added HTML in the start, and later of modified the DOM tree of a page. Superb idea, we created a scripting language that is domain-specific but not exactly to serve its purpose. Javascript has the design concept of a general-purpose programming language, yet we use it like XSLT, to modify XML data. I am sure it is fun to traverse node lists and create new tags the hard way.

At the end, to complete our divine masterpiece, we made the ultimate move. We created incompatible web browsers, that had unique features. So it is nice that a web developer, must have Internet Explorer, Opera, Safari, Firefox, Chrome and Camino to check if the web site works and is displayed correctly. And yes each browser it is like a platform with unique add-ons, interpretation and implementation of the web standards (what?). So what if the menu is an inch lower in Internet Explorer? We have to live with it.

I will not refer to Java applets, flash or Silverlight. All those technologies are helping to increase the complexity not reduce it, introducing more and more diverse features.

Give the Web Back …

… to the computer scientists, because now it is a playground. Everyone can do whatever he wants and get away with it. The web is now built on unstable ground, and it will soon collapse. See all the web apps, like gmail. Try to estimate the effort behind the creation of it. You think it is fun or creative to do it? Or do you think that it would require half the time of creating it in a decent development platform? No, I’m not trying to estimate the development time here, i know it is a very difficult task.

Programmers Love the Web …

… and they want the web to love them back. I do not think i have the required skill to propose things to do it better, so i want you to add a big IMHO (In My Humble Opinion) just before every bullet that follows. So i think that it is time to …

… to enforce the standards. And i mean no best effort service anymore. The web has now penetrated all households and all businesses, time to mature.

… to create a compatible platform. No more dozens of browsers with unique behavior. I want it to work the same way in each one of them. Why LaTeX does it? Do the same.

… to find a decent scripting language. I think javascript is not enough. We create specialized languages for this kind of work.

… to try and find a common syntax for all the related technologies. We like XML notation? Stick with it! Do not create more and more languages that cause diversity. We like humans to learn and use it.

… to find ONE standard for HTML. I do not care who will it be. But it is funny to see standards like, XHTML, HTML 4.01, strict, and transitional.

In the End …

… we all use it. Even the most non-technical user knows that <b>text</b> prints the text bold. We all like blogging, forums and googling. Let’s make it work the right way.

VN:F [1.9.14_1148]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)

I always argue with network administrators. They use firewalls to block and monitor the traffic of the intranet and refuse to open any other port except 80 (of course) for any other service.

Ports in TCP and UDP exist for the sole reason for multiplexing many virtual channels on one physical medium. Those guys (and many others) seem to forget that and re-invent multiplexing techniques on higher layers, using web services for example (See Figure below).

How can you stay in the market? Say the same technology again and again.

How can you stay in the market? Sell the same technology again and again.

Original Post

VN:F [1.9.14_1148]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)