Little library to extract top N words from wikipedia

Library

 

This library has also unittesting and code coverage

Advertisements

The #Swap case

In case you need more swap and can’t create new partitions, here is a trick.

We’re using and adding, in this case, 512MB of swap file to the box

swapfileX where X is an integer >= 1

$ dd if=/dev/zero of=/swapfileX bs=1024 count=524288; chown root:root /swapfileX; chmod 0600 /swapfileX; mkswap /swapfileX; swapon /swapfileX

To make the change permanent across reboots, add

/swapfileX none swap sw 0 0

In /etc/fstab

The magic of #strace

A collogue of mine showed me some magic today.

Here is the magic command:

strace -ttt -fff -o rm rm /tmp/t

The result is like magic:

1455022679.446613 execve("/bin/rm", ["rm", "/tmp/t"], [/* 22 vars */]) = 0
1455022679.446786 brk(0)                = 0x19f4000
1455022679.446808 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
1455022679.446829 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe98e690000
1455022679.446874 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
1455022679.446896 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
1455022679.446915 fstat(3, {st_mode=S_IFREG|0644, st_size=31854, ...}) = 0
1455022679.446930 mmap(NULL, 31854, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fe98e688000
1455022679.446944 close(3)              = 0
1455022679.446958 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
1455022679.446975 open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
1455022679.446991 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\v\2\0\0\0\0\0"..., 832) = 832
1455022679.447005 fstat(3, {st_mode=S_IFREG|0755, st_size=1869392, ...}) = 0
1455022679.447020 mmap(NULL, 3972864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fe98e0a5000
1455022679.447035 mprotect(0x7fe98e265000, 2097152, PROT_NONE) = 0
1455022679.447050 mmap(0x7fe98e465000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7fe98e465000
1455022679.447070 mmap(0x7fe98e46b000, 16128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fe98e46b000
1455022679.447089 close(3)              = 0
1455022679.447111 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe98e687000
1455022679.447127 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe98e686000
1455022679.447141 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe98e685000
1455022679.447155 arch_prctl(ARCH_SET_FS, 0x7fe98e686700) = 0
1455022679.447213 mprotect(0x7fe98e465000, 16384, PROT_READ) = 0
1455022679.447233 mprotect(0x60d000, 4096, PROT_READ) = 0
1455022679.447249 mprotect(0x7fe98e692000, 4096, PROT_READ) = 0
1455022679.447264 munmap(0x7fe98e688000, 31854) = 0
1455022679.447336 brk(0)                = 0x19f4000
1455022679.447349 brk(0x1a15000)        = 0x1a15000
1455022679.447369 open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
1455022679.447387 fstat(3, {st_mode=S_IFREG|0644, st_size=2919792, ...}) = 0
1455022679.447402 mmap(NULL, 2919792, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fe98dddc000
1455022679.447418 close(3)              = 0
1455022679.447462 ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
1455022679.447490 newfstatat(AT_FDCWD, "/tmp/t", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_SYMLINK_NOFOLLOW) = 0
1455022679.447517 geteuid()             = 0
1455022679.447529 unlinkat(AT_FDCWD, "/tmp/t", 0) = 0
1455022679.447568 lseek(0, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
1455022679.447583 close(0)              = 0
1455022679.447596 close(1)              = 0
1455022679.447608 close(2)              = 0
1455022679.447620 exit_group(0)         = ?
1455022679.447670 +++ exited with 0 +++

/run/user/$uid and #systemd

Interesting and neat trick from systemd

 

/run/user/$uid is created by pam_systemd and used for storing files used by running processes for that user. These might be things such as your keyring daemon, pulseaudio, etc.

Prior to systemd, these applications typically stored their files in /tmp. They couldn’t use a location in /home/$user as home directories are often mounted over network filesystems, and these files should not be shared among hosts. /tmp was the only location specified by the FHS which is local, and writable by all users.

However storing all these files in /tmp is problematic as /tmp is writable by everyone, and while you can change the ownership & mode on the files being created, it’s more difficult to work with.

So systemd came along and created /run/user/$uid. This directory is local to the system and only accessible by the target user. So applications looking to store their files locally no longer have to worry about access control.
It also keeps things nice and organized. When a user logs out, and no active sessions remain, pam_systemd will wipe the /run/user/$uid directory out. With various files scattered around /tmp, you couldn’t do this.

Source: http://unix.stackexchange.com/questions/162900/what-is-this-folder-run-user-1000

#DNS …. that strange thing | back to Internet at the beginning

cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
127.0.0.1 localhost.localdomain localhost
192.9.200.10 apima
192.9.200.11 minolta
192.9.200.12 kyocera
192.9.200.13 pserv1
192.9.200.14 pserv2
192.9.200.15 lex654
192.9.200.20 xy1
192.9.200.70 renato
192.9.200.90 patrizia
192.9.200.249 PC-loretta
192.9.200.110 luca
192.9.200.120 grazia
192.9.200.121 presidenza
192.9.200.50 Melania
192.9.200.111 Fabrizio
192.9.200.80 Paola
192.9.200.40 Cristina
192.9.200.198 Pc-Paola
192.9.200.174 Simone
192.9.200.101 pccristina
#192.9.200.250 m1p504
192.9.200.250 giorgia

Nostalgia.. Touched #C for the first time in ages

#include <stdio.h>
#include <stdlib.h>
#define MAX_ELEMENTS 4

typedef struct _node {
  int el;
  struct _node *next;
} node;

node *push(node *head, int el) {
  if (head == NULL) {
    node *first = malloc(sizeof(struct _node));
    first->el = el;
    first->next = NULL;
#ifdef DEBUG
    printf("Element [%d] added as head\n", el);
#endif
    return first;
  }
  node *curr = head;
  while ((curr->next != NULL) && (curr != NULL)) {
    curr = curr->next;
  }
  node *tmp = malloc(sizeof(struct _node));
  tmp->el = el;
  tmp->next = NULL;
  curr->next = tmp;
#ifdef DEBUG
  printf("Element [%d] added\n", el);
#endif
  return curr;
}

int pop(node **head) {
  node *curr = (*head);
  int ret = (*head)->el;
  (*head) = (*head)->next;
  free(curr);
  return ret;
}

int printList(node *head) {
  node *curr = head;
  while (curr->next != NULL) {
    printf("[%d]\t", curr->el);
    curr = curr->next;
  }
  printf("[%d]\n", curr->el);
}

void freeList(node *head) {
  node *curr = head;
  node *tmp = NULL;
  while (curr != NULL) {
    tmp = curr;
#ifdef DEBUG
    printf("Freeing element [%d] \n", tmp->el);
#endif
    curr = curr->next;
    free(tmp);
  }
}

int main() {
  node *head = push(NULL, 0);
  printList(head);
  int i;
  for (i = 1; i < MAX_ELEMENTS; i++) {
    push(head, i);
    printList(head);
  }
  printf("Starts with pop(ing)\n\n");
  int n = pop(&head);
  printf("\nPop(ed) [%d]\n\n", n);
  printList(head);
  n = pop(&head);
  printf("\nPop(ed) [%d]\n\n", n);
  printList(head);
  printf("Starts freeing \n\n");
  freeList(head);
  return 0;
}