Friday 31 August 2012

Grails -- unable to download groovy 1.7.12


So I recently ran into a problem with my Grails build. The problem seem to stem from the fact that one of my dependencies (an older Groovy snapshot jar?!) can not be fetched from the main grails site. So I wanted to run `grails dependency-report` to see who's using that rouge jar...unfortunately it didn't build and gave me the same message.

This is the message that I got:


[NOT FOUND  ] org.codehaus.groovy#groovy;1.7.12-SNAPSHOT!groovy.jar (226ms)
==== http://repo.grails.org/grails/core: tried
  http://repo.grails.org/grails/core/org/codehaus/groovy/groovy/1.7.12-SNAPSHOT/groovy-1.7.12-SNAPSHOT.jar
::::::::::::::::::::::::::::::::::::::::::::::
::          UNRESOLVED DEPENDENCIES         ::
::::::::::::::::::::::::::::::::::::::::::::::
:: org.grails.plugins#cloud-support;[1.0.7,): not found
::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::
::              FAILED DOWNLOADS            ::
:: ^ see resolution messages for details  ^ ::
::::::::::::::::::::::::::::::::::::::::::::::
:: org.codehaus.groovy#groovy;1.7.12-SNAPSHOT!groovy.jar
::::::::::::::::::::::::::::::::::::::::::::::
| Downloading: groovy-1.7.12-SNAPSHOT.jar.sha1
| Error Failed to resolve dependencies (Set log level to 'warn' in BuildConfig.groovy for more information):
- org.codehaus.groovy:groovy:1.7.12-SNAPSHOT


So, to fix it (so that I can troubleshoot the problem and exclude the old Groovy snapshot jar). All I did was to add the `http://snapshots.repository.codehaus.org` repository before the grails default repositories in BuildConfig.groovy.

So it looks something like this:



repositories {
inherits true // Whether to inherit repository definitions from plugins
mavenRepo "http://snapshots.repository.codehaus.org" //comes first
grailsPlugins()
grailsHome()
grailsCentral()
mavenCentral()
mavenRepo "http://twitter4j.org/maven2"
// uncomment these to enable remote dependency resolution from public Maven repositories
mavenLocal()
mavenRepo "http://repository.codehaus.org"
mavenRepo "http://download.java.net/maven/2/"
mavenRepo "http://repository.jboss.com/maven2/"
}






Tuesday 28 August 2012

Using Twitter Bootstrap's modal from an ajax loaded page.

So I'm working on one of my apps and had an issue with modal dialogs and Bootstrap. According to Bootstrap, you can do something like this:
Activate a modal without writing JavaScript. Set data-toggle="modal" on a controller element, like a button, along with a data-target="#foo" or href="#foo" to target a specific modal to toggle. 
Therefore, initially, this is what I had:

 <a data-toggle="modal" href="#help-with-url" >Content not showing up?</a>

However, what I found was that on pages that are loaded via ajax which the contents are put on a separate dialog, one cannot use what they described above for reasons I do not know why. I checked to see if there were any errors in the bootstrap js, but couldn't find any. I did solve it by just calling the modal using the javascript way, like so:

 <a onclick="$('#help-with-url').modal()" data-toggle="modal" >Content not showing up?</a>





Friday 24 August 2012

Use Heroku, MongoLab and Node.js and mongo node-mongodb-native

So I am trying out MongoLab for their database, and it uses a connection string, where in the node native drivers examples they instantiate a new Server() instance. I got it to work with the connection string, so I thought I would share:

My previous code:

SiteService.prototype.save = function (site, callback) {
    var db = new Db(mongods.datasource.db, new Server(mongods.datasource.hostname, mongods.datasource.port, {auto_reconnect:true}, {}));
    db.open(function () {
        self.getCollection(db, function (error, collection) {
            if (error) {
                callback(error);
            } else {
                site.created_at = new Date();
                collection.insert(site, function () {
                    callback(null, site);
                    db.close();
                });
            }
        });
    });
};


The code that uses the connection string:

SiteService.prototype.save = function (site, callback) {  
   mongodb.connect(mongods.datasource, {auto_reconnect: true}, function(error, db)  
   {  
     console.log("connected, db: " + db);  
     self.getCollection(db, function (error, collection) {  
       if (error) {  
         callback(error);  
       } else {  
         site.created_at = new Date();  
         collection.insert(site, function () {  
           callback(null, site);  
           db.close();  
         });  
       }  
     });  
   });  
 };  


Notice also that I changed how the `mongods` variable is defined. Instead of return a json with the individual properties, the connection string is now embedded into the datasource property.

Tuesday 21 August 2012

Heroku: specifying node / npm version doesn't work

node js heroku specify version not working

I'm deploying my app on Heroku today and because I use some libraries that require the latest version of Node, the deploy to Heroku fails because I haven't declare which version of Node to use. The docs says to create an "engines" property as Json and add in the version, so initially this is what I added (based on their sample) in my package.json:

  "engines": {  

   "node": "0.8.x",
   "npm": "1.1.x"
  }


When I pushed again, I saw the same error message? What gives?

Well, stupid me. Turned out that I was working on my develop branch and I was following the tutorials, which issues the command `git push heroku master`. Once I merge my changes from develop to master and retried pushing to master, everything worked.


Friday 17 August 2012

Node js - set your content type if you are returning JSON objects



So I'm working on my app which at times return XHR json responses, and I was a little curious when the client interpreted the json as a string. Of course, stupid me forgot to set the content-type to be 'text/json' in the headers using Express. DUHHHH.

The correct way of doing it should be like this (note: `text/json`).

 app.post("/submitNew", function(req, res) {  

   var siteService = new site.SiteService();
   res.writeHead(200, {'Content-Type':'text/html'});
   var siteObj = req.body;
   if (siteService.isUnique(siteObj.url)) {
     siteService.save(siteObj, function(error, site) {
       rabbitmq.publish(site);
       res.write(JSON.stringify(site));
     });
   } else {
     res.write(JSON.stringify({error: true, field: 'url'}));
   }
   res.end('\n');
 });


Thursday 16 August 2012

I'm using Bootstrap and knockout for my upcoming app, 404hound, and I had a bit of an issue with the enable binding from knockout when the element is an anchor.

Problem #1: I was using the anchor as a button (by annotating the class as `btn`) and unfortunately the disabled doesn't really work. Fortunately though, I was able to fix that problem easily by changing the type from to

Problem #2: I wanted to be able to set the `disabled` class (to disable the button) when the preconditions have not been met. I managed to fix that by using the css binding like so:


       
            changes