pyk deep learning & natural language processing

Sale Stock Backend Technical Assesment

Update 29 January 2016

I take the offer from Sale Stock Indonesia to be their Jr. Data Scientist.
Start from 15 February 2016 I will join the Data Science Departement at Sale Stock Indonesia.
Also, It turns out that at saturday dan sunday they off from work. That's why they are not responding my email.

I passed the Salestock backend technical assesment.

This commit will exactly tell you how I felt at that time.

For me, they are not responsive. I got reply after 2 days. It make me feel like

“Ok, You guys are contact me and told me todo this. I will not working on this if you are not responding my questions”

But, I’m afraid at the same time. I’m afraid that I became a person who can’t hold their words. Because, I say to the recruiters who call me that I’m going to do their assesment.

So, I decided to working on it and here it is the result. After I submit my work, the recruiter call me that I passed their backend technical assesment a few hours later.

The recruiters only say that my submission is good. Wondering if they are ever really read my code.

Supreme C

Lately, I’ve been thinking about consistency in C programming language API. Honestly, for me Go Programming Language is very well designed. Not to mention that a bunch of smart peoples are behind it.

I like Go interface, I like how to Go handle an error, awesome standart libraries, awesome communities, etc. I would like to write in C and feels like to write Go code. Can I have it?

Right now, I have an idea to create an simple, consistent, and high-level C programming language API. I called it “Supreme C”. In case you curious, “Supreme C” I take from Supreme Chancellor name.

I would like to have an API that handle a low level stuff for netoworking, so I can use a function like connect("localhost:8080") and socket file descriptor ready to read and write is returned.

I want to write and read buffer safely. So, using io.Reader and io.Writer concept from Go programming language is a good idea.

Maybe I will start building Supreme C from the problem that I need to solve. But, I already have the big picture. Supreme C will look like a standart Go library.

Consistent Compilation In C

Compiling C program using -std option will save me from a bunch of problems about portability of my program. I use C99 standart, since C11 is not widely implemented yet.

CC -std=c99 -pedantic -Wall -Werror -o program program.c

Sometimes I need a function definitions that are not specified in ISO C standart. Such as getaddrinfo, getnameinfo and freeaddrinfo for socket stuff. Those functions are specified in POSIX.1-2008 standart.

Naturally -std=c99 option will force a system headers to only expose a definitions that valid in ISO C99 standarts, and it’s good. Compiling a program that include a system header and use a functions that are not specified in the standart will yield the following errors:

% CC=clang-3.7 make
clang-3.7 -std=c99 -pedantic -Wall -Werror -o hostinfo hostinfo.c
hostinfo.c:58:21: error: variable has incomplete type 'struct addrinfo'
    struct addrinfo hints, *addri;
                    ^
hostinfo.c:58:12: note: forward declaration of 'struct addrinfo'
    struct addrinfo hints, *addri;
           ^
hostinfo.c:62:18: error: implicit declaration of function 'getaddrinfo' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
    int gairet = getaddrinfo(argv[1], NULL, &hints, &addri);
                 ^
hostinfo.c:64:40: error: implicit declaration of function 'gai_strerror' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
        fprintf(stderr, "Error: %s\n", gai_strerror(gairet));
                                       ^
hostinfo.c:64:40: note: did you mean 'strerror'?
/usr/include/string.h:413:14: note: 'strerror' declared here
extern char *strerror (int __errnum) __THROW;
....

I need to define feature test macros for POSIX.1-2008 explicitly in order to tell compiler that I need a features from POSIX.1-2008 standart:

#define _POSIX_C_SOURCE 200809L

This macro causes header files to expose definitions corresponding to the POSIX.1-2008 base specification (excluding the XSI extension) when program is compiled.

Now, my program will consistently compiled in POSIX-compliant system.

Multiple Lines String In C

There are two ways of splitting char * variable in mupltiple lines.

/* the first one */
char *str1 = "line 1\n \
line 2";

/* the second one */
char *str2 = "line 1\n"
             "line 2";

I like the second one.

It can be useful for printing multple lines in C. Let’s take a look redis source code as an example. Instead of printing multiple lines string like this

I like to write the code like this one

less typing FTW.

Exit Status In POSIX-compliant Systems

Choosing the right exit status for success or failure opreation in the program is critical.

In POSIX-compliant systems, there are 2 exit codes. 0 indicate a success and 1 indicate a failures.

I use {0,1} instead of a macro {EXIT_SUCCESS, EXIT_FAILURE} that defined in stdlib.h because it’s the same things and it’s less type for me.