Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, April 26, 2011

List of MAC OSX Command Line

I just find a very useful site which contains a list of MAC OSX command line. Check out [ here ].


Command Line Interface


Terminal is a useful utility, which allows advanced users to work with command line interface (CLI). A lot of programmers prefer this mode due to its flexibility to customize things.

Even for semi-advanced users, Terminal looks scary. One of the problems is that you don't know the command name and their syntax. Documentation is long and some time hard to read. But for sure, it require a lot of effort to comb through the documentation to get what you do using CLI. So a lot of users just give up using CLI.

SS64

Recently, I find a useful site, which lists the most frequently used commands for various platforms, e.g., OSX, Oracle, Windows. The list is not too long and is accompanied with short description. In my opinion, it is a very good reference site. Check out [ here ].

My Personal Use: Copy file content to clipboard. 

Let me give you an example use. Do you know that OSX has a command "pbcopy"? To me, I would like to copy the content in a text file to the clipboard. Here is what I do:

  1. Type "less myfile.txt | pbcopy" at the command prompt.
  2. Press Command + V on the application that I would like to paste the content (Note: in Windows, press Ctrl + V).
Pretty cool isnt' it?

Sunday, September 27, 2009

[NS2] Deterministic v.s. Random

Deterministic Setting

By default, NS2 runs deterministic simulation. That is, you will get the same result for every run. The deterministic setting is usually good for debugging, where you would like to know what goes wrong at an exact point.

Random Setting

Statistical analysis involves running simulation for several times and find averages/variance for all the runs. NS2 is deterministic by default. The results from every run with default setting are the same, and the variance of the results is therefore zero. Statistical analysis require randomness so that the avarages and variances would be meaningful.

In order to introduce a randomness to NS2, you will need to insert the following line into the Tcl Simulation script prior to "$ns run":

$defaultRNG seed n

where is an integer. If n is zero, the simulation would be totally random. The result would be different for every run. If n is another integer, NS2 will use n as a seed for random number generator.


By default, NS2 sets n to "1". Therefore, every run generate the same result. If you set n to 101, by executing

$default seed 101

the result would be different from the result corresponding to the default setting. But all the result with n = 101 would still be the same.

For more information about Random Number Generators, see Chapter 12 in the following book from Springer:

T. Issaraiyakul and E. Hossain, "Introduction to Network Simulator
NS2", Springer 2008.
http://www.springer.com/engineering/signals/book/978-0-387-71759-3

You may also find the following website useful:
http://www.ece.ubc.ca/~teerawat/NS2.htm

Sunday, February 8, 2009

[NS2] The difference between an instproc "compute-routes" and a C++ function "computes_routes()"

Two NS2 functions and instproc has very similar name: "compute-routes{}" and "compute_routes()". The differences are shown below:

compute-routes{}
  • is an OTcl command
  • is defined in class Simulator
  • is defined in file ~ns/tcl/lib/ns-route.tcl
  • populate routing information into nodes

compute_routes()
  • is a C++ function
  • is defined in class RouteLogic
  • is defined in file ~ns/routing/route.cc
  • computes the routing information for all pairs of nodes

For more information about Nodes and Route setup, see Chapter 6 in the following book from Springer:

T. Issaraiyakul and E. Hossain, "Introduction to Network Simulator
NS2", Springer 2008.
http://www.springer.com/engineering/signals/book/978-0-387-71759-3

You may also find the following website useful:
http://www.ece.ubc.ca/~teerawat/NS2.htm

Saturday, January 31, 2009

Correction for NS2 Book: ARQ Codes

This is the correction for the following book:

T. Issaraiyakul and E. Hossain, "Introduction to Network Simulator
NS2", Springer 2008.
http://www.springer.com/engineering/signals/book/978-0-387-71759-3


If you are trying to run the ARQ codes in chapter 14, it will not work. You need to add the following code into your arq.cc file:

static class ARQTxClass: public TclClass {
public:
ARQTxClass() : TclClass("ARQTx") {}
TclObject* create(int, const char*const*) {
return (new ARQTx);
}
} class_arq_tx;


You might also find the following slide useful:
http://www.ece.ubc.ca/~teerawat/NS2.htm

Best,
Teerawat

Wednesday, January 21, 2009

"Can I use NS2" v.s. "Do I need NS2"

Yes, NS2 is a very powerful network simulation tools. A lot of people wants to use it (some without knowing whether they really need NS2). A common question is that "Can I use NS2 for my work?" Unfortunately, no one knows the answer more than yourself. In fact, it is more appropriate to rephrase the question as "Do you really need NS2?" A tough one, eh?

So, here are some question which can help you determine whether you need NS2.

- You don't want to use NS2 if your work is self-contained. If your work does not need any interaction with many other component (e.g., determine bit error rate for a particular modulation), it would be easier to write codes in a basic programming language (e.g., C++).
- You want to use NS2 if you work is so connected to other components and you don't want to re-create those component. NS2 has a whole lot of modules that you can re-use. Those modules are written and proved by others. They are quite robust and ready to use. If for example you want to study TCP performance for your new modulation scheme, you might consider writing your own modulation module and use TCP module available in NS2.

Come back to our original question: "Can I use NS2 for my work?" Well, the answer is always YES! NS2 is just a combination of C++ and Tcl. If your work can be programmed by using C++, Tcl, or both. You can use and integrate your work into NS2. But, again, if you don't need to, don't bother using NS2. After all, use NS2 to make your life easier. Do not enslave yourself by using NS2 :)

For more information about language structure (C++-Tcl) in NS2, please look at chapter 3 in the following book:

T. Issaraiyakul and E. Hossain, "Introduction to Network Simulator
NS2", Springer 2008.

Here is the link:
http://www.springer.com/engineering/signals/book/978-0-387-71759-3

You might also find the following slide useful:
http://www.ece.ubc.ca/~teerawat/NS2.htm

Best,
Teerawat

Saturday, July 19, 2008

Linux initialization files: .bash_profile and .bashrc

As a Linux or Cygwin (Linux emulation for Windows) new, would you wonder what really happen when you execute the shell (e.g., double click on the Cygwin icon)? In the old day, Windows always invokes a file called "autoexec.bat". This file contains a bunch of thing the the window will do at the boot-up such as setting path or invoke other programs (e.g., anti-virus).

In your home directory, there are two files, ".bash_profile" and ".bashrc", which are the initialization file in the Linux. When you open a shell, they are automatically executed as a shell initialization.The path setting is contained in these files.

The difference? According to [Josh Staiger],

- ".bash_profile" is invoked for a log-in session. Log-in? Yeah, log-in. It means anything that you usually need to provide user name and password such as log-in physically at the boot-up or using ssh

- ".bashrc" is invoked for a non-log-in session. For example, when you have already log-in to a graphical environment such as KDE. All you have to do is to click on a terminal icon and you don't have to provide username/password to open a shell.

In fact, you can see in the file ".bash_profile" the following

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi


which basically invokes ".bashrc" if it exists.

For the Cygwin environment, you can add your own initialization in either ".bashrc" or ".bash_profile". Wanna try? Add the following lines into the files and restart the shell.

- Add to ".bashrc"


echo Add2.bashrc


- Add to ".bash_profile"

echo Add2.bash_profile

PATH=${PATH}:
export =


ENJOY...