In Perl 5.10, the ActiveState ppm server no longer includes the GD package because it's difficult to include it in the automated build process [1]. The GD module however is available from the repository of the University of Winnipeg at http://theoryx5.uwinnipeg.ca/ppms/ (for Perl 5.8) or http://cpan.uwinnipeg.ca/PPMPackages/10xx/ (for Perl 5.10) [2].
So when use ppm to install GD module, one needs to add the second repository.
[1] http://docs.activestate.com/activeperl/5.10/faq/ActivePerl-faq2.html
[2] http://trouchelle.com/perl/ppmrepview.pl
[Added 3/6/2010]
On Centos, installing GD library for PHP can be easily done by: yum -install php-gd
Monday, January 25, 2010
Wednesday, December 23, 2009
CVS
Quick start to CVS on linux.
CVSNT/CVS 2.x client/server downloads for windows, linux and Mac OS X:
http://www.march-hare.com/cvspro/
WinCVS client also can be separately downloaded from WinCVS download.
Set up CVSNT 2.5.04 on WindowsXP or Windows 2003 server:
(The following steps are extracted from here)
CVSNT/CVS 2.x client/server downloads for windows, linux and Mac OS X:
http://www.march-hare.com/cvspro/
WinCVS client also can be separately downloaded from WinCVS download.
Set up CVSNT 2.5.04 on WindowsXP or Windows 2003 server:
(The following steps are extracted from here)
1. Preparation
1) Prepare a NTFS partition for CVSNT. [this is not necessary]
2) In folder's Tools -> Folder Options -> View -> Advanced Settings,
Cancel "Use Simple File Sharing (recommended)". [this is not necessary]
3) Create two folders:
- D:\Temp, set its security settting to "fully control" by all users.
- D:\CVSRepo. This will be where repositories are stored in.
2. Installation of CVSNT. Use default settings.
3. Configure
1) First create two windows system accounts, say CVS_Mgr and CVS_Usr.
2) Open CVS control panel, in tab "About", Click on "Stop" to stop CVSNT service.
3) In "server settings" tab, choose "Temporary" folder to the previous created D:\Temp.
Choose "CVS_Mgr" or "CVS_Usr" for "Run as user".
4) In "Repository configuration" tab, add new repository,
set "Location" to "D:\CVSRepo", and set "Name" to "\CVSRepo".
Leave "Default repository" unchecked and the rest 3 checkboxes checked.
5) Now in CVS control panel, in tab "About", Click on "Start" to start CVSNT service.
6) Add users. Do this from command line in a DOS windows.
Let CVS_Mgr belong to the Administrators group.
In command line, type these:
set cvsroot=:sspi:<computer name>:/CVSRepo
cvs passwd -a CVS_Mgr
cvs passwd -a CVS_Usr
It will prompt for the passwords of these 2 users.
Now the setup is done.
7) Use the following to test it:
In a DOS window, type
set cvsroot=:pserver:CVS_Mgr@<computer name>:/CVSRepo
cvs login
cvs ls
This will list the current files in the repository.
Now one can connect to the CVSNT server from CVS clients on other machines.
Saturday, December 12, 2009
Bloom Filter
One problem is to determine if a given value x exists in a set S. When the size of the set S is huge, there can be computational cost and storage difficulty.
Bloom filter solves this problem by a way similar to this:
1) preprocess the set: for every value w in the set S, compute a feature vector (v_w1, v_w2, .. v_wn). In the entire vector space, set these as 1, set the rest as 0.
2) compute the feature vector for the given value x (v_x1, v_x2, ..., v_xn). Now if all of v_x1, v_x2, ..., v_xn are 1, then it's possible the value x is in the set S.
The issue is possible false-positive: x is not in the set, but its feature vector are all 1s. To solve the issue, the key is to choose good vector computation function(s). Usually the probability of false positive is 0.0001 or below.
The advantage, on the other hand, is that there is NO false-negative: if computation shows the value x does not exist, then this is 100% correct. Therefore bloom filter is very reliable and efficient in ruling out a value that does not exist.
See this page for a more detailed explanation for bloom filter, and a piece of comment.
More topics of the application of math from this author are here.
Bloom filter solves this problem by a way similar to this:
1) preprocess the set: for every value w in the set S, compute a feature vector (v_w1, v_w2, .. v_wn). In the entire vector space, set these as 1, set the rest as 0.
2) compute the feature vector for the given value x (v_x1, v_x2, ..., v_xn). Now if all of v_x1, v_x2, ..., v_xn are 1, then it's possible the value x is in the set S.
The issue is possible false-positive: x is not in the set, but its feature vector are all 1s. To solve the issue, the key is to choose good vector computation function(s). Usually the probability of false positive is 0.0001 or below.
The advantage, on the other hand, is that there is NO false-negative: if computation shows the value x does not exist, then this is 100% correct. Therefore bloom filter is very reliable and efficient in ruling out a value that does not exist.
See this page for a more detailed explanation for bloom filter, and a piece of comment.
More topics of the application of math from this author are here.
Read/Write Excel on Windows & Linux
On windows read/write Excel is easy. Set up ODBC for read and write connections on source and destination Excel files. For some reason Microsoft does not allow delete records in Excel through the ODBC interface (actually might be in any other interfaces), so delete can be done by replacing the current Excel with a blank Excel at the File System level.
In linux, there are modules created by people in PHP to do this, such as PHPExcel. So you download the library and use it. In Perl, the modules Spreadsheet::ParseExcel and Spreadsheet:WriteExcel are written by Takanori Kawai and John McNamara in 2000 and tincluded into CPAN. If your Perl installation does not come with this, install them (e.g., using PPM on windows or CPAN on linux). Some example code are here. This code works for Excel up to version 2000. I didn't try on more recent versions. On windows Perl also can manipulate Excel using the Win32::OLE package which is recommended.
To write Excel file, there is a shortcut to output to a *.csv file. A *.csv file uses comma as delimiter and is opened by Excel, then you can save it as a true Excel file. To escape comma in a *.csv file, quote the entry by double quotes, e.g., "a,b". To include a double quote in an quoted entry, replace it with two double quotes, e.g., "a""b".
In linux, there are modules created by people in PHP to do this, such as PHPExcel. So you download the library and use it. In Perl, the modules Spreadsheet::ParseExcel and Spreadsheet:WriteExcel are written by Takanori Kawai and John McNamara in 2000 and tincluded into CPAN. If your Perl installation does not come with this, install them (e.g., using PPM on windows or CPAN on linux). Some example code are here. This code works for Excel up to version 2000. I didn't try on more recent versions. On windows Perl also can manipulate Excel using the Win32::OLE package which is recommended.
To write Excel file, there is a shortcut to output to a *.csv file. A *.csv file uses comma as delimiter and is opened by Excel, then you can save it as a true Excel file. To escape comma in a *.csv file, quote the entry by double quotes, e.g., "a,b". To include a double quote in an quoted entry, replace it with two double quotes, e.g., "a""b".
Thursday, December 10, 2009
Network tools
To find out what server (IIS/Apache etc.) a site is running:
http://uptime.netcraft.com/up/graph
or: http://whois.domaintools.com/thedomainname.com
Many tools for analyzing web stuff:
http://www.dnsstuff.com/tools/
http://uptime.netcraft.com/up/graph
or: http://whois.domaintools.com/thedomainname.com
Many tools for analyzing web stuff:
http://www.dnsstuff.com/tools/
Saturday, December 5, 2009
DOS batch file to backup files
Batch file backup_mystuff.bat:
And example mystuff_exclude_list.txt file:
echo off
REM
REM This script backs up files.
REM Files listed in %exclude_list% are excluded.
REM
REM Reference: http://www.ahuka.com/backup/backup3.html
REM By: XC
REM Created on: 12/5/2009
REM Last modified: 12/5/2009
REM
echo.
echo == Back Up Files ==
echo.
REM
REM Use this, and !var! after assignment.
REM Otherwise the input value will be buffered until next execution.
REM
SETLOCAL ENABLEDELAYEDEXPANSION
set "dstDir=mystuff_%date:~10,4%-%date:~4,2%-%date:~7,2%"
set srcDir=D:\wwwroot\mystuff
set exclude_list=mystuff_exclude_list.txt
if EXIST %dstDir% (
(set USRINPUT=)
set /P USRINPUT=Delete existing directory %dstDir% [y/n]:
REM echo Your input was: !USRINPUT!
if "!USRINPUT!" == "y" goto:go_on
if "!USRINPUT!" == "Y" goto:go_on
REM If input is not 'y' or 'Y', exit.
goto:EOF
:go_on
echo Delete existing directory %dstDir%...
rmdir /S /Q %dstDir%
)
echo.Copy files from %srcDir% to %dstDir%, please wait...
echo.
mkdir %str%
xcopy /E /V /Y /Q /EXCLUDE:%exclude_list% %srcDir%\* %dstDir%\.
echo.
And example mystuff_exclude_list.txt file:
D:\wwwroot\mystuff\download
D:\wwwroot\mystuff\aspnet_client
Monday, November 30, 2009
A Perl script to count LOC (Lines Of Code)
#!/usr/bin/perl
#
# This script counts number of lines in files of specified type.
# The counting is done recursively into subdirectory.
# @Usage: perl getLOC.pl [dir|file]
# If no argument is provided, start from current dir ".".
# @By: XC
# @Created on: 11/29/2009
#
print "\n- Line Counter -\n\n";
# specify file type(s) here. Use "[]" to escape ".".
my @types = ("[.]c", "[.]h");
#my @types = ("[.]cs"); #, "[.]aspx");
#my @types = ("[.]asp");
my $dirname = ".";
my $total_loc = 0;
# Get input directory name.
my $argc = $#ARGV + 1;
if ($argc > 0) {
$dirname = $ARGV[0];
}
# Process the starting directory or file.
if (-d $dirname) {
processDIR($dirname);
} else {
if (inTypesArray($dirname)) { countLOC($dirname); }
}
# Output total line count.
print "\n[$dirname] Total Lines: $total_loc\n";
1;
#
# Recursively process directory.
#
sub processDIR() {
my ($dirname) = @_;
my $file;
opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
# Exclude "." and "..".
my @files = grep { !/^\.{1,2}$/ } readdir (DIR);
closedir(DIR);
#sort @files;
foreach (@files) {
$file = "$dirname/$_";
if (-d $file) {
processDIR($file); # Is directory. Recursion.
}
elsif (inTypesArray($file)) {
countLOC($file);
}
}
}
#
# Determine if this file is of specified type.
#
sub inTypesArray() {
my ($f) = @_;
my $t;
foreach $t (@types) {
if ($f =~ /$t$/) { return 1; }
}
return 0;
}
#
# Count number of lines in the file.
#
sub countLOC() {
my ($file) = @_;
my $loc = 0;
my @lines;
my $line_ct;
open(FILE, "$file");
while(<FILE>) {
@lines = split(/\r/, $_);
$line_ct = @lines;
#$loc ++;
$loc += $line_ct;
}
close(FILE);
print "[$file] Lines: $loc\n";
$total_loc += $loc;
}
Subscribe to:
Posts (Atom)
Blog Archive
-
▼
2026
(36)
-
▼
June
(19)
- C10K to C10M: from thread-per-connection model to ...
- Benchmark server performance
- Application server for php, python, java, node.js,...
- Application server for C++, Go and Rust
- Nginx as reverse proxy and load balancer
- Infrastructure running: nginx, apache, php, python...
- Flow chart of nginx+apache+uvcorn infrastructure
- Flow chart of apache+uvcorn infrastructure
- Uvicorn and Gunicorn
- What's deadsnakes PPA
- What's the optional lsb-core package
- Codex known logging bug
- Daemonsize a service
- Train text to image model, to generate images of c...
- Train a model based on OpenAI API
- Open port 8080 for WebSocket
- Add websocket support on Bluehost Ubuntu VPS for D...
- Install Claude Code on ubuntu VPS of Bluehost
- Install PostgreSQL on Mac
-
▼
June
(19)