Socket Programming C#

There is some situation that you have to work extremely real time with your network system so it is necessary to sleep some threads until they have job to do!  in this situation you need to work with

  • AsyncCallback
  • ManualResetEvent

there are good references to do that



Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that need to be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remain intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, and storing complex data in XML.


Write to a file in C++

Name: Open_file_and_write.c
Date: 02/01/05
Description: Opens file by append example.
#include <stdio.h>
int main()
FILE *file;
file = fopen("file.txt","a+"); /* apend file (add text to a file or create a file if it does not exist.*/
fprintf(file,"%s","This is just an example :)"); /*writes*/
fclose(file); /*done!*/
getchar(); /* pause and wait for key */
return 0;


htpasswd replacement

use strict;
chomp(my $filename=$ARGV[0]);
chomp(my $username=$ARGV[1]);
chomp(my $password=$ARGV[2]);
if (!$filename || !$username || !$password) {
print "USAGE: ./ filename username password\n\n";
} else {
open FILE, ">>", $filename or die $!;
print FILE $username . ":" . crypt($password, $username) . "\n";
close FILE or die $!;

c++: cpu count

#ifdef _WIN32
#include <windows.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

int main() {
long nprocs = -1;
long nprocs_max = -1;
#ifdef _WIN32
#define sysconf(a) info.dwNumberOfProcessors
nprocs = sysconf(_SC_NPROCESSORS_ONLN);
if (nprocs < 1)
fprintf(stderr, "Could not determine number of CPUs online:\n%s\n",
strerror (errno));
nprocs_max = sysconf(_SC_NPROCESSORS_CONF);
if (nprocs_max < 1)
fprintf(stderr, "Could not determine number of CPUs configured:\n%s\n",
strerror (errno));
printf ("%ld of %ld processors online\n",nprocs, nprocs_max);
fprintf(stderr, "Could not determine number of CPUs");


linux: Mean of Load Average in uptime Command

For example, one can interpret a load average of “1.73 0.50 7.98” on a single-CPU system as:

  • during the last minute, the CPU was overloaded by 73% (1 CPU with 1.73 runnable processes, so that 0.73 processes had to wait for a turn)
  • during the last 5 minutes, the CPU was underloaded 50% (no processes had to wait for a turn)
  • during the last 15 minutes, the CPU was overloaded 698% (1 CPU with 7.98 runnable processes, so that 6.98 processes had to wait for a turn)

Wikipedia has a good article about that you can find it HERE!