Wednesday, June 4, 2014

Install Mac OS on windows laptop


You need:
  • iAtkos ML2 (Mountain Lion 10.8.2 or higher)
  • An 64 Bit laptop
  • USB Flash (capacity 8gb or larger)
  • Plenty of time (esp the laptop does not have an SSD )
You need tp download iAtkos ML2 as a DMG file and write to your USB Flash. You can find the file from various torrent sites. You need a Mac computer or a virtual host Mac to write the DMG to your USB. If you have your USB Flash ready with iAtkos ML2 DMG, then plug it in to your computer and reboot. You may need to choose boot from USB (press F12 on some BIOSes)
Some important steps:
BIOS setting must bring to factory defaults and activate "Intel Virtualization Technology" setting on your BIOS.
You may need to activate verbose mode of iAtkos ML2 by pressing  -v key combination. 
If your HD has a partition , erase it and create a brand new Mac OS partition.
If you have an old graphics card (not Mobility) you have to disable graphic card activation.
Once you configure your MacOS , you can upgrade to latest from Apple Menu. 

Tuesday, June 3, 2014

A Simple webserver on your Mac to access your files remotely from Windows

Open a terminal window and run following commands :

$ cd /Documents/yourSharedFiles
$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8000 ...

That's it!!! Your web server is started. 

On the browser, type following address to access your files remotely.

http://localhost:8080

The contents of your current directory must be shown on the browser now.

Advanced issues & troubleshooting:

8080 is the port number. If you get "socket.error: [Errno 48] Address already in use" , change the port number to another one. (less than 65536)

If you want to make your webserver run in port 80 , launch the command above with sudo and enter your root password :

$ python -m SimpleHTTPServer 80
Password:

Serving HTTP on 0.0.0.0 port 80 ...

in this case the url will be :

http://localhost

Make sure to shut the webserver down when you are done with cmd-c key or just closing the terminal window.



Wednesday, May 28, 2014

Connect via SSH without a password from MacOS to Linux with an SSHKEY

Don't panic , it is really easy.

Your Steps will be:
1. Create a key on your Mac
2. Define your key on remote Linux
3. Connect via ssh.

1.  Create the key on your Mac

Open the terminal :)

First make a directory named .ssh on your home directory (mkdir .ssh) If it exist , no problem. Go to the newly created .ssh directory with command cd .ssh

Then, you need to create a ssh key on your MAC.

There will be 2 files for key. If you dont want any passwords , just press enter when passphrase asked.

Filename will be default id_rsa if you just hit enter. But if it already exists , you may want to choose another name.

Hakos-MacBook-Pro:.ssh hakan$ ssh-keygen -t rsa -C "your@email.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/hako/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/hako/.ssh/id_rsa.
Your public key has been saved in /Users/hako/.ssh/id_rsa.pub.
The key fingerprint is:
3e:5c:1a:b1:ea:9f:0a:48:c7:43:90:7b:95:a2:b7:a9 your@email.com
The key's randomart image is:
+--[ RSA 2048]----+
|      ..   .     |
|      o.. o      |
|       o.o       |
|      o.o        |
|      .oSo       |
|     . oo=       |
|      *.* .      |
|      Eo O .     |
|      . o.=      |
+-----------------+
Hakos-MacBook-Pro:.ssh hako$ 

There should be 2 files , id_rsa(your private key) and id_rsa.pub( your public key to share with remote hosts)

Then you need to this key to your keystore: (make sure you are on the .ssh directory)

Hakos-MacBook-Pro:.ssh hako$ ssh-add id_rsa

That's it. Now you need to copy the contents of your public-key , do not share your private key. It should always be on your computer. 

Hakos-MacBook-Pro:.ssh hako$ cat id_rsa.pub
ssh-rsa BCAAB3NzaC1yc2EAAAADAQABAAABAQDDQ9NsOquCHBXm+gHl4k4VwA0xmChG0mQhYQPUJrugyNzeYbcwzjWKtCKZiIufRhXP36hHXqxhA1b8adv9AQaFYdNJBA93Dpr9gxxNOKc3Wv1o/WtfEgdC9MflynPcIbliWOc62zZP/RhCeQN+Ucp+H6briI3xTaVzWbJwaP7WbsgCdwKIrRBFtcGERFYs440IJWdYFi5ZeNd20+WrgIRKTMqljAIEhbww7EWE5v3lrbo/bwxr1pNWfYAckH1u4+IXKU91xvhypSsFC1EY8Ef2PtFO7wsBHEfLM4MEBF8o6mPxKTgsOCz2TgYHjJ6RBe3dyCWH4nrQVwdkQgi75J8p your@email.com

copy all of the gibberish above. Now, you define your key in remote Linux

2. Define The key on Linux

go to .ssh directory from your home directory.

be sure there is a file named authorized_keys

If the file is write-protected, open the write permission:
$ chmod 600 authorized_keys

Then, paste your public key content and press ctrl-D
$ cat > authorized_keys

and make the file write protected.

$ chmod 400 authorized_keys

You are done on the Linux, you can connect from Mac via ssh now.

3. Connect

Hakos-MacBook-Pro:.ssh hako$ ssh your_remote_user@remoteIP

You should connect without a password now. 

For easy connecting, You may want to add the ssh command as an alias.

On your home directory :

Hakos-MacBook-Pro:.ssh hako$ nano .bash_profile

add the line
alias myssh='ssh your_remote_user@remoteIP'

kntrl-X and save the file.

Hakos-MacBook-Pro:.ssh source .bash_profile
Hakos-MacBook-Pro:.ssh myssh

That's it ! :)










Wednesday, May 21, 2014

ClassNotFoundException in java

java.lang.ClassNotFoundException occurs when your JVM can not find a required class within your application. The most common cause of this exception is missing required jar's in your project.

If you got this exception in Eclipse you should check your project settings. (Right click on your project , choose BuildPath and Configure BuildPath. Find Libraries tab and add required jars or libraries which are bunch of jars)

If you got this exception in command line first be sure to run your your class in correct directory. For example you have a test.Tester class. Since each package is in a folder, you run your class in upper directory of the test in command prompt.

If your class file is :
/usr/home/youruser/test/Tester.class

then you should run :
$cd /usr/home/youruser
$java test.Tester

If you use some jars or some other class files from other places , check your classpath. You can fix this in 2 ways.

1. You can add your jars folder to CLASSPATH environment variable of your Operating System.

On windows right-click to my computer -> Properties -> Advanced -> Environment variables. Once you add your folder , you can check it by opening new command window and type echo %CLASSPATH

On Linux you add export CLASSPATH="YourClasspath" to your .bash_profile or .bashrc file in your home directory. Here is a good explaination of those files.

2. You can override the classpath in Java.

For example , you have your jars or classes on /usr/home/youruser/javalib1 and /usr/home/youruser/javalib2

$cd /usr/home/youruser
$java -cp /usr/home/youruser/javalib1:/usr/home/youruser/javalib2 test.Tester

Current directory "." is in classpath by default for any jvm and jvm looks for directories in the order they listed in cp or CLASSPATH environment variable.

If you get this error in Tomcat , look for catalina.sh or catalina.bat(windows) and add your classes or jars to CLASSPATH variable of Tomcat.

Hope this helps , thanks for your comments and contribution.

Sunday, May 19, 2013

Where to put Config or Properties files on Eclipse?

On top directory of your project. In Eclipse environment workdirectory of any launched class (Run As Application) is the projects main folder , that is , the directory named by your proj. For example : c:\eclipse\workspace\MyProject.

Sunday, June 26, 2011

String Performance

Perhaps string concatenation is the most frequently used string operation in any language. In Java you can concat two string in this manner:

String concatdStr = "String1"+"String2"+" and String3";

But this is not a good idea. Behind the curtain , Java does string concatenation using StringBuffer class. So the above concat becomes :

String sBuf = new StringBuffer(32);
sBuf.append("String1").append("String2").append(" and String3");

Sunday, March 27, 2011

Clearing WAR , EAR JAR files for .svn folders and library jars

Big archieve sizes can be annoying. There can be some useless files within a war or jar file.

1. If you uploaded your library files to application server than you do not need to pack them everytime you create application archieve file.

2. There can be subversion folders which do not have a function in runtime.

I wrote a basic windows batch file. it uses 7-zip.

clearJavaArchieves.bat


cd %TEMP%
rem "C:\Program Files\7-Zip\7z.exe" d %1 *.jar -r -tzip
"C:\Program Files\7-Zip\7z.exe" d %1 .svn -r -tzip
rem "C:\Program Files\7-Zip\7z.exe" d %1 WEB-INF\lib -tzip
pause

paste this code to file.

first line is the for the temp files.

if you want to clear all jar files within your archieve , and you know what you are doing , delete rem part of line 2 , otherwise you can delete delete line 2.

3rd line deletes all .svn folders within your archieve file. if you donot want to do this , delete line 3.

if you want to delete web-inf/lib , delete rem part of 4th line. (warning be sure you uploaded all necessary jar files to your application server's lib folder) , otherwise you can delete delete line 4!!!

on windows , right-click to your arcive file -> open with -> choose default program -> (you can uncheck "always use the selected..." checkbox if you donot wanto to change your default program) -> browse.

once you open your archieve file with this script , windows adds it to open-with menu with the right-click.


use with caution and test before deploying to production.