Nitobi
About Nitobi
Services
Products
Home -> Blogs -> Joe@Nitobi

Joe@Nitobi

Android Webkit Tutorial

October 8th, 2008

Recently, I’ve been playing with the Android SDK. The main thing that has me pumped about Android is the fact that it’s open and the fact that I can actually write code for it without having to get a Mac and run Mac OS X. I’ve been messing around with it a couple weeks, and I found that there wasn’t a good set of code samples for developing with Android.

So, here’s a rough description of what you need to do to get a WebView to actually be useful in Android. First of all, you should already be familiar with the basics, since we’re not going to be spending too much time on them here. You need to use the following in the layout:

            

This should be in a layout element in your XML Layout. I use the Linear Layout similar to the tutorial, but you may want to use a different layout. Then, I started using it with the following Java code:


WebView appView;
appView = (WebView) findViewById(R.id.appView);
appView.getSettings().setJavaScriptEnabled(true);
appView.loadUrl("http://www.nitobi.com");

This code should be put in the onCreate method of the activity, since this will be loaded at the beginning of the activity. This is the most basic way to make sure that you get a full running browser. It’s something that I didn’t find straight forward from the API docs, so I figured that I’d pass this thing on. It’ll be a while since I’ll be getting one of these phones, since I’m in Canada, but I have a feeling that this will be coming up again very soon.

Digg! | Del.icio.us

Posted in Uncategorized | No Comments »

The Pitfalls of Ultrasphinx and Ultraminx

September 26th, 2008

Recently, we had a Merb project that we needed to add search to. Now, since Merb doesn’t use plugins the same way Ruby does, I decided to look for a nice easy gem to make life easier. At the time, I found ultraminx. Ultraminx was basically ultrasphinx made into a gem with no docs. Things were good, except that it broke when I decided to upgrade to the latest version of Merb.

The problem that I found is that when we did the upgrade, Ultraminx refused to work. In fact, I was rather disturbed that the repository hasn’t been touched in a while. Therefore, I decided to look at Ultrasphinx again. I found that on GitHub that it was forked numerous times by different developers, and I eventually used Jamie’s code. However, I had to hack it as well.

Straight from the github

However, even that is rather old. I’m tempted to do what 10 other people have done before me and fork the ultrasphinx code and to see what happens when I pull from these other repos. Of course, I haven’t taken the plunge and used DataMapper or Sequel yet, so I’m going to wait until MerbCamp to see what happens when I hack on this.

Yes, I said I’m going to MerbCamp.

Digg! | Del.icio.us

Posted in Uncategorized | No Comments »

will_paginate and Ajax pagination

September 2nd, 2008

One thing that I’ve been using a lot is will_paginate and it’s derivatives, such as merb_paginate, ultraminx and ultrasphinx. One problem that I noticed with merb_paginate was that it didn’t want to use the restful paths in the merb app that I was using. This was rather annoying, since I was trying to make my merb app almost entirely restful, except for the home controller. So, instead of using paginator, I decided that I wanted to add ajax pagination.

The first step that needs to be done is to create a create and delete js view. This is extremely basic. I have some code that does this in one of my github repositories. Namely, the sparty_server code.

In the controller, uncomment this line as usual. We are going to be sending back json:

 provides :xml, :yaml, :js

Then create the following *.js.erb files:

index.js.erb

var events = "";
<%= partial "widgets", :with => @widgets %>
<%= partial "shared/paginate", :items => @widgets %>
$jQ(”#main_eventlist”).empty();
$jQ(”#main_eventlist”).append(events);
$jQ(”.pagination”).empty();
$jQ(”.pagination”).append(navigation);

Note that you should really make this so that it uses your jQuery variable. Here, we’re not using noConflict. noConflict should almost always be used, since you most likely will be using a non-jQuery item with your software. We also created two partials, namely one that just lists the lists. This could be used for anything that will update inside a div. The other thing that we created is a pagination partial, which is just a string definition.

This is pretty obvious. This just uses the methods present in all will_paginate derived objects to determine which page is present. One thing that we found is that we don’t always have access to all the methods and attributes, which is why it looks rather odd.

Here’s the javascript code that does the pagination:

var prevPaginate = function(id)
{
  items = id.split('_')[1];
  current_page = id.split(’_')[2];
  next_page = parseInt(current_page) - 1;
  next_page_key = “#page_” + next_page;
  uri = parseMerbUri(window.location.href);
  good_uri = window.location.href.split(”#”)[0];
  next_page_key = good_uri + next_page_key;
  hist.add(next_page_key);

  query_string = uri + “?page=” + next_page;
  if(next_page > 0)
  {
    jQuery.get(query_string, function(data){eval(data);});
    return false;
  }
}

var nextPaginate = function(id)
{
  items = id.split(’_')[1];
  current_page = id.split(’_')[2];
  next_page = parseInt(current_page) + 1;
  uri = parseMerbUri(window.location.href);
  good_uri = window.location.href.split(”#”)[0];
  next_page_key = good_uri + “#page_” + current_page;
  hist.add(next_page_key);

  query_string = uri + “?page=” + next_page;
  jQuery.get(query_string, function(data){eval(data);});
  return false;
}

Of course, we have a method that parses the URI so that we are going to the right resource. This is important for nested resources to do this, since we want to display the correct results. We also use the Nitobi history in this case because we want the back button to use the pagination, and not go back to the previous page in the history.

I’m going to make this more generic in the next couple of weeks and post the code to the blog, however this should be rather trivial for anyone to do once they know how will_paginate works and how to use the json data that it sends back.

Digg! | Del.icio.us

Posted in Ruby, UI | No Comments »

Merb, jQuery and Nitobi

August 29th, 2008

Recently, we reached a milestone with our first Merb project. The project was interesting, since it was the largest Merb app that we had to deal with. The good thing about Merb was the fact that it’s lightweight, and gives you a sense of what you’re actually using as opposed to Rails, which is full of methods that I just don’t use. I also like the way file uploads are just handled in Merb, as opposed to the Rails way, which is far more cryptic.

The fact that whenever you post data, it just goes to the following parameter:

params[:file][:tempfile]

Is extremely handy, since this doesn’t have to be handled like the good old ruby way of handling blob data through your app. You still have to move the file, but you aren’t just being handed some weird data in memory and expected to use something to process it. This is why people use plugins like attachment_fu and things like that. The less your web app is handling that sort of data, the more requests that it can handle, and the more things it can get done.

Of course, that’s the whole point of Merb. Admittedly, we don’t take advantage of this as much as we could have in this project. We have Rails projects that handle hundreds of uploads that would probably be more suited for Merb, but of course hindsight is almost always 20/20 and it’s time to move on to talk about jQuery and Nitobi Toolkit.

Since this was an experimental project of sorts, I decided to try out jQuery to see what all the hype was about. jQuery is a nice little framework that makes doing simple things like Ajax requests easy. Attaching events to classes is handy, and that is the fundamental strength of the framework. Also, using jQuery UI was interesting as well. While making things appear and disappear was easy, some of the components tended to be ugly, and lacked functionality, so we decided to use Nitobi Calendar instead of the jQuery calendar early on.

This brought us into bringing in Nitobi Toolkit and Nitobi Calendar and making it play nice with jQuery. We learned the number one thing about jQuery, which is that you should always use noConflict if you believe that you are going to use more than one framework. In our case, we use both the Calendar and the Nitobi History object, simply because of the lack of examples of the jQuery.history object, and the fact that it relied on Anchor tags in the examples. It wasn’t clear if we could custom define the URI behind the scenes, and use that instead of something defined in the markup, which is exactly what we wanted to do.

Therefore, we used Toolkit’s history method, and it worked rather well. I may check out jQuery’s History add-on library, but the Nitobi history comes standard in Complete UI and is rather easy to use. There will be some tweaks to it in the next version of CUI.

In short, it was an interesting expeirence working on the project, and being able to work with Merb. I’m definitely going to move towards Merb, and it should be good when Merb 1.0 comes out at MerbCamp in San Diego. Unfortunately, it’s at the same time as Canadian Thanksgiving, but there may be at least one person from Nitobi present.

There may not necessarily be a MerbDog soon, but It’s definitely my first choice for any new personal web projects that I do.

Digg! | Del.icio.us

Posted in Uncategorized | 1 Comment »

Introducing VHS

August 20th, 2008

Recently, I’ve been talking about VHS. VHS is an acronym, which now stands for Vancouver Hacker Space.

The Vancouver Hacker Space is a project that I’ve been working on for a while. It was started with the FreeTheNet.ca people at The Vault, which was in the BC Electric Building. However, we didn’t quite have critical mass, since people were still uber-psyched about FreeTheNet (note: VONIC is still around, I’m just taking a break from it). However, after I went to The Last HOPE in NYC and met up with the people at NYC Resistor and HacDC, among other Hackerspaces, I decided that Vancouver really needs a hackerspace.

Now, Hackerspaces aren’t anything new, in fact Germany has had them for years. In fact, Andre has been to c-base, which is one of the older Hackerspaces in Germany that double as a nightclub. The hackerspaces are all over Germany and they are run by the CCC, who are a damn cool group, with a really interesting history.

Anyway, this is interesting because there will finally be a place where people can collaborate and see different hack projects. For example, I had a multitouch interface that worked, but the problem was getting it out of the apartment to Nitobi Hack Days. With the new hackspace, interested hackers can go check out the thing in action, and the public can see it. (And as much as I like people, I don’t want them coming into my apartment randomly). We’ll also be working on Arduino hacking, and Robots, and LED Throwies and all sorts of other cool stuff.

The first public meeting is tonight at the hackerspace. The meeting will be at 6:30 PM. If you’re interested in getting more info, please let me know.

Digg! | Del.icio.us

Posted in VHS | 1 Comment »

Nitobi Grid on Firefox 3

June 12th, 2008

Check the Forward and Back button!

Support for Firefox 3 will hopefully be in the next release of Complete UI. This is a screenshot of the grid shortly after I got it rendering properly in Firefox 3 RC3 on Linux. There are still changes with backwards compatibility with Firefox 2, however the adoption rate for Firefox appears to be a lot higher, and with the Guiness Book of Records PR Campagin that Mozilla is doing, there may be hope that things will get a lot faster.

Digg! | Del.icio.us

Posted in CUI, Firefox, Grid | 1 Comment »

Passenger - When you have to use Apache!

June 3rd, 2008

Recently, someone gave me some server space and root. I could do what I wanted to the server, as long as I kept the PHP and Drupal configurations working. While I at first was somewhat annoyed with it, being a fan of nginx and mongrel, I tried to install an Apache + Mongrel configuration, similar to what we deploy on other severs over and over again. The problem is that this was an Ubuntu server, therefore mod_php needs apache2-mpm-prefork to work, while mod_proxy needs apache2-mpm-worker. This will probably explain the oh-so-misleading error log:

[Mon Jun 02 18:01:26 2008] [warn] proxy: No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

and the even worse

[Mon Jun 02 18:08:44 2008] [error] proxy: BALANCER: (balancer://mongrel_cluster). All workers are in error state

Of course, Google has told me that I wasn’t running the right modules, while Ubuntu’s documentation told me that I needed apache2-mpm-worker. After apt-getting the stuff, and realizing that the two are mutually exclusive, I decided to give passenger a try.

The setup is way simpler, but there are definitely some downsides to it. It appears that mod_rails is about as fast as mongrel so far (although I am not using it on a live environment), but when things go wrong, going through the trace stack is definitely a lot more painful. Also, another thing that I noticed is that with every deploy change, that I have to restart Apache now, which disrupts the other apps on the server. This is probably more of the case of getting your own box, but of course if I had my own box to play with, I wouldn’t be using Apache.

Overall, if you are stuck sharing a box with some Drupal users, Passenger is your friend, since you won’t have to explain why their PHP is now using FastCGI. It’s clearly the path of least resistance as far as some Rails deployments go. This also means though that things like Capistrano will have to change to reflect this. I guess this is my assignment to lazyweb. Go find Cap scripts that deploy to Passenger. :P

Digg! | Del.icio.us

Posted in Linux, Rails, Ruby, drupal | No Comments »

w00t, The Great Internet Migratory Box Of Electronics Junk has a wiki

June 2nd, 2008

In my spare time, I like to mess around with things such as Arduino hacking, SpokePOVs and other small electronics projects. I may have commented in the past about a couple of them such as the failed attempt to build a touch screen interface. I also have accumulated stuff from the FreeTheNet Community Wifi project as well.

Well, Evil Mad Scientist Labs has created this project called “The Great Internet Migratory Box of Electronics Junk”. This is where a box of electronic parts gets mailed from place to place and it gets picked through, parts get added and removed and the box moves on to its next destination. I put my name on the wiki to get a box, but if you want it, you really should check their wiki out and put your name down. I seem to be the first Canadian link, so I’m pretty pumped about that, even if I don’t get the box. :)

It’s definitely very cool, and I recommend you check it out!

Digg! | Del.icio.us

Posted in Uncategorized | No Comments »

Moving to Merb and More Events

May 20th, 2008

I’m currently working on a project in Merb, and I’m liking it. So far, I’ve just done some basic stuff, like added merbful_authentication, and simple things like that, but overall I’m finding that it’s not much different from rails. The main thing that I’m liking the most about it is getting rid of prototype. After the last couple of projects that I’ve worked on with Prototype, it felt like I only had a hammer and everything that I was looking to solve were nails. I was able to beat the crap out of it to get it to work, but it wasn’t as elegant as it should have been.

I may hack something together with Merb at Hackday, but I haven’t decided yet. I could just as easily play with Arduino again or try out Django or play with another Python app.

However, here’s the list of events that are interesting to me:

  • May 24th - Nitobi Hackday the Third - At Nitobi HQ!
  • May 26th - VanLUG presentation - From Embedded to Web, the Tech behind FreeTheNet
  • May 29th to June 1st - Something in Portland (TBD!)
  • June 2nd - van.rb presentation - From Embedded to Web, the Tech behind FreeTheNet

Digg! | Del.icio.us

Posted in FtN, Linux, Rails, Ruby, VONIC | No Comments »

Presenting at VanLUG, Blog Syncing

April 30th, 2008

I got an e-mail from some of the VanLUG people saying that they want a repeat of the OpenWebVancouver presentation. I’m constantly re-tooling it, and once I know for certain when I will be presenting it, I’ll have more information. The presentation does need some polish since I went straight to the demo halfway through the presentation before I really got a chance to talk about other things with FreeTheNet.

Also, it should be noted that I’m going to test a sync script on this blog shortly.

Digg! | Del.icio.us

Posted in FtN, VONIC, openwebvan | No Comments »


Search Posts

Pages

Archives

Categories

All contents are (c) Copyright 2006, Nitobi Software Inc. All rights Reserved
Joe@Nitobi Entries (RSS) and Comments (RSS).