Wednesday, April 06, 2011

Grails: Securing CKEditor URLs

Problem:
I am using the grails CKEditor plugin and i wanted to secure the file manager urls to be accessed only by a site admin. I am using the Spring Security Core plugin for site security, but i was already using annotations elsewhere on my site, so using a InterceptUrlMap was not an option.

So, how to keep using annotations and secure a plugin's urls?

Solution:
The trick is properly using the controllerAnnotations.staticRules (which really isnt that hard if you pay attention to the docs).
Here is the mapping that works for ANY url mapping you define to CKEditor:



Thursday, March 24, 2011

manually set id of grails domain object

Problem:
if you create a new domain object and set its id in the constructor like this:
Cat catman = new Cat(id:1000, name: "catman", kind: "domestic short haired")
later, if you look at the object the id will be null. what gives?!


Solution:
Its madness, but it works to assign the id after the object is made. Just add
catman.setId(1000);
and you are in business.

Note: if you want to save the object into db after doing this, you must set the id generator to 'assigned'

Sunday, March 13, 2011

lg cdma usb modem driver

The lg mobile phone driver is hard to find. i am using it to make bitpim work with my phone.

It will work with all LG VX-something phones and also is sometimes called this:

Prolific USB-to-Serial Comm Port Driver
LGE CDMA Composite USB Device Driver
LGE CDMA USB Modem Driver
LGE CDMA USB Modem Diagnostic Serial Port Driver
LGE CDMA USB Modem (VCOMM) Driver
LGE CDMA USB Modem Diagnostic Serial Port (VCOMM) Driver
LGE CDMA USB Serial Port Driver


get it here:
http://programmingdrunk.com/random-stuff/LGUSBModemDriver_4.6_WHQL.zip

Monday, February 21, 2011

Class needed by SvnTask cannot be found

problem:
getting this error when trying to build:

taskdef A class needed by class org.tigris.subversion.svnant.SvnTask cannot be found: org/tigris/subversion/svnclientadapter/SVNClientException

solution:

I didnt unzip all libs that came with svnant into my lib folder. Only unzipped svnant.jar. need to put them all in there.

Sunday, February 06, 2011

Multiple domains with tomcat behind apache

This is how you would host multiple domains/webapps on a single tomcat behind apache via mod-jk.

first setup tomcat behind apache

I am setting up a new domain called dogself.com:

in server.xml add this under last host:

<Host name="dogself.com"  appBase="webapps-dogself"
  unpackWARs="true" autoDeploy="true"
  xmlValidation="false" xmlNamespaceAware="false">
<alias>www.dogself.com<alias>
</Host> 
 
and also add another connector port:
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" /> 

create a webapps-dogself directory next to webapps and give it the same permissions

in your virtualhost apache config:
ServerName dogself.com 
JkMount  /* dogself 
 
in workers.properties add dogself worker to list:
worker.list=another,dogself

# Define dogself
worker.dogself.port=8010
worker.dogself.host=dogself.com
worker.dogself.type=ajp13 

If you want the manager app to work on the domain you need to:
mkdir /etc/tomcat6/Catalina/dogself.com 

and copy the manager.xml into it from /etc/tomcat6/Catalina/localhost

in /var/lib/tomcat6 create a webapps-dogself dir and give it 0775 perms and chown it to tomcat:tomcat

restart tomcat and apache

Troubleshooting:
if you get error:
worker dogself can't resolve tomcat address dogself.com
Check that your dns a/aaaa records point to your ip. Comment out the worker in workers.properties and see if you can get to the apache vhost.

if any of the domains seems to point to another domain, ie the war that is running on one domain is incorrect. check if you are in the www.domain and if you have aliased the www both in tomcat and in apache. if you dont alias the www correctly tomcat will send you the the defaultDomain as defined in server.xml

Thursday, February 03, 2011

Linode: how to install mod_jk, tomcat behind apache

This "tutorial" is for Ubuntu 10.04 LTS (Lucid).
This is how you would set up Tomcat6 behind Apache2 via mod_jk

I am assuming that you have apache2 installed and tomcat6 installed. I also assume you have deployed and can find your tomcat app possibly on port 8080 of your linode.

  1. Install mod_jk:
    apt-get install libapache2-mod-jk
  2. Create workers.properties in /etc/apache2/ and add the following into it:
    # this lives in /etc/apache2/workers.properties
    # workers.properties - ajp13
    #
    # List workers
    worker.list=worker1
    
    # Define worker1
    worker.worker1.port=8009
    worker.worker1.host=localhost
    worker.worker1.type=ajp13
    
  3.  Edit your apache2 config in /etc/apache2/apache2.conf and add this to the end:
    # tomcat connector stuff:
    JkWorkersFile /etc/apache2/workers.properties
    # Where to put jk shared memory
    JkShmFile     /var/log/apache2/mod_jk.shm
    # Where to put jk logs
    JkLogFile     /var/log/apache2/mod_jk.log
    # Set the jk log level [debug/error/info]
    JkLogLevel    info
    # Select the timestamp log format
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y] 
    
  4. In your /etc/apache2/sites-enabled/ dir find the vhost you want to use tomcat and edit it, at the end of the vhost declaration put:
    #Everything under root goes to tomcat
    JkMount  /* worker1
    #html files should be served by apache2
    JkUnMount /*.html worker1
    
  5. Edit /etc/tomcat6/server.xml and make sure that the ajp connector is uncommented:
    <connector port="8009" protocol="AJP/1.3" redirectport="8443" />
    
  6. restart tomcat: /etc/init.d/tomcat6 restart
  7. restart apache: /etc/init.d/apache2 restart
  8. navigate to yourdomain.com/ and you should be all tomcatted

Wednesday, January 26, 2011

How to make your bed for engineers

Being an engineer I am always looking for more efficient ways to do all manner of household tasks.
Making the bed has never been my strong point. My wife makes the bed faster than me, and it always looks better. I have long given up trying to figure out her technique, she probably just has many more years of experience than me. She is a principal bed maker while i am just a bed maker intern.

Yesterday a friend of mine shared a bed making technique with me that has improved the tidiness and speed of bed making. I would like to share this technique with you!

The secret to making large beds efficiently is to make the bed while you are in it! Being in the middle of the bed gives you maximum reach to both sides, where you can straighten out the covers. You no longer need to make several passes from one side of the bed to the other. After you get the bed looking nice, carefully roll out. Chances are that you will need just one more pass to fix the wrinkles in the covers. 



Thursday, December 23, 2010

after a request, page reloads 2 times and contains very little html

I just fixed a very strange issue in our application.

It went something like this:
User would click on a link that opened another page. This page would flash for a second, then another page would open containing just the string "2010".

The bug came from QA as being a regression related to recent development, so i started debugging in the code. There was nothing in the logs.

Then i opened firebug, went into "net" mode and persisted it. I saw my original request made, along with headers, and then another request made, this one had no headers at all.

Solution:

document.write is evil. There was recently a change to the code which attempted to make the copyright year dynamic by replacing it with
document.write(new Date().getFullYear());
inside of a script tag. This alone wouldn't cause the issue, but document.write only works correctly if its called when the page is being rendered. If the page is rendered, it will overwrite the entire page with whatever its writing out. The issue was the the page the user was going to next, was gotten via ajax, and thus the script was called after the page was loaded, overwriting the entire page.

Oh the glory of being a programmer.

Saturday, December 04, 2010

Convert map to object in groovy

You need to convert a map into an object in groovy. There must be a better way then iterating through the map and setting all the properties in the object via reflection or otherwise. There is:


posting with syntaxhighlighter

I always forget the markup for posting syntax highlighted code. here it is:

<script class="brush: java" type="syntaxhighlighter">

thank me later

Monday, November 29, 2010

fixing java.lang.NoClassDefFoundError: javax/el/ELContext error

I got the error java.lang.NoClassDefFoundError: javax/el/ELContext  when i was trying to run a unit test.

Solution:
el-api.jar needs to be in your class path. This is usually found in the tomcat/lib dir. I usually add everything in the tomcat lib to my classpath

select from two tables into a single column

delete from user where id not in (select a.id from person a UNION select b.id from merchant b)

Tuesday, October 26, 2010

No Hibernate Session bound to thread

Problem:
I am converting an application that uses HibernateDaoSupport in the DAOs to use POJOs instead.
Each pojo now must autowire a sessionFactory in order to hook into hibernate.

I am getting the following error when i try to getSession() on my sessionFactory:


No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

Solution:
add a OpenSessionInViewFilter to my web.xml and filter on * with it

Saturday, October 16, 2010

MLSPin google maps grease monkey script

I am looking at houses.
I am on the mlspin website which has addresses but no maps. I end up having to go look up these addresses in google maps.

This plugin adds a google map iframe on each listing page in mls pin.

download:
http://userscripts.org/scripts/show/88186

Runs on: http://vow.mlspin.com/clients/

Thursday, September 02, 2010

Babushka's Mushroom Soup

  1. make chicken or beef broth in a 2 liter pot
  2. add some rice (4-5 TBSP)
  3. let boil so that rice and potatos cook
  4. cut up some mushrooms and add them. wait until it boils
  5. combine ghee, 2 grated carrots and 1 chopped onion, salt, pepper, 1/4 tsp sugar. cook in the microwave for 2-3 mins
  6. when the halved potatos are cooked, take them out and mash them
  7. add potatos and ghee mixture to the soup
  8. take out some broth and put it in a cup, add 2 tablespoons of mushroom cheese, and mix
  9. add mushroom cheese mixture into the soup
  10. add bay leaf and greens

done!

For those who are wondering what mushroom cheese is. here is a link to an example of it.
I found some being sold in a Russian store. You can buy ghee at whole foods

Tuesday, August 24, 2010

Waiting for things in javascript

Problem:
Sometimes i need to wait for something to come into existence in javascript, and then do something with it. This is usually because another frame (shudder) is still loading and i need something in it. Also it helps with IE bugs where something should be there, but isn't because IE is taking a stupid long time to load it.

Solution:

Use this utility function to create a check/act loop.