Thursday, December 9, 2010

Grails reasonable log4j settings for development

Config.groovy

...
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

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.org

Purpose

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 terminal

mac

All modern macs have a terminal application.

Ubuntu

Applications -> Accessories -> Terminal

Windows

Install cygwin. Make sure you get the SSH package. Open a terminal from Start -> All Programs -> Cygwin -> Cygwin Bash Shell
enter 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 -> Options


Choose 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 typing
p4 help fstat
into 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

Tuesday, February 9, 2010

Stupid Perforce Trick #87 - show my last 100 submits

the trick

command: p4 changes -u myusername | head -100 | awk '{print $2}' | p4 -x- describe

purpose

Perforce on the unix command line to search through last 100 changes you made

platform

any command line perforce with gnu tools available

introduction

Every once in a while someone asks me what i did to some code a month ago. Okay maybe it's more like 'what did you screw up 10 minutes ago?!?!' If you're anything like me - once you commit your changes you forget all about the task and move on (note to self eclipse mylyn is a great enabler of this attitude)

The easy answer to the question 'what did you do to this code somewhere in the recent past' is to check the perforce history for your checkins. Pipe this to your trusty GNU tools and you can easily weed out all the crap and find exactly what you're looking for.

So lets say I remember my bug had something to do with the Person.java class. I want to review that changeset and make further modifications to some of the files.. i just don't remember what the changes were or what files were affected.

the command

step 1 - list changes

the following command gives you a printout of all the changes submitted to your perforce server

command: p4 changes

step 2 - list your changes only

You really just want to see your changes

command: p4 changes -u myusername

this gives you several rows of information that look like this

output:
Change 9991 on '2010/01/01' by myusername@myclientname 'FIX horrible bug i am unsung hero'

Change 9995 on '2010/01/02' by myusername@myclientname 'oops fix 9991 again because i was drunk yesterday'

step 3 - extract only the changeset id from the output

We'll pull out just the changeset id so that we can investigate those changesets further

command: p4 changes -u myusername | awk '{ print $2 }'
output:
9991
9995

step 4 - dig deeper into those changeset

take our list of changesets and ask perforce to describe each of those in detail
command: p4 changes -u myusername | awk '{ print $2 }' | p4 -x- describe

the final 'p4 -x- describe' means 'take stdin and perform the p4 command on it'

'cat blah.txt | p4 -x- describe' is equivalent to 'cat blah.txt | xargs -I {} p4 describe {}'

if that helps

the output of this command can be quite large. it contains the the files you have changed and the diffs of each changed file.

step 5 - use our favorite editor to search through the changes

Now you have an output stream that you can use with grep or less or whatever to find filenames and lines of code. Remember that i was looking for a change that had something to do with Person.java

command: p4 changes -u myusername | awk '{ print $2 }' | p4 -x- describe | grep -n Person.java



or my favorite
command: p4 changes -u myusername | awk '{ print $2 }' | p4 -x- describe | less

PGP key verification


purpose


Notes on how to check a PGP signature.


Platform


Ubuntu 8.x

note: gpg is the open version of pgp.. once you install pgp or gpg the commands will be the same.. use pgp and gpg interchangeably

install pgp

command: sudo apt-get install pgp

download your software and key

command: wget www.somehost.com/blah.tar.gz
command: wget www.somehost.com/blah.tar.gz.asc

first pass at verifying

will probably fail because you don't have the signer's public key yet

command: pgp blah.tar.gz.asc

this will print out a message that you dont have the public key for some key id like
No signature found for AC487ADC


get the signers key from a store

gpg --keyserver pgpkeys.mit.edu --recv-key AC487ADC


second pass at verifying

command: pgp blah.tar.gz.asc

this should show that the binary blah.tar.gz was signed by the author

it might print some messages that nobody else trusts this signature because the author has not built a web of trust