Friday, 27 December 2013

Experimenting with Ubuntu...establishing internet

Hi there! Finally a post after a long time!
I have been experimenting with ubuntu these days! The first thing we need is internet. Perpetual connectivity is one thing we strive for!

So this post intends to cover two major issues I came against while establishing internet on Ubuntu. Ubuntu works in quite different way than windows so the BSNL or ISPs might not help you much in this case!

Initially, I tried establishing mobile internet (!dea Netconnect dongle), recently I tried establishing BSNL Broadband Connection.

Lets first talk about what is still fresh:

ESTABLISHING BSNL BROADBAND CONNECTION:

If you have already experimented a lot then you might be suffering a problem where wired network is  "unmanaged".

Solution:

First, remove the existing network configurations for eth* from /etc/network/interfaces. So the resulting /etc/network/interfaces will only has the following loopback interface.

auto lo
iface lo inet loopback



PS: If you are new to Ubuntu you might be finding difficulty to edit the file due to read only rights. Only root can modify the file. So I would suggest opening the file through terminal using this command:





$sudo gedit /etc/network/interfaces









                       

Note: sudo helps you to access files as root.You are asked to enter the password before the file opens. Make the asked changes. The changes can be saved now.

Now, enable wired network settings on NetworkManager by changing "managed=false" to "managed=true" in /etc/NetworkManager/NetworkManager.conf.

NOte: Open the file in the same way as above.

[ifupdown]
managed=true
Finally, restart NetworkManager to reload its configuration.

$ sudo service network-manager restart
Once you restart NetworkManager, you will be able to edit wired network settings in System Settings -> Network -> Wired.

Next , issue you would face is configuring the modem and defining the access point. Here it goes:

  1. Connect your ethernet wire to the port at the back of your computer.
  2. Fire up the terminal and type in sudo pppoeconf
  3. It should detect your modem.
  4. Keep on pressing enter. Fill in your user name and password when indicated.
  5. It should be easy to stick on to defaults.
  6. You should be prompted back to your terminal when it would say pppoe loaded. Simple. That's the end of terminal. Now go to System>Networking. Click on it
  7. Activate the Wired connection.
  8. Highlight the wired connection and click on properties.
  9. Check the box "enable the connection"
(Source: askubuntu.com)




These would definitely sort out the issue for you. Let's come to establishing net connectivity via mobile internet:

1- get the a readymade Script

If the link doesn't works, make a file named MobileBroadband-autoconnect.sh
with this Script:

#!/bin/bash

while true; do
    LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
    if [ $? -eq 0 ]; then
        #jdownloader is still in the download status so stop it because
        #internet is disconnected and jdownloader won't resume download
        #when connected again
        #jdownloader --stop-download
        #sometimes I can not get connected after disconnection when
        #I click on <name of the network connection>. I have to disable
        #and enable Mobile Broadband
        nmcli -t nm wwan off
        sleep 1
        nmcli -t nm wwan on
        sleep 1
        nmcli -t con up id "Tunisie Télécom / TUNTEL WEB DATA"
        #wait approximately 15 sec to get connected
        #if anyone can add better command to check for it just comment it :-p
        sleep 15
        #now connected to internet so start download
        #jdownloader --start-download
    fi
    #it does not worth keep it checking every millisecond.
    #my connection will be reestablished within 5-15 seconds
    sleep 2
    #if anyone can code it better please feel free to comment
    #TO-DO:: check for data received. if data < 15 KB after 20 seconds of connection
    #reconnect mobile broadband connection 
done


2- extract it to your home folder (or somewhere safe) and make it hidden by placing a period before it like this .network-autoconnection.sh (so that you won't accidentally delete it)

3- Give it execution permission like this: right click on it, go to "properties", then navigate to "permissions" then tick "Allow executing file as program"

4- go to t/media/infinite/New Volume/100/MobileBroadband-autoconnect.shhe Mint menu and type "startup applications"


5- click on "add" then "browse" opposite to "command" field to give the directory of the script (your home folder or wherever you've placed it) then give it a name in the "name" field, for example mine is "Tunisie Télécom / TUNTEL WEB DATA".


That's it guys!
Hope this may help you and you have your internet up and running!
Do drop by queries if you have any! :)

Thursday, 30 May 2013

Ruby on Rails with MongoDB

Lots of new techniques and web development simplified! As a part of some project I came across these names "Ruby on Rails", "MongoDB", "Mongoid" and these followed by several doubts! What is rails? What is MongoDb? How to incorporate MongoDB on rails?
So I decided to put it up on my blog to simplify and encapsulate the steps needed to be performed in order to get through it!

Ruby on Rails  is one of the most easy and efficient tools for creating any website! Especially those which have a database management system linked to it.
Ruby on rails with mongodb is one of the easiest ways to create data management website!

For more information about the two you can have a look at these links:
>> Ruby on rails
>> MongoDB

I struggled a lot to incorporate MongoDB and hence here follows a step by step instruction guide in order to have your rails running:

Lets create a demo app to understand it, open the command prompt with ruby on rails and navigate to the folder in which you are creating your rails projects:

>cd rails_pro
>rails new demoApp --skip-active-record

The folder demoApp will be created in the specified directory, now open the folder and open Gemfile in text editors like Sublime Text2, and add these two lines:

gem 'mongoid', "~> 3.0.0"
gem 'bson_ext'

Now...lets add a controller to our app...switch back to command prompt and type:

> cd  demoApp
> rails generate controller students

this command would create students_controller.rb in app>controllers and a students folder in app>views.
We will write code for these later, first lets create a model (which actually defines database) as follows:
Come back to cmd, type
> rails generate mongoid:config

This will crete mongoid.yml file in demoApp\config folder!
Further type:
>rails generate model student
This will create student.rb file in app\models folder.

Done? Now lets write code in these files:
>>1. Open student.rb in Sublime Text 2 and type:



To keep it short and simple, lets add just 3 functionality to the model/ table:
1.  list : will list all the existing records (will have corresponding view)
2. new: will display form to create new student's record (will have corresponding view)
3. create: will actually create the record (no corresponding view)

>>2. Now open students_controller.rb in Sublime Text2 and type:


>> Now lets develop corresponding views, create a 2 new files list.html.erb and new.html.erb, type the corresponding code (shown below) and save them inside app\views\students folder:





Its all done! Now comes the main step, but before that ensure you have done this:
# Open config\routes.rb and  remove # from the last line, so that the line is included:
match ':controller(/:action(/:id))(.:format)'

# Remove files from app\assets\javascripts and app\assets\stylesheets, these unnecessary cause ExecJS error!

Lets move to cmd now, open one more cmd and navigate to the directory where you have unzipped mongodb  and run command mongod.exe:


Leave this cmd as it is, and in the first cmd, type:
>bundle install
>rails s

Now switch to web browser and type: localhost:3000/students/list


You will get a view like this if any previous records are inserted, if not then "1 default" won't appear!
Type in URL: localhost:3000/students/new



Enter the details, click create, now when you move back to list, the new added record will be displayed! Hence you are able to establish connectivity between mongodb and RoR :D

This worked pretty well for me, hope this would have helped you! For any further queries do leave a comment I will get back to it asap.  

A secret love message ~

Hmm, so the trick of putting up a catchy seasonal title worked out, we got you here! Folks, we will be talking about a really cool tech...