Entries Tagged as ''

Happy Mom and Dad’s Day – The Living Years

Long time no listen. Finally found out. Happy Mom and Dad’s Day.

YouTube – Mike & The Mechanics – The Living Years

FTP Active Mode vs. Passive Mode

Since we need to deal with firewall between FTP clients and server, the following diagram shows that two modes of FTP. So, we can design more accuracy firewall policy by applying different modes.

FTP Active vs. Passive

The following is quoted the pros and cons:

Active FTP is beneficial to the FTP server admin, but detrimental to the client side admin. The FTP server attempts to make connections to random high ports on the client, which would almost certainly be blocked by a firewall on the client side. Passive FTP is beneficial to the client, but detrimental to the FTP server admin. The client will make both connections to the server, but one of them will be to a random high port, which would almost certainly be blocked by a firewall on the server side.

vsftpd put “553 Could not create file” solution

I set up a new FTP server by using vsftpd. I observed that I could get file but failed to upload file. After investigation, I found out there are three points I should concern about.

First, write_enable=YES in /etc/vsftpd/vsftpd.conf

Second, system-config-firewall to enable command port 21 and data port 20.

Last, system-config-selinux to set Boolean ftp_home_dir to 1

After service vsftpd restart, I can get and put file in my home directory.

tftpboot directory changed in FC9

One change in FC9 is tftpboot directory. In the previous release, after installed tftp-server, it created /tftpboot directory. In FC9, the directory change to /var/lib/tftpboot/. The reason I guess is to keep root directory more clear.

UTF-8 to UTF-16 Mapping

UTF-8 to UTF-16

UTF-8 Pattern UTF-16 High Byte UTF-16 Low Byte
0tuvwxyz 00000000 0tuvwxyz
110pqrst
10uvwxyz
-
00000pqr
-
stuvwxyz
1110jklm
10npqrst
10uvwxyz
-
-
jklmnpqr
-
-
stuvwxyz
11110efg
10hijklm
10npqrst
10uvwxyz
-
110110ab
-
110111qr
-
cdjklmnp
-
stuvwxyz

Reference: Cameron, R. “A Case Study in SIMD Text Processing with Parallel Bit Streams”, School of Computing Science, SFU, 2008

Unicode Range to UTF-16 Pattern

Using one table to express RFC 2781

Unicode to UTF-16

Unicode Range Code Point Pattern UTF-16 Pattern
0000-007F 00000 00000000 0tuyvwxyz 00000000
0tuvwxyz
0800-FFFF 00000 00000pqr stuvwxyz 00000pqr
stuvwxyz
0800-FFFF 00000 jklmnpqr stuvwxyz jklmnpqr
stuvwxyz
10000-10FFFF efghi jklmnpqr stuvwxyz 110110ab
cdjklmnp
110111qr
stuvwxyz

C/C++: srand() and rand() to get random numbers

We can simply design a 6/49 lottery selector by randomly get numbers from 1 to 49. We will use srand() and rand().

srand() initializes random generator by argument seed. Normally, we use time() as seed.

srand( (unsigned int) time( (time_t *) NULL) );

rand() is function call to generate numbers which initialized some distinctive value using srand(). We can get number from 1 to 49 by mod 49 and plus 1.

(rand() % 49) + 1;

C/C++: Swap Two Value by XOR

#include<stdio.h>
int
main()
{
int one=20;
int two=21;

one ^= two;
two ^= one;
one ^= two;

printf(“new one is:%d, new two is:%d\n”, one, two);

return 0;
}

C/C++: #define

#define is precompile directive for compiler. Basically, #define has three functionalities, text substitutions, macro and conditional compiler directives.

1. Define Text Substitutions

#define MAXNUMBER 1024

#define BUFFER 2048

#define TRUE 1

#define FALSE 0

2. Define Macro

#define mem_clear(name) memset( name, ‘ ‘, sizeof(name))

#define max(a, b) ( (a) > (b) ? (a) : (b) )

However, sometimes, define macro do have some drawbacks. If “a” is “++i” in above definition, the “i” will be increment two times. Macro doesn’t have memory address. Macro doesn’t have recursive algorithm. Thus, Macro is hard to debug.

3. Conditional Precompile Directive

This feature has more advantage. we can put #ifdef, #ifndef and #endif in anywhere in the body of program. It will cooperate with configuration file to realize the certain functions.

#ifdef FAST_FUNC
#ifndef BUFFERED_FUNC
rslt = func((char **) &srcbuf_ptr,
&inbytes_left,
(char **) &trgtbuf_ptr,
&outbytes_left);
#endif