log4p

Peter Maas’s Weblog

Archive for February, 2009

Ioke @ Amsterdam.rb

Tonight I visited Amsterdam.rb. Mainly because I wanted to see Ola Bini talk about his pet project Ioke. Although Ioke is far from finished, or even usable in real life it was really nice to see someone try out new language concepts.

Ioke is a strongly typed, extremely dynamic, prototype based object oriented language. It’s homoiconic and got built in support for several kinds of macros. The languages that most closely influence Ioke is Io, Smalltalk, Self, Ruby and Lisp (Specifically Common Lisp).

Ioke seems to be mainly focussed at writing nice-to-talk-to code, it gives developers much more freedom to shape the language into DSL-like syntax.

In contrast to what you would expect from a 'pet language' Ola demonstrated nice generated documentation and some cool debugger features. And even a RSpec-like testing framework: ISpec. Really nice. Here is an example of a parser definition (from paser_comb.ik example) written in Ioke:

  1. IParse Parser(
  2.   digit = 0..9
  3.   letter = ("a".."z") | ("A".."Z")
  4.   id = letter (letter | digit)*
  5.   id2 = letter* (letter | digit)
  6.   number = 1..9 digit*
  7.   primary = "(" expr ")" | number | id
  8.   term = primary ("*" | "/") term | primary
  9.   expr = term ("+" | "-") expr | term
  10.   and = expr "and" expr | expr
  11. )

Looks kinda neat, doesn't it? I don't see Ioke as the next big thing, but I think it is a really nice testbed for new languages and language concepts.

No comments

Posting to twitter from Android (commons httpclient 4+)

While developing a helper for the Twitter API to be used in the Android application which I'm writing I ran into a nasty problem. While trying to post to Twitter Twitter kept sending "417 - Expectation Failed" responses. I solved this by specifically setting the UseExpectContinue flag to false.

The following snippets are part of my helper class to talk to twitter, it runs fine on my ADP1 using Android 1+ :

  1. private static final DefaultHttpClient httpclient = new DefaultHttpClient();
  2. private static final AuthScope AUTH_SCOPE = new AuthScope("twitter.com", 80, AuthScope.ANY_REALM);
  3.  
  4. private static JSONObject post(final String url, final Map<String, String> fields, final UsernamePasswordCredentials credentials) throws Exception {
  5.     final HttpParams params = createParamsForPosting();
  6.  
  7.     // Tell twitter who we are
  8.     httpclient.getCredentialsProvider().setCredentials(AUTH_SCOPE, credentials);
  9.     httpclient.setParams(params);
  10.  
  11.     final HttpPost post = new HttpPost(url);
  12.  
  13.     // Setup the form data to post
  14.     final UrlEncodedFormEntity requestEntity = mapToFormEntity(fields);
  15.     post.setEntity(requestEntity);
  16.  
  17.     final HttpResponse response = httpclient.execute(post);
  18.     final HttpEntity responseEntity = response.getEntity();
  19.     final String data = IOUtils.convertStreamToString(responseEntity.getContent());
  20.    
  21.     return new JSONObject(data);
  22. }
  23.  
  24. private static HttpParams createParamsForPosting() {
  25.     final HttpParams params = new BasicHttpParams();
  26.     HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
  27.     HttpProtocolParams.setContentCharset(params, UTF_8);
  28.     HttpProtocolParams.setUseExpectContinue(params, false); // solves the '417' issue
  29.     return params;
  30. }
  31.  
  32. private static UrlEncodedFormEntity mapToFormEntity(final Map<String, String> fields) throws UnsupportedEncodingException {
  33.     final ArrayList<NameValuePair> values = new ArrayList<NameValuePair>(fields.size());
  34.     for (final Entry<String, String> entry : fields.entrySet()) {
  35.         values.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
  36.     }
  37.    
  38.     final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(values, UTF_8);
  39.     return entity;
  40. }

When complete I'll probably opensource the twitter API wrapper in full, at the moment it is not complete enough to do so.

2 comments

ADP1

Today UPS brought me the Android Generation One Dev phone which I ordered only 2 days ago. Although I'm stuck with a bad case of the flu I had to unwrap and operate it.

Nice present you bought me dad!

Initial impressions of the device are quite good. But yes it is not and iPhone. Installing applications from the marketplace is a breeze.

I started hacking on an Android app myself, but felt to ill to figure out how to get it on the ADP1 today. As soon as I get better I'll do a write-up!

1 comment