Monday, January 21, 2013

One line command to add host in /etc/hosts at mac os


If i simply echo and output to /etc/hosts, i will get permission denied



sudo echo 127.0.0.1 myhelloword.localhost >> /etc/hosts
-bash: /etc/hosts: Permission denied


That's because echo is being run as root, but shell is the one who actually performing the redirection. The solution will be spawn a new shell to make this work:


sudo -- sh -c "echo 127.0.0.1 myhelloword.localhost >> /etc/hosts"

VMware CentOS 6.3 Network issue

I just grab new centos and start with "basic server" installation within VMWare delivered no IPAddress and etc.

Simply just run
"ifup eth0" to solve the problem



Friday, January 18, 2013

Avoid WordPress Asking FTP Credentials When You Install/ Upgrade Plugins


If you are using php fastcgi and PHP runs under the same user as the owner of the files you don’t have to use FTP at all. WP can directly access the files. Just add the following to your wp-config.php file:

define( 'FS_METHOD', 'direct' );
define( 'FS_CHMOD_DIR', 0777 );
define( 'FS_CHMOD_FILE', 0777 )

Friday, January 11, 2013

Passbook


PASSBOOK COUPONS AND PASSES DELIVERY

Passbook is a new app in iOS that works as a virtual container for all your passes, ticket, discount coupons, loyalty cards and gift cards. As a web developer you may want to serve the user with a discount coupon, a ticket to an event, an e-ticket for your next flight or a loyalty card.
Apple allow websites to deliver this kind of passes from a website without the need of a native app.
To deliver the pass on your website you just need to use the MIME type application/vnd.apple.pkpass or send it through email
Apple provides a tool that you can install on your server to package and sign customized passes on the fly that may include current user information
To pass file is just a JSON meta-data file and a couple of images. We need to package the file and sign it. Unfortunately, to sign the pass we need a signature from Appleand that means that the web developer needs an iOS Developer Program account ($99/year). If you receive the pass already signed, you can just insert it on your own site.
One of the great features of passes is that once installed you can provide some web services on your end and through Push Notification Services, the operating system will call your web services to update the information on the pass.
More information at developer.apple.com/passbook
There are website for you to create passbook coupons

There is  

For android, this is the app can import ios PKPass https://play.google.com/store/apps/details?id=com.attidomobile.passwallet&hl=en




Thursday, January 10, 2013

Where is java_home at mac os lion 10.8

Where is java_home at mac os lion 10.8 ?


Edit the file ~/.bash_profile 
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
this will set the environment variable accordingly.
Reference from stack over flow:

Friday, November 16, 2012

enable apache ssl


LoadModule ssl_module modules/mod_ssl.so

#
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
#
Listen 443
Listen 1443

##
##  SSL Global Context
##
##  All SSL configuration in this context applies both to
##  the main server and all SSL-enabled virtual hosts.
##

#   Pass Phrase Dialog:
#   Configure the pass phrase gathering process.
#   The filtering dialog program (`builtin' is a internal
#   terminal dialog) has to provide the pass phrase on stdout.
SSLPassPhraseDialog  builtin

#   Inter-Process Session Cache:
#   Configure the SSL Session Cache: First the mechanism
#   to use and second the expiring timeout (in seconds).
SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout  300

#   Semaphore:
#   Configure the path to the mutual exclusion semaphore the
#   SSL engine uses internally for inter-process synchronization.
SSLMutex default

#   Pseudo Random Number Generator (PRNG):
#   Configure one or more sources to seed the PRNG of the
#   SSL library. The seed data should be of good random quality.
#   WARNING! On some platforms /dev/random blocks if not enough entropy
#   is available. This means you then cannot use the /dev/random device
#   because it would lead to very long connection times (as long as
#   it requires to make more entropy available). But usually those
#   platforms additionally provide a /dev/urandom device which doesn't
#   block. So, if available, use this one instead. Read the mod_ssl User
#   Manual for more details.
SSLRandomSeed startup file:/dev/urandom  256

SSLRandomSeed connect builtin
#SSLRandomSeed startup file:/dev/random  512
#SSLRandomSeed connect file:/dev/random  512
#SSLRandomSeed connect file:/dev/urandom 512

#
# Use "SSLCryptoDevice" to enable any supported hardware
# accelerators. Use "openssl engine -v" to list supported
# engine names.  NOTE: If you enable an accelerator and the
# server does not start, consult the error logs and ensure
# your accelerator is functioning properly.
#
SSLCryptoDevice builtin
#SSLCryptoDevice ubsec

##
## SSL Virtual Host Context
##



  Include /etc/httpd/conf.d/ssl.inc
  RedirectMatch ^/[^/]*$ http://www.example.com
  SSLProxyEngine On
  # No forward proxy
  ProxyRequests Off
  ProxyVia Off
  ProxyPreserveHost On
 
    Order deny,allow
    Allow from XX.XX.XX.XX
 

  ProxyPass /abc/ http://XX.XX.XX.XX:XX/abc/
  ProxyPass /xyz/ https://XX.XX.XX.XX:XX/xyz/
  ProxyPassReverse /xyz/ https://XX.XX.XX.XX:XX/xyz/





ssl.inc
---------------

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"

RailsBaseURI /redmine





# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   SSL Protocol support:
# List the enable protocol levels with which clients will be able to
# connect.  Disable SSLv2 access by default:
SSLProtocol all -SSLv2

#   SSL Cipher Suite:
# List the ciphers that the client is permitted to negotiate.
# See the mod_ssl documentation for a complete list.




#   Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.  If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.  Note that a kill -HUP will prompt again.  A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/pki/tls/certs/XXXX.crt



#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/pki/tls/private/xxxx.key




    SSLOptions +StdEnvVars


    SSLOptions +StdEnvVars



SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0


#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
Include /etc/httpd/conf.d/ssl/*.conf






Thursday, November 15, 2012

How to increase the Java heap memory for Maven 2 on linux


java.lang.OutOfMemoryError: PermGen space (Maven/Jetty)


If you get an error OutOfMemory error while doing mvn site,  to solve this problem one needs to increase the memory available to JVM (i.e. to Maven -- which invokes Jetty)


Increasing memory by setting env variable

Monday, November 05, 2012

Read text from image file in Java


Read text from image file in Java


There's GOCR and tesseract, but I'm not sure about how their current releases stack up -- what about trying both on some typical inputs you need to deal with, and choose by this trial?



Friday, November 02, 2012

phonegap - splash screen for Android app



Answers


In order to have a splash screen in a PhoneGap Android application you need to put your splash.png file into res/drawable-ldpi, res/drawable-mdpi, res/drawable-hdpi, res/drawable-xhdpi. Where those directories represent low, medium, high and extra large dots per inch. You'll need to resize you slash.png for each directory or Android will stretch it for you.
The sizes of each image should be:
  • xlarge (xhdpi): at least 960 x 720
  • large (hdpi): at least 640 x 480
  • medium (mdpi): at least 470 x 320
  • small (ldpi): at least 426 x 320
Then in your main Java class, the one that extends DroidGap, you'll need to add one line and modify another. First add:
super.setIntegerProperty("splashscreen", R.drawable.splash);
this line should show up under super.onCreate but before super.loadUrl. Then you'll need to modify your loadUrl method to pause for 5 seconds before loading up the main page. It would look like this:
super.loadUrl("file:///android_asset/www/index.html", 5000);
That should do it for you.
I've recently made some updates to how the SplashScreen works on PhoneGap Android. The main app now loads while the splash screen is being shown. This is a big improvement over the previous blocking splash screen call. Read more about the changes on my blog.


navigator.splashscreen.hide();
but that call isn't ready yet. However, if you want to be on the bleeding edge you should be able to call:
cordova.exec(null, null, "SplashScreen", "hide", []);
but you are wait out on the edge there so don't blame me if it doesn't work. Then you'll be able to tell the splash screen to go away once you have "deviceready".
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    console.log("We got device ready");
    cordova.exec(null, null, "SplashScreen", "hide", []);
    // Soon to be
    // navigator.splashscreen.hide();
}



Reference:http://stackoverflow.com/questions/8156841/phonegap-splash-screen-for-android-app

Thursday, November 01, 2012

Is it safe to use HTTPS without SSL certificates for my own domains?




Answers



Not verifying the identity of the server you connect to leaves the connection open to potential MITM attacks. SSL/TLS can be used without certificates (with anonymous cipher suites), but they're insecure (and disabled by default); as the TLS RFC says: "Note that this mode is vulnerable to man-in-the-middle attacks and is therefore deprecated." In addition, the HTTPS specification itself expects there to be an X.509 certificate.
Checking the identity of the remote party is a necessary element for securing your system. It's not very useful to exchange data secretly with a remote party who may not be who they claim they are (even if the secrecy is guaranteed).
This being said, you don't have to go via a commercial CA. You can either use self-signed certificates, which you would have to import individually into each client as trusted certificate, or create your own institutional CA. There are tools to do this, ranging from OpenSSL's CA.pl (see man-page), TinyCA or OpenCA amongst others. Some operating systems also provide their own small CA capabilities.
If I connect using my own domainname or IP address, I know I'm the owner. What additional value does an SSL certificate provide if I'm the owner of both ends of a connection?
The certificate assures you that you're indeed connecting to your machine and that the traffic hasn't been intercepted. That's why you need to check that it's a certificate that you recognise.



Reference: http://stackoverflow.com/questions/10029574/is-it-safe-to-use-https-without-ssl-certificates-for-my-own-domains


Self Signed SSL acceptance Android

http://stackoverflow.com/questions/1217141/self-signed-ssl-acceptance-android


SchemeRegistry schemeRegistry = new SchemeRegistry();
// http scheme
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// https scheme
schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

HttpParams params = new BasicHttpParams();
params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);

Thursday, August 16, 2012

Automatic Completion in Windows

How to use authomatic Completion in Windows. In Linux, we often type "TAB" to display possible file that match character we typed. This can be done in windows too .. http://support.microsoft.com/
kb/310530

Wednesday, August 15, 2012

Installing Maven On CentOS

Copy from key2start wordpress

Installing Maven On CentOS

05APR
These are the simple sequences for making maven work on a CentOS machine.
Pre-requisite : Java to be installed, check using java -version
1. Download the current maven version from the prescribed repository, http://maven.apache.org/download.html. I use to work with maven version 2.0.11 and hence downloaded using,
> wget http://www.eng.lsu.edu/mirrors/apache//maven/binaries/apache-maven-2.0.11-bin.tar.gz
Please wait while it is downloaded as a tar archive.
2. Extract the archive to the desired maven home directory, which can be a common, /usr/local/
So move the downloaded apache-maven-2.0.11-bin.tar.gz to /usr/local/ path using mv command or a short way can be use the wget command told before after going to the /usr/local/ path. Any way no issues..
> mv apache-maven-2.0.11-bin.tar.gz /usr/local
> cd /usr/local
> tar -zxvf apache-maven-2.0.11-bin.tar.gz
This will extract the apache-maven-2.0.11 directory into /usr/local/
3. Create sym link..
> ln -s apache-maven-2.0.11 maven
4. Open ~/.bashrc file with vi ~/.bashrc and add the following lines to the end of the file,
export M2_HOME=/usr/local/apache-maven-2.0.11
export PATH=${M2_HOME}/bin:${PATH}
5. AT last execute the environment changes with the command,    
> . ~/.bashrc
Check the installation with,
> mvn -version

http://key2start.wordpress.com/2011/04/05/maven-on-centos/