Friday, June 1, 2012

Vala Woes

Having finished classes in France, I'm spending a week in Austria before I return to the United States. Much of this week has been spent working on my Twitter project; however, I'm finding myself frequently frustrated by Vala bugs and lacking documentation.

Vala's bugs often derive from its decomposition to C during its compile step. Vala is supposed to catch any errors that could result in a C error; however, it often fails at this. Right now I'm using an officially-supported binding for the Gnome-Keyring library (gnome-keyring-1); however, the binding doesn't seem to work well in Vala 0.18 as it throws obscure C errors which are sufficiently difficult to debug that I can't justify the debugging time. I think I'm going to have to scrap working with the keyring and 1) try to find another somewhat-easy way to securely store Twitter's OAuth access credentials or 2) use a language with better keyring support (perhaps C#/Mono?).

For the most part, Vala is a really cool language as it is FAST when things work properly. Unfortunately, when things don't work properly, a large development cost is often incurred.

Tuesday, May 29, 2012

Gnome Keyring tutorial and security article; Vala resources; etc

As I've been tinkering around with the Gnome Keyring with Vala lately, and my exploration has brought me across many a webpage.

Here's an interesting article about Gnome Keyring Security.

Here's a Pythonic tutorial for the Keyring which I've been mapping to the Vala language via the ValaDoc, a very useful resource for most of the Vala language (however, in its newness, most of the language seems to be incompletely documented).

And here are a couple questions for whom I couldn't find answers on the Internet:
How to securely generate/store a keyring password?
How to store OAuth credentials in the Gnome Keyring

Saturday, May 19, 2012

Vala tutorial: Twitter Authentication

I'm just starting to learn Vala as it appears to be one of the most swiftly-growing languages for open-source development. It's fast like C/C++ but supposedly a lot more intuitive and generally less hateful. We'll see. Anyway, there doesn't seem to be a lot of great instructive material for it floating around the ether, so I decided I'd try to give back here and there with a brief tutorial.

Here goes:

1. Install librest

I'm using Ubuntu as my development platform, so my installation step was
sudo apt-get install librest-dev

2. Register Your App on Twitter

This step is fairly straight forward. Create a profile on Twitter's developer page and then start a new project. For this tutorial, you'll need to change the settings for you project such that it has read/write/direct privileges for tweets.

3. The code:

To see a nice copy with syntax highlighting, click here. Otherwise the code can be found at the bottom of the post, sans syntax-highlighting.

4. Compile:

someone@someone-UBook:~/workspace/vala/twitter$ valac --pkg rest-0.7 simpletweet.vala -o simpletweet

5. Execute:

someone@someone-UBook:~/workspace/vala/twitter$ ./simpletweet "Test 2"
Go to http://twitter.com/oauth/authorize?oauth_token=0RKxDFc5NFWoucwubsdGxfBMl37ZHWFhTnggbCVnZA then enter the PIN
6408330
Tweet succeeded!

Conclusion

As this is a simple demonstration, the user is forced to do the very tedious authentication step repeatedly. My guide is primarily an adaptation of Ross Burton's tutorial, in which he suggests storing the authentication credentials in GNOME's keyring; however, I don't know how to do that yet. If you have questions or comments, post 'em up.

simpletweet.vala :



using Rest;

public class SimpleTweet {
 private static const string CONSUMER_KEY = "#######################"; // this comes from your app's twitter account page
 private static const string CONSUMER_SECRET = "########################################"; // this comes from your app's twitter account 
 private static const string URL_FORMAT = "https://api.twitter.com";
 private static const string REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token";

 private static const string FUNCTION_ACCESS_TOKEN = "oauth/access_token";
 private static const string FUNCTION_STATUSES_UPDATE = "1/statuses/update.xml";

 private static const string PARAM_STATUS = "status";

 public static int main(string[] args) {
  // make sure there is a message to tweet
  if(args[1] == null || args[1] == "") {
   stdout.printf("No tweet message specified.\n");
   return 0;
  }

  /** Authenticating with Twitter */
  // initialize proxy
  var proxy = new OAuthProxy(CONSUMER_KEY, CONSUMER_SECRET, URL_FORMAT, false);

  // request token
  try {
   proxy.request_token("oauth/request_token", "oob");
  } catch (Error e) {
   stderr.printf("Couldn't get request token: %s\n", e.message);
   return 1;
  }

  // prompt user for pin
  stdout.printf("Go to http://twitter.com/oauth/authorize?oauth_token=%s then enter the PIN\n", proxy.get_token());
  string pin = stdin.read_line();

  // access token
  try { proxy.access_token(FUNCTION_ACCESS_TOKEN, pin); }
  catch (Error e) {
   stderr.printf("Couldn't get access token: %s\n", e.message);
   return 1;
  }

  /** sending the tweet */
  // setup call
  ProxyCall call = proxy.new_call();
  call.set_function(FUNCTION_STATUSES_UPDATE);
  call.set_method("POST");
  call.add_param(PARAM_STATUS, args[1]);
  try { call.sync(); } catch (Error e) {
   stderr.printf("Cannot make call: %s\n", e.message);
   return 1;
  }

  // print success
  stdout.printf("Tweet succeeded!\n");

  return 0;
 }
}

Tuesday, December 27, 2011

Ubuntu on MacBook

Since my 21-credit-hour semester ended, I've had a little more time to tinker. In preparation for my trip to France, I wanted to install Windows and Ubuntu on my MacBook (model 4,1) so I could have all three major operating systems on my computer so I can develop for any platform (or use iTunes to rescue my iPod and Photoshop as there isn't anything on Ubuntu that really compares).

I followed this tutorial to set everything up (I got a free Windows 7 license from my school's CS department which pays for licenses for students--Microsoft's online support was incapable of allowing me to move my license from my old hardware to new hardware, even after me being on the phone with them for 3+ hours). There were a few minor hiccups with rEFIt (a necessary piece of software used to allow non-OSX operating systems to run on a MacBook)--it had a tendency to not boot correctly but the problem evaporated for no apparent reason and it seemed the problem was pretty rare anyway.

Because I used rEFIt instead of BootCamp to install Windows 7, I'm having a driver problem preventing me from scrolling or right-clicking with the trackpad--making Windows 7 even more frustrating to use.

Lately I've been using Ubuntu 11.10 exclusively and I'm incredibly happy with it. Many of the usability bugs in Unity have been worked out in this iteration (many still remain, but it's much more tolerable) and it's actually a pleasure to use as things have become more customizable. Additionally, because everything is so customizable in Ubunu, the operating system is a pleasure to use compared to OSX which is fairly locked-down. I truly love that I can push a key combination (by default Alt+F1) and navigate the dock with arrow keys. Furthermore, Unity + the Software Center make the new Ubuntu a great operating system for beginners (the Software Center was my biggest criticism for Ubuntu in appealing to new users, but, as I predicted, the Mac App Store drove many improvements in Ubuntu's Software Center).

That said, I plan to install this OS on the computers of a couple of my friends and family before I leave for France. Give it a try. Documentation abounds on how to install the operating system and it's probably the easiest operating system to install.

Genie

Genie is the newest programming language I've been playing around with lately. To date, my experience has been almost exclusively in interpreted languages, so Genie (a close relative of Vala) is my foray into a true compiled language. Like Vala, Genie code compiles to C code which of course then compiles into a binary executable. In fact, according to Genie's Wikipedia entry, the differences between Genie and Vala are only syntactical--Vala looks like C/C++ and Genie looks Python-esque. The valac compiler is used to compile both languages.

Unfortunately, Genie has only been in active development since 2008 and documentation is sparse and almost useless and my few attempts at using the language have been foiled by absurd errors. Most recently, I tried to declare a list (a basic Genie data structure) exactly how the Genie tutorial showed and it threw an error. You can view the specifics in the StackOverflow question I asked here.

When it matures, I really look forward to using Genie as it seems to offer the simplicity and sanity of Python with all the advantages of being a compiled language. The silly Vala overhead is gone
I'm really looking forward to:

  • Stability
  • Proper documentation (and a stronger community, which of course comes with time and adoption)
  • Better debugging
  • Vim syntax highlighting support
In the meanwhile, as long as I stick with using the language, I plan to file bugs and produce tutorials here. Then again, I'm a pretty flaky blogger so we'll see how that goes.

Thursday, February 10, 2011

My Projects

School has kept me really busy lately, but I'm enjoying it quite a bit. My Python class is a breeze as I've been working with it since the beginning of last semester, but I'm still learning quite a bit about coding efficiently, which is kind of why I'm pursuing a Computer Science major to begin with. My electrical engineering classes are considerably more challenging this semester, but I'm enjoying almost understanding the science behind wireless communication systems. I'm even enjoying my senior design project which is at any given time the biggest obstacle between myself and my EET degree. I don't even mind too much the rate at which school is reducing my social life to the ghost of its former self.

Thursday, February 3, 2011

Evolution makes me look less like an idiot

Evolution, Ubuntu's default mail client, makes me look less like an idiot with its useful reminder. The image pretty much sums it up. Thanks Evolution!