Wednesday, March 18, 2009

Commonly Used UNIX Commands

There are a few things you need to remember when entering UNIX commands:

  • UNIX commands are typed at a prompt. Very often the prompt is a percent sign %. Sometimes it is the name of the machine followed by the %. The cursor may be a blinking white square on a black background, a blinking black square on a white background, or a blinking color square on a color background.
  • UNIX commands are case sensitive and are usually lower case. This means that ls and LS are completely different commands. At the end of this section is a chart of some commonly used UNIX commands.
  • Spaces are very important. There is always a space between the command and the file or directory it acts upon. In the following example of a command line, cd is the command and /afs/andrew/course/76/271-Summer/dheagy is the directory.
    Example: cd /afs/andrew/course/76/271-Summer/juser
  • In order for a UNIX command to be executed, you must press Enter at the end of a command line. If all goes well, the prompt and cursor appear on the next line waiting for the next command. It often looks like you haven’t done anything, but unless there is an error message, your command has been executed. If there is a problem, you will generate an error message, such as “Command not found.” If you generate this type of error, you probably typed something incorrectly. Try again.
  • If you type something and you want to get out of it, press Ctrl + C.

Command

Action

cat

Print contents of file in the command window

cd

Change directories

cp

Copy the contents of file into file2

history

List history of all commands issued at system prompt

ls

List the files and subdirectories in a directory

ls -F

List the difference between files and directories (directories will have a /)

ls -l

List files with status information (list the long way)

ls -lt

List file information in long format, sorted by time with newest files (or newly changed files appearing first

ls -a

List all the files in a directory, including dot files

mkdir

Make a directory

mv

Move file to file 2

pwd

Print the pathname of the current directory

rm

Remove, or delete, files

rmdir

Remove directory

fs la

List access rights for (for more information on access rights, read File and Directory Protections)

source

Monday, March 16, 2009

XP Pro logs off immediately after you log in

Got a problem that both in Windows itsself and in Safe Mode you can not login ? It logs off right after entering your username & password, well here is your way out of it :

Problem: Computer Logs off out when you login
Cause: Search Assistant (search bar aside the clock in windows)

3 Steps.

1.- Get into the recovery console (with boot disks, you can get them from microsoft page).

2.- Get the file userinit.exe from another NOT INFECTED computer. (located in windows/system32 folder)

3.- Overwrite the userinit.exe original file (from the infected computer) with the new one (use a cd or disk to transport it) (COMMAND: COPY e:/userinit.exe c:/windows/system32/userinit.exe)

4.- Rename the userinit.exe to wsaupdater.exe

5.- Exit and ENJOY.

Source : http://www.opentechsupport.net/forums/archive/topic/20552-1.html

Friday, March 13, 2009

Solving equation of three variables in Matlab

If we have the following equations :

8x-2y+5z=10
-2x+10y-3z=0
-5x-3y+10z=0

we can solve the equation in Matlab in the following way. Write simply in the command window :

A=[8 -2 5; -2 10 -3; -5 -3 10]; % a 3x3 matrix
b=[10;0;0]%a 3x1 matrix, be careful not to forget the two semicolons they mean break to the next row in matrix

temp=inv(A)*b % temp will be a 3x1 matrix and contains your answer :-)
x=temp(1)
y=temp(2)
z=temp(3)

Thursday, March 12, 2009

Changing the language in Mac

I found one very intresting and powerful tools in Mac and it is that it is possible to change the whole language system without reinstalling the mac. I mean in my case, I had chosen Norwegian by mistake and I wanted to change back to English and it was fantastic that I didn't have to go through the whole reinstallation :-)

I just went into Apple sign from the toolbar, System Preferences, and then International. There I chose English as my language for Order for stored lists. I should mention I have Mac OSX 10.5.5.

iApple ;-)

Just bought an Apple ! Oh my god, I can't do anything with it, have even problems changing my background image ;-)

Tuesday, March 10, 2009

IMAP vs. POP

With IMAP, the master copy of your mail is on the server. Though mail is also downloaded to your personal computer and placed into a local copy of your IMAP server folder structure, it is not necessarily a complete copy at any given time. This is very different from POP. In POP, if you see a summary line for a message in your Inbox, the entire message is there on your personal computer, and you don't have to be connected to the email server to see it. But with IMAP, the summary line may be the only part of the message that has been downloaded to your personal computer. When you ask to see the message, it will be downloaded to your personal computer and then displayed to you, and the copy will remain there on your personal computer till you delete the message in your Inbox.

Source : http://www.stanford.edu/services/imap/firstday.html

Lexial structure

Lexial Structure of a programming language is the set of elementary rules that specifies how you write program in the language. It is the lowest level of syntax of a language; specifies how variables should look like, what characters are used for comments, etc ...

I have started to read a little bit about Javascript on the way home in the subway and I thought maybe some people around the world might wonder about this phrase.

Cheers ...

Shahab, Oslo, 7:55 A.M., just got to work ;-)

Thursday, March 05, 2009

Shutdown shell commands for Ubuntu

The shutdown command at Ubuntu servers :

Code:
sudo shutdown -P now
you can also use: sudo init 0
----------------
Restart command :
Code:
sudo reboot

Thursday, February 19, 2009

Testing EOF of DataInputStream JAVA

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class TestEOF {
  // Throw exceptions to console:
  public static void main(String[] argsthrows IOException {
    DataInputStream in = new DataInputStream(new BufferedInputStream(
        new FileInputStream("TestEOF.java")));
    while (in.available() != 0)
      System.out.print((charin.readByte());
  }
///:~



Source

Tuesday, January 20, 2009

Shahabinary Alpha 0.002

Hi.

Shahabinary English to Norwegian dictionary :

Shahabinary is a OS free, freeware PC application which is at least runable on Linux & Windows (TESTED). The code is not open source this time (like Shahabinary 0.001) but I will post the source code in near future. Due to some technical difficulties with GUI, the word recognition ability has been disabled but will be functional again in version 0.003. This version enjoys a better GUI and much more comfortable design with significant changes in the code which makes it smaller and easier to compile. The only thing you need to do for running is to unzip the folder and double click on Shahabinary v. 0.0002.jar.

Again I repeat the words and database are not trustable and this is just an exercise in my learning progress. This project the focus is mostly on the technical part and not the dictionary parts of the application.

Click here
to download the latest Shahabinary ...

Enjoy ...

Thursday, January 08, 2009

How to run an exe file from java

If you want something which you do not need to read much about it but it is old :

Runtime.getRuntime().exec( "myprog.exe" );

will spawn an external process (usually a program written in some language other than Java) that runs in parallel with the Java execution. In W95/W98/Me/NT/W2K/XP/W2K3, you must use an explicit *.exe or *.com extension on the parameter. In Vista it will still work even if you leave it off. Be careful to include it, or your code will mysteriously fail on the older operating systems.

It is also best to fully qualify executable names so that the system executable search path is irrelevant, and so you don’t pick up some stray program off the path with the same name.


-----


ATTENTION : Starting with JDK 1.5, exec has been replaced by ProcessBuilder. start. You should likely not be using exec for new programs. However, studying exec is useful to understand old programs that use exec and to understand why ProcessBuilder is designed the way it is. They have many things in common, especially the way command interpreters and internal commands must be handled, and they both use the same Process class. So read about exec first, then enjoy the improved ProcessBuilder.

example :

/ using ProcessBuilder to spawn an process
ProcessBuilder pb = new ProcessBuilder( "dolunch.exe", "firstarg", "secondarg" );

Map env = pb.environment();

// insert set FRUIT=strawberry into environment just for our children
env.put( "FRUIT", "strawberry" );

// remove set LIVERCOURSE=YES from environment just for our children
env.remove( "LIVERCOURSE" );

// modify set WINE=pinot to WINE=pinot blanc
env.put( "WINE", env.get("WINE") + " blanc" );

// set up the working directory.
// Note the method is called "directory" not "setDirectory"
pb.directory( new File( "/lunchDir" ) );

// merge child's error and normal output streams.
// Note it is not called setRedirectErrorStream.
pb.redirectErrorStream( true );

Process p = pb.start();
// From here on it, it behaves just like exec, since you have the
// exact same Process object.
// ...

// You can reuse the ProcessBuilder objects.
// They retain their initialisation.
Process sister = pb.Start();


SOURCE

reqading txt files with UTF8 formats

Well this code helped me reading Persian language characters from a text files.


java.io.FileInputStream fis=new java.io.FileInputStream(
"File Path");
java.io.InputStreamReader isr=new java.io.InputStreamReader(
fis, "UTF8");
java.io.BufferedReader fin=
new java.io.BufferedReader(isr);
String line;
while((line=fin.readLine())!=null){
//Statements
}//end of while

How do I right-align a JTextField?

short answer : add this code to the constructor ...
myTextField.setHorizontalAlignment(SwingConstants.TRAILING);

Tuesday, January 06, 2009

Finally Shahabinary Alpha 0.001 is ready :-)

Finally after a long delay because of my exams the Shahabinary dictionary alpha version 0.001 probably full of non discovered bugs with very little amount of words is ready to download for coders. This dictionary is coded in Java and is a open source free Norwegian to English dictionary. I hope this is my first step toward the next better versions of this dictionary specially from Norwegian to Persian and the other way.

Click HERE to download.

Wish me luck and enjoy...

Shahab.

How to make an iterator for a Hashmap in Java

Iterate through the values of Java HashMap example :


  1. /*
  2. Iterate through the values of Java HashMap example
  3. This Java Example shows how to iterate through the values contained in the
  4. HashMap object.
  5. */
  6. import java.util.Collection;
  7. import java.util.HashMap;
  8. import java.util.Iterator;
  9. public class IterateValuesOfHashMapExample {
  10. public static void main(String[] args) {
  11. //create HashMap object
  12. HashMap hMap = new HashMap();
  13. //add key value pairs to HashMap
  14. hMap.put("1","One");
  15. hMap.put("2","Two");
  16. hMap.put("3","Three");
  17. /*
  18. get Collection of values contained in HashMap using
  19. Collection values() method of HashMap class
  20. */
  21. Collection c = hMap.values();
  22. //obtain an Iterator for Collection
  23. Iterator itr = c.iterator();
  24. //iterate through HashMap values iterator
  25. while(itr.hasNext())
  26. System.out.println(itr.next());
  27. }
  28. }
  29. /*
  30. Output would be
  31. Three
  32. Two
  33. One
  34. */

Saturday, December 20, 2008

Install flash player on ubuntu

Q. How do I install Flash Player for Firefox web browser under Ubuntu Linux?

A. First, close running Firefox.

Open the terminal (shell prompt)

Type the following command to install flash player:

$ sudo apt-get install flashplugin-nonfree

Now flash player should be working. Visit youtube or any other site to view flash content.

Troubleshooting tip

Update: This issue only relevant to older Ubuntu Linux version such as 6.04.

Some people may find voice is not working with newly installed flash player. Type following commands to solve this problem (thanks to macewan.org):
$ sudo apt-get install alsa-oss
$ gksudo gedit /etc/firefox/firefoxrc

Find line that read as FIREFOX_DSP and set to:
FIREFOX_DSP="aoss"

Save and close the file.

Close Firefox and restart it again.


Click here to see the source.


Monday, December 01, 2008

Linux on USB memory stick

Now you can have your Linux on your USB memory stick and go around, boot different computers with your memory stick without installing or changing whatever crap(WINDOWS) on that computer which is not yours or for whatever reason you can not install Linux on it. There is a piece of software development called Unetbootin which makes this dream come true and with this piece of very handy technology, you just do not boot the system BUT makes changes that you can carry it around on your USB stick :-)

The following Linux distributions are supported by Unetbootin:

  • Ubuntu, Kubuntu, Xubuntu
  • Debian
  • Linux Mint
  • opensuse
  • Arch Linux
  • Damn Small Linux
  • Slitaz
  • Puppy Linux
  • FreeBSD
  • NetBSD
  • Fedora
  • PCLinuxOS
  • Gentoo
  • Zenwalk
  • Slax
  • Dreamlinux
  • Elive
  • CentOS
  • Mandriva
  • FaunOS
  • Frugalware Linux
Actually some have their own type like Ubuntu which tutorial for it follows here :

Ubuntu 8.10 offers a way to create a USB drive from the Live CD or an .iso. The question is, how well does this really work. In order to test we created several of these USB drive installs. The first thing to note is that the process is easy to do. Here is a step by step in create a USB Pen Drive disk.

Insert the USB Pen Drive once you have booted the Live CD. Now go to System/Administration and Create USB startup disk in the menu. You will see it has detected the 2 GB San Disk. You can use as small as 1 GB for the disk. You will also need to indicate the location of the Live CD or an .iso so the system can build the disk. Here we used the Live CD.


It provides you with the option to decide how much free space to allow for files that you create. What this does is give you a way to move this Pen Drive from computer to computer and save your files. A mobile Pen Drive.


Installation process is quick.

News source (NORWEGIAN) : http://www.hardware.no/artikler/kjor_linux_fra_minnepinnen/58108
Tutorial Source : http://beginlinux.wordpress.com/2008/11/18/ubuntu-810-usb-drive-review/

Tuesday, November 11, 2008

VLC doesn't show subtitle automaticly under Linux

The thing is this, the avi file can be played by VLC media player and if you have the subtitle file (.srt) in the same folder with the same name beside the avi file then it should be read by VLC media player automaticly. But not always, for example mine under Linux refused to add it to the movie. Here is the way to do it manualy :

You click on open file, you specify the video file, then you click on use subtitle file, and then specify the subtitle file, it does not have to have the same name, as long as you specify the correct path

also, the subtitles file might be wrong, try to open it with a text editor and check its contents.

also try opening another subtitles, just to make sure that the subtitles file is not corrupted/worng.

Source that helped me : http://ubuntuforums.org/archive/index.php/t-803063.html

Monday, November 10, 2008

How to set JAVA_HOME variable

Q : I just need a help to show me how to setup java path on Linux. How can I set JAVA_HOME and PATH variables for every user under my Linux system?

A : ~/.bash_profile is a startup script which generally runs once. This particular file is used for commands which run when the normal user logs in. Common uses for .bash_profile are to set environment variables such as PATH, JAVA_HOME, to create aliases for shell commands, and to set the default permissions for newly created files.

Set JAVA_HOME / PATH for single user

Login to your account and open .bash_profile file
$ vi ~/.bash_profile
Set JAVA_HOME as follows using syntax export JAVA_HOME=. If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:
export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java
Set PATH as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
Save and close the file. Just logout and login back to see new changes:
$ echo $JAVA_HOME
$ echo $PATH

Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:
$ which java

Please note that the file ~/.bashrc is similar, with the exception that ~/.bash_profile runs only for Bash login shells and .bashrc runs for every new Bash shell.


Set JAVA_HOME / PATH for all user

You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
# vi /etc/profile
Next setup PATH / JAVA_PATH variables as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin

Save and close the file.


Source : http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/