Solution to ‘Wireless disabled by Hardware switch’

Ohhh … Suddenly my wifi goes off( a combination of DELL with Ubuntu natty) and got a display – wireless disabled by hardware switch. Got down to googling and finally got this.

To get back your wifi to start working, type in the following:

$:  sudo rfkill list

You will get back something like this.

0: dell-wifi: Wireless LAN
    Soft blocked: yes
    Hard blocked: no
1: dell-bluetooth: Bluetooth
    Soft blocked: no
    Hard blocked: no
2: phy0: Wireless LAN
    Soft blocked: yes
    Hard blocked: no
4: hci0: Bluetooth
    Soft blocked: no
    Hard blocked: no

As you could see (0,2) the Wireless Lan has been soft blocked.  We need to unblock it to get it up and working properly.

$: sudo rfkill unblock 0

$: sudo rfkill unblock 2

 

Restart your networking

$: sudo /etc/init.d/networking restart

 

and yup! the wifi should be back now.

RubyconfIndia 2011

May 27,28 – Attended Rubyconf India 2011 held at Royal Orchid hotel, Bangalore.’  For some one who has less than a year of hands on with ruby, it was great hearing from the giants – the very Matz himself expressed his love for the community(in his own peculiar Japaneese way), Ola bini, Chad Fowler,  Brian and others. What in short ? – awesome 2 days.



Module functions as class and instance methods

Consider you have a module and a class.

module Mymod and a class Myclass.

The situation in hand is such that certain functions in the module need to end up being instance methods of the class Myclass and certain functions need to be Class methods.  You could very well imagine of such situations. Consider you are using ActiveRecord and have a sub class Subscription in correspondence with a DB table. You want to insert logic, within the module, that would work in each of the following case.

1) When a subscription fails or succeeds.

2) When an unsubscription fails or succeeds

You do this.

module SubscriptionLogic

   def  after_sub

      ….

   end

   def  after_unsub

     ….

   end

   def  after_sub_fail

     ….

   end

   def  after_unsub_fail

      ….

    end

end

class Subscription

   include SubscriptionLogic

   …..

end

You insert the logic as functions of a module, say SubscriptionLogic. Ideally you want the methods containing the logic to be instance methods of the class Subscription. You include the module SubscriptionLogic in the class and you avail all the functions in the module as Instance methods. Now you consider the case when an unsubscription fails – i.e, there is no existing subscription so that an unsub could take place.  No way is it possible that you could have a function ‘logic_after_unsub_fail’  in the module SubscriptionLogic and use it as an instance method, simply because there is no instance available.  You think and decide to use the function as your class method, but you have ‘included’  the  module in your class and hence its not possible to use it as your class method. You cannot extend the entire module coz , ideally you want the logic to be instance methods.

So you could get this solved up by a simple piece of extra coding.

module SubscriptionLogic

  def  after_sub

      ….

  end

  def  after_unsub

      ….

  end

  def  after_sub_fail

      ….

  end

  module ClassMethods

      def after_unsub_fail

           ….

      end

      def self.included(base)

          base.extend(ClassMethods)    # base pertains to the class within which you include the module.

      end

   end

end

Now within the class insert this line.

class Subscription

   include SubscriptionLogic

   extend SubscriptionLogic::ClassMethods

   …..

end

Back after a Long Gap…

Haven’t Written any thing for  quite some time now. It was last november that i actually sat down to write something. Started off my professional career then and obviously was busy with work and stuff. Need to get back to writing stuff, little and bigger stuffs that i have learnt while working. In between i have fallen in love with a a new language – Ruby, the popular choice for web apps these days.  From a person who never had any kind of fondness for OOP, i have started loving to talk about about objects and classes. Learnt the difference between fun coding and professional coding. These 6-8 months has really been a learning curve for me and i really do hope that my following posts would reflect that.

Getting started with PHP and apache

Someone who gives it a thought of using PHP , apache and stuff for the first time will be faced up with a few number of fixed problems . Configuring your apache server , establishing a connection between PHP and apache , stuffs like that . Here is a basic introduction to start using these things and kick off as a web programmer .

Obviously you need to have PHP and apache installed on your system .

$ : sudo apt-get install apache2

$ : sudo apt-get install php5-cli

$: sudo apt-get install libapache2-mod-php5

 

would get you apache and PHP installed on your system  .

Using the appropriate versions is left upto individuals .

Just have a peep into some of the files like :

/etc/php5/apache2/php.ini —–> You would see a lot of variables set to ‘ON’  and ‘OFF’ . You may well have to toggle those values as and when necessary .

 

Try starting , stopping and restarting your apache web server .

$ :sudo  /etc/init.d/apache2 start

$: sudo /etc/init.d/apache2 stop

$: sudo /etc/init.d/apache2  restart

 

Once everything is fine and and perfect  , try out your first PHP script . Script it , save it in a file with a ‘.php’ extension and put your file in the directory ‘/var/www ‘. Now you could access this script from your browser

localhost/’scriptname’

and you see the result right there in front of you . Thats just how you enter the world of web programming .

GreaseMonkey : Customizing your webpages

There would have been times when you would have felt if the web page in front of you behaved a bit more according to your like . This might specially happen if the page consists of forms that you fill with data directed to live servers .  In such cases you wouldn’t mind customizing the page to suit your needs so that you don’t do some nonsense that would result in chaos .

Firefox , i see many using it as their default browser , offers a plugin called ‘Grease monkey‘  that allows you to do just that . All you need to is to install the plugin , write your own javascripts , install them ( thats pretty easy to do ) and start using them  .

Write your javascripts to customize your webpage . What you need to do in addition is to add some metadata providing extra information to greasemonkey .

The meta data might look as follows :

 

 

 

 

 

 

The first and the last lines are necessary to indicate to the greasemonkey that the script it to be processed by it .

The name and the description are optional . It might prove helpful to you if you have scripted and installed a number of greasemonkey scripts .

The 4th an the 5th line of the metadata are extremely important and needs to be well understood . These lines tell the greasemonkey the URLs on which the script is to be applied and not to be applied .

@include -> specifies the URLs on which the script is to be installed . Here ‘*’ is specified which is just a wildcard and indicates that the script is to applied on all the sites  .

@exclude -> specifies the URLs that are to be left out . It is to be noted that @exclude is processed before @include .

This gives you an idea of the metadata part of the script . Now you may write your own javascript , add your metadata at the beginning and save the file with the extension ‘ .user.js ‘  .

To install the script , open the file in firefox and you would see an option ‘install’ . Just give a click and you are ready to use your greasemonkey script .You could manage your script , disable it , uninstall it as well . Just click

Tools —-> Greasemonkey —-> Manage user scripts ….

Having another plugin ‘firebug’ may help you in the process of writing the script . This allows you to view the html code of the webpage that is infront of you . Infact the plugin is almost a necessity to help you write efficient code with greasemonkey .

Now you may start writing your own greasemonkey scripts and customize any of the webpages as and according to your like . It’s also to be understood that greasemonkey is a plugin of firefox . If you use Google chrome as your browser , you wouldn’t need to install any plugin . The facility to customize the webpage is provided by default . You may use the same code that you have written to work with greasemonkey . The metadata and the process of installing is the same and obviously the results are the same as well .

Using Screens

You might have often had the experience where you would have had to open quite a few terminals on your screen simultaneously . This might often be the case when you are doing stuffs like data processing on particular files and you intend not to sit idle during that particular time . What you do is to keep unnecessary number of terminals open on your screen .

You could get rid of this by using the ‘screens’ option in Linux . This allows you to enter a new screen where you could perform time consuming processes like a data processing operation using the  ‘awk’  command . Start the process in the screen , exit the screen and now do your own stuff in the main console , go back to your screen after a while and view the results of  whatever operations you had performed . You could do all this stuff without the necessity of opening terminals again and again .

Create a new Screen :

$ : screen -S ‘Screen name’

To detach from the current screen :

Use CTRL + a + d

To terminate a screen :

Use CTRL + d

To attach an already created screen :

$ : screen -x ‘screen name’

You could keep on creating screens within screens and keep going on as and when needed  .