Linux alias on Windows (7)

Sebagai pengguna windows kita bisa pakai UnixUtils untuk, dan dalam solusi memendekkan command bisa gunakan doskey (perlu cek untuk windows 8 dst)

doskey yd=e:\installer\youtube-dl.exe -f 18 -t –write-auto-sub $1
http://www.palmtoppaper.com/ptphtml/17/pt170037.htm
http://darkforge.blogspot.com/2010/08/permanent-windows-command-line-aliases.html

CodeIgniter flow

appflowchart

  1. The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.
  2. The Router examines the HTTP request to determine what should be done with it.
  3. If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
  4. Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.
  5. The Controller loads the model, core libraries, helpers, and any other resources needed to process the specific request.
  6. The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served

This is original link from CI docs, Thank to Ravi, and IDD team

Simple C++ template char* and int, different strcmp output ?

#include <stdio.h>
#include <string.h>
//max returns the maximum of the two elements
template <class T> T max(T a, T b)
{
    return a > b ? a : b ;
}

// Specialization of max for char*
template <> char* max(char* a, char* b)
{
    return strcmp(a, b) > 0 ? a : b ;
}

int main()
{
    printf( "%d ", max(10, 15) );
    printf( "%s\n", max("Aladdin", "Jasmine") );
    return 0 ;
}

Output :
Windows: 15 Jasmine
Linux : 15 Aladdin

Reference:
http://www.iis.sinica.edu.tw/~kathy/vcstl/templates.htm

Very simple C++ string class in 31 lines

Bismillah

Its 2 things what I learnt

 1: #include <stdio.h>
 2: #include <stdlib.h>

 3: class cstring {
 4: private :
 5:  short int i;
 6:  short int maxl;
 7:  char * data;
 8: public:
 9:  short int len;
10:  char *str;

11:  cstring()  { data = (char*) malloc( 1024); str = data; maxl = 1024; };
12:  cstring( char * c ) {  data = (char*) malloc( 1024); str = data; maxl = 1024;  strcopy( str, c ); };  // lesson 1
13:  ~cstring() { free( data );  };

14:  cstring& operator = ( char * c ) { strcopy( str, c ); return *this; };

15:  void strcopy( char * dest, char * src ) {
16:    i = 0;
17:    while( (*src != '') && (i++ < maxl) )
18:      *(dest++) = *(src++);
19:    *(dest++) = *(src++);
20:    len = i;
21:  };
22: };

23: void main() {
24:   cstring b;
25:   b = " world";                               // b.operator=( "world" );   // lesson 2
26:   printf( "%d %s\n", b.len, b.str );
27:   cstring c[] = { "hi", "there" } ;
30:   printf( "%s %d\n", c[0].str, c[1].len );
31: }

Lessons learn:

  1. You can NOT call constuctor line 11 in line 12 , ie: cstring(); because its not what you mean. Compiler will interpret it as Object creation. My friend told me that he ever do similar code but forgot how to avoid duplicate code in line 11 and line 12. Anyone have idea ?
  2. b.operator= is function name

References:

  1. http://www.cplusplus.com/doc/tutorial/classes2.html
  2. http://csl.sublevel3.org/programming/my_string/

Can someone point out what wrong with my understanding. Thanks

error: asm/socket.h: No such file or directory and solution

Someday i want to compile this very simple socket program on RHEL5 Linux when get error like that.

#include <sys/types.h>
#include <sys/socket.h>main() {
  int svr_sd = socket(AF_INET, SOCK_STREAM, 0 );
  return 0;
}:

Diagnose:

#rpm -q kernel-headers
#rpm -V kernel-headers // to verify that everytingk is OK, print nothing on OK, else here what will you get :

# rpm -V kernel-headers

missing     /usr/include/asm/socket.h

Solution :

#rpm -e –nodeps kernel-headers
#yum install kernel-headers

Note: on RHEL4 “kernel-headers” name is “glibc-kernheaders”

Moral of story:

Program error message already point to solution. Because we make an assumption that gcc/g++ can compile other program  we dont go to right direction. We ask , “how can possible asm/socket.h not found, i dont touch the system?”

pthread_create valgrind memory leak solved

Its look like pthread_detach() and pthread_create()   is couple like free() to  malloc() . So … dont forget !

#include <stdio.h>
#include <pthread.h>

// unmark pthread_detach(), memory leak will be gone

void* process( void* data ) {
printf( “hello world\n” );
}

main() {
pthread_t th;
pthread_create( &th, NULL, process, NULL );
sleep( 1 );
// pthread_detach( th );
return 0;
}

/*

$ valgrind –tool=memcheck –leak-check=full –show-reachable=yes ./a.out

==23782== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1
==23782== at 0x4C1DCBF: calloc (vg_replace_malloc.c:279)
==23782== by 0x400FDF2: _dl_allocate_tls (in /lib64/ld-2.5.so)
==23782== by 0x4E28A33: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.5.so)
==23782== by 0x4005BF: main (thsimple.c:11)
==23782==
==23782== LEAK SUMMARY:
==23782== definitely lost: 0 bytes in 0 blocks.
==23782== possibly lost: 272 bytes in 1 blocks.
==23782== still reachable: 0 bytes in 0 blocks.
==23782== suppressed: 0 bytes in 0 blocks.

*/

Links:

http://sourceware.org/ml/glibc-bugs/2007-04/msg00036.html

http://www.linuxquestions.org/questions/programming-9/memory-leak-in-pthread-591263/

http://sources.redhat.com/bugzilla/show_bug.cgi?id=5171