Thứ Tư, ngày 29 tháng 4 năm 2015

BUG: Ubuntu 14.04 LTS not show USB 3.0 devices

Fix 1: sudo echo "blacklist uas" >> /etc/modprobe.d/blacklist.conf
Fix 2: sudo apt-get install libnss-myhostname

# sudo reboot

Chủ Nhật, ngày 26 tháng 4 năm 2015

Top 10 Inheritance Interview questions

1.what is inheritance?
  • inheritance is one of the oops concepts in java.inheritance is concept of  getting properties of one class object to another class object.
  • Inheritance represents the IS-A relationship,also known as parent-child relationship.
2.what are the types of inheritance?

1.Multiple inheritance( java doesn't support multiple inheritance).
2.Multilevel inheritance.

3.How Inheritance can be implemented in java?
  • Inheritance can be implemented in JAVA using below two keywords:
1.extends
2.implements
  • extends is used for developing inheritance between two classes and two interfaces.
  • implements keyword is used to developed inheritance between interface and class.
4.Why we need to use Inheritance?

1.For Code Re usability.
2.For Method Overriding.

5.what is syntax of inheritance?

public class subclass extends superclass{

//all methods and variables declare here
}

6.what is multilevel inheritance?
  • Getting the properties from one class object to another class object level wise with different priorities.
6.what is Multiple inheritance?why Java Doesn't Support multiple Inheritance.
  • The concept of Getting the properties from multiple class objects to sub class object with same priorities is known as multiple inheritance.
  • In multiple inheritance there is every chance of multiple properties of multiple objects with  the same name available to the sub class object with same priorities leads for the ambiguity. also known as diamond problem. one class extending two super classes.
  • Because of multiple inheritance there is chance of the root object getting created more than once.
  • Always the root object i.e object of object class hast to be created only once.
  1. Because of above mentioned reasons multiple inheritance would not be supported by java.
  2. Thus in java a class can not extend more than one class simultaneously. At most a class can extend only one class.

8.How do you implement multiple inheritance in java?
  • Using interfaces java can support multiple inheritance concept in java. in java can not extend more than one classes, but a class can implement more than one interfaces.
Program:

interface A{

}
interface B{
}
class C extends interface A,B{
}

9.Can a class extend itself?

  • No,A class can't extend itself.

10.What happens if super class and sub class having same field name?


  • Super class field will be hidden in the sub class. You can access hidden super class field in sub class using super keyword.

Thứ Sáu, ngày 10 tháng 4 năm 2015

Compare RESTful vs SOAP Web Services

There are currently two schools of thought in developing Web Services – one being the standards-based traditional approach [ SOAP ] and the other, simpler school of thought [ REST ].
This article quickly compares one with the other -
RESTSOAP
Assumes a point-to-point communication model–not usable for distributed computing environment where message may go through one or more intermediariesDesigned to handle distributed computing environments
Minimal tooling/middleware is necessary. Only HTTP support is requiredRequires significant tooling/middleware support
URL typically references the resource being accessed/deleted/updatedThe content of the message typically decides the operation e.g. doc-literal services
Not reliable – HTTP DELETE can return OK status even if a resource is not deletedReliable
Formal description standards not in widespread use. WSDL 1.2, WADL are candidates.Well defined mechanism for describing the interface e.g. WSDL+XSD, WS-Policy
Better suited for point-to-point or where the intermediary does not play a significant roleWell suited for intermediated services
No constraints on the payloadPayload must comply with the SOAP schema
Only the most well established standards apply e.g. HTTP, SSL. No established standards for other aspects.  DELETE and PUT methods often disabled by firewalls, leads to security complexity.A large number of supporting standards for security, reliability, transactions.
Built-in error handling (faults)No error handling
Tied to the HTTP transport modelBoth SMTP and HTTP are valid application layer protocols used asTransport for SOAP
Less verboseMore verbose
Published at DZone with permission of Jagadeesh Motamarri, author and DZone MVB. (source)

The two protocols have very different uses in the real world.
SOAP(using WSDL) is a heavy-weight XML standard that is centered around document passing. The advantage with this is that your requests and responses can be very well structured, and can even use a DTD. The downside is it is XML, and is very verbose. However, this is good if two parties need to have a strict contract(say for inter-bank communication). SOAP also lets you layer things like WS-Security on your documents. SOAP is generally transport-agnostic, meaning you don't necessarily need to use HTTP.
REST is very lightweight, and relies upon the HTTP standard to do it's work. It is great to get a useful web service up and running quickly. If you don't need a strict API definition, this is the way to go. Most web services fall into this category. You can version your API so that updates to the API do not break it for people using old versions(as long as they specify a version). REST essentially requires HTTP, and is format-agnostic(meaning you can use XML, JSON, HTML, whatever).

Generally I use REST, because I don't need fancy WS-* features. SOAP is good though if you want computers to understand your webservice using a WSDL. REST specifications are generally human-readable only.

Thứ Tư, ngày 01 tháng 4 năm 2015

How to Install the Linux Dynamic Update Client on Ubuntu

You will be able to install No-IP.com’s DUC on Ubuntu in just a few minutes with Terminal. Once you have opened up your Terminal window you will need to login as the “root” user. You can become the root user from the command line by entering “sudo -s” followed by the root password on your machine.
  1. cd /usr/local/src/
  2. wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
  3. tar xf noip-duc-linux.tar.gz
  4. cd noip-2.1.9-1/
  5. make install
You will then be prompted to login with your No-IP.com account username and password.
If you get “make not found” or “missing gcc” then you do not have the gcc compiler tools on your machine. You will need to install these in order to proceed.
To Configure the Client
As root again (or with sudo) issue the below command:
  • /usr/local/bin/noip2 -C (dash capital C, this will create the default config file)
You will then be prompted for your username and password for No-IP, as well as which hostnames you wish to update. Be careful, one of the questions is “Do you wish to update ALL hosts”. If answered incorrectly this could effect hostnames in your account that are pointing at other locations.
Now the client is installed and configured, you just need to launch it. Simply issue this final command to launch the client in the background:
  • /usr/local/bin/noip2
Read the README file in the no-ip-2.1.9 folder for instructions on how to make the client run at startup. This varies depending on what Linux distribution you are running.
And you are done! The DUC should now be installed on Ubuntu.

Chủ Nhật, ngày 29 tháng 3 năm 2015

Suspend and wake PC at certain time

Want to put your Linux PC into sleep or hibernate mode and have it automatically wake at a specific time? You can easily do this with the rtcwake command, included by default with most Linux systems.
This can be useful if you want your computer to do something at a specific time, but don’t want it running 24/7. For example, you could put your computer to sleep at night and have it wake up before you do to perform some downloads.

rtcwake

The command that you are interested in is rtcwake:
This program is used to enter a system sleep state until specified wakeup time.

testing

To find the correct syntax that works for you try the following:
sudo rtcwake -u -s 60 -m mem
This should suspend the computer for 60 seconds before restoring. The significant parameter is memYou have several options you can choose - play to find the value that works best for you:
          standby
                 ACPI state S1. This state offers  minimal,  though  real,
                 power savings, while providing a very low-latency transi‐
                 tion back to a working system. This is the default mode.

          mem    ACPI state S3 (Suspend-to-RAM). This state offers signif‐
                 icant  power  savings  as everything in the system is put
                 into a low-power  state,  except  for  memory,  which  is
                 placed in self-refresh mode to retain its contents.

          disk   ACPI  state  S4  (Suspend-to-disk). This state offers the
                 greatest power savings, and  can  be  used  even  in  the
                 absence  of  low-level platform support for power manage‐
                 ment. This state operates  similarly  to  Suspend-to-RAM,
                 but  includes  a final step of writing memory contents to
                 disk.

          off    ACPI  state  S5  (Poweroff).  This  is  done  by  calling
                 '/sbin/shutdown'.   Not officially supported by ACPI, but
                 usually working.

          no     Don't suspend. The rtcwake command sets RTC  wakeup  time
                 only.

          on     Don't  suspend,  but  read  RTC  device  until alarm time
                 appears. This mode is useful for debugging.

suspend until a known time

A script (at the bottom of this post) could be used to suspend your computer and wake at a specific time:
syntax is suspend_until [hh:mm] for example
sudo ./suspend_until 07:30
Save the script as the name suspend_until and give it execute rights i.e.
chmod +x suspend_until

Cron

You can create a root cron job that calls this script to execute at a specific time in the evening and then awake in the morning:
sudo crontab -e
Now enter something like to run the suspend script at 23:30:
30 23 * * * /home/myhomefolder/suspend_until 07:30

suspend_until script

#!/bin/bash

# Auto suspend and wake-up script
#
# Puts the computer on standby and automatically wakes it up at specified time
#
# Written by Romke van der Meulen 
# Minor mods fossfreedom for AskUbuntu
#
# Takes a 24hour time HH:MM as its argument
# Example:
# suspend_until 9:30
# suspend_until 18:45

# ------------------------------------------------------
# Argument check
if [ $# -lt 1 ]; then
    echo "Usage: suspend_until HH:MM"
    exit
fi

# Check whether specified time today or tomorrow
DESIRED=$((`date +%s -d "$1"`))
NOW=$((`date +%s`))
if [ $DESIRED -lt $NOW ]; then
    DESIRED=$((`date +%s -d "$1"` + 24*60*60))
fi

# Kill rtcwake if already running
sudo killall rtcwake

# Set RTC wakeup time
# N.B. change "mem" for the suspend option
# find this by "man rtcwake"
sudo rtcwake -l -m mem -t $DESIRED &

# feedback
echo "Suspending..."

# give rtcwake some time to make its stuff
sleep 2

# then suspend
# N.B. dont usually require this bit
#sudo pm-suspend

# Any commands you want to launch after wakeup can be placed here
# Remember: sudo may have expired by now

# Wake up with monitor enabled N.B. change "on" for "off" if 
# you want the monitor to be disabled on wake
xset dpms force on

# and a fresh console
clear
echo "Good morning!"
N.B.
Change mem in this part of the script for whatever suspend method works for you:
# Set RTC wakeup time
sudo rtcwake -l -m mem -t $DESIRED &
You may also have to substitute the -u flag in place of the -l flag depending on whether your hardware clock uses UTC (-u) or local (-l) time. Note that your hardware clock is different from the system clock you see in your operating system.

Thứ Năm, ngày 26 tháng 3 năm 2015

How To Install LinOTP On Ubuntu 12.04 LTS

How To Install LinOTP On Ubuntu 12.04 LTS

by 
Please shareShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditDigg thisShare on StumbleUpon
Security is very important nowadays especially if you run an online business want to deal with clients safely without them worrying about their account getting hacked or their cookies getting stolen. In this detailed tutorial we will show you how to install an opensource solution tool for two factor authentication.

Short Information On LinOTP

LinOTP is an opensource linux based solution to manage authentication devices for two-factor authentication with one time passwords. Being written in python programming language and open for everyone on github, it is easy to hack its code especially if you are a python developer and interested in some deep knowledge.
According to Wikipedia LinOTP provides a REST-like web API and return responses as JSON objects. Now lets go and install it on our Ubuntu 12.04 LTS systems.

Install LinOTP On Ubuntu

The first step needed to be taken to install LinOTP consists in  creating a MYSQL database so we need to make use of the following command to download and install mysql on our Ubuntu system.
sudo apt-get install mysql-server
Once the installation is finished you will be prompted to set the root’s user password for your database, which is a very important step as you will need this password later.
So make sure to not forget it!
Now log into MySQL using the following command.
mysql -u root -p
The following is showed on my console after running the above command successfully.
Execute the following sql code.
CREATE DATABASE LinOTP2;
GRANT ALL PRIVILEGES ON LinOTP2.* TO 'linotp2'@'localhost' IDENTIFIED BY 'ChangeThis';
FLUSH PRIVILEGES;
Once the execution of the above sql code is completed without errors you can exit the MySQL console with the help of the following command. Just a simple exit.
exit
Now we need to add LinOTP’s repository on our system so we can continue with the installation, but first make sure that the python-software-properties package is already installed as it will help us to add and use the repo. If not then you can install it by using the following command.
sudo apt-get install python-software-properties
It is already installed on my system.
Now use the following command to add the repository.
sudo add-apt-repository ppa:linotp/stable
Press Enter.
Update the repositories using the following command.
sudo apt-get update
To install LinOTP simply run the following command.
sudo apt-get install linotp
Type Y and press Enter.
Then you will be prompted some questions for the purpose of the configuration.
It is recommended that LinOTP can be run within a webserver like Apache, but for the purpose of this tutorial we will not cover Apache this time. Just select No.
LinOTP uses a SQL database to store its token data so you will be prompted with a question on what database you want to use. Select MySQL in our case.
You can also select none if you want to use another backend system like Microsoft SQL server or Oracle. After that you need to edit the /etc/linotp2/linotp.ini manually.
Then choose the hostname of the computer where the database is located. I will keep mine as localhost.
Enter the database name you created, mine is LinOTP2.
Leave the user as default.
Enter the password for the database.
Then once is all finished run the following command to complete the configuration.
sudo paster setup-app /etc/linotp2/linotp.ini

Run LinOTP

Open a new tab in you web browser and use the following syntax.
http://your_ip_or_localhost/manage
Done!

Thứ Hai, ngày 16 tháng 3 năm 2015

Disable autostart for any service in Linux

Apache

sudo update-rc.d -f apache2 disable
Apache is still using rc.d init script, which is why you must disable it using update-rc.d.

MySQL

echo manual | sudo tee /etc/init/mysql.override
A cleanest way to disable autostart for any service with a .conf file in /etc/init (like mysql), is to run as root: echo "manual" >> /etc/init/[service_name].override.