How to develop web applications – primary web development concepts 1.0

GET vs POST
When to use GET and when to use POST? a coool explanation is here following are some exerpts:

Rule #1: Use GET for safe actions and POST for unsafe actions.

Rule #2: Use POST when dealing with sensitive data. ( like passwords, so it can’t be seen/bookmarked/used later in urlbar)

Rule #3: Use POST when dealing with long requests.

Although the RFC doesn’t lay down any length-related guidelines, Internet Explorer – with its insistence on finding ways to make things difficult for us – enforces a maximum URL length of 2,048 characters.

Rule #4: Use GET in AJAX environments.

GET requests are more useable:

  1. GET requests can be cached
  2. GET requests can remain in the browser history
  3. GET requests can be bookmarked
  4. GET requests can be distributed & shared
  5. GET requests can be hacked

SOAP vs REST

There are a lot of chatter whether to use REST (Learn REST) or SOAP. Simply put, REST is very simple to use (a simple http GET request with https://www.mycompany.com/program/method?Parameters=xx will be enough for REST) and implement. But REST assumes that the connection is point to point (not processed through many servers). it’s rather hard to actually implement REST services to be truly distributed. There comes SOAP with a mandatory POST method and a fat ass data packet. Meanwhile a good read will be WSDL (Web Service Definition Language). a XML based specification for a certain web service, about the url, methods, data, comments.. etc..

To summarize their strengths and weaknesses: (as described in here)

*** SOAP ***

Pros:

  • Langauge, platform, and transport agnostic
  • Designed to handle distributed computing environments
  • Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors
  • Built-in error handling (faults)
  • Extensibility

Cons:

  • Conceptually more difficult, more “heavy-weight” than REST
  • More verbose
  • Harder to develop, requires tools

*** REST ***

Pros:

  • Language and platform agnostic
  • Much simpler to develop than SOAP
  • Small learning curve, less reliance on tools
  • Concise, no need for additional messaging layer
  • Closer in design and philosophy to the Web

Cons:

  • Assumes a point-to-point communication model–not usable for distributed computing environment where message may go through one or more intermediaries
  • Lack of standards support for security, policy, reliable messaging, etc., so services that have more sophisticated requirements are harder to develop (“roll your own”)
  • Tied to the HTTP transport model

However, since advent of Web 2.0 (it is the sophisticated name for interactive web movement where users are not only content viewers, but content creators as well), all the applications are becoming RESTful.

Now how to request for a page/service through PHP

naive way: user headers.

but hey, wait. headers *redirects* the page ot the other page. here we are trying to just silently send request to certain web url and get the output back. for this, in php our best bet is curl.

now for a GET request, it’s easy . just a function (not curl. native php)

$result = file_get_contents(http://asd.com/service/method?id=value);

for a post request, easy way is to use curl in php

sample code:

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://www.example.com/yourscript.php"); curl_setopt($ch, CURLOPT_HEADER,false); curl_setopt($ch, CURLOPT_POST,true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_POSTFIELDS, array(     'field1'=>'some date',     'field2'=>'some other data')); $result = curl_exec($ch); curl_close($ch);

for sending data over http, the url needs to be encoded. in php there’s a cool funciton to do that. urlencode.

without the curl library it’s now posible in php to send POST data itself. but that’ll be th enxt post after i try all these stuff to complete my RESTful service for my website!

NOTE to me: JSON, XMLHttpRequest, XML and XSLT, the ugly iFrame, AJAX

I will be back people.


Advertisements

Configuring GTK+ 2.x in Netbeans

Well, hello after a long time. Blogging needs time and that is the thisng I do not seem to have much these days. 😦  I even can’t remember the last time i took a photo. really busy over making the unique file browser for Sahaj Linux.

As I am working in GTK+ 2 and the main lot of programmers (except me) sees Netbeans as their wordprocessor (!) … A friend and fellow programmer insistemd me to try Netbeans once.  Thus I begun.

Well, if you don’t have the entire package of Netbeans, you will have to download the C/C++ Development Pack. After this, the netbeans will be able to detect and debug general C/C++ code. However, one have to configure Netbeans to include support for external libraries like GTK. Her’s how to do it:

Open a project in netbeans. right click onto it and get into Properties. In the Build menu (probably the 2nd menu in the tree), click “C compilers”.

Here you’ll see the option “Include Directories under “General” Tab. Click on browse (at left a small button) and include all the dependecy for gtk like cairo, gtk, glib, pango, atk, libpng, libjpg, etc.. detailed picture given below !

Screenshot for including necessary libs for gtk+ 2

Now again We have to configure the Linker of Netbeans. We go to Linker > Libraries > Add Library. Here you’ll have to choose the libgtk xxxx.so file from “/usr/lib/” .. so go in the folder /usr/lib. Now select the File type to  “.so” (dynamic library) from the default “.a” (static library). unless this you’ll not find libgtk.so ! Again the following picture explains all this!
Linker configuration for GTK+2 in Netbeans

Now you are done. Enjoy writing GTK code with Netbeans.

P.S: Though I was referred to write code on Netbeans, I am back to GEdit again! I’ll let you know How and Why in the next post where i’ll show you how to make GEdit a really cool code editor.

Adios!

Getting Linux back after Windows reinstallation

Many of us have dual-boot system which have Linux and Windows( or any other, say, Mac OSX etc… ) both installed. We have a operating-system-choice screen just after BIOS gets checked, by which we can choose, which OS to load in a session.
This is the Boot Loader (usually GRUB or LiLo). It has some commands (editable) by which it just gets the control from Master Boot Record (MBR) and chainloads the volume boot record (VBR) of the active (primary) partition where the bootable system image resides.

During Linux installation, we have GRUB installed in our system, so it can directly detects the other already installed operating systems in the HDD. Thus it produces the OS-Choice screen at the startup and we can choose which OS to load.

But the problem arises, if we have to reinstall/repair the previous OS in the same partition it was before.
i.e : s’ppose, windows was in C:\ and we’re trying to reinstall windows again on same partition C:\

During installation, every OS overwrites the MBR and keeps it’s fresh copy. So, if you have previously installed the Bootloader (e.g : GRUB ), then it’ll dessapear and you’ll not be able to boot into Linux. After startup, system will directly boot into Windows.

Now, get one point clear that the Linux OS is still intact. you just have lost the pointer how and from where to load it. Because, it was the job of your bootloader installed in MBR and you’ve overwritten the MBR, your bootloader is now history! 😛

Clearly, the solution is to install the bootloader once again so that it can detect both ( even more than 2 ) the OS and give you the sweet OS-Choice screen once again! 😀

Here’s how to do it :
step 1) put your Linux CD/DVD and boot from it in restore mode. After that, if all goes right, it’ll give you a command console.
step 2) type
chroot /mnt/sysimage
it loads the system image and present the root console.

step 3) reinstall GRUB into your MBR by typing
/sbin/grub-install /dev/hda (for ATA hard drive )
or
/sbin/grub-install /dev/sda (for SATA harddrives )

After this reboot the system and you’re done! 😀

NOTE :
I have a complication regarding the correct partition of the system images of Linux. I solved it by correcting the GRUB command. Here’s how I did it. 🙂

I went into edit command. there I saw 3 commands. The first command was for selecting the proper partition, the second was for lading the system image, and the third was initrd command.

The first command looked like,
root (hd0,1)
I just edited it to
root (hd0,2)
and everything fell perfectly into place. 🙂

One more thing… The above mentioned procedure will not work if you install windows in any other partitions other than the previous partition in which it originally was. in that case, GRUB will not be able to detect that. 😛

Hope you’ll find this tutorial useful. Wishing you people a smooth sail.

Be wise, Use Linux

Counter Strike in Linux… :)

Hey all you Counter Strike 1.6 fR3/\ks out there… 🙂
Good news! You don’t have to depend on Windows anymore for playing your favourite game, “Counter Strike 1.6”. :p It’s right here in our very own, Linux! 😀

Yes, CS 1.6 is duly available for Linux also.
I’ll now guide you through the procedure to install official “Steam” in your Linux Box.

Firstly, we’ll start by creating a directory ( in your home folder, preferably ) called hlds.

mkdir hlds

Now we’ll go to the directory created (cd hlds) and there we’ll download a file named, hldsupdatetool.bin

wget http://www.cstrike-planet.com/dls/hldsupdatetool.bin

after downloading, we’ll change it’s permission to executable by,

chmod +x hldsupdatetool.bin

and then run hldsupdatetool.bin

./hldsupdatetool.bin

After agreeing the conditions 😛 by hitting yes, if all goes well, you’ll have a file named “steam” in that folder. If you get any error message ( Like me :p ) like
'uncompress: command not found'
take heart… don’t get frustrated mann…
just uncompress it by

ln -s /bin/gunzip /bin/uncompress

after you finally got the file named steam, you again change the permission of it to executable by,

chmod +x steam

and run it by

./steam -command update -game cstrike -dir .

Yay, you’re done….

now just sit back for a considerable amount of time leaving it all for the installer to download and install CS 1.6 for you.
A word of caution though : This process will take about 11/2 – 2 Hrs. So, just make sure, you have enough time for it… 🙂

Best of luck at the Arena…

And, do tell me how this helped you if we meet somewhere… be it Dust 2, Train, Cbble, inferno or Nuke… 😉
I’ll be as /i/ VooDoo Child ~ozh in there… 🙂

Best of luck, Happy Hunting dudes… 🙂

Writing in Bengali in Fedora 9…! ফেডোরা ৯ লিনাক্সে বাংলা লেখা।

Yes buddies, I know that this is a pretty cliche topic and there are maybe many sites explaining the same. I also took help from specilaly অঙ্কুর বাংলা Website and some more sites which I forgot to bookmark 😦 . Specially, Project has many activities which ranges from Localisation to creating a fantastic বাংলা বানান নিরিক্ষক অভিধান for Firefox.

Well, I’m telling you *My* Procedure! It’s simple like hell.

I went into ” System > Preferences > Hardware > Keyboard ”

Then, I selected, Layouts in there. After that, I clicked “Add” and found out বাংলাদেশ প্রভাত and  ইন্ডিয়া বাংলা keyboard layouts. I added them and set the USA Layout to the defaults. There are other layouts for other Indic languages also. You can Try out that if you know them!

Now I right clicked into my gnome panel and selected, “Keyboard Layout Indicator” such that I can switch to any desired keyboard Layout when I want to.

Whoa, I’m done. Now Selecting the indic layouts, I can write in bengali in anywhere… 🙂

But now, one problem arised. I wasn’t being able to write composite letters in bengali. that is যুক্তাক্ষর . Fortunately, Kushal da was online ( who is also in অঙ্কুর বাংলা Project among his many activities and busy schedulle ) and I mailed him my problem. The response was instant, to-the-point and a complete breeze. He just said, ” use ‘/’  ” … That is, k / t = ক্ট ! 😀

More support about the layout and writing যুক্তাক্ষর can be found in here.

Whoa. I’m done fianly and chatted for almost 4 hours with her in bengali… 😀

Hope, This will be a little help to all those, who still stumbles writing in Indic font. This’s also a reason among a thousand, why one should switch into Linux… and trash Windoze 😛

Everything is sooo cool in this OS. I just Love it… 😀

Trouble with “/etc/X11/xorg.conf”

Heya… It’s been a long long time since my last post in here. I’m sorry, I went totally haywire from the Linux world… Only Academics and all that Master’s Degree plans… 😛

Well, Since 2 weeks, I’m back with my Linux box tweaks. Tonight, At very early hours, I was trying to install the new nVidia Driver into my machine. They have closed the rpm repository so the installation is a complex procedure now… You’ve to configure the xorg.conf file, then close the X server, and then, another problem may arise if you don’t have any precompiled kernel but only the binary image of it. I had, unfortunately nVidia installation software stopped me right there and as it was very late, I was gearing up for bed, then the bolt came from the blue.

I tried to restore my X server back by [ALT+F7] and it failed, giving a quick and scrolled error message. What I guessed that, It has something to do with what I’ve changed.

/etc/X11/xorg.conf

I just checked, what was wrong with that, ( I had my command line shell 🙂 )and I found I’ve left the server name in

Section “Device”
Identifier  “Videocard0”
Driver      “nvidia”
EndSection ,

The root of the problem was the word, nvidia. Which I recalled, earlier was, nv. Actually what happened, HAL didn’t find any device named nvidia… that’s it so X server failed.

I changed that. and restarted.

Everything worked fine, until the login screen. I was shocked to see that my keyboard is not working! 😦

I logged into my root accnt by help of on-screen keyboard and again oened the xorg.conf file. There I found,

# keyboard added by rhpxl
Identifier  “Keyboard0”
Driver      “nvidia”
Option        “XkbModel” “pc105”
Option        “XkbLayout” “us”
EndSection

How silly of me… 😦 I’ve mistakenly put the keyboard driver also as nvidia which was earlier, intuitively, “kbd”

I changed that and restarted again.. and Whoa… Life is peaceful once again.. ! 😀

Motto of the text : Always have a backup file while tweaking with system files !

Hope this experience will someday be a help to you… 🙂 Signing off… Need a sleep seriously… 😀 … Good Night… or rather, mornin’.. 🙂

Love you sweetheart… 🙂