Archive for the ‘Programming’ Category
August 24th, 2015
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 »
April 18th, 2014
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 !
November 26th, 2013
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
- Select Save File when prompted.
- Open the downloaded exe.
- Click Yes when Windows asks if you want to allow it.
- Click Next > on the Welcome screen.
- Select Download and Install and click Next >
- Read the License Agreement and click I agree
- Select Current to install the current MinGW package and click Next >
- Check the MinGW base tools and g++ compiler click Next
- Destination Folder should be C:\MinGW
- Click Next >
- Leave the default folder and click Install
- When Installation is complete, click Next >
- Click Finish
Install MSYS:
- Download MSYS
- Run the downloaded exe.
- Click Yes when Windows asks if you want to allow it.
- Click Yes you want to install in the Setup pop-up.
- Click Next in the Welcome Window.
- Read the License Agreement and click Yes
- Read the Information and click Next >
- The Default Destination of C:\msys\1.0 is fine, so click Next >
- The default folder of MinGW is fine, so click Next >
- Click Install
- A cmd shell will pop-up asking if you want to continue with the post install, enter y enter
- Answer y you do have MinGW Installed.
- Enter c:/mingw as the path where MinGW is installed.
- It should confirm that you have make.exe installed, press any key to continue.
- 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.
July 6th, 2013
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.
April 4th, 2013
#!/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;
}
}
March 21st, 2013
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 »