Aug 07

GNOME 3 Plugins: DBus

I’m currently messing around with GNOME 3 plugins, and there’s not a whole lot of information out there.  Like, almost nothing.  So, as I’m working on this stuff I will be posting up some information and some small plugins that demonstrate a certain feature.  Whenever possible, I will also link to the relevant code or library function(or at least what I think the proper library/function is).

Now, before we get started, note that this information is for GNOME shell 3.8.4, which is what Debian 8 ships with, as well as Red Hat Enterprise Linux(RHEL) 7.  Also, a note to the GNOME devs: WRITE SOME DOCUMENTATION.  Seriously.  Even a generated API document that shows what methods are on each object in JavaScript would be better than what currently is available(re: nothing).

Note that this is also going to be a bit of a crash course in JavaScript for me, so I may say some completely incorrect things about JavaScript.  If I make any errors, please feel free to leave a comment to correct me.  If you could also put a source with that, that would be very helpful so that we can all learn.

Alright, now let’s get onto the examples!

Create a new Extension

This is covered in most of the tutorials already, but we of course need an extension to edit!  So, let’s create a new one with:

gnome-shell-extension-tool --create-extension

Now give it a name, description and UUID. You can see an example here.  The new extension will be in

~/.local/share/gnome-shell/extensions/<your-extension-id>

Once you have edited an extension, you will have to reload the gnome-shell in order for the changes to take effect.  To do this, do ALT+F2, type ‘r’, and hit enter.

To view the output of the console, you will have to use systemd’s journalctl(for Debian 8, and probably RHEL 7).  The command is:

journalctl /usr/bin/gnome-session -f -o cat

Source here.

Also, you can enable-disable extensions using gnome-tweak-tool.

Example 1: DBus Connections

If you’re unfamiliar with DBus concepts, I recommend that you take a look at my DBus tutorial.  The first thing that we are going to have to do is to define an XML interface(essentially, what the DBus Introspection method gives back).

So, using our old friend the DBus tutorial, we will create an interface that looks suspiciously similar to our first DBus example of simply echoing a string out to the console. Here’s the interface XML:

<interface name="com.rm5248.ReceiveInterface">
<method name="echoMessage">
    <arg type="s" direction="in" name="message"/>
</method>
</interface>

For each method that we put on the bus, we must have a method on our javascript object that has the same name.  If we don’t, we will get an error about there not being a method to call.

Here’s the important part that actually connects to the bus(DBusIface refers to the XML that we defined above):

    this._dbusImpl = Gio.DBusExportedObject.wrapJSObject( DBusIface, this );
    this._dbusImpl.export( Gio.DBus.session, '/' );

You can check to see that this method works using qdbus:

qdbus org.gnome.Shell / com.rm5248.ReceiveInterface.echoMessage hithere

You should now see the log printed out with your message.

This is all well and good, but what if we want to have our own DBus address?  We don’t want everything to be under the org.gnome.Shell address. To do that, we simple need to acquire the well-known name on the bus that we want to use:

this._dbusId = Gio.DBus.session.own_name( 'com.rm5248', Gio.BusNameOwnerFlags.NONE, this._nameAcquired, this._nameLost );

A note on this though: your object will still be accessible from the well-known bus names of ‘com.rm5248’ and ‘org.gnome.Shell’.  Essentially, ‘com.rm5248’ becomes an alias for ‘org.gnome.Shell’, so any path that you can access using ‘org.gnome.Shell’ you can also use ‘com.rm5248’.  This perhaps not a bug, but it is contrary to how most bindings work.

The source that I used for testing can be found here. I’ve commented as much as I can, given my knowledge of how it works.

Example 2: Sending Messages

Now that we have our connection on the bus, and we can receive messages, how do we send messages out?  Well, we need to do two things: Create a proxy, and then create an instance of that proxy.  Once we have the proxy, we can call the methods asynchronously or synchronously.  Here’s the important part of the code(note that DBusIface is the same XML that we defined earlier):

   
    const ReceiveInterface = Gio.DBusProxy.makeProxyWrapper( DBusIface );
    var prox = new ReceiveInterface( Gio.DBus.session, 'com.rm5248', '/', 
        // I don't know what this Lang.bind does, but it's very important(the
        // plugin will load very slowly if it isn't here)
        Lang.bind( this, function( proxy, error ){
            if( error ) {
                log('error: ' + error );
                return;
            }
        })
    );

    try{
        // There are two methods that are made on the javascript object: <name>Sync and <name>Remote.
        // <name>Sync calls the method synchronously, <name>Remote calls it async.  
        //  I don't know where the error message goes when you call it async; a message is printed
        // out in the console that the exception was ignored.
        prox.echoMessageSync( "hithere" );
    }catch( e ){
        // This could fail if the well-known bus name does not exist
        log( 'Error calling method: ' + e );
    }

So, now we can call methods on other objects.  You can get the source code for this example here.  Also, a note on calling methods: there appears to be a bug when calling with the ‘sync’ method, in that it will take a long time to return.  I will do some more investigation.

Coming up in our next tutorial: settings.

Aug 03

Israel and Palestine in 2014

As of today, Operation Protective Edge has been going on for almost four weeks.  There doesn’t seem to be a clear end in sight at the moment.  Here’s some thoughts on what it looks like to me.

While Israel is probably justified in responding to attacks from Hamas, the entire thing is completely stupid.

Why?

Well, you can’t bomb Hamas out of existence.  It’s just not going to happen.

Why does Hamas exist in the first place?  Well, I don’t claim to be an expert on the Middle East.  But there are several problems here.  First, unemployment is around 30%.  That is not to say that unemployment is the root of all the problems; and in fact may not be, as crime does not necessarily go up when unemployment goes up.  In addition to just the unemployment, the population in Gaza is very young.  If the Freakonomics guys are to believed, that is the root of the problem here.  Essentially, people have no future, so they turn to the one organization that can give them something: Hamas.

Now, back to the central question: Why can’t we just bomb Hamas out of existence?  Well a few reasons.

  1. Hamas does have a legitimate grief against Israel, to the extent that Israel takes up much more land now then they originally were supposed to in 1947, and is currently occupying the West Bank.
  2. Bombing people will, in general, make them resentful.
  3. The danger of Hamas isn’t in guns and bombs.

The dangerous man is the one who has only one idea, because then he’ll fight and die for it.

-Francis Crick

I don’t know if the above quote is actually from Crick, but I have seen it attributed to him.  This is the main problem with Hamas – they have an idea, and people turn to them because they feel that there’s no hope(my thoughts, I don’t know if that’s actually true).

So, what has to happen?

If you want to defeat Hamas, you need to weaken them(duh).  To do that, you need to reform them.  That simply isn’t going to happen while bombs are still dropping; it creates a lot of resentment.  A large investment in Gaza and the West Bank is what has to happen in order for people to have jobs and turn against Hamas.  After all, Hamas was first elected because the people in Gaza thought that they would be able to give them a better life – since that hasn’t happened, people have begun to turn against Hamas.  Since the sentiment is generally against Hamas, now is the time to come in and invest properly.

I don’t have a magic pill that will solve everything.  But there are things that should be done to make this a better world.  Even if there aren’t any formal peace negotiations, both sides should still talk to each other.  After all, what my uncle says is true:

You’re not going to solve any problems if you don’t talk to each other.

Not talking to other people means that you don’t go anywhere.  If you’re talking, you can at least get somewhere.

Jul 07

Website Hack

So, apparently my website was hacked.

It doesn’t look like a WordPress vulnerability(although I can’t say for sure).  Anybody know where any logs are kept?

Of course, passwords have been changed to 15+ characters in length, so that should keep any passwords from being hacked easily.

May 09

Gravity

How did Gravity get so many awards?  I didn’t think that it was a very good movie.

 

I mean, sure it was nicely made.  It had good effects.  But it was an hour and a half of Sandra Bullock breathing heavily and being incompetent.  I just don’t see it.  To some extent, a lot of people would freak out; on the other hand, you’re supposed to be a professional.

May 02

Odd Code

I came across this odd piece of code today:

data[4] = (char)((1<<7) + (1<<5));

Can you figure out what it’s doing?  It took me a while as well.

It’s doing a bitwise-OR of the data.  But this ONLY works because of how the bits are shifted.  In this particular case, it does a bitwise-OR because no bits overflow.  For example, in base-10, if we have two numbers that we are adding together, and one of the numbers is 0, we can essentially just ignore it and put the two numbers together(in this example, the 1s place and 10s place only have one number each in them, so you can basically just combine them):

 103
+ 20
 123

You can do the same thing with binary numbers:

1010
+ 01
1011

Note that because there is no overflow in any place, this will have the same result if you do an add or a bitwise-OR together.  Clearly, if there are two bits in the same position in both numbers and you add them together, that will give you a different answer than if you or them together.

Apr 13

GNOME 3 Hate

Can anybody tell me why people are hating on GNOME 3 so much?  I can’t seem to quite figure it out.

The best that I can come up with is “Because it’s different.”  My Jack O’Neill response: “And? But? So? Therefore?”

I’ve been using GNOME 3 on Debian 7 for the past few months now, and I don’t see where all the hate is coming from.  I did a few things to tweak GNOME, but nothing drastic.  Sure, it may be a little annoying to not have a taskbar, but there are a bunch of extensions that give you a taskbar back if you want it.  Whenever you get a new program, often times you have to customize it to the way that you want it.  Everybody that’s complaining seems to be either a) hating change and/or b) unwilling to spend the time to customize things to how they want them.

When you get a new car, does it automatically match up with what your old car was like?  No, of course not.  When things are redesigned, there are going to be changes.  Some of them are bad.  Some of them are good.  Sometimes, it would help to read the manual.  Because then you might understand what is there and how to use it.  Because just opening something up, going “this is complicated and stupid, I’m going back to what I was using before” is not very productive to anyone.  Often I find that when things are changed, they do seem complicated and stupid.  But once I give it a chance, I can then better evaluate what is wrong/what is working, and how I can tweak the experience to better fit my working methods.

Mar 25

How to compile a SINGLE kernel module on Ubuntu

 

Today, I had to compile a custom kernel driver for Ubuntu, and it took me quite a while to do. There are a lot of guides out there, but many of them don’t seem to show the right way, or they do it one very specific way.  Fortunately, thanks to this person, I’ve figured out an easy way to do this which doesn’t involve re-compiling the entire kernel.

  1. Install the dependencies you need to build(build-essential will be pulled in automatically on Ubuntu, you may need to specify it if you’re using Debian): sudo apt-get install dpkg-source
  2. Install whatever kernel you want to use.  If you’re running the kernel you want to use, skip this step.  For example, on Ubuntu 12.04, you can install an image as such: sudo apt-get install linux-image-3.5.0-47-generic
  3. Install your kernel headers if you have not done so: sudo apt-get install linux-headers-`uname -r`
  4. Get the source of the kernel.  This is going to be quite large.  Also, you don’t have to do this as sudo.  apt-get source linux-image-`uname -r`
  5. Go to the directory that this source is in; for default Ubuntu installations, this will be: cd ./linux-3.2.0
  6. Prepare the workspace: make oldconfig && make prepare
  7. Copy the Module.symvers file from your currently running kernel into the build directory.  This is VERY IMPORTANT, as otherwise you will be unable to properly build and install the module.  This may lead to errors such as “no symbol table for module_layout” in dmesg when you attempt to load the module.  cp /usr/src/linux-headers-`uname -r`/Module.symvers .
  8. Edit whatever module you want.  In this example, I’m going to edit the ftdi_sio driver so that whenever the driver loads it will print out an awesome message.  In the ftdi_init function, I simply added a line to print when the module is loaded: printk( “RM5248 IS AWESOME” );
  9. Make the module.  Since we don’t want to rebuild the entire kernel, we just have to specify which driver to build.  Do it as such: make M=drivers/serial/usb/
    Using M=<directory> here is important; it makes sure that your Module.symvers won’t be overwritten
  10. Insert the module into the kernel to test it out: sudo insmod drivers/usb/serial/ftdi_sio.ko
    If you get an error “Invalid module format” you’ve done something wrong, probably with the Module.symvers file.  On my system, this fails the first time with “Unkown symbol in module” – you should be able to fix this by doing: sudo depmod -a
  11. Once you’re happy with your kernel module, put it into its permanent location: sudo cp drivers/usb/serial/ftdi_sio.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/ftdi_sio.ko
Mar 17

The Best Action Movie Ever

I just re-watched Transporter 2, and I came up with the best idea ever for an action movie.  Well, technically I came up with it a few days or weeks ago, but now seems like a good time to post.

What if we took Vin Diesel and Jason Statham and put them in a movie together?  It’d be two hours of beating other people up.

After all, most of their movies seem to follow the same basic plot.  Guy goes on a mission/people are coming to get him.  He beats them up.  End of story.  I’m looking at you, Riddick and Transporter.

If we want to throw in more bald people in there, throw Bruce Willis in as well.  That would be a great trio right there.

Of course, I have a feeling that the movie would have no plot.  But then again, you have three guys beating up other guys, so what plot needs to be there? 😛

(also, relevant XKCD)
Feb 27

What we dream

So I had a funny dream last night.

For some reason, I was thinking of the song Tubthumping by Chumawamba(a.k.a. I get Knocked Down).  This morning, shortly I woke up, I had a dream about part of the song.  Only some of the lyrics were replaced.  The best way to describe it is when the woman sings “Pissing the night away / pissing the night away” I replaced the lyrics with “I believe in the darkness / I believe in the light”.  Only a little happier.  And it was also sung by a woman with long pink hair in WWII-era uniform.  She was in the bar from Band of Brothers next to Carwood Lipton.

This brings up a good question: what do we dream?  Do we have full lifetimes in our dreams?  There is one person that I can remember(though sadly I can’t remember who at this point) who had a years-long dream and was in the middle of writing it down when he was interrupted.  Can we all have dreams like this?  It reminds me of the Batman Beyond episode where people were addicted to a virtual reality simulation.

Anyway, that’s the random thought of the day.

Jan 18

CGI in Movies

Last night, I went to see The Hobbit: The Desolation of Smaug, and it got me thinking about the CGI that was used.  Not just in The Hobbit, but in the previews as well.  There was a preview for The Amazing Spiderman 2, and almost the entire trailer was CGI clips.  Now don’t get me wrong, CGI can be used to do some great shots.  However, the problem as I see it is that it can be greatly over-used.

On some movies, this can be an intentional choice.  Such as in Sky Captain and the World of Tomorrow, where pretty much the entire movie was CGI – this works in my opinion.  However, when you need to mix CGI and live-action seamlessly, there can be a tendency more to be lazy with the live-action.  Before CGI, miniatures had to be made for everything, and miniatures almost always look better than CGI.  Granted, these shots probably used CGI to cut two shots together, but in my mind this is an acceptable use of CGI.  Creating an entire scene seems lazy.

The reason that I found The Hobbit to have a lot of CGI is because most of the movie that was inside the lonely mountain was CGI.  Everything just seemed too perfect.  The gold coins seemed all flat, Smaug was sitting on  a ridiculously large pile of gold, among other things.  I will paraphrase The Hobbit book here, from memory:

A constant stream of smoke came out of the gate.

I never got this feeling from the movie; everything still seemed as though the dwarves had left the lonely mountain and nothing had really changed.

To conclude, I think that this video shows what I’m talking about well; there are CGI elements, but it’s used more to tie two real shots together.  Because of this, it really shows better what is going on, and everything seems more realistic.  One of the problems with CGI as I see it is that everything seems too perfect; this is partly because of how the light is reflecting off of objects.  Most of the time, everything seems too bright.  The rest of the time, it generally feels off because the laws of physics seem to be broken; miniatures still have to follow the laws of physics.