Tuesday, 17 December 2013

Run a java application as a service (deamon) on linux

A simple solution is to create a script start.sh that runs Java through nohup and then stores the PID to a file:
nohup java -jar myapplication.jar > log.txt 2> errors.txt < /dev/null &
PID=$!
echo $PID > pid.txt
Then your stop script stop.sh would read the PID from the file and kill the application:
PID=$(cat pid.txt)
kill $PID
#Collected from stackoverflow

Monday, 16 December 2013

Tools to profile memory usage

1. MemCheck:
Dr. Memory. It is a relatively new tool, works very well on Windows 7. My favorite feature is that it groups the same leaks' allocation stacks in the report.
I have also used UMDH( http://support.microsoft.com/kb/268343 ) and found it quiet useful and easy to setup. It works from Win2000 to Win7.
AppVerifier is a must have swissknife for windows native code developers, its "memory" checker does similar job http://msdn.microsoft.com/en-us/library/dd371695%28v=vs.85%29.aspx
2. Callgrind:
My favorite is verysleepy ( http://www.codersnotes.com/sleepy ) It is tiny but very useful and easy to use.
If you need more features, AMD CodeAnalyst™ Performance Analyzer is free:http://developer.amd.com/documentation/videos/pages/introductiontoamdcodeanalystperformanceanalyzer.aspx
Windows Performance Analysis tools is free from Microsoft, not very easy to use but can get the job done if you are willing to spend the time.http://blogs.microsoft.co.il/blogs/sasha/archive/2008/03/15/xperf-windows-performance-toolkit.aspxDownload: http://msdn.microsoft.com/en-us/performance/cc752957
3. Massif:
Similar(not quite exact match) free tools on windows are:
4. Cachegrind:
Above mentioned Windows Performance Tools has certain level of L2 cache miss profiling capability but not quite as good and easy to use as Cachegrind.
5. DRD:
Haven't found anything free and as powerful on Windows yet, the only free tool for windows I can find that is slightly close is the "lock" checker in AppVerifier: http://msdn.microsoft.com/en-us/library/dd371695%28v=vs.85%29.aspx

#reference: stackoverflow

Thursday, 12 December 2013

Build sample Android NDK on Linux

1. Download Android-NDK (i'm using android-ndk-r8-crystax-1)
2. Create a simple Java wrapper file named NativeLib.java
package com.pt;

/**
 * @author khanh
 *
 */
public class NativeLib {
    static {
        System.loadLibrary("ndk_sample");
    }

    /**
     * Adds two integers, returning their sum
     */
    public native int add(int v1, int v2);

    /**
     * Returns Hello World string
     */
    public native String hello();
}
3. Create C header file by running javah -jni
javah -jni com.pt.NativeLib
mv mv com_pt_NativeLib.h ../jni/
4. Write implement C file for com_pt_NativeLib.h
 #include "com_pt_NativeLib.h"

JNIEXPORT jstring JNICALL Java_com_marakana_NativeLib_hello
  (JNIEnv * env, jobject obj) {
        return (*env)->NewStringUTF(env, "Hello World!");
}

JNIEXPORT jint JNICALL Java_com_marakana_NativeLib_add
  (JNIEnv * env, jobject obj, jint value1, jint value2) {
        return (value1 + value2);
}
5. To build library, create file Android.mk to lead compilers how to build
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := ndk_sample
LOCAL_SRC_FILES := ndk_sample.c

include $(BUILD_SHARED_LIBRARY)
6. Create folder in /apps/ndk_sample/ and create Application.mk
APP_PROJECT_PATH := $(call my-dir)/project
APP_MODULES      := ndk_sample
7. Create symbol link to the project by typing
ln -s ~/home/Android/NDKSampleProj /apps/ndk_demo/project
8. Finally, run make APP=ndk_sample that will generate libs/armeabi/libndk_sample.so
9. Enjoy the coding now with native code.

Monday, 9 December 2013

Install & Configure Qt with Visual Studio

1. Download and extract Qt
2. Set environment variable: QMAKESPEC (..\Qt4\4.8.5\mkspecs\win32-msvc2005)
3. Goto extracted folder of Qt, then open Visual Studio Command Prompt, then type configure.exe with relevant options. Example: configure.exe -platform win32-msvc2005
4. Finally, type: nmake (This will take a very long time. Go out to dinner or something).
5. Reboot computer and enjoy programming with Qt

Wednesday, 19 December 2012

Install SVN Server on CentOS


Install SVN


Install mod_dav_svn right away which is required to make SVN work with Apache.
$ yum install mod_dav_svn subversion

Create a repository
$ svnadmin create /path/to/

Permissions to access the repository
$ chown -R apache:apache /path/to/


Setup SVN Users

Config file for the repository to allow users access to it
$ vi /path/to//conf/svnserve.conf

Uncomment the lines like so:
auth-access = write
password-db = passwd

Create a htpasswd file which will hold users and passwords for accessing to this repository
$ htpasswd -c /path/to//conf/passwd


Configure Apache

Edit the following file:
$ vi /etc/httpd/conf.d/subversion.conf

LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
DAV svn
SVNPath /path/to/
Authtype Basic
AuthName "My Repository"
AuthUserFile /path/to//conf/passwd
Require valid-user
 

The path /svn is where the repository will be served out of.
Finally, restart apache for new configuration to take affect:
$ service httpd restart

Wednesday, 18 April 2012

4 Things Young Entrrepreneurs Need (A Fancy College Degree Isn’t One of Them)

“What’s the most important thing I need to know?”
Whether I’m working with one of the businesses I mentor, speaking at events, perusing my inbox or answering questions on a panel, this is the question that arises more than any other. While there is no magic formula to success, there are some key factors that every young entrepreneur should know.
1. Remember the “you.” Don’t lose yourself by trying to act how you think a CEO or business owner should act. Instead, be authentic to who you are and what you believe in, and enjoy being the leader. True leaders not only have a vision – they also possess the guts to pursue it. You must grow as your business and organizations grow, but never forget the core values you possess right now.
2. Trust your gut. Your instincts got you to where you are now, and while you certainly want and cherish occasional input from those you trust, don’t be afraid to make decisions based on what you feel is right.
3. Find “elephants” (big customers). I always wondered why someone would focus on getting a hundred small customers when for the same effort (if they know how to do it correctly), they could get a few really big customers that could each buy 10 to 100 times as much as the hundred small ones. This thinking applies to every single industry, from retail stores to online businesses, from applications to pizza parlors – even B2Bs. Focus your business on the big customers. Here are a few tips to start your sales force down the big customer path:
  • Position your company for the big customer. Ask yourself what it is about your product or service that appeals to the big customer. Most likely you will have to reposition or shape your offering to directly meet those needs. For example, if you sell retail, ask how big companies can use your product. Maybe corporate or executive gifts. If you have a specialty baking shop, can a big company send out a huge volume as holiday gifts? If you sell B2B, how can your product be shaped to meet global needs of a huge customer?
  • Learn the language. Every large company has its own language. Learn what they call the different buildings and the name of the local sandwich shop. What do they call their contracts? How about their cafeteria and conference rooms, not to mention initiatives that are applicable to you? Learn and use everything you can so that you assimilate into their culture. This information is all around you. Just ask, look around and listen.
  • Embrace bureaucracy. Bureaucracy is a reality of larger companies. Once you accept it, get in there with a small sale at first and then work from the inside out, helping your buyer by helping them within his or her own company. Ask how you can help, then meet with as many different departments as possible.
  • Find your champion. You need someone to represent you in the room when you aren’t there. Whenever you sell the big customer, make sure to leave them with five simple bullet points highlighting the things you want them to know about your product. This way they will remember the key aspects without having to dig through the pile of materials – which, by the way, they won’t do.
4. Think BIG. It amazes me how often I have to push young entrepreneurs to think really big. Many that are starting out are happy just to get some traction. Don’t be. Once you have that traction, it’s time to build big. Look at your business in two ways: 1) How can I sell new stuff to the same people and 2) How can I sell the same stuff to new people?
Focus in on which option or options will lead to huge growth and build your strategy around that. The rest will pick up from there.

Giveaway – 1 Hour Phone Call

Steve Kaplan grew a target marketing company from startup to $250 million in sales with offices in 14 countries before selling it as part of a public company for $2.1 billion. He has owned over 30 businesses – 26 of which have been sold – and is now offering a free one-hour consultation to one of our Under30CEO blog readers!
To enter, leave a comment below explaining why you’d like a personal consultation with him. One winner will be chosen at random on April 23rd.

Monday, 5 March 2012

[SLOVED] reset MySQL Password

Sometime you face a problem look like:
ERROR 1045: Access denied for user: 'root@localhost' (Using 
password: NO)
or 
ERROR 1045: Access denied for user: 'root@localhost' (Using 
password: YES) 
 Hence, you should reset your mysqld password just follow these instructions :
stop mysql demon: sudo /etc/init.d/mysql stop
Start the mysqld demon process:
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
After that, type these commands:
mysql -u root
FLUSH PRIVILEGES;
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
FLUSH PRIVILEGES;
Anyway, stop mysqld and relaunch mysql by;
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

[SOLVED] Ibus doesn't work on Skype

I found the method to fix the problem: "unable Ibus working on Skype" as following as:
  1. Make sure installed ibus-qt4, if not try: sudo apt-get install ibus-qt4
  2. Editing /etc/X11/xinit/xinput.d/default, by copying arguments respectively from file /etc/X11/xinit/xinput.d/ibus and then reboot to enjoy it
I guarantee that it's working properly.

Thursday, 1 March 2012

Crack permanently IDM

My IDM had been expired a long time, and I didn't know which version of IDM installed on my laptop to google the correct serial number. However, I have got a method to solve this problem regardless which version of IDM using. Here it is:
- copy the following code below to C:\Windows\System32\drivers\etc\hosts
127.0.0.1 tonec.com
127.0.0.1 www.tonec.com
127.0.0.1 registeridm.com
127.0.0.1 www.registeridm.com
127.0.0.1 secure.registeridm.com
127.0.0.1 internetdownloadmanager.com
127.0.0.1 www.internetdownloadmanager.com
127.0.0.1 secure.internetdownloadmanager.com
127.0.0.1 mirror.internetdownloadmanager.com
127.0.0.1 mirror2.internetdownloadmanager.com
127.0.0.1 mirror3.internetdownloadmanager.com
 - after that, open IDM and fill one of the key below:
QIBWH-F5SRH-9XAM2-DVHDR
or
L59BR-8CKUC-W9RIM-YSOT6
or
MWNDP-HO0R0-0U710-I63WG
 Hope you get thing done.

Saturday, 24 December 2011

Happy Merry Chistmas!

One more Merry Chistmas, I will go out with my friends to drink something.
I don't know when I will spend the time with a person who I'm looking for...:)

keep everyone warm during this winter!

Monday, 12 September 2011

Terminology in GMAT

I have read about GMAT, so I got some terminologies in GMAT. I will present it as following:
  1. Whole number: non-negative integer
  2. The mean: average of set
  3. The most: the most common element in a set
  4. Right Triangles: in which one of the angles has a measure equal to 90.

Sunday, 4 September 2011

Start new season to gain expected outcome!:)

New season is coming for me. So, I will try to work by my best to gain most expected outcome which I proposed.

Wednesday, 31 August 2011

KiA(Know it All) ChatBot

Learning English with intermediate KiA program.

Note: The program is running as trial. I will keep it up-to-date.

Wednesday, 29 June 2011

SQL Optimization: Transaction - Part 1

The optimization is an integral part of software development. There are a lot of things which we need to optimize as coding, speed, SQL statement, etc.. for example. Hence, this entry will provide some information about how to optimize SQL Transaction Statement that I got from the internet.
  • Try to restricts the queries result set by using WHERE clause: the SQL server will return to client only particular columns, not all table's column. It means reducing SQL network traffic
  • Try to avoid using the COUNT(*) clause:  you should use alternative way to count
  • Try to use constraints instead of triggers, whenever possible
  • Use table variables instead of temporary variables
  • Try to avoid the HAVING, DISTINCT clause, whenever possible
  • Try to use UNION ALL statement instead of UNION: because of UNION ALL does not look for duplicate rows, UNION does look for duplicate rows.