push-glib

I needed to do some push notifications to Android and iOS, so I put together a library for doing so. It's early, but is functional thus far. No API guarantees, of course. C2DM still uses the (newly) deprecated Google ClientLogin authorization. I still need to do some research for moving that to the forward supported OAuth2 authorization. The APS client uses your TLS certificates registered with the app store. It speaks the "enhanced" protocol, which lets you know about errors. Occasionally. Sometimes. If you're lucky.

Push-GLib-0.1.9.

mongo-glib

I recently wanted to learn the mongo wire protocol so I could better understand how to optimize my queries. I'm not a huge fan of Mongo, but they do a few things well. Additionally, I wanted something that would eventually work with GObject Introspection so I have the same API in multiple languages.

Therefore, I started writing one. It takes a different approach than most of the drivers out there. Primarily, it uses the asynchronous model introduced in GIO. This of course adds some extra complexity, but allows you to pipeline some packets together which can be useful.

Additionally, there is a MongoBsonStream object that is useful for reading through a file that contains a stream of BSON documents sequentially. This is the wire format for mongodump. Therefore, if you want to do offline jobs against your mongo backups, this can be quite useful. I in fact use it to verify the BSON schema of our database offline, after backups have occurred.

I don't know what will end up happening with it, but here it is.

Mongo-GLib-0.1.9

A moment to give thanks

I'm offline for the next two weeks, visiting Morocco. The time away is quite welcomed. I don't celebrate religious holidays, but the end of the year does present a time to reflect on a year passed by. I wanted to celebrate a short list of people that have had a positive influence on me this year, and that means something to me. This list is, by far, not comprehensive.

  • Emmanuele Bassi for his hard work and dedication to bringing us a solid platform. Clutter, gtk+, glib, json-glib. Your attitude and ability to stay calm when surrounded by trolls does not go unnoticed.
  • Hub Figuière for never relenting to others revisionist history.
  • Andy Isaacson for being 5 steps ahead of everyone else. Every conversation I have with you ends up in amazing stories, a history lesson, and what we can do to make it better. It is always inspiring.
  • Jacob Berkman for the indistinguishable mix of charm and bad attitude. It was unforgettable working with you.
  • Hylke Bons for taking the rudeness and undeserved aggression too often found in our community and continuing to produce quality.

Thank You!

There are so many others, but I wanted to keep this list short.

Translucent Scrollbars

While working on mock-ups and prototypes for Builder, I realized that I can't stand those clunky bars, and they need to go. 1/3rd will like the idea, 1/3 will say they prefer scrollbars, and a third will say I'm copying mac. Comments typically just put me into episodes of depression, so I'm not enabling them. I think that's why I blog less, but that is a rant for another lifetime.

http://www.youtube.com/watch?v=bNV8-evh-VY

moving along …

Today was my last day at VMware. I'm off to do another start-up.

I want GtkBuilder+JavaScript

While having coffee with some friends a few weeks ago, I kept coming back to the thought that I need to be able to do small amounts of scripting within GtkBuilder. Especially if I'm going to switch to that from hard coding UIs in C. I figured it would take some hacking to GtkBuilder to do what I wanted. Well, it turns out not. I came to the revelation late last night, in bed, and hacked it up this morning.

First, we create GScriptJs which is a thin wrapper around Gjs. Mostly, just to be able to create an object from within the GtkBuilder file. Then, we create a custom connect func that will look for a given function in the script and attach it to the requested signal. All in all, very few lines of code. I'm pleasantly surprised.

Example GtkBuilder+JavaScript

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <interface>
  3. <object class="GScriptJs" id="script">
  4. <property name="script">
  5. const Gtk = imports.gi.Gtk;
  6.  
  7. function onClicked() {
  8. let w = new Gtk.Window();
  9. w.set_default_size(320, 240);
  10. w.present();
  11. }
  12.  
  13. function onQuit() {
  14. Gtk.main_quit();
  15. }
  16. </property>
  17. </object>
  18. <object class="GtkWindow" id="window">
  19. <signal name="delete-event" handler="onQuit" swapped="no"/>

Example GtkBuilderConnectFunc

  1. static void
  2. connect_func (GtkBuilder *builder,
  3. GObject *object,
  4. const gchar *signal_name,
  5. const gchar *handler_name,
  6. GObject *connect_object,
  7. GConnectFlags flags,
  8. gpointer user_data)
  9. {
  10. const gchar *script_name = user_data;
  11. GScriptJs *script;
  12. GClosure *closure;
  13.  
  14. g_return_if_fail(script_name != NULL);
  15. g_return_if_fail(connect_object == NULL); /* TODO */
  16.  
  17. script = G_SCRIPT_JS(gtk_builder_get_object(builder, script_name));
  18. if (!script) {
  19. g_critical("Cannot locate script %s", script_name);
  20. return;
  21. }
  22.  
  23. closure = g_script_js_get_function(script, handler_name);
  24. if (!closure) {
  25. g_critical("Cannot locate function %s", handler_name);
  26. return;
  27. }
  28.  
  29. g_signal_connect_closure(object, signal_name, closure,
  30. !!(flags & G_CONNECT_AFTER));
  31. }

Get the code at https://github.com/chergert/gtkbuilderscript.

Gom data mapper

Sorry it has been so long. I've been trying to keep busy, playing with lots of new ideas to see what pans out. I guess I throw a lot of code away because of it.

Anyway, a while back I played with making a sort of data mapper. I figured it is time to post it here to see if anyone finds interest in it. Otherwise I'll just let it continue to bitrot. It lets you map GObjects to SQL or whatever. I've also only implemented sqlite. But it works okay for that so far. There are probably still a bunch of bugs or corner cases missing.

But it lets you do some fun stuff, like relations. It can handle basic properties, relations and groups, enums, etc etc. It does not do migrations.

Defining a resource

  1. #include "mock-gender.h"
  2. #include "mock-occupation.h"
  3. #include "mock-person.h"
  4.  
  5. GOM_DEFINE_RESOURCE(MockPerson, mock_person,
  6. GOM_RESOURCE_TABLE("persons");
  7. GOM_RESOURCE_HAS_MANY("friends",
  8. _("Friends"),
  9. _("The persons friends."),
  10. MOCK_TYPE_PERSON,
  11. NULL);
  12. GOM_RESOURCE_BELONGS_TO("occupation",
  13. _("Occupation"),
  14. _("The persons occupation."),
  15. MOCK_TYPE_OCCUPATION,
  16. NULL);
  17. GOM_RESOURCE_PROPERTY(g_param_spec_uint64("id",
  18. _("Identifier"),
  19. _("The persons identifier."),
  20. 0,
  21. G_MAXUINT64,
  22. 0,
  23. G_PARAM_READWRITE),
  24. "key", TRUE,
  25. "serial", TRUE,
  26. NULL);
  27. GOM_RESOURCE_PROPERTY(g_param_spec_string("name",
  28. _("Name"),
  29. _("The persons name."),
  30. NULL,
  31. G_PARAM_READWRITE),
  32. NULL);
  33. GOM_RESOURCE_PROPERTY(g_param_spec_enum("gender",
  34. _("Gender"),
  35. _("The persons gender"),
  36. MOCK_TYPE_GENDER,
  37. MOCK_GENDER_UNKNOWN,
  38. G_PARAM_READWRITE),
  39. NULL););

And no, you don't have to use the macros if you have something more complex.

Saving a resource

  1.  
  2. GomResource *resource;
  3.  
  4. resource = g_object_new(MOCK_TYPE_PERSON,
  5. "adapter", sqlite_adapter,
  6. "name", "Jane Doe",
  7. "gender", MOCK_GENDER_FEMALE,
  8. NULL);
  9. gom_resource_save(resource, &error);

Get the code here.

smoother graphs coming

I did a bit more work on the real-time graphs during my current vacation. It has resulted in being a whole lot smoother. Primary fixes were:

  • Graph tracks time rather than "available buckets" for data points. It works so much better I feel stupid for not doing it in the first place.
  • Use floating point for positioning throughout pipeline until last possible step.
  • Render updates in thread and only blit to cairo xlib surface in main loop. This probably isn't technically safe at the moment as reference counting of images in libpixman aren't thread aware. However, it seems to work pretty well for a single rendering thread. Once that is fixed, we can scale up rendering to more threads (which helps a bit if you have a lot of visualizers in perfkit).
  • Not really a performance/smoothing fix, but the renderers are abstracted more from the graph. This means the visualizers and realtime graphs in perfkit share rendering code.

It also now works on gtk+ 3.0. Obligatory screencast below.

http://www.youtube.com/watch?v=Yw88edHU18E

Things I’ve been working on

(Animations) ...

http://www.youtube.com/watch?v=lp6ceGP-6vU
http://www.youtube.com/watch?v=AlvieV-sBJo
http://www.youtube.com/watch?v=_koPfiJ2zn0

Visualizing main loop delays

Ross suggested adding a feature to show when your main loop has been blocked. I borrowed some code from libsocialweb to do this. The orange blocks are periods of time when the main loop was delayed for more than 10 milliseconds. Probably useful for people trying to have high frame-rate/smooth animations.