Tuesday, March 22, 2011

Exit on interstate: Left or Right?

This is good one. Let's say you are on interstate and you don't know which side your exit is going to come for your town/city. Don't assume that it's going to be on right. Yeah most of the times that's true. Some times it does come on your left. So if you stay on right you are pretty much screwed.

So how do you figure it out? Solution is to look at the boards that show how far away your exit is going to be. For example, let's say your exit is going to come in another mile. The board shows the exit number in a small square on top of big square. Right? The big square shows the town/city name and how much distance is left for you to reach exit from there. Ok. So it has exit number, destination name and the distance left to exit. But it doesn't say anything about which side exit is going to come. Actually, it does. Just not explicitly.

Here is the clue. If the small square that has exit number on it stays on right side on top of the big square then your exitis going to be on your right. If it is on left side thenit comes on left. Simple, neat and effective. Right?

Sent from my phone.

House numbering based on direction

You guys ever wondered about house numbering system here in US. I did. You can easily determine which side the house or apartment is going to be if you know the direction you are walking.

If you are walking towards east even numbers come on your right and odd numbers on left. It is exactly opposite if you are walking towards west.

The same rule applies to north and south. North is like east and south is like west. As simple as that.


Sent from my phone.

Monday, March 21, 2011

PATH Trains: Time hasn't been changed

It's been more than a week since time change happened. Still these PATH trains haven't updated it yet. So much for saying we are fast.

Just now wrote them an email requesting them to update the time on the display screens inside the coaches. Hope they read the emails.

Let's see whether they oblige. Will let you know.

Sunday, March 13, 2011

Caffeine and InsomniaX for Mac OS X

I think I came across these two applications almost 2 to 3 years back. These are very useful in their own ways. First one, Caffeine, keeps your system screen from automatically dimming, going to sleep or starting screensavers. You can write a simple script to start and stop this application at certain times in a day so that it would come alive by the time you go to your office and turn off at the end of the day right before you leave your office. Check my previous posts for the scripts and setting up alarms through iCal.

The second application is InsomniaX. Did you ever wish that you could run your macbook even after closing the lid. I always until I found this as I don't like having any bit of light when I go to sleep and at the same time I always wanted to run some stuff on my mac while I went to bed. This is where this application came handy. Now you know what it is for. It just prevents the laptop from going to sleep even after you close the lid to keep the applications running.

I don't know how battery life would be affected because of these two applications. I don't like using Caffeine on my laptop as I think it would affect the battery life. But if you have desktop I highly recommend it. On laptops we might forget to turn it off and it eats the battery life off. I don't think this is the problem with the second one.

Just wanted to share. I'm sure you must be knowing about these apps but if you don't here you found it.

C program to check whether a given year is leap year

Program
/* This program checks whether the given year is a leap year or not */
#include <stdio.h> /* It's ok not to have space between include and <stdio.h> */

int main (void) /* It's ok not to have space between main and (void). You can drop void off too. */
{
 int year;
 
 printf("\nEnter the year: ");
 scanf("%d",&year);
 
 if ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )
  printf("\n%d is a leap year.\n\n",year);
 else
  printf("\n%d is not a leap year.\n\n",year);
 
 return; /* "return ;" works too. "return 0" works too. "return (0)" works too.*/ 
}
Compilation, Run and Output
[sreedhar@manchu2 cprogs_work_machine]$ gcc calendar.c -o calendar
[sreedhar@manchu2 cprogs_work_machine]$ ./calendar 

Enter the year: 2000

2000 is a leap year.

[sreedhar@manchu2 cprogs_work_machine]$ ./calendar 

Enter the year: 2001

2001 is not a leap year.

[sreedhar@manchu2 cprogs_work_machine]$ ./calendar 

Enter the year: 2004

2004 is a leap year.

[sreedhar@manchu2 cprogs_work_machine]$ ./calendar 

Enter the year: 2100

2100 is not a leap year.

[sreedhar@manchu2 cprogs_work_machine]$

C program to print fibonacci numbers

Program
#include <stdio.h>

int main()
{
 int a,b,temp,n;

 printf("\nEnter the number upto which you want fibonacci sequence: ");
 scanf("%d",&n);
 
 printf("\nFibonacci Sequence upto %d:\n",n);

 a=0;
 b=1;
 printf("\n%d, %d",a,b);
 while (b <= n)
 {
  temp=b;
  b=a+b;
  a=temp;
  if (b <= n) printf(", %d",b);
 }
 printf("\n\n");

}
Compilation, Run and Output
[sreedhar@manchu2 cprogs_work_machine]$ gcc fibonacci.c -o fibonacci
[sreedhar@manchu2 cprogs_work_machine]$ ./fibonacci 

Enter the number upto which you want fibonacci sequence: 21

Fibonacci Sequence upto 21:

0, 1, 1, 2, 3, 5, 8, 13, 21

[sreedhar@manchu2 cprogs_work_machine]$

C program for bubble sorting

Program
#include <stdio.h>

#define SIZE 5

int main()
{
  int a[SIZE],b[SIZE];
  int temp,i,j;

  printf("\nBubble Sorting\n");
  printf("\nEnter the %d numbers: ",SIZE);

  for(i=0; i<SIZE; i++)
    scanf("%d",&a[i]);

  for(i=0; i<SIZE; i++)
    {
      for(j=SIZE-1; j>i; j--)
 {
   if (a[j-1]>a[j])
     {
       temp = a[j-1];
       
       a[j-1] = a[j];
       
       a[j] = temp;       
     }
 }
    }

  printf("\nSorted numbers: \n");
  for(i=0;i<SIZE;i++) printf("%d ",a[i]);

  printf("\n\nIf you need to sort more than %d numbers, change SIZE in porogram\n\n",SIZE);
  
}
Compilation, Run and Output
[sreedhar@manchu2 cprograms]$ gcc bubble_sort.c -o bubble_sort
[sreedhar@manchu2 cprograms]$ ./bubble_sort 

Bubble Sorting

Enter the 5 numbers: 8 3 16 24 19

Sorted numbers: 
3 8 16 19 24 

If you need to sort more than 5 numbers, change SIZE in porogram

[sreedhar@manchu2 cprograms]$ ./bubble_sort 

Bubble Sorting

Enter the 5 numbers: 6 3 15 27 1

Sorted numbers: 
1 3 6 15 27 

If you need to sort more than 5 numbers, change SIZE in porogram

[sreedhar@manchu2 cprograms]$

PBS Script Generator: Interdependent dropdown/select menus in Javascript

PBS SCRIPT GENERATOR
SH/BASH TCSH/CSH
Begin End Abort

About Me

LA, CA, United States
Here I write about the battles that have been going on in my mind. It's pretty much a scribble.

Sreedhar Manchu

Sreedhar Manchu
Higher Education: Not a simple life anymore