Tuesday 7 February 2012

Disabling bluethooth and setting default screen brightness on startup(Ubuntu)

I have noticed a few annoying things in ubuntu, two of them are
  • By default system will power on bluetooth automatically
  • Screen brightness restored to maximum on every reboot
Hopefully we can make default settings to the above mentioned problems. All you need is to add a few lines of commands to rc.local file

Open rc.local :
sudo vim /etc/rc.local
Add the following lines to the file before exit 0
echo 0 > /sys/class/backlight/acpi_video0/brightness
rfkill block bluetooth
save and exit vim
The first one will set the screen brightness to 0 and the second one will disable bluetooth at startup.Reboot the machine to see the changes.


Wednesday 11 January 2012

Creating your own "cat" command

In this blog post I am going to explain how to create your own cat command :-) . we can do it with a simple 'C' program with command line arguments. We write a simple program with basic file operations and command line arguments.


Step 1: Open your favorite text editor
Step 2: Copy the following code to your text editor
/*
 @
 @ File Name   : mycat.c
 @ Author      : Prabhendu V Senan
 @ Description : This is a simple C program to display the contents of a file(exactly like the "cat" command in Linux)
 @                                                                          
 @
 */

#include
#include

#define INVALID_ARG_LIST 2


int main(int argc,char *argv[])
{

   FILE *pfile     = NULL;
   char *file_name = NULL;
   int fchars      = 0;
   int arg_index   = 0;

   /* If no file name is given then exit the program  */
   if(argc < INVALID_ARG_LIST)
   {
     printf("Correct usage is: mycat \n");
     exit(1);
   }

   for(arg_index = 1; arg_index < argc; arg_index++)
   {
 
   file_name = argv[arg_index];

   /* Try to open the file. If failed,Exit the program */
   if(!(pfile = fopen(file_name,"r")))
   {
     printf("Unable to open file!!\nEither the file doesn't exist or pemission denied\n");
     exit(1);
   }

   while((fchars = fgetc(pfile)) != EOF)
   {
       putchar(fchars);
   }
  
      fclose(pfile);

      pfile     = NULL;
      file_name = NULL;
      fchars    = 0;
   }
 
   return 0;
}
Step 3: Save the file(ex: mycat.c)
Step 4: Go to file location
            Example: cd /home/senan/myprograms
Step 5: Compile the file 
            cc -o mycat mycat.c in your terminal
Step 6: run the program by
            ./mycat /etc/passwd or you can copy the file to /bin in order to avoid the ./ usage. That is 
            sudo cp mycat /bin
Step 7: :-)

Saturday 3 September 2011

Changing GNOME 3 wallpaper

I have been using fedora with gnome 3 for many months.Even though GNOME 3 is a great release,its has some rough edges too.In this example I will explain how to change the wallpaper in regular interval(say 1 minute interval).Here I am using perl script to accomplish my goal.You can also use python to do the same.Following are the steps
  1. Create a directory(ex: /home/senan/wallpaper) and copy all the images to it or you can use the default wallpaper directory
  2. we will store the image names in array
  3. Then we will pick an image randomly and set it as wallpaper using gsettings every 10 seconds
use the following perl script to do the above things

#!/usr/bin/perl -w
#
# Author      : Prabhendu V Senan
# Description : This is a perl script for changing the Gnome wallpaper in a specified time interval
# File Name   : change_wall.pl
#

# Directory containing the wallpaper images
$wallDir = '/home/senan/wallpaper';

# Wallpaper change interval time

$interval = 10;

# First check whether the directory containing images exists or not

unless(-d $wallDir)
{
  print "There is no such $wallDir directory \n";
  exit();
}

# Parse the directory,get all the image filenames and fill it into an array

@images = `find $wallDir -type f | grep [jJ]*[pP][nN]*[eE]*[gG]`;

chomp(@images);

#if the directory has no images,Exit()

if(@images == 0)
{
  print "No Images found in $wallDir \n";
  exit();
}

my $nowShowin;

while(1)
{
   $nowShowing = $images[rand(@images)];
  `gsettings set org.gnome.desktop.background picture-uri "file:///$nowShowing"`;
   sleep($interval);
}

To run the script: Copy and paste it into your favourite text editor.
  1.  Save the file(ex:wallChange.pl
  2.  Make it executable(ex: chmod +x wallChange.pl)
  3.  CD to script dir and run the script :-)
  4.  To run the script during start up:Open gnome-session-properties->Add->Browse the script and add :-) 
  5. Restart your computer



Tuesday 23 August 2011

Writing a simple app to resolve IP Address from host name

In Linux and Windows we can use various command line utilities to resolve IP address from a host name. Here I am using visual studio 2010 to create a simple GUI app that will give the ip address of a user supplied hostname. It very simple to create an app like this using vs 2010 because we can make use of the existing base class libraries to accomplish the task.

First Open visual Studio->Create New Project

Language C# and choose windows Form Project.

For the GUI Part we need two text fields one for host name and one for IP Address. Also a button named  “Get IP”.In the click event of the button we write code to get ip address.After designing the UI,It will look like this










 To get the IP Address we need to use the following System.Net namespace like this
using System.Net;
 The above name space contains a class called  IPHostEntry and using the method Dns.GetHostEntry(),We can get the IP Address corresponding to a host name :-)
 IPHostEntry iHost = null;
 iHost = Dns.GetHostEntry(hostName);
 txt_ip.Text = iHost.AddressList[0].ToString();
To download the solution and executable file please click here



Friday 15 July 2011

My first look at fedora 15

Hello All, In this blog post I am going to take a look at Fedora 15 Gnome 3 desktop. Fedora is one of the Leading GNU/Linux distribution providing GNOME3 as Default desktop environment

Installing Linux is not a big deal now a days because tons of tutorials available on the internet. Also schools and colleges use Linux in desktops and servers. Here in Kerala almost  all the schools(as far as I know) use Linux to teach IT and I heard a news that they are switching to ubuntu from  a custom debian based desktop developed by the government IT Organization.

If you want to try or Linux you don’t need to write the ISO image to a disk. There are many software utilities available today  that can make a bootable Linux usb drive from the iso images(If your computer is capable of booting from usb drive) .One such utility is unetbootin. It support many Linux distributions and you can download it from here. . Fedora is also providing a live usb creator, for details click here

Let’s take  look at fedora 15

Look and Feel:

Fedora 15 comes with GNOME 3 Desktop environment. I am a big fan of the GNOME desktop and I used the live CD for installing fedora. GNOME  3 is completely redesigned  desktop environment with usability in mind.

After logging in you will be greeted with a desktop with no icons..wow I personally prefer that scheme because I don't put anything on desktop.It will be zen desktop with just  a wallpaper :-)

Where are the applications in GNOME3? For that just place your mouse on top of the activities on the top left corner of the screen then you can see the favorite’s panel, windows and applications. You can easily add an application to the favorite’s panel by just dragging and dropping the application to the panel.

The title bar has only close button so where is minimize and maximize buttons? Do they forgot to include that? No actually you don’t need those buttons because you can maximize a window by jut double clicking the title bar or just dragging it to the top of the screen. To minimize just use the middle mouse button click on the title bar. You can also put minimize and maximize buttons using gnome-tweak-tool

Tweaking Desktop:

The main thing I dislike in fedora gnome3 is the icon themes and shell themes. To change the themes and icons you can use the Gnome-tweak-tool. To install that you can use either yum or Add/Remove software (GUI). I will explain how to install Gnome Shell themes and Icon themes in another post.

Installing Applications:

To install or remove applications you can use the Add/remove software  application. LibreOffice is not included with the CD release,all the other common apps are already installed by default. To Install flash and mp3 plug-in you need to manually configure the repository :-( and details available on fedora wiki

The last thing is about shutting down your computer :-)

How do I shut down my computer because there is no shutdown option listed when I click the user name on the top right corner of the desktop.The trick is click on the username then a popup window will appear then press the 'ALT' key now the suspend will be changed to Power off

Conclusions:

Fedora 15 Gnome 3 is a great release and with many features however it has also some rough edges. At some places you still need to configure things using the command line in fedora.It will be good choice if you are not afraid of the commandline.So my suggestion is to use ubuntu if you are a NEWBIE because ubuntu is well polished compared to fedora. You don’t need any commandline skills(in most cases) when using Ubuntu.But keep in mind that ubuntu doesn’t  ship with gnome 3,they use Unity shell .You can install gnome 3 after installing ubuntu.

Saturday 9 July 2011

Using a Wi-Fi powered laptop as an Access point for sharing internet connection


In this blog post I am going to explain how we can use a Wi-Fi enabled laptop as an Access point for sharing internet .All you need is a Wi-Fi enabled laptop, a wired internet connectivity(idea netsetter, mobile modem, wired broadband).I am using  my Nokia E71 modem for setting up a Wi-Fi network on Windows 7 home premium

Step 1:

Connect your device to computer and establish a connection to internet.

Step 2:

Go to network and sharing center. For that right click the network icon on the taskbar 











In that open window select change adapter settings(top left corner of the window)








Right click the appropriate adapter and select properties. Since I am using E71, am going to take the properties for Nokia E71USB Modem. If you are using Idea Internet choose it



















Make sure that Allow other network users to connect through this computers internet Connection is Checked (Sometimes it will show a message about username and password, don’t worry just click ok).
Select Home Networking Connection: as Wireless Network Connection (It’s just blow the checkbox)
Now Click Ok button to finish adapter settings

Step 3:

If the connection is active, it will show a warning since the connection is active the settings can be applied only next time when the connection is active. Just disconnect and reconnect the device

Step 4:

Now we are going to create an Ad-Hoc network. For that do the following
Open Network and Sharing Center as Before









Click set up a new connection or network














Scroll down to bottom and Select Set up a wireless ad hoc network and Click next and again next
















Choose a name for the Network (any name), Security type and Security key. Here I chose No authentication (anybody having a Wi-Fi device can connect).If you want to control access then choose another security type. Make sure that save this network is checked, otherwise changes will be lost in next reboot
Click next and close the wizard

Step 5:

Now switch on your laptops Wi-Fi. Click on the network icon in the taskbar. You will see something like this


















Click Dragon Fly and click Connect button. We are done. Now it’s the time to check whether it is working properly or not. Connect to internet if your connection is not active. Take another wifi powered device and scan for network. Then connect to internet using the “Dragon Fly” access point
Happy Browsing J