Applications
| ||||||
Libraries
| ||||||
Linux Kernel
| ||||||
Boot
| ||||||
Hardware
| ||||||
This weblog only liked a combination of technical articles and writings have been using to keep. Many of the articles published in this blog do not belong to me, articles resources, am showing you care to publish the latter part of the articles.
Wednesday, October 30, 2013
Open Platform Trust Services (OpenPTS)
Open Platform Trust Services is a proof-of-concept (PoC) and reference implementation of Platform Trust Services (PTS) which is defined by the Trusted Computing Group, https://www.trustedcomputinggroup.org/home. The infrastructure working group in the TCG is defining an Integrity Management Infrastructure in which the Platform Trust Services (PTS) is a key new components which deals with the integrity information of a trusted platform. OpenPTS is a reference implementation of the PTS, and works with other trusted computing opensource components, BIOS, GRUB-IMA, Linux-IMA, TrouSerS.
Tuesday, April 16, 2013
2 ways to convert Java Map to String
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
public class MapUtil {
public static String mapToString(Map<String, String> map) {
StringBuilder stringBuilder = new StringBuilder();
for (String key : map.keySet()) {
if (stringBuilder.length() > 0) {
stringBuilder.append("&");
}
String value = map.get(key);
try {
stringBuilder.append((key != null ? URLEncoder.encode(key, "UTF-8") : ""));
stringBuilder.append("=");
stringBuilder.append(value != null ? URLEncoder.encode(value, "UTF-8") : "");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("This method requires UTF-8 encoding support", e);
}
}
return stringBuilder.toString();
}
public static Map<String, String> stringToMap(String input) {
Map<String, String> map = new HashMap<String, String>();
String[] nameValuePairs = input.split("&");
for (String nameValuePair : nameValuePairs) {
String[] nameValue = nameValuePair.split("=");
try {
map.put(URLDecoder.decode(nameValue[0], "UTF-8"), nameValue.length > 1 ? URLDecoder.decode(
nameValue[1], "UTF-8") : "");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("This method requires UTF-8 encoding support", e);
}
}
return map;
}
}
Thursday, March 14, 2013
Setting up an android Device for Development
INSTALL
1、Create the file "51-android.rules" with text editor on ubuntu,like vi ,vim ,or gedit.
2、Add lines below to file
---------------------------------------- BEGIN ---------------------------------------------------------------
#Acer
SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0660", OWNER="zana"
#ASUS
SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", MODE="0660", OWNER="zana"
#Dell
SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", MODE="0660", OWNER="zana"
#Foxconn
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0660", OWNER="zana"
#Fujitsu/Fujitsu Toshiba
SUBSYSTEM=="usb", ATTRS{idVendor}=="04c5", MODE="0660", OWNER="zana"
#Garmin-Asus
SUBSYSTEM=="usb", ATTRS{idVendor}=="091e", MODE="0660", OWNER="zana"
SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0660", OWNER="zana"
#Hisense
SUBSYSTEM=="usb", ATTRS{idVendor}=="109b", MODE="0660", OWNER="zana"
#HTC
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0660", OWNER="zana"
#Huawei
SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0660", OWNER="zana"
#K-Touch
SUBSYSTEM=="usb", ATTRS{idVendor}=="24e3", MODE="0660", OWNER="zana"
#KT Tech
SUBSYSTEM=="usb", ATTRS{idVendor}=="2116", MODE="0660", OWNER="zana"
#Kyocera
SUBSYSTEM=="usb", ATTRS{idVendor}=="0482", MODE="0660", OWNER="zana"
#Lenovo
SUBSYSTEM=="usb", ATTRS{idVendor}=="2006", MODE="0660", OWNER="zana"
#LG
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0660", OWNER="zana"
#Motorola
SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0660", OWNER="zana"
#NEC
SUBSYSTEM=="usb", ATTRS{idVendor}=="0409", MODE="0660", OWNER="zana"
#Nook
SUBSYSTEM=="usb", ATTRS{idVendor}=="2080", MODE="0660", OWNER="zana"
#Nvidia
SUBSYSTEM=="usb", ATTRS{idVendor}=="0955", MODE="0660", OWNER="zana"
#OTGV
SUBSYSTEM=="usb", ATTRS{idVendor}=="2257", MODE="0660", OWNER="zana"
#Pantech
SUBSYSTEM=="usb", ATTRS{idVendor}=="10a9", MODE="0660", OWNER="zana"
#Pegatron
SUBSYSTEM=="usb", ATTRS{idVendor}=="1d4d", MODE="0660", OWNER="zana"
#Philips
SUBSYSTEM=="usb", ATTRS{idVendor}=="0471", MODE="0660", OWNER="zana"
#PMC-Sierra
SUBSYSTEM=="usb", ATTRS{idVendor}=="04da", MODE="0660", OWNER="zana"
#Qualcomm
SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", MODE="0660", OWNER="zana"
#SK Telesys
SUBSYSTEM=="usb", ATTRS{idVendor}=="1f53", MODE="0660", OWNER="zana"
#Samsung
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0660", OWNER="zana"
#Sharp
SUBSYSTEM=="usb", ATTRS{idVendor}=="04dd", MODE="0660", OWNER="zana"
#Sony
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", MODE="0660", OWNER="zana"
#Sony Ericsson
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0660", OWNER="zana"
#Teleepoch
SUBSYSTEM=="usb", ATTRS{idVendor}=="2340", MODE="0660", OWNER="zana"
#Toshiba
SUBSYSTEM=="usb", ATTRS{idVendor}=="0930", MODE="0660", OWNER="zana"
#ZTE
SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", MODE="0660", OWNER="zana"
---------------------------------------- END--------------------------------------------------------------------
2、Replace the name of the OWNER(eg.zana) with your username,which is used for logging into the Ubuntu System.Then,save it.
3、Copy the file "51-android.rules" to "/etc/udev/rules.d/51-android.rules".To Achieve it,You should be sure that you have the root permission.
4、Now open the console,and execute:
sudo chmod a+r /etc/udev/rules.d/51-android.rules
5、Then execute:
sudo service udev restart
6、When plugged in over USB, can verify that your device is connected by executing adb devices from your SDK platform-tools/ directory. If connected, you'll see the device name listed as a "device."
Wednesday, March 13, 2013
Object Orientated Programming
OO programming suggests that you use the following principles during the design of a software. The following are not "Design Principles" but a repetition of a good OO design.
In general a general manipulation of an object's variables by other objects or classes is discouraged to ensure data encapsulation. A class should provide methods through which other objects could access variables. Java deletes objects which are not longer used (garbage collection).
Java support the abstraction of data definition and concrete usage of this definition.
The concept is divided from the concrete which means you first define a class containing the variables and the behavior (methods) and afterwards you create the real objects which then all behave like the class defined it.
A class is the definition of the behavior and data. A class can not be directly be used.
A object in an instance of this class and is the real object which can be worked with.
The ability of object variables to contain objects of different classes. If class X1 is a subclass of class X then a method which is defined with a parameter for an object X can also get called which an object X1.
If you define a supertype for a group of classes any subclass of that supertype can be substituted where the supertype is expected.
If you use an interface as a polymorphic type any object which implements this interface can be used as arguments.
Inheritance allows that classes can be based on each other. If a class A inherits another class B this is called "class A extends class B".
For example you can define a base class which provides certain logging functionality and this class is extended by another class which adds email notification to the functionality.
Delegation is then you hand over the responsibility for a particular task to anther class or method.
If you need to use functionality in another class but you do not want to change that functionality then use delegation instead of inheritance.
When you refer to a whole family of behavior then you use composition. Here you program against an interface and then any class which implements this interface can be used to be defined. In composition the composition class is still defined in the calling class.
When you use composition, the composing object owns the behaviors is uses and they stop existing as soon as the composing object does.
Aggregation allows you to use behavior from another class without limiting the lifetime of those behaviors.
Aggregation is when one class is used as part of another class but still exists outside of that class.
Programming by contract assumes both sides in a transaction understand what actions generate what behavior and will abide by that contact.
Methods usually return null or unchecked exceptions when errors occurs in programming by contract environment.
If you believe that a method should not get called in a certain way just throw an unchecked runtime exception. This can be really powerful. Instead of checking in your calling code for exceptions you just throw an exception in the called code. Therefore you can easier identify the place in the coding their an error occurs. This follows the "crash-early" principle, which tells that if an error occurs in your software you should crash immediately and not later in the program because then it is hard to find the error.
A system should have a high cohesion.
Cohesion is a measure of how strongly-related and focused the responsibilities of a single class are. In object-oriented programming, it is beneficial to assign responsibilities to classes in a way that keeps cohesion high.
Code readability and the likelihood of reuse is increased, while complexity is kept manageable, in a highly-cohesive system.
Therefore you should avoid classes which have several responsibilities, e.g. a Logger class should only be responsible for logging.
Software entities like classes, modules and functions should be open for extension but closed for modifications.
This principles encourages developers to write code that can be easily extended with only minimal or no changes to existing code.
An example for a good application of this principles would be that a certain class calls internally an abstract class to conducted a certain behavior. At runtime this class is provided with an concrete implementation of this abstract class. This allows the developer later to implement another concrete calls of this abstract class without changing the code of the class which uses this abstract class.
Another excellent example is the Eclipse Extension Point method. Eclipse Plugins or Eclipse based application can define extension points where other plugs-ins can later add functionality.
Design Patterns in Java - Singleton
A singleton in Java is a class for which only one instance can be created provides a global point of access this instance. The singleton pattern describe how this can be archived.
Singletons are useful to provide a unique source of data or functionality to other Java Objects. For example you may use a singleton to access your data model from within your application or to define logger which the rest of the application can use.
The possible implementation of Java depends on the version of Java you are using.
As of Java 6 you can singletons with a single-element enum type. This way is currently the best way to implement a singleton in Java 1.6 or later according to that book ""Effective Java from Joshua Bloch.
package mypackage; public enum MyEnumSingleton { INSTANCE; // other useful methods here }
Before Java 1.6 a class which should be a singleton can be defined like the following.
public class Singleton { private static Singleton uniqInstance; private Singleton() { } public static synchronized Singleton getInstance() { if (uniqInstance == null) { uniqInstance = new Singleton(); } return uniqInstance; } // other useful methods here }
A static class with static method would result in the same functionality as a singleton. As singletons are define using an object orientated approach it is in general advised to work with singletons.
Singleton violate the "One Class, one responsibility" principle as they are used to manage its one instance and the functionality of the class.
A singleton cannot be subclassed as the constructor is declared private.
If you are using multiple classloaders then several instances of the singleton can get created.
Design Patterns in Java
The terminology of "Design Pattern" in software developed is based on the GOF (Gang of Four) book "Design Patterns - Elements of Reusable Object-Oriented Software" from Erich Gamma, Richard Helm, Ralph Johnson und John Vlissides. Design Pattern are proven solutions approaches to specific problems. A design pattern is not framework and is not directly deployed via code.
Design Pattern have two main usages:
- Common language for developers: They provide developer a common language for certain problems. For example if a developer tells another developer that he is using a Singleton, the another developer (should) know exactly what this means.
- Capture best practices: Design patterns capture solutions which have been applied to certain problems. By learning these patterns and the problem they are trying to solve a unexperienced developer can learn a lot about software design.
Design pattern are based on the base principles of object orientated design.
- Program to an interface not an implementation
- Favor object composition over inheritance
Design Patterns can be divided into:
- Creational Patterns
- Structural Patterns
- Behavioral Patterns
Tuesday, November 27, 2012
Ubuntu 12.04 – install sun jdk 6-7
Ubuntu GNU/Linux 12.04 LTS (Precise Pangolin) released. I wanted to manually install the Sun JDK 6 and 7 on Ubuntu.
Installing Sun JDK 6 on Ubuntu 12.04:
- Download the sun jdk 6 bin from here.
- Make the bin file executeable:
chmod +x jdk-6u32-linux-x64.bin
- Extract the bin file:
./jdk-6u32-linux-x64.bin
- Move extracted folder to this location:
sudo mv jdk1.6.0_32 /usr/lib/jvm/
- Install new java source in system:
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_32/bin/javac 1 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_32/bin/java 1 sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_32/bin/javaws 1
- Choose default java:
sudo update-alternatives --config javac sudo update-alternatives --config java sudo update-alternatives --config javaws
- java version test:
java -version
- Verify the symlinks all point to the new java location:
ls -la /etc/alternatives/java*
- Enable Java plugin for Mozilla Firefox (even for Chrome)
#for 64-Bit jdk sudo ln -s /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins #for 32-Bit jdk sudo ln -s /usr/lib/jvm/jdk1.6.0_32/jre/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins
Installing Sun JDK 7 on Ubuntu 12.04:
- Download the sun jdk 7 tar file from here
- Extract the tar file:
tar -xvzf jdk-7u4-linux-x64.tar.gz
- Move extracted folder to this location:
sudo mv jdk1.7.0_04 /usr/lib/jvm/
- Install new java source in system:
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_04/bin/javac 1 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_04/bin/java 1 sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.7.0_04/bin/javaws 1
- Choose default java:
sudo update-alternatives --config javac sudo update-alternatives --config java sudo update-alternatives --config javaws
- java version test:
java -version
- Verify the symlinks all point to the new java location:
ls -la /etc/alternatives/java*
- Enable Java plugin for Mozilla Firefox (even for Chrome)
#for 64-Bit jdk sudo ln -s /usr/lib/jvm/jdk1.7.0_04/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins #for 32-Bit jdk sudo ln -s /usr/lib/jvm/jdk1.7.0_04/jre/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins
Update: I have added Java Web Start configuration (Thanks Jack).
Update: I have added Java Plugin configuration for Mozilla Firefox even for Chrome (Thanks shetty).
Update: JAVA_HOME configuration: Some tools require JAVA_HOME variable. You can set JAVA_HOME in Ubuntu so simple: Edit the file .bashrc under your home directory and add the following lines: (if .bashrc is hidden click in Nautilus Menu View > Show Hidden Files)
export JAVA_HOME=/path/your/jdk export PATH=$JAVA_HOME/bin:$PATH
Friday, November 16, 2012
Upgrade subversion from 1.6 to 1.7 on ubuntu 12.04
execute the following commands:
echo "deb http://opensource.wandisco.com/ubuntu lucid svn17" | sudo tee /etc/apt/sources.list.d/svn.list
sudo wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get dist-upgradeTuesday, October 16, 2012
grep --exclude/--include syntax (do not grep through certain files)
grep -Ir --exclude="*\.svn*" "pattern" *
Friday, October 12, 2012
Linux : search and replace string in a directory recursively
find /home/zana/folder -type f -exec sed -i 's/oldstring/newstring/g' {} \;
find . -type f -print0 | xargs -0 sed -i 's/Application/whatever/g'
Thursday, September 27, 2012
find and replace a file by another file recursively in all subdirectories
find . -type f -name "image.png" -printf "%h\n" | xargs -i cp /home/zana/DEVELOPMENT/LIB/DIR/Images/image.png "{}"'/'
Thursday, August 9, 2012
How to remove MySQL completely with config and library files on ubuntu 12.04
sudo apt-get remove mysql-server mysql-client mysql-common
sudo apt-get purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
shell>> locate mysql
Wednesday, June 13, 2012
The sky's the limit.
At Intel, we're unlocking the potential of the cloud. We envision a world where data and services are shared securely—confidently—from person to person across multiple clouds. Where shared resources and cloud infrastructure can be redeployed and reallocated on the fly. Where clouds are client aware, so people who access the cloud have a great experience no matter what device they're using. Intel®Architecture is ideal for the cloud, whether at the system, storage or network level.
The sky really is the limit. Here's how we're making it happen.
The sky really is the limit. Here's how we're making it happen.
Wednesday, March 28, 2012
Set ulimit parameters on ubuntu
Set ulimit parameters on ubuntu
By default the number of open files pro user in Ubuntu 8.04 is 1024. In my case this number was too small so I have to increase it.This is done with the ulimit command:
$ulimit -a # see all the kernel parameters
$ulimit -n #see the number of open files
$ulimit -n 9000 # set the number open files to 9000
$ulimit -n #see the number of open files
$ulimit -n 9000 # set the number open files to 9000
The problem with this way is that the ulimit parameter is only set currently for this command terminla and user.If you open a new tab and type again ulimit -a you will see that the number of open files is 1024.This means that after a reboot you’ll need to set the parameter again.
First, in order to set this options automatically you have to edit theetc/security/limits.conf file.
$sudo gedit /etc/security/limits.conf #open the file in gedit
The # means that this part is commented.The wildcard * means for all users.We need to set the nofile option meaning maximum number of open files.If you want to change the number of files of user, you should add this line in the limits.conf:
user soft nofile 9000
user hard nofile 65000
If you want to set the nofile only for superuser you just write root instead of user.
root soft nofile 9000
root hard nofile 65000
Second you have to add a line in the /etc/pam.d/common-session file:
$ sudo gedit /etc/pam.d/common-session #open the file in gedit
Then add the line:
session required pam_limits.so
Now after rebooting you can see in the terminal with ulimit -a the change.
The option with wildcard *didn’t work for me , because I used root accout to run my programms and wildcard option doesn’t affect the superuser.
Remark: Using the same steps you should be able to set and change other parameters ( core file size, max user processes, stack size ….) from the ulimit options.
References:
- Open File Limits Settings on Ubuntu
- ulimits not set according to /etc/security/limits.conf for root – update documentation
- Hacking Ubuntu to Improve Performance
Subscribe to:
Posts (Atom)