Monthly Archives: January 2009

Cambio de Blog

Es oficial. Me paso de blogger a wordpress.
Empezé a usar bloggger no se muy bien porque. Es fácil de usar, un par de clicks y los tienes en marcha, pero cuando quise empezar a poner código fuente me encontré con problemillas:
Que si toca el template por aquí, que si cambia los css, … En fin que no me apetecía hacer hacking en una herramienta propietaria como blogger (que yo sepa no se publica el código fuente aunque las modificaciones de templates están documentadas). Así que me abrí una cuenta en wordpress. Había instalado y jugado un poco con wordpress hace tiempo y no me gustaba mucho, pero al descubrir que dan hosting gratis me lanzé a probarlo y no lo cambio por blogger ni en pintura. Ha mejorado mucho desde que lo por primera vez.

Después de hacer el arduo trabajo de migrar todos mis posts de blogger a mano (eran la desorbitante cifra de 4). Me doy cuenta que podía haberlo hecho semiautomático exportándolos en blogger e importándolos en wordpress. En fin que se le va a hacer.

Por cierto el código fuente queda monísimo sin tener que tocar nada.

JSONP. JSON with Padding

JSON is a really good solution to send data from server to client in web applications. Almost every program language has his own json encode and decode. PHP allows natively to do this encoding from php arrays and objets to JSON. And Zend Framework implements Zend_JSON who also allows you to encode/decode from XML.

When I was developing a rss client to my personal home page. I discover JSONP services. Those services are really easy to use and really easy to integrate them into your projects:

If the following url gives you a json data

url: http://www.server.com/service {“identifier”:”id”,”items”:[{"id":"18","title":" Asterisk. The future of telephony","author":"Jim Van Meggelen","bookyear":"2008","why":""}]}

It is very helpfully when

url: http://www.server.com/service?callback=myfunction
myfunction({“identifier”:”id”,”items”:[{"id":"18","title":" Asterisk. The future of telephony","author":"Jim Van Meggelen","bookyear":"2008","why":""}]})

with this if you develop the function ‘myfunction‘ with a few javascrip lines you can consume those jsonp webservices.

This is the source code I use to read

function googleSearch(bibkeys) {
  var scriptElement = document.createElement(”script”);
  scriptElement.setAttribute(”id”, “jsonScript”);
  scriptElement.setAttribute(”src”, “http://books.google.com/books?bibkeys=” + 
    bibkeys + “&jscmd=viewapi&callback=googleCallback”);
  scriptElement.setAttribute(”type”, “text/javascript”);
  document.documentElement.firstChild.appendChild(scriptElement);
}
function googleCallback(booksInfo) { // do what you want with the booksInfo }

Bagera…

BAGERA…¡
GU ERE BAI¡
GU BETI POZEZ,
BETI ALAI

SEBASTIAN BAT BADA ZERUAN
DONOSTIA BAT BAKARRA MUNDUAN
HURA DA SANTUA
TA HAU DA HERRIA
HORRA ZER DEN GURE DONOSTIA

HIRUTXULOKO
GAZTELUPEKO
JOXEMARITAR ZAHAR ETA GAZTE.
JOXEMARITAR ZAHAR ETA GAZTE.

KALERIK KALE
DANBORRA JOAZ
UMORE ONA ZABALTZEN
OR DIHOAZ
JOXE MARI¡

GAURTANDIK GERORA
PENAK ZOKORA
FESTARA¡
DANTZARA¡
DONOSTIARREI OIHU
EGITERA GATOZ
POZALDIZ
IHAUTERIAK DATOZ!
IHAUTERIAK DATOZ!

BAGERA…¡
GU ERE BAI¡
GU BETI POZEZ,
BETI ALAI

Adding my blog’s feed to my personal site

I have my personal web page hosted in a free hosting service. Basically it’s a dojo application working with a Zend Framework Backend. I had the idea of include a the last posts of my blog from the rss to the front page (original isn’t it?), and I start to develop it.

I started using Zend_Feed to fetch the RSS from my blog. The idea of my personal site was to develop a web application based on dojo framework so I decide to use the dojo way using dojox.data.AtomReadStore.That sounds cool but I faced with the first problem. Due to security reasons XHR requests can’t be done to a different domain. My personal page and the url of the blog’s feed were under different domain.

Problem 1: XHR with different domains.

To solve this problem I must create a proxy with PHP to RSS feed in my personal page. With this proxy XHR requests will be in the same domain, so dojox.data.AtomReadStore will work correctly. the proxy worked perfectly in my local computer but when I upload it to my hosting I realized that it didn’t work.

Problem 2: The hosting of my project doesn’t allow php’s socket functions

As I see in php.ini. some PHP functions (socket functions for example) are disallowed in the server. Because of that my code does not work. Surfing into Zend framework source code (open source is cool). I saw Zend_Feed uses Zend_Http_Client_Adapter_Socket. My hosting allows me to use curl extension instead of socket functions. But Zend Framework does not have a Zend_Http_Client_Adapter_Curl. So other problem.

Problem 3: Zend_Http_Client with Curl

As I read in some newsgroup my problem with my hosting, curl and sockets was not only mine. Zend Framework doesn’t not have a curl adapter in the production tree but they have a Zend_Http_Client_Adapter_Curl in the incubator. This adapter is not fully tested and it can crash behind proxies and things like that but it sounds good for my situation. Using this adapter the code works in my local server and in my hosting. that’s sounds good but there is other problem

Problem 4: CPU usage

Looking in the statistics of my site in the hosting I realized that the CPU usage was hight. The application is a client side application and this CPU usage graph shows me the problem. Curl functions are slow and my rss proxy is consuming too much cpu time. It sounds I am under a no-solution problem. I need a proxy to avoid XHR cross domain restriction but this proxy uses too much CPU in my poor-man- hosting. Solution: turn the logic to the client and and do all the job with javascript.

Finding some RSS reader with js I faced with GFdynamicFeedControl. Really easy to use. It also has a wizard to generate code to copy and paste. Of course the generated code didn’t work in my application but hacking a bit I have finally my RSS feeds in my personal page. GFdynamicFeedControl allow you to mix different RSS so y also include the rss of my github account with the source code.

<div id="feed-control">
    <span style="color:#676767;font-size:11px;margin:10px;padding:4px;">Loading...</span></div>
@import url("http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css");

google.load('feeds', '1');
dojo.addOnLoad(function(){
    var options = {
        stacked : true,
        vertical : true,
        title : "Feeds"
    }
    new GFdynamicFeedControl(gamJs.feeds, 'feed-control', options);
})

Follow

Get every new post delivered to your Inbox.

Join 869 other followers