Tuesday, March 4, 2014

Install Node.js on Ubuntu

From Ubuntu 12.04 to 13.04, an old version (0.6.x) of Node is in the standard repository. To install, just run:

$ sudo apt-get install nodejs

Obtaining a recent version of Node or installing on older Ubuntu and other apt-based distributions may require a few extra steps. Example install:

$ sudo apt-get update
$ sudo apt-get install -y python-software-properties python g++ make
$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs

source: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint

Wednesday, February 19, 2014

Get my Process ID and Parent Process ID in C, by calling getpid() and getppid()

Example to Get my Process ID (PID) and Parent Process ID (PPID) by calling getpid() and getppid().

#include <stdio.h>
#include <sys/types.h>

main(){
 pid_t mypid;
 pid_t myppid;
 
 mypid = getpid();
 myppid = getppid();
 printf("My PID: %ld\n", (long)mypid);
 printf("My PPID: %ld\n", (long)myppid);
}

getpid() and getppid()

Get GNU libc version at run-time using C

To get GNU libc version in C language at run-time, you can call gnu_get_libc_version() and gnu_get_libc_release().

- gnu_get_libc_version() returns string that identifies the glibc version available on the system.
- gnu_get_libc_release() returns string indicates the release status of the glibc version available on the system.

And, you can retrieve _CS_GNU_LIBC_VERSION with confstr().

Here is example, test_version.c:
#include <stdio.h>
#include <gnu/libc-version.h>
#include <stdlib.h>
#include <unistd.h>

main(){
    printf("GNU libc version: %s\n", gnu_get_libc_version());
    printf("GNU libc release: %s\n", gnu_get_libc_release());
    
    char *buf; size_t n;
    n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t)0);
    if ((buf = malloc(n)) == NULL) 
        abort();
    confstr(_CS_GNU_LIBC_VERSION, buf, n);

    printf("_CS_GNU_LIBC_VERSION: %s\n", buf );
    free( buf );
}

Get GNU libc version at run-time using C
Get GNU libc version at run-time using C

Tuesday, January 28, 2014

cal - Linux command to display calendar

cal
cal command
cal is a Linux command run on Terminal, to display built-in calendar on Terminal in text mode.


Monday, January 27, 2014

GtkColorChooser example

GtkColorChooser
GtkColorChooser

#include <gtk/gtk.h>

static void 
chooser_color_activated(GtkColorChooser *chooser, 
 GdkRGBA *color, gpointer user_data)
{
 GtkLabel *label = user_data;
 gtk_label_set_text (label, gdk_rgba_to_string(color));
}

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *label;
    GtkWidget *chooser;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 250);
    gtk_window_set_title(GTK_WINDOW(window), "Linux-buddy.blogspot.com");

    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);

 label = gtk_label_new("label");
    gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 3);

 //Create GtkColorChooser
    chooser = gtk_color_chooser_widget_new();
    gtk_box_pack_start(GTK_BOX(box), chooser, FALSE, FALSE, 3);
    g_signal_connect (GTK_COLOR_CHOOSER(chooser),
                    "color-activated", 
                    G_CALLBACK (chooser_color_activated), 
                    label);

    g_signal_connect(G_OBJECT(window), "destroy", 
        G_CALLBACK(gtk_main_quit), NULL);

    gtk_container_add(GTK_CONTAINER(window), box);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}


Note: double click the color buttons to activate color change.

Saturday, January 25, 2014

View hiden file start with a "."

Filenames which start with a "." (dot) are normally not shown. Use 'ls .*' or 'ls -a ...' to see them.


Wednesday, January 22, 2014

GTK+ example: Scale

GTK+ example: Scale
GTK+ example: Scale

#include <gtk/gtk.h>

static gboolean
scale_changed (GtkRange *range, gpointer data)
{
    gchar *text;
    gdouble value;
    GtkLabel *label;

    label = data;
    value = gtk_range_get_value (range);
    text = g_strdup_printf ("%.1f", value);
    gtk_label_set_text (label, text);
    g_free (text);

    return TRUE;
}

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *label;
    GtkWidget *spinButton;
    GtkWidget *scale;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 250);
    gtk_window_set_title(GTK_WINDOW(window), "Linux-buddy.blogspot.com");

    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);

    //Create Label
    label = gtk_label_new("label");
    gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 3);

    //Create Scale
    scale = gtk_scale_new_with_range (
        GTK_ORIENTATION_HORIZONTAL, 
        0,      //gdouble min
        10,     //gdouble max
        0.5);     //gdouble step
    gtk_widget_set_hexpand (scale, TRUE);
    g_signal_connect(G_OBJECT(scale), "value-changed", 
        G_CALLBACK(scale_changed), label);

    gtk_box_pack_start(GTK_BOX(box), scale, FALSE, FALSE, 3);

    //Connects GCallback function gtk_main_quit to "destroy" signal for "window"
    g_signal_connect(G_OBJECT(window), "destroy", 
        G_CALLBACK(gtk_main_quit), NULL);

    gtk_container_add(GTK_CONTAINER(window), box);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}