Skip to main content

Posts

Showing posts with the label coding

Stalin Sort

Once in a while, I found a funny and interesting thing related to coding. I love coding (and to code). So, when somebody forwarded this - Stalin Sort, I laughed so hard but at the same time was intrigue. (Here is the link: https://github.com/gustavo-depaula/stalin-sort) The main gist of this "Stalin Sort" is that if you found an element that does not met with the sort criteria, you send it "to Gulag". Ha ha ha. That is so funny. You just delete or drop the element. Just like what Stalin would do. Later, I checked the github codes. Lots of codes there. The first thing I do is to find Perl implementation. I love perl. There, I found exactly what I wanted to see, a beautiful implementation. No, not the one-liner but the more verbose one. I love to explain things. When I see code that "no need to explain", you know you find a good code. It's just like jokes. If you have to explain it, it's not a good joke. Few days ago, I just had to roll my own Python...

Python Language

Finally, I decided to create a (YouTube) video. This time, it is about the Python programming language. In this video I talked about why Python is the language of today. (Not sure 5 years down the line.) Enjoy the video. Unfortunately the video is in Bahasa Indonesia. When I have the time, I'll make an English version of this. Come to think of it, there are already tons of videos on Python in English. I don't think you'll need another one. I guess, I'll make more videos in Bahasa Indonesia then.

Can't get getrusage working

We are trying to measure the amount of resources needed to run our program, written in C. Looking here and there, I found getrusage (2). So, yesterday I tried to write a simple code: #include <stdio.h> #include <errno.h> #include <sys/resource.h> int main(){ int y[100][100]; struct rusage *resource; int x; x = getrusage(0, resource); printf("x = %d\n", x); printf("errno = %d\n", errno); return(0); } The result was not great. getrusage returned -1. According to the man page , non zero return value means it fails. The value of errno is 14. What went wrong? Anybody? Is there a better way to measure the amount of resources (memory, CPU, time) needed for a program? [Right now, I am looking at dtrace . Would it help?]