Java provides multiple Text Formatting classes to enable easy conversion of integers, decimals, floats, and etc into Strings. The DecimalFormat class enables the formatting of Floats and Decimals and can be used to easily display percentages and currency amounts.
Example:
Converting a Float into Dollars formatted String
import java.text.DecimalFormat;
...
float amount = 100453.23f;
DecimalFormat dollarFormat = new DecimalFormat( "$#,##0.0#" );
System.out.println( dollarFormat.format( amount ) );
Resources:
Decimal to Dollars, DecimalFormal, Dollars, Float to Dollars
When writing SQL we may find that we need to write a WHERE clause that checks if a columns is not a certain value. To do this we have the <> operator that means does not equal. However you may be surprised that you are not getting all the results you expected, this is because <> does not match null values. To get all values that are not equal you need to check that a value is not equal or that it is null.
Examples SQL
SELECT * FROM CLIENT
WHERE SENSITIVE <> 'Y' or SENSITIVE IS null
not equal, not null, SYBASE, Transact-SQL
New Version released ! Get it Here.
I’ve been making enhancements since the initial release of the PHP Wrapper Library for the Harvest API, that I first released a week ago in my entry PHP Wrapper Library for the Harvest API. This 0.2 version of the wrapper library contains bug fixes for some issues that Jesse Mortenson of Supermega Design found, as well as implementation of the full API for Projects, Clients, and Client Contacts. Create and Delete functionality has been included for all other Harvest Objects but is currently untested.
Example Setup
- Require the HarvestAPI main class
require_once( dirname(__FILE__) . '/HarvestAPI.php' );
- Register the Auto Loader
spl_autoload_register(array('HarvestAPI', 'autoload') );
- Set Account & User information
$api = new HarvestAPI();
$api->setUser( "user@email.com" );
$api->setPassword( "password" );
$api->setAccount( "account" );
Example: Create a new Client
- Initialize and populate your Client Object
$client = new Harvest_Client();
$client->set( "name", "New Client" );
$client->set( "details", "Our new Client" );
- Call create method
$result = $api->createClient( $client );
- Check if request was successfull
if( $result->isSuccess() ) {
...
}
- If successful you will be returned the new Client’s Harvest ID
$client_id = $result->data;
Example: Toggle a Projects active state
- Call toggle method with the Project’s Harvest ID
$result = $api->toggleProject( $project_id );
- Check if request was successfull
if( $result->isSuccess() ) {
...
}
Contact
If you encounter bugs, or issues with the library please contact me with the details. I hope that you will find this useful and if you do feel free to leave a comment.
Download
Resources
API Wrapper, Harvest, Harvest API, PHP Library
You may find that when developing Select queries for an Application that you may want to dynamically limit the results returned from a Stored Procedure. Upon first inspection you may think oh lets use a TOP clause with a limit variable passed in when the stored procedure is called.
CREATE PROCEDURE getROWS
@LIMIT INT
AS
BEGIN
SELECT TOP @LIMIT *
FROM TABLE
ORDER BY modTS DESC
END
GO
Unfortunately Sybase T-SQL does not allow variables in the limit clause. Don’t worry though the ROWCOUNT variable can be paramaterized. This gives us the following procedure that limits the results returned to our desired amount.
CREATE PROCEDURE getROWS
@LIMIT INT
AS
BEGIN
SET ROWCOUNT @LIMIT
SELECT *
FROM TABLE
ORDER BY modTS DESC
SET ROWCOUNT 0
END
GO
That is all there is to it, simply remember to use a ROWCOUNT statement instead of a TOP clause in your stored procedures.
ROWCOUNT, TOP clause, Transact-SQL
When working in a unix environment you may find the need to compare the contents of 2 files. To do this unix provides the diff command. The diff command takes 2 files as an argument and outputs the differences between them in a simple easy to understand format using a simple change notation using numbers and the c d a and , characters.
How to run the diff command
Running the diff command is done by typing diff followed by the 2 files to be compared.
diff file1.txt file2.txt
diff file1.txt updates/file2.txt
Understand the output
The diff command outputs the difference found in the file or nothing if there are no differences. The basic syntax is that a reference line will be outputted dictating the lines affected and the type of change followed by the contents of the files for the differing lines.
The type of change is coded by the character between the line references. Where:
- c: item changed
- d: item was deleted
- a: item was added
To the left of the code character is denoted the line numbers present in the first file and to the right is the line numbers in the second file. For example
- 1c1
Means the first line differs between the two files
- 8d7
Means that line 8 of file one was deleted from file 2 and it would have been present after line 7
- 9a9
Means that line 9 of file two was added and would be present after line 9 in file one
- 2,4c3,5
Means that there was a multi-line change where lines 2-4 in the first file where changed to the value in lines 3-5 of the second file.
In addition to the codes that explain the differences the lines that are different are also outputted and follow the codes. A < character before teh output means first file and > character means second file. When output is shown for both files in the case of a change — will separate the output of their content. For example
2,4c2,4
< bbb
< ccc
< ddd
---
> bcd
> cde
> def
compare text, diff