WebArchitectures: first (and not so useful) post

Leave a comment

Well, today the “game” is over, let’s start posting.

To be honest this is the first day I come out with something useful, and this would not be so bad if only I didn’t waste about one week in pointless experiments. A lot of effort has been spent in trying to figure out how Eclipse works. I’m totally not a big fan of IDEs: I’ve always preferred the GNU/Linux Shell and a good text editor (yes, I’m a Vim user), but I feel I can get used with some exercise. I just hope to speed up a little, or I will never finish!

Enough philosophy for today, let’s talk about Hibernate. There’s no much to say anyways…

Ingredients for the recipe:

  • A chroot sandbox for the mysql daemon (I like to separate stuff, and a chroot jails are just awesome)
  • All required libraries as explained here;
  • The java connector for mysql, which can be found here.

As probably half of the pepole who tried this, I experimented some troubles in figuring out why the gorramhibernate.cfg.xml” file cannot be found by the library. The problem was actually rooted in my lack of experience with Java, but I guess that the cumulated experience will prevent me from stumbling again in such trivial issues.

Meh. What a useless post…

Who’s writing me?

2 Comments

Have you ever noticed how some applications seems to be aware of how you pass them data? Take the su program, for instance:


$ echo 'my password' | su
su: must be run from a terminal

More

SOPA STRIKE

Leave a comment

http://americancensorship.org/modal/state-dept-petition/index.html

Interesting article

Leave a comment

That guy seems to be pretty much aware of what’s Erlang:
http://www.javalimit.com/2011/05/erlang-is-not-a-concurrent-functional-programming-language.html

Worthy read.

Erlang make – Give priority to behaviors

Leave a comment

Erlang/OTP has a nice pattern which strictly resambles Java’s Interfaces: behaviors. I’m using a behavior (“conf“) inside my application for {enter technical details here}, so I stumbled into a little itchy issue during compile time:

The problem… I hate warnings!

The solution comes strightforward: compile src/conf.erl before anything else. How to do that? Well, I surfed the Internet, searching for solutions. It turns out that, for instance, ejabberd is using Autotools instead of the standard Erlang compile system. Autotools are a really nice piece of crap software, but I don’t have time to discover how to use it with Erlang.

Then I just reconnected my brain…

Easy huh?

Note: Place the

-pa
flag before
-make
, otherwise the make command will not consider the output directory in the path.

Sparse matrix with Python

Leave a comment

For some applications you may have big sparse matrices, basicallly it’s filled of zeros everywhere, except for some points in which you setted some value, depending on your application logic. In this case a whole N×M matrix is a waste of memory (expecially for huge N and M) not to mention the fact you may want a matrix with more than two dimensions!

As you probably know, a good idea here would be using a mapping instead, say a Hash table, to store the elements you would put in the matrix with the coordinates as keys. In order to explain this concept to a friend of mine, I sketched an implementation of this principle in Python, and soon I realized it’s extremely easy!

More

The with statement

Leave a comment

I heard about Python‘s with statement, however I didn’t know about it. I suggest this link: it explains how that works in an effective and concise way.

Private Symbols

Leave a comment

The wise C programmer knows how souce code gets linked, so he or she is also aware of how symbols are managed into object code. In our module we typically want to export some symbols, like for instance a function or, if you really need to do it a global variable. Note also that types are not object symbols. More

Attributes Doxygen

Leave a comment

Sometime you need to use the attributesfor structs or functions. By example you may define:

typedef struct {
    uint8_t foo;
    uint16_t bar;
} __attribute__((packed)) foo_t;

From the doxygen point of view this could be nasty, since it will start thinking __attribute__((packed)) is the name of the struct.

Doxygen provides a solution to this through a special command inside the Doxyfile:

# The PREDEFINED tag can be used to specify one or more macro names that
# are defined before the preprocessor is started (similar to the -D option of
# gcc). The argument of the tag is a list of macros of the form: name
# or name=definition (no spaces). If the definition and the = are
# omitted =1 is assumed. To prevent a macro definition from being
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.

PREDEFINED             =

So we can just put a PREDEFINED = DOXYGEN and modify our code as follows:

typedef struct {
    uint8_t foo;
    uint16_t bar;
}
#ifndef DOXYGEN
__attribute__((packed))
#endif
foo_t;

Notes

I learned this trick by reading Alsa ASoundLib’s source code.

Python: default values in a dictionary

2 Comments

Sometimes it’s useful to define an associative array which maps a certain key to a list of elements. This is used basically everywhere you need to achieve some categorization. Just to give an example, suppose we want to group a bunch of people by name. Each person has an unique id, while there may be multiple guys with the same name.

More

Older Entries

Follow

Get every new post delivered to your Inbox.