Ph: 277212429492

Archive for June, 2008

Don’t Let the “Smart” Way to Write the Swap Function in C++ Fool You

11

Over the years many beginning programmers have shown me two different versions of C++ code for swapping the values of two variables. I am now starting to get tired of correcting the wrong version of the two, especially because of the disappointment that I get to see written on the face of those who thought theirs to be a very clever way of writing code. (Even if the version was correct, I don’t know why they take such personal pride in the code. Obviously they have not invented the code; it has been circling the Internet or the general student community for many years, from where they have merely copied it.)

The first and the correct version for swapping values of two variables, in C++, is like this:
[cpp]
template
void swap(T &a, T &b)
{
T t = a;
a = b;
b = t;
}
[/cpp]

Simple, straightforward, and correct.

The second, wrong version goes like this:
[cpp]
template
void swap(T &a, T &b)
{
a = a + b;
b = a – b;
a = a – b;
}
[/cpp]

The openly asserted advantage of this version is that one variable is saved in this case. But the real, hidden attraction is that it appears to be smartly written code. If only the version was correct too. The problem with this version, of course, is that it is useless for any type that doesn’t support arithmetic operations. It works fine for integer type for example, most of the times at least. It is not guaranteed to work even for floating point variables. But what if I want to swap the values of two Colour objects? Two Shape objects? The requirement that the type support addition and subtraction operations for its objects to be swappable is very absurd.

More problems with the second “smart” version:

The code fails utterly when you pass references to the same variable!
[cpp]
int a;
//read something into a
::swap(a, a); //BOOM! ‘a’ is now corrupted and beyond recovery.
[/cpp]
The call to swap() in this case should have been a “no operation” like it will be with the first version.
The code fails even for the integers when the the sum of two passed variables exceeds the maximum integer limit on that machine. The code is also needlessly unnatural. Human beings don’t swap things by indulging in addition and subtraction activities. Unless a person knows that the second version works for at least the integer type (some of the times), or verifies it manually by working through it logically or with a large number of example cases, it is difficult to just see and “get” that the code indeed does the swapping operation. The second version indeed uses one less variable than the first version but at the same time uses three additional arithmetic operations.

There are similar clever ways to swap two variables(using XOR operation, or macros for example), but all of them have one or more problems of similar kind. The best way to swap two variables is definitely the natural way to do it. By the way, parts of the above explanation apply to swapping variables in most other languages too(can’t think one where it doesn’t). Clever code is useless code if it isn’t also correct at the same time.

WordPress Upgrading Experience With Automatic Upgrade Plugin

1

Finally took the bite and tried out the upgrading process of my WordPress blog using the WordPress automatic upgrade plugin. Tried it directly with my main blog with not even a single test run before this.

WordPress Automatic Upgrade allows a user to automatically upgrade the wordpress installation to the latest one provided by wordpress.org using the 5 steps provided in the wordpress upgrade instructions.
The whole process was relatively smooth and void of many surprises. I wish that the output messages from each test were accumulated together and displayed somewhere(a right sidebar?) so that it gives some structure to the upgrade progress and also keeps links to important downloads always visible.

The place the plugin broke-down was when re-activating all the plugins once the upgrade process was complete. I got the error message asking me if I am sure repeat the action. It never budged even an inch from there, so I quit it and activated all my plugins one by one manually for almost fifteen frustrating minutes. Reason? WordPress doesn’t only takes its own time but also refreshes the whole page for every plugin activation. Why not do the operation asynchronously? At least the location on the page where I am working will not be lost this way, saving me the constant scrolling.

My one complain with the WordPress Automatic plugin is that it doesn’t allow my own WordPress archive to be uploaded and used instead of the “latest” version automatically downloaded from WordPress.org. It’s a good default value for those who can’t be bothered but I would definitely like to use a Subversion WordPress package for my blog. I have been using the svn install method for over an year and it makes the minor upgrades such a breeze that I got totally used to it. And in one fluid motion, automatic upgrade plugin replaced my svn install with the normal one before I could realise what I was going to lose.

I also realised that there is only “Deactivate All Plugins” link on the “Plugins” page where as I would like to see a “Remember Currently Active Plugins and Then Deactivate All Plugins” option so that we can restore the previously active ones with a single click.

How To Create a Single-Click Link to View All Unread EMails in GMail

0

It was one of the requested features in my now almost two years old “GMail Wish List”. I wanted one click access to all of my unread emails only. There is still no such ready-made solution in GMail but I am happy that I can at least create one now, thanks to GMail’s advance search operators and the new “Quick Links” feature introduced as part of GMail Labs experimental features. Follow these five steps to create a custom link to fetch all unread emails from the GMail inbox.

Sign-in to your GMail account. Go to the Settings page and click on the Labs link.

If it is visible, you can also click the green funnel like icon sitting just to the left of “Settings” link(it is not visible when no GMail Labs feature is selected).

(If these links are not there, then you have to first enable the GMail Labs feature for your GMail account. Look for a link at the top-right corner of your GMail inbox page to do so.)

On the Labs settings page, enable the “Quick Links” feature, which should be the first feature listed on the page.
Now enter the text “in:inbox is:unread” into GMail search box as shown in the below screenshot, and click the “Search Mail” button(or press ENTER).
Find the “Quick Links” box in the left sidebar(should be somewhere below the “Contacts” and “Labels” boxes) and click the “Add Quick Link” link in it.
Enter some readable text for this custom link as shown in the screenshot below.
Your custom link is piping hot and ready now.

Just click on it whenever you want to load all the unread messages in your inbox. Alas there is no way to just drag this “Quick Links” block and place it at the top of the GMail page.

You can similarly create custom links using other search operators; refer to GMail help for more advanced search operators. These search operators can also be used to create filters and label the messages.

Dreamhost Invitation Codes Give Four Times The Normal Bandwidth and Disk Space

I got this email from th Dreamhost folks couple of weeks ago and they sent me five special invitation codes that can be used to sign-up for Dreamhost web hosting packages but get four times the normal bandwidth and hard disk space. Here is the complete text of the email:

You just got five DreamHost Invitations!

Hey Tabrez!

This email is to let you know that you, yes you, have just been given
five (5) oh so special DreamHost Invitations you can use to invite your
friends and colleagues to DreamHost!

Of course, they don’t NEED an official invitation to sign up, but if you
email them and tell them to use one of these five invitation codes:





277212429492 670907616224 450568037263 134970060629600482886073

… they will get all these super special advantages not available any
other way:

* They will get four (4) times the normal disk and bandwidth!
* If they choose our five-year plan, they’ll get $150 off!
* If they choose our ten-year plan, they’ll get $200 off!
* YOU will still earn a full $97 for each person who signs up!

That means these five invitations are worth like, $485 in your pocket!
(Each code is good for only ONE sweet DreamHostering referral!)

Tell your invitees to use the 12-digit code you give them in the “Promo
Code” field when they sign up at:

https://signup.dreamhost.com/

So there you are. All the details are included in the quoted email text. Have a look at Dreamhost’s normal shared hosting package feature set. It comes with 500GB of disk space and 5TB of bandwidth. Now multiply that with four!

The reason for not posting the invite codes here earlier is that, in my opinion, even the normal amount of bandwidth and disk space that comes with Dreamhost shared hosting package is way, way more than most users will ever need. I don’t use even 2% of it. What then is the big attraction of four times of that bandwidth and disk space? If there is someone who hosts a lot of static content and this kind of huge disk space and bandwidth make sense to them, well, the invite codes are here for the grabbing:




Code 5 : 277212429492 Code 4 : 670907616224 Code 3 : 450568037263 Code 2 : 134970060629 Code 1 : 600482886073

There may be many such invite codes posted on Dreamhost forum too. Hosting service wise, Dreamhost is pretty good. Apart from the never going away ~30 minutes of downtime almost every week, I like their hosting service very much. For example, they have got very good wiki documentation. You can read reviews of it on the Internet.

Creating “Hello World” Web Application Using the Grails Framework

8
I have covered the installation procedure of Grails framework in my previous posts:
Setting Up Development Environment For Grails on Windows Vista/XP and GNU/Linux.

Just to make sure, check out again if the following environment variables are set properly on your operating system.

On Windows:
Set Grails environment variables in Windows
Set Java HOME environment variable in Windows
Set Groovy HOME environment variable in Windows
Set Grails HOME environment variable in Windows
Set Grails PATH environment variables in Windows

PATH should be set to something like(you can also check with ‘echo %PATH%’ on the command prompt):
c:\ruby\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin;C:\Program Files (x86)\Subversion\bin;%JAVA_HOME%\bin;%GROOVY_HOME%\bin;%GRAILS_HOME%\bin

On GNU/Linux:

# echo $JAVA_HOME :: $GROOVY_HOME :: $GRAILS_HOME
/usr/lib/jvm/java-6-sun :: /home/tabrez/groovy :: /home/tabrez/grails
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/tabrez/groovy/bin:/home/tabrez/grails/bin
Now you are all set to create Grails applications from the command line using your favourite text editor. IDE integration support for Groovy and Grails is not that great at this moment, I will write more about it in the next post. Let me just walk you through the creation of a sample Grails application from the command line.

Open the command prompt and run the following commands:

# grails create-app hello
[lot of text]
Created Grails Application at C:\Users\tabrez\grails_apps/hello
# cd hello && dir
.classpath
.project
application.properties
build.xml
grails-app
hello.launch
hello.tmproj
lib
scripts
src
test
web-app
# grails create-controller hello
[lot of text]
Created ControllerTests for Hello
Open hello/grails-app/controllers/HelloController.groovy using your favourite programming editor/IDE(e.g. SciTE, Emacs, Vim) and change its content to look like this:
Hello World program in Grails and Groovy
Run the web application and view it in the web browser.
# grails run-app
[lot of text]
Server running. Browse to http://localhost:8080/hello
2008-06-15 15:55:51.363:/hello:INFO: GSP servlet initialized

Now our application is running at the specified url. To invoke the controller that we had written earlier(Step 3), open the following url in a web browser:

http://localhost:8080/hello/hello/hello

And you should see the following output.
Grails Hello World program output in Web Browser
(If you are confused about the url: the first hello is the name of the application, the second hello is the name of the controller and the third hello is the name of the action to be invoked. In non-hello-world applications, these three will be different from each other!)

That’s it. You have created and executed your first Grails web application. Next up is IDE integration.

Resources:
For more information, refer to the following resources:
1. Grails QuickStart Guide
2. Grails Tutorials and Screencasts
3. The Definitive Guide to Grails (Amazon)

buy genuine Zovirax online purchase prednisone prescription online prednisone no prior script prednisone no rx needed order prednisone usa cod buy prednisone without rx from us pharmacy buy prednisone online without rx purchase prednisone without prescription order prednisone saturday delivery buy prednisone amex online without prescription ordering prednisone over the counter buy prednisone amex online without rx ordering Paxil over the counter order Paxil without rx needed order Paxil pharmacy Paxil overnight delivery fed ex ordering Paxil without a script order Paxil order amex order Paxil amex online without prescription buy Paxil pay pal without prescription order rx free Paxil cheapest Paxil available online purchase Paxil without purchase Paxil without prescription how to order Paxil online without a prescription purchase Paxil cod next day delivery buy discount Paxil online buy Paxil no visa online without rx prednisone cheap overnight fedex Zovirax canadian pharmacy Zovirax cheap overnight fedex purchase Strattera usa cod Cytotec online buy saturday delivery where to buy accutane buy Cytotec online overseas buy frontpage software cheap mortgage application software iphone software download plagiarism software to buy for parents Crestor side effects buy masterwriter software discount bmi sesac microsoft software downloads wm5 software download treo software download best antivirus software download cheap microsoft word software buy software for mac software discounts for educators microsoft office buy windows xp oem software buy flash cs3 software photoshop cs 5 full fashion conference italy buy Orlistat with amex windows 7 product key purchase online cheapest xenical available online prescription xenical online Zithromax uk sales where to purchase generic valtrex online without a prescription quality generic valtrex cheap valtrex usa (no prescriptions needed for Buspar|buy Buspar with no prescription|online pharmacies Buspar|Buspar cheap|buy Buspar without rx|purchase rx Buspar without|Buspar purchase online|purchase Buspar online without rx|purchase Buspar free consultation|buy Buspar Online|buy Buspar american express|buy Buspar Online|buy cheap Buspar with dr. prescription|Buspar side effects|fedex Buspar without priscription|overnight Buspar without a rx|order cheap overnight Buspar|Buspar toronto|uk order Buspar|Buspar no doctors prescription|Buspar mexico|Buspar order|no prescription Buspar with fedex|order generic Buspar|buy Buspar without rx from us pharmacy|prezzo Buspar|Buspar 10mg|Buspar from canada|purchasing Buspar without a script|buy Buspar australia|purchase Buspar visa without prescription|online purchase Buspar|buy Buspar no perscription cod|buy Buspar drugs|buy Buspar with visa|buy Buspar without rx needed|buy Buspar without prescription|buy Buspar no prescription low cost|purchase purchase Buspar no prescription cheap buy generic Valtrex buy cheap Nolvadex cod buy Nolvadex infertility in internet visa at Wisconsin Ontario omicrosoft office 2003 megaupload buy pharmacy Strattera waterview Buy genuine accutane online buy Cytotec online no rx Cytotec online buy nolvadex amex online where to buy synthroid in germany where to buy synthroid pills cheap discount Nolvadex overnight Accutane 20mg mexico buy zithromax overnight purchase online prescription zithromax without buy Nolvadex cheap cheapest Nolvadex available online buy Nolvadex without rx from us pharmacy buy Nolvadex without a prescription overnight delivery buy 20mg Nolvadex free shipping buy Nolvadex no prescription order zithromax overnight delivery buy zithromax 100 mg visa Valtrex without doctor prescription buying zithromax over the counter order zithromax with no prescription order zithromax 250mg mastercard order zithromax 250 mg visa order zithromax 500mg amex buy mail order Orlistat buy Valtrex online now Orlistat tablets Strattera best buy free fedex delivery Buspar buy cheap Finpecia under without rx purchase online finpecia without rx finpecia fedex no prescription buy line finpecia want to buy Maxalt in malaysia generic Crestor uk Buspar u.p.s shipping cod order cheap overnight Buspar free fedex delivery prednisone prednisone no script fedex buy valtrex cheap without prescription purchase Zithromax without purchase Zithromax no scams Arimidex delivered overnight order cheap overnight Arimidex want to buy Flomax in malaysia buy cheap Flomax without prescription purchase Cytotec over the counter fedex buy cheap Cytotec online free consult buy Cytotec online overnight adobe financial results microsoft office professional 2007 upgrade download microsoft office professional 2007 cheap Buspar by money order cheap valtrex uk purchase Proscar usa cod adobe lm service adobe after effects simple creativity latest adobe flash download buy Crestor amex Photoshop For Sale buy discount Tamsulosin line Autocad 2010 Review download adobe premiere complete removal of office 2003 adobe indesign cs2 where can i buy herbal Crestor where to buy Crestor buy Crestor online cod Buy Fincar online 5 mg mastercard cheapest price for microsoft office vio software discount coupon purchase Orlistat amex online without prescription adobe photoshop 6 cd key Cheap Software Buy Downloads For Photoshop flash catalyst sql ms office 2010 enterprise windows 7 upgrade oem Windows Server 2003 Standard Edition Downloads For Windows 7 Ultimate Buy cheap Valtrex without a perscription buy Crestor drugs Valtrex no prescription purchase Valtrex amex online without prescription Xenical Orlistat Flomax buy on line boilsoft viseo create new instrument logic studio 9 cheap purchase finpecia buy Strattera no prescription low cost Flomax best buy formica countertop buy Prednisone no prescriptions cheap indesign cs android acdsee buy Flomax australia generic Valtrex online download de driver para corel windvd buy microsoft office online cheap generic Valtrex online buy Flomax online no prescription buy pharmacy Flomax waterview price of valtrex buy valtrex doctor prescription buy generic Crestor purchasing prednisone without a script order generic Tamsulosin buy Buspar without a rx cheap digital video want to buy Buspar in malaysia buy Crestor now buy Valtrex without a rx purchase rx Valacyclovir without Bupropion buy Bupropion buy no perscription Amitriptyline buy discount Zithromax cheapest Zithromax available online how to order Buspar online without a rx purchase prednisone cod next day delivery where can i purchase prednisone online prednisone online cash on delivery microsoft office 2010 3 user license cheap mac desktops no prescription Orlistat cod delivery Acrobat 6.0 Professional Oem Version Windows 7 buy Valtrex where order Orlistat no rx Microsoft Windows Xp Purchase buy Valtrex legally buy cheap Proscar without prescription buy cheap online pharmacy Buspar generic Zithromax usa accutane 40 mg delivered overnight buy accutane 40 mg with no prescription media 8 oline cheap cs software buy Flomax online us pharmacy cheapest Buspar available online where can i purchase Buspar without a prescription sony oem software Valtrex from india Maxalt pharmacy Prednisone prescription order buy Crestor overnight Buspar shipped by cash on delivery purchase Proscar online with overnight delivery prezzo Valtrex buy Valtrex shipped cod Proscar no prescription overnight Proscar overnight no consult where to purchase cheap Cytotec no rx Cytotec to buy canadian prescriptions prednisone where to buy Prednisone online Prednisone buy Prednisone Proscar online no rx overnight where can i buy Valtrex online without a prescription buy valtrex legally order Valtrex without a rx overnight shipping c.o.d prednisone purchase Prednisone money purchase where to buy generic Crestor online without a rx buy Cytotec cheapest Cytotec without rx medications buy Zithromax on line buy rx Maxalt without how to buy prednisone online without rx Buy Finpecia 1 mg online finpecia overdose excel new window windows for loop microsoft office 2008 for mac home student cheap collection software virtual dj software web design software mac cheap or discount photoshop software load windows xp buy Orlistat legally Rosuvastatin generic order buspar pharmacy dreamweaver cs4 windows mobile opera Maxalt online adobe photoshop price epson creativity suite
Go to Top


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser