Wednesday, February 08, 2006

HTML: Remove Margins from web pages

Sometimes making a webpage can be frusterating. You make a table with width and height of 100% for positioning and it still doesn't fill up the whole webpage why? Margins.

Don't forget to set margins in your body tag.

<html>
<
head>
<
title>webpage title</title>
<
/head>

<
body bgcolor="#ffffff" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<
/body>
<
/html>


with CSS:
<style type="text/css">
body
{
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
</style>

Tuesday, January 31, 2006

LINUX: SUSE + APACHE2 + PHP + MYSQL + ODBC

SUSE + APACHE2 + MYSQL + PHP + ODBC = SAMPO

SAMPO is a type of LAMP install. The acronmym LAMP comes from Linux + Apache + Mysql + PHP.

I wrote this a while ago while consulting for a company with SAMPO needs. The goal was to host a php website on a linux webserver while the data was hosted on a windows mysql server. Only step 7 is specific to that where you end up pointing to the windows server across the network. Optional points in step 4 are specific to the client I was doing this for.
----------------------------
Meant to be included are a number of files:
testfile.html [inline at end]
phptest.php [inline at end]
mysqltest.php [inline at end]
myodbctest.php [inline at end]
odbc.ini [inline at end]
odbcinst.ini [inline at end]
MyODBC-3.51.11-2.i586.rpm [click to download]

Note:
A. Your linux machine's assumed IP Address is 192.168.0.2
B. commands to be typed at the command prompt start with 'command:' (some may need to be done as root)

1. Install Suse Linux 9.3
-In the screen labelled 'Installation Settings', click on 'Software'
-Make sure you select Standard System w/ KDE
-In the top-left of the screen, under Filter, select 'Search'
-Search and make sure all of the following packages have been selected
-apache2
-apache2-mod_php4
-apache2-prefork
-php4
-php4-bz2
-php4-curl
-php4-ftp
-php4-gd
-php4-mcrypt
-php4-mysql
-php4-session
-php4-unixODBC
-php4-zlib
-mysql
-mysql-client
-mysql-shared
-unixODBC
-openssl
-bison
-libxml2
-readline
-flex


2. Enable apache2 and mysql services
-After booting your system, go to
-Linux 'Start' Menu > System > Yast > Network Services > HTTP Server
-configure the http server
-Linux 'Start' Menu > System > Yast > System > System Services
-enable mysql and apache2 (now they will start when the machine reboots)

3. Test apache2
-Copy testfile.html to /srv/www/htdocs
-test it by viewing http://192.168.0.2/testfile.html

4. Test php
-edit php.ini
-set register_globals to On [optional]
-set display_errors to Off [optional]
-restart web server to apply php changes
-command: rcapache2 restart
-Copy phptest.php to /srv/www/htdocs
-test it by viewing http://192.168.0.2/phptest.php
-ensure phptest.php display information about mcrypt, odbc, and mysql

5. Setup mysql locally (not required but good to test mysql connectivity locally before testing it over the network)
-set mysql root password (below, change 'mysqlrootpassword' to your root password preserving quotes)
-command: /usr/bin/mysqladmin -u root password 'mysqlrootpassword'
-go into mysql and execute the following commands
-command: mysql -u root -p
create database testdb;
use testdb;
create table testtable (item_id char(10), item_desc char(100));
insert into testtable values ('001','This is test data 1');
insert into testtable values ('002','This is test data 2');
select * from testtable;
exit;

-Copy mysqltest.php to /srv/www/htdocs
-modify mysqltest.php to contain a reference to the mysql user and password that you setup (can be root)
-test it by viewing http://192.168.0.2/mysqltest.php

6. Setup unixODBC (best to test with database created in step 5)
-install MyODBC-3.51.11-2.i586.rpm
-as root, command: rpm -iv MyODBC-3.51.11-2.i586.rpm
-Copy odbc.ini and odbcinst.ini to /etc/unixODBC
-modify odbc.ini to contain a reference to the mysql user and password that you setup (can be root)
-test with isql (obviously modify mysqluser and mysqluserpassword to point to the user you setup)
-command: isql testdb mysqluser mysqluserpassword
-Copy myodbctest.php to /srv/www/htdocs
-modify myodbctest.php to contain a reference to the mysql user and password that you setup (can be root)
-test it by viewing http://192.168.0.2/myodbctest.php
-if it doesn't work go to the fix on 6a.

6a. unixODBC fix
-as root (su) execute the following commands at the shell:
-command: cd /usr/lib/php/extensions
-command: sed -i -e 's/libc.so.6/xxodbc.so/' unixODBC.so
-command: cd /usr/lib
-command: ln -s libodbc.so xxodbc.so
-command: rcapache2 restart
6a source: http://susewiki.org/index.php?title=PHP4_ODBC

7. Point to final distination
Now that you have a server with Suse + Apache + PHP + Mysql + unixODBC + MyODBC setup,
-setup odbc.ini and odbcinst.ini to point to a windows mysql server over the LAN
-you may have to open a hole in the windows mysql server firewall at port 3306 to allow mysql connections through

======================================
ATTACHED FILES
======================================
testfile.html
If you can see this in <b>bold</b> your
http server is working.


phptest.php
<? echo phpinfo(); ?>



mysqltest.php
<?php
echo "just checking";
$link = mysql_connect('localhost', 'root', 'r00tpwd') or
die('not connect');

echo "\ngood connect";

mysql_select_db('testdb') or ('not select db');

$query = 'SELECT * from testtable';
$result = mysql_query($query) or die('Query failed');

while($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print_r($line);
}

mysql_free_result($result);

mysql_close($link);
?>



myodbctest.php
<?php echo "just checking";
$conn = odbc_connect('mysqltest', 'root', 'r00tpwd')
or die('error connecting');

echo 'connected successfully';

$sql = "select * from testtable";
$rs = odbc_exec($conn, $sql);
while(odbc_fetch_row($rs))
{
$f1 = odbc_result($rs, 1);
$f2 = odbc_result($rs, 2);

echo "
QUERY RESULTS:" .$f1." ".$f2;
}

?>


odbc.ini
[mysqltest]
Description = MySQL ODBC Database
Driver = MyODBC
Server = localhost
Database = testdb
#Port =
#Socket =
#Opinion =
#Stmt =


odbcinst.ini
[MyODBC]
Description = MySQL ODBC 3.51 Driver DSN
Driver = /usr/lib/libmyodbc3.so
Trace = Off
TraceFile = stderr

[MySQL ODBC 3.51 Driver]
DRIVER = /usr/lib/libmyodbc3.so
SETUP = /usr/lib/libmyodbc3S.so
UsageCount = 1

Thursday, January 26, 2006

INSTALL: Installing CURL for PHP (win32)

Assumptions:
PHP folder is C:\PHP
extension folder is C:\PHP\ext
php.ini found in C:\WINDOWS
system32 is C:\WINDOWS\SYSTEM32
web folder is C:\Apache2\htdocs


1. Create a phpinfo.php file in C:\Apache2\htdocs
2. Write <?php echo phpinfo(); ?> as the text of the file phpinfo.php
3. Verify it works: http://localhost/phpinfo.php (should display readonly php.ini in a table). *This confirms that http server works and php is installed
4. At the DOS/Command Prompt type echo %PATH% to view the current path
5. Put C:\PHP and C:\PHP\ext in your path: Go to My Computer->Advanced->Environment Variables->System Variables, and add C:\PHP;C:\PHP\ext; to the end of your path
6. Download the php .zip archive (with all the extensions in it) that corresponds to your version of php and extract libeay32.dll and ssleay32.dll
7. Put libeay32.dll and ssleay32.dll in your C:\WINDOWS\SYSTEM32 folder
8. Verify php_curl.dll is found in your C:\PHP\ext folder
9. Modify C:\WINDOWS\php.ini
- remove semi-colon from line ;php_curl.dll
- in php.ini, verify that extensions_dir = "C:\PHP\ext"
10. Restart HTTP service if you can't tell it worked.
- Start->Control Panel->Administrative Tools->Services
- right click Apache or HTTP or IIS and select restart
11. Verify by checking http://localhost/phpinfo.php
- Curl should have its own spot

Troubleshooting:
If you get the error...
PHP Warning: Unable to load dynamic library 'C:\PHP\ext\php_curl.dll' - The specified module could not be found. in Unknown on line 0
... at the bottom of your http://localhost/phpinfo.php or at the bottom of any php script, then verify that you followed all the steps.

Also, verify that the php.ini you made changes to is the same one that http://localhost/phpinfo.php displays in the fifth (or so) row down under
"Configuration File (php.ini) Path"

Also, verify that you clicked [Apply] or [OK] after step 5

Keep trying stuff until it works.

Thursday, December 29, 2005

CRYSTAL: EOleSyserror Exception - Class Not Registered

In the Windows environment DLLs consist of two things, classes (blueprints that objects are made from) and functions.

Windows provides a way to register a DLL using C:\WINDOWS\SYSTEM32\REGSVR32.EXE. As I understand it, this makes the classes and functions in that DLL available for use.

Recently I was faced with a problem where there was a delphi application which used Crystal Reports 9.0 which when it was ran on a non-developer machine gave an error: EOleSyserror Exception - Class Not Registered. I did some research and found that the application used the classes CRAXDRT_LIB, OleServer, and OleCtrls. My research also told me that Crystal Reports runtime uses ActiveX Controls and components. I went to the a help pdf on businessobjects.com and found a number of DLLs.

I eventually found that I could fix the problem with the following steps:
1. Find crviewer9.dll on a machine that has crystal reports installed.
2. Copy it into a folder like C:\WINDOWS\SYSTEM32
3. In the Windows Start Menu go to "Run".
4. type "cmd" at the prompt and click Ok.
5. type "C:\WINDOWS\SYSTEM32\REGSVR32.EXE C:\WINDOWS\SYSTEM32\crviewer9.dll"

Solved.

Friday, December 09, 2005

PHP: Hide Progress Bar After Page Fully Loaded

How do you show a progress bar when something has partially loaded, and get rid of it on the same page when it is done loading?

<?php
echo "<div id='a'><center>Processing Data<br>";
echo "<img src='http://www2.bulkregister.com/images/progressbar.gif'">;
echo "</center></div>";
flush();
sleep(5);//do real work or just sleep (for testing)
echo "Afterwords: <br>";
$js="'document.getElementById(\"a\").style.display=\"none\"'";
echo "<img src='http://www.cwts.nl/ed/buttons/completed.gif'
onload='$js'>"
;
?>

Thursday, November 17, 2005

HUMOR: Switch to Linux Cartoon

http://www.ubergeek.tv/article.php?pid=54 has a nice flash cartoon advertising the benefits of linux.

For the true geek/nerd in all of us.

Monday, November 14, 2005

REG: Remove Dangling Shared Folders in XP

Problem:
On my local area network (LAN) in windows, I had shared a folder, then deleted it. From another machine, it still shows that the folder is shared, yet is inaccessible, how can I remove it?

Solution:
Windows settings are in the registry editor. This includes shared folders which are just keys in the registry.

In Windows, in your Start Menu, click on [Run], type "regedit" and click OK. Using the registry key below, you can find your a registry entry for your shared folder. Remove the registry entry/key with your shared folder's name and it will remove the shared folder.

HKEY_LOCAL_MACHINE
\SYSTEM
\ControlSet001
\Services
\lanmanserver
\Shares

Tuesday, November 08, 2005

REG: Missing System Tray Icons in Windows XP

If you google the topic you will find this link:
http://www.techzonez.com/forums/archive/index.php/t-16911.html

It looks all professional, but it isn't actually helpful.

The cause of the problem for me was when I was setting automatic login on my laptop to true (with a password), then later going in and disabling the automatic login.

I did however find a solution.

In your registry editor, search for keys named "NoTrayItemsDisplay", and delete them.
ie:

HKEY_LOCAL_MACHINE
\SOFTWARE
\Microsoft
\Windows
\CurrentVersion
\Policies
\Explorer
"NoTrayItemsDisplay"=dword:00000000

or

HKEY_CURRENT_USER
\SOFTWARE
\Microsoft
\Windows
\CurrentVersion
\Policies
\Explorer
"NoTrayItemsDisplay"=binary:00000000


source: http://www.techzonez.com/forums/archive/index.php/t-16911.html

Wednesday, October 26, 2005

SQL: Migrating MySQL scripts to MS SQL

I had some database table creation scripts to migrate from MySQL to MS SQL.

Primary Key:
MySQL allows a primary key on the either of NULL, and NOT NULL declarations.
MSSQL only allows primary keys on fields that are NOT NULL

Date Fields:
MySQL uses a DATE field
MSSQL uses a DATETIME field

Table Creation with AutoIncrement:
MySQL uses keyword AUTO_INCREMENT
example:
CREATE TABLE mytable (
myfield1 integer(12) NOT NULL AUTO_INCREMENT,
myfield2 CHAR(9) NULL,
myfield3 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);


MSSQL uses keyword IDENTITY(1,1)
example:
CREATE TABLE mytable (
myfield1 int IDENTITY(1,1) NOT NULL,
myfield2 CHAR(9) NULL,
myfield3 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);


Create Table 'IF NOT EXISTS'
MySQL uses keywords IF NOT EXISTS
example:
CREATE TABLE IF NOT EXISTS mytable (
myfield1 CHAR(9) NOT NULL,
myfield2 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);


MSSQL uses a query into a system table
example:
IF NOT EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mytable')
CREATE TABLE mytable (
myfield1 CHAR(9) NOT NULL,
myfield1 CHAR(6) NULL,
PRIMARY KEY(myfield1)
);


More information on autoincrement fields in MSSQL can be found at
an article on http://www.databasejournal.com

HUMOR: Anti- telemarketer Strategy (Counterscript)

http://www.xs4all.nl/~egbg/counterscript.html

A script to use vs. telemarketers calling to harrass you.

Monday, October 24, 2005

CSS: Force a Fixed Width HTML Webpage

Cross-browser content layout fix for variable-length content using CSS

BACKGROUND:
Firefox browser page has no vertical scrollbar unless the content exceeds the browser window height. IE always has a vertical scrollbar, it is merely greyed out when the content doesn't exceed the browser window height.

PROBLEM:
This can be a problem if you have some centered content in pages with the same layout but some content fits in the browser window and on other pages the content is taller than the window. Navigating from one page to the other appears as if the centered content is misaligned.

SOLUTION:
Include this stylesheet in your html code of the webpage to force a scrollbar even when its not necessary, for regular width pages.

<style type="text/css">
html { height: 100.1%; }

</style>

Friday, October 21, 2005

JAVASCRIPT: Make a pop up window

The following HTML code:

<form><input type=button value="Open new window"
onClick="myRef = window.open(self.location,'mywin',
'left=20,top=20,width=800,height=500,toolbar=1,
resizable=0');myRef.focus()"
></form>


Generates this:

Friday, October 14, 2005

COBOL: EBCDIC File Formats

I had some file formats I had to import into a database for work and it was in a strange format I had never seen before.

05 RECORD1-RAW                          PIC X(17).
05 RECORD1-AREA REDEFINES RECORD1-RAW
10 REC2-RAW PIC 9(9).
10 REC2-AREA REDEFINES REC2-RAW
15 REC3-F1 PIC X(3).
15 REC3-F2 PIC X(2).
15 REC3-F3 PIC X(4).
10 REC2-FOOTER PIC S9(6)V99.


I saw the word EBCDIC, and I was clued in that I was not using ASCII. I read somewhere that Mac still uses EBCDIC.

http://www.natural-innovations.com/computing/asciiebcdic.html is Google's top link for EBCDIC. But here is a cleaner looking table comparing ascii and ebcdic: http://www.simotime.com/asc2ebc1.htm

Wikipedia's link: http://en.wikipedia.org/wiki/EBCDIC

But what finally helped was when I found: http://www.discinterchange.com/reading_COBOL_layouts_.html

and then used http://www.discinterchange.com/TechTalk_signed_fields_.html to figure out signed fields like above.

Monday, October 03, 2005

APP: Backup DVDs to your hard drive (like ripping CDs)

After you've ripped you CD collection to your hard drive so you can listen to them whenever you want, you realize you have this hefty DVD collection and you wouldn't mind ripping this onto your hard drive. But DVDs don't have to take up a ton of space on your hard drive, just like audio CDs don't have to take up 700MB per CD.

Most DVDs for sale in North America are NTSC set at 720x480 resolution and can take up to 9.4 GB on a dual layer DVD, but with DivX or Xvid compression you can backup a DVD onto your computer to sizes between 700MB and 1400MB without significant quality loss.

Make a DVD Backup/How to rip the DVD

Download and install
DVD Decrypter and Auto Gordian Knot

Copy to Computer
Use DVD Decrypter to copy the DVD files to you computer's hard drive (minus encryption). These often take around 6-8GB but you can erase them when you're done.

Compress
Next, run AutoGK. Select the decoded DVD files on your computer. Select an output .avi file. Additionally, AutoGK allows you to choose the file size of your output file, in case you want to compress and back it up onto a CD or other media.

AutoGK is a front-end programs which actually runs a few other programs in the background to perform different tasks in video compression like audio compression, and codec specific tasks etc.

Play it
Now to play the .avi file in windows, all you need is something like Winamp 5.1 installed with video support(or windows media player if you must).

Housekeeping
Now, don't forget to erase the files generated by DVD Decryptor, once you have the output .avi file and you've test it and it works. These files take up a 6-8GB normally, so you really out to clear them off before doing another disc.

Saturday, October 01, 2005

APP: Make PDFs from any document (Windows)

PDF Creator an open source project is a great way to create PDFs for free.

A PDF is a platform independent document with fixed formatting, and once created, it cannot be edited, making it excellent for copyrighted material.

Install it, and it will create a new 'printer'. To create a PDF of a document, go to print the document, and select PDFCreator as the printer. When it goes to print it will ask you where you want to save the PDF.

SourceForge.Net Project site:
http://sourceforge.net/projects/pdfcreator

Wednesday, September 28, 2005

RSS: Add RSS feed as a Bookmark in Firefox

You can add this blog as a Live Bookmark in Firefox.

What is a Live Bookmark? It is a folder of bookmarks, where each bookmark is a link to an article or posting in the RSS feed. It can be added to your Bookmarks Toolbar folder in Mozilla so you can skip bookmark menus.

Go to: Bookmarks > Manage Bookmarks
Now go to: File > New Live Bookmark...
Feed Location: http://whitemarker.blogspot.com/atom.xml

Now under Manage Bookmarks, drag and drop it into your Personal Toolbar folder or Bookmarks Toolbar folder.

OPINION: Blu-ray or HD-DVD

The epic battle of good versus evil is only eclipsed by the epic battle between good and good. Two new technologies, HD-DVD and Blu-Ray are both determined to be the next video standard. Part of the problem is that the entertainment industry is totally split on the issue with major heavyweights of the industry on each side. Recently, Microsoft and Intel have taken sides. In terms of single layer capacity, HD-DVD has 15GB compared with Blu-Ray at 25GB. Additionally, Blu-Ray is also more expensive to mass produce. A main concern of consumers seems to be the DVD compatibility issue, but both sides have said they will offer video content in DVD format on one side and their format on the other.

The war to become the next big standard is reminiscent of the VHS-Beta war of the 70s and 80s. Some important lessons we can learn from the past, are that the best technology won't necessarily prevail, and that production costs are a significant factor. Both of these reasons point away from Blu-ray but it doesn't matter anyway. Other than the ability to record HD-TV, there is no other driving force for adopting a new disc technology. HD-TV has a few more years before it is widely accepted, and current DVDs are so cheap to produce that they will be used in place of a higher standard for years. HD-DVD is only 3 times the size of current DVDs, which isn't big enough for people to make the move. When it comes down to it though, there is one trick that VHS and Betamax could never do: Offer a disc with HD-TV on one side and Blu-ray on the other.

Tuesday, September 27, 2005

REG: Remove WMP Explorer Shell Extensions

HARD WAY:
Remove Windows Media Player (WMP) Explorer Shell Extensions From the Context Menu

Go into your registry editor, and remove the following keys to remove "Add to Playlist" from your context menu for video files.

This may also be done for:
Add to Now Playing List
Add to Sync List
Add to Burn List
Play on My TV

;Remove Add to Now Playing List and Add to Playlist for WMV files
[HKEY_CLASSES_ROOT\WMVFile\shellex\ContextMenuHandlers\WMPAddToPlaylist]

;Remove Add to Now Playing List and Add to Playlist for MPEG AND MPG Files
[HKEY_CLASSES_ROOT\mpegfile\shellex\ContextMenuHandlers\WMPAddToPlaylist]

;Remove Add to Now Playing List and Add to Playlist for ASF Files
[HKEY_CLASSES_ROOT\ASFFile\shellex\ContextMenuHandlers\WMPAddToPlaylist]

;Remove Add to Now Playing List and Add to Playlist for Avi Files
[HKEY_CLASSES_ROOT\AVIFile\shellex\ContextMenuHandlers\WMPAddToPlaylist]

;This key also needs to be removed along with any of the 4 keys above
;It is found in HKEY_CLASSES_ROOT
[...root\SystemFileAssociations\video\shellex\ContextMenuHandlers\WMPAddToPlaylist]


You can do the same for audio files.

EASY WAY:
download ShellExView and disable WMP extensions.

Friday, September 23, 2005

APP: Bart's Preinstalled Environment

I included a link to Bart's Preinstalled Environment
http://www.nu2.nu/pebuilder/
because it looks like a pretty good tool for sysadmins. The tom's hardware article says that you can load it onto a 256 meg USB drive, and boot into it that way.


http://www.tomshardware.com/howto/20050909/index.html


This is a useful tool if you want to boot into a windows type environment from a CD or USB drive. (if you are a top secret guy using a public computer and you want no traces left behind).

Also check out portableapps.com

Thursday, September 22, 2005

CSS: Hide blocks of a webpage when printing

When printing a webpage, how do you hide certain elements of the page?

There is no onprint action in Javascript that I am aware of.

The key is to use css:

Note: In css '#' denotes an ID selector, '.' denotes a class selector.
<style type="text/css">
@media print
{
div.headerbox{ display:none; }
}
</style>

<
div class="headerbox">...
hidden when printed</div>
<
div class="otherbox">...
not hidden when printed</div>

or

<style type="text/css">
@media print
{
div#headerbox{ display:none; }
}
</style>

<
div id="headerbox">... hidden when printed</div>
<
div id="otherbox">... not hidden when printed</div>