This is a skeleton of what is needed to build a custom jsp tag which does something to its body. For example a tag could change the urls of all the links found in its body.
make a file called CustomTag.tld and put it into WEB-INF:
use it like this on your JSP:
<%@ taglib uri="com.mycompany.CustomTag" prefix="x"%>
<x:ct>
here is some stuff inside the tag!
<c:out value="${someparam}"/>
</x:ct>
Friday, February 09, 2007
How to make a redirect servlet
make a servlet which calls the following method on doPost() and on doGet()
Wednesday, February 07, 2007
improve eclipse performance in windows
this eclipse plugin forces windows keep eclipse in memory / reduces thrashing
http://suif.stanford.edu/pub/keepresident/
http://suif.stanford.edu/pub/keepresident/
UNIX: list what sudo permissions you have
> sudo -l
Password:
You may run the following commands on this host:
(root) /usr/local/apache/bin/
(root) NOPASSWD: /app/teamsite/iw-home/opendeploy/bin/iwsyncdb.ipl
(root) NOPASSWD: /etc/init.d/smb
(root) NOPASSWD: /usr/local/samba/bin
(root) NOPASSWD: /bin/vi /etc/group
(root) NOPASSWD: /usr/local/bin/top
(root) NOPASSWD: /bin/vi /etc/group
(root) NOPASSWD: /usr/bin/ls
(root) NOPASSWD: /usr/ucb/vipw
(root) NOPASSWD: /usr/local/bin/top
(root) /bin/tail
Password:
You may run the following commands on this host:
(root) /usr/local/apache/bin/
(root) NOPASSWD: /app/teamsite/iw-home/opendeploy/bin/iwsyncdb.ipl
(root) NOPASSWD: /etc/init.d/smb
(root) NOPASSWD: /usr/local/samba/bin
(root) NOPASSWD: /bin/vi /etc/group
(root) NOPASSWD: /usr/local/bin/top
(root) NOPASSWD: /bin/vi /etc/group
(root) NOPASSWD: /usr/bin/ls
(root) NOPASSWD: /usr/ucb/vipw
(root) NOPASSWD: /usr/local/bin/top
(root) /bin/tail
Javascript: matching with regex
There seem to be 3 ways to use regular expressions in javascript:
1.
var val = document.getElementById("some_id").value;
val.replace(/^\s+|\s+$/g, ""); //trim using regex
2.
var alpha = /^[A-Za-z]+$/ ;
var val = document.getElementById("some_id").value;
if(alpha.test(val)){
//val matches alpha
}
3.
1.
var val = document.getElementById("some_id").value;
val.replace(/^\s+|\s+$/g, ""); //trim using regex
2.
var alpha = /^[A-Za-z]+$/ ;
var val = document.getElementById("some_id").value;
if(alpha.test(val)){
//val matches alpha
}
3.
var val = document.getElementById("some_id").value;
var alpha ='((?:[a-z][a-z]+))'; // Word 1
var p = new RegExp(alpha,["i"]);
var m = p.exec(val);
if (m.length>0)
{
var word=m[1];
//word is the capture group 1
}if anyone knows a better way, feel free to share.
Monday, January 29, 2007
NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream
problem:
when trying to send mail i get error: NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream
solution:
get mail.jar and put it on your classpath
http://java.sun.com/products/javamail/downloads/index.html
when trying to send mail i get error: NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream
solution:
get mail.jar and put it on your classpath
http://java.sun.com/products/javamail/downloads/index.html
Friday, January 26, 2007
Java: find nested balanced tags
Problem:
I needed to parse out some divs from a html page, and java's regex cant do it. atleast when you have arbitrary number of nested balanced elements.
Solution:
Use at your own risk.
I needed to parse out some divs from a html page, and java's regex cant do it. atleast when you have arbitrary number of nested balanced elements.
Solution:
Use at your own risk.
Tuesday, January 16, 2007
UNIX: dd trick to speed up disk access times
This was stolen from the Lucene mailing list as a strategy to warm up an IndexSearcher:
Something like dd if=/path/to/index/foo.cfs of=/dev/null
Basically, force the data through the kernel preemptively, so FS caches it.
Run vmstat while doing it, and if the index hasn't been cached by the FS, you should see a spike in IO activity while dd is running.
source: (something in the middle of the thread)
http://www.gossamer-threads.com/lists/lucene/java-user/43418
Something like dd if=/path/to/index/foo.cfs of=/dev/null
Basically, force the data through the kernel preemptively, so FS caches it.
Run vmstat while doing it, and if the index hasn't been cached by the FS, you should see a spike in IO activity while dd is running.
source: (something in the middle of the thread)
http://www.gossamer-threads.com/lists/lucene/java-user/43418
Monday, January 15, 2007
java.lang.NoSuchFieldError:prohibited Lucene Highligher
Problem:
java.lang.NoSuchFieldError: prohibited
at
org.apache.lucene.search.highlight.QueryTermExtractor
.getTermsFromBooleanQuery(QueryTermExtractor.java:91)
Solution:
You are using an old (pre 1.9) highlighter lib on a
1.9+ lucene. You need to pull the latest highlighter
sources from the svn repos, make a jar out of them and
use that inst
also, 'prohibited' referes to actual method param inside
of highlighter.
nice regex util class, replaceAll
elliotth.blogspot.com/java-implementation-of-rubys-gsub.html
Here is an example of what this does:
Here is an example of what this does:
String result = new Rewriter("([0-9]+) US cents") {
public String replacement() {
long dollars = Long.parseLong(group(1))/100;
return "$" + dollars;
}
}.rewrite("5000 US cents");
System.out.println(result);
prints>> $50
nice!
Wednesday, January 10, 2007
java.io.IOException: read past EOF on Lucene
Problem:
This is the error:
java.io.IOException: read past EOF
Lucene throws that error when you try to read an index.
Solution:
The lucene index was most likely corrupted at some point. In my case, it broke during the ant's copy in the deployment.
Other pages say that it may be because the index uses a weird char set where chars may be bigger or smaller then what you think they are, so if you think they are 8 bits, and they are actually 7, you will read past EOF.
This is the error:
java.io.IOException: read past EOF
Lucene throws that error when you try to read an index.
Solution:
The lucene index was most likely corrupted at some point. In my case, it broke during the ant's copy in the deployment.
Other pages say that it may be because the index uses a weird char set where chars may be bigger or smaller then what you think they are, so if you think they are 8 bits, and they are actually 7, you will read past EOF.
Friday, December 08, 2006
using cron on solaris
crontab -l
figure out whats in your cron, copy to a file called myCron
modify the file and add the crap you want
50 13 * * * /usr/local/subversion/svnbackup.sh
this runs the script at 1:50pm every day
then copy the file into the cron:
crontab < myCron
yey!
figure out whats in your cron, copy to a file called myCron
modify the file and add the crap you want
50 13 * * * /usr/local/subversion/svnbackup.sh
this runs the script at 1:50pm every day
then copy the file into the cron:
crontab < myCron
yey!
Monday, December 04, 2006
UNIX: delete files older then X days old
This can be useful when making a rolling backup script
find /directory -type f -mtime +12 | xargs rm
/directory: your directory name that the files are under (rename appropriately)
-type f: only delete files (not subdirectories)
+12: older than 12 days old
find /directory -type f -mtime +12 | xargs rm
/directory: your directory name that the files are under (rename appropriately)
-type f: only delete files (not subdirectories)
+12: older than 12 days old
Monday, November 27, 2006
quick mod by 11
1==1 (mod 11)
10==-1 (mod 11)
100==1 (mod 11)
1000==-1 (mod 11)
Therefore 123456 == 6 - 5 + 4 - 3 + 2 - 1 (mod 11) == 3 (mod 11)
Obviously you may need to do a further % operation after adding and subtracting digits, but it should be reasonably fast.
10==-1 (mod 11)
100==1 (mod 11)
1000==-1 (mod 11)
Therefore 123456 == 6 - 5 + 4 - 3 + 2 - 1 (mod 11) == 3 (mod 11)
Obviously you may need to do a further % operation after adding and subtracting digits, but it should be reasonably fast.
Wednesday, November 08, 2006
Thursday, October 19, 2006
handy eclipse template: class quick init
public ${enclosing_type}() {
${cursor}
}
public static void main(String[] args){
new ${enclosing_type}();
}
${cursor}
}
public static void main(String[] args){
new ${enclosing_type}();
}
Wednesday, September 13, 2006
how to update ports on freebsd (better way)
first get cvsup_fastest
then make a script
#!/bin/sh
cvsup -gL2 -h`cvsup_fastest -Q -c us` /usr/share/examples/cvsup/ports-supfile
cron this or whatever
then make a script
#!/bin/sh
cvsup -gL2 -h`cvsup_fastest -Q -c us` /usr/share/examples/cvsup/ports-supfile
cron this or whatever
Tuesday, September 12, 2006
unix shell scripting: args check
usage()
{
echo "Usage: program [args] [bleee]"
}
if [ $# -eq 0 ] ; then
echo "ERROR Insufficient arguments"
usage
exit 1
fi
{
echo "Usage: program [args] [bleee]"
}
if [ $# -eq 0 ] ; then
echo "ERROR Insufficient arguments"
usage
exit 1
fi
Monday, September 11, 2006
send email on solaris 8 with xmail
/bin/mailx -s "subject" email@address.com < /path/to/message/body.txt
the message body has to be a file.
the message body has to be a file.
Tuesday, September 05, 2006
Subscribe to:
Posts (Atom)