| |
Mystery Channel Communications
New York, NY
 |
|
| Internet Technology - Building the web - ** FREE Code snippets and helpful tips. ** |
INDEX:
+ HTML Starter File
+ PHP
+ FREE SCRIPT: Generate Time Option List
+ Tips and Tricks for PHP - Helpful Code Snippets
+ MySQL
+ Tips and Help for MySQL
+ Vote against software patents
 |
HTML Starter File
This is a simple HTML help file for beginners. Simply download the index.txt file. Follow the instructions that are written into the code. Then change the ".txt" to ".html" in the file name.
PHP
PHP is a all-purpose scripting language that is suited for Web development and can be embedded into HTML.
Installation materials can be obtained from:
Berkeley DB2 (Unix/Win) : http://www.sleepycat.com/.
Get a US mirror - download PHP
http://us2.php.net/get/php-5.0.5.tar.bz2/from/a/mirror
+ Tips and Tricks for PHP:
Resources: Zend Technologies, PHP.org, Ironpaper Design, and anonymous entries
+ How to resize and center an image:
<?
function miniatura ( $imagem , $l , $a ){
$tam = getimagesize ( $imagem );
$x = (( $tam [ 0 ]/ 2 )-( $l / 2 ));
$y = (( $tam [ 1 ]/ 2 )-( $a / 2 ));
$img = imagecreatefromjpeg ( $imagem );
if(( $l <= $tam [ 0 ])&&( $a <= $tam [ 1 ])){
$mini = imagecreate ( $l , $a );
imagecopyresized ( $mini , $img , 0 , 0 , $x , $y , $l , $a , $l , $a );
return imagejpeg ( $mini );
imagedestroy ( $mini );
}else{
return imagejpeg ( $img );
}
imagedestroy ( $img );
}
header ( "Content-type: image/jpeg" );
// imagem - local imagem
// l - largura final (width)
// a - altura fianl (height)
echo miniatura ( $imagem , $l , $a );
?>
+ Appying a screen to an image:
<?php
function screen ( & $im ) {
$imx = imagesx ( $im );
$imy = imagesy ( $im );
$black = imagecolorallocate ( $im , 0 , 0 , 0 );
for( $y = 1 ; $y <= $imy ; $y ++ ) {
for( $x = 1 ; $x <= $imx ; $x ++ ) {
if( ( $y % 2 ) && ( $x % 2 ) )
imagesetpixel ( $im , $x , $y , $black );
else if( !( $x % 2 ) )
imagesetpixel ( $im , $x , $y , $black );
}
}
}
?>
+ Bank ID Validator -
validates the supplied ABA number using a simple mod 10 check digit routine: <?php
function abavalidate ( $aba )
{
// First, check for 9 digits and non-numeric characters.
if ( ereg ( "^[0-9]{9}$" , $aba ))
{
$n = 0 ;
for ( $i = 0 ; $i < 9 ; $i += 3 )
{
$n += ( substr ( $aba , $i , 1 ) * 3 )
+ ( substr ( $aba , $i + 1 , 1 ) * 7 )
+ ( substr ( $aba , $i + 2 , 1 ));
}
// If the resulting sum is an even multiple of ten (but not zero),
// the aba routing number is good.
if ( $n != 0 && $n % 10 == 0 )
{
return( true ); // found good aba
}
else
{
return( false );
}
}
else
{
return( false );
}
}
?>
+ USPS
Shipping Calculator: <?php
class USPS {
var $server = "" ;
var $user = "" ;
var $pass = "" ;
var $service = "" ;
var $dest_zip ;
var $orig_zip ;
var $pounds ;
var $ounces ;
var $container = "None" ;
var $size = "REGULAR" ;
var $machinable ;
function setServer ( $server ) {
$this -> server = $server ;
}
function setUserName ( $user ) {
$this -> user = $user ;
}
function setPass ( $pass ) {
$this -> pass = $pass ;
}
function setService ( $service ) {
/* Must be: Express, Priority, or Parcel */
$this -> service = $service ;
}
function setDestZip ( $sending_zip ) {
/* Must be 5 digit zip (No extension) */
$this -> dest_zip = $sending_zip ;
}
function setOrigZip ( $orig_zip ) {
$this -> orig_zip = $orig_zip ;
}
function setWeight ( $pounds , $ounces = 0 ) {
/* Must weight less than 70 lbs. */
$this -> pounds = $pounds ;
$this -> ounces = $ounces ;
}
function setContainer ( $cont ) {
/*
Valid Containers
Package Name Description
Express Mail
None For someone using their own package
0-1093 Express Mail Box, 12.25 x 15.5 x
0-1094 Express Mail Tube, 36 x 6
EP13A Express Mail Cardboard Envelope, 12.5 x 9.5
EP13C Express Mail Tyvek Envelope, 12.5 x 15.5
EP13F Express Mail Flat Rate Envelope, 12.5 x 9.5
Priority Mail
None For someone using their own package
0-1095 Priority Mail Box, 12.25 x 15.5 x 3
0-1096 Priority Mail Video, 8.25 x 5.25 x 1.5
0-1097 Priority Mail Box, 11.25 x 14 x 2.25
0-1098 Priority Mail Tube, 6 x 38
EP14 Priority Mail Tyvek Envelope, 12.5 x 15.5
EP14F Priority Mail Flat Rate Envelope, 12.5 x 9.5
Parcel Post
None For someone using their own package
*/
$this -> container = $cont ;
}
function setSize ( $size ) {
/* Valid Sizes
Package Size Description Service(s) Available
Regular package length plus girth (84 inches or less) Parcel Post
Priority Mail
Express Mail
Large package length plus girth (more than 84 inches but Parcel Post
not more than 108 inches) Priority Mail
Express Mail
Oversize package length plus girth (more than 108 but Parcel Post
not more than 130 inches)
*/
$this -> size = $size ;
}
function setMachinable ( $mach ) {
/* Required for Parcel Post only, set to True or False */
$this -> machinable = $mach ;
}
function getPrice () {
// may need to urlencode xml portion
$str = $this -> server . "?API=Rate&XML=<RateRequest%20USERID="";
$str .= $this->user . ""%20PASSWORD="" . $this->pass . ""><Package%20ID=" 0 "><Service>" ;
$str .= $this -> service . "</Service><ZipOrigination>" . $this -> orig_zip . "</ZipOrigination>" ;
$str .= "<ZipDestination>" . $this -> dest_zip . "</ZipDestination>" ;
$str .= "<Pounds>" . $this -> pounds . "</Pounds><Ounces>" . $this -> ounces . "</Ounces>" ;
$str .= "<Container>" . $this -> container . "</Container><Size>" . $this -> size . "</Size>" ;
$str .= "<Machinable>" . $this -> machinable . "</Machinable></Package></RateRequest>" ;
$fp = fopen ( $str , "r" );
while(! feof ( $fp )){
$result = fgets ( $fp , 500 );
$body .= $result ;
}
fclose ( $fp );
# note: using split for systems with non-perl regex (don't know how to do it in sys v regex)
if (! ereg ( "Error" , $body )) {
$split = split ( "<Postage>" , $body );
$body = split ( "</Postage>" , $split [ 1 ]);
$price = $body [ 0 ];
return( $price );
} else {
return( false );
}
}
function trackPackage ( $ids ) {
$url = "$this->server?API=Track&XML=" ;
$xml = "<TrackRequest USERID=" $this -> user " PASSWORD=" $this -> pass ">" ;
for ( $i = 0 ; $i < count ( $ids ); $i ++) {
$id = $ids [ $i ];
$xml .= "<TrackID ID='$id'></TrackID>" ;
}
$xml .= "</TrackRequest>" ;
$xml = urlencode ( $xml );
$url = $url . $xml ;
$fp = fopen ( $url , "r" );
while (! feof ( $fp )) {
$str .= fread ( $fp , 80 );
}
fclose ( $fp );
$cnt = 0 ;
$text = split ( "<TrackInfo ID=" , $str );
for ( $i = 0 ; $i < count ( $text ); $i ++) {
if ( ereg ( "<TrackSummary>(.+)</TrackSummary>" , $text [ $i ], $regs )) {
$values [ "eta" ] = $regs [ 1 ];
if ( eregi ( "delivered" , $values [ "eta" ])) {
$values [ "eta" ] = "Delivered" ;
} else {
$values [ "eta" ] = "In Transit" ;
}
$cnt ++;
}
}
$values [ "type" ] = "Priority Mail" ;
return $values ;
}
}
?>
|
| Generate Time Option List - FOR - Select statement |
|
+ MySQL
The World's Most Popular Database. Open source database.
http://dev.mysql.com/tech-resources/ News:
+
MySQL 5 is on its way! -- And .. to test this new candidate, prizes will be given for bug finders and blog writers!
Tips and Help:
+ SQL Injection
SQL injection is a common form of hacking a website or preying on a vulnerability of a website. This form of hacking attacks the database directly. SQL injection can happen if the website's functionality does not include adequate text validation code. SQL inject happens when unsuitable data is executed by the database--this allows the hacker to access the database and manipulate it.
|
+ Vote Against Software Patents
Basically patenting software would hurt development, because it allows only large corporations to deal with the ongoing issues of an ever changing world of discovery and innovation. In addition, it would slow down the rate of discovery and innovation to the terms of the patent, which is currently a 20 year span ( even a one year span would prove harmful to innovation of emerging technologies ). If you look at the case of MySQL and other open-source structures, innovation through an open scientific community has excelled far beyond the scope of privatized development, an example of which is Microsoft's MSSQL.
Express yourself -- Vote Now >>>>>>> |
| |
|