Thursday, July 4, 2013

Maximum number of Collinear Points | Java

I came across this question to find the maximum number of Collinear Points.
I have used a Binary Search Tree(BST) structure to keep track of all the gradients between the different points. Another approach which could have been simpler would have been to use a HashMap. However, considering that there would be a limited number of gradients, unless its a curve... a HashMap would have resulted in occupying far much space compared to a BST.
Here's my attempt at it.

Wednesday, July 3, 2013

Checking for Palindromes in Java

In our first year at KCL, I remember a lab assignment to write something which would check for palindromes. So when recently I came through this question apparently posed during a Facebook interview to check for palindromes whilst ignoring spaces, I felt this shouldn't be mind bogging.

It certainly isn't. In my code below, I have created an internal private class Cursor, which as its name suggests will act as a cursor on the String. The cursor can move one character at a time, either backwards or forwards.  Two cursor objects will be initialised, head and tail. The head will move from the first character whereas the tail will move from the last. This will be so until they reach opposite ends and the head is at a position lower than the tail.

To avoid spaces, I loop the head cursor, until it finds a valid character. I follow this by looping the tail cursor until it finds a valid character as well. And then finally compare them, if they dont match then the test is terminated with the method returning false.

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

Thursday, December 9, 2010

Failed Student Protests ....

“This exit is closed because of Student Protest, please use the other exit at Strand,” this is what greeted me as I tried to exit the Charing Cross Station (close to Trafalgar Square) from the closest route. I still didn’t realize the scale of the protest until I actually came out where I was greeted with slogans against the mammoth increase in Tution Fees and one individual in particular, deputy Prime Minister Mr Nick Clegg. .
As they went along, they went not alone, they were accompanied with full protocol from the police. Infact the police had blocked many roads for them. As thestudents from King’s College about to disappear in sight, students from London School of Economics marched on and it seemed as if I was witnessing an actual war, the students against the state.
However, amazingly while at one side I could see huge bursts of energy, all was lost when I entered the class room. More than half were present for the class, it felt as if more of us there were not concerned at all.. That’s why it’s a lost case. Many of us think the protests might end up violent as they have been before and hence its not worth the trouble. This is where the movement has failed, for the full strength of the students had not been harnessed.
What many of us fail to realize is that in the current circumstance it is unrealistic to imagine the state paying for the tution fees for world class education. Education in America is still strong even though they have fewer concessions from the state, and they dont have a cap such as that here. Better universities charge more and offer more scholarships to deserving students. 
the resolution has  passed in favour of an increase in tution fees then it’s a failure of Nick Clegg for failing to hold on to his promise and also of students, for marring the protests with violence and scarring the hell of students who had some what interest in it. 

watch these clips which i have recorded


Cheers.

Sunday, September 12, 2010

Apple iPod nano sixth generation




When Apple names things, it takes it seriously. We saw what it did with iPhone. It changed the meaning of a phone completely. Now with the iPod nano, it attempts something similar. It's called the Nano because its ==> Nano Tiny. At about 1.54 inches, Apple makes a point that it can shrink anything. The previous generation has been shrinked by almost 50% to make it nanoer.
However it must be noted that in exchange for the size, Apple has removed some of the features of the previous generation. Most notable amongst them are Video Playback and camera. This may be because Apple intends to sell this device to those who are more interested in the size than in its features

Tuesday, September 7, 2010

Google : everywhere!!!

Google started as a search company, way back in the late 20th century.. Now it has expanded itself way beyond search. From mail to office suite, it has left no stone untouched. Now its time for the company to be aggressive with VOIP, with it buying Global IP solutions.
The company has started free calls to US and Canada landline and mobile. Rates for other countries are cheap as pointed out by its own chart here on this website--->https://www.google.com/voice/rates 
All you need to do is open your gmail account. On the left navigation pane you will find a Call Phone button. Click it and install the required number. Now dial any number for free in States and Canada.
Skype is in a tough position... lets see how it manges to compete with Google's marketing strategy... But for now enjoy the calls!!!
Peace....