JulioCapote
Web Application Developer
E-mail / AIM: jcapote@gmail.com

RSS:
 Subscribe


Feeds:
Twitter
Shared Items
Bookmarks

Links:
Resume
Work
GitHub

Archive

    Feb
    14th
    Sun
    permalink

    On Google Buzz

    Summary: In this post I attempt to rationalize the creation of Google Buzz.

    How I see it
    Google Buzz is a subset of email, optimized for sharing information and discussing said information amongst a network of followers. I’m sure Google noticed that a large number of users send short messages, occasionally accompanied by a link or an attached image, to the same people over and over. I know I do; Regardless of Twitter or Facebook, Email is still my preferred medium for propagating content to my close friends. In fact, the first browser add-on I install is the “send via gmail” to automate this process. So upon seeing Google Buzz, instead of seeing it as “another social network”, I saw it as a streamlining of my current link sharing workflow.

    Sharing
    Sharing things on Google Buzz is pretty easy (although I’m still waiting for my chrome extension). It’s faster than sending out an email because you can create groups of those you would normally CC and you don’t have to think about a subject line.

    Private Groups
    I believe that this is Google Buzz’s killer feature. As our social graphs increase and intersect/overlap, the importance of segregating information increases. For instance, your Mom/Boss/Girlfriend(s) seeing pictures of you at that raunchy party the other night. This is a common problem that anyone with a Facebook/Myspace can attest to having (at least once). Not just for privacy’s sake but for the sake of your followers. I used to have every tweet posted to my Facebook but people complained that they didn’t understand 99.9% of the things I posted (programming links/info usually). And inversely if I started posting non technical/silly things to Twitter, I’ll lose the technical audience there (this is why this app rules). Google Buzz allows me to share content with just the people I want (and discuss with the people I want).

    Discussion
    Let’s face it, trying to have a deep discussion is next to impossible on Twitter (not that this is bad). Meanwhile, Google Buzz inherits gmail’s threaded conversation feature (one of it’s best features) which makes discussing buzzed items a breeze. Also the “Like” concept is not to be underestimated, how many times have you seen email replies with “+1” in them? Or, if a discussion you don’t care about keeps showing up on your stream you can simply Mute it. Crazy Speculation: This may be what’s coming next for Google Groups.

    Pain Points
    Nothing is perfect, and Google Buzz is surely is not. For one, it’s, some say, intrusive, arrival rubbed a lot of people the wrong way. You’ll find all kinds of posts on the internet about how they feel betrayed by Google for forcing a social network down their throat. Others felt that their gmail was their “work area” and didn’t want to bothered with such folly (understandably so). That’s why I feel it should’ve been deployed like this: Wave style invites and if you buzz someone that doesn’t have an invite, they just get it like a regular email with a link on the bottom to join. The early adopters will bring in those they feel will like the service and use it with them. The other point is that you can’t filter out buzzed tweets (when you tweet, Google Buzz will buzz it automatically) so you end seeing tweets twice.

    Conclusion
    So in conclusion, will Buzz replace Twitter for me? No. But it will definitely replace those quickie emails I fire off to the same group of people over and over. I feel like they are trying to market Google Wave to a bigger, more mainstream audience. If that’s the case, I look forward to see what else Google Buzz will bring to the table in the future.

    Comments (View)
    Nov
    15th
    Sun
    permalink

    On PHP Frameworks...

    • My Friend: I never realized there were so many PHP frameworks...
    • Me: That's cause they aren't smart enough to realize it's impossible to build abstractions without lambdas
    Comments (View)
    Jul
    19th
    Sun
    permalink

    Using Rack applications inside GWT Hosted mode

    This guide will show you how you can use JRuby to run any Rack application inside Google Web Toolkit’s (GWT) hosted mode server so your interface and your backend are of the Same Origin.

    Background
    GWT has two ways of interacting with a server: GWT Remote Procedure Call (RPC) and plain HTTP (XHR). GWT-RPC is a high level library designed for interacting with server-side Java code. GWT-RPC implements the GWT Remote Service interface allowing you to call those methods from the user interface. Essentially, GWT handles the dirty work for you. However, it only works on Java backends that can implement that interface. Since most of my backends are Sinatra/Rack applications, I’ll be using the plain HTTP library.

    The problem
    Due to the restriction of the Same Origin policy, the interface served out of GWT’s development, or Hosted Mode server can only make requests back to itself. If you were using real servlets or GWT’s RemoteService this wouldn’t be an issue; but since Rack applications listen on their own port, you cannot make requests from GWT to our application without resorting to something like JSONP or server-side proxying. This leaves you having to compile our interface to HTML/JS/CSS, which is lengthy process, and serve it from the origin of the Rack application to see our changes.

    The solution
    Since I wanted to develop using GWT’s development environment with a Rack backend, I devised a way to use jruby-rack to load arbitrary Rack applications alongside our interface.

    First let’s setup our environment:

    1. Download and unpack the latest GWT for your platform (mine’s being linux) and goto it:

    wget http://google-web-toolkit.googlecode.com/files/gwt-linux-1.7.0.tar.bz2
    tar -xvjpf gwt-linux-1.7.0.tar.bz2
    cd gwt-linux-1.7.0

    2 .Download the latest jruby-complete.jar:

    wget http://repository.codehaus.org/org/jruby/jruby-complete/1.3.1/jruby-complete-1.3.1.jar
    mv jruby-complete-1.3.1.jar jruby-complete.jar

    3. Download the latest jruby-rack.jar

    wget http://repository.codehaus.org/org/jruby/rack/jruby-rack/0.9.4/jruby-rack-0.9.4.jar
    mv jruby-rack-0.9.4.jar jruby-rack.jar

    Now let’s create our GWT application using an example Sinatra backend:

    4. Create an app with webAppCreator:

    ./webAppCreator -out MySinatra com.example.MySinatra
    cd MySinatra

    5. In order for this to work you have to package any gem dependencies your backend needs (sinatra, in our case) as jars within your application. For Sinatra it looks like this:

     java -jar jruby-complete.jar -S gem install -i ./sinatra sinatra --no-rdoc --no-ri
    jar cf sinatra.jar -C sinatra .

    6. Add jruby-complete.jar, jruby-rack.jar, sinatra.jar (and any other jars you’ve created) to the libs target of your build.xml:

     <target name="libs" description="Copy libs to WEB-INF/lib">
    <mkdir dir="war/WEB-INF/lib" />
    <copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
    <!-- Add any additional server libs that need to be copied -->
    <copy todir="war/WEB-INF/lib" file="${gwt.sdk}/jruby-complete.jar" />
    <copy todir="war/WEB-INF/lib" file="${gwt.sdk}/jruby-rack.jar" />
    <copy todir="war/WEB-INF/lib" file="${gwt.sdk}/sinatra.jar" />
    </target>

    7. Add these lines right after <web-app> in war/WEB-INF/web.xml:

     <context-param>
    <param-name>rackup</param-name>
    <param-value>
    require 'rubygems'
    require './lib/sinatra_app'
    map '/api' do
    run MyApp 
    end
    </param-value>
    </context-param>

    <filter>
    <filter-name>RackFilter</filter-name>
    <filter-class>org.jruby.rack.RackFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>RackFilter</filter-name>
    <url-pattern>/api/*</url-pattern>
    </filter-mapping>

    <listener>
    <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
    </listener>

    Note: All you’re doing here is passing the contents of a config.ru file into the <param-value> element for the <context-param> (make sure this is HTML encoded!). This states that any request to /api is to be handled by your Sinatra application and not GWT’s Hosted mode servlet.

    8. Create your Sinatra backend and place it in war/WEB-INF/lib/sinatra_app.rb

    require 'sinatra'
    require 'open-uri'
    class MyApp < Sinatra::Base

    get '/showpage' do
    open('http://www.yahoo.com').read
    end

    get '/helloworld' do
    'hello world'
    end

    end

    9. Run your new awesome setup:

    ant hosted

    Now when navigate to http://localhost:8888/api/helloworld or http://localhost:8888/api/showpage you should see the Sinatra application being served via GWT.

    Comments (View)
    Jan
    1st
    Thu
    permalink

    Useful Rails Routing tips

    Even though I have been using Rails for fun and profit for about 2 years now, I felt I never really used it’s routing engine to its full potential. So I checked out new Rails Routing from the outside in guide and discovered bunch of useful tricks that I (and maybe you) had no idea you could do. Here they are:

    Multiple resource definitions on a single line

    map.resources :photos, :books, :videos

    Impose a certain format for resource identifiers

    map.resources :photos, :requirements => { :id => /[A-Z][A-Z][0-9]+/ }


    This way, /photos/3 would not work, but /photos/DA321 would.

    Friendlier action names

    Say for your application ‘create’ and ‘change’ make more sense than the default ‘new’ and ‘edit’ you can do

    map.resources :photos, :path_names => { :new => 'make', :edit => 'change' }

    You can also do this site-wide also, in your environment.rb

    config.action_controller.resources_path_names = { :new => 'make', :edit => 'change' }

    Trim the fat off resources with :only and :except

    When you use map.resources, rails generates 7 restful routes for that resource; But what if that resource only needed to be seen and listed, never edited or created?

    map.resources :photos, :only => [:index, :show]

    If your application uses alot of map.resources calls but not neccesarily all its generated routes, you can save memory this way.

    Adding extra routes to your resources

    Instead of fighting the map.resources generator by placing a horror like this atop your routes.rb

    map.connect '/photos/:id/preview', { :controller => 'photos', :action => 'preview' }


    You can do this to your already mapped resource

    map.resources :photos, :member => { :preview => :get }


    This will map all GET’s to /photos/3 to the preview action of your photos controller

    This can also be  used in collections instead of singular members, just change :member to :collection

    map.resources :photos, :collection => { :search => :get }

    This will give you /photos/search and hit the search action within the photos controller

    Comments (View)
    Oct
    29th
    Wed
    permalink

    So you want to click that button?

    I stumbled upon http://clickthatbutton.com during my routine lurking of hacker news. After being amused for about 10 seconds,  I decided to take it to the next level; I wanted to click on it really, really fast. After going through a few solutions (simple js while loop in firebug, then curl/wget) and failing, the idea of using selenium popped into my head. So I went off to their site and installed the extension. I figured a simple recording of the mouse event, then wrapping it around a loop in selenium would do the trick, but I quickly found that selenium doesn’t support loops. Not to be stopped, I searched google and ended up with this. After installing the plugin for selenium (a plugin for a plugin!?) and restarting firefox, I tried it again and to my surprise it worked! The click counter was going up steadily on its own (18k clicks and counting). Here is my selenium test case for those of you following along:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head profile="http://selenium-ide.openqa.org/profiles/test-case">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="selenium.base" href="http://clickthatbutton.com/" />
    <title>haha</title>
    </head>
    <body>
    <table cellpadding="1" cellspacing="1" border="1">
    <thead>
    <tr><td rowspan="1" colspan="3">haha</td></tr>
    </thead><tbody>
    <tr>
        <td>open</td>
        <td>/</td>
        <td></td>
    </tr>
    <tr>
        <td>store</td>
        <td>x</td>
        <td>1</td>
    </tr>
    <tr>
        <td>while</td>
        <td>storedVars['x'] == storedVars['x']</td>
        <td></td>
    </tr>
    <tr>
        <td>click</td>
        <td>submit</td>
        <td></td>
    </tr>
    <tr>
        <td>endWhile</td>
        <td></td>
        <td></td>
    </tr>
    
    </tbody></table>
    </body>
    </html>
    

    Just paste that into a file, open it with selenium ide, hit play and you should be good to go.

    Comments (View)
    Oct
    12th
    Sun
    permalink

    Arrow key navigation for text fields

    Here is a class for enabling the use of arrow keys to navigate through a grid of input fields: (using mootools)

    
    var FocusMover = new Class({
    
    	initialize: function(sel, col_num){
    
    		this.sel = sel
    		this.col_num = col_num
    		this.inputs = $$(this.sel)
    		this.current_focus = 0
    
    		var self = this
    
    		this.inputs.each(function(item, index){
    			item.addEvent('keydown',function(key){
    				$try(function(){
    					self[key.key]()
    				})
    			})
    			item.addEvent('focus',function(e){
    				self.refresh(e)
    			})
    
    			item.set('myid', index)
    		})
    
    		this.inputs[0].focus()
    
    	},
    
    
    	refresh: function(e){
    		this.current_focus = e.target.get('myid')
    	},
    
    	down: function(){
    		i = parseInt(this.current_focus) + parseInt(this.col_num)
    		this.inputs[i].focus()
    	},
    
    	up: function(){
    		i = parseInt(this.current_focus) - parseInt(this.col_num)
    		this.inputs[i].focus()
    	},
    
    	left: function(){
    		i = parseInt(this.current_focus) - 1
    		this.inputs[i].focus()
    	},
    
    	right: function(){
    		i = parseInt(this.current_focus) + 1
    		this.inputs[i].focus()
    	}
    
    })
    
    

    As you can see, the constructor takes two arguments: a selector (which should return a list of all your input fields), and the number of input field columns. So for a 4x2 table, you would set it up like this:

    
    var FM = new FocusMover('#mytable input', 4)
    
    Comments (View)
    Oct
    11th
    Sat
    permalink

    Tabbing through fields vertically

    Sometimes it’s useful to switch the browser’s default tabbing behavior (left to right) to the opposite (top to bottom) when your input fields are in a grid layout instead the of the usual single column layout. Having to do this manually is a real pain, especially for large grids; So here is a solution in javascript, using mootools:

    
    window.addEvent('domready', function(){
        var trs = $$('#mytable tr')
        var accum = 0
        trs.each(function(tr, trindex){
            accum = trindex + 1
            tr.getChildren().each(function(td, tdindex){
                td.getChildren('input')[0].tabIndex = accum
                accum = accum + trs.length
            })	    
        })
    })
    

    Comments (View)
    Sep
    30th
    Tue
    permalink

    Why MooTools (or Why not JQuery)

    I’ve been toying around with MooTools a bit lately, and I’ve found the experience quite enjoyable and refreshing. Naturally, I twittered about it and went along my merry way. Moments later (and much to my surprise), I had a direct message from John Resig himself asking “Why, what’s wrong with jQuery?”. I was pretty taken aback that he would take time from his surely busy day to message a total stranger in an effort to improve his project or at least gain an insight in the everyday life of a js developer (it’s not like DHH would personally message people that are dumping rails to use merb). I figured he deserved a straight, honest answer; One that at least would be longer than 140 characters (even though I managed to use every single one). So it begs the question, Why MooTools?

    1. Class support.
      JQuery’s SQL-like syntax is fine for quick and dirty javascripting, but eventually you’ll want real classes to structure your UI logic.
    2. It smells, feels and tastes like regular javascript.
      JQuery doesn’t even look like javascript, which isn’t necessarily a bad thing, since that’s kind of their goal. MooTools however, feels like just an extension of the language (more on this at point #9).
    3. Faster.
      ‘Nuff Said
      EDIT: This was pointed out to be false; It is only faster in certain cases (such as mine, WebKit nightly on OS X).
    4. Robert Penner’s easing equations baked right in.
      This could just be me, but I find the animations that mootools creates are alot smoother than JQuery’s (especially the easing).
    5. Creating new DOM elements is a snap.
      Need to create a dom element? var el = new Element(‘a’, { ‘href’: ‘juliocapote.com’}); Done.
    6. Modular.
      I like that I can just build and pull down a moo.js that only contains the functionality I need.
    7. Better Documented.
      Or at least, its faster to find what you need.
    8. Easier to hack on and extend.
      While I haven’t personally delved into the internals of either system, the consensus seems to be that jquery is an unintelligible mess when it comes to modifying how it works.
    9. Prototype Approach (versus a namespaced approach)
      This is really just matter of preference; MooTools achieves it’s magic by just extending the prototypes of common objects (Array, String, etc); While this is obstrusive, it makes for shorter, more natural code. JQuery does its thing via a main object (which you can name, hence the namespace), that you wrap around whatever you want to make magical; This is unobstrusive, but you pay for that by having to wrap anything you want to use (which ends up being everything). It basically boils down to arr.each(fn) vs $.each(arr, fn)
    10. It’s not a revolution.
      It feels as if JQuery is trying to take on the world (it seems like it too, since its now included with visual studio and the nokia sdk). However, I’m not; I’m just trying to write some javascript here.

    It’s not like I’m never going to use JQuery again; It simply isn’t my default js framework any longer.

    Comments (View)
    Sep
    29th
    Mon
    permalink
    I would buy and frame this.

    I would buy and frame this.

    Comments (View)
    Sep
    27th
    Sat
    permalink

    Highlight link based on current page in rails

    This is common pattern in website navigation, where it highlights the link (usually by setting class=”active”) that took you to the current page while you are on that page.

    First, define a helper:

      def is_active?(page_name)
        "active" if params[:action] == page_name
      end

    Then call it in your link_to’s in your layout as such:

    
    link_to 'Home', '/', :class => is_active?("index")
    link_to 'About', '/about', :class => is_active?("about")
    link_to 'contact', '/contact', :class => is_active?("contact")
    
    

    This effect is achieved due to how link_to handles being passed nil for its :class, so when is_active? returns nil (because its not the current page), link_to outputs nothing as its class (not class=”” as you might expect).

    Comments (View)