2009-10-22

HOWTO: Install Java 1.4 & 1.5 on Snow Leopard

Because of some projects, I need to complie some Java projects in Eclipse with older Java versions, such as 1.4.2, on my MacBook, but since Snow Leopard is such a new(!) operating system, it lacks a lot of support for softwares running with older versions of libraries.

After a long while searching in the internet, finally I found the way to install JVM 1.4 & 1.5 on Snow Leopard!

Java 1.4:
Here is how to get Java 1.4 running on snow leopard.
cd /tmp/
curl -o java.1.4.2-leopard.tar.gz http://tedwise.com/files/java.1.4.2-leopard.tar.gz
tar -xvzf java.1.4.2-leopard.tar.gz
sudo mv 1.4.2 /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2
cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo ln -s 1.4.2 1.4
open "/Applications/Utilities/Java Preferences.app"
and Java 1.5:
cd /tmp/
curl -o java.1.5.0-leopard.tar.gz http://tedwise.com/files/java.1.5.0-leopard.tar.gz
tar -xvzf java.1.5.0-leopard.tar.gz
sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leo
cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm 1.5.0
sudo mv 1.5.0-leo 1.5.0
sudo ln -s 1.5.0 1.5
open "/Applications/Utilities/Java Preferences.app"
It really works! ;-)

via [OneSwarm]

Update (2014-05-05): the broken links are fixed.

2009-09-29

Some Reasons Why I Don't Update My iPhone (1st Gen) To Firmware 3.1

The firmware 3.1 for iPhone has been released for a while. Every time when I plug in my iPhone to my Macbook, the iTunes reminds me always of a new iPhone OS available. But I must say no to iTunes every time. So why I don't want update my iPhone to that version 3.1? There are 5 reasons or at least my considerations.

PROs:
1. PwnageTool 3.1 (http://blog.iphone-dev.org/) is ready for the go. AppSync for OS 3.1 in Cydia is appeared too. (Instructions)
2. iPhone OS 3.1 has the funtion that man can arrange the application layout directly in iTunes.
3. Genius Mix will be supported.

CONs:
1. For non-Standard accessories there are still no hacks appeared like 3.01. The magic is called iapd. It fixs the problem with the message "This Accessory is not made to work with iPhone"

2. It's possible to develope iPhone applications for jailbroken iPhone 3.0 with a patched XCode 3.1.3. (Source) But until now, I didn't get how to make it work with iPhone OS 3.1 and XCode 3.2.


Updates!
1. MichaelS confirmed that the pathed iapd for 3.0 also works for 3.1.2!
2. Xcode 3.2 works
with jailbroken iPhone 3.1 too according to
the "Float Middle" Blog.


So, now it is the time to update! :)

2009-07-22

Passing Additional Parameters Or Arguments Using addEventListener In Flex

With Adobe Flex one can make a lot of things. In the heart of its event-driven-programming, there is a famous function called addEventListener(). From Adobe LiveDoc we can see the syntax is like:

addEventListener() method
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void

Parameters


type:String — The type of event.


listener:Function — The listener function that processes the event. This function must accept an Event object as its only parameter and must return nothing, as this example shows:
function(evt:Event):void

The function can have any name.



useCapture:Boolean (default = false)Determines whether the listener works in the capture phase or the target and bubbling phases. If useCapture is set to true, the listener processes the event only during the capture phase and not in the target or bubbling phase. If useCapture is false, the listener processes the event only during the target or bubbling phase. To listen for the event in all three phases, call addEventListener twice, once with useCapture set to true, then again with useCapture set to false.


priority:int (default = 0) — The priority level of the event listener. The priority is designated by a signed 32-bit integer. The higher the number, the higher the priority. All listeners with priority n are processed before listeners of priority n-1. If two or more listeners share the same priority, they are processed in the order in which they were added. The default priority is 0.


useWeakReference:Boolean (default = false) — Determines whether the reference to the listener is strong or weak. A strong reference (the default) prevents your listener from being garbage-collected. A weak reference does not.

Class-level member functions are not subject to garbage collection, so you can set useWeakReference to true for class-level member functions without subjecting them to garbage collection. If you set useWeakReference to true for a listener that is a nested inner function, the function will be garbage-collected and no longer persistent. If you create references to the inner function (save it in another variable) then it is not garbage-collected and stays persistent.


Throws

ArgumentError — The listener specified is not a function.

See also


========================================================
There is no way to pass some addtional parameters to an event handling function!

Deva Raj's solution is fine, but without some explaination it is hard to understand.

So the quick and dirty way is to use an inline function:

btn1.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){myEventHandler(e, btn1.id)});

public function myEventHandler(e:MouseEvent, btnId:String) {
Alert.show("Clicked button"+btnId, "Great Title",Alert.OK);
}

Here btn1.id is just an example parameter, you can replace it with what you want.

Another better(!) solution is to create custom Event, which you can find it here:

ActionScript Code:
package com
{
import flash.events.Event;

public class EventWithData extends Event
{
public var data:*;

public function EventWithData(type:String, data:*,
bubbles:Boolean = false, cancelable:Boolean = false)
{
this.data=data;
super(type, bubbles, cancelable);
}

}
}
The mechanism details can be found also in Adobe LiveDocs: Registering event handlers

2009-06-18

How to write a Java-based HTML-Crawler?

It's actually a task from my test work. First idea that came to me is: Use an instance of XMLReader to fetch a page, then use regular expression to parse, save the results with the help of XMLWriter. Such a way seems naive, but almost non-usable! So let me explain the difficulty which can be confronted.


1. Internet is a mess.



There are too many web pages in the cyberspace that do NOT pay any attention to the web standard (X)HTML. So we can see a lot of nested tags, unpaired tags and even worse, badly programmed JavaScript may be in just one page.



2. Ads are confusing.


Now come Advertisements with different formats, e.g. Text, Flash, Images and Videos(!). Most of them live with a lot of JavaScript to improve their impact. Some use even non-standard tags such as <noscript> or browser-specific tags.


3. Ajax is not so user-friendly.

We all love to use Ajax technology. A typical Ajax use case is to let some texts loaded dynamically, then it results a severe problem with a HTML-Parser. If the parser saves the fetched HTML-page in a cache, the cache file contains a lot of JavaScript which load elements later. So with the cache file we cannot get what we want normally.


What can we do with all those?


The current popular solution is to use the HTML or Webpage validation tools! Between different libraries HTMLUnit will fit our requirement exactly. The project describes itself as a "GUI-Less browser for Java programs". So we can handle a webpage just like we see it in our browser. The above disadvantages could be then avoided.


Interesting is, HTMLUnit is originally a java unit testing framework for testing web based applications. It is similar in concept to HTTPUnit but is very different in implementation.


For beginners, HTMLUnit provides a very simple documentation to "Get Started". With the examples provided on the website it's okay to write a HTML-Crawler now.


2009-05-05

blue-chip company

Today I got an offer from a headhunter for a contract-based work. Interesting is, I met a foreign word called "Blue Chip Company". So I did a little research to find out what it really means. Here it is! ;)

1. finance definition:

A company that is very strong financially, with a solid track record of producing earnings and only a moderate amount of debt. A blue-chip company also has a strong name in its industry with dominant products or services. Typically, blue-chip companies are large corporations that have been in business for many years and are considered to be very stable. However, there is no formal requirement for being a blue chip. Often, blue-chip companies are found in the Dow Jones Industrial Average.

2. Better explanation

Blue chip (stock market)

A blue chip stock is the stock of a well-established company having stable earnings and no extensive liabilities. The term derives from casinos, where blue chips stand for counters of the highest value. Most blue chip stocks pay regular dividends, even when business is faring worse than usual.

The phrase was coined by Oliver Gingold of Dow Jones sometime in 1923 or 1924. Company folklore recounts that the term apparently got its start when Gingold was standing by the stock ticker at the brokerage firm that later became Merrill Lynch. Noticing several trades at USD$200 or USD$250 a share or more, he said to Lucien Hooper of W.E. Hutton & Co. that he intended to return to the office to “write about these blue chip stocks.” Thus the phrase was born. It has been in use ever since, originally in reference to high-priced stocks, more commonly used today to refer to high-quality stocks. In contemporary media, Blue Chips and their daily performances are frequently mentioned alongside other economic averages like the Dow Jones Industrial Average.

/////////////////////

2009-02-13

The notorious Problem with letterSpacing in Flash

These days I met a problem in Flash with the property letterSpacing of a dynamic text field.

If we are looking at the examples provided by Adobe:

this.createTextField("mytext", this.getNextHighestDepth(), 10, 10, 200, 100);
mytext.multiline = true;
mytext.wordWrap = true;
mytext.border = true;

var format1:TextFormat = new TextFormat();
format1.letterSpacing = -1;

var format2:TextFormat = new TextFormat();
format2.letterSpacing = 10;

mytext.text = "Eat at \nJOE'S.";
mytext.setTextFormat(0, 7, format1);
mytext.setTextFormat(8, 12, format2);

The problem is, this doesn't work for a dynamic text field, only for dynamic generated text field!

There are a lot of solutions on the internet.

Solution 1:

var
styling:TextFormat = new TextFormat();
styling.font = "Blackadder";
styling.color = 0xBA1424;
styling.letterSpacing = 15;

tf.setNewTextFormat(styling);
tf.text="mööööp"


This one doesn't use the method setTextFormat() to set the letterSpacing, instead of that, setNewTextFormat() will be used.

Solution 2:

From the blog "Summit Projects":

function setTextFormatting(){
var fmt:TextFormat = club_name.name.getTextFormat();
club_name.name.setTextFormat(fmt);
club_name.name.setNewTextFormat(fmt);
club_name.name.autoSize = “left”;
}


He said, "It’s silly, but it works.". Unfortunately, it didn't work in my case.

Solution 3:

Bob Walton suggests that in his blog "Flash: yourMom.getTextFormat(); //is the key to letterSpacing"

var fmt:TextFormat = myTextField.getTextFormat();
myTextField.setTextFormat(fmt);
myTextField.setNewTextFormat(fmt);


This also didn't work for me.

I spent hours to figure out how can I fix it. Now here is the solution from mine.

txtCtrl.html = true;
txtCtrl.htmlText = "<font letterspacing='-3'>Now it is the right one!</font>";


So you can see, I got no sucess on setting the format of a dynamic text field. At the end, a font property can achieve that so easily!