Posts

Showing posts from April, 2011

Binding a List of Objects to a GridView in VB.NET

Setting a gridview to a list of objects in this instance we define a class TestResult to hold a list of TestResult, This class will hold a list of results for tests carried out on a  specific date.

We want to bind this to a gridview called  GridView_TestResults1 dynamically.

To do this in your web form add the GridView_TestResults1 and set AutoGenerateColumns to True.

Create a class TestResult add add this code

Public Class TestResult
      Private test_id As String
      Private test_date As DateTime
      Private test_result As String

      Public Property TestID() As String
            Get
                  Return test_id
            End Get
            Set(ByVal value As String)
                  test_id = value
            End Set
      End Property

      Public Property TestDate() As DateTime
            Get
                  Return test_date
            End Get
            Set(ByVal value As DateTime)
                  test_date = value
            End Set
      End Property

  …

Adding JSON Support to PHP on your CentOS LAMP Installation

Before you begin start by making sure you have everything up to date by running
$--> yum update
or
$--> yum update "*php*"

The first command will update all components to the latest version.  Be careful make sure this won't interfere with anything else you may be running.

The second will update only php related components.  But caution should be taken with this command also if you are running any kind of bespoke application.  Make sure if you update your php components to the latest version/release that your web application will still operate correctly.

Next run
$--> pecl install json

After this command has completed you need to make sure that JSON support is enabled with your Apache/PHP stack starts

To do this, you can either add the following line to the end of  your /etc/php.ini file or what I prefer to do is create a json.ini in the folder /etc/php.d  so run the command
$--> echo “extension=json.so” > /etc/php.d/json.ini

To add this to your php.ini fil…

Monitor LAMP on Centos

While not applicable for projects I based on Amazon Cloud Infrastructure when it comes to dedicated hosting on a third party hosting providers network, two tools I find extremely useful and easy to use for my LAMP based server monitoring projects are Munin (http://munin-monitoring.org/) and Monit (http://mmonit.com/monit/)

This is a very good how-to on using both these tools http://www.howtoforge.com/server-monitoring-with-munin-and-monit-on-centos-5.2
Its basic but aside from the standard monitoring plugins available for munin that monitor load averages, cpu usage, memory usage etc you can also get it to monitor items such as mysql queries, mysql slow queries, web requests etc. So its well worth checking out.
Monit is also very useful for monitoring and restarting services on your LAMP box. For example say you wanted to restart your httpd process if the load average on your server exceeded 5 for the past five minutes. Monit is an ideal tool for this.

Trevor

Installing APC on CentOS

The following procedure work for installing APC on CentOS
yum install php-pearyum install php-develyum install httpd-develpecl install apcSometimes you may get a missing pcre.h when compiling if you get this error
"apc pcre.h: No such file or directory"
if so run the following yum install pcre-devel and then run pecl install apc

The Value of AMIs for Cloud Testing?

Think of an AMI as an image of your server in the office with similar characteristics such as disk space, memory, processor power etc.

While several off-the-shelf AMIs exist either offered by Amazon themselves or the wider community.

The real beauty of AMIs, is the ease at which you can create your own custom AMIs that are specific to your business.

In addition to the standard computer charactertistics such as operating system, disk layout etc, you can also install and configure a set of pre-defined software and data specific to your business needs.

This gives you a great deal of availability when it comes to keeping your business running with minimum disruption.

Aside from Amazon’s big blunder towards the end of last week they are still one of the best cloud infrastructure provider in the world and in my view they well deserve that title.

When you set-up your Amazon Web Services account and register for specific services you can very quickly launch a computer in the Amazon cloud and …

MS Access, Group Totals by Week/Year

Table:

TAB_MOVEMENTS
DATE_RECORDED
DIRECTION

A basic table to track how many items moved in a particular direction

DIRECTION = U=up, D=down, E=error

Write a basic query for MS Access to group by week in the format WW/YY (week,year) with a total for each direction.

SELECT FORMAT( FORMAT (DATE_RECORDED, 'WW'),'00') + '/' + FORMAT(DATE_RECORDED,'YY') as DATEEXPR1, SUM( IIF( [DIRECTION] = 'U',1,0)) as TOTALU, SUM( IIF( [DIRECTION] = 'D',1,0)) as TOTALD, SUM( IIF( [DIRECTION] = 'E',1,0)) as TOTALE
FROM TAB_MOVEMENTS
WHERE [DATE_RECORDED] >= #01/01/2009# AND [DATE_RECORDED] <= #31/12/2009#
GROUP BY FORMAT( FORMAT (DATE_RECORDED, 'WW'),'00') + '/' + FORMAT(DATE_RECORDED,'YY')

This should return something similar to

DATEEXPR1TOTALUTOTALDTOTALE09/09101210/09523311/09727

Update SSL Cert on Amazon Elastic Load Balancer

If you have an SSL certificate associated with a HTTPS Load Balancer on Amazon Cloud

Here are the steps to update it

At the command prompt type the following to upload your new certificate to the IAM Service

$> iam-servercertupload -b /tmp/newsslcert.pem -k /tmp/my-private-key.pem -s MySiteSSL -v

Make sure to use the -v switch, we need the output for the next step.

you should see something like this

arn:aws:iam::55119xxxxxxx:server-certificate/MySiteSSL

You will need the ARN Amazon Resource Name which in this case is

Now use elb-set-lb-listener-ssl-cert using a https listener i.e. 443

$> elb-set-lb-listener-ssl-cert trevors-lb --lb-port 443 --cert-id arn:aws:iam::55119xxxxxxx:server-certificate/MySiteSSL

SQL Find Most Recent Items

Often I want to select the most recent test result for each item from a single table in my database.

For example, say I have table called tab_tests

And within that table I store test results for each item.

Over time I may have several results for the same item

Before I do the next test I wish to check what the most recent result was for each item.

Here is the query I use

SELECT o.itemid, o.testdate, o.testitem,o.nexttestdate, o.lasttestdate, o.testresult
FROM tab_tests AS o
WHERE (((o.testdate)=(SELECT MAX(testdate) FROM tab_tests as i WHERE i.itemid = o.itemid ) )AND ((o.nexttestdate)<=Date()));

Testing RFID on a Psion Workabout Pro

If your Workabout Pro has the correct Software installed for the installed/configured RFID reader, then you can simply use it's passive mode for reading RFID tags.

This works exactly the same as a barcode scanner.

So if you have an application open it, place the cursor in a data input field (textbox). Working like the barcode scanner, when the RFID reader reads the tag it will place the scanned data in that data field (textbox).
Its no more then 10 minutes to create a little test program in your favourite language such as VB, Visual C++, Java etc

Process CSV Files with VB.NET

An example CSV file containing the following record

"Firstname", "Surname", "Date-Time-Entered","Items"
"Trevor","O Connell","26/02/2009 18:01:00","12"
....

Dim fName, sName,sDate,sTime,readLine,strfilename,textdelimiter as String
Dim tmpDate as DateTime
Dim nItems as Integer
Dim splitLine() As String
Dim objStreamReader As StreamReader

filename = Server.MapPath("~/app_data/sampledata.csv")
objStreamReader = File.OpenText(filename)

' Read and Ignore Header
readLine = objStreamReader.ReadLine()

textdelimiter = ","`

While objStreamReader.Peek() <> -1
readLine = objStreamReader.ReadLine()

' Check if its a blank line if so ignore.
If LTrim(RTrim(readLine)) <> "" Then
splitLine = Split(readLine, textdelimiter)
sFname = = splitout(0).Replace("""", "")
sSname = = splitout(1).Replace("""", "")
tmpDate = sp…

View Database Profiling Informaiton with Zend_Db_Profiler_Firebug with Firebug Console.

For anyone who wants to get a quick idea how long various database queries may be taking in there php/zend applicaiton

Install and configure Zend_DB_Profiler
http://framework.zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug

you will require


* Firefox Browser ideally version 3 but version 2 is also supported.
* Firebug Firefox Plugin from http://www.getfirebug.com/
* FirePHP Firefox Plugin from http://www.firephp.org/
* FirePHP Core Library from http://www.firephp.org/
* FirePHP Zend Framework Library

you can simply enable it from your application .ini

[testing]
database.adapter = pdo_mysql
database.params.host = localhost
database.params.username = trevor
database.params.password = trevor123
database.params.dbname = db_store
database.params.profiler.enabled = true
database.params.profiler.class = Zend_Db_Profiler_Firebug

Comodo SSL - Firefox Warning when go from http to https

Recently I installed a new SSL certificate from Comodo.

After install, clients using Firefox were getting a warning when going from http to https.

On my server I was running CentOS, Apache, MySQL etc

I configured the httpd.conf as required.

My hosting company told me that Comodo did not send a CA-Bundle on this occarion i.e. certificate chain so I could use the old one

That was fine, but the certificate was renewed last April.

In the meantime Comodo issued a new CA bundle

So May 26th 2010.

https://support.comodo.com/index.php?_m=downloads&_a=viewdownload&downloaditemid=92&nav=0,1,5

I downloaded this, placed it on my server and pointed SSLCACertificateFile to it and all worked fine again

Reset Forgotten Password

This is the pseudo-code for scripting a forgotten password routine in your web software.

* User selects forgot password option
* User enters email address, maybe with confirm visual image code
* Find that email address in your database, verify it exists
* Generate a unique ID (token) and send this in an email confirmation mesage to the end user
* In addition save this unique ID (token) in a database along with a TTL (Time to Live) value.
* When the end user opens his/her email and clicks on the confirmation link
* Retrieve the unique ID (token) from the confirmation URL
* Check this exists in the table created above and verify that the TTL has not expired.
* If all okay, option to allow user reset password by entering a new password.
* Alternatively - a new randomly generated password is sent to that users email account.

VB.NET Replace Quotes Within a String

Parsing strings and removing double quotation from within a string.

Dim str As String = ""26/02/2009 18:01:00""

str = str.Replace("""", "") ' "26/02/2009 18:01:00"

Calling UDF C Functions from Genero 4Js

The classic process when creating a C/C++ function that can be called from 4Js Genero is as follows:

Step 1. Check that the number of parameters is correct

Step 2. Retrieve the parameters using the stack functions

Step 3. Do what the function has to do

Step 4. Sse the stack functions to stack the return values

Step 5. Return 0 in case of success

An exmaple calling WSC32.DLL routines.

//--------------------------------------------
// Sets parity, stop bits, and word length.
int _SioParms(const struct frontEndInterface &fx)
{
short status = -1;

// check if the in and out parameters are correct
if (fx.getParamCount() == 4 && fx.getReturnCount() == 1) {
long param1, param2, param3, param4;
short isNull1, isNull2, isNull3, isNull4;

int code;

// get from the stack each parameter
fx.popInteger(param4, isNull4);
fx.popInteger(param3, isNull3);
fx.popInteger(param2, isNull2);
fx.popInteger(param1, isNull1);

// check if they are not null
if (!isNull1 && !isNull2 &…

Download Orders from Pixmania Marketplace

# code snippet, Trevor O Connell, 2008
$oCurl = curl_init();

# Use your correct secret serial ID here. Pix Marketplace will supply these when
# you sign up.
$sSerial = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$sHttpLogin = 'pixloginaccount';
$sHttpPwd = 'pixpassword';

print "Downloading Pixmania UK Order File\n";

$sCalledurl = 'https://pixplace-ws.pixmania.com/index.php?d=webServices_Server&c=ServerRest&rm=exportFile&rf=exportOrdersToDeliver&site_id=1&sl='.$sSerial;

try
{
//Option: Url to call
curl_setopt( $oCurl, CURLOPT_URL, $sCalledurl );

//Option: Do not display the result but store it in a variable
curl_setopt( $oCurl, CURLOPT_RETURNTRANSFER, 1);

//Option: Set HTTPS Login And password
curl_setopt( $oCurl, CURLOPT_USERPWD, $sHttpLogin.':'.$sHttpPwd );
curl_setopt( $oCurl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt( $oCurl, CURLOPT_UNRESTRICTED_AUTH, true);

curl_setopt( $oCurl, CURLOPT_SSL_VERIFYHOST, 0);
curl_set…

Amazon EC2 Free for 1 Year

Over the past couple of months Digital Technology Management have been busy migrating a number of existing customer applications and systems over to Amazon Cloud Computing Platform.

We work with several hosting providers and each have there own benefits.

However on this occasion I got to hand it to Amazon. Its a very neat piece of technology.

For anyone who would like to try this out you can sign up for 1 year free at

Getting Current Inventory Listing on Amazon MWS

To get your current inventory listing on amazon do the following

Step 1. Run RequestReport with ReportType set to _GET_MERCHANT_LISTINGS_DATA_

$request = new MarketplaceWebService_Model_RequestReportRequest();
$request->setMarketplace(MARKETPLACE_ID);
$request->setMerchant(MERCHANT_ID);
$request->setReportType('_GET_MERCHANT_LISTINGS_DATA_');

Step 2: Run GetReportList

Step 3: Using the response from Step 2, match the ReportRequestIDs from 1 and 2 and extract the corresponding ReportID

Step 4: Use GetReport to retrieve the data for that specific ReportID which will include a flat file listing of all inventory you have currently loaded in to Amazon marketplace.

Startup Online Business – low budget security tips

What do you do when asked by a small startup at early stage, can you help secure our online business. In many instances they may have already purchased a standalone server either dedicated, shared, virtual or on the cloud some where.

At a minimum make sure that people connecting to your server are all working from a static IP address With these static IP address you can use a number of methods to tie down your server Use hosts.allow and hosts.deny and tcp_wrappers Use iptables and ipchains Use access control directives within apache httpd.conf Disable root access and setup accounts for each person connecting and require each user to su in order to access root

Access Windows Servers on the Cloud

Utilizing Microsoft RDP (Remote Desktop Protocol), iTap RDP gives you complete control over and fast access to your Windows PC from anywhere. ...

http://itap-mobile.com/itap-rdp

Advantages of Microsoft Windows Azure

Why Microsoft Azure
Cheaper then Amazon EC2 in the long run.Microsoft takes care of software updates, software patching, backups, virus protection etc.EC2 is not good for pure software developers too much hands on configuration.Complete integration with Visual Studio Development Environment.From a developers perspective scaling with Azure is much easier then with EC2.

Getting started with a free Amazon EC2 instance

This is a very easy step by step guide how to get started with Amazon EC2 Free Tier. http://lenni.info/blog/2011/03/getting-started-with-a-free-amazon-ec2-instance-logging-in-with-ssh/

Benchmarking Disk I/O with IOzone

IOzone is a filesystem benchmark tool. The benchmark generates and measures a variety of file operations. Iozone has been ported to many machines and runs under many operating systems.
http://www.iozone.org/