Privacy

roland's picture

The issue of privacy has gotten me concerned recently.

  • I have an android phone and my location can be polled by any governmental authority with ease.
  • My fingerprints are taken at airports almost anually.
  • My online information is stored in various sites which most likely will sell it to data aggregator vendors
  • Cops monitor my driving on streets which is pretty normal anyways.
  • Teachers and assistants monitor that I don't cheat, apparently I am not trusted because of others past wrong-doings.

It's just weird that we claim we live in a free society but in fact, you can be monitored at any point.

People in dictatorships, probably, had more privacy than we do today, and the strangest thing of all, is that people don't care about giving up their personal data in return of service. The people trust authorities to not abuse the privileged information handed over.

All is well if you don't care, but what if things were to turn around like in China, where you can be imprisoned for many years, and probably die in prison, for thinking or speaking against any governmental activities.

Also, the technology that we produce in the west, is being actively used to monitor and control people in dictatorships such as China.

Goodbye Twitter

roland's picture

Finally I decided to cancel my twitter account for the following reasons:

  • I hate the word tweet and all the crazy movement about twitter which is supported by noobs.
  • Most posts on Twitter are useless and pointless.
  • Since businesses have gotten the word about twitter, it has become another way of looking at continuous ads.

 

So, I get my fair share of bombardment of junk and fud over my daily sources, so bye twitter.

A Knights Problem

roland's picture

Well, someone at work gave me this silly problem to solve: Suppose there are N knights, and one sword. A killer goes through the list of knights in a circular manner killing every other one. The problem is: Who is the last knight remaining? So I decided to run a comparison of what it takes to execute this code for 50,000 knights, the answer is 34465:

Langugage Time (seconds)
C++ (g++ 4.3.3) 0.008
C# (Mono 2.4.4) 0.055
Java 0.110
PHP (Linked Lists) 0.788
Python 2.6.2 2.191
Ruby (1.8.7) 2.314
T-SQL 3.212
LISP (clisp 2.44.1) 13.834
PHP 5.2.6 (Arrays) 39.747
Perl v5.10.1 155.70
Bash 4.1.5 Not finished after 2h 15m, so I terminated it

 

The implementation sometimes relies on arrays, sometimes on lists, vectors or queues. Technically the most efficient implementation would be that of a queue or a doubly linked list (single linked list too but it would require a few more conditionals).

I am sure you can probably implement this without using arrays (which is rather bad if the size is changing). I was blown away by C++, impressed by Java, Python and Ruby, and disappointed by LISP and PHP.

I wasted some time given that the problem was relatively easy:

C++:

Copying Arrays of Structures in C

roland's picture
My question is what would happen if you did array1[i] = array2[i] vs array1 = array[2]. The first works like *pointer1 = *pointer2, the latter is ambiguous. hmmm.
#include 

struct x {
  int y;
  int z;
};

int main() {
  struct x a[5];
  struct x b[5];

  int i;
  for(i = 0; i < 5; i++) {
    a[i].y = i;
    a[i].z = 100+i;
  }

  for(i = 0; i < 5; i++) {
    b[i] = a[i];
  }


  for(i = 0; i < 5; i++) {
    printf("%d -> %d\t %d -> %d\n", a[i].y, b[i].y, a[i].z, b[i].z);
  }
  
  printf("------------------------\n");

  a[3].y = 10;

  for(i = 0; i < 5; i++) {
    printf("%d -> %d\t %d -> %d\n", a[i].y, b[i].y, a[i].z, b[i].z);
  }
  
  printf("\n");
  return 0;
} 

Result:

0 -> 0	 100 -> 100
1 -> 1	 101 -> 101
2 -> 2	 102 -> 102
3 -> 3	 103 -> 103
4 -> 4	 104 -> 104
------------------------
0 -> 0	 100 -> 100
1 -> 1	 101 -> 101
2 -> 2	 102 -> 102
10 -> 3	 103 -> 103
4 -> 4	 104 -> 104

Understanding Arrays and Pointers and 2D Arrays in C

roland's picture
Have a look at the following code:
#include 
#include 

int **array;
int array_dim1 = 5, array_dim2 = 6;

int main() {
  // Declare Vars
  int i, j;

  // Allocate Memory
  array = (int **)malloc(array_dim1*sizeof(int *));
  for(i = 0; i < array_dim1;  i++) {
    array[i] = (int *)malloc(array_dim2*sizeof(int));
    for(j = 0; j < array_dim2; j++)
      array[i][j] = i*array_dim2+j;
  }
  for(i = 0; i < array_dim1; i++) {
    for(j = 0; j < array_dim2; j++) {
      printf("%d\t", array[i][j]);
    }
    printf("\n");
  }

  int *k = array[2];
  for(i = 0; i < 2; i++)
    printf("k: %d\n", k[i]);

  // Free Memory
  for(i = 0; i < array_dim1;  i++)
    free(array[i]);
  free(array);

  return 0;
}
It will print out
0	1	2	3	4	5	
6	7	8	9	10	11	
12	13	14	15	16	17	
18	19	20	21	22	23	
24	25	26	27	28	29	
k: 12
k: 13
So, you can point a pointer to a 2D array and iterate over it as if it were a regular 1D array. Cool eh?

My workload

roland's picture

Well, I have been taking the P536 (http://www.cs.indiana.edu/classes/p536/) at IU this semester and it's been kicking my butt. Seriously, this is one difficult programming class.

We have to work with crappily document toy OS called os161, which is developed by the research group at harvard. The guy that wrote this probably thought that code speaks for itself, and while I tend to do that, it's usually code that I'm pretty much the only one that will use it.

I posted some of the answers on this site to see how it would affect people.

If you want my answers to the second assignment, let me know, I will give it to you, but the code doesn't pass the tests. So, it's not that great, but it may provide you with a starting point. BTW, I implemented the whole thing by myself. 60+ hours of coding non-stop. It was crazy.

Next assignment is Virtual Memory, and I am already shaking in my boots.

 

Update: It turns out someone wants to see my answers. I hope you don't plan on cheating. Please, use the code as a basis of understanding how to solve the problem. The code doesn't pass many tests, it hangs, and has a lot of problems with it. So, use it at your own risk. Download files.

FreeBSD in Virtualbox

roland's picture

I've wasted a lot of time trying to compile gnome2 in FreeBSD. So for all of you considering using ports and compiling in VirtualBox, FORGET IT!

Just use pkg_add -r gnome2

Freebsd ld -lpth cannot be found

roland's picture

I tried fixing this problem by letting ldconfig know where libpth.so was and it knew it but when compiling py-libxml2 I kept getting this error about lpth. Anyways, here's what to do:

cd /usr/local/lib/pth
 ln  -s `pwd`/libpth.so ../  tada
Syndicate content