Monday, November 29, 2010

Recursive setfacl or how to add your PostgreSQL data directory to Git

This was an interesting annoyance.

I was working on some examples and wanted to be able to delete everything cleanly after I was done.

I had an instance of JBoss and wanted PostgreSQL to use a local directory for data.

My directory structure was :
example/
data
jboss-eap-5.1
logs

I had a user "postgres" to run PostgreSQL. Since the rest of the directory was created by me, "jeremy," I used setfacl to add "postgres" to the data directory:
setfacl -m u:postgres:rwx ./data/

When I ran :
initdb -D data/

It wasn't happy. I got :
"initdb: could not change permissions of directory"

Next up was :
sudo chown -R postgres:postgres data/

That worked for "initdb." I was able to su to the "postgres" user and execute "initdb" in "data/."

I was happy until I tried to add "data/" to Git :
[jeremy@jeremy example]$ git add data
error: open("data/PG_VERSION"): Permission denied
error: unable to index file data/PG_VERSION
fatal: adding files failed

setfacl to the rescue!
sudo setfacl -Rm u:jeremy:rwx ./data/

Unfortunately I got the same error.
I was missing the important "d" argument. The following worked :
sudo setfacl -Rm u:jeremy:rwx,d:u:jeremy:rwx ./data/
"sudo" was necessary because of changing the ownership to the "postgres" user.

I added everything to Git.

The moral of this rambling story : use the "d" flag with setfacl to cascade permissions to the files.

Tuesday, October 12, 2010

xlcip or How to copy past from the command line to x-windows

Brain Ashburn, my colleague in the Atlanta Red Hat office, introduced me to the xclip utility today. It copies output from the command line and puts it into x-windows.

For example, to copy the current directory :
 pwd | xclip -i -sel "clip"

There are of course more useful things that can be piped to it. To try it out create a file, add some text and :
cat newfile | xclip -i -sel "clip"

Its available through yum :
sudo yum install xclip

Tuesday, October 5, 2010

Installing MySQL with Yum

A quick note on installing mysql with yum in case anyone else is lazy (like me) and runs :

sudo yum install mysql

That only installs half of what's needed. nixCraft sums it up nicely for RHEL. It also works for Fedora :

$ sudo yum install mysql
$ sudo yum install mysql-server

To start it up and set the root user/password :

$ sudo yum install mysql
$ sudo chkconfig mysqld on
$ sudo /etc/init.d/mysqld start
$ mysqladmin -u root password PASSWORD
$ mysql -u root -p

H2 Connections in Eclipse

H2 is a great database for prototyping and local work. Eclipse does not come with a default driver definition though.

Dan Allen has a nice tutorial on Google code illustrating how to set one up.

Friday, October 1, 2010

You don't have permission to access / on this server.

More fun with Apache.

There was a time when I could configure Apache without the help of Google. Alas, that time was years ago.

I wanted several versions of Apache on my machine so that I could test different mod_cluster configurations side by side.

I downloaded the Apache source, built it and put in "/examples" under my home directory. After I started it I got :
You don't have permission to access / on this server.


I immediately checked the directory permissions. They looked okay. I spent some time monkeying with the SELinux security settings.

The problem was simple: Apache needs execute permissions all the way up to the root directory.

Simply moving my "examples" directory to the root fixed it.

Friday, September 24, 2010

httpd dead but subsys locked

While firing up apache this morning I got nothing. A quick "httpd status" returned an interesting message :
httpd dead but subsys locked
I have no idea when the lock got created. I assume it was the last time I ran apache. I don't use it as a daemon.

The solution was simply to delete the lock :
sudo rm /var/lock/subsys/httpd
All was well after that.

Friday, August 27, 2010

Gnome Do

A Mac user by choice I am completely addicted to Quicksilver.

I've used Launchy on Windows. Launchy is okay, but it requires a lot of babysitting. Searchable folders have to be tweaked to get decent results.

I've recently started using Fedora 13. Naturally I wanted a launcher. Wikipedia has a nice comparison of launchers. I installed Gnome Do from yum :

sudo yum install gnome-do



Its fast and returns meaningful results quickly. Its also written in Mono which I find marginally interesting.

Thursday, August 26, 2010

Hidden Gnome Panels in Fedora 13

I recently installed the new Fedora.

I right clicked my top panel and chose "Add Panel." Firefox, which had been maximized shrank about the size of a panel on the right side of the screen.

Just for grins I right clicked and added another panel. Firefox shrank on the left side.

I added "Show Desktop" to the top panel and clicked it. Panels appeared on each side of the desktop. I right clicked and deleted them.

Sunday, August 8, 2010

Debugging Grails Apps in Eclipse

This is pretty simple to accomplish. Simply run "grails-debug run-app" instead of "grails run-app".

However, be sure to start the debugger in Eclipse! The app doesn't finish starting up until the debugger is attached. I spent some time wondering what was taking so long before putting that together.

Thursday, July 29, 2010

Grails LinkageError for SAXParseException

I ran "grails run-app" for the app that I've been working on and was greeted with the following :

java.lang.LinkageError: loader constraint violation: loader (instance of <bootlo
ader>) previously initiated loading for a different type with name "org/xml/sax/
SAXParseException"
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:4
6)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at grails.util.PluginBuildSettings.getPluginInfos(PluginBuildSettings.gr
oovy:127)
at grails.util.PluginBuildSettings.getPluginInfos(PluginBuildSettings.gr
oovy)
at grails.util.PluginBuildSettings$getPluginInfos.callCurrent(Unknown So
urce)
at grails.util.PluginBuildSettings.getPluginInfo(PluginBuildSettings.gro
ovy:164)
at grails.util.PluginBuildSettings$getPluginInfo.callCurrent(Unknown Sou
rce)
at grails.util.PluginBuildSettings.getPluginInfoForSource(PluginBuildSet
tings.groovy:202)
at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTran
sformationVisitor.java:303)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(Compil
ationUnit.java:832)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(Compilat
ionUnit.java:519)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(Co
mpilationUnit.java:495)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.j
ava:472)
at _GrailsEvents_groovy.run(_GrailsEvents_groovy:54)
at _GrailsEvents_groovy$run.call(Unknown Source)
at _GrailsClean_groovy$run.call(Unknown Source)
at _GrailsClean_groovy.run(_GrailsClean_groovy:29)
at _GrailsClean_groovy$run.call(Unknown Source)
$
at _GrailsPlugins_groovy.run(_GrailsPlugins_groovy:32)
at _GrailsPlugins_groovy$run.call(Unknown Source)
at _GrailsRun_groovy$run.call(Unknown Source)
at _GrailsRun_groovy.run(_GrailsRun_groovy:31)
at _GrailsRun_groovy$run.call(Unknown Source)
at RunApp.run(RunApp.groovy:25)
at RunApp$run.call(Unknown Source)
at gant.Gant.prepareTargets(Gant.groovy:606)
Error loading event script from file [PATH_TO_GRAILS\.grails
\1.3.1\projects\PROJECT_NAME\plugins\code-coverage-1.1.8\scripts\_Events.gr
oovy] loader constraint violation: loader (instance of <bootloader>) previously
initiated loading for a different type with name "org/xml/sax/SAXParseException"

Grails had done some sort of update that I didn't pay a lot of attention to. I wondered if this had something to do with the update and will have to find out what went on later.

I found an entry on the Grails Jira dealing with the problem of xerces and Java 6. The suggested solution was to remove xml-apis-1.0.2.b2.jar.

I ran :
find . -name "*xml*"
find . -name "*api*"
from my project directory, my .grails directory and my .ivy directory. I found xml-apis-1.3.04.jar in my .ivy directory.

I ran jarscan against my project directory, .grails directory and .ivy directory and found 0 hits for SAXParseException.

I added :

    inherits("global") {
excludes "xml-apis"
}

To my BuildConfig.groovy file just below dependencies. The app ran.

Saturday, July 17, 2010

Changing form actions with jQuery

I'm working on a simple cms in a side project. Naturally I have a page where administrators can create new web pages.

I'm using the jQuery version of TinyMCE for editing. It is worth a look if you need wysiwyg textarea editing.

I wanted to give my client the ability to preview the page before saving it. The solution was simple: change the form's action in the click handler.

The implementation eluded me for a while; although, it was completely obvious:
                $("#preview").click(function(event){
event.preventDefault();
$("#create_page_form").attr( "action", "/preview_page" );
$("#create_page_form").submit();
});

$("#submit").click(function(event){
event.preventDefault();
$("#create_page_form").attr( "action", "/create_page" );
$("#create_page_form").submit();
});


"#preview" and "#submit" are the ids of two links but could be buttons.

I thought I would post it in the event that anyone else Google's "jQuery change form action."

Tuesday, July 13, 2010

SHIFT : q

No matter what text editor I'm in I can't help but typing "SHIFT :" followed by "q".

Does that happen to anyone else?

Friday, June 25, 2010

groovy.lang.MissingMethodException: No signature of method: static .list() is applicable for argument types:

I've started using Grails recently. Its really nice. Productive, easy to get up and running, etc.

My first stab at testing a Controller produced :
groovy.lang.MissingMethodException: No signature of method: static dbtestapp.Team.list() is applicable for argument types:
(org.codehaus.groovy.grails.web.taglib.GroovyPageAttributes) values: [[max:10]]
Possible solutions: is(java.lang.Object), wait(), wait(long), print(java.lang.Object), split(groovy.lang.Closure), use([Ljava.lang.Object;)
at dbtestapp.TeamController$_closure2.doCall
A little weird. list() is a dynamic method and should be on the object.

Its a known issue in the Grails Jira. The solution is to stick the test inside the "integration" package.

Monday, June 14, 2010

Ubuntu slow internet connection

I'm running Ubuntu Karmic Koala on a Dell Latitude D620. I've had a pretty tough time with wireless. Broadcom's support for Linux is terrible.

Yesterday my browsers became ridiculously slow. Running "ping" or "host" from Konsole showed that the problem wasn't networking.

I found a few posts suggesting that I disable IPv6 and reboot. I created a file "/etc/modprobe.d/bad_list", added "alias net-pf-10 off" and rebooted. Much better.

I was on another machine and don't have links to the actual posts from Linux forums and Ubuntu's forums. My apologies to the solution's authors.


Monday, June 7, 2010

java.lang.ClassNotFoundException: org.codehaus.groovy.transform.powerassert.ValueRecorder

Running a GroovyTestCase in a new project I got the following :

java.lang.NoClassDefFoundError: org/codehaus/groovy/transform/powerassert/ValueRecorder
at [My Package Hierarchy].[My TestCase].[My Test Method]([My Test Case].groovy:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.transform.powerassert.ValueRecorder
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 20 more
I found a bug that was closed because it couldn't be reproduced in the Groovy Eclipse JIRA.

I had run GroovyTestCases in other projects without this problem.

I right clicked the project and chose "Groovy -> Add Groovy libs to Classpath." That fixed it.

I had added my own Groovy library instead of the plugins. I often point Eclipse Libraries to the jar files in my .m2 directory. The "org.codehaus.groovy.transform.powerassert" package was not part of the Groovy distro. It is part of Groovy Eclipse plugin.

Saturday, June 5, 2010

Another cool NetBeans theme

I really like a dark background in my IDE. I previously mentioned the Aloha theme for NetBeans. I've been using if for a while.

Yesterday I found a version of Twilight for NetBeans. This one is set up for PHP, but works pretty well for Python. It is tweakable of course too.

Wednesday, May 19, 2010

Using .hgignore

Being a Java guy by day I typically use the source control stalwarts subversion and cvs. I've been exposed to other source control software of course. I used Borland's StarTeam on one gig, and I had a brief, horrific experience with Visual Source Safe.

Now that I'm a Python guy by night I have been using Mercurial. I like it. Its fast. Bitbucket is really sweet.

I use it on the command line; although, NetBeans has built in support. Naturally I got tired of seeing all my compiled Python files (*.pyc) when I ran, "hg status."
hg status
...
flatpages/forms.pyc
flatpages/models.pyc
...
Putting a file, ".hgignore" in the root of the directory is the solution. This is duly documented all over the web. I had problems with the syntax nonetheless.

That was what I ended up with:
# use glob syntax.
syntax: glob
*.elc
*.pyc
*
*.bfproject
*.kpf

templates_compiled/**
The glob syntax is pretty intuitive.

Sunday, May 16, 2010

Parse Error: Expected no additional symbols at symbol select

Running the following query :
query = MODEL_NAME.gql("select * from MODEL_NAME where name = :1", supplied_name) 
I got the error below :
Traceback (most recent call last):                                                               
File "<console>", line 1, in <module>
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/db/__init__.py", line 1100, in gql
*args, **kwds)
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/db/__init__.py", line 2047, in __init__
self._proto_query = gql.GQL(query_string, _app=app)
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 192, in __init__
if not self.__Select():
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 799, in __Select
return self.__From()
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 820, in __From
return self.__Where()
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 833, in __Where
return self.__OrderBy()
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 1056, in __OrderBy
return self.__Limit()
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 1098, in __Limit
return self.__Offset()
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 1117, in __Offset
return self.__Hint()
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 1140, in __Hint
return self.__AcceptTerminal()
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appengine/ext/gql/__init__.py", line 784, in __AcceptTerminal
self.__Error('Expected no additional symbols')
File "[PATH TO APP ENGINE INSTALL]google_appengine_1.3.1/google/appeng
ine/ext/gql/__init__.py", line 724, in __Error
(error_message, self.__symbols[self.__next_symbol]))
BadQueryError: Parse Error: Expected no additional symbols at symbol select
This is a simple fix:
query = MODEL_NAME.gql("select * from MODEL_NAME where name = :1", supplied_name) 
App Engine's orm is already supplying the "select * from" part of the query.

Thursday, May 13, 2010

Gql and object inheritance

I am working on an AppEngine project using the Kay Framework.
I was testing my queries in Kay Framework's shell. If you are familiar with Django's shell it is essentially the same.

Running the following query :
query = db.GqlQuery("select * from MyUserObject where user_name = :1 and password = :2")
I got this error :
raise KindError('No implementation for kind \'%s\'' % kind)
I had imported the object. My object inherits from the framework's DatatstoreUser.


Changing to the following :
query = MyUserObject.gql("where user_name = :1", "testuser@testuser.com")
provided exactly what I needed.

Friday, April 30, 2010

Projects using GWT 1.5 or lower may only specify one entry point module to compile

Despite
Having the 2.0.3 GWT plugin installed
Never having used the 1.5 GWT plugin

I was getting the following error when clicking the GWT compile button :
 Projects using GWT 1.5 or lower may only specify one entry point module to compile
The solution was to move my GWT dependencies above my Maven dependencies.

Right click on the project -> Build Path -> Configure Build Path... -> Order and Export
Click on GWT SDK and Up until it is just below the JDK.

Please make sure the -vm option in eclipse.ini is pointing to a JDK

Ececutive summary : put the vm argument on the line after "-vm" in eclipse.ini.

I got the following dialog after a fresh Eclipse install :
The Maven Integration requires that Eclipse be running in a JDK, because a number of Maven core plugins are using jars from the JDK.
Please make sure the -vm option in eclipse.ini is pointing to a JDK and verify that Installed JREs are also using JDK installs.

The Installed JREs were already pointing to a JDK. I set my my eclipse.ini to : -vm C:\Sun\SDK\jdk
-vm C:\Sun\SDK\jdk\bin\javaw.exe

No luck.
Eclipsepedia has an eclipse.ini.

I put the vm location on the next line and everything worked.

Tuesday, March 16, 2010

Cool NetBeans Plugin

Last week at AJUG's Devnexus conference Venkat Subramanium made an interesting point about IDEs.

He asked how many of the people in attendance used Eclipse. Unsurprisingly almost everyone raised a hand.

Then he asked how many of us would use it if it cost $500. Almost all of the hands dropped, including mine.

I downloaded NetBeans and IntelliJ.

I had used NetBeans for a while before. One thing I liked was its themes. I like light text on a dark background.

I found this theme, Aloha, and installed it. Pretty nice.

Wednesday, March 10, 2010

Django Nonrel and Google App Engine

The guys behind appengine patch have a new project using the Django nonrel project to run on App Engine.

Clone the appropriate projects from bitbucket :
$ hg clone https://[Bitbucket User Name]@bitbucket.org/wkornewald/django-nonrel/
$ hg clone https://[Bitbucket User Name]@bitbucket.org/wkornewald/djangoappengine/
$ hg clone https://[Bitbucket User Name]@bitbucket.org/wkornewald/django-testapp/


The instructions say next, "Now you should be able to create a new app in the testapp folder and use native Django models on App Engine. Try it!"

dignan@dignan-laptop:~/workspace/django-nonrel/django-testapp$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 4, in <module>
from djangoappengine.boot import setup_env
ImportError: No module named djangoappengine.boot

Hmmm.
The documentation calls for two symlinks :
django-testapp/common-apps/djangoappengine -> ../../djangoappengine
django-testapp/common-apps/djangoappengine -> ../../django-nonrel/django

I created them and tried again.
The Google App Engine SDK could not be found!
Make sure it's accessible via your PATH environment.
So I added the it to my path and tried again. Same result.

I found the following on the appengine-patch website:
"you can also put the SDK into any folder that is in the system's PATH environment variable as long as it's called "google_appengine" (this works with any OS)"

My sdk was in "google_appengine_1.3.0". I created a symlink, "google_appengine" and tried again.

/home/dignan/tools/appengine/google_appengine_1.3.0/google/appengine/api/datastore_file_stub.py:40: DeprecationWarning: the md5 module is deprecated; use hashlib instead                                                             
import md5
/home/dignan/tools/appengine/google_appengine_1.3.0/google/appengine/api/memcache/__init__.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
import sha
WARNING 2010-03-10 22:41:09,468 datastore_file_stub.py:483] Could not read datastore data from /tmp/django_nonreltest.datastore
Traceback (most recent call last):
File "workspace/django-norel/django-testapp/manage.py", line 16, in <module>
execute_manager(settings)
File "/home/dignan/workspace/django-norel/django-testapp/common-apps/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/dignan/workspace/django-norel/django-testapp/common-apps/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "workspace/django-norel/django-testapp/common-apps/djangoappengine/management/commands/runserver.py", line 88, in run_from_argv
start_dev_appserver(argv)
File "workspace/django-norel/django-testapp/common-apps/djangoappengine/management/commands/runserver.py", line 74, in start_dev_appserver
dev_appserver_main.main([progname] + args + [os.getcwdu()])
File "/home/dignan/tools/appengine/google_appengine_1.3.0/google/appengine/tools/dev_appserver_main.py", line 360, in main
config, matcher = dev_appserver.LoadAppConfig(root_path, {})
File "/home/dignan/tools/appengine/google_appengine_1.3.0/google/appengine/tools/dev_appserver.py", line 3441, in LoadAppConfig
raise AppConfigNotFoundError
google.appengine.tools.dev_appserver.AppConfigNotFoundError



At least it started! I cd'd into the app's directory and ran:

python manage.py runserver


It started up. I got the default "It worked!" page.

Sunday, February 14, 2010

Using the Google App Engine Helper for Django

Working through the steps to install the Google Appengine Helper for Django, I zipped up Django 1.1 and placed it in the root directory. I ran, "python manage.py runserver" and got the following error :

dignan@dignan-laptop:~/workspace/python/[PROJECT_NAME]$ python manage.py runserver
ERROR:root:Django 1.0 or greater is required!

The solution was simple. I zipped up the "django" folder inside the complete distro and put it in the root.

Thursday, January 21, 2010