create an eclipse auto-complete template for creating a logger
Window -> Show View -> Other.. -> Templates
new java template
name logger
${:import(org.apache.commons.logging.LogFactory,org.apache.commons.logging.Log)}
private final static Log log = LogFactory.getLog(${enclosing_type}.class);
now ctrl+space and logger will save you some typing
Thursday, July 14, 2011
Thursday, February 10, 2011
make java xpath work on large files
this post is just for my own reference. if it helps you then fine. but read the following post first:
http://blog.astradele.com/2006/02/24/slow-xpath-evaluation-for-large-xml-documents-in-java-15/
family.xml
...
if we've got a few thousand dads in a 10 meg xml file and you try and use xpath
dads.item(i) will completely screw you here. you will wait forever.
if you break the dads.item(i) off of the tree you'll be fine. of course you wont be able to look back up the new tree.
method 1
i like method 2.. make a new doc with the nodes you need. this will not be reparsed. just a different reference point for the expression to start from
http://blog.astradele.com/2006/02/24/slow-xpath-evaluation-for-large-xml-documents-in-java-15/
family.xml
if we've got a few thousand dads in a 10 meg xml file and you try and use xpath
DocumentBuilder docbuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); org.w3c.dom.Document doc = docbuilder.parse(new FileInputStream("family.xml"); XPath xpath = XPathFactory.newInstance().newXPath(); NodeList dads = (NodeList)xpath.evaluate("//dad", doc, XPathConstants.NODESET) for( int i = 0 ; i < dads.getLength() ; i++){ System.out.println(xpath.evaluate("./son/@age",dads.item(i))); }
dads.item(i) will completely screw you here. you will wait forever.
if you break the dads.item(i) off of the tree you'll be fine. of course you wont be able to look back up the new tree.
method 1
for( int i = 0 ; i < dads.getLength() ; i++){ Node oneDad = dads.item(i); System.out.println(xpath.evaluate("./son/@age",oneDad.getParentNode().removeChild(oneDad)); }
i like method 2.. make a new doc with the nodes you need. this will not be reparsed. just a different reference point for the expression to start from
for( int i = 0 ; i < dads.getLength() ; i++){ org.w3c.dom.Document oneDad = docbuilder.newDocument(); oneDad.adoptNode(dads.item(i)); System.out.println(xpath.evaluate("./son/@age",oneDad); }
Thursday, December 9, 2010
Grails reasonable log4j settings for development
Config.groovy
...
debug to file and info to your terminal window
...
log4j = { appenders { console name:'stdout', threshold: org.apache.log4j.Level.INFO file name:'file', file:'/var/logs/grails.log' } root { debug 'file', 'stdout' additivity = true } error 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration 'org.springframework', 'org.hibernate', 'net.sf.ehcache.hibernate' warn 'org.mortbay.log', 'org.codehaus.groovy.grails.commons' // core / classloading info 'org.codehaus.groovy.grails.web.servlet', // controllers 'org.codehaus.groovy.grails.web.pages', // GSP 'org.codehaus.groovy.grails.web.sitemesh', // layouts 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping 'org.codehaus.groovy.grails.web.mapping', // URL mapping 'org.codehaus.groovy.grails.plugins' // plugins debug 'grails.app' }
debug to file and info to your terminal window
Tuesday, October 26, 2010
Tapestry 5.1 @OnEvent not firing
Submit buttons in Tapestry 5.1 not firing their @OnEvent handlers
There are a lot of examples out there in the ether for a tapestry 5 submit button handler. And they don't work right off the bat.
Bad Example
If you read Tapestry 5: Building Web Applications you will find an example of a form submit button handler.blah.tml: <input type="submit" t:type="submit" t:id="submitButton" value="Submit"/> blah.java: @OnEvent(component="submitButton") void onSubmitButton() { System.out.println("Submit button was pressed!"); }
It doesn't work. Then you start stepping through the code and learning more than anyone wants to know about tapestry's event handling. Note: i did not step through the code or learn anything about tapestry's event handling.
The problem is that the default for @OnEvent 's value parameter is 'action'.
The default event value for a submit button is 'selected'.
Good Example
blah.tml: <input type="submit" t:type="submit" t:id="submitButton" value="Submit"/> blah.java: @OnEvent(component="submitButton", value="selected") void onSubmitButton() { System.out.println("Submit button was pressed!"); }
Read the book
I really did like the book Tapestry 5: Building Web Applications. It has a lot of simple recipes. Well presented concepts.Also the beginners Guide Tutorial on the tapestry home page is very good. Gets you up and running with a default application very quickly. Assuming you can hack your way by the typos and deprecated maven commands.
They both suffer from the fact that tapestry changes in little ways and the documentation gets stale pretty quickly. Hey, just like code in the real world.
Monday, September 27, 2010
Jrebel is the greatest tool in the world
thank you jrebel
thank you jrebel
thank you jrebel
watch the video
http://www.zeroturnaround.com/blog/video-do-you-really-get-class-loaders-a-jazoon-talk-by-jevgeni-kabanov/
use the tricks
1)
String classname= getClass().getName().replace('.', '/')+".class";
URL resource= getClass().getClassLoader().getResource(classname);
2)
-verbose:class
3)
javap -private Myclass
thank you jrebel
thank you jrebel
watch the video
http://www.zeroturnaround.com/blog/video-do-you-really-get-class-loaders-a-jazoon-talk-by-jevgeni-kabanov/
use the tricks
1)
String classname= getClass().getName().replace('.', '/')+".class";
URL resource= getClass().getClassLoader().getResource(classname);
2)
-verbose:class
3)
javap -private Myclass
Monday, March 1, 2010
SOCKS: Your only paranoid if they aren't out to get you
The Command
ssh -C2qTnN -D 9990 myusername@my.linux.server.orgPurpose
Secure a private connection from your laptop to your linux server in order to bypass local snoops and rules.Platform
Firefox 3.x web browser. Debian-style linux server.Disclaimer
There are several blog posts on this very same subject (TODO: link helpful blogs here.) I wanted to add this post to get some more recent screenshots of foxyproxy (TODO: link foxyproxy here) and discuss some troubleshooting techniques.Oh and this is meant for completely legal internet operations. Don't use it to subvert the law. You are completely responsible for everything you do to your computer and with your computer.
Introduction
The scenario here is you, sitting in the local coffee shop. With your macbook and your 17word coffee order that makes you feel like some sort of a connoisseur. You are connected to their wifi. You are chatting over IM and reading web-pages and skyping over your fancy VOIP. There is no reason anybody should be monitoring what you are doing. But they could. They could have blocked access to meebo because they don't want you to jerk around at work... they could have blocked out the new york times website because it's a hotbed of liberal thinky think that might offend jesus.Good news - that's not how the internets work. You have a linux server with an SSH server running on it. (TODO: blog on how to create a linux server with ssh running) You have firefox. You can make a relatively secure and private connection between your laptop and your linux server. The coffeeshop only sees an encrypted connection between your laptop and your linux box. Your linux box and the rest of the interweb sees you browsing free and easy from your linux box.
laptop in coffee shop <--secure cnx-->linux box<--normal internet surfing activity-->the interwebs
Set up the proxy connection on your laptop
open up a command line terminalmac
All modern macs have a terminal application.Ubuntu
Applications -> Accessories -> TerminalWindows
Install cygwin. Make sure you get the SSH package. Open a terminal from Start -> All Programs -> Cygwin -> Cygwin Bash Shellenter the command
ssh -C2qTnN -D 9990 myuser@my.host.com
You may be prompted to verify the servers key - type Yes. You will be prompted for a password - enter it. LEAVE THIS TERMINAL OPEN! Your connection will drop once you close this terminal.
Verify you have a connection up. Open up another terminal and type
telnet localhost 9990. This should connect. It's more likely you will get a negative message if it doesn't connect than a positive message if it does connect.
Firefox and FoxyProxy
Install firefox. Then install the addon FoxyProxy.I have always used the free version without experiencing any limitations. Feel free to pay if you want to support the developer.
Configure FoxyProxy
In firefox go to Tools -> FoxyProxy -> OptionsChoose Add New Proxy on the left
set up your proxy details
host: localhost
port: 9990
Check the box 'SOCKS proxy?'
set up your url pattern
Select the URL pattern tab. Click the 'Add new pattern' button on the top left.
fill out the new pattern form like so:
hit OK and you've got your proxy configured.
now enable private-ish surfing through the tools menu
Closing Arguments
Now what do you have on your hands? Assuming you have the latest version of FoxyProxy and everything works as advertised. All of your DNS lookups should be done over the proxy so the local wifi cannot tell what you are looking for. And all of your browsing http traffic should be private from the laptop to the linux server. All the traffic should appear to the various servers in the cloud as if it originates from your linux server. There is NO privacy for bare http requests between your linux server and the interwebs.
Monday, February 22, 2010
Stupid perforce trick #517
command
p4 fstat //depot/mycode/myfile.html | grep clientFile | awk '{print $3}'
purpose
Perforce command line often spits out filenames in the 'depot' format. You will need to translate these 'depot' names into local paths in order to work with the files in your favorite editors and GNU utilities.explanation
p4 fstat
p4 fstat is a very useful command that can access all sorts of fun information about a file under perforce control. Do yourself a favour and look it up right now by typingp4 help fstatinto your terminal. Then try out as many options as you can before screaming 'i hate perforce and what is so f@#$king wrong with SVN..' but i digress
the output of p4 fstat filename is something like this
... depotFile //depot/mycode/myfile.html ... clientFile /home/username/mycode/myfile.html ... isMapped ... headAction integrate ... headType text ... headTime 1253307019 ... headRev 2 ... headChange 73363 ... haveRev 2
grep clientFile
Filter out the line containing the filename on the local filesystem... clientFile /home/username/mycode/myfile.html
awk '{print $3}'
print the 3rd field which contains the actual file name/home/username/mycode/myfile.html
Subscribe to:
Posts (Atom)