By PDLCPayday Loan

Kubuntu wiht ugly menus, buttons and weird look and feel?

This seems to be a popular problem in kde’s history, after an update your menus and general look & feel of your desktop is just weird (actually is just without any theme). Trying to set a theme again it won’t work. To fix this you just have to remove one file and regenerate the cache config with another command, just execute:

$ rm ~/.config/Trolltech.conf
$ kbuildsycoca4 --noincremental

Then restart your session (or close your apps and open them again) and there you go, pretty again!

error on super() method, TypeError: must be type, not classobj

If you have an error like:

    ...
    super(NuclearMissileHandler, self).__init__()
TypeError: must be type, not classobj

That means you have forgotten to inherit from object in the superclass/es.

Mental note: write something interesting in the fraking blog yo.

What you should know before walk into a job interview for a developer position

You could be an awesome developer or a really bad one, it doesn’t matter, a job interview is something different. It’s like doing a crossword for a writer or a drive license test for a f1 driver, they should do it just ok, but a bit of practice before won’t hurt.

Things I’d recommend:

  • To code something while other people are watching you (if you have a blackboard, the better): I don’t know about you, but I get really nervous if someone is looking at my screen, I start to do a lot of typos, even with really short shell commands and don’t even try to think and write logical stuff. One thing sort of work for me is to (try to) think out loud in those situations.
  • Remember basic data types: Nowadays we got into bad habits of using a lot of libraries so we forgot about really basic stuff, do you know how to write a basic “set” date type from zero? a list? a balanced tree? 10 years ago I knew it, right now probably it would take me much more time.
  • Algorithm’s costs: more of the same. It’s quite easy, but you should remember and take a look into this, again.
  • Learn name of things: once thing is to have an anonymous function without being bound to some identifier and another different thing is to have a lambda. It’s not the same to have a class that exposes the functionality that to have a façade. Well, in fact those things are the same, but it helps if we speak the same language.
  • Do not panic: it’s not about answer quickly, take it easy.

May the source be with you.

Create ruby/jruby bindings of C++/C with ffi

Let’s start with the basic. What are bindings? It’s a way to call low level libraries (normally in C or C++) from another language (high level one, like ruby, java or whatever). This simple step requires two important things: 1) first, to know how we should call the method itself and 2) second, how to map the type from the high level language to C primitives types. To accomplish this, we have what is called foreign function interface which trivialize this task.

In ruby/jruby world we are gonna need ffi gem (jruby also has a compatible ffi gem), besides that the most important part is to have a clear interface in C. You can do bindings for a C++ library if you create a C interface first (because the bindings between C++ and C are free, the compiler knows how to do it by itself). So let’s cut the crap and write some code

First our C++ library which can be this few lines or thousands:

class awesome_object {
  public:
    awesome_object(int a, int b) : a_(a), b_(b) {}
 
    int awesome_method() {
      return a_ + b_;
    }
 
  protected:
    int a_, b_;
}

Now the C bindings which will be our façade for our c++ library:

extern "C" {
  typedef awesome_object_p void *;
 
  awesome_object_p create_awesome_object(int a, int b) {
    return static_cast<void *>(new awesome_object(a, b));
  }
 
  void delete_pointer_to_awesome_object(awesome_object_p p) {
    delete static_cast<awesome_object *>(p);
  }
 
  int awesome_method(awesome_object_p p) {
    awesome_object o = *static_cast<awesome_object *>(p);
    return o.awesome_method();
  }
}

Now ruby code that use ffi gem to be able to call the methods defined in C:

require 'ffi'
 
module AwesomeObject
  include FFI
  extend FFI::Library
  ffi_lib "libawesome.so" # .dll if you are in windows, it doesn't matter the OS
  attach_function "delete_pointer_to_awesome_object", "delete_pointer_to_awesome_object", [:pointer], :void
  attach_function "awesome_method", "awesome_method", [:pointer], :int
  attach_function "create_awesome_object", "create_awesome_object", [:int, :int], :pointer
end

With this you can use your C++ library from ruby code (I’d recommend package everything as a gem) just like this:

class MyTest
  include AwesomeObject
  def test!
    object = create_awesome_object(11, 31)
    awesome_method object
    delete_pointer_to_awesome_object object
  end
end
MyTest.new.test!

So, if you have read until now, probably you just want something working, say no more. Download this tar.gz, and see all this by yourself. In the tar you have the code split into c/h cpp/hpp files as it should be, in the post I’ve put all together to simplify things. Just execute make test and if you have ruby, ffi gem and g++ installed on your system, you’ll see something like:

$ make test
g++ -g -Wall -fPIC -c awesome_object.cpp
g++ -g -Wall -fPIC -c awesome.c
g++ -g -Wall -fPIC -shared -o libawesome.so awesome.o awesome_object.o
ruby test.rb
42

Attach android sources to your applications on eclipse

One of the awesome things about dealing with open software is to be able to access to the source code. When you deal with complex systems (so, every fraking day normally) the worst thing are black boxes that you cannot see, check or change their inside. This black boxes use to be closed/privaty systems/libraries/whatever. Lucky we are, android is open source you can get the source easily with repo but for developing applications in eclipse you can just install Android sources plugin and that’s it, really nice.

http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/

Scrollbars like they used to be in Ubuntu

I honestly don’t know why I still use ubuntu, it pisses me off a lot with so many useless change related to its user interface, very pretty (the first 2 minutes) but totally useless. At least it’s easy to change this stuff. To go back to the typical scrollbar just execute this in a console:

$ gsettings set org.gnome.desktop.interface ubuntu-overlay-scrollbars false