Site Sponsors:
Easier Hourly Rate Calculation - 2012 
I had a few moments today to update the "Reasonable Rate Calculator."

http://soft9000.com/CalcYouLater/

Note that we kept the PHP version in there for those who do not have Java.


Enjoy,

-Rn

[ view entry ] ( 6843 views )   |  permalink  |  related link
Easy Backgrounds for Android 
I have developed a great respect for the developers of the Android Graphics Framework. Why? Because it is obvious that the developers like to use their classes, themselves.

It's Ragu!


Indeed, from doing complex things like affine transforms, to even simple things like measuring a Canvas or a Bitmap, Android has the data we need, when-we-need-it. -From splits to splines, it all seems to be "in there"! (The Company that makes Ragu Spaghetti Sauce had a commercial a few years back - many take the expression it's ragu to mean ''it's in there''!)

Vista


Such was thee case of having what we needed "in there" when we set our paws to spruce-up a little ditty we wrote for the Android Marketplace. When it came time to spread a tile image all over a background, we had what we needed. -So much so that we feel confident that what we wrote will be able to work across hand-held devices of infinite screen size. All because members are ragu, where & when they should be... and more:

public void draw(Canvas can) {
if (bmpBack != null) {
PixelCellMap map = new PixelCellMap(can.getWidth(), can.getHeight(), bmpBack.getWidth(), bmpBack.getHeight());
int iCells = map.getCellCount();
for (int ss = 0; ss < iCells; ss++) {
Point pt = map.getActual(ss);
can.drawBitmap(bmpBack, pt.x, pt.y, paintPaper);
}
} else {
can.drawColor(paintPaper.getColor());
}
}

Note that the PixelCellMap class is part of a forthcoming Open Source Toolkit. One we are creating for cross-platform Android / Swing / AWT portability. -If you want to learn more about it (the code-named for the graphical part of the framework is Vista (sorry - but that moniker just made the most sense at the moment)), then give us a holler.


[ view entry ] ( 2412 views )   |  permalink  |  related link
New Pascal Strings for PHP 
New Pascal: We use it in Java, .Net, and C/C++ - I even used them in the 118,000 recipes we have on this site.

Now is the time to share!

New Pascal Strings


Perfect for when we need to quickly index / save large "heaps" of textual data - or when we need to communicate between just about any other programming languages - we believe that the New Pascal String convention is both obvious, & simple. -So simple that we wrapped the convention up into a PHP class:


<?php
/**
* An opportunity to encapsulate the reading & writing of New Pascal Strings.
* Designed to work with my other "New Pascal Strings" readers and writers
* for Java, C/C++, and .NET.
*/
class IOPascal {

/**
* Properly open a file for cross-platform string-reading.
* @param type $file The file to read.
* @return type The file handle will be FALSE on error.
*/
public static function OpenRead($file) {
$hfile = fopen($file, 'rb');
return $hfile;
}

/**
* Properly open a file for cross-platform string-writing.
* @param type $file The file to write.
* @return type The file handle will be FALSE on error.
*/
public static function OpenAppend($file) {
$hfile = fopen($file, 'a+b');
return $hfile;
}

/**
* Read a Pascal String, as written by this, or a legacy, Pascal String writer.
* @param type $handle The handle of a file to read-from. (see <i>OpenRead</i>)
* @return type The string, as read from the file.
*/
public static function ReadString($handle) {
$char = '-';
while ($char != ' ') {
if (feof($handle))
return null;
$char = fgetc($handle);
if ($char == ' ')
continue;
$len = $len . $char;
}
if ($len)
$string = fread($handle, $len);
return $string;
}

/**
* Write a string to the file for reading by this, or a legacy. Pascal String reader.
* @param type $handle The handle of a file to write-to. (see <i>OpenAppend</i>)
* @param type $string The stirng, as destined to write-to a file.
* @return type Returns the size of the string as written to the file, else FALSE on error / partial write.
*/
public static function WriteString($handle, $string) {
$len = strlen($string);
$len = fwrite($handle, $len);
if($len == false)
return $len;
$len = fwrite($handle, ' ');
if($len == false)
return $len;
return fwrite($handle, $string);
}

}
?>


So when you feel the need to put a simple cross-tech count in front of a string - and when you do not want the newlines to stomp all over your activities - free free to use IOPascal.

Here is the test case:

<?php

include_once 'IOPascal.php';

echo '<h1>IOPascalTest.php</h1>';

$file = 'IOPascal.tmp';
$tstx = new IOPascal;

$test = 'If you can read this, then all is well';

unlink($file);
$hand = $tstx->OpenAppend($file);
if ($hand == false) {
echo 'Error 0: Access Permission Failure.';
exit(1);
}
$pos = $tstx->WriteString($hand, $test);
fclose($hand);

if ($pos != strlen($test)) {
echo 'Error 100: Basic read error.';
exit(1);
} else {
$hand = $tstx->OpenRead($file);
if ($hand == false) {
echo 'Error 101: Open Error.';
exit(1);
}
$result = $tstx->ReadString($hand);
fclose($hand);

if (strcmp($result, $test) != 0) {
echo 'Error 102: IO result mis-match?';
exit(1);
} else {
unlink($file);
$hand = $tstx->OpenAppend($file);
if ($hand == false)
echo 'Error 103<br>\n';
else {
$stuff = array('One', 'Two', '', "F\rour", "\nFive\r\n", 'Six');
foreach ($stuff as $str) {
$pos = $tstx->WriteString($hand, $str);
}
fclose($hand);
$hand = $tstx->OpenRead($file);
foreach ($stuff as $str) {
$input = $tstx->ReadString($hand);
if (strcmp($str, $input) != 0) {
echo "Error 104: Unable to read [$str]<br>";
exit(1);
} else {
echo "Okay [$str]<br>";
}
}
fclose($hand);
unlink($file);
echo 'Success.<br>';
exit(0);
}
}
}
?>


Enjoy,

-Rn


[ view entry ] ( 2235 views )   |  permalink  |  related link

<<First <Back | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | Next> Last>>