Arquivos de Autor: marcotmarcot

How to check the size allocated by malloc

#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char ** argv)
{
for(int i = 1; i < 1000; i++)
{
size_t *p = (size_t *) malloc(i * sizeof(size_t));
printf(“%zu = %d * %zu\n”, *(p – 1), i * [...]

How to correct Emacs23 minibuffer in XMonad

In XMonad, when I start Emacs23, the minibuffer is very big:

To correct it to use just one line, you must split the window vertically with another window:

Then, when you make Emacs full screen again, the minibuffer will use only one line.

Using when with multiple files

when is a very nice perl program to keep track of appointments. I wanted to use more than one file as the input of when, so I made this make script:

#!/usr/bin/make -f
calendar = $(HOME)/.when/calendar
.PHONY: all
all: $(calendar)
when –nopaging
$(calendar): $(wildcard $(HOME)/.when/calendars/*.when)
cat $^ > $@

Match-Anything Pattern Rules

http://www.gnu.org/software/make/manual/make.html#Match_002dAnything-Rules

Executing code from time to time

This is a simple way to make a code be executed from time to time, using alarm().

#include
#include
#include

static void
run(int signal)
{
printf(“signal = %i\n”, signal);
alarm(1);
}

int main(int argc, char **argv)
{
struct sigaction act;

act.sa_handler = run;
if(sigaction(SIGALRM, &act, NULL))
[...]

gconf_client_add_dir() and remove

They don’t really create the directory. They just turn on and off listening to them.

g_idle_add()

When a signal is emitted a lot of times, and the processing of the action associated with the signal is expensive, it’s an option to only run the action when the system is idle. Using this function in this manner, this result can be achieved. I got to know this talking to pierlux [...]

Configuring Evolution after building from git

After building from git, the following command is necessary to avoid lock problems in local mail boxes, when evolution-data-server was built with –prefix=$dir and installed as a user.

# chown root:mail $dir/libexec/camel-lock-helper-1.2
# chmod ug+s $dir/libexec/camel-lock-helper-1.2

Adding an Accelerator to a GtkImageMenuItem in glade-3

To add an accelerator to a GtkImageMenuItem, you must:

Create the accelerator for the signal in the GtkImageMenuItem: Common -> Accelerators.
Create an accelerator group in the GtkImageMenuItem: General -> Accel Group
Set the window to use this accelerator. In GtkWindow: General -> Accel Groups.

Rank 2 Types

I’ve always seen the forall a types in some GHC messages or in other person’s code, but I couldn’t get the point of it until I needed to use it myself. I was writing a Gtk2hs application with some windows, and I noticed that for each created window, I was doing the same steps. [...]