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".
Saturday, December 12, 2009
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;
}
Thursday, November 12, 2009
Latex and paper preparation
IEEE - Author Digital Tool Box
Here there are templates in both Word and Latex formats.
Latex tips:
- Use \include to include a section would cause the included content to start on a new page. To avoid starting on a new page, use \input instead of \include.
- To install new x.sty file on linux: copy the file to /usr/share/texmf/tex/latex/x/x.sty, then run texhash. Sometimes one may also run texconfig. On Windows there is a GUI tool for updating the hash.
Here there are templates in both Word and Latex formats.
Latex tips:
- Use \include to include a section would cause the included content to start on a new page. To avoid starting on a new page, use \input instead of \include.
- To install new x.sty file on linux: copy the file to /usr/share/texmf/tex/latex/x/x.sty, then run texhash. Sometimes one may also run texconfig. On Windows there is a GUI tool for updating the hash.
Thursday, October 29, 2009
Wednesday, October 28, 2009
Linux admin notes
10/28/2009
- Install software on Unix/Linux
- ./configure, make, su, make install
- Redhat: rpm. Debian: apt-get. Mandrake: urpm. Fedora: yum. Slackware: . Gentoo: Emerge.
- Install binary (.BIN, .SH):
- Install package:
- Install software on Unix/Linux
- ./configure, make, su, make install
- Redhat: rpm. Debian: apt-get. Mandrake: urpm. Fedora: yum. Slackware: . Gentoo: Emerge.
- Install binary (.BIN, .SH):
- Install package:
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)