The proliferation of modern programming languages (all of which seem to have stolen countless features from one another) sometimes makes it difficult to remember what language you're currently using. This handy reference is offered as a public service to help programmers who find themselves in such a dilemma.
TASK: Shoot yourself in the foot.
C: You shoot yourself in the foot.
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
FORTRAN: You shoot yourself in each toe, iteratively, until you run out of toes, then you read in the next foot and repeat. If you run out of bullets, you continue with the attempts to shoot yourself anyways because you have no exception-handling capability.
Pascal: The compiler won't let you shoot yourself in the foot.
Ada: After correctly packing your foot, you attempt to concurrently load the gun, pull the trigger, scream, and shoot yourself in the foot. When you try, however, you discover you can't because your foot is of the wrong type.
COBOL: Using a COLT 45 HANDGUN, AIM gun at LEG.FOOT, THEN place ARM.HAND.FINGER on HANDGUN.TRIGGER and SQUEEZE. THEN return HANDGUN to HOLSTER. CHECK whether shoelace needs to be re-tied.
LISP: You shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds the gun with which you shoot yourself in the appendage which holds...
FORTH: Foot in yourself shoot.
Prolog: You tell your program that you want to be shot in the foot. The program figures out how to do it, but the syntax doesn't permit it to explain it to you.
BASIC: Shoot yourself in the foot with a water pistol. On large systems, continue until entire lower body is waterlogged.
Visual Basic: You'll really only _appear_ to have shot yourself in the foot, but you'll have had so much fun doing it that you won't care.
HyperTalk: Put the first bullet of gun into foot left of leg of you. Answer the result.
Motif: You spend days writing a UIL description of your foot, the bullet, its trajectory, and the intricate scrollwork on the ivory handles of the gun. When you finally get around to pulling the trigger, the gun jams.
APL: You shoot yourself in the foot, then spend all day figuring out how to do it in fewer characters.
SNOBOL: If you succeed, shoot yourself in the left foot. If you fail, shoot yourself in the right foot.
UNIX: (The way most UNIX hackers shoot themselves in the foot.)
% ls
foot.c foot.h foot.o toe.c toe.o
% rm * .o
rm:.o no such file or directory
% ls
%
Concurrent Euclid: You shoot yourself in somebody else's foot.
370 JCL: You send your foot down to MIS and include a 400-page document explaining exactly how you want it to be shot. Three years later, your foot comes back deep-fried.
Paradox: Not only can you shoot yourself in the foot, your users can, too.
Access: You try to point the gun at your foot, but it shoots holes in all your Borland distribution diskettes instead.
Revelation: You're sure you're going to be able to shoot yourself in the foot, just as soon as you figure out what all these nifty little bullet-thingies are for.
Modula2: After realizing that you can't actually accomplish anything in this language, you shoot yourself in the head.
Assembler: You try to shoot yourself in the foot, only to discover you must first invent the gun, the bullet, the trigger, and your foot.
Sunday, 3 August 2008
Computer Programming joke
At a computer software course, the participants were divided into programming teams. At the end of the session they were given an awkward question to answer: "If you had just boarded an airliner and discovered that your team of programmers had been responsibled for the flight control software, how many of you would disembark
immediately?"
Among the ensuing forest of raised hands only one person sat motionless. The instructor asked why the lone brave person would be so content to stay on board.
"With my team's software," he reasoned, "the plane would be unlikely to successfully taxi to the runway, let alone take off."
Saturday, 2 August 2008
Google search in command line
Recently I discovered a web page that provide command line interface for google search, as the author called it as Google Shell. Check out the screenshot, and also try it out at http://goosh.org/.

It does looks like unix-shell, thank to Ajax. You may think that is hilarious, but don’t make judgment before trying it out. For me, that is usable. and I should say that is perfect for CLI hardcore users.
I like google translate command line feature very much. Try this:
guest@goosh.org:/web> translate en de hello
translating "hello" from "english" to "german":
"hallo"
Surprisingly, when you hit tab, it does support auto complete and hitting arrow key up and down support keeping history list.
Linux commands list the processes
top command provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. But if you want get something more specific, you must play some tricks on it. For example, I want a clean view of top ten busiest processes every seconds without those summary info, how should I do with top?
Batch mode operation
top is a real-time application that keeps display processes info sorted by cpu usage, if you redirects the outputs to a file like command line below, you will having your results mixed with ugly symbols, which is not what you want.
top > top.txt
Well, top support batch mode. By specified top on batch mode, top will display the outputs without arrange the views properly, but if you redirects it to a file, you won’t get those messy symbols mixed up.
top -b > top.txt
I just want to monitor top ten processes every seconds!
You can limits your views of top ten using head and tail, but this will STOP top from continuing to monitor the processes.
top -d 1 | head -n 17 | tail -n 11
Fortunately, we have watch to help, but you needs to put top in batch mode, and also you can ask top to stop after done displaying the result for one time. This will increase the accuracy of the result.
watch -n 1 "top -b -n 1 | head -n 17 | tail -n 11"
Tips on JPA Domain Modelling
1. Put Annotation on Methods, not Attributes
If using annotations on attributes, JPA engine will set directly in the attributes using reflection, hereby by-passing any code in setters and getters. This makes it hard to do extra work in setters and getters, if the need arises.
In addition, if you add a getter for some calculated value which has no corresponding attribute, you can mark it @Transient on the method. Had you been putting it on the attributes, you would have no attribute to put the annotation on.
Whatever you do: Try not to mix, using with annotations both on fields and methods. Some JPA providers cannot handle this!
2. Implement Serializable
The specification says you have to, but some JPA providers does not enforce this. Hibernate as JPA provider does not enforce this, but it can fail somewhere deep in its stomach with ClassCastException, if Serializable has not been implemented.
3. Use The Fine Grained Domain Modelling and Mapping Possibilities in JPA
If coming from EJBs (before EJB3), you are not used to be able to do fine grained modelling. EJB2.x was very entity centric. In JPA, you have @Embeddable and @Embedded. Doing more fine grained domain modelling can help make your domain model more expressive.
An @Embeddable is a value object, and as such, it shall be immutable. You do this by only putting getters and no (public) setters on its class. The identity of a value object is based on its state rather than its object id. This means, that the @Embeddable will have no @Id annotation.
As an example, given the domain class Person:
@Entity
public class Person implements Serializable {
...
private String address;
@Basic
public String getAddress() { return address; }
public void setAddress(String address) { this.address = address; }
}
We could express Address better, by giving it a class of its own. Not because it should be mapped to some other table, but because it makes sense in this particular model. Like this:
@Embeddable
public class Address implements Serializable {
...
private String houseNumber;
private String street;
@Transient
public String getHouseNumber() { return houseNumber; }
@Transient
public String getStreet() { return street; }
@Basic
public String getAddress() { return street + " " + houseNumber; }
// setter needed by JPA, but protected as value object is immutable to domain
protected void setAddress(String address) {
// do all the parsing and rule enforcement here
}
}
@Entity
public class Person implements Serializable {
...
private Address address;
@Embedded
public Address getAddress() { return address; }
public void setAddress(Address address) { this.address = address; }
}
The better expressiveness comes from: a) Putting a named class on a concept in the model and, b) having a place (the value object class) where to put domain logic and enforce domain rules.
4. Implement Equality using Real Domain Attribute Values
Classes marked @Entity will always have an id attribute. Often, this is a long sequence. It can be tempting to use this value when implementing equals and hashCode (which is also a requirement), but I recommend against it. I can find two good reasons: One based on modelling rules and one based on technical terms.
* Modelling rule: A class modelled as an entity should be uniquely distinguishable from other instances, solely based on a combination of some of its domain attributes. A long sequence, used solely to obtain relational identification, does not constitute a domain attribute. If you are unable to find a unique combination, it might very well be a sign of a problem with the model.
* Technical term: If equality is based on a database generated and assigned value, you will not be able to use equals and hashCode before an instance has been persisted. That includes putting the instance into container classes, as they rely on equals and hashCode.
5. Protect the Default Constructor
The JPA specification mandates a default constructor on mapped classes, but a default constructor seldom makes sense in modelling terms. With it, you would be able to construct an entity instance with no state. A constructor should always leave the instance created in a sane state. The requirement for the default constructor is only to make dynamic instantiation of instances of the class possible by the JPA provider.
Luckily, you can, and are allowed to, mark the default constructor as protected. Hibernate will even accept it as private, but that is not by the spec.
6. Protect Setter Method on Id Attribute
Basically the same story as above. In this case, it is just because it makes no sense for the application to assign an id.
NOTE: This is only for when the id attribute is marked as assignable by the provider.
7. Avoid Primitives when Mapping Id Attribute
Simply use Long and not long. This makes it possible to detect a not yet set value by testing for null. If using Java5 or above, auto-boxing should take away the pain.
8. Use the Basic Annotation to Override Defaults
By all means, use @Basic to override the default true value of optional to false, for those fields that are not actually optional (I often find that to be most of my attributes).
9. Go Ahead and Use the Column Annotation
Even if you are not interested in generating a schema or DDL from it, you should not hold back on using the @Column annotation. It tells the reader of the code about important information related to the attribute. This is stuff like nullability, length, scale and precision.
10. Do Not Use java.sql.Date/java.sql.Timestamp in Domain Model
Instead, use java.util.Date or java.util.Calendar. Using the types from the java.sql package is a leakage of concerns into the domain model, that we do not want, nor need.
Just remember to put @Temporal on date and calendar attributes.
Reviews about IT companies and products
This blog is about new technologies, news from Cyberworld, new products and softwares, hardwares, gadgets. Reviews and opinions about IT companies and products. All the "tech-nicks" that you need to know about Cyberworld.
http://codevalley.blogspot.com
http://codevalley.blogspot.com
Photoshop Tutorial
Photoshop is a standard name in graphic design for web use, print layout, and more. Recognized world-wide as the industry-standard, Photoshop offers one of the most robust graphics editing experiences available. Learn tips and tricks, cool effects, and how to use the Photoshop tools more effectively.
http://pisiform.blogspot.com
http://pisiform.blogspot.com
Cell Rater
The Ultimate Guide to cellphones. Why settle for one of the half dozen phones offered by your mobile carrier? There are hundreds of phones all over the world compatible with your service, and you don't have to lock yourself into a contract. Cell Rater brings some of the worlds most exclusive handsets to you with the latest news and detailed reviews.
Windows Vista Recovery Disk
So, you have just purchased a new PC and you finally have Windows Vista! I'll bet you got a great deal as well from one of the major manufacturers. Unfortunately, as much as every manufacturer attempts to be different and better than the competition, they all have one thing in common. One thing missing actually. None of these PC and laptop manufacturers provide you a real Windows Vista installation or recovery CD with your purchase. Instead, they bundle what is referred to as a "recovery disc" (that is if you're lucky - in many instances, you are only offered a a recovery partition) with your machine and leave it at that. The recovery partition will recover your system to factory settings, if need be.
It doesn't matter that you just paid a thousand dollars for a machine that comes with a valid Windows Vista license - computer manufacturers and Microsoft shift the onus to the consumer. it is your responsibility to backup your data and make the required recovery cd's. Manufacturers simply provide the means to do so through a create recovery disk utility in Windows Vista. OK, in all honesty, maybe they have a point, but really, how much does a recovery dvd cost the manufacturer in the overall price of the PC or laptop? Ever heard of common courtesy, or just a nice thing to do?
The problem is, with Windows Vista, the installation media serves dual purposes. It is not just a means to get Windows Vista installed, but also the only way of recovering a damaged installation. The Windows Vista DVD has a "recovery center" that provides you with the option of recovering your system via automated recovery (Vista searches for problems, and attempts to fix them automatically), rolling-back to a previous system restore point, recovering a full PC backup, or accessing a command-line recovery console for advanced recovery purposes.
Microsoft seems to have realized this problem, and have thankfully made a recovery disc for this purpose. The recovery disk contains the contents of the Windows Vista DVD's "recovery center," It cannot be used to install or reinstall Windows Vista, and just serves as a Windows PE (bare bones) interface to recovering your PC.
Just burn with a program such as Nero, onto a CD or DVD, and then boot into it with your PC!
Download the cd:
Vista.part1.rar
Vista.part2.rar
It doesn't matter that you just paid a thousand dollars for a machine that comes with a valid Windows Vista license - computer manufacturers and Microsoft shift the onus to the consumer. it is your responsibility to backup your data and make the required recovery cd's. Manufacturers simply provide the means to do so through a create recovery disk utility in Windows Vista. OK, in all honesty, maybe they have a point, but really, how much does a recovery dvd cost the manufacturer in the overall price of the PC or laptop? Ever heard of common courtesy, or just a nice thing to do?
The problem is, with Windows Vista, the installation media serves dual purposes. It is not just a means to get Windows Vista installed, but also the only way of recovering a damaged installation. The Windows Vista DVD has a "recovery center" that provides you with the option of recovering your system via automated recovery (Vista searches for problems, and attempts to fix them automatically), rolling-back to a previous system restore point, recovering a full PC backup, or accessing a command-line recovery console for advanced recovery purposes.
Microsoft seems to have realized this problem, and have thankfully made a recovery disc for this purpose. The recovery disk contains the contents of the Windows Vista DVD's "recovery center," It cannot be used to install or reinstall Windows Vista, and just serves as a Windows PE (bare bones) interface to recovering your PC.
Just burn with a program such as Nero, onto a CD or DVD, and then boot into it with your PC!
Download the cd:
Vista.part1.rar
Vista.part2.rar
Solar Powered Video Game Chargers
Are you looking for an easy way to keep your handheld gaming system powered up when your on the go? Look no further than the Solio line of hybrid solar chargers. These three units allow you to plug into the sun and with the appropriate tip charge your Gameboy Advance, Nintendo DS, or PSP. The chargers range in price from $79-199, and the gaming tips are available for all three models for just $9.95.
In addition to lengthening your on the go gaming session, the Solio chargers also help you lower your carbon footprint. Over the next five years, the US will import and use over 2.5 billion chargers for handheld electronics. These chargers will create a total of 9 billion kilograms of carbon - equivalent to the pollution created by five year's-worth of driving by 1.8 million American cars.
Subscribe to:
Posts (Atom)