Category Archives: Coding

Using Python to replace spaces with underscores in filenames.

Python can be used on Window, Linux and Mac. It just a simple install.

download code

#!/usr/bin/python

import string
import os
import re

# task:
# loop thur input directory
# look for .pdf
# replace space with underscore
# rename/move to output directory

inputDir = "./" # Current directory
outputDir = "./new_location"

for filename in os.listdir(inputDir):
    if filename[-4:] == ".pdf":
        tempName = filename
        tempName = tempName.replace(' ', '_')
        os.rename(inputDir + "/" + filename, outputDir + "/" + tempName)

Microsoft Certified Professional Developer (MCPD)

How to earn your MCPD certification on Visual Studio 2008

Each MCPD certification on Visual Studio 2008 requires that you pass two to four Microsoft Certified Technology Specialist (MCTS) prerequisite exams and one Professional Series exam, as shown in the following table. When you pass all the exams in a specific MCPD path, you earn the related MCTS certifications as well as the relevant MCPD certification.

I will be focusing on this particular track: MCPD: ASP.NET Developer 3.5 so I’ll need to pass the following exams: 70-536, 70-562 and 70-564.

Exam 70-536: Microsoft® .NET Framework 2.0 Foundation

Just purchased a book to pass Exam 70-536.

MCTS Self-Paced Training Kit
MCTS Self-Paced Training Kit

Exam 70-562: TS: Microsoft .NET Framework 3.5, ASP.NET Application Development

Exam 70-564: PRO: Designing and Developing ASP.NET Applications Using Microsoft .NET Framework 3.5

Deprecated innerHTML

This is a JavaScript example of how to use the createTextNode instead of the deprecated innerHTML. There is also an example of how to use the removeChild function if the node you want to add to has child nodes.



php turns SQL to Excel

Thanks StarGeek for this code.

this php script will write data from php using text from an SQL table (MySQL, supply your own SQL query) to a microsoft excel (.xls) file. The Excel file is specified as such by a set of headers, defining content, using php’s header() function.

<?php
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell
//pear excel package has support for fonts and formulas etc.. more complicated
//this is good for quick table dumps (deliverables)

include(‘DB_connection.php’);
$result = mysql_query(‘select * from excel_test’, $linkID);
$count = mysql_num_fields($result);

for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($result, $i).“t”;
}

while($row = mysql_fetch_row($result)){
$line = ;
foreach(
$row as $value){
if(!isset(
$value) || $value == “”){
$value = “t”;
}else{
# important to escape any quotes to preserve them in the data.
$value = str_replace(‘”‘, ‘””‘, $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
$value = ‘”‘ . $value . ‘”‘ . “t”;
}
$line .= $value;
}
$data .= trim($line).“n”;
}
# this line is needed because returns embedded in the data have “r”
# and this looks like a “box character” in Excel
$data = str_replace(“r”, “”, $data);

# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == “”) {
$data = “nno matching records foundn”;
}

# This line will stream the file to the user rather than spray it across the screen
header(“Content-type: application/octet-stream”);

# replace excelfile.xls with whatever you want the filename to default to
header(“Content-Disposition: attachment; filename=excelfile.xls”);
header(“Pragma: no-cache”);
header(“Expires: 0”);

echo $header.“n”.$data;
?>