Skip to main content

Posts

Showing posts from 2011

SC.Menu dynamic positioning with OpenLayers

In one app I needed to allow the user to CTRL-click on an OpenLayers map to popup a tool menu. Since all the rest of the app is Sproutcore based I also wanted the menu to have the same look&feel. Sproutcore already has a menu view which is called SC.MenuPane . Unfortunately SC.MenuPane can be positioned only relatively to another SC.View, but what if I want to position the menu exactly where I clicked on the map? The solution turns out to be pretty simple and requires us to override only one MenuPane method. The method is positionPane and can be overridden at definition time by adding it to the mixin as done below (gotta love javascript, huh?): Maps.openLayersController.menuPane: SC.MenuPane.create({ layout: {width: 120}, itemHeight: 25, items: [ { title: '_geocode'.loc(), icon: 'http://maps.gstatic.com/favicon.ico', action: "geocode" }, { title: '_streetview'.loc(), icon: 'icon-streetview-16', action: "streetview"

Using a separate settings file with Abbot and Sproutcore 1.6

In some cases it is practical in an application to have a single global settings file where all configuration is stored. Most often this configuration file varies between a deployment and another, depending on customer requirements, licensed features, backend technology, etc. When developing an application with Sproutcore 1.x (1.6 is assumed) it is not immediately clear how to do it, not because it is not possible but just because documentation on Abbot , SC's build tool is, to use an euphemism, well, scarce. So what do we want to do exactly? We want to have a single config.js file that is included before any other application file and, most importantly, must not be minified and packed so that on-the-fly editing or inspection is still conveniently possible. The file should be kept small anyway so that packing and minifying it is not going to be necessary. To do this we need to create a new .js file and place it wherever we like in the application tree. A sensible choice wou

Postgres maintenance: vacuum hell, cluster to the rescue

I have an OpenNMS server (a PC really) sitting under a desk at a company that I don't hear from often, but I still get weekly backup mail-recaps. This week the recap brought bad news: postgres stopped accepting connections until the db is vacuumed to prevent transaction id wraparound. I have know of this issue of postgres for some time and planned accordingly: a cron job every month would run a full vacuum. Unfortunately in one month the db grew so much that vacuum never reached completion because the customer simply rebooted the server thinking that it was 'stuck'. This vacuum-stuck-reboot had gone on for months until today. As I knew from prior experience this was going to be a painful experience: a quick du on the database folder reported 60GB of data. Vacuum would probably take days. Luckily for me I had heard from the great Postgresql 9.0 high performance book that there is another tool in the toolbox called cluster . So I decided to execute this plan this

Fixing GrailsUI infamous 'Cannot create a menubar within a menu'

I personally like/use GrailsUI a lot and I'm sorry that it's been discontinued. Just today while I was upgrading an app from Grails 1.1 to 1.3.6 I found out that my previously working menubar is now spitting out ugly errors (like this one ). The problem lies in the unsafe use of instance variables by the tag library. Luckily for us the solution is pretty simple, just replace all references to items and group with a request scope variable like request.items and request.group. In my case I went a little further and tried to come up with a variable name that would not clsh with other variables actually used by me. My (working, yup) copy of the menu tag library is available at  https://gist.github.com/1358135 . To use it just copy it into your project's taglib folder and then build a menubar as you would do with GrailsUI, only using the g: prefix instead of gui: .

Improve OpenLayers performance in a Sproutcore app

When using OpenLayers embedded in a Sproutcore app you will want to set the following option on the OpenLayers.Map constructor: fallThrough  : false to avoid double handling events (once in OpenLayers and once in Sproutcore). Map dragging should improve and feel much smoother. Although deprecated this wiki page explains very clearly Sproutcore event handling.

RIP Dennis Ritchie

Dennis Ritchie died last week. While Steve Jobs had a great influence in my past years (I have only recently become an Apple customer/fan) my first experiences with Ritchie's (and Kernigan) go back  to my university days and are forever linked to my first baby steps with Slackware linux, fvwm and tcp-ip. I miss those days as anyone misses his/hers youth. So long Dennis and thanks for all the segfaults!

Grails ajax login from a Sproutcore app

Warning : this post is a work in progress. Full source code for both Sproutcore and Grails  parts can be found at my github account  https://github.com/unicolet . All the Sproutcore examples that I've found so far only show how to fetch data from different backends, but there is unfortunately very little material on authentication. In my case I'm hooking up to a Java backend written in  Grails  with authentication being provided by by Spring Security . The grails spring-security-core plugin documentation already incorporates  Ajax logins so the server-side code is already in place. We only have to apply one small tweak to make it work with Sproutcore. Prerequisites: Grails, Sproutcore > 1.6 with Statecharts. The statechart in the figure illustrates the states and transitions we plan to handle. Authentication Let's start with authenticating the user. We will deal with reconnecting the session later. Assuming you have a basic Grails app with spring-securi

Adding Google Web Fonts to a Sproutcore app

Yesterday I was playing with the Hubbub   Sproutcore app that is just plain beautiful (and useful, if anyone used it over here in stodgy Italy). Anyway I noticed that the beautiful texts on the home page are not images, but actual text with fonts. I did not know I had such great fonts on my computer and in fact I don't. Those fonts come from Google Web Fonts  and you can use them too, right away in any of your web apps or sites. Since I am working on a Sproutcore app that could use some beauty I decided to style the app name with this font. Now, if only I knew how to add the css link to the html generated by abbot... [/me is gtfw & source browsing for a good 30 mins...] The solution turns out to be pretty simple and elegant (as everything in SC world, wink wink). Open the Buildfile in your favourite editor and add a stylesheet_libs option to the project config as follows: config :all do |c| c[:javascript_libs] = ['http://maps.google.com/maps/api/js?v=3

Adding Sproutcore KVO to OpenLayers - More Automation - Part 3

I have showed in the previous post how to add KVO to OpenLayers objects and then connect these objects to inputs, etc. The approach was unfortunately troublesome because each OpenLayers object had to be programmatically augmented through a SC.mixin call. In this post I will show how the OpenLayers source can be patched to make the augmentation process built-in. The only modification that needs be done is in Class.js where the OpenLayers.Class function must be modified as follows: OpenLayers.Class = function() {     var len = arguments.length;     var P = arguments[0];     var F = arguments[len-1];     var C=null;     if(typeof F.initialize == "function") {         if (!F.__my_init) {             F.__my_init = F.initialize             F.initialize = function() {                         F.__my_init.apply(this,arguments);                         SC.mixin(this, SC.Observable);             };         }         C = F.initialize;     } else {         C = func

Adding Sproutcore KVO to OpenLayers - Part 2

You can also  Read Part 1   or   Read Part 3 In the previous post of this series I have showed how easily an OpenLayers object can be extended with Sproutcore KVO . The main driver behind integrating KVO into OL is that of beauty and simplicity. When KVO is available texfields, checkboxes, layers, features, you name it can all have their state transparently and continuosly synchronized without writing any code at all. The first post was more of a proof of concept. In this post instead I am going to show a more practical use and rewrite one the OpenLayers examples (from the dev examples). The original example shows how to create and add features to a map from javascript. With the help of KVO I am going to expand the original and also make the features editable. As we will see the changes will propagate immediately into the map. The full source is available on github . To run the example simply download/clone/fetch the repo and open index.html with a browser. The example was w

Adding Sproutcore KVO to OpenLayers - Part 1

The truth is that after you start using Sproutcore KVO you become addicted to its beauty and simplicity. Where in other frameworks you spent most time keeping each part of the app in sync, in Sproutcore you get it for free. Sure Sproutcore isn't perfect and is not for all, but KVO is simply automagical! In this post I will show how easy it is to implement KVO on top of OpenLayers and take advantage of KVO to bind features, wfs queries and UI controls to otherwise stubborn Openlayers objects. In this example we will create a Vector layer, add KVo to it and then verify KVO bindings by manually adding an observer. I have run all this code from Google Chrome console and you can do it too. First thing to do is to create a scratch SC project: sc-init kvool then let's edit the Buildfile and add the following lines at the end so that the OpenLayers library is loaded with the app: config :all do |c| c[:javascript_libs] = ['http://www.openlayers.org/api/OpenLaye

Simple VCB: a tool For Vmware Consolidated Backup

I have written and would like to share with the world a groovy script that can be used to drive VCB backups without additional third party software. One of the most common gripes with VCB is that it doesn't integrate naturally into the VMWare management solution. Of course one can always buy a license for the integration module of his backup software, but that costs additional money. Some people then resort to script VCB so that additional licenses are not necessary but that, of course, requires scripting skills. Which also means reinventing the wheel just another time. This has happened to me too recently and I decided that ok, I would reinvent the damn wheel, but this time I would also make sure that the blueprint goes public! So I wrote this groovy script which I creatively named Simple VCB which does some nice things like: handles more than one esx, vcenter or vsphere server so that you don't have to split your configuration and schedules in more than one scrip

HOWTO: Parallel deployment on tomcat 7

News broke out recently that Tomcat 7 supports parallel deployment . This feature allows one to deploy a newer version of a web application while maintaining the current one online. The net effect is that new users will be connected to the newest version while already connected users will not be kicked out. Neat uh? One could even have more than two versions online at any time (if that was necessary). The details of how this works are explained in the Context Container documentation . Only it doesn't really tell you how to use it, it tells you how they implemented instead. So what do you have to do to take advantage of this great feature? First of all upgrade to Tomcat 7 (which btw requires Java 6), but you knew that already, didn't you? Then simply adopt the following naming strategy when deploying apps: name your war file mygreatapp## version .war (note the ## used to mark the beginnning of the version substring) where version can actually be anything (it is ma

Oracle Enterprise Linux on VMWARE

If you, like me, would like to play around with Oracle Enterprise Linux or whatever it's called these days it is most likely you'll end up installing it on some flavor of VmWare. I tried Esxi 4.1, and installation is smooth (I chose RHEL 6 as Guest OS type because Oracle Linux was not available). Not so much for the Vmware Tools install which quite blankly stated that the kernel headers were not valid, whatever kernel directory I threw at it. Then it hit me that Oracle is using a special kernel which is buzzworldy named UEK (Unbreakable Enterprise Kernel). I then edited grub.conf and reverted to a normal kernel (normally the second item), rebooted and installation of Vmware tools finally succeeded. Next question is: should I bother about NOT using Oracle's UEK? The answer is generally no (in my case I'm just running a Zope App), unless you are using the VM for running a production database (and in that case you shouldn't be running it on vmware in the firs

Migrating existing opennms database to provisiond

In the next few days I will be migrating a rather large install from a discovery configuration to a manually provisioned configuration in an attempt to reduce confusion and the number of misconfigured nodes. To ease the process I have implemented a set of two migration script, they can be found on my Github repo . Basic instructions are available in the README file.

Sproutcore closable Mixin

I've been working with sproutcore in my spare time for almost 6 months now and along the path I came up with some nice (I think) components. This one is a tiny unintrusive mixin that can be applied to panette panes and adds a close button on the top right corner. I have tried to make it work on panel panes too, but without success so far. That is probably because panel panes, being modal, grab all events before the events reach the mixin. Fetch from my github account: https://github.com/unicolet/stuff-I-m-proud-of P.S.: I also have a functional OpenLayers view, but it requires some refactoring before I can make it public.

Sproutcore calendar component

I've realized a calendar component for sproutcore. It's at https://github.com/unicolet/stuff-I-m-proud-of . It could use some improvement, particularly with regard to layout but it's already pretty solid and usable.