Categories
News

Facebook Developer Garage in New Delhi, India

facebook developer garage A good news for all Indian Facebook Apps Developers. Tekriti Software is organizing Facebook Developer Garage event in New Delhi on 25th April 2009.

Facebook like other parts in the world, growing in India in terms of popularity and user base.

As Facebook platform and its apps can be nice source of revenue, many developers are willing to develop for Facebook. So this event can be a good starting point for newbies who wants to try their hands on Facebook platform.

The event is free and open for all. To confirm your attendance for event, head over to this event’s Facebook page.

More details about this event are not yet available but you can same Facebook event page to get your query answered.

On side note, our parent company rtCamp, will be having openings for full-time Facebook developers soon. Point of telling is that, Facebook apps development is enough skill to get you a job! 😉

Link: Facebook Developer Garage Event | Google Map

Categories
Tutorial

#6: PHP Tutorials for Beginners – Logical Expressions

Coding ImageAs we have already learnt about data types, we will now study about logical expressions and also about switch. Logical expressions are basically if else statements. You might have given orders to somebody like if jam is available then apply that on bread else if butter is available, then apply that else don’t apply anything. We can also write such commands in PHP. It is a very important and useful topic. So let us learn about it!

Categories
Tutorial

#5: PHP Tutorials for Beginners – Data Types (Continued)

Diving into PHPIn the previous post, we talked about some data types – variables, strings, string functions and numbers. In this post we will talk about more data types which are floats, arrays, array functions, booleans and constants. We will also talk about type casting. So, without wasting time, let us start!

Categories
Tutorial

#4: PHP Tutorials for Beginners – Data Types

As we have already learnt about using XAMPP and other tools, PHP open and close tags, phpinfo function, printing text on screen, adding comments in PHP files and some conversation on what does the server do, it’s now time for learning the various types of data. In this post, we will talk about variables, strings and numbers.

Variables

Simple definition of a variable is that it is a symbolic representation of a value. But as its name says, it can change or vary. In PHP, variables are going to

  • Start with a $ (dollar) sign.
  • They can be then followed by a letter or underscore.
  • They can contain letters, underscores, numbers and dashes.
  • There can NOT be any spaces in them.
  • They are case-sensitive.

You can see the following examples of variables. Also see the comments with them for the explanation.

$devil
$Devil //see the capital D
$devilsWorkshop //can contain capital letters in-between
$devils_workshop //can contain underscores
$devils-workshop //can contain dashes, but I recommend not to use these
$D3v1ls_W0rk-sh0p //can contain numbers, capital letters, underscores, dashes
$_devil //can contain underscore in the beginning, not recommended as PHP already uses single underscore itself to define a certain type of variable
$__devil //can contain as many underscores, not recommended as it is difficult to make out just by seeing that how many underscores are there

Now, as we have learnt about the types of variables we can have, we must do some experiment. Here is one!

<?php
$devil = 1; //assigning a number to a variable, numbers don't need to be wrapped with quotes
echo $devil."<br />"; //note that we can put a period and merge two strings
$devilvar = "Hello World"; //settings a variable
$devilVar = "Hello World!!"; //note here that the "V" is capital and the variables are case-sensitive, so $devilvar is different from $devilVar
echo $devilVar."<br />"; //it will echo back "Hello World!!", not "Hello World" as the variables are case sensitive
$devil = 2; //we can reset a variable
echo $devil; //the new value which is "2" will be echoed.
?>

Here is an online demo.You can view the highlighted source here.

We will do the same thing which we did before, go to htdocs and create a new file named “variables.php”. Paste this code there. And access it on http://localhost/variables.php.
You will understand everything by reading the comments which are written in the code.

Strings

We have been using strings everywhere without even knowing about that. For example, “Hello World” is a string. Let us learn more about them! Here is a code, read the comments in the code too (actually that’s the explanation).

<?php
echo "Hello World<br />"; //we can wrap strings within double quotes and also put HTML code in them
echo 'Hello World<br />'; //we can also wrap them with single quotes
$devil = "Welcome in the World"; //we can assign strings to variables
echo $devil."<br />"; //we can echo variables, while we also merge HTML with them
echo "$devil of Devils!<br />"; //we can put the variable within the double quotes - not recommended as if you put $devilof, it will try to search for a variable called $devilof
echo "{$devil} of DevilsWorkshop!<br />"; //We can wrap the variable with curly brackets and put it in within double quotes - Recommended
echo '$devil of Devils!<br />'; //this technique doesn't works with single quotes, it will echo "$devil of Devils!" as it doesn't try to parse any variables within single quotes
?>

Here is an online demo.You can view the highlighted source here.

So, we came to a conclusion that we should wrap all variables with curly braces and always use double quotes (Well, it all depends on you, it is not necessary. We can still use periods to put variables in single quote strings).

String Functions

Well, I can’t cover all the string functions, but I will cover the basic ones. You can see the exhaustive list of functions on PHP.net and can take more reference from there. Here is a code by which you can understand it better!

<?php
$devil = "Devils"; //assigning a string to a variable
$workshop = " Workshop"; //notice the space in the beginning
$tut = "php tutorials"; //assigning another string to a variable
$dw = $devil; //the value of $devil is now also the value of $dw
$dw .= $workshop; //we can also merge 2 strings like this, notice the period with equals to sign (".=")
echo $dw."<br />"; //echoing the merged string with HTML
// Below are some functions which we can apply, refer to PHP.net for more functions
echo strtolower($dw)."<br />"; //this will make all the letters of the string to lowercase and echo the string. Note that a function can be used with another function.
echo strtoupper($dw)."<br />"; //this will make all the letters of the string to uppercase and echo the string.
echo ucfirst($tut)."<br />"; //this will make the first letter of the string capital. Note - we are using $tut here, not $dw
echo ucwords($tut)."<br />"; //this will make the first letter of each word in the string to a capital letter. Note - we are using $tut here, not $dw
echo strlen($dw)."<br />"; //this will count the number of letters in the string and echo it
echo $trimmed = $devil.trim($workshop)."<br />"; //See here, that I have made a new variable and also echoed it. The new variable contains $devil as it is and trim function is applied to $workshop which will remove all the whitespaces (spaces, tabs etc.) from the beginning and ending.
echo strstr($dw, "W")."<br />"; //this function is string in a string. It finds a string in a string and returns the string which is after the string we are trying to find with the string we are trying to find. So, here $dw is the string and "W" is the string which we are finding. It should echo "Workshop" as the echo function is also there.
echo str_replace("Workshop", "Head", $dw)."<br />"; //this function will replace the word Workshop with Head in the string $dw. So, it should echo back "Devils Head"
echo str_repeat($dw." ", 3)."<br />"; //it will repeat the string 3 times (see the last value entered in the function. Also note that I added a space after $dw within the function.
echo substr($dw, 7, 4)."<br />"; //it will echo 4 characters which are after 6 letters in the string (see the 3rd and 2nd value of the function)
echo strpos($dw, "W")."<br />"; //it will echo the position of the letter "W"
?>

Here is an online demo. You can view the highlighted source here. Hope you understood this long code. If you have any doubts, then please ask in the comments section.

Numbers

As we have already talked about variables, strings and strings functions, we will now talk about numbers. You know what are numbers.. don’t you? No?

So let us try PHP doing some maths for us. Here is an example!

<?php
$d = 1; //note that the numbers don't need to be wrapped with quotes
$w = 2; //another number
echo (10 - ($d + $w)) / (($w * $w) + ($d + $w)); //this is some basic maths, guessed the answer? The answer is 1.
echo "<br />"; //echoing html (for a line break)
$dw = $d += 4; echo $dw; //this will add 4 to $d and it will echo it. Note that we do not need to make separate lines for each bit of code, the semi-colon (";") tells PHP that a command is over
echo "<br />";
echo $dw -= 3; //it will subtract 3 from $dw (newly made string) and will also echo it
echo "<br />";
echo $w *= 4; //it will multiply $w with 4. Note - here we have used $w, not $dw
echo "<br />";
echo $w /= 2; //it will divide $w with 2
echo "<br />";
$d++; echo $d; //it will increase the value of $d by 1 and echo it
echo "
";
$d--; echo $d; //it will decrease the value of $d by 1 and echo it
?>

Here is an online demo. You can view the highlighted source here. That’s all with number! 😉

Hope you enjoyed the post and had loads of fun learning data types today! My next post will contain about the other types of data types which are floats, arrays, booleans and constants. We will also talk about typecasting.

Image Credits: IT Bench

Categories
Tips

How To Optimize Your Website For Printers Using A Separate Stylesheet

First of all I would like to explain what I mean by Optimizing a website for Printing using following screenshot.

A highly optimized website for printing

Optimizing a website for printing means removing the extra stuff like logos, forms, navigation links, advertising, blog rolls, flash widgets, etc from the website while printing and give a clean preview of your website.

We can do this with the help of CSS. In CSS itself we have many ways but the most easy way is to use <link> element and add specify print as value for media attribute.

<link rel="stylesheet" href="filename.css" media="print" />

In the above example, we declared that stylesheet “filename.css” should be used whenever media is print. Thus it will be used while printing the document only. These styles will have no effect on the display of the document when viewed using a monitor,  handheld or any other non-printing device.

We have CSS files for 10 different kinds of media like…

  1. all
  2. aural
  3. braille
  4. embossed
  5. handheld
  6. print
  7. projection
  8. screen
  9. tty
  10. tv

For Optimizing your website paste the code below in between <head> tag.

<link rel="stylesheet" href="filename.css" media="print" />

Note: You can change the filename.css to any file name you wish but don’t change the extension.

Now you have to code the CSS part. If you know CSS well you can code it yourself if you don’t just copy-paste this code.

body {
font-family: arial,helvetica,sans;
font-size: 13px;
background:fff;
color:000;
}
// This makes the backgroud white and text to 13px with black color
a,a:visited,a:link {
color:#0000ff;
text-decoration:none
}
// Do no underline links and hyperlinks in blue
.noprint {
display:none
}
// This will hide the items

Copy the code above and give it a file name and paste it in the head section like this

<link rel="stylesheet" href="filename.css" media="print" />

How to use the code:

If you want to hide a image or flash widget use this code

<span class="noprint">
<!-- The embedded code should be enclosed by these tags -->
</span>

And if you want to hide big items like navigation, ad space and all which are in div tags use this

<div id="navigation" class="noprint">Content</div>

Note: Change navigation to your own id I mean which is used in site.

And if you want to give your users a option like “Print this page” use this code.

<form>
<input type="button" value="Print this page" onClick="window.print()">
</form>

or simple print link like this

<a href="#" onClick="window.print(); return false">Print this page</a>

Usage:

  1. Users can save ink in their printers as many useless elements won’t get printed anymore.
  2. Print stylesheet encourages users to take printout of your page for offline reading. This may increase your traffic.

Hope this tutorial helps all of you to improve your site.


[Editors Note: This post is by Kranthi. He blogs on Devils Workshop only about blogging and website optimization tips. You can follow Kranthi on Twitter.

If you too like to write for Devils Workshop, please check this. Details about our revenue sharing programs are here.]

Categories
Tutorial

#3: PHP Tutorials For Beginners – Writing The Code

CodingWelcome Back! Today we will start with the basics on – “Writing the Code”. We will talk about how the PHP code is written, simple basic code like echoing Hello World, adding comments in the PHP file etc. We will also talk about the official site of PHP and how it can help you discover new things. I hope that you have installed the recommended programs of which I had written a couple of days back.

Categories
Tutorial

#2: PHP Tutorials for Beginners – Recommended Programs

Download ButtonHi again. Well, before starting off, I want you to download some softwares which will help you a lot in coding. These are recommended programs, and are not necessary. But in the tutorials, only these softwares will be used, so I request you to download & install these. As I use Windows Vista, I will be giving the tutorial to install the programs for Windows. Links to download & documentation of same programs for other OS also given in this post.

Categories
Tutorial

#1: PHP Tutorials for Beginners – Introduction

This is post post in new series started by PHP Tutorials for Beginners by Gautam. This post provides general introduction to PHP and some historical facts about it! As PHP if language top-blogging platform WordPress uses, it is good to have little understanding of PHP. This will help you for sure in your blogging carrier even if programming is not your prime occupation.  (Added by Editor)

Categories
Editorial

We are hiring – WordPress Developers

wordpresslogo.pngOur parent company rtCamp is looking for expert WordPress developers.

Main role will be to create WordPress themes. Ability to code wordpress plugins will be added bonus.

This opening is strictly for our Pune, India office and this is full-time office job. Of course, you can work from home once you get used to with things we are working on.

I repeat, we are looking for full time WordPress developers only.

Job Profile Links: View | Download | Apply

Categories
Analysis

The truth about Virtual or Swap Memory

A lot has been said about how virtual memory increases system performance. After RAM, people often suggest the second best way to get a speed boost is to increase the size of pagefile.sys. Its time for debunking some myths about virtual memory.

Here are a few false beliefs about virtual memory

  1. More is better.
  2. Setting a static swap file size will make virtual memory more effective.
  3. Emptying the Pagefile will increase system performance.

All of these are false!!!!

What is virtual memory?

Without turning this into a lecture on Operating Systems, I’ll explain what Virtual memory is all about and keep it brief.hdd Virtual memory is a technique which gives an application program the impression that it has contiguous working memory, while in fact it may be physically fragmented and may even overflow on to disk storage.

Now, lets say I have 512MB RAM and running Adobe Photoshop and Firefox simultaneously. On wndows XP, assuming 200MB is already allocated to the kernal, the user applications i.e Photoshop and Firefox are left with 300 MB of space. Firefox will run smoothly while you’ll notice lag while working with photoshop.

This is due to pagefaults which occur when the required amount of RAM is insufficient and data needs to be fetched from the hard disk. Firefox can accomodate itself well within 300MB of RAM but for photoshop it isnt a sweet deal. Thats where virtual memory kicks in, the OS reserves some portion of the hard disk as memory, hence the name virtual. As HDD space is higher than RAM, programs  use virtual address ranges which in total exceed the amount of real memory.

Problem with virtual memory

As the memory available for the system increases, you’d expect the performance to increase. To a certain extent it does help but as read/write speeds of electromagnetic HDD are very slow compared to the semiconductor based RAM, it doesnt help even page file increases twice the size of your main memory. Simply put, having over 1.5 GB of pagefile for 512 MB RAM is not benefitial.

Now adays, RAM has become very inexpensive and 4GB RAM in dual channel is very common. I prefer to disable page file as it saves me unnecessary read writes cycles on the HDD while also conserving my laptop battery. 4GB of memory is enough for most people and disabling the page file has given be better results. It even has long term benefits as it prevents undue HDD activity and increases its life.

Best way to enable virtual memory

  • If you do not plan to upgrade to 4GB memory, then you can still make the best of your page file, by keeping it in a separate Hard drive altogether, the read write headers are spared of the extra overhead as pagefaults are dealt with in the other hard drive.
  • Never, keep the pagefile in a different partition than that of Windows in the same HDD. Meaning, if you have only one hard disk then you should keep the pagefile in the same partition as that of Windows and not a different partition of the same hard drive as many people believe. As, doing so results in the read/write heads requiring to travel large distances spanning partitions back and forth!

I hope this mini guide on virtual memory help the readers. 🙂


[Editor Note: This post is by guest blogger Vaibhav Kanwal. He blogs at Calling All Geeks about technology.

If you too like to write for Devils Workshop, please check this. Details about our revenue sharing programs are here.]