Archive for the ‘Programming’ Category

Simple Web server in 15 lines of code

No Comments »

I was trying to build a webserver for just displaying a simple message but I don’t want to use Apache/IIS/nginx etc.
So I tried nodejs and literally it is so easy to write a webserver in just 15 lines of code.

Webserver:

  • which can show static index.html page
  • which can log remote client IPs
  • which can use port from commandline to listen.
  • Portable, can run same code on Windows/Linux

Read the rest of this entry »


FTP clean-up script – PHP (delete old files on server)

2 Comments »

One of my blog user “Chris” asked for FTP clean up script, so here it is:


//CONFIG SECTION
//*******************************************************
// Credentials for FTP Server
$source_server_ip = "your_domain_or_IP"; // Server IP or domain name eg: 212.122.3.77 or ftp.domain.tld
// Credentials for FTP account
$ftphost = "ip_or_hostname_of_ftp"; // FTP host IP or domain name
$ftpacct = "userid"; // FTP account
$ftppass = "password"; // FTP password
$logs_dir = "/"; //FTP Remote Folder
$email_notify = 'your_email@domain.com'; // Email address for backup notification
$backupexpireindays=21; //3 weeks expire time in days, 21 days = 7*24*60
//END OF CONFIG SECTION
//*******************************************************


//Do not edit below this line
$backupexpireindays=($backupexpireindays*24)*3600; //convert it to seconds, 24 hours * 60 minutes * 60 seconds

// Delete any other backup with filetime greater than expire time, before create new backup
$conn_id = ftp_connect($ftphost);
$login_result = ftp_login($conn_id, $ftpacct, $ftppass);

ftp_chdir($conn_id, $logs_dir);
$files = ftp_nlist($conn_id, ".");
foreach ($files as $filename) {
        $fileCreationTime = ftp_mdtm($conn_id, $filename);
        //$date = date("F j, Y, g:i a", ftp_mdtm($conn_id, $filename));
        //print "
Timestamp of '$filename': $date"; $fileAge=time(); $fileAge=$fileAge-$fileCreationTime; if ($fileAge > $backupexpireindays) { // Is the file older than the given time span? //echo "
The file $filename is older than Expire time :$expiretime ...Deleting\n"; ftp_delete($conn_id, $filename); //echo "
Deleted

"; } } ftp_close($conn_id); print "Remote FTP clean up Finish deleted files older than $backupexpireindays days"; ?>

Enjoy !


Installing MinGW/MSYS on Windows with OpenSSL support

1 Comment »

 

Installing MinGW/MSYS
http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite
http://www.mingw.org/wiki/MSYS

Install MinGW (before MSYS)

Download the MinGW Installer from http://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/download

  1. Select Save File when prompted.
  2. Open the downloaded exe.
  3. Click Yes when Windows asks if you want to allow it.
  4. Click Next > on the Welcome screen.
  5. Select Download and Install and click Next >
  6. Read the License Agreement and click I agree
  7. Select Current to install the current MinGW package and click Next >
  8. Check the MinGW base tools and g++ compiler click Next
  9. Destination Folder should be C:\MinGW
  10. Click Next >
  11. Leave the default folder and click Install
  12. When Installation is complete, click Next >
  13. Click Finish

Install MSYS:

  1. Download MSYS
  2. Run the downloaded exe.
  3. Click Yes when Windows asks if you want to allow it.
  4. Click Yes you want to install in the Setup pop-up.
  5. Click Next in the Welcome Window.
  6. Read the License Agreement and click Yes
  7. Read the Information and click Next >
  8. The Default Destination of C:\msys\1.0 is fine, so click Next >
  9. The default folder of MinGW is fine, so click Next >
  10. Click Install
  11. A cmd shell will pop-up asking if you want to continue with the post install, enter y enter
  12. Answer y you do have MinGW Installed.
  13. Enter c:/mingw as the path where MinGW is installed.
  14. It should confirm that you have make.exe installed, press any key to continue.
  15. Click Finish you are done the installation. (It is up to you if you want to open the documents.)

OpenSSL

OpenSSL is a library for Secure Sockets Layer (SSL), Transport Layer Security (TLS) protocols, and cryptography. Some tools require openSSL, if so, here are some instructions:

I downloaded an openssl installer from: http://www.slproweb.com/products/Win32OpenSSL.html

I installed into /mingw/openssl/. I then linked the includes:

cd /mingw/include
ln -s ../openssl/include/openssl openssl

That's it.

Flash C++ compiler is now open source

No Comments »

 

If you like Flash, here is a good news that should interest you. Adobe released its open source Flash C + + compiler.

FlashCC, this compiler can import and use of C or C + + code to the web while maintaining good performance, cross-browser compatibility, connecting with the Flash API, and support for graphics acceleration .

FlasCC is now available on Github as brick CrossBridge project.

There were no major changes from the previous version and it apart from the passage in open source will allow to everybody to make forks or integrate the compiler code in their own projects.

Demo of Epic Games using Flash C++ Compiler is here Unreal Engine 3.

For more information it is here.

 


Code formating script

No Comments »
#!/usr/bin/perl -w
 
my $ifile = shift;
my $blank = 0;
my $indent = 2;
open(IFILE, "$ifile") or die "Cannot open $ifile\n";
while(my $line = ) {
  if($line =~ /^\s*else/i
     or $line =~ /^\s*end/i
    ) {  #reduce indent before xxx
    $blank = $blank - 2;
  }
  if($blank > 0) {
    print " " x $blank;  #print several blanks
    print "$line";
  } else {
    print "$line";
    $blank = 0;
  }
  if($line =~ /^\s*if/i
     or $line =~ /^\s*else/i
     or $line =~ /^\s*loop/i
    ) {  #increase indent after xxx
    $blank = $blank + 2;
  }
}

Growl Notifications for MSOutlook (Any Version)

8 Comments »

Growl is very good tool for local and remote notifications, we can compare it with libnotify in Linux plus growl is already available on multiple platforms, So now I want to use it with Microsoft Outlook to notify me when new email arrives, but unfortunately there is no Add-on available for growl after Outlook 2007 onwards, so I did the work for myself, basically it is too simple to write a procedure in VBA for Office (Macros) but the only drawback is that you need to allow macros (security involved) OR sign it with Digital Certificate (money involved) Read the rest of this entry »