Monday, March 5, 2012

Hostname on Mac OS X

If the dynamic hostname is provided by DHCP, and you prefer a fixed one, there are a few ways to do it.

From System Preferences/Network

  • Select the network adapter which interfaces the DHCP server.
  • Click on the "Advanced" button on the lower right.
  • In the TCP/IP tab, specify the "DHCP client ID" text field.
Or depending on the version of Mac OS:

-- Mac OS X 10.5 and older
On Mac, the hostname shown on the terminal prompt is configured by the file,
/etc/hostconfig. If it is specified as
HOSTNAME=-AUTOMATIC-,
the name shown in the prompt is provided by DHCP or BootP server.

Change that line to
HOSTNAME=(preferred-name)

-- Mac OS X 10.6 and newer
Use the command scutil (system configuration utility)
scutil --set HostName (preferred-name)

Remember to check the name set in
/Library/Preferences/SystemConfiguration/preferences.plist,
under System/System/ComputerName

Thursday, February 23, 2012

Modify grapeConfig.xml to speed up groovy script with @Grab

I had a post on speed up groovy script startup time if Grape @Grab annotation is used in the script.
The cause is described in this post, http://swainya.blogspot.com/2011/09/skip-download-when-groovy-code.html.

The solution described in that post is to add one line in the .groovy/grapeConfig.xml to decrease cache TTL.  Add

<property name="ivy.cache.ttl.default" value="15m"/>

in the <ivysettings> section.

Your grapeConfig.xml will look like this after adding that line


<ivysettings>
  <property name="ivy.cache.ttl.default" value="15m"/>
  <settings defaultResolver="downloadGrapes"/>
......

Friday, January 13, 2012

Show user Library folder in Finder

Since moved to MacOS Lion (10.7.x), the folder Library disappeared from my Finder window.  It bothers me a lot.  Apparently Apple hides it in this OS release.   Here is the way to reveal it.

From console terminal, use this command.

$ chflags nohidden ~/Library/

Friday, December 30, 2011

Comment out multiple lines in vi

Press Ctrl-v to start a VISUAL BLOCK
Move the cursor (up/down arrow key) to expand the block
Press I (Shift-i) to start insert.
Type in the character(s) that you want to insert, such as #, or //.
Press ESC to leave the visual block.

Tuesday, December 6, 2011

Global search in vi and list results

We use the simple command to search a pattern (or a fragment of text),

:/{pattern}

Sometimes, there would be a few dozens of matches that you want to list and browse quickly.  Use this command,

:g/{pattern}

It lists the search results in one buffer.  If you want to search the pattern case insensitive, add \c in the command, like

:g/\c{pattern}

Tuesday, November 1, 2011

Monitor disk IO activities on a Linux host

1. Use df first to find all the devices
2. Use iostat

iostat -dx <device> <time-interval>

For example,
iostat -dx /dev/sdb 5

to display disk IO activities every 5 seconds.

Thursday, October 27, 2011

Find CPU information on a Linux

A good tip for finding out CPU and 32/64 bit kernel information on a Linux host, at http://www.cyberciti.biz/faq/linux-how-to-find-if-processor-is-64-bit-or-not/

In short, use

uname -a 

and

cat /proc/cpuinfo