Posts

Showing posts from 2011

Java Ping Servers - Flyweight Reduce Memory Footprint

package ServerProbe;

/*
 * Simple demonstration how to use the flyweight design pattern to improve performance and reduce
 * memory footprint.
 * Create a ServerFactory based on a pre-defined number of server types e.g. Windows, Unix etc
 *  Within Server object, for example have a shareable method such as pingIT, also the server_type is
 * shareable
 * Pass IP address and ping duration in as parameters
 *
 */

public class Server {
  String server_type;

  Server(String type){
  server_type = type;
  }

  String getType() {
     return server_type;
  }

  public void pingIT(String ip, int duration) {
  System.out.println("Pinging ->" + server_type + " IP -> " + ip);
  }

  public String toString() {
      return server_type;
  }
}

import java.util.HashMap;

public class ServerFactory  {
  private static final HashMap serverByType = new HashMap();

  public static Server getServer(String serverType) {
     Server server  = (Server) serverByType.get(serverType);

   …

Composite Design-Pattern Amazon Payment Lines

package PaymentManager;

public class Order {
  String reference;
  double value;

  Order(String r, double v){
      reference = r;
      value = v;
  }
  String getReference() {
     return reference;
  }
  double getValue() {
     return value;
  }
  public String toString() {
      return reference;
  }
}


public class Payment {
  Payment pay;
  Order[] orders;
  String order_type;
  Payment(Payment p, Order[] o, String type ) {
      this(o, type);
      this.pay = p;
  }

  Payment(Order[] o, String type) {
      orders = o;
      order_type =type;
  }
  String getOrderType() {
      return order_type;
  }
  Payment getPayment() {
      return pay;
  }
  Order[] getOrders() {
      return orders;
  }
  public String toString() {
      return "Order Type -> " +order_type;
  }
}


public class OrderTestRun {
  public static void main(String[] args) {
  Order[] detail = {
  new Order("AMZ-SUB-001", 15.00),
  new Order("AMZ-SUB-002", 15.00)
      };
      Pa…

Using Amazon SQS from Java

You can find the AWS SDK for Java API Reference - 1.2.15 here
http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/overview-summary.html
....
....
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSClient;
....
.... static public String awsAccessKeyId = "";

static public String awsSecretAccessKey = "";
....
....
AmazonSQS sqs =
    new AmazonSQSClient(new BasicAWSCredentials(awsAccessKeyId ,awsSecretAccessKey ));

....
....

String url =
    sqs.createQueue(new CreateQueueRequest("dtm_test_queue")).getQueueUrl();
....
....

sqs.sendMessage(new SendMessageRequest(url, "Queue Data"));

Demo file copy using Guava

/* Demo file copy using Guava
 * src:file to be copied
 * dst:copied/new file created from copy.
 */
   public void dtmCopyFile(final String src, final String dst)
   {
      checkNotNull(src, "Source file cannot be null.");

      checkNotNull(dst, "Destination file cannot be null.");

      final File srcFile = new File(src);
      final File dstFile = new File(dst);

      try
      {
         Files.copy(srcFile, dstFile);
      }
      catch (IOException fileIoEx)
      {
         err.println("ERROR");
         err.println("Error copying file.");
err.println("Error Message: " + fileIoEx.toString() );
      }
   }

EJB Intercepts

EJB3 offers the ability to intercept EJB business methods by using AroundInvoke interceptors.

From this you can access the method name, the parameters passed, and the EJB context.

This is useful for

1. Performing security checks
2. Performing audits
3. Changing the values of method parameters in your Java EE applications using EJB interceptors

Here is a simple EJB interceptor:

public class InterceptorHandler {

@Resource
 private EJBContext context;

@AroundInvoke
protected Object audit(InvocationContext ctx) throws Exception {
    Principal principal = context.getCallerPrincipal();
    if (userIsValid(principal)) {
  // Complete code for logging
      }else{
  // Complete code for logging and exception handling
    }
    return ctx.proceed();
  }
}
To use this interceptor put an annotation on the designated EJB, for example

@Interceptors(InterceptorHandler.class)
@Stateless
public class TestBean {
  // Complete code here
}

ActiveMQ, easy to use open source message oriented middleware (MOM)

ActiveMQ is message oriented middleware (MOM), useful for receiving and processing asynchronous messages (queues or topics).
It is easily integrated with Java based applications (and others) via  the JMS API.
ActiveQ offers enterprise scale features which may be required when implementing complex distributred systems such as High availability with failover.Scalability and clustering through a distributed Network of Brokers.Pluggable persistence stores (JDBC, BDB, JDBM, file system).Distributed destinations and XA support.Caching.Connection pooling.Support for cross language clients such as .NET, C++.Support for scripting environments such as Perl, Python, and Ruby.Multiple Transport layers (TCP, UDP, multicast, NIO, SSL, Zeroconf, JXTA, JGroups).

Download at http://activemq.apache.org/

Getting to grips with Google Analytics API

Getting to grips with Google Analytics API


This shows the top 15 regions / by source / by number of visits decending

<?php

require 'gapi.class.php';

$username='your gmail email address';
$password='your password';
$profile_id='your profile ID, you can get this from the url when you view the standard report. Just look for id on the url';

$ga = new gapi($username,$password);

$ga->requestReportData($profile_id,array('source','region'),array('pageviews','visits'), '-visits','',
 '2011-11-01', // Start Date
                       '2011-11-30', // End Date
                       1,  // Start Index
                       15 // Max results
                       );

echo '<strong>Top 20 Region/Source by Visits</strong><br><br>';
echo '<table><tr>';

echo '<td>Region</td><td>Source</td><td>Page Views</td>…

AWS SDK for .NET with ElasticCache Support

AWS launched Amazon ElastiCache in Ireland

AWS launched Amazon ElastiCache in the US East (Northern Virginia) Region back in August and today enabled ElastiCache in EU West (Dublin), US West (Northern California), and Asia Pacific (Singapore and Tokyo).

New X-CART Store

A great site and resource if you require x-cart specific add-ons.  They developt e-commerce modules and templates for the x-cart platform.  I've worked with several of the modules and all are very easy to implement.  In addition if you don't want the hassle of installing the components yourself, William Hayes and his team will be more then happy to help

Check it out now The XCART Store

Top 8 Performance Problems on the Top 50 Retail Sites before we enter Holiday Seaso

Here are the top 5 performance bottlenecks that online retailers face.

Problem #1: Too many Redirects result in delayed First Impression
Problem #2: Web 2.0 / JavaScript impacting onLoad and blocking the browser
Problem #3: Complex CSS Selectors failing on IE8
Problem #4: 3rd Party Plugins such as Superfish
Problem #5: Large Content leads to long load times

Check out the full article here

Display ASP Menu Control in Chrome / Safari

I had a problem displaying the standard asp.net menu control in Google Chrome and Safari

I was using master pages

but if you modify the source file behind your master page and include the following

C#
protected void Page_Load(object sender, EventArgs e)
{
if (Request.UserAgent.Contains("AppleWebKit")) Request.Browser.Adapters.Clear();
}

VB.NET
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
If Request.UserAgent.Contains("AppleWebKit") Then
Request.Browser.Adapters.Clear()
End If
End Sub

Evaluating CDNs

This service CloudHarmony will test CDN networks near you.  It can test for other services also such as Cloud Storage etc.  Very neat.

http://cloudharmony.com/speedtest/run

UDF Class VB.NET Reset Connection String for Entity Framework

This is a useful class I've created mixing and matching code from the web.

But basically it allows you to reset the connection string for an entity framework and save the values to the current application configuration file.

To use, something as follows


       Dim uConnection As New uCustomConnectionString

' Connection String  Name
' Server
' Database / Catalog
' Username
' Password
        uConnection.SetDatabaseConnection ("db1001229_CountersEntities", "localhost\sqlexpress", "db1001229_Counters", "sa", "password")



----
Class

Imports System.Configuration
Imports System.Data.EntityClient
Imports System.Data.SqlClient

Public Class uCustomConnectionString
    Public Function SetDatabaseConnection(ByVal oConnectionString As String, ByVal ServerName As String, ByVal DatabaseName As String, ByVal NewUsername As String, ByVal NewPassword As String) As DialogResult
        Dim curConnection = ConfigurationManager.Conn…

.htaccess for XCART 4.4

Below is a typical .htaccess file to be used with x-cart 4.4
Change yourdomain to what ever.

Redirects from yourdomain.com to www.yourdomain.com

Also forces home.php to www.yourdomain.com

Also implements clean URL. Make sure Clean URL turned on in admin control panel within x-cart

# Clean URLs [[[
Options +FollowSymLinks -MultiViews -Indexes
<IfModule mod_rewrite.c>
        RewriteEngine On

        RewriteBase /
        DirectoryIndex home.php index.php
        RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /home\.php\ HTTP/
        RewriteRule ^(.*)home\.php$ / [R=301,L]
        RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
        RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

        RewriteCond %{ENV:REDIRECT_STATUS} !^401$
        RewriteCond %{REQUEST_URI} !^/(payment|admin|provider|partner)/
        RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico)$
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        Rew…

Is mod_deflate working in Apache

Just working on a number of projects and I wanted a quick and easy way to check if mod_deflate(compression) originally mod_gzip is enabled for a paritcular web server running apache.

This web site has a number of useful tools to assist with this.

http://www.whatsmyip.org/http_compression/

* http://www.elara.ie is gzipped
* Original Size: 285.14 KB
* Gzipped Size: 49.74 KB
* Data Savings: 82.56%

Microsoft All-In-One Code Framework

The Microsoft All-In-One Code Framework is a free, centralized code sample library provided by the Microsoft Community team.  Their goal is to provide typical code samples for all Microsoft development technologies.

You can view and download code samples from this link. You can also request code samples from Microsoft from this site.

http://1code.codeplex.com/wikipage?title=All-In-One%20Code%20Framework%20Sample%20Catalog

Freely-available libraries for the Microsoft .NET

Qink has assembled a comprehensive list of freely-available libraries for the Microsoft .NET platform.

http://qink.net/page/The-Ultimate-List-of-Freely-Available-_NET-Libraries.aspx

Charting Made Simple with FusionCharts

Image
A very neat library that developers can use free of charge in your web development projects to display nice charts e.g. bar charts, line charts, pie charts etc is
Fusion Charts Free Edition
http://www.fusioncharts.com/free/



I will post some code later for using these

But used dynamically with database content they provide an excellent way to help your end users visualise trends in data over time etc

Amazon Outage - What can you do

I think one of the biggest challenges facing any start-up is how to develop a sustainable DR strategy and plan which takes consideration of the current financial standing of the start-up. I also think many start-ups with good intentions discuss, explore and document DR strategies most appropriate to there business, but how many actually test or execute the DR strategy prior to a major outage. And it’s not good enough to just test the infrastructure, application and data You got to literally pull the plug. While many cloud vendors will claim that they can offer full redundancy and reliability its my opinion that all start-ups where it is financially viable should select two cloud providers i.e. primary and stand-by (DR). Interesting debate at CloudAve http://www.cloudave.com/11886/some-lessons-from-aws-outage/#comment-13688

NimbusDB Next Generation Database Platform

This looks really cool. NimbusDB. Its a combination of NoSQL and SQL, takes the best from both, combines them but plans to give developers a much more scalable database platform on which to build applications yet maintain the simplicity of using standard SQL Queries.

Watch Barry Morris, who is ex founder of IONA by the way.



Video streaming by Ustream


NimbusDB Presents at Under the Radar

Resize your VMWare Disks on CentOS

Modify you VM settings and increase the hard disk size for example add an additional 10GB.Boot systemRun fdisk and recreate partition #2fdisk /dev/sda2Issue the following commands D2NP2<enter> <enter>t28ewReboot Systemlvm pvresize /dev/sda2lvm pvdisplay # Take a note of the free PE (physical extents)lvm vgchange -a y lvm lvdisplay  # Take a note of logical volumelvm lvextend -l +320 /dev/VolGroup00/LogVol00resize2fs /dev/VolGroup00/LogVol00
You will need to tweak as  you go along.  In some examples above on the web, some people don’t do any reboot after step 4, but I needed to do a reboot.  Also after step 9ome people run an e2fsck, when ever I did this step 10 failed

Sample Conflict Resolution File for Plesk Restore

This is a sample conflict resolution file for Plesk which can be used during a restore

Change mydomain.ie to your domain and the IP address to your new shared IP address

<?xml version="1.0" encoding="UTF-8"?>
<conflict-resolution-rules>
    <policy/>

<rule conflict-guid="3fa1491e30551a7e3d1800bcc04077e1" conflict-id="0">
 <node children-processing-type="" name="domain">
    <attributes>
     <attribute name="id" value="4"/>
     <attribute name="guid" value="D68A3BF8-9C79-4072-A65F-8B25A02C7BC9"/>
     <attribute name="owner-guid" value="B416FF5A-136E-49F2-87B5-AEE13717F68B"/>
     <attribute name="name" value="mydomain.ie"/>
    </attributes>
   </node>
</dump-objects>
<resolution>
            <rename new-name="ip-type:shared:ip-address:212.212.212.1"…

Microsoft.Jet.OLEDB.4.0 provider is not registered on the local machine

I had a basic problem recently porting an ASP.NET application from 32 bit Windows 2003 to a virtual environment running Windows 64 bit.

The ASP.NET application was pretty basic and it worked with a MS Access backend.

I was using OLEDB Provider to connect from ASP.NET to the backend database

But as it turns out there is no version of JET for Windows 64 bit.

So you have to disable 64 bit ASP.NET under IIS and enable 32 bit ASP.NET under IIS.

Here are the steps I followed.

To run the 32-bit version of ASP.NET 2.0, follow these steps.  This was based on ASP.NET 2.0.50727

Start / Run  / cmdcscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET   W3SVC/AppPools/Enable32bitAppOnWin64 1%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -iNote One thing I missed, again simple but is to make sure that the 64 bit version of ASP.NET is prohibited and the 32 bit is allowed under the IIS web service extension list.

A Change from Zend, try Grails

I’ve been working with Grails for the past few months and I really like the platform.  Having worked with frameworks such as Zend, Grails comes as a breath of fresh air.
Grails is an open-source web application framework that leverages the Groovy language and complements Java Web development.

Its based on the MVC framework and it simplifies the work involved in getting your next web application up and running
Visit http://www.grails.org/

Getting Started With Grails

Reset Plesk Admin Password from Command Prompt

To get the current 'admin' password for Plesk, execute the following command at a command prompt in windows

"%plesk_bin%\plesksrvclient" -get

%plesk_bin% is something like c:\parallel\plesk\admin\bin

To get the password at command line and save to a file use the -nogui option
"%plesk_bin%\plesksrvclient" -get -nogui > c:\plesk_admin_passwd.txt

To set a new admin password for the Plesk Admin run the following command at a command prompt:
"%plesk_bin%\plesksrvclient" -set mypass true

Where mypass is the new password

Stashboard

A very basic dashboard for monitoring cloud based services such as EC2 instances etc

The open source status page for cloud services and APIs.
http://www.stashboard.org/

Simple But Neat FreeNATS

FreeNATS is an open source PHP and MySQL based network status testing, alerting and reporting package.

FreeNATS allows you to test your network and generate reporting to give you a bird's eye view of what is happening.

FreeNATS allows you to test nodes with

Ping Test (ICMP)
HTTP/HTTPs Test (Web)
IMAP/IMAPs Test
POP3/POP3s Test
MySQL Connection Test
MySQL Queries Test
TCP Port Test

Ideal for light weight use. Not as good as Nagios or Zenoss but for a basic LAMP configuration where basic reporting / alerting is required this is a nice fit.

Check it out
http://www.purplepixie.org/freenats/

Monitorix - Easy Server Monitoring

Monitorix allows you to monitor system CPU load, file usage, disk I/O, network port activity, mysql statistics, apache statistics, system demand and much more.

# Install pre-reqs
yum install httpd
yum install rrdtool rrdtool-perl
yum install perl-libwww-perl perl-MailTools perl-MIME-Lite perl-CGI

# Download RPMs from monitorix
# http://www.monitorix.org/downloads.html
# Download the latest version for your arch e.g. CentOS
wget http://www.monitorix.org/monitorix-2.3.0-1.noarch.rpm

# Install RPM
rpm -ivh monitorix-2.3.0-1.noarch.rpm

# Start the collection agent
service monitorix start

Happy monitoring!!

Coffescript

CoffeeScript is a new programming language that compiles to javascript

you can download the latest version here from git
http://jashkenas.github.com/coffee-script/



you can find a quick introduction to the key features / syntax here
http://coffeescript-seattlejs.heroku.com/#36
http://www.codeproject.com/Articles/240308/A-brief-introduction-to-CoffeeScript

Make File Synch Easier

For anyone looking to replace rsynch unison is a very useful bi-directional file synch program

http://www.cis.upenn.edu/~bcpierce/unison/

Test Remote MySQL from JAVA

import java.sql.*;

public class MysqlConnect{
  public static void main(String[] args) {
  System.out.println("MySQL Connect Example.");
  Connection conn = null;
  String url = "jdbc:mysql://mysql.myserver.com:3306/";
  String dbName = "my_database";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "my_user";
  String password = "my_password";
  try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  System.out.println("Connected to the database");
  conn.close();
  System.out.println("Disconnected from database");
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
}

Basic Zenoss Install

Download Zenoss RPM-GPG key
wget http://dev.zenoss.com/yum/RPM-GPG-KEY-zenoss

Import key
rpm --import RPM-GPG-KEY-zenoss

Download Zenoss Core
wget http://sourceforge.net/projects/zenoss/files/zenoss-3.1/zenoss-3.1.0/zenoss-3.1.0.el5.x86_64.rpm/download

Install Zenoss Core
yum install zenoss-3.1.0.el5.x86_64.rpm

Perform first-boot initialization
/etc/init.d/zenoss start

Once completed, connect to http://<your_server_name>:8080 with a web browser and run through the initial setup wizard i.e. set admin username and password.

Check server for rootkits with rkhunter

Step 1. Download the source files
mkdir $HOME/rkhunter
cd $HOME/rkhunter
wget -q http://sourceforge.net/projects/rkhunter/files/rkhunter/1.3.8/rkhunter-1.3.8.tar.gz

Step 2. Untar the archive
gzip -d rkhunter-1.3.8.tar.gz
tar -xvf rkhunter-1.3.8.tar

Step 3. Installation
cd $HOME/rkhunter/rkhunter-1.3.8
./installer.sh --install

Step 4. Try it out
/usr/local/bin/rkhunter -c

Remove Files with Special Characters

If you ever create a file with special characters by accident e.g.

--strip-options

You can delete by using

rm -- --strip-options

The initial -- means that no more arguments will appear on the command line thus --strip-options is treated at the file name

Repair All MYI Files with a single command

cd /var/lib/mysql

find . -name *.MYI -exec myisamchk -r '{}' \;

Change Security Groups on EC2

It is difficult to change the secuirty group which an EC2 instance is assigned once its running

However one way to accomplish this is

1. Right click on instance and select "Create Image (EBS AMI). For example if the instance is called staging-srv.

2. Give the image a name and description and then create

3. Create your new security group and define required security measures e.g. inbound ports

4. Create a new EC2 instance based on the above created image.

5. If a elastic IP is assigned to staging-srv then disassoicate it

5. Launch the new instance

6. Associate the elastic IP with the new instance

6. Rename the old instance to e.g. staging-srv to staging-srv-old

7. Name the new instance staging-srv

8. Test your new instance with the new security group

9. Once happy it works delete the old ECS instance.

Mount an EBS Volume on CentOS

1. Create a new EBS Volume.  Note the device name returned by AMZ e.g. /dev/sdf
2. Login to your Amazon Instance
3. At the prompt type fdisk /dev/sdf
4. Create a new primary partition and accept all the default values.
5. Type (w) to write partition data to disk
6. At the command prompt type mkfs.ext3 /dev/sdf  to format as an ext3 file system.
7. mkdir /web
8.Type mount /dev/sdf /web

Change Storage Engine from INNODB to MyISAM for all tables

The following is a basic php script to change the storage engine used by all MySQL tables for a specified database to MyISAM from INNODB.



<?php
$conn = mysql_connect("localhost","username","password"); mysql_select_db("database-name",$conn);
$sql = "SHOW tables"; $rs = mysql_query($sql);
while($row = mysql_fetch_array($rs)) {   $tbl = $row[0];   $sql = "ALTER TABLE $tbl  ENGINE=myisam";   mysql_query($sql); } ?>

To change all tables from MyISAM to INNODB

<?php
$conn = mysql_connect("localhost","username","password"); mysql_select_db("database-name",$conn);
$sql = "SHOW tables"; $rs = mysql_query($sql);
while($row = mysql_fetch_array($rs)) {   $tbl = $row[0];   $sql = "ALTER TABLE $tbl  ENGINE=INNODB";   mysql_query($sql); } ?>

Install PHP 5.3.6 on CentOS 64bit

Create Install folders and get rpms
Login as root
cd $HOME
mkdir php-setup-packages
cd $HOME/php-setup-packages
wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-6.ius.el5.noarch.rpm

Install Required RPMs
cd $HOME/php-setup-packages
rpm -Uvh *.rpm

Remove Existing PHP Packages
yum remove php php-*

Install PHP 5.3.5 Packages
yum install php53u-pear
yum install php53u php53u-cli
yum install php53u-common
yum install php53u-devel
yum install php53u-gd
yum install php53u-mbstring
yum install php53u-mcrypt
yum install php53u-mysql
yum install php53u-pdo
yum install php53u-soap
yum install php53u-xml
yum install php53u-xmlrpc
yum install php53u-bcmath
yum install php53u-pecl-apc
yum install php53u-pecl-memcache
yum install php53u-snmp

Chroot Apache on CentOS 5 32bit

SECUREFOLDER=/securesystem
mkdir $SECUREFOLDER
mkdir -p $SECUREFOLDER/var/run
chown -R root.root $SECUREFOLDER/var/run
mkdir -p $SECUREFOLDER/home/httpd
mkdir -p $SECUREFOLDER/var/www/html
mkdir -p $SECUREFOLDER/tmp
chmod 1777 $SECUREFOLDER/tmp
mkdir -p $SECUREFOLDER/var/lib/php/session
chown root.apache $SECUREFOLDER/var/lib/php/session
cd /opt/
yum list | grep chroot
wget http://core.segfault.pl/~hobbit/mod_chroot/dist/mod_chroot-0.5.tar.gz
tar -zxvf mod_chroot-0.5.tar.gz
cd mod_chroot-0.5
apxs -cia mod_chroot.c
vi /etc/httpd/conf/httpd.conf
setsebool httpd_disable_trans 1
vi /etc/init.d/httpd
chattr +i /etc/init.d/httpd
/etc/init.d/httpd start
/etc/init.d/httpd start

Script to chroot MySQL on 32bit CentOS 5

#!/bin/bash
# Set chroot location
J=/securesystem/mysql
/etc/init.d/mysqld stop

# Creating directory structure
mkdir -p $J/dev $J/etc $J/tmp $J/var/tmp $J/usr/libexec $J/usr/share/mysql/english \
  $J/usr/share/mysql/norwegian $J/var/run/mysqld $J/var/log $J/var/lib $J/bin $J/lib $J/var/run/nscd
chown -R root:sys $J
chmod -R 755 $J
chmod 1777 $J/tmp
# Copy necessary files
cp /usr/libexec/mysqld $J/usr/libexec/
cp /usr/share/mysql/english/errmsg.sys $J/usr/share/mysql/english/
cp /usr/share/mysql/norwegian/errmsg.sys $J/usr/share/mysql/norwegian/
cp -r /usr/share/mysql/charsets $J/usr/share/mysql/
cp /etc/hosts $J/etc/
cp /etc/host.conf $J/etc/
cp /etc/resolv.conf $J/etc/
cp /bin/bash $J/bin
grep mysql /etc/group > $J/etc/group
grep mysql /etc/passwd > $J/etc/passwd
cp /etc/my.cnf $J/etc/
cp -R /var/lib/mysql $J/var/lib/
chown -R mysql:mysql $J/var
cp /usr/lib/libkrb5.so.3 /lib/libdl.so.2 /lib/libc.so.6 /lib/ld-linux.so.2 \
/lib/librt.so.1 /usr/lib/libz.so.1 /lib/libssl.so.6 /lib…

SolarWinds latest tool lets you shut down & restart VMware machine

SolarWinds latest tool lets you shut down & restart VMware machines without logging into vCenter™ or vSphere™. It also gives you constant visibility into your VMware environment & up/down status of your VMware apps.

Free VM Console Highlights:

Bounce VMs without logging into vCenter/vSphereEnd-to-end visibility into your VMware environment- from vCenter through ESX hosts to VM guestTrack the real-time up/down status of your VMs from your desktop
http://www.solarwinds.com/register/registrationshort.aspx?program=1320&c=70150000000P9IG&CMP=BIZ-TAD-PETRI-VIRT-VMCNSL-DL-2011

Table ‘mysql.servers’ doesn’t exist

ERROR 1146 (42S02): Table ‘mysql.servers’ doesn’t exist
This appeared up on Server version: 5.1.57 when ever I'd run the FLUSH PRIVILEGES command from within mysql
To resolve this 


USE mysql; CREATETABLE`servers`(`Server_name`CHAR(64)NOTNULL,`Host`CHAR(64)NOTNULL,`Db`CHAR(64)NOTNULL,`Username`CHAR(64)NOTNULL,`Password`CHAR(64)NOTNULL,`Port`INT(4)DEF

MySQL Error Invalid Table or Database Name

We upgraded our MySQL server recently which ran several Joomla web sites

After the upgrade we discovered the following error in the mysql log files

090425 23:10:52 [ERROR] Invalid (old?) table or database name 'database-name'

It turns out MySQL does not like the use of - in database names.

One solution is to rename the MySQL database changing the - to an _

Then update the mysql dictionary

UPDATE mysql.db SET Db = 'database_name' WHERE Db = 'database\-name'; FLUSH PRIVILEGES;

Mango Features for Business Users

What can business users expect from Mango

1. Mobile access to documents
Mango will add the ability to share and save documents though Office 365.

2. Pinnable e-mail folders
You'll be able to pin specific e-mail folders or RSS feeds to the start screen.

3. E-Mail server search
Mango will add the ability to search for old e-mail stored on the server, not just on phone.

4. Support for Lync
Microsoft's unified communications platform, will be available as a free download around the time Mango is released.

5. Support for stronger passwords
At the moment you can only use simple PINS but with Mango you will be able to set morecomplex alpha-numeric passwords, which will improve security.

6. Information Rights Management
Support for additional security, tracking and blocking policies around emails and documents.

7. Support for hidden Wi-Fi netowrks.
The ability to connect to corporate WLANs which have hidden SSIDs.

“Mango” Available. Windows Phone Developer Tools

I develop software that runs on mobile devices including PDAs, iPhone and most recently which uses the Microsoft Windows Phone.

What is Mango? Mango is the code name for The Windows Phone Developer Tools 7.1 Beta.

For those interested you can download the 7.1 Beta Tools from here.


The Windows Phone Developer Tools includes the following

•Microsoft Windows Phone Developer Tools 7.1 (Beta)
•Windows Phone Emulator (Beta)
•Silverlight 4 SDK and DRT
•Microsoft XNA Game Studio 4.0 Referesh Windows Phone Extensions
•Microsoft Expression Blend SDK Preview for Windows Phone 7.1
•WCF Data Services Client for Window Phone 7.1

New X-CART Has Memcache Options

One thing I really like about the new x-cart versions is that they allow you to use memcache to cache data

In the root x-cart folder in config.php you can specify to use memcache

define('USE_MEMCACHE_DATA_CACHE', true);
define('MEMCACHE_SERVER_ADDRESS', 'localhost');
define('MEMCACHE_SERVER_PORT', 11211);

Now the only problem is that it only uses one memcache server so you either use the server you are running x-cart on or else dedicate a server specific for caching

Configure OBM Client Backup on CentOS

Creating a new profile on

Step 1
Delete old configuration file
rm /root/.obm/config/config.sys

Step 2
Run Configurator
/usr/local/obm/bin/Configurator.sh

Step 3
Enter a new username/password


Step 4
Enter a server URL

Step 5
Select Protocol HTTP or HTTPS

Step 6
Do you want to use a Proxy server?

Step 7

It will find your Backup Sets and list them

Step 8
Select the type of encrypting algorithm ? (1) Twofish (2) AES (3) Triple DES (4) No encryption :

Step 9

Enter your encryption key. Very important if you loose this you cannot restore your data in the future.

Step 10.
Enter it a second time.

Step 11.
Select Encrypting Mode ? (1) ECB (2) CBC : 1
Step 12.
Do you want to run scheduled backup on this computer, I normally select yes.

Replace Your MySQL Server with Percona Server

Percona Server is an drop-in replacement for MySQL. It has better performance and it provides far better slow-log diagnostics

In addition with Percona Server:

1. Query times are faster and more consistent.
2. Because of this you can introducing techniques such as data sharding
3. Save costs with less hardware upgrades
4. Better uptime with less system administration and tuning

X-CART Static Pages for X-Mall

Static Pages for x-mall in x-cart by BCS is a very useful add-on for allowing providers create static pages for example specific terms and conditions, refund policy etc

http://www.bcsengineering.com/store/x-mall-static_pages-for-each-store.html

This mod allows each provider to have their own static pages on their store front!

X-CART : Give Each Provider Standalone Shop Front

BCS have a very neat module for x-cart that allows you give each provider there own sub domain

For example

jones.myshop.com

toys.myshop.com
etc

http://www.bcsengineering.com/store/x-mall/

UK IP Addressing and Amazon

Something that came to my attention recently is that Amazon Cloud Solutions i.e. EC2 Instances etc cannot supply a customer with a UK registered IP address which they can assign to either an Elastic IP or and Elastic Load Balancer IP.

This creates problems for companies seeking high google rankings

Shard-Query - Improve MySQL Query Performance

Shard-Query is an open source tool kit which helps improve the performance of queries against a MySQL database by distributing the work over multiple machines and/or multiple cores.
Visit MySQL Performance Blog - Shard-Query

Monitoring Bandwidth Usage on CentOS

Recently I came across a very neat tool for monitoring bandwidth usage on CentOS

It takes about 5 minutes to install / configure with yum repos.

Have a read through "Monitoring bandwidth usage with vnStat under CentOS 5 Linux"

Custom XCF Example

This is an example custom XCF file for Four Js GAS.

In this example I've set custom environment variables, set the path for the working application directory, specified a specific module and passed in a parameter.

One handy use of an XCF file like this is that I can setup several for example say I have 5 weighbridges and I run a 4Js application to capture the weight etc of each truck as it passes over the weighbridge

I can setup an XCF for each weighbridge passing in the parameter 1, 2, 3, to the same program weighbridge.42r


<APPLICATION Parent="defaultgdc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="http://www.4js.com/ns/gas/2.20/cfextwa.xsd">
  <EXECUTION AllowUrlParameters="TRUE">
        <ENVIRONMENT_VARIABLE Id="DBDATE">DMY4/</ENVIRONMENT_VARIABLE>
        <ENVIRONMENT_VARIABLE Id="GREDIR">f:\PROGRAM FILES (X86)\FOURJS\GRE\</ENVIRONMENT_VAR…

Reference Remote DB in 4js Genero

In your fglprofile in $FGLDIR/etc to access remote MySQL databases


dbi.default.driver = "dbmmys51x.dll"
dbi.database.rdb.source = "remote_db@remote_host:3306"
dbi.database.rdb.driver = "dbmmys51x"
dbi.database.rdb.username = "remoteuser"
dbi.database.rdb.password = "remotepassword"

Remote host can be valid hostname or else and IP address e.g. 192.60.30.11

OpenLayers for Web Based Maps

OpenLayers is a JavaScript library for displaying map data in web browsers.
Its 100% javascript based and is a possible solution for developing GIS based solutions on the web.
http:/ /openlayers.org/

Get Amazon Orders for the Last Two Hours

$tmptime = time() - (3600*2);
$ordertime=date("Y-m-d H:i:s",$tmptime);
$request->setCreatedAfter(new DateTime($ordertime, new DateTimeZone('UTC')));

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()));