Wednesday, May 05, 2010

Monday, January 25, 2010

HttpCommons and Ror

I finally got everything to work - in case this helps anyone else:

httpClient.getParams().setParameter("http.socket.timeout",
new Integer(90000)); // 90 second
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_0);
httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,
"UTF-8");

post = new HttpPost(new URI(url));

Charset chars = Charset.forName("UTF-8");
StringBody user_id = new StringBody("32432", chars);

MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartContent.addPart("media_entry[media]", new FileBody(file));
multipartContent.addPart("media_entry[user_id]", user_id);


post.setEntity(multipartContent);



HttpResponse response = httpClient.execute(post);
response.getEntity().getContent().close();


does the trick.

The important part is the forcing of the HTTP/1.0 protocol, since most rails web servers don't support chunked-encoding.

Saturday, January 23, 2010

Android and RoR Rest Services

In case this helps anyone else:
When you are doing multipart uploads from Android to Rails, you need to make sure that you tell the MultipartEntry to be Browser compatible:

MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartContent.addPart("media_entry[media]", new FileBody(file));
multipartContent.addPart("media_entry[user_id]", sb1);
and now I'll get back to our new project. More to come when we release an alpha version.


Wednesday, January 30, 2008

Nothing new... so just wanted to thank

This guy, who started my morning off with a very simple solution:
http://www.planetrubyonrails.org/tags/view/cookies

Thank you Rspec and thank you planetrubyonrails.org...

Tuesday, January 22, 2008

Rails Routes Hell

I have spent the last day in the seventh level of Rails hell (or something like that... it's been a while since I've read my Dante). Quite simply, I have been trying to have routes send a url in the form /cgi-bin/query?command=5 to a different controller/action based on the command parameter.

To be honest, I'd prefer to just remove the asinine code in the first place, but given that I don't have time to rewrite a fairly large client, it would be a great deal easier if I could just do a simple url rewrite.

Well, since I did work a solution out, I'll post it here, but good God (what's with my theological allusions today?) - if you have a better way, please tell me.




module ActionController
module Routing

class Route

TESTABLE_REQUEST_METHODS = [:command]

def recognition_conditions
result = ["(match = #{Regexp.new(recognition_pattern).inspect}.match(path))"]
conditions.each do method, value
if TESTABLE_REQUEST_METHODS.include? method
result << method =""> request.method,
:command => request.query_parameters['command']
}
end
end
end
end

and then in my controller:
map.connect 'cgi/query', :action => 'homepage', :controller => 'home', :conditions => { :command => /1/ }


This works, but isn't there are a good way of doing this without have to extend Rails internals? It just seems like there should be an easier way. I read Jamis articles, and while I learnt a great deal about the routes system, I still didn't get how to do any better that this.

http://weblog.jamisbuck.org/2006/10/4/under-the-hood-route-recognition-in-rails

and his routing trick plugin...
http://www.workingwithrails.com/railsplugin/4789-routing-tricks.

Wednesday, August 09, 2006

SyncML

Well, since I can't say that I post here on a regular basis, I will at least attempt to mark some things that I find interesting:

www.scheduleworld.com

This is a nifty little tool which allows you to sync all of your devices and program together by taking advantage of the many SyncML clients out there. While for the moment, google and others do not provide a SyncML, this little website meshes it all together...

And if you need SyncML clients for anything ( iPod included):
http://www.funambol.com/opensource/

Wednesday, February 08, 2006

Mobile Phone Servers

Ok.. so now there is apparently a sudden realization in the community that, yes, you can run a server on a mobile phone.
http://www.mopocket.com/2006/02/use_your_phone_as_a_web_server.php

Now, I am really sorry to rain on the parade here, but this is hardly a newsworthy item in itself. The fact that someone ported Apache is rather fun... but that is about it. And besides, the concept is hardly new: Symbian released on for their communicator servies sometime about 4(?) years ago.

I am, however, going to ignore the prior art and concentrate on what it might provide:
http://mobilesociety.typepad.com/mobile_life/2006/02/this_is_a_draft.html

NO, NO, and NO.... sorry guys. Why would I possibly make a web server on my mobile, which may have internet outages due to lack of Wifi and GSM? How about just the boring old central web server, and lots of client ( e.g. your notebook, desktop and mobile phone) connecting to this. In terms of real time update, you can simply have the devices check every minute for updates and pull new information, or use a push approach which tries to contact the mobile devices/notebook/desktop whenever there is some new data.... this is not rocket science here guys.

I'll be honest - Blackberry has a better infrastruture that multiple web hosts.

Sorry to be so down on this hype.

I hate Symbian C++

Well... i have been hating it for some time now.
I have finally achieved something, which for all intents and purposes should be a very simple task: to record audio and muck around a little with the content.

I have finally managed, but damn I wish there were more documentation on this stuff.
In case you happen to be working on this stuff: find the Audio_Streaming_Example.Take a look at it, and understand that in most new versions of symbian, the buffers only get filed with 320 bytes, regardless of how large the buffer is.
Also - make sure that you have an Active Objects timer running. Running this stuff from a console app is virtually impossible.

Oh - and if you don't ingest the object, the timer may stop - i am not clear on whether it always stops, but this is very worth noting. If you happen to be sending stuff over http,be careful, since it may garble the recording if you send anything too large.

So much fun...