Sunday, July 8, 2012

Overriding properties in CSS

While working on the design of my site using Twitter's bootstrap, I had a hard time resizing the height of the search box, which due to a strange reason was looking much smaller than it should.
The first thing I tried was making my own CSS file and make a class style.css . However even after adding that class to my search box div, there was no change. This is because the class contained within the bootstrap.css is more specific. To enforce a change however all that needs to be done is add !important following the property in css. As an example :-
.search
{ height: 28px !important; }

Tuesday, July 3, 2012

multi-dimensional array in php

Similar to Java, php also allows us to have multi-dimensional arrays. As an example of this
$food = arrays('healthy' => arrays('salad', 'chicken') , 'unhealthy' => arrays('ice cream', 'pizza'));


Now to access salad element, the following needs to be done.

$food[healthy][0];

associative arrays in php

Associative arrays are similar to arrays discussed previously, however they have a key attached to a value.

As an example

$food = ('pizza' => 300 , 'pasta' => 100, 'ice cream' =>100 );


to get the value stored at key 'pizza' :-


$food['pizza'];

arrays in php

An array can be simply defined as a collection of data stored within one variable. To do this in php initialize the variable using the dollar sign, and then in the right hand side add the values within rounded brakets each data entry separated with a inverted comma. Bear in mind that the types of the data should not be different for each value within that array.

An example of an array :-
$food = ('apple', 'chicken' ,' sandwich');

Thursday, June 28, 2012

php functions on strings

The following are some functions which can be used on strings in php.
  1. str_word_count :- str_word_count has different results depending on parameters.
    • str_word_count($string_variable) returns the word count
    • str_word_count($string_variable, (0,1 or 2)) where
      • 0 returns the word count(the default option)
      • 1 returns an array
      • 2 returns an associative array
    • str_word_count($string_variable, (0,1,2), ' (something to be included as a word for ex '.!&' ').
      • different arguments included next to each other.
  2. str_shuffle($string_variable) :- shuffles string_variable
  3. substr($string_variable,  starting position, ending position) :- returns the substring
  4. strlen($string_variable) :- returns the length of the string_variable
  5. strtolower($string_variable) :- returns $string_variable with all characters in lower case
  6. strttoupper($string_variable) :- returns $string_variable with all characters in upper case 


Tuesday, June 26, 2012

Ruby On Rails...



despite being all set for php, I decided to change gears and opt for the relatively newer and rather more exciting ruby on rails framework. After installing it on my Ubuntu machine which isn't that too complicated, I started following this book http://ruby.railstutorial.org/chapters/beginning#top by Michael Hartl.


I reached around chapter 8 only to realize that copying and pasting stuff wasnt really turning out to be helpful as I had hoped it would be. Therefore I am now going to do stuff from the scratch avoiding the book as much as possible. 

UPDATE :- I am now back to php, seeing that the syntax of it confused me pretty much!

Wednesday, April 18, 2012

installing LAMPP in Ubuntu

I finally felt it was the right time to learn php, and now here's the thing about php, you actually need to set up a virtual server on your own machine to test your php files. So here is how to set up the server:-

  1. Go to http://www.apachefriends.org/en/xampp-linux.html and download the files.
  2. Once downloaded, extract them.
  3. Open up terminal and type in sudo nautilus
  4. Move the extracted lampp folder to /opt/
  5. To start the server type the following command in terminal sudo /opt/lampp/lampp start
If you get a message saying that any service is already running, that is because well they are... so say for instance if you have installed apache (the web server) because you were following some instructions saying you needed to or some other reason , well either un-install it or you will have to do sudo killall "the service which was already running" each time you want to run the lampp server

To test your php files all you need to do is create a directory within the /opt/lampp/htdocs/ folder and place the files inside it. Now fire up the browser with /localhost/"name of folder created in htdocs"/"name of php file".php