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.
Friday, December 30, 2011
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.
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
In short, use
uname -a
and
cat /proc/cpuinfo
Friday, September 30, 2011
Find directory path of the current groovy script
Bash or PHP script has a function that returns the directory path of the current script file.
$my_dir=dirname(__FILE__);
Groovy script lacks such a capability but an alternative is available by calling
def my_dir = new File(getClass().protectionDomain.codeSource.location.path).parent
$my_dir=dirname(__FILE__);
Groovy script lacks such a capability but an alternative is available by calling
def my_dir = new File(getClass().protectionDomain.codeSource.location.path).parent
Tuesday, September 27, 2011
Skip download when groovy code annotated with Grapes
Grapes is a great utility to manage class path automation when coding with groovy.
http://groovy.codehaus.org/Grape
But it slows down the start-up if there are a lot of dependent jars to download. Even all the dependent jar files have been downloaded to local m2 and grapes store previously, the download process still takes place, which slow things down unnecessarily.
Use the following options to ask groovy look into local storage directly.
groovy -Dgroovy.grape.autoDownload=false [groovy file path] [arguments ......]
http://groovy.codehaus.org/Grape
But it slows down the start-up if there are a lot of dependent jars to download. Even all the dependent jar files have been downloaded to local m2 and grapes store previously, the download process still takes place, which slow things down unnecessarily.
Use the following options to ask groovy look into local storage directly.
groovy -Dgroovy.grape.autoDownload=false [groovy file path] [arguments ......]
Friday, September 23, 2011
Suppress test stage during maven build
Use
-Dmaven.test.skip.exec=true
to skip running test cases without skipping test jar build
-Dmaven.test.skip.exec=true
to skip running test cases without skipping test jar build
A class path with all jar files in a folder
Typing in all the jar files to form a class path is not a fun job. This quick trick may alleviate some of the pain.
export CLASSPATH=`echo $PWD/*.jar | sed 's/ /:/g'`
Customize the "echo" part to get all the files needed.
Such as
export CLASSPATH=`echo $PWD/*.jar . $HOME/lib | sed 's/ /:/g'`
Thursday, August 18, 2011
Use wildcard in the command find
To use a wildcard
Without quote or backslash
find . foo*bar -print
the shell will expand * before passing it into find command. This results is a different, and most likely a narrower, search.
To avoid that, use
find . 'foo*bar' -print
or
find . foo\*bar -print
*in the find command needs a little more care.
Without quote or backslash
\, such as
find . foo*bar -print
the shell will expand * before passing it into find command. This results is a different, and most likely a narrower, search.
To avoid that, use
find . 'foo*bar' -print
or
find . foo\*bar -print
Tuesday, August 16, 2011
Add one more yum repository
Read yum.conf first. Usually the path is /etc/yum.conf.
Understand where the cache and repository configuration file directory
The following examples use default locations
## add epel to the repo list
## see what is there before change
ls /var/cache/yum/*/*
cd yum.repos.d/
## copy contents from another configured host
sudo vi epel.repo
sudo yum clean all
## make sure it is empty
ls /var/cache/yum/*/*
sudo yum makecache
## see if the new repo epel is added
ls /var/cache/yum/*/*
## add GPG key for the new repo, also do copy-paste
sudo vi /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
If you are not sure about the name of RPM-GPG key, run rpm to install the package. Towards the end, rpm will complain about missing the GPG key and prompt the file name for you.
Understand where the cache and repository configuration file directory
The following examples use default locations
## add epel to the repo list
## see what is there before change
ls /var/cache/yum/*/*
cd yum.repos.d/
## copy contents from another configured host
sudo vi epel.repo
sudo yum clean all
## make sure it is empty
ls /var/cache/yum/*/*
sudo yum makecache
## see if the new repo epel is added
ls /var/cache/yum/*/*
## add GPG key for the new repo, also do copy-paste
sudo vi /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
If you are not sure about the name of RPM-GPG key, run rpm to install the package. Towards the end, rpm will complain about missing the GPG key and prompt the file name for you.
Find out it is a 32 or 64-bit Linux
Use the command
uname -m
If it shows x86_64, it is a 64-bit host.
If it shows i386 (or sometimes i686), it is a 32-bit machine
Plus, run the command
file /bin/ls
For 64-bit kernel, it should show
/bin/ls: ELF 64-bit LSB executable ....
uname -m
If it shows x86_64, it is a 64-bit host.
If it shows i386 (or sometimes i686), it is a 32-bit machine
Plus, run the command
file /bin/ls
For 64-bit kernel, it should show
/bin/ls: ELF 64-bit LSB executable ....
Find installed packages on Linux hosts
To find installed packages on a Redhat/CentOS Linux, use
Once the package name is found, use this command to find more details
To find installed packages on a Debian (also Ubuntu) Linux, use
Once the package name is found, use this command to find more details
rpm -qa | less
Once the package name is found, use this command to find more details
rpm -qil {package-name}
To find installed packages on a Debian (also Ubuntu) Linux, use
dpkg --list
Once the package name is found, use this command to find more details
dpkg -p {package-name}
Tuesday, August 9, 2011
Find and delete into directories recursively
How to find a set of files or directories that are named the same? For example, to delete all the '.svn' directories in the current working directory.
One easy way is
The option [-v] prints out the files/directories found. and rm -rf is the typical force deletion of a directory.
Another way to do it is
But this command prints out warning messages that sometimes confuse users.
The warning message means it found a .svn directory in the current directory and deleted as instructed ( -exec rm -rf ). When the command find wanted to descend into .svn directory, it could not.
The trailing {} \; is required. Pay attention to its format: there is a space between } and \.
One easy way is
rm -rvf `find . -type d -name .svn`
The option [-v] prints out the files/directories found. and rm -rf is the typical force deletion of a directory.
Another way to do it is
find . -name ".svn" -exec rm -rf {} \;
But this command prints out warning messages that sometimes confuse users.
find: ./.svn: No such file or directory
find: ./images/.svn: No such file or directory
find: ./images/.svn: No such file or directory
The warning message means it found a .svn directory in the current directory and deleted as instructed ( -exec rm -rf ). When the command find wanted to descend into .svn directory, it could not.
The trailing {} \; is required. Pay attention to its format: there is a space between } and \.
Programmically create a Mule 3.x Inbound point to a Mule service
I use JMS inbound endpoint as an example. Different types of inbound endpoints differ slightly.
1. Create an inbound point configurer of the target inbound type
public class JmsInboundConfigurer implements MuleContextAware
{
ServiceCompositeMessageSource msgSource;
public void setMuleContext(MuleContext context) {...}
public MuleContext getMuleContext() {...}
public void setService(Service svc) {...}
public Service getService() {...}
public void setConnector(Connector conner) {...}
public Connector getConnector() {...}
}
In the mule-config.xml, add
<spring:bean id="my.configurer" class="com.acme.JmsInboundConfigurer" init-method="init">
<spring:property name="service">
<spring:ref bean="my.service"/>
</spring:property>
<spring:property name="connector">
<spring:ref bean="activemq.connector"/>
</spring:property>
</spring:bean>
2. Statically configure an inbound point and read it back to match the configuration
<jms:activemq-connector name="activemq.connector"
brokerURL="tcp://localhost:61616"/>
<jms:endpoint name="jms.endpoint" queue="..."
connector-ref="activemq.connector" exchange-pattern="request-response"/>
JmsInboundConfigurer.init() would make a good place to output all the information.
this.msgSource =
(ServiceCompositeMessageSource)getService().getMessageSource();
logger.info(msgSource.toString());
Use msgSource.getEndpoint("jms.endpoint") or msgSource.getEndpoints() to read back end points to compare with the static configuration
3. Comment out the static configure and create it programmatically
The following code fragment creates and add a JMS inbound point to the service assigned
EndpointURIEndpointBuilder builder = new EndpointURIEndpointBuilder(uri, this.muleContext);
builder.setName("jms.endpoint");
builder.setConnector(this.connector);
builder.setExchangePattern("request-response");
// builder.setProperty("", xyz); // if any
if (transaction needed) {
MuleTransactionConfig txConf = new MuleTransactionConfig();
txConf.setAction(ACTION_BEGIN_OR_JOIN);
txConf.setMuleContext(muleContext);
txConf.setTimeout(30000);
JmsTransactionFactory factory = new JmsTransactionFactory();
factory.setName("a-good-name");
txConf.setFactory(factory);
builder.setTransactionConfig(txConf);
}
builder.setInitialState(AbstractService.INITIAL_STATE_STARTED);
builder.setResponseTimeout(10000);
builder.setDeleteUnacceptedMessages(false);
builder.setDisableTransportTransformer(false);
builder.setEncoding("UTF-8");
InboundEndpoint inept = builder.buildInboundEndpoint();
muleContext.getRegistry().registerEndpoint(inept);
msgSource.addSource(inept);
The inbound endpoint should work at this point.
1. Create an inbound point configurer of the target inbound type
public class JmsInboundConfigurer implements MuleContextAware
{
ServiceCompositeMessageSource msgSource;
public void setMuleContext(MuleContext context) {...}
public MuleContext getMuleContext() {...}
public void setService(Service svc) {...}
public Service getService() {...}
public void setConnector(Connector conner) {...}
public Connector getConnector() {...}
}
In the mule-config.xml, add
<spring:bean id="my.configurer" class="com.acme.JmsInboundConfigurer" init-method="init">
<spring:property name="service">
<spring:ref bean="my.service"/>
</spring:property>
<spring:property name="connector">
<spring:ref bean="activemq.connector"/>
</spring:property>
</spring:bean>
2. Statically configure an inbound point and read it back to match the configuration
<jms:activemq-connector name="activemq.connector"
brokerURL="tcp://localhost:61616"/>
<jms:endpoint name="jms.endpoint" queue="..."
connector-ref="activemq.connector" exchange-pattern="request-response"/>
JmsInboundConfigurer.init() would make a good place to output all the information.
this.msgSource =
(ServiceCompositeMessageSource)getService().getMessageSource();
logger.info(msgSource.toString());
Use msgSource.getEndpoint("jms.endpoint") or msgSource.getEndpoints() to read back end points to compare with the static configuration
3. Comment out the static configure and create it programmatically
The following code fragment creates and add a JMS inbound point to the service assigned
EndpointURIEndpointBuilder builder = new EndpointURIEndpointBuilder(uri, this.muleContext);
builder.setName("jms.endpoint");
builder.setConnector(this.connector);
builder.setExchangePattern("request-response");
// builder.setProperty("", xyz); // if any
if (transaction needed) {
MuleTransactionConfig txConf = new MuleTransactionConfig();
txConf.setAction(ACTION_BEGIN_OR_JOIN);
txConf.setMuleContext(muleContext);
txConf.setTimeout(30000);
JmsTransactionFactory factory = new JmsTransactionFactory();
factory.setName("a-good-name");
txConf.setFactory(factory);
builder.setTransactionConfig(txConf);
}
builder.setInitialState(AbstractService.INITIAL_STATE_STARTED);
builder.setResponseTimeout(10000);
builder.setDeleteUnacceptedMessages(false);
builder.setDisableTransportTransformer(false);
builder.setEncoding("UTF-8");
InboundEndpoint inept = builder.buildInboundEndpoint();
muleContext.getRegistry().registerEndpoint(inept);
msgSource.addSource(inept);
The inbound endpoint should work at this point.
Wednesday, August 3, 2011
Find socket/port status on Linux
When debugging or monitoring a client-server application or any connected application, it is necessary to find out what is going on at socket level.
To start, use
netstat -an
To start with TCP connections, use
netstat -ant
Although the option -p should show process information (PID), it usually gives a "-" for that field. Remember to use ifconfig to find interfaces and IP addresses.
To start, use
netstat -an
To start with TCP connections, use
netstat -ant
Although the option -p should show process information (PID), it usually gives a "-" for that field. Remember to use ifconfig to find interfaces and IP addresses.
To begin this blog
I am a software engineer, and I code.
I use the Internet as a reference, language features, open-source software, best practices and quick suggestions on day-to-day issues. There are a lot of good articles, but they are easily buried under by other search engine optimized sites. I decided to log what I found and my thoughts on the fine points. This will definitely help myself, and hopefully will help other people.
Subscribe to:
Posts (Atom)