Monday, September 11, 2006

Shutup PHP @ $%!

OK.. I'm getting a bit carried away here.

I saw a bit of code in PHP like ..
$contents = @file_get_contents($filename);

But what is the @ before the function call?? As bad as I am with googling I was not able to get some good docs on this. The best info I got was from meeting notes which says that its called the shut-up operator.

So then I backtracked to the PHP manual and found Error Control Operators. The doc says..
"PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored."

Yet another example of a lazy programmer trying to code before reading docs

Monday, September 04, 2006

Re: On the road



Took this on ride to San Francisco on Sunday. It's directly across the Oracle HQ. There are infact two billboards along the highway. Really nice to see Ubuntu get some (well deserved) publicity.

Saturday, August 26, 2006

Internet Explorer on Linux??

You mostly want to check for web page compatibility with IE if you're doing some web app stuff. So whats the solution if you prefer to use a linux distro rather than Windoz??

Enter ies4linux. ies4linux installs IE binaries over Wine. Wine is an Open Source implementation of the Windows API on top of X and Unix. ies4linux has a script which will download the IE setup files right from the microsoft site, and install over Wine. The best part is that you can install multiple versions of IE as well ;)

Saturday, August 05, 2006

Circular dependency between Tables in SQL

Update: Added a new way to solve the problem

Q) How had to create Tables with a circular dependency between them. Like

CREATE TABLE A (
....A_ID INT,
....PRIMARY KEY A_ID,
....B_FK INT,
....FOREIGN KEY B_FK
....REFERENCES B(B_ID)
);


CREATE TABLE B (
....B_ID INT,
....PRIMARY KEY B_ID,
....A_FK INT,
....FOREIGN KEY A_FK
....REFERENCES A(A_ID)
);

... now this will not work as during create, table B does not exist

A) So one solution is ...

CREATE TABLE A (
....A_ID INT,
....PRIMARY KEY A_ID
);

CREATE TABLE B (
....B_ID INT,
....PRIMARY KEY B_ID,
....A_FK INT,
....FOREIGN KEY A_FK
....REFERENCES A(A_ID)
);

ALTER TABLE A ADD COLUMN B_FK INT AFTER A_ID;
ALTER TABLE A ADD FOREIGN KEY B_FK REFERENCES B(B_ID);

A little bit of cheating does the trick :)



A) Another mysql specific solution is to use the FOREIGN_KEY_CHECKS variable.

mysql> SET FOREIGN_KEY_CHECKS = 0;
mysql> SOURCE dump_file_name;
mysql> SET FOREIGN_KEY_CHECKS = 1;

In the dump_file_name, tables can be created in any order without checking of Foreign Key constraints. So we can create tables with circular depenndencies

Monday, July 24, 2006

Java Generics FAQ

Java Generics FAQs - Frequently Asked Questions - This is a collection of answers to frequently asked questions (FAQs) about Java Generics, a new language feature added to the Java programming language in version 5.0 of the Java Standard Edition (J2SE 5.0).

Sunday, July 23, 2006

midday

I've always liked Mid-Day. I was pretty happy to find their site. But the format they have is pretty sucky. They provide a pdf for each page. So to read the entier paper, each page has to be downloaded separately. Not the most convenient thing.

I had started looking at Python a bit (going from the previous post). This seemed to be a pretty good project to use it for. The script - midday - automates the process. Given the paper you want (sunday|mumbai|vashi), it downloads each paper's pdf pages to your machine. It also uses a third party app - pdftk - to combine all the pages into one pdf. It needs to be downloaded and the location it was installed in needs to be passed into the script, but its not necessary. The script still works w/o it, but the pages are in separate pdfs. Should work on both Windows and Linux, but I've tested it only on Linux.

Overall, I liked Python quite a bit. Definitely more productive that Java... for something like this. Less upfront design needed, but is still structured. All the data structures mentioned in the last post came into play. Also, being interpreted, it's pretty easy to make it work on multiple platforms. The library is pretty extensive and with the easy ability to call other programs (especially in the linux environment where the culture is to create small programs that can be stiched together), python can be used for a wide range of applications.

Re: One Array to rule them all

Pretty late reply... I've been doing a bit of python of late. And although there isn't 'one array to rule them all' there are some similarities. In python there are three main data structures - lists, dictionaries and tuples. Lists are growable arrays (ArrayList in Java) and Dictionaries are associative arrays (HashMap in Java). Tuples are just containters to hold other objects (No equivalent in Java). They are immutable.

People always talk of productivity with dynamic languages. These built-in data structures are one of the main reasons for it. Sure Java has an amazing collections framework, but it's not a language feature. It's a framework built on top of the language. In python, these are part of the language... [] creates a list, {} creates a dictionary and () creates a tuple.

Having these be part of the language makes a huge difference. In Java, if you want to return multiple values from a method... either do something ugly like return an array with the values (the values have to be of the same type) or define a new class to hold the values and return an instance of that class. Quite a pain. In python, you just put the values (of any type) inside a tuple and return. As simple as that. And as you can imagine, lists are used a lot to hold collections of data. But probably the most used data structure is the dictionary. It's a dumping ground in all sorts of situations. You would think it would be a readability nightmare but it isn't. It's almost a convention in python and when you come across code, it is immediately recognizable. And these ds's combined make for more productivity gains. Tuples, being immutable, can be used as keys. Also, python has support for sets as well.

Saturday, July 15, 2006

Right to Information

The Right to Information Act (RTI) was passed in 2005 which empowers Indians to ask the Government about anything that concerns them. You can ask questions like why the road outside your house is not repaired or why some facility is polluting your city. The official is under an obligation to respond to your query within a stipulated period.

Now things are amazing on paper. I doubt that information comes so fast and easily. There are a few sites, organisations which assist in this.

See http://www.righttoinformation.org/

Maybe such a wiki like community site would better serve this purpose

Thursday, July 06, 2006

[Trackback]How to concentrate on writing

Something to think about..

<quote>
When I am up against a deadline and I absolutely, definitely have to get on with my work, I use a few tactics to force myself to concentrate:

1. Switch off email. I don’t start Outlook (or if I do, I disable all the notifications that tell me I have new mail).

2. Isolate myself. I use Bose noise-cancelling headphones but don’t plug them into anything. The silence really is golden.

3. Greed and guilt. I remind myself how much money I’m getting paid for a particular assignment and how ashamed I will be if I miss the deadline. This actually works sometimes.

4. Stop with the blog already. When I’m pressed for time, distractions like blogging and hoovering become very compelling. Knowing this makes it easier to resist.

5. Get up early. 6am is the most productive time of day for writing. No distractions. It also feels more virtuous than staying up late with work.

6. Little treats. I bribe myself: ‘Matthew, if you write another 500 words, you can have a cup of tea and a biscuit.’

7. Chunking. Setting a timer or alarm clock for 15, 20, 30, 50 minutes and doing nothing but writing until it goes off and then taking a break seems like a good way to make progress.

8. Go full screen. Switching Word into full screen mode (from the view menu) eliminates all distractions but the piece I’m working on.

9. Shitty first draft. Splitting the work into distinct writing and editing phases breaks the job down nicely and it takes off some of the pressure to ‘get it right first time’.

10. Change location. Sometimes, if I’m really struggling to get started, taking a laptop or my notebook to a cafe and scribbling out something there - a fresh new location - is a good way to jolt-start an assignment.

</quote>

Thursday, June 29, 2006

One Array to rule them all

I've been coding in php of late. So some thoughts on that...

Most languages have a few Data Structures (ds). Java has the excellent Collections framework which contains quite a few types of ds as shown in the figure



What I found in php was the array();

It can be used like...

$pasta = array('spaghetti', 'penne', 'macaroni');

In this case the array can be compared to a List or an Array.


You can also add an element to the end of an existing array with the array_push() function or remove an element from the end by using the array_pop() function.

Using the array_shift() and the array_unshift() function removing or adding elements to the beginning of the array can be done.

So now the array can work both as a Queue and a Stack.


Additionally it is possible to declare an array like..

$menu = array('breakfast' => 'bacon and eggs', 'lunch' => 'roast beef', 'dinner' => 'lasagna');

Here 'breakfast' is a key and 'bacon and eggs' is the value. Usually keys are numbers from 0 onwards. In effect our innocent array is now a Map as well.


All this is extremely great for learners. A few thoughts ..

1. The array exposes an API for all these ds'es. How can I enforce an array to act only as a Queue? Is the leakage of the abstraction too much.

2. How do they optimize? In Java I know the costs when I create a LinkedList or an ArrayList. Or use a TreeMap or HashMap. How is it done in php?

3. Also are there Sets in php where one object cannot be added twice. Maybe I am missing some ds library in php ;)

Wednesday, June 21, 2006

Tuesday, June 20, 2006

Get Functional

This article - Functional Programming for the rest of us - is like Argentina's performance against Serbia-Montenegro... beautiful.

Wednesday, June 07, 2006

Re: Have you ever felt this?

The "there's got to be more to life than this" deamon thread gets activated often. It's still at a way low priority level as compared to that dude but dunno for how long.

Sunday, May 21, 2006

Is India at the Tipping Point?

Here's the article... http://www.alwayson-network.com/comments.php?id=15024_0_38_0_C. It's by a Microsoft employee, but talks generally about whats good/bad about the Indian market. He covers pretty much the entire spectrum. Specifically, I thought this statement holds very true...

"It's also interesting to note that many Indians from the Valley are returning to India to set up their startup companies as well as to leverage the engineering/labor-cost advantages. While many startups we talked with have big ideas, they will need coaching to pitch ideas for funding and must be willing to accept possible failure, a normal part of the entrepreneurial culture.".

I've been following a few blogs by Indians who worked in software companies in the US and have gone back to start companies (startups) of their own. These are proper software companies, products based not services/bpo companies, targeting the Indian market. I feel this is an important trend. The backbone of the Indian IT industry is services, but it probably won't be able to sustain the growth in the years to come especially as salaries increase.

But at the same time, there are challenges. You have to think differently from if you were starting a co in the US because the market is so different. Broadband penetration is not high, payment procedures are different... credit card usage is not that common etc... But the guys who go back are smart and seem to take all this into account. Another thing is that the mobile market is booming and growing way faster than pc/broadband. So what about targeting mobile devices? That would be a huge market to target right off. I'm sure the big players like google, yahoo are already planning things, but there maybe opportunities to start some small super specific services?? What dyou think?

Friday, May 05, 2006

Bruce Eckel interviews.....

Bruce Eckel interviews.....

AndersHejlsberg
GuidoVanRossum
JoshuaBloch
MartinFowler
BillVenners

and others.

If you want descriptions.. go here else for direct mp3's go here